EcchiGrill commented on issue #19064:
URL: https://github.com/apache/echarts/issues/19064#issuecomment-3669753281
Same issue here. When I try to access `value` and `data` from tooltip
`params` for a specific chart, I have to rely on TS type assertions to
explicitly type those values, which isn’t an ideal workaround.
I also tried using `DefaultLabelFormatterCallbackParams`, but it didn’t help
much in this case. It would be great to have something like generics to type
the `params` entity in a more flexible and efficient way.
```ts
interface FormatMediaSynergyTooltipArgs {
value: [number, number, number];
data: HeatmapData;
avgValue: number;
namesDelta: string[];
totalPairs: number;
}
const formatMediaSynergyTooltip = ({
value,
data,
avgValue,
namesDelta,
totalPairs,
}: FormatMediaSynergyTooltipArgs) => {
if (!value || value[2] === null) return '';
const [synergyIndexA, synergyIndexB] = value;
const rank = data?.rank;
const synergyValue = data?.synergyValue;
const synergyText =
synergyValue !== null ? `${formatPercent(synergyValue)}%` : ' ';
const indexValue =
synergyValue !== null && avgValue ? synergyValue / avgValue : null;
const indexText = indexValue !== null ? `${formatPercent(indexValue)}%` :
' ';
const tooltip = `
${namesDelta?.[synergyIndexA]} with ${namesDelta?.[synergyIndexB]}
<br/>Synergy: <b>${synergyText}</b>
<br/>Index: <b>${indexText}</b>
<br/>Rank: <b>${rank} of ${totalPairs}</b>
`;
return tooltip;
};
export const generateMediaSynergyTooltip = (
avgValue: number,
namesDelta: string[],
totalPairs: number
): TooltipComponentOption => {
const tooltip: TooltipComponentOption = {
trigger: 'item',
formatter: (params): string => {
if (Array.isArray(params)) {
return '';
}
const { value, data } = params;
const formattedTooltip = formatMediaSynergyTooltip({
value: value as [number, number, number],
data: data as HeatmapData,
avgValue,
namesDelta,
totalPairs,
});
return formattedTooltip;
},
};
return tooltip;
};
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]