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

Select reasonable values from g.snapEnds() #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

greezybacon
Copy link

g.raphael seems to select strange values for the axis limits. This commit edits the code for g.snapEnds to make it simpler and pick sane numbers for the axis limits:

Thanks to Drew Noakes and his algorithm posted at http://stackoverflow.com/questions/326679/choosing-an-attractive-linear-scale-for-a-graphs-y-axis, which I adapted into g.snapEnds(). In my case, with a time-series dataset, the values for the axis were being selected outside the timeframe of the data. Therefore, the graph was plotted outside the graph area on both sides of the graph. This algorithm selects axis ends that are outside the dataset, is simple, and likely much faster.

Thanks to Drew Noakes and his algorithm posted at
http://stackoverflow.com/questions/326679/choosing-an-attractive-linear-scale-for-a-graphs-y-axis
which I adapted into g.snapEnds(). In my case, with a time-series
dataset, the values for the axis were being selected outside the
timeframe of the data. Therefore, the graph was plotted outside the
graph area on both sides of the graph. This algorithm selects axis
ends that are outside the dataset, is simple, and likely much faster
@eddiefletchernz
Copy link

I just figured that this was a problem after 2 days of trying to debug my code.... I was going to fix this but thanks for already doing it!

@eddiefletchernz
Copy link

Here's a jsFiddle that demonstrates the issue:
http://jsfiddle.net/TheodoreIII/PgwcU/1

and with your new code:
http://jsfiddle.net/TheodoreIII/PgwcU/2

Thank you so much!

@kcar
Copy link

kcar commented Feb 15, 2013

Is there a reason to leave in rounding at all rather than just using the actual minimum and maximum of your graph?

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

Successfully merging this pull request may close these issues.

3 participants