Skip to content

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

@JacquiManzi

Description

@JacquiManzi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions