Skip to content

Commit

Permalink
fix(plugin-chart-echarts): tree graph tooltip polish (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenLYZ authored and zhaoyongjie committed Nov 26, 2021
1 parent 9227b1e commit 28003ad
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
*/
import { ChartProps, getMetricLabel, DataRecordValue } from '@superset-ui/core';
import { EChartsOption, TreeSeriesOption } from 'echarts';
import { TreeSeriesNodeItemOption } from 'echarts/types/src/chart/tree/TreeSeries';
import {
TreeSeriesCallbackDataParams,
TreeSeriesNodeItemOption,
} from 'echarts/types/src/chart/tree/TreeSeries';
import { OptionName } from 'echarts/types/src/util/types';
import {
EchartsTreeFormData,
Expand All @@ -28,6 +31,21 @@ import {
import { DEFAULT_TREE_SERIES_OPTION } from './constants';
import { EchartsProps } from '../types';

export function formatTooltip({
params,
metricLabel,
}: {
params: TreeSeriesCallbackDataParams;
metricLabel: string;
}): string {
const { value, treeAncestors } = params;
const treePath = (treeAncestors ?? [])
.map(pathInfo => pathInfo?.name || '')
.filter(path => path !== '');

return [`<div>${treePath.join(' ▸ ')}</div>`, value ? `${metricLabel}: ${value}` : ''].join('');
}

export default function transformProps(chartProps: ChartProps): EchartsProps {
const { width, height, formData, queriesData } = chartProps;
const data: TreeDataRecord[] = queriesData[0].data || [];
Expand Down Expand Up @@ -96,7 +114,7 @@ export default function transformProps(chartProps: ChartProps): EchartsProps {
// generate tree
for (let i = 0; i < data.length; i += 1) {
const node = data[i];
if (node[parent] === rootNodeId) {
if (node[parent]?.toString() === rootNodeId) {
tree.children?.push({
name: node[nameColumn],
children: children[i],
Expand Down Expand Up @@ -179,6 +197,11 @@ export default function transformProps(chartProps: ChartProps): EchartsProps {
tooltip: {
trigger: 'item',
triggerOn: 'mousemove',
formatter: (params: any) =>
formatTooltip({
params,
metricLabel,
}),
},
};

Expand Down

0 comments on commit 28003ad

Please sign in to comment.