Skip to content

Commit

Permalink
Addition to #5234, filter the array only if necessary.
Browse files Browse the repository at this point in the history
We don't want to run the expensive filter operation unless the array actually contains invalid items.
  • Loading branch information
TorsteinHonsi committed May 4, 2016
1 parent f42f8b6 commit a689771
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
14 changes: 10 additions & 4 deletions js/highcharts.src.js
Expand Up @@ -2,7 +2,7 @@
// @compilation_level SIMPLE_OPTIMIZATIONS

/**
* @license Highcharts JS v4.2.4-modified (2016-05-03)
* @license Highcharts JS v4.2.4-modified (2016-05-04)
*
* (c) 2009-2016 Torstein Honsi
*
Expand Down Expand Up @@ -7356,14 +7356,20 @@
if (axis.isXAxis) {
xData = series.xData;
if (xData.length) {
// If xData contains values which is not numbers, then filter them out
if (!isNumber(xData)) {
// If xData contains values which is not numbers, then filter them out.
// To prevent performance hit, we only do this after we have already
// found seriesDataMin because in most cases all data is valid. #5234.
seriesDataMin = arrayMin(xData);
if (!isNumber(seriesDataMin)) {
xData = grep(xData, function (x) {
return isNumber(x);
});
seriesDataMin = arrayMin(xData); // Do it again with valid data
}
axis.dataMin = mathMin(pick(axis.dataMin, xData[0]), arrayMin(xData));

axis.dataMin = mathMin(pick(axis.dataMin, xData[0]), seriesDataMin);
axis.dataMax = mathMax(pick(axis.dataMax, xData[0]), arrayMax(xData));

}

// Get dataMin and dataMax for Y axes, as well as handle stacking and processed data
Expand Down
14 changes: 10 additions & 4 deletions js/highmaps.src.js
@@ -1,5 +1,5 @@
/**
* @license Highmaps JS v4.2.4-modified (2016-05-03)
* @license Highmaps JS v4.2.4-modified (2016-05-04)
*
* (c) 2011-2016 Torstein Honsi
*
Expand Down Expand Up @@ -7082,14 +7082,20 @@
if (axis.isXAxis) {
xData = series.xData;
if (xData.length) {
// If xData contains values which is not numbers, then filter them out
if (!isNumber(xData)) {
// If xData contains values which is not numbers, then filter them out.
// To prevent performance hit, we only do this after we have already
// found seriesDataMin because in most cases all data is valid. #5234.
seriesDataMin = arrayMin(xData);
if (!isNumber(seriesDataMin)) {
xData = grep(xData, function (x) {
return isNumber(x);
});
seriesDataMin = arrayMin(xData); // Do it again with valid data
}
axis.dataMin = mathMin(pick(axis.dataMin, xData[0]), arrayMin(xData));

axis.dataMin = mathMin(pick(axis.dataMin, xData[0]), seriesDataMin);
axis.dataMax = mathMax(pick(axis.dataMax, xData[0]), arrayMax(xData));

}

// Get dataMin and dataMax for Y axes, as well as handle stacking and processed data
Expand Down
12 changes: 9 additions & 3 deletions js/highstock.src.js
Expand Up @@ -7356,14 +7356,20 @@
if (axis.isXAxis) {
xData = series.xData;
if (xData.length) {
// If xData contains values which is not numbers, then filter them out
if (!isNumber(xData)) {
// If xData contains values which is not numbers, then filter them out.
// To prevent performance hit, we only do this after we have already
// found seriesDataMin because in most cases all data is valid. #5234.
seriesDataMin = arrayMin(xData);
if (!isNumber(seriesDataMin)) {
xData = grep(xData, function (x) {
return isNumber(x);
});
seriesDataMin = arrayMin(xData); // Do it again with valid data
}
axis.dataMin = mathMin(pick(axis.dataMin, xData[0]), arrayMin(xData));

axis.dataMin = mathMin(pick(axis.dataMin, xData[0]), seriesDataMin);
axis.dataMax = mathMax(pick(axis.dataMax, xData[0]), arrayMax(xData));

}

// Get dataMin and dataMax for Y axes, as well as handle stacking and processed data
Expand Down
12 changes: 9 additions & 3 deletions js/parts/Axis.js
Expand Up @@ -458,14 +458,20 @@ Axis.prototype = {
if (axis.isXAxis) {
xData = series.xData;
if (xData.length) {
// If xData contains values which is not numbers, then filter them out
if (!isNumber(xData)) {
// If xData contains values which is not numbers, then filter them out.
// To prevent performance hit, we only do this after we have already
// found seriesDataMin because in most cases all data is valid. #5234.
seriesDataMin = arrayMin(xData);
if (!isNumber(seriesDataMin)) {
xData = grep(xData, function (x) {
return isNumber(x);
});
seriesDataMin = arrayMin(xData); // Do it again with valid data
}
axis.dataMin = mathMin(pick(axis.dataMin, xData[0]), arrayMin(xData));

axis.dataMin = mathMin(pick(axis.dataMin, xData[0]), seriesDataMin);
axis.dataMax = mathMax(pick(axis.dataMax, xData[0]), arrayMax(xData));

}

// Get dataMin and dataMax for Y axes, as well as handle stacking and processed data
Expand Down

0 comments on commit a689771

Please sign in to comment.