From 52e31084175c2bf9d7dce27687a3fe21bfd2219a Mon Sep 17 00:00:00 2001 From: Ivan Parfenchuk Date: Tue, 9 Jul 2024 08:48:16 +0300 Subject: [PATCH] improve: Pass through timeInterval prop to d3-cloud This commit adds timeInterval prop, which is passed through to d3-cloud it allows to limit the amount of time d3-cloud spends on layout of a single item. --- README.md | 1 + src/WordCloud.tsx | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 288fef7..36fd0b5 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ for more detailed props, please refer to below: | data | The words array | `{ text: string, value: number }>[]` | ✓ | | width | Width of the layout (px) | `number` | | `700` | | height | Height of the layout (px) | `number` | | `600` | +| timeInterval | The maximum amount of time that can be spent during the current timestep (ms). Prevents the layout from getting stuck. | `number` | | `Infinity` | | font | The font accessor function, which indicates the font face for each word. A constant may be specified instead of a function. | `string \| (d) => string` | | `'serif'` | | fontStyle | The fontStyle accessor function, which indicates the font style for each word. A constant may be specified instead of a function. | `string \| (d) => string` | | `'normal'` | | fontWeight | The fontWeight accessor function, which indicates the font weight for each word. A constant may be specified instead of a function. | `string \| number \| (d) => string \| number` | | `'normal'` | diff --git a/src/WordCloud.tsx b/src/WordCloud.tsx index 5963d97..f00b870 100644 --- a/src/WordCloud.tsx +++ b/src/WordCloud.tsx @@ -20,6 +20,7 @@ type WordCloudProps = { data: Datum[]; width?: number; height?: number; + timeInterval?: number; font?: string | ((word: Word, index: number) => string); fontStyle?: string | ((word: Word, index: number) => string); fontWeight?: @@ -46,6 +47,7 @@ function WordCloud({ data, width = 700, height = 600, + timeInterval, font = 'serif', fontStyle = 'normal', fontWeight = 'normal', @@ -130,6 +132,10 @@ function WordCloud({ } }); + if (timeInterval) { + layout.timeInterval(timeInterval); + } + layout.start(); return el.toReact();