moex-chartsrc/components/ChartTooltip/index.tsx
See all issues in this file
<div
className={styles.tooltip}
style={style}
ref={refTooltip}
>
{vmLegend?.map((indicator) => {
Refactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed.
if (indicator.isIndicator) {
const entries = getEntries(indicator.values).filter(([, entry]) => Boolean(entry));
const showSeriesLabel = entries.length > 1;
return entries.map(([key, entry]) => {
if (!entry) {
return null;
}
return renderRow(
`${indicator.id}-${String(key)}`,
showSeriesLabel
? entry.name
|| String(indicator.name) : String(indicator.name),
entry.value,
);
});
}
const entries = Object.fromEntries(getEntries(indicator.values)) as Partial<
Record<keyof Ohlc, { value: number | string | Time; color: string; name: string }>
>;
return (
<Fragment key={indicator.id}>
{tooltipConfig.time?.visible &&
entries.time?.value &&
renderRow(
`${indicator.id}-time`,
tooltipConfig.time.label,
formatDate(
entries.time.value as UTCTimestamp,
format?.dateFormat
?? Defaults.dateFormat,
format?.timeFormat
?? Defaults.timeFormat,
showTime,
),
)}
{((tooltipConfig.close?.visible
&& entries.close?.value
) ||
(tooltipConfig.open?.visible
&& entries.open?.value)
||
(tooltipConfig.value?.visible
&& entries.value?.value)) && (
<Divider
direction="horizontal"
pt={{ divider: { className: styles.divider } }}
/>
)}
{tooltipConfig.close?.visible &&
renderRow(`${indicator.id}-close`, tooltipConfig.close.label, entries.close?.value)}
{tooltipConfig.value?.visible &&
renderRow(`${indicator.id}-value`, tooltipConfig.value.label, entries.value?.value)}
{tooltipConfig.open?.visible &&
renderRow(`${indicator.id}-open`, tooltipConfig.open.label, entries.open?.value)}
{((tooltipConfig.high?.visible
&& entries.high?.value
) ||
(tooltipConfig.low?.visible
&& entries.low?.value)
||
(tooltipConfig.absoluteChange?.visible
&& entries.absoluteChange?.value)
||
(tooltipConfig.percentageChange?.visible
&& entries.percentageChange?.value)) && (
<Divider
direction="horizontal"
pt={{ divider: { className: styles.divider } }}
/>
)}