Skip to content

Instantly share code, notes, and snippets.

@adambard
Last active August 29, 2015 14:02
Show Gist options
  • Save adambard/9395123d1fbb5a530ecc to your computer and use it in GitHub Desktop.
Save adambard/9395123d1fbb5a530ecc to your computer and use it in GitHub Desktop.
// Chart.redraw
redraw: function (animation) {
var chart = this,
//...
series = chart.series,
//...
;
// ...<snip>...
// redraw affected series
each(series, function (serie) {
if (serie.isDirty && serie.visible &&
(!serie.isCartesian || serie.xAxis)) { // issue #153
serie.redraw(); // <==============================
}
});
},
///////////// CALLS ///////////////////
// Series.redraw
redraw: function () {
var series = this,
chart = series.chart,
wasDirtyData = series.isDirtyData, // cache it here as it is set to false in render, but used after
group = series.group,
xAxis = series.xAxis,
yAxis = series.yAxis;
// reposition on resize
if (group) {
if (chart.inverted) {
group.attr({
width: chart.plotWidth,
height: chart.plotHeight
});
}
group.animate({
translateX: pick(xAxis && xAxis.left, chart.plotLeft),
translateY: pick(yAxis && yAxis.top, chart.plotTop)
});
}
series.translate();
series.setTooltipPoints(true);
series.render();
if (wasDirtyData) {
fireEvent(series, 'updatedData'); // <=================================
}
},
////////////// WHICH FIRES ///////////////////
// Scroller.updatedDataHandler
updatedDataHandler: function () {
var scroller = this.chart.scroller,
baseSeries = scroller.baseSeries,
baseXAxis = baseSeries.xAxis,
baseExtremes = baseXAxis.getExtremes(),
baseMin = baseExtremes.min,
baseMax = baseExtremes.max,
baseDataMin = baseExtremes.dataMin,
baseDataMax = baseExtremes.dataMax,
range = baseMax - baseMin,
stickToMin,
stickToMax,
newMax,
newMin,
doRedraw,
navigatorSeries = scroller.series,
navXData = navigatorSeries.xData,
hasSetExtremes = !!baseXAxis.setExtremes;
// detect whether to move the range
stickToMax = baseMax >= navXData[navXData.length - 1] - (this.closestPointRange || 0); // #570
stickToMin = baseMin <= baseDataMin;
// set the navigator series data to the new data of the base series
if (!scroller.hasNavigatorData) {
navigatorSeries.options.pointStart = baseSeries.xData[0];
navigatorSeries.setData(baseSeries.options.data, false);
doRedraw = true;
}
// if the zoomed range is already at the min, move it to the right as new data
// comes in
if (stickToMin) {
newMin = baseDataMin;
newMax = newMin + range;
}
// if the zoomed range is already at the max, move it to the right as new data
// comes in
if (stickToMax) {
newMax = baseDataMax;
if (!stickToMin) { // if stickToMin is true, the new min value is set above
newMin = mathMax(newMax - range, navigatorSeries.xData[0]);
}
}
// update the extremes
if (hasSetExtremes && (stickToMin || stickToMax)) {
if (!isNaN(newMin)) {
baseXAxis.setExtremes(newMin, newMax, true, false, { trigger: 'updatedData' });
}
// if it is not at any edge, just move the scroller window to reflect the new series data
} else {
if (doRedraw) {
this.chart.redraw(false); // <================================== LOOPS
}
scroller.render(
mathMax(baseMin, baseDataMin),
mathMin(baseMax, baseDataMax)
);
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment