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 11, 2023
1 parent aede70c commit f2654ba
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 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,26 @@ const IndicatorWidget = React.forwardRef<ChartKitWidgetRef | undefined, ChartKit
onLoad,
formatNumber,
data: {data = [], defaultColor},
id,
onRender,
} = props;

const generatedId = React.useMemo(
() => `${id}_${getRandomCKId()}`,
[data, defaultColor, formatNumber, 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(() => {
if (onRender) {
onRender({renderTime: getChartPerformanceDuration(generatedId)});
return;
}
onLoad?.({widgetRendering: getChartPerformanceDuration(generatedId)});
}, [onLoad, onRender, generatedId]);

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

0 comments on commit f2654ba

Please sign in to comment.