From 9ab0ea7eb338440b2c18b6b30e9df9106e184cae Mon Sep 17 00:00:00 2001 From: keating529 Date: Mon, 19 Oct 2020 09:02:51 +0900 Subject: [PATCH] `initRender` options for better UX when maxFontSize is too bigger than optimized value --- src/index.js | 2 ++ src/layout.js | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/index.js b/src/index.js index e2aafbb..22d02c3 100644 --- a/src/index.js +++ b/src/index.js @@ -33,6 +33,7 @@ function ReactWordCloud({ options, size: initialSize, words, + initRender, ...rest }) { const [ref, selection, size] = useResponsiveSvgSelection( @@ -55,6 +56,7 @@ function ReactWordCloud({ selection, size, words, + initRender, }); } }, [maxWords, callbacks, options, selection, size, words]); diff --git a/src/layout.js b/src/layout.js index 9bd83c8..55200a3 100644 --- a/src/layout.js +++ b/src/layout.js @@ -131,6 +131,7 @@ export function layout({ selection, size, words, + initRender, }) { const MAX_LAYOUT_ATTEMPTS = 10; const SHRINK_FACTOR = 0.95; @@ -217,6 +218,15 @@ export function layout({ minFontSize, ); + if (attempts === 1 && initRender) { + render({ + callbacks, + options, + random, + selection, + words: computedWords, + }) + } draw([minFontSize, maxFontSize], attempts + 1); } else { render({