Skip to content

Commit

Permalink
Fixed #6203, yAxis extremes were wrong calculated for visible scatter…
Browse files Browse the repository at this point in the history
… points
  • Loading branch information
sebastianbochan committed Mar 24, 2017
1 parent 142173e commit 1eace3d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion js/parts/Series.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ H.Series = H.seriesType('line', null, { // base series options
// visible range, consider y extremes
validValue = (isNumber(y, true) || isArray(y)) && (!yAxis.positiveValuesOnly || (y.length || y > 0));
withinRange = this.getExtremesFromAll || this.options.getExtremesFromAll || this.cropped ||
((xData[i + 1] || x) >= xMin && (xData[i - 1] || x) <= xMax);
((xData[i] || x) >= xMin && (xData[i] || x) <= xMax);

if (validValue && withinRange) {

Expand All @@ -886,6 +886,7 @@ H.Series = H.seriesType('line', null, { // base series options
}
}
}

this.dataMin = arrayMin(activeYData);
this.dataMax = arrayMax(activeYData);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
resources:
- https://code.jquery.com/qunit/qunit-2.0.1.js
- https://code.jquery.com/qunit/qunit-2.0.1.css
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script src="https://code.highcharts.com/stock/highstock.js"></script>

<div id="qunit"></div>
<div id="qunit-fixture"></div>

<div id="container" style="width: 600px; margin: 0 auto"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$(function () {
QUnit.test('yAxis extremes should adapt to visible points, not all.', function (assert) {
var chart = Highcharts.stockChart('container', {
series: [{
data: [1, 2, 3, 4, 5, 3, 2, 1, 2, 4, 5, 8, 6, 4, 2, 3, 4, 2, 3, 4, 5, 6, 3, 2, 1, 2, 3, 4, 5, 6, 7, 3]
}, {
type: "scatter",
data: [{
x: 4,
y: 200,
}, {
x: 10,
y: 2,
}],

}]
});

chart.xAxis[0].setExtremes(8, 10);

assert.deepEqual(
chart.yAxis[0].max,
10,
'yAxis extremes adapted to visible scatter points.'
);
});
});

2 comments on commit 1eace3d

@sebastianbochan
Copy link
Contributor Author

@sebastianbochan sebastianbochan commented on 1eace3d Mar 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I aware of failing 334 test, but looks like correct.

@TorsteinHonsi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That code snippet was written to include the point immediately outside the visible range to the left and right when finding Y extremes, but I am not sure if it's necessary. If this is the only failing test it is probably safe to merge it.

Please sign in to comment.