Skip to content

Commit

Permalink
Fixed #4558, when resizing chart during addPoint animation cause erro…
Browse files Browse the repository at this point in the history
…r in stacking.
  • Loading branch information
pawelfus authored and TorsteinHonsi committed Sep 17, 2015
1 parent dc21764 commit 8d8cbee
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 26 deletions.
49 changes: 41 additions & 8 deletions js/highcharts.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -13812,6 +13812,10 @@ Series.prototype = {
plotX,
plotY,
lastPlotX,
stackIndicator = {
x: null,
index: 0
},
closestPointRangePx = Number.MAX_VALUE;

// Translate each point
Expand All @@ -13836,9 +13840,9 @@ Series.prototype = {

// Calculate the bottom y value for stacked series
if (stacking && series.visible && stack && stack[xValue]) {

stackIndicator = series.getStackIndicator(stackIndicator, xValue);
pointStack = stack[xValue];
stackValues = pointStack.points[series.index + ',' + i];
stackValues = pointStack.points[series.index + ',' + xValue + ',' + stackIndicator.index];
yBottom = stackValues[0];
yValue = stackValues[1];

Expand Down Expand Up @@ -15202,6 +15206,10 @@ Series.prototype.setStackedPoints = function () {
yAxis = series.yAxis,
stacks = yAxis.stacks,
oldStacks = yAxis.oldStacks,
stackIndicator = {
x: null,
index: 0
},
isNegative,
stack,
other,
Expand All @@ -15218,8 +15226,8 @@ Series.prototype.setStackedPoints = function () {
for (i = 0; i < yDataLength; i++) {
x = xData[i];
y = yData[i];
pointKey = series.index + ',' + i;

stackIndicator = series.getStackIndicator(stackIndicator, x);
pointKey = series.index + ',' + x + ',' + stackIndicator.index;
// Read stacked values into a stack based on the x value,
// the sign of y and the stack key. Stacking is also handled for null values (#739)
isNegative = negStacks && y < (stackThreshold ? 0 : threshold);
Expand Down Expand Up @@ -15288,7 +15296,11 @@ Series.prototype.setPercentStacks = function () {
var series = this,
stackKey = series.stackKey,
stacks = series.yAxis.stacks,
processedXData = series.processedXData;
processedXData = series.processedXData,
stackIndicator = {
x: null,
index: 0
};

each([stackKey, '-' + stackKey], function (key) {
var i = processedXData.length,
Expand All @@ -15299,8 +15311,9 @@ Series.prototype.setPercentStacks = function () {

while (i--) {
x = processedXData[i];
stackIndicator = series.getStackIndicator(stackIndicator, x);
stack = stacks[key] && stacks[key][x];
pointExtremes = stack && stack.points[series.index + ',' + i];
pointExtremes = stack && stack.points[series.index + ',' + x + ',' + stackIndicator.index];
if (pointExtremes) {
totalFactor = stack.total ? 100 / stack.total : 0;
pointExtremes[0] = correctFloat(pointExtremes[0] * totalFactor); // Y bottom value
Expand All @@ -15311,6 +15324,21 @@ Series.prototype.setPercentStacks = function () {
});
};

/**
* Get stack indicator, according to it's x-value, to determine points with the same x-value
*/
Series.prototype.getStackIndicator = function(stackIndicator, x) {
if (stackIndicator.x !== x) {
stackIndicator = {
x: x,
index: 0
};
} else {
stackIndicator.index++;
}
return stackIndicator;
};

// Extend the Chart prototype for dynamic methods
extend(Chart.prototype, {

Expand Down Expand Up @@ -15886,6 +15914,7 @@ var AreaSeries = extendClass(Series, {
plotY,
points = this.points,
connectNulls = this.options.connectNulls,
stackIndicator,
i,
x;

Expand Down Expand Up @@ -15923,8 +15952,12 @@ var AreaSeries = extendClass(Series, {

// Loop down the stack to find the series below this one that has
// a value (#1991)
for (i = series.index; i <= yAxis.series.length; i++) {
stackPoint = stack[x].points[i + ',' + x];
for (i = series.index; i <= yAxis.series.length; i++) {
stackIndicator = series.getStackIndicator({
x: null,
index: 0
}, x);
stackPoint = stack[x].points[i + ',' + x + ',' + stackIndicator.index];
if (stackPoint) {
y = stackPoint[1];
break;
Expand Down
8 changes: 6 additions & 2 deletions js/highmaps.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -13313,6 +13313,10 @@ Series.prototype = {
plotX,
plotY,
lastPlotX,
stackIndicator = {
x: null,
index: 0
},
closestPointRangePx = Number.MAX_VALUE;

// Translate each point
Expand All @@ -13337,9 +13341,9 @@ Series.prototype = {

// Calculate the bottom y value for stacked series
if (stacking && series.visible && stack && stack[xValue]) {

stackIndicator = series.getStackIndicator(stackIndicator, xValue);
pointStack = stack[xValue];
stackValues = pointStack.points[series.index + ',' + i];
stackValues = pointStack.points[series.index + ',' + xValue + ',' + stackIndicator.index];
yBottom = stackValues[0];
yValue = stackValues[1];

Expand Down
49 changes: 41 additions & 8 deletions js/highstock.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -13812,6 +13812,10 @@ Series.prototype = {
plotX,
plotY,
lastPlotX,
stackIndicator = {
x: null,
index: 0
},
closestPointRangePx = Number.MAX_VALUE;

// Translate each point
Expand All @@ -13836,9 +13840,9 @@ Series.prototype = {

// Calculate the bottom y value for stacked series
if (stacking && series.visible && stack && stack[xValue]) {

stackIndicator = series.getStackIndicator(stackIndicator, xValue);
pointStack = stack[xValue];
stackValues = pointStack.points[series.index + ',' + i];
stackValues = pointStack.points[series.index + ',' + xValue + ',' + stackIndicator.index];
yBottom = stackValues[0];
yValue = stackValues[1];

Expand Down Expand Up @@ -15202,6 +15206,10 @@ Series.prototype.setStackedPoints = function () {
yAxis = series.yAxis,
stacks = yAxis.stacks,
oldStacks = yAxis.oldStacks,
stackIndicator = {
x: null,
index: 0
},
isNegative,
stack,
other,
Expand All @@ -15218,8 +15226,8 @@ Series.prototype.setStackedPoints = function () {
for (i = 0; i < yDataLength; i++) {
x = xData[i];
y = yData[i];
pointKey = series.index + ',' + i;

stackIndicator = series.getStackIndicator(stackIndicator, x);
pointKey = series.index + ',' + x + ',' + stackIndicator.index;
// Read stacked values into a stack based on the x value,
// the sign of y and the stack key. Stacking is also handled for null values (#739)
isNegative = negStacks && y < (stackThreshold ? 0 : threshold);
Expand Down Expand Up @@ -15288,7 +15296,11 @@ Series.prototype.setPercentStacks = function () {
var series = this,
stackKey = series.stackKey,
stacks = series.yAxis.stacks,
processedXData = series.processedXData;
processedXData = series.processedXData,
stackIndicator = {
x: null,
index: 0
};

each([stackKey, '-' + stackKey], function (key) {
var i = processedXData.length,
Expand All @@ -15299,8 +15311,9 @@ Series.prototype.setPercentStacks = function () {

while (i--) {
x = processedXData[i];
stackIndicator = series.getStackIndicator(stackIndicator, x);
stack = stacks[key] && stacks[key][x];
pointExtremes = stack && stack.points[series.index + ',' + i];
pointExtremes = stack && stack.points[series.index + ',' + x + ',' + stackIndicator.index];
if (pointExtremes) {
totalFactor = stack.total ? 100 / stack.total : 0;
pointExtremes[0] = correctFloat(pointExtremes[0] * totalFactor); // Y bottom value
Expand All @@ -15311,6 +15324,21 @@ Series.prototype.setPercentStacks = function () {
});
};

/**
* Get stack indicator, according to it's x-value, to determine points with the same x-value
*/
Series.prototype.getStackIndicator = function(stackIndicator, x) {
if (stackIndicator.x !== x) {
stackIndicator = {
x: x,
index: 0
};
} else {
stackIndicator.index++;
}
return stackIndicator;
};

// Extend the Chart prototype for dynamic methods
extend(Chart.prototype, {

Expand Down Expand Up @@ -15886,6 +15914,7 @@ var AreaSeries = extendClass(Series, {
plotY,
points = this.points,
connectNulls = this.options.connectNulls,
stackIndicator,
i,
x;

Expand Down Expand Up @@ -15923,8 +15952,12 @@ var AreaSeries = extendClass(Series, {

// Loop down the stack to find the series below this one that has
// a value (#1991)
for (i = series.index; i <= yAxis.series.length; i++) {
stackPoint = stack[x].points[i + ',' + x];
for (i = series.index; i <= yAxis.series.length; i++) {
stackIndicator = series.getStackIndicator({
x: null,
index: 0
}, x);
stackPoint = stack[x].points[i + ',' + x + ',' + stackIndicator.index];
if (stackPoint) {
y = stackPoint[1];
break;
Expand Down
9 changes: 7 additions & 2 deletions js/parts/AreaSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var AreaSeries = extendClass(Series, {
plotY,
points = this.points,
connectNulls = this.options.connectNulls,
stackIndicator,
i,
x;

Expand Down Expand Up @@ -70,8 +71,12 @@ var AreaSeries = extendClass(Series, {

// Loop down the stack to find the series below this one that has
// a value (#1991)
for (i = series.index; i <= yAxis.series.length; i++) {
stackPoint = stack[x].points[i + ',' + x];
for (i = series.index; i <= yAxis.series.length; i++) {
stackIndicator = series.getStackIndicator({
x: null,
index: 0
}, x);
stackPoint = stack[x].points[i + ',' + x + ',' + stackIndicator.index];
if (stackPoint) {
y = stackPoint[1];
break;
Expand Down
8 changes: 6 additions & 2 deletions js/parts/Series.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@ Series.prototype = {
plotX,
plotY,
lastPlotX,
stackIndicator = {
x: null,
index: 0
},
closestPointRangePx = Number.MAX_VALUE;

// Translate each point
Expand All @@ -767,9 +771,9 @@ Series.prototype = {

// Calculate the bottom y value for stacked series
if (stacking && series.visible && stack && stack[xValue]) {

stackIndicator = series.getStackIndicator(stackIndicator, xValue);
pointStack = stack[xValue];
stackValues = pointStack.points[series.index + ',' + i];
stackValues = pointStack.points[series.index + ',' + xValue + ',' + stackIndicator.index];
yBottom = stackValues[0];
yValue = stackValues[1];

Expand Down
32 changes: 28 additions & 4 deletions js/parts/Stacking.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ Series.prototype.setStackedPoints = function () {
yAxis = series.yAxis,
stacks = yAxis.stacks,
oldStacks = yAxis.oldStacks,
stackIndicator = {
x: null,
index: 0
},
isNegative,
stack,
other,
Expand All @@ -268,8 +272,8 @@ Series.prototype.setStackedPoints = function () {
for (i = 0; i < yDataLength; i++) {
x = xData[i];
y = yData[i];
pointKey = series.index + ',' + i;

stackIndicator = series.getStackIndicator(stackIndicator, x);
pointKey = series.index + ',' + x + ',' + stackIndicator.index;
// Read stacked values into a stack based on the x value,
// the sign of y and the stack key. Stacking is also handled for null values (#739)
isNegative = negStacks && y < (stackThreshold ? 0 : threshold);
Expand Down Expand Up @@ -338,7 +342,11 @@ Series.prototype.setPercentStacks = function () {
var series = this,
stackKey = series.stackKey,
stacks = series.yAxis.stacks,
processedXData = series.processedXData;
processedXData = series.processedXData,
stackIndicator = {
x: null,
index: 0
};

each([stackKey, '-' + stackKey], function (key) {
var i = processedXData.length,
Expand All @@ -349,8 +357,9 @@ Series.prototype.setPercentStacks = function () {

while (i--) {
x = processedXData[i];
stackIndicator = series.getStackIndicator(stackIndicator, x);
stack = stacks[key] && stacks[key][x];
pointExtremes = stack && stack.points[series.index + ',' + i];
pointExtremes = stack && stack.points[series.index + ',' + x + ',' + stackIndicator.index];
if (pointExtremes) {
totalFactor = stack.total ? 100 / stack.total : 0;
pointExtremes[0] = correctFloat(pointExtremes[0] * totalFactor); // Y bottom value
Expand All @@ -361,3 +370,18 @@ Series.prototype.setPercentStacks = function () {
});
};

/**
* Get stack indicator, according to it's x-value, to determine points with the same x-value
*/
Series.prototype.getStackIndicator = function(stackIndicator, x) {
if (stackIndicator.x !== x) {
stackIndicator = {
x: x,
index: 0
};
} else {
stackIndicator.index++;
}
return stackIndicator;
};

0 comments on commit 8d8cbee

Please sign in to comment.