Skip to content

Commit 5c72381

Browse files
author
sulemanof
committed
Use throttled chart update
1 parent aed0355 commit 5c72381

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/plugins/vis_type_tagcloud/public/components/tag_cloud_chart.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
* under the License.
1818
*/
1919

20-
import React, { useCallback, useEffect, useRef } from 'react';
20+
import React, { useEffect, useMemo, useRef } from 'react';
2121
import { EuiResizeObserver } from '@elastic/eui';
22+
import { throttle } from 'lodash';
2223

2324
import { TagCloudVisDependencies } from '../plugin';
2425
import { TagCloudVisRenderValue } from '../tag_cloud_fn';
@@ -57,14 +58,18 @@ export const TagCloudChart = ({
5758
}
5859
}, [visData, visParams, renderComplete]);
5960

60-
const onResize = useCallback(() => {
61-
if (visController.current) {
62-
visController.current.render().then(renderComplete);
63-
}
64-
}, [renderComplete]);
61+
const updateChartSize = useMemo(
62+
() =>
63+
throttle(() => {
64+
if (visController.current) {
65+
visController.current.render().then(renderComplete);
66+
}
67+
}, 300),
68+
[renderComplete]
69+
);
6570

6671
return (
67-
<EuiResizeObserver onResize={onResize}>
72+
<EuiResizeObserver onResize={updateChartSize}>
6873
{(resizeRef) => (
6974
<div className="tgcChart__wrapper" ref={resizeRef}>
7075
<div className="tgcChart__container" ref={chartDiv} />

0 commit comments

Comments
 (0)