Skip to content

Commit

Permalink
fix: fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Marginy605 committed Jan 23, 2023
1 parent 27ddb48 commit b0c5227
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
14 changes: 13 additions & 1 deletion src/components/ChartKit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ type ChartKitComponentProps<T extends ChartKitType> = Omit<ChartKitProps<T>, 'on

const ChartKitComponent = <T extends ChartKitType>(props: ChartKitComponentProps<T>) => {
const widgetRef = React.useRef<ChartKitWidgetRef>();
const {instanceRef, id: propsId, type, data, onLoad, isMobile, ...restProps} = props;
const {
instanceRef,
id: propsId,
type,
data,
onLoad,
onRender,
onChartLoad,
isMobile,
...restProps
} = props;

const ckId = React.useMemo(() => getRandomCKId(), []);
const id = propsId || ckId;
Expand Down Expand Up @@ -56,6 +66,8 @@ const ChartKitComponent = <T extends ChartKitType>(props: ChartKitComponentProps
lang={lang}
data={data}
onLoad={onLoad}
onRender={onRender}
onChartLoad={onChartLoad}
{...restProps}
/>
</div>
Expand Down
37 changes: 17 additions & 20 deletions src/plugins/highcharts/renderer/components/HighchartsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,24 @@ export class HighchartsComponent extends React.PureComponent<Props, State> {
}>();

componentDidMount() {
if (this.props.onChartLoad) {
if (!this.state.isError && !this.props.splitTooltip) {
const widget = this.chartComponent.current
? this.chartComponent.current.chart
: null;
if (!this.props.onChartLoad) {
this.onLoad();
return;
}

if (this.state.callback && widget) {
this.state.callback(widget);
}
const needCallbacks = !this.state.isError && !this.props.splitTooltip;
if (!needCallbacks) {
return;
}
const widget = this.chartComponent.current ? this.chartComponent.current.chart : null;

this.props.onChartLoad?.({
widget,
});
}
} else {
this.onLoad();
if (this.state.callback && widget) {
this.state.callback(widget);
}

this.props.onChartLoad?.({
widget,
});
}

componentDidUpdate() {
Expand All @@ -127,9 +128,9 @@ export class HighchartsComponent extends React.PureComponent<Props, State> {
renderTime: getChartPerformanceDuration(this.getId()),
});
}
} else {
this.onLoad();
return;
}
this.onLoad();
}

render() {
Expand Down Expand Up @@ -188,10 +189,6 @@ export class HighchartsComponent extends React.PureComponent<Props, State> {
return `${this.props.id}_${this.id}`;
}

/**
* @depricated: please use onRender & onChartLoad instead
* @private
*/
private onLoad() {
if (!this.state.isError && !this.props.splitTooltip) {
const data = {
Expand Down
7 changes: 1 addition & 6 deletions src/plugins/indicator/renderer/IndicatorWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,16 @@ const IndicatorWidget = React.forwardRef<ChartKitWidgetRef | undefined, ChartKit
const {
onLoad,
onRender,
onChartLoad,
formatNumber,
data: {data = [], defaultColor},
} = props;

React.useLayoutEffect(() => {
// TODO: swap to onRender after https://github.com/gravity-ui/chartkit/issues/33
onLoad?.();
onRender?.(); // TODO renderTime ?
onRender?.(); // TODO renderTime
});

React.useLayoutEffect(() => {
onChartLoad?.({widget: null});
}, []);

if (isEmpty(data)) {
throw new ChartKitError({
code: CHARTKIT_ERROR_CODE.NO_DATA,
Expand Down
4 changes: 2 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type ChartKitProps<T extends ChartKitType> = {
isMobile?: boolean;
/**
* @depricated: please use onRender & onChartLoad instead
* @private
* @param data
*/
onLoad?: (data?: ChartKitOnLoadData<T>) => void;
/**
Expand All @@ -49,7 +49,7 @@ export type ChartKitProps<T extends ChartKitType> = {
*/
onRender?: (data?: ChartKitOnRenderData) => void;
/**
* called on mount
* called on chart mount
* @param data
*/
onChartLoad?: (data?: ChartKitOnChartLoad) => void;
Expand Down

0 comments on commit b0c5227

Please sign in to comment.