Fix: minOpen is true will drop a piece#12147
Fix: minOpen is true will drop a piece#12147100pah merged 2 commits intoapache:masterfrom susiwen8:#12121
Conversation
|
Thanks for your contribution! The pull request is marked to be |
|
In this way, the |
| if (thisOption.minOpen) { | ||
| pieceList.push({ | ||
| index: index++, | ||
| index: index, |
There was a problem hiding this comment.
Only remove ++ is not correct. Because after ++ removed, the first piece and the second piece has the same index.
That cause when click on the first piece, both the first piece and the second pieces are highlighted/downplayed.
There was a problem hiding this comment.
Also consider
(1) @pissang mentioned: when the split number is 5, the final pieces should better be 5.
(2) The potential bug that the piece.index forget to change after reformIntervals(pieceList) called.
I think the code to resolve this issue could be:
splitNumber: function () {
var thisOption = this.option;
var pieceList = this._pieceList;
var precision = Math.min(thisOption.precision, 20);
var dataExtent = this.getExtent();
var splitNumber = thisOption.splitNumber;
splitNumber = Math.max(parseInt(splitNumber, 10), 1);
thisOption.splitNumber = splitNumber;
+ var closedIntervalCount = splitNumber - (+thisOption.minOpen) - (+thisOption.maxOpen);
- var splitStep = (dataExtent[1] - dataExtent[0]) / splitNumber;
+ var splitStep = (dataExtent[1] - dataExtent[0]) / closedIntervalCount;
// Precision auto-adaption
while (+splitStep.toFixed(precision) !== splitStep && precision < 5) {
precision++;
}
thisOption.precision = precision;
splitStep = +splitStep.toFixed(precision);
- var index = 0;
if (thisOption.minOpen) {
pieceList.push({
- index++,
interval: [-Infinity, dataExtent[0]],
close: [0, 0]
});
}
for (
- var curr = dataExtent[0], len = index + splitNumber;
- index < len;
- curr += splitStep
+ var index = 0, curr = dataExtent[0];
+ index < closedIntervalCount;
+ curr += splitStep, index++
) {
var max = index === splitNumber - 1 ? dataExtent[1] : (curr + splitStep);
pieceList.push({
- index: index++,
interval: [curr, max],
close: [1, 1]
});
}
if (thisOption.maxOpen) {
pieceList.push({
- index: index++,
interval: [dataExtent[1], Infinity],
close: [0, 0]
});
}
reformIntervals(pieceList);
- zrUtil.each(pieceList, function (piece) {
+ zrUtil.each(pieceList, function (piece, index) {
+ piece.index = index;
piece.text = this.formatValueText(piece.interval);
}, this);
},|
Congratulations! Your PR has been merged. Thanks for your contribution! 👍 |
Brief Information
This pull request is in the type of:
What does this PR do?
When minOpen is true, index shouldn't increase to 1
Fixed issues
Close #12121
Details
Before: What was the problem?
After: How is it fixed in this PR?
Usage
Are there any API changes?
Related test cases or examples to use the new APIs
NA.
Others
Merging options
Other information