Skip to content

Commit

Permalink
feat(axis): support tooltip for axis label
Browse files Browse the repository at this point in the history
  • Loading branch information
plainheart committed Nov 23, 2024
1 parent 2576fc2 commit 8f7773c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 11 deletions.
11 changes: 5 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"dependencies": {
"tslib": "2.3.0",
"zrender": "5.6.0"
"zrender": "github:ecomfe/zrender"
},
"devDependencies": {
"@babel/code-frame": "7.10.4",
Expand Down
13 changes: 12 additions & 1 deletion src/component/axis/AxisBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check warning on line 37 in src/component/axis/AxisBuilder.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

'TSpan' is defined but never used
import OrdinalScale from '../../scale/Ordinal';
import { prepareLayoutList, hideOverlap } from '../../label/labelLayoutHelper';

Expand Down Expand Up @@ -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) {
Expand Down
63 changes: 60 additions & 3 deletions test/axisLabel.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8f7773c

Please sign in to comment.