From 8f7773c4fd2c99bf66cea2514a96e738338f745d Mon Sep 17 00:00:00 2001 From: plainheart Date: Sat, 23 Nov 2024 09:55:29 +0800 Subject: [PATCH 1/2] feat(axis): support tooltip for axis label --- package-lock.json | 11 +++--- package.json | 2 +- src/component/axis/AxisBuilder.ts | 13 ++++++- test/axisLabel.html | 63 +++++++++++++++++++++++++++++-- 4 files changed, 78 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index ae4cddd643..769753fce5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "tslib": "2.3.0", - "zrender": "5.6.0" + "zrender": "github:ecomfe/zrender" }, "devDependencies": { "@babel/code-frame": "7.10.4", @@ -11298,8 +11298,8 @@ }, "node_modules/zrender": { "version": "5.6.0", - "resolved": "https://registry.npmjs.org/zrender/-/zrender-5.6.0.tgz", - "integrity": "sha512-uzgraf4njmmHAbEUxMJ8Oxg+P3fT04O+9p7gY+wJRVxo8Ge+KmYv0WJev945EH4wFuc4OY2NLXz46FZrWS9xJg==", + "resolved": "git+ssh://git@github.com/ecomfe/zrender.git#980b0ea43e68da10f82aa9a18449357e8c40bba0", + "license": "BSD-3-Clause", "dependencies": { "tslib": "2.3.0" } @@ -20322,9 +20322,8 @@ } }, "zrender": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/zrender/-/zrender-5.6.0.tgz", - "integrity": "sha512-uzgraf4njmmHAbEUxMJ8Oxg+P3fT04O+9p7gY+wJRVxo8Ge+KmYv0WJev945EH4wFuc4OY2NLXz46FZrWS9xJg==", + "version": "git+ssh://git@github.com/ecomfe/zrender.git#980b0ea43e68da10f82aa9a18449357e8c40bba0", + "from": "zrender@github:ecomfe/zrender", "requires": { "tslib": "2.3.0" } diff --git a/package.json b/package.json index 3f0d0a3428..f556f8f468 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ }, "dependencies": { "tslib": "2.3.0", - "zrender": "5.6.0" + "zrender": "github:ecomfe/zrender" }, "devDependencies": { "@babel/code-frame": "7.10.4", diff --git a/src/component/axis/AxisBuilder.ts b/src/component/axis/AxisBuilder.ts index 1644d50246..b139a27fdb 100644 --- a/src/component/axis/AxisBuilder.ts +++ b/src/component/axis/AxisBuilder.ts @@ -32,8 +32,9 @@ import {shouldShowAllLabels} from '../../coord/axisHelper'; import { AxisBaseModel } from '../../coord/AxisBaseModel'; import { ZRTextVerticalAlign, ZRTextAlign, ECElement, ColorString } from '../../util/types'; import { AxisBaseOption } from '../../coord/axisCommonTypes'; -import Element from 'zrender/src/Element'; +import type Element from 'zrender/src/Element'; import { PathStyleProps } from 'zrender/src/graphic/Path'; +import type TSpan from 'zrender/src/graphic/TSpan'; import OrdinalScale from '../../scale/Ordinal'; import { prepareLayoutList, hideOverlap } from '../../label/labelLayoutHelper'; @@ -836,6 +837,16 @@ function buildAxisLabel( }); textEl.anid = 'label_' + tickValue; + graphic.setTooltipConfig({ + el: textEl, + componentModel: axisModel, + itemName: formattedLabel, + formatterParamsExtra: { + isTruncated: () => textEl.isTruncated, + value: rawLabel, + tickIndex: index + } + }); // Pack data for mouse event if (triggerEvent) { diff --git a/test/axisLabel.html b/test/axisLabel.html index a3c5b97971..572abcffcc 100644 --- a/test/axisLabel.html +++ b/test/axisLabel.html @@ -44,7 +44,7 @@
- +
+ - \ No newline at end of file + From 15a8f644b93220a4652405a3ee4bef36a0e0b41d Mon Sep 17 00:00:00 2001 From: plainheart Date: Sat, 23 Nov 2024 10:05:36 +0800 Subject: [PATCH 2/2] fix(axis): remove unused import --- src/component/axis/AxisBuilder.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/component/axis/AxisBuilder.ts b/src/component/axis/AxisBuilder.ts index b139a27fdb..406b3eecab 100644 --- a/src/component/axis/AxisBuilder.ts +++ b/src/component/axis/AxisBuilder.ts @@ -34,7 +34,6 @@ import { ZRTextVerticalAlign, ZRTextAlign, ECElement, ColorString } from '../../ import { AxisBaseOption } from '../../coord/axisCommonTypes'; import type Element from 'zrender/src/Element'; import { PathStyleProps } from 'zrender/src/graphic/Path'; -import type TSpan from 'zrender/src/graphic/TSpan'; import OrdinalScale from '../../scale/Ordinal'; import { prepareLayoutList, hideOverlap } from '../../label/labelLayoutHelper';