From 438f403704d39daa1725dccfe92280dd0587ce58 Mon Sep 17 00:00:00 2001 From: 100pah Date: Mon, 15 Mar 2021 20:27:44 +0800 Subject: [PATCH] fix: [tooltip] keep support tooltip on graphic component. --- src/component/graphic/install.ts | 28 ++++++- src/component/tooltip/TooltipView.ts | 6 +- test/runTest/actions/__meta__.json | 2 +- test/tooltip-component.html | 115 +++++++++++++++++++++++++++ 4 files changed, 146 insertions(+), 5 deletions(-) diff --git a/src/component/graphic/install.ts b/src/component/graphic/install.ts index b51bb6799..9d952e0e9 100644 --- a/src/component/graphic/install.ts +++ b/src/component/graphic/install.ts @@ -30,7 +30,8 @@ import { Dictionary, ZRStyleProps, OptionId, - OptionPreprocessor + OptionPreprocessor, + CommonTooltipOption } from '../../util/types'; import ComponentModel from '../../model/Component'; import Element, { ElementTextConfig } from 'zrender/src/Element'; @@ -44,6 +45,7 @@ import { getECData } from '../../util/innerStore'; import { TextStyleProps } from 'zrender/src/graphic/Text'; import { isEC4CompatibleStyle, convertFromEC4CompatibleStyle } from '../../util/styleCompat'; import { EChartsExtensionInstallRegisters } from '../../extension'; +import { graphic } from '../../export/api'; const TRANSFORM_PROPS = { x: 1, @@ -129,6 +131,8 @@ interface GraphicComponentBaseElementOption extends textConfig?: ElementTextConfig; $action?: 'merge' | 'replace' | 'remove'; + + tooltip?: CommonTooltipOption; }; interface GraphicComponentDisplayableOption extends GraphicComponentBaseElementOption, @@ -461,7 +465,8 @@ class GraphicComponentView extends ComponentView { if (elOptionStyle && isEC4CompatibleStyle(elOptionStyle, elType, !!textConfig, !!textContentOption) ) { - const convertResult = convertFromEC4CompatibleStyle(elOptionStyle, elType, true) as GraphicComponentZRPathOption; + const convertResult = + convertFromEC4CompatibleStyle(elOptionStyle, elType, true) as GraphicComponentZRPathOption; if (!textConfig && convertResult.textConfig) { textConfig = (elOption as GraphicComponentZRPathOption).textConfig = convertResult.textConfig; } @@ -514,6 +519,25 @@ class GraphicComponentView extends ComponentView { elInner.__ecGraphicWidthOption = (elOption as GraphicComponentGroupOption).width; elInner.__ecGraphicHeightOption = (elOption as GraphicComponentGroupOption).height; setEventData(el, graphicModel, elOption); + + const tooltipOption = elOption.tooltip; + const componentIndex = graphicModel.componentIndex; + getECData(el).tooltipConfig = tooltipOption + ? { + componentMainType: graphicModel.mainType, + componentIndex: componentIndex, + name: el.name, + option: zrUtil.defaults({ + content: el.name, + formatterParams: { + componentType: 'graphic', + graphicIndex: componentIndex, + name: el.name, + $vars: ['name'] + } + }, tooltipOption) + } + : null; } }); } diff --git a/src/component/tooltip/TooltipView.ts b/src/component/tooltip/TooltipView.ts index 0efd6bdae..06d90dcd0 100644 --- a/src/component/tooltip/TooltipView.ts +++ b/src/component/tooltip/TooltipView.ts @@ -723,9 +723,11 @@ class TooltipView extends ComponentView { // that requires setting `trigger` nothing on component yet. this._showOrMove(subTooltipModel, function (this: TooltipView) { + // Use formatterParams from element defined in component + // Avoid users modify it. + const formatterParams = zrUtil.clone(subTooltipModel.get('formatterParams') as any || {}); this._showTooltipContent( - // Use formatterParams from element defined in component - subTooltipModel, defaultHtml, subTooltipModel.get('formatterParams') as any || {}, + subTooltipModel, defaultHtml, formatterParams, asyncTicket, e.offsetX, e.offsetY, e.position, el, markupStyleCreator ); }); diff --git a/test/runTest/actions/__meta__.json b/test/runTest/actions/__meta__.json index e5509b45a..e8fa80b30 100644 --- a/test/runTest/actions/__meta__.json +++ b/test/runTest/actions/__meta__.json @@ -151,7 +151,7 @@ "tooltip-axisPointer": 20, "tooltip-axisPointer2": 1, "tooltip-cascade": 4, - "tooltip-component": 3, + "tooltip-component": 4, "tooltip-event": 1, "tooltip-link": 2, "tooltip-rich": 1, diff --git a/test/tooltip-component.html b/test/tooltip-component.html index 53e647229..4ad17ca2b 100644 --- a/test/tooltip-component.html +++ b/test/tooltip-component.html @@ -39,6 +39,7 @@ under the License.
+
@@ -251,6 +252,120 @@ under the License. + + + -- GitLab