You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2020/07/29 07:25:53 UTC

[GitHub] [incubator-echarts] pissang commented on a change in pull request #12947: New tooltip design

pissang commented on a change in pull request #12947:
URL: https://github.com/apache/incubator-echarts/pull/12947#discussion_r461431291



##########
File path: src/component/tooltip/TooltipView.ts
##########
@@ -752,12 +810,46 @@ class TooltipView extends ComponentView {
             html = formatter(params, asyncTicket, callback);
         }
 
-        tooltipContent.setContent(html, markers, tooltipModel);
-        tooltipContent.show(tooltipModel);
-
+        tooltipContent.setContent(html, markers, tooltipModel, nearPoint.color, positionExpr);
+        tooltipContent.show(tooltipModel, nearPoint.color);
         this._updatePosition(
             tooltipModel, positionExpr, x, y, tooltipContent, params, el
         );
+
+    }
+
+    _getNearestPoint(
+        point: number[],
+        tooltipDataParams: TooltipDataParams | TooltipDataParams[]
+    ): {
+        color: ZRColor;
+    } {
+        if (!zrUtil.isArray(tooltipDataParams)) {
+            if (!tooltipDataParams.position) {
+                return {
+                    color: tooltipDataParams.color || tooltipDataParams.borderColor
+                };
+            }
+            return {
+                color: tooltipDataParams.color || tooltipDataParams.borderColor
+            };
+        }
+
+        const distanceArr = tooltipDataParams.map(params => {
+            let dim = '';

Review comment:
       Use `zrUtil.map` instead of native map

##########
File path: src/component/tooltip/TooltipView.ts
##########
@@ -985,7 +1077,8 @@ function calcTooltipPosition(
 ): [number, number] {
     const domWidth = contentSize[0];
     const domHeight = contentSize[1];
-    const gap = 5;
+    const gap = 10;
+    const offset = 5;
     let x = 0;

Review comment:
       I can't get the difference between offset and gap

##########
File path: src/component/tooltip/TooltipView.ts
##########
@@ -752,12 +810,46 @@ class TooltipView extends ComponentView {
             html = formatter(params, asyncTicket, callback);
         }
 
-        tooltipContent.setContent(html, markers, tooltipModel);
-        tooltipContent.show(tooltipModel);
-
+        tooltipContent.setContent(html, markers, tooltipModel, nearPoint.color, positionExpr);
+        tooltipContent.show(tooltipModel, nearPoint.color);
         this._updatePosition(
             tooltipModel, positionExpr, x, y, tooltipContent, params, el
         );
+
+    }
+
+    _getNearestPoint(
+        point: number[],
+        tooltipDataParams: TooltipDataParams | TooltipDataParams[]
+    ): {
+        color: ZRColor;
+    } {
+        if (!zrUtil.isArray(tooltipDataParams)) {
+            if (!tooltipDataParams.position) {
+                return {
+                    color: tooltipDataParams.color || tooltipDataParams.borderColor
+                };
+            }
+            return {
+                color: tooltipDataParams.color || tooltipDataParams.borderColor
+            };
+        }
+
+        const distanceArr = tooltipDataParams.map(params => {
+            let dim = '';
+            if (params.coordinateSystem && params.coordinateSystem.type === 'cartesian2d') {
+                dim = params.coordinateSystem.getBaseAxis().dim;
+            }
+            const posIndex = +(dim === 'x');
+            const distance = Math.abs(params.position[posIndex] - point[posIndex]);
+            delete params.position;
+            delete params.coordinateSystem;
+            return distance;
+        });
+        const index = distanceArr.indexOf(Math.min(...distanceArr));
+        return {

Review comment:
       Use `zrUtil.indexOf` instead of native indexOf. 
   
   

##########
File path: src/component/marker/markerHelper.ts
##########
@@ -81,9 +81,9 @@ function markerTypeCalculatorWithExtent(
         ? data.getCalculationInfo('stackResultDimension')
         : targetDataDim;
 
-    const value = numCalculate(data, calcDataDim, markerType);
+    const value = numCalculate(data, targetDataDim, markerType);

Review comment:
       It's better to put it in a separate PR and have further discussion about this change.




----------------------------------------------------------------
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:
users@infra.apache.org



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