Skip to content

Commit

Permalink
feat(tree): add tree path info to tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenLYZ committed May 16, 2021
1 parent 202bfcc commit 7cebeff
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/chart/tree/TreeSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import View from '../../coord/View';
import { LayoutRect } from '../../util/layout';
import Model from '../../model/Model';
import { createTooltipMarkup } from '../../component/tooltip/tooltipMarkup';
import { wrapTreePathInfo } from '../helper/treeHelper';

interface CurveLineStyleOption extends LineStyleOption{
curveness?: number
Expand Down Expand Up @@ -112,6 +113,16 @@ export interface TreeSeriesOption extends
data?: TreeSeriesNodeItemOption[]
}

interface TreePathInfo {
name: string
dataIndex: number
value: number
}

interface TreeSeriesCallbackDataParams extends CallbackDataParams {
treePathInfo?: TreePathInfo[]
}

class TreeSeriesModel extends SeriesModel<TreeSeriesOption> {
static readonly type = 'series.tree';

Expand Down Expand Up @@ -224,6 +235,16 @@ class TreeSeriesModel extends SeriesModel<TreeSeriesOption> {
});
}

// Add tree path to tooltip param
getDataParams(dataIndex: number) {
const params = super.getDataParams.apply(this, arguments as any) as TreeSeriesCallbackDataParams;

const node = this.getData().tree.getNodeByDataIndex(dataIndex);
params.treePathInfo = wrapTreePathInfo(node, this);

return params;
}

static defaultOption: TreeSeriesOption = {
zlevel: 0,
z: 2,
Expand Down
19 changes: 18 additions & 1 deletion test/tree-basic.html

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

0 comments on commit 7cebeff

Please sign in to comment.