Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import React from 'react';
import {useThemeValue} from '@gravity-ui/uikit';
import type {YagrChartProps} from '@gravity-ui/yagr/react';
import type {MinimalValidConfig, YagrTheme, YagrWidgetProps} from '../types';
import {shapeYagrConfig} from './utils';
export const useWidgetData = (
props: YagrWidgetProps,
id: string,
): {config: MinimalValidConfig; debug: YagrChartProps['debug']} => {
const {data, sources, libraryConfig} = props.data;
const theme = useThemeValue() as YagrTheme;
const config: MinimalValidConfig = React.useMemo(
() =>
shapeYagrConfig({
data,
libraryConfig,
theme,
customTooltip: Boolean(props.tooltip),
}),
[data, libraryConfig, theme, props.tooltip],
);
const debug: YagrChartProps['debug'] = React.useMemo(() => {
const filename = sources
? Object.values(sources)
.map((source) => {
return source?.data?.program;
})
.filter(Boolean)
.join(', ') || id
: id;
return {filename};
}, [id, sources]);
return {config, debug};
};
|