Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exact dates contained in the data not being displayed #167

Open
chrislkeller opened this issue Jun 26, 2015 · 3 comments
Open

Exact dates contained in the data not being displayed #167

chrislkeller opened this issue Jun 26, 2015 · 3 comments
Labels

Comments

@chrislkeller
Copy link

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 chrislkeller changed the title Why wouldn't exact dates contained in the data be displayed Exact dates contained in the data not being displayed Jun 26, 2015
@nsonnad
Copy link
Contributor

nsonnad commented Jun 28, 2015

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

@yanofsky
Copy link
Contributor

@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 yanofsky@c69abba

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.

@chrislkeller
Copy link
Author

@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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants