Skip to content

Commit

Permalink
feat(Indicator plugin): add renderTime
Browse files Browse the repository at this point in the history
  • Loading branch information
mournfulCoroner committed Apr 6, 2023
1 parent aede70c commit dc04d25
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/plugins/indicator/renderer/IndicatorWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {isEmpty} from 'lodash';
import {i18n} from '../../../i18n';
import {CHARTKIT_ERROR_CODE, ChartKitError} from '../../../libs';
import {CHARTKIT_SCROLLABLE_NODE_CLASSNAME} from '../../../constants';
import {getChartPerformanceDuration, getRandomCKId, markChartPerformance} from '../../../utils';
import type {ChartKitWidgetRef, ChartKitProps} from '../../../types';
import {IndicatorItem} from './IndicatorItem';

Expand All @@ -19,13 +20,24 @@ const IndicatorWidget = React.forwardRef<ChartKitWidgetRef | undefined, ChartKit
onLoad,
formatNumber,
data: {data = [], defaultColor},
id,
onRender,
} = props;

const generatedId = React.useMemo(
() => `${id}_${getRandomCKId()}`,
[data, defaultColor, id],
);

React.useLayoutEffect(() => {
// TODO: swap to onRender after https://github.com/gravity-ui/chartkit/issues/33
onLoad?.();
// TODO: add onRender with renderTime Issue #114
});
markChartPerformance(generatedId);
}, [generatedId]);

React.useEffect(() => {
// TODO: swap to onRender after https://github.com/yandex-cloud/chartkit/issues/33
onLoad?.({widgetRendering: getChartPerformanceDuration(generatedId)});
onRender?.({renderTime: getChartPerformanceDuration(generatedId)});
}, [onLoad, onRender]);

if (isEmpty(data)) {
throw new ChartKitError({
Expand Down

0 comments on commit dc04d25

Please sign in to comment.