100pah commented on a change in pull request #12147: Fix: minOpen is true will 
drop a piece
URL: 
https://github.com/apache/incubator-echarts/pull/12147#discussion_r379893617
 
 

 ##########
 File path: src/component/visualMap/PiecewiseModel.js
 ##########
 @@ -402,7 +402,7 @@ var resetMethods = {
 
         if (thisOption.minOpen) {
             pieceList.push({
-                index: index++,
+                index: index,
 
 Review 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:
   
   ```js
       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);
       },
   
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org
For additional commands, e-mail: commits-h...@echarts.apache.org

Reply via email to