100pah commented on a change in pull request #11973: fix bug #11528 Modify 
default value of tooltip and label
URL: 
https://github.com/apache/incubator-echarts/pull/11973#discussion_r363364428
 
 

 ##########
 File path: src/chart/helper/labelHelper.js
 ##########
 @@ -25,7 +25,8 @@ import {retrieveRawValue} from 
'../../data/helper/dataProvider';
  * @return {string} label string. Not null/undefined
  */
 export function getDefaultLabel(data, dataIndex) {
-    var labelDims = data.mapDimension('defaultedLabel', true);
+    var dataDimsLen = data.dimensions.length;
+    var labelDims = data.mapDimension(dataDimsLen > 2 ? 
data.dimensions[dataDimsLen - 1] : 'defaultedLabel', true);
 
 Review comment:
   @pissang 
   > So can we solve it by using the dimension that has not been encoded yet?
   
   I am not understand what it means yet. Could you tell me more?
   
   > It seems currently we use the same encoding strategy on them.
   
   The attribute `encode` and the encode strategy is introduced to echarts 
earlier than `dataset`. It originally to enable users specify any columns to 
map x/y/labels/tooltips, rather than have to travel and exchange the order of 
the columns of the raw data. That especially helps the scenario that users need 
different types of mappings in a single case.
   
   I think the concept and behavior of the attribute `encode` should better be 
consistent either using `series.data` or `dataset`. Otherwise it may bring 
confuse and more learning cost to users.
   
   But for the "default strategy when no encode" I think probably we need to 
trade it differently for `series.data` and `dataset` if necessary.
   
   @yufeng04 @pissang 
   I think the fix could be:
   (1) Add `isFromDataset` method to `List` class:
   ```js
   + listProto.isFromDataset = function () {
   +     var provider = this._rawData;
   +     // There might be no `getSource` in some legacy provider input from 
upper application.
   +     return provider.getSource && provider.getSource().fromDataset;
   + };
   ```
   (2) Modify the logic about "defaultedLabel" in `summarizeDimensions` of 
`dimensionHelper.js`:
   ```js
   
   export function summarizeDimensions(data) {
       var summary = {};
       var encode = summary.encode = {};
       var notExtraCoordDimMap = createHashMap();
       var defaultedLabel = [];
       var defaultedTooltip = [];
   
       // See the comment of `List.js#userOutput`.
       var userOutput = summary.userOutput = {
           dimensionNames: data.dimensions.slice(),
           encode: {}
       };
   
   +   var fromDataSet = this.isFromDataSet();
   +   var defaultedLabelDimNonDataset;
   
       each(data.dimensions, function (dimName) {
           var dimItem = data.getDimensionInfo(dimName);
   
           var coordDim = dimItem.coordDim;
           if (coordDim) {
               if (__DEV__) {
                   assert(OTHER_DIMENSIONS.get(coordDim) == null);
               }
   
               var coordDimIndex = dimItem.coordDimIndex;
               getOrCreateEncodeArr(encode, coordDim)[coordDimIndex] = dimName;
   
               if (!dimItem.isExtraCoord) {
                   notExtraCoordDimMap.set(coordDim, 1);
   
                   // Use the last coord dim (and label friendly) as default 
label,
                   // because when dataset is used, it is hard to guess which 
dimension
                   // can be value dimension. If both show x, y on label is not 
look good,
                   // and conventionally y axis is focused more.
   -               if (mayLabelDimType(dimItem.type)) {
   +               if (fromDataset && mayLabelDimType(dimItem.type)) {
                       defaultedLabel[0] = dimName;
                   }
   
                   // User output encode do not contain generated coords.
                   // And it only has index. User can use index to retrieve 
value from the raw item array.
                   getOrCreateEncodeArr(userOutput.encode, 
coordDim)[coordDimIndex] = dimItem.index;
               }
               if (dimItem.defaultTooltip) {
                   defaultedTooltip.push(dimName);
               }
           }
   
   +       // For data specified on `series` directly, we use different strategy
   +       // to guess defualt label from data specified on `dataset`. That is,
   +       // Find the last possible dimension. For example, consider the case
   +       // [[latitude, longitude, val], ...], the `val` would be the best 
choise.
   +       if (!fromDataSet && !dimItem.isExtraCoord) {
   +           defaultedLabelDimNonDataset = dimName;
   +       }
   
           OTHER_DIMENSIONS.each(function (v, otherDim) {
               var encodeArr = getOrCreateEncodeArr(encode, otherDim);
   
               var dimIndex = dimItem.otherDims[otherDim];
               if (dimIndex != null && dimIndex !== false) {
                   encodeArr[dimIndex] = dimItem.name;
               }
           });
       });
   
   +   if (defaultedLabelDimNonDataset != null)
   +       defaultedLabel[0] = defaultedLabelDimNonDataset;
   +   }
   ```
   
   
   
   
   
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to