Skip to content

Commit

Permalink
Fix #7955 (do not filter empty data item in data zoom, which makes li…
Browse files Browse the repository at this point in the history
…ne chart keeping broken)
  • Loading branch information
100pah committed Mar 21, 2018
1 parent de58767 commit d4d848f
Show file tree
Hide file tree
Showing 2 changed files with 255 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/data/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,15 +1267,13 @@ listProto.filterSelf = function (dimensions, cb, context, contextCompat) {
* Select data in range. (For optimization of filter)
* (Manually inline code, support 5 million data filtering in data zoom.)
*/
listProto.selectRange = function (range /*, stack */) {
listProto.selectRange = function (range) {
'use strict';

if (!this._count) {
return;
}

// stack = stack || false;

var dimensions = [];
for (var dim in range) {
if (range.hasOwnProperty(dim)) {
Expand Down Expand Up @@ -1303,7 +1301,7 @@ listProto.selectRange = function (range /*, stack */) {
var max = range[dim0][1];

var quickFinished = false;
if (!this._indices /* && !stack */) {
if (!this._indices) {
// Extreme optimization for common case. About 2x faster in chrome.
var idx = 0;
if (dimSize === 1) {
Expand All @@ -1313,7 +1311,14 @@ listProto.selectRange = function (range /*, stack */) {
var len = Math.min(this._count - k * this._chunkSize, this._chunkSize);
for (var i = 0; i < len; i++) {
var val = chunkStorage[i];
if (val >= min && val <= max) {
// NaN will not be filtered. Consider the case, in line chart, empty
// value indicates the line should be broken. But for the case like
// scatter plot, a data item with empty value will not be rendered,
// but the axis extent may be effected if some other dim of the data
// item has value. Fortunately it is not a significant negative effect.
if (
(val >= min && val <= max) || isNaN(val)
) {
newIndices[offset++] = idx;
}
idx++;
Expand All @@ -1333,7 +1338,14 @@ listProto.selectRange = function (range /*, stack */) {
for (var i = 0; i < len; i++) {
var val = chunkStorage[i];
var val2 = chunkStorage2[i];
if (val >= min && val <= max && val2 >= min2 && val2 <= max2) {
// Do not filter NaN, see comment above.
if ((
(val >= min && val <= max) || isNaN(val)
)
&& (
(val2 >= min2 && val2 <= max2) || isNaN(val2)
)
) {
newIndices[offset++] = idx;
}
idx++;
Expand All @@ -1344,12 +1356,13 @@ listProto.selectRange = function (range /*, stack */) {
}
if (!quickFinished) {
if (dimSize === 1) {
// stack = stack || !!this.getCalculationInfo(dim0);
for (var i = 0; i < originalCount; i++) {
var rawIndex = this.getRawIndex(i);
// var val = stack ? this.get(dim0, i, true) : this._getFast(dim0, rawIndex);
var val = this._getFast(dim0, rawIndex);
if (val >= min && val <= max) {
// Do not filter NaN, see comment above.
if (
(val >= min && val <= max) || isNaN(val)
) {
newIndices[offset++] = rawIndex;
}
}
Expand All @@ -1360,8 +1373,8 @@ listProto.selectRange = function (range /*, stack */) {
var rawIndex = this.getRawIndex(i);
for (var k = 0; k < dimSize; k++) {
var dimk = dimensions[k];
// var val = stack ? this.get(dimk, i, true) : this._getFast(dim, rawIndex);
var val = this._getFast(dim, rawIndex);
// Do not filter NaN, see comment above.
if (val < range[dimk][0] || val > range[dimk][1]) {
keep = false;
}
Expand Down
232 changes: 232 additions & 0 deletions test/dataZoom-extreme.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="lib/esl.js"></script>
<script src="lib/config.js"></script>
<script src="lib/jquery.min.js"></script>
<script src="lib/facePrint.js"></script>
<script src="lib/testHelper.js"></script>
<link rel="stylesheet" href="lib/reset.css" />
</head>
<body>
<style>
.test-title {
background: #146402;
color: #fff;
}
</style>


<div id="main0"></div>
<div id="main1"></div>
<div id="main2"></div>


<script>

var chart;
var myChart;
var option;

require([
'echarts'/*, 'map/js/china' */
], function (echarts) {

// Thanks to <https://github.com/vision57>
// See <https://github.com/ecomfe/echarts/issues/7666>

function createParams() {
var notMerge = true;
var option = {
dataZoom: [{
type: 'inside'
}, {
type: 'slider'
}],
xAxis: {
type: 'time'
},
yAxis: {
type: 'value'
},
series: []
};
return {
title: 'series empty, should no exception.',
notMerge: notMerge,
option: option,
info: option
};
}

chart = myChart = testHelper.create(echarts, 'main0', createParams());
// Set option again with notMerge mode.
chart.setOption(createParams().option, true);
});

</script>










<script>

// See https://github.com/ecomfe/echarts/issues/7955
// Thanks to https://github.com/cbtpro

require([
'echarts',
'extension/bmap'
], function (echarts) {
var option = {
tooltip: {
trigger: 'axis'
},
legend: {
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
name:'Step Start',
type:'line',
step: 'start',
data:[120, 132, null, 134, 90, 230, 210]
},
{
name:'Step Middle',
type:'line',
step: 'middle',
data:[220, 282, 201, 234, null, 430, 410]
}
]
}

var chart = testHelper.create(echarts, 'main1', {
title: 'When toolbox.dataZoom enabled, line should keep broken.',
option: option,
button: {
text: 'Click enable toolbox.dataZoom',
onClick: function () {
chart.setOption({
toolbox: {
feature: {
dataZoom: {}
}
},
// xAxis: {
// type: 'category',
// data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
// },
// yAxis: {
// type: 'value'
// },
// series: [
// {
// name:'Step Start',
// type:'line',
// step: 'start',
// data:[120, 132, null, 134, 90, 230, 210]
// },
// {
// name:'Step Middle',
// type:'line',
// step: 'middle',
// data:[220, 282, 201, 234, null, 430, 410]
// },
// {
// name:'Step End',
// type:'line',
// step: 'end',
// data:[450, 432, 401, 454, 590, null, 510]
// }
// ]
});
}
}
});

});
</script>




<script>

require([
'echarts',
'extension/bmap'
], function (echarts) {

var option = {
tooltip: {
trigger: 'axis'
},
legend: {
},
xAxis: {
},
yAxis: {
},
series: [
{
name:'Step Start',
type:'line',
data:[[12, 120], [23, 132], null, [19, 134], [45, 90]]
},
{
name:'Step Middle',
type:'line',
data:[[42, 120], [53, 132], [null, 55], [49, 134], [15, 90]]
}
]
}

var chart = testHelper.create(echarts, 'main2', {
title: 'Add dataZoom, and zoom data, line should keep broken',
option: option,
button: {
text: 'Click to add dataZoom',
onClick: function () {
chart.setOption({
dataZoom: [{
}, {
type: 'inside'
}]
})
}
}
});
});

</script>









</body>
</html>

0 comments on commit d4d848f

Please sign in to comment.