Skip to content

Commit

Permalink
Merge pull request #14972 from apache/fix/legend-tooltip-inherit
Browse files Browse the repository at this point in the history
fix: When component `tooltip.formatter` is not specified, use a specific default formatter, rather than use global `tooltip.formatter` as default. Fix #14939
  • Loading branch information
pissang committed May 18, 2021
2 parents 35a15f8 + 50a91c4 commit e112417
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/component/legend/LegendView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ class LegendView extends ComponentView {
invisible: true
});

const tooltipModel = legendItemModel.getModel('tooltip') as Model<CommonTooltipOption<LegendTooltipFormatterParams>>;
const tooltipModel =
legendItemModel.getModel('tooltip') as Model<CommonTooltipOption<LegendTooltipFormatterParams>>;
if (tooltipModel.get('show')) {
graphic.setTooltipConfig({
el: hitRect,
Expand Down
7 changes: 6 additions & 1 deletion src/component/tooltip/TooltipView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ class TooltipView extends ComponentView {
) {
const ecData = getECData(el);
const tooltipConfig = ecData.tooltipConfig;
let tooltipOpt = tooltipConfig.option;
let tooltipOpt = tooltipConfig.option || {};
if (zrUtil.isString(tooltipOpt)) {
const content = tooltipOpt;
tooltipOpt = {
Expand All @@ -722,6 +722,11 @@ class TooltipView extends ComponentView {
if (cmpt) {
tooltipModelCascade.push(cmpt as Model<TooltipableOption>);
}
// In most cases, component tooltip formatter has different params with series tooltip formatter,
// so that they can not share the same formatter. Since the global tooltip formatter is used for series
// by convension, we do not use it as the default formatter for component.
tooltipModelCascade.push({ formatter: tooltipOpt.content });

const positionDefault = e.positionDefault;
const subTooltipModel = buildTooltipModel(
tooltipModelCascade,
Expand Down
2 changes: 1 addition & 1 deletion test/runTest/actions/__meta__.json

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

2 changes: 1 addition & 1 deletion test/runTest/actions/tooltip-component.json

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions test/tooltip-component.html

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

0 comments on commit e112417

Please sign in to comment.