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

Browser crash - Too many ticks added when min and max are of similar values #23

Open
JacquiManzi opened this issue Apr 10, 2013 · 0 comments

Comments

@JacquiManzi
Copy link

The problem exists on line 7230 in envision.js in the extendYRange function.

As an example, two values of min and max are compared... let's use:

o min = 18.0001530072
o max = 18.0001530082

Let's use 2 for our line width and we get this:

o range = (max-min) //1.000000082740371e-9
o max += 2 * 0.01 //18.0201530082
o min -= 2*0.01 //17.980153007200002
o newRange = (min-max) //0.04000000099999923
o newRange / range //39999997.69038458

As shown above, 39999997.69038458 is the number of ticks that will be added to Y Axis. This causes the browser to freeze and crash.

Function in question:

extendYRange : function (axis, data, options, lines) {

var o = axis.options;

// HACK
if ((!o.max && o.max !== 0) || (!o.min && o.min !== 0)) {
  axis.max += options.lineWidth * 0.01;
  axis.min -= options.lineWidth * 0.01;
  /*
  axis.max = axis.p2d((axis.d2p(axis.max) + options.lineWidth));
  axis.min = axis.p2d((axis.d2p(axis.max) - options.lineWidth));
  */
}

}
});

I have modified this in my code base to resolve the issue for myself. I am now scaling the tick size with the axis range:

// HACK
var numTicks = (axis.max-axis.min)/axis.tickSize;
if ((!o.max && o.max !== 0) || (!o.min && o.min !== 0)) {
axis.max += options.lineWidth * 0.01;
axis.min -= options.lineWidth * 0.01;

//JMM: Added this because increasing the min/max when numbers with very little difference between min and max (e.g 1e-9) meant that the size of the adjustment above caused millions of ticks to be generated. So, we need to scale the tick size with the axis range.
if((axis.max - axis.min)/axis.tickSize > numTicks)
{
axis.tickSize = (axis.max-axis.min)/numTicks;
}
/*
axis.max = axis.p2d((axis.d2p(axis.max) + options.lineWidth));
axis.min = axis.p2d((axis.d2p(axis.max) - options.lineWidth));
*/
}
}
});

This is what I did to fix this, but am not sure if this is a good general solution since I am not sure why the range is being extended in the first place.

Thanks!
-Jacqui

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

No branches or pull requests

1 participant