Chartbuilder icon indicating copy to clipboard operation
Chartbuilder copied to clipboard

Exact dates contained in the data not being displayed

Open chrislkeller opened this issue 10 years ago • 3 comments

Have to say this refactor is a dream. Nice work all around.

I'm working to get our version at KPCC updated and in some test data I'm not getting the years to display verbatim. By default dates are rendered every five years. I did add a four year frequency to the dateFrequencies object, but that ignores the minDate (1962) and the maxDate (2014).

Any hints on where I can begin to address and configure to only 1962, 1966, 1970, etc are displayed?

Data is:

year,Midterm Primary Turnout,Midterm General Turnout
2014,17.08%,25.25%
2010,23.45%,53.77%
2006,27.44%,52.14%
2002,25.85%,45.03%
1998,38.44%,53.41%
1994,31.78%,58.59%
1990,37.71%,55.23%
1986,38.61%,59.99%
1982,52.96%,69.72%
1978,74.09%,68.68%
1974,51.70%,62.60%
1970,61.32%,75.50%
1966,64.14%,79.55%
1962,60.86%,78.14%

Using Auto date frequency image

Attempt at 4-year date frequency image

chrislkeller avatar Jun 26 '15 21:06 chrislkeller

This is to do with how d3 handles date intervals. As you can see in the code for d3.time.interval.range, it works by converting your year to a number and running year % interval, adding to the final array whichever values resolve to zero. So in your case:

1962 % 4 // 2 -- not added to array
1964 % 4 // 0 -- added to array

Here's a basic example: http://requirebin.com/?gist=8a857f836aefc7e43e72

nsonnad avatar Jun 28 '15 19:06 nsonnad

@chrislkeller I would say the best bet is to make two new date frequencies: "presidential election years" and "mid-term election years" adding them to the array here https://github.com/Quartz/Chartbuilder/blob/master/src/js/util/process-dates.js#L207

Here's commit that does that https://github.com/yanofsky/Chartbuilder/commit/c69abbaf6e46820e679ed860210b93015d94be52

but there's some bug that will incorrectly label the first tick if it doesn't fall on an election year, so it's not ready for production.

I'm trying to track down what code is causing that issue or fix this code so that it wont.

yanofsky avatar Jun 28 '15 23:06 yanofsky

@nsonnad, @yanofsky: The knowledge and example code is much appreciated.

@yanofsky - Aside from the bug you point out your commit works like you mentioned, though we do lose a tick for the last year in the data - in this case 2014.

image

Using the RequireBin link I'll continue to learn more about how this works...

chrislkeller avatar Jul 01 '15 06:07 chrislkeller