MCPcopy
hub / github.com/apache/echarts / defaultSeriesFormatTooltip

Function defaultSeriesFormatTooltip

src/component/tooltip/seriesFormatTooltip.ts:33–101  ·  view source on GitHub ↗
(opt: {
    series: SeriesModel;
    dataIndex: number;
    // `multipleSeries` means multiple series displayed in one tooltip,
    // and this method only return the part of one series.
    multipleSeries: boolean;
})

Source from the content-addressed store, hash-verified

31
32
33export function defaultSeriesFormatTooltip(opt: {
34 series: SeriesModel;
35 dataIndex: number;
36 // `multipleSeries` means multiple series displayed in one tooltip,
37 // and this method only return the part of one series.
38 multipleSeries: boolean;
39}): TooltipMarkupSection {
40 const series = opt.series;
41 const dataIndex = opt.dataIndex;
42 const multipleSeries = opt.multipleSeries;
43
44 const data = series.getData();
45 const tooltipDims = data.mapDimensionsAll('defaultedTooltip');
46 const tooltipDimLen = tooltipDims.length;
47 const value = series.getRawValue(dataIndex) as any;
48 const isValueArr = isArray(value);
49 const markerColor = retrieveVisualColorForTooltipMarker(series, dataIndex);
50
51 // Complicated rule for pretty tooltip.
52 let inlineValue;
53 let inlineValueType: DimensionType | DimensionType[];
54 let subBlocks: TooltipMarkupBlockFragment[];
55 let sortParam: unknown;
56 if (tooltipDimLen > 1 || (isValueArr && !tooltipDimLen)) {
57 const formatArrResult = formatTooltipArrayValue(value, series, dataIndex, tooltipDims, markerColor);
58 inlineValue = formatArrResult.inlineValues;
59 inlineValueType = formatArrResult.inlineValueTypes;
60 subBlocks = formatArrResult.blocks;
61 // Only support tooltip sort by the first inline value. It's enough in most cases.
62 sortParam = formatArrResult.inlineValues[0];
63 }
64 else if (tooltipDimLen) {
65 const dimInfo = data.getDimensionInfo(tooltipDims[0]);
66 sortParam = inlineValue = retrieveRawValue(data, dataIndex, tooltipDims[0]);
67 inlineValueType = dimInfo.type;
68 }
69 else {
70 sortParam = inlineValue = isValueArr ? value[0] : value;
71 }
72
73 // Do not show generated series name. It might not be readable.
74 const seriesNameSpecified = isNameSpecified(series);
75 const seriesName = seriesNameSpecified && series.name || '';
76 const itemName = data.getName(dataIndex);
77 const inlineName = multipleSeries ? seriesName : itemName;
78
79 return createTooltipMarkup('section', {
80 header: seriesName,
81 // When series name is not specified, do not show a header line with only '-'.
82 // This case always happens in tooltip.trigger: 'item'.
83 noHeader: multipleSeries || !seriesNameSpecified,
84 sortParam: sortParam,
85 blocks: [
86 createTooltipMarkup('nameValue', {
87 markerType: 'item',
88 markerColor: markerColor,
89 // Do not mix display seriesName and itemName in one tooltip,
90 // which might confuses users.

Callers 2

formatTooltipMethod · 0.90
formatTooltipMethod · 0.90

Calls 13

retrieveRawValueFunction · 0.90
isNameSpecifiedFunction · 0.90
createTooltipMarkupFunction · 0.90
isArrayFunction · 0.85
formatTooltipArrayValueFunction · 0.85
trimFunction · 0.85
mapDimensionsAllMethod · 0.80
getNameMethod · 0.80
getDataMethod · 0.65
getRawIndexMethod · 0.65
getRawValueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…