From ed87b2c155c95966cb4b2ceb462b71065b024ef3 Mon Sep 17 00:00:00 2001
From: Karandeep Singh <46585033+ConfuseIous@users.noreply.github.com>
Date: Thu, 7 Sep 2023 19:35:22 +0800
Subject: [PATCH] update to work with react 18
---
docs/faq.mdx | 162 ----------
docs/hero.tsx | 44 ---
docs/index.mdx | 12 -
docs/props/callbacks-interface.tsx | 5 -
docs/props/component-props.tsx | 5 -
docs/props/options-interface.tsx | 5 -
docs/props/props.mdx | 37 ---
docs/props/word-interface.tsx | 5 -
docs/react-wordcloud.tsx | 23 --
docs/usage/basic.mdx | 18 --
docs/usage/callbacks.mdx | 66 ----
docs/usage/optimizations.mdx | 26 --
docs/usage/options.mdx | 175 ----------
docs/usage/size.mdx | 40 ---
docs/usage/transitions.mdx | 35 --
docs/words.ts | 502 -----------------------------
doczrc.js | 33 --
package.json | 20 +-
types/index.d.ts | 176 +---------
19 files changed, 10 insertions(+), 1379 deletions(-)
delete mode 100644 docs/faq.mdx
delete mode 100644 docs/hero.tsx
delete mode 100644 docs/index.mdx
delete mode 100644 docs/props/callbacks-interface.tsx
delete mode 100644 docs/props/component-props.tsx
delete mode 100644 docs/props/options-interface.tsx
delete mode 100644 docs/props/props.mdx
delete mode 100644 docs/props/word-interface.tsx
delete mode 100644 docs/react-wordcloud.tsx
delete mode 100644 docs/usage/basic.mdx
delete mode 100644 docs/usage/callbacks.mdx
delete mode 100644 docs/usage/optimizations.mdx
delete mode 100644 docs/usage/options.mdx
delete mode 100644 docs/usage/size.mdx
delete mode 100644 docs/usage/transitions.mdx
delete mode 100644 docs/words.ts
delete mode 100644 doczrc.js
diff --git a/docs/faq.mdx b/docs/faq.mdx
deleted file mode 100644
index 10f8b81..0000000
--- a/docs/faq.mdx
+++ /dev/null
@@ -1,162 +0,0 @@
----
-name: FAQ
-route: /faq
----
-
-import { Playground } from 'docz';
-import { useMemo, useState } from 'react';
-
-import ReactWordcloud from './react-wordcloud';
-import words from './words';
-
-# FAQ
-
-## Re-rendering issues
-
-Various props for `react-wordcloud` such as `size`, `callbacks`, `options` are array/object-based. A common mistake in React components is to declare these conveniently as literal prop values:
-
-```js
-function MyWordcloud() {
- return (
-
- )
-}
-```
-
-When your component re-renders, the array/object literal props are always initialized as new instances, and this causes the underlying `react-wordcloud` component to re-render as props have changed (React behavior). To avoid this situation, either declare these prop values outside of your component, or memoize them:
-
-```js
-const size = [400, 300];
-const options = {
- fontFamily: 'courier new',
- fontSizes: [10, 20],
-};
-
-function MyStaticWordcloud() {
- return (
-
- )
-}
-```
-
-```js
-import { useMemo } from 'react';
-
-function MyMemoizedWordcloud() {
- const size = useMemo(() => {
- return [400, 300];
- }, []); // add dependencies to useMemo where appropriate
-
- const options = useMemo(() => {
- return {
- fontFamily: 'courier new',
- fontSizes: [10, 20],
- }
- }, []); // add dependencies to useMemo where appropriate
-
- return (
-
- );
-}
-```
-
-Here is a playground that illustrates the difference between memoizing th;e `size` prop.
-
-
- {() => {
- const [iteration, setIteration] = useState(0);
- const size = [600, 300]; // this creates a new array when state updates
- const memoizedSize = useMemo(() => [600, 300], []); // memoized. You can also simply just define the size variable itself outside of the componenet
- return (
-
-
-
Will re-render because the 'size' prop is always recreated
-
-
Will not re-render because the 'size' prop is memoized
-
-
- );
- }}
-
-
-## Deterministic layouts
-Please refer to the [Deterministic Behavior](../usage/options#deterministic-behaviour) section for more details on controlling deterministic layouts of wordclouds.
-
-## Performance issues
-
-### Cloud-based
-Performance issues in the underlying `d3-cloud` layout can be encountered in these common situations:
-
-- Multiple wordcloud instances.
-- Large `words` data.
-- High `maxWords` prop.
-- Large `fontSizes` with small `size` prop (or parent container size).
-
-The `options.enableOptimizations` flag can be uesd to solve the first two performance problems. For the other problems, you will have to experiment and pick ideal options to configure your wordclouds.
-
-### Browser-based
-`react-wordcloud` requires access to canvas data to render. If browsers are blocking canvas data access (e.g. Firefox's `privacy.resistFingerprinting = true` which prompts for permission to access canvas data), you need to enable it. If you are implementing projects that use `react-wordcloud`, you should inform users on how to get around the issue as shown in the example below:
-
-```js
-function MyWordcloud(props) {
- const canvasAllowed = typeof document !== 'undefined' && document.createElement('canvas').getContext('2d').getImageData(0, 0, 1, 1).data.every(v => v === 0);
-
- if (!canvasAllowed) {
- return (
-
- React wordcloud requires access to canvas image data. Please allow
- access in your browser and reload the page.
-
- );
- }
-
- return
-```
-
-## Dropped Words
-
-This issue happens when the most _frequent_ word is also the _longest_ word. For a given wordcloud size, if the longest and most frequent word does not fit in the wordcloud SVG container, the `d3-cloud` algorithm drops them out. This is a known issue discussed in: [#36](https://github.com/jasondavies/d3-cloud/issues/36).
-
-`react-wordcloud` tries to solve this issue by recursively rendering the wordcloud if it detects that words have been dropped out. Each recursion would decrease the applied font-size by a scale factor. The recursion will bail out after some maximum attempts is reached, and a console warning will be thrown to the user informing that the words cannot be rendered in the wordcloud. The following example below demonstrates this scenario.
-
-
-
-
-
-If you see this console warning, it is recommended that you address it in the following ways:
-
-- Increase the wordcloud size (either using the `size` prop or the parent container).
-- Reduce the `options.fontSizes` values.
-- Avoid rendering long words at vertical angles (i.e. 90 degrees). Browser heights are more limited than widths, and the long words may not fit within the wordcloud height. You can control rotation angles using `rotationAngles` and `rotations` in the `options` props.
-
-## Typescript errors
-Common typescript issues are frequently experienced when working with `Scale`, `Spiral`, `MinMaxPair` types where providing literal number arrays or strings will cause the TS compiler to complain. Most of these are type aliases (e.g. `[number, number]` and `'linear' | 'log' | 'sqrt'`) and you can resolve these issues by type-asserting them e.g.
-
-```ts
-const fonSizes: MinMaxPair = [10, 20];
-const fontSizes = [10, 20] as MinMaxPair;
-
-const scale = 'linear' as const;
-const scale = 'linear';
-```
diff --git a/docs/hero.tsx b/docs/hero.tsx
deleted file mode 100644
index 8b29776..0000000
--- a/docs/hero.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-import React, { useEffect, useState } from 'react';
-
-import { choose } from '../src/utils';
-import ReactWordcloud, { MinMaxPair, Scale, Spiral } from './react-wordcloud';
-import words from './words';
-
-const { random } = Math;
-
-const fontFamilies = ['Arial', 'Times New Roman', 'Impact'];
-const fontSizes: MinMaxPair = [14, 40];
-const rotationAngles = [
- [-90, 90],
- [-45, 45],
- [-180, 180],
-];
-const scales: Scale[] = ['linear', 'log', 'sqrt'];
-const spirals: Spiral[] = ['rectangular', 'archimedean'];
-
-function Hero(): JSX.Element {
- const [iteration, setIteration] = useState(0);
-
- useEffect(() => {
- const interval = setInterval(() => {
- setIteration(iteration + 1);
- }, 3000);
- return () => clearInterval(interval);
- }, [iteration]);
-
- const options = {
- fontFamily: choose(fontFamilies, random),
- fontSizes,
- scale: choose(scales, random),
- spiral: choose(spirals, random),
- rotationAngle: choose(rotationAngles, random),
- };
-
- return (
-
-
-
- );
-}
-
-export default Hero;
diff --git a/docs/index.mdx b/docs/index.mdx
deleted file mode 100644
index b7ec932..0000000
--- a/docs/index.mdx
+++ /dev/null
@@ -1,12 +0,0 @@
----
-name: Home
-route: /
----
-
-import Hero from './hero';
-
-# `react-wordcloud`
-
-Simple React + D3 wordcloud component with powerful features. Uses the [`d3-cloud`](https://github.com/jasondavies/d3-cloud) layout.
-
-
diff --git a/docs/props/callbacks-interface.tsx b/docs/props/callbacks-interface.tsx
deleted file mode 100644
index c4f93fb..0000000
--- a/docs/props/callbacks-interface.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { CallbacksProp } from '../react-wordcloud';
-
-export default function CallbacksInterface(_props: CallbacksProp): JSX.Element {
- return null;
-}
diff --git a/docs/props/component-props.tsx b/docs/props/component-props.tsx
deleted file mode 100644
index 6e6e790..0000000
--- a/docs/props/component-props.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { Props } from '../react-wordcloud';
-
-export default function ComponentProps(_props: Props): JSX.Element {
- return null;
-}
diff --git a/docs/props/options-interface.tsx b/docs/props/options-interface.tsx
deleted file mode 100644
index 9641381..0000000
--- a/docs/props/options-interface.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { OptionsProp } from '../react-wordcloud';
-
-export default function OptionsInterface(_props: OptionsProp): JSX.Element {
- return null;
-}
diff --git a/docs/props/props.mdx b/docs/props/props.mdx
deleted file mode 100644
index 1c1a00a..0000000
--- a/docs/props/props.mdx
+++ /dev/null
@@ -1,37 +0,0 @@
----
-name: Props
-route: /props
----
-
-import { Props } from 'docz';
-
-import CallbacksInterface from './callbacks-interface';
-import ComponentProps from './component-props';
-import OptionsInterface from './options-interface';
-import WordInterface from './word-interface';
-
-# Props
-
-`react-wordcloud` provides a simple set of props to build and configure wordclouds.
-
-
-
-Additional props will be passed through to the underlying HTML element.
-
-## `Word`
-
-The `word` object takes the following shape
-
-
-
-## `options`
-
-You can customize the wordcloud by configuring the `options` prop. All fields are optional.
-
-
-
-## `callbacks`
-
-The `callbacks` prop provides advanced ways to control the wordcloud behaviors. All fields are optional.
-
-
diff --git a/docs/props/word-interface.tsx b/docs/props/word-interface.tsx
deleted file mode 100644
index 9d9b91f..0000000
--- a/docs/props/word-interface.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { Word } from '../react-wordcloud';
-
-export default function WordInterface(_props: Word): JSX.Element {
- return null;
-}
diff --git a/docs/react-wordcloud.tsx b/docs/react-wordcloud.tsx
deleted file mode 100644
index d51c1a3..0000000
--- a/docs/react-wordcloud.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-import React from 'react';
-
-import 'tippy.js/dist/tippy.css';
-import 'tippy.js/animations/scale.css';
-
-import ReactWordcloudSrc, { Props } from '..';
-
-export * from '..';
-
-export default function ReactWordcloud(props: Props): JSX.Element {
- const canvasAllowed = typeof document !== 'undefined' && document.createElement('canvas').getContext('2d').getImageData(0, 0, 1, 1).data.every(v => v === 0);
-
- if (!canvasAllowed) {
- return (
-
- React wordcloud requires access to canvas image data. Please allow
- access in your browser and reload the page.
-
- );
- }
-
- return ;
-}
diff --git a/docs/usage/basic.mdx b/docs/usage/basic.mdx
deleted file mode 100644
index 8203964..0000000
--- a/docs/usage/basic.mdx
+++ /dev/null
@@ -1,18 +0,0 @@
----
-name: Basic
-menu: Usage
-route: /usage/basic
----
-
-import { Playground } from 'docz';
-
-import ReactWordcloud from '../react-wordcloud';
-import words from '../words';
-
-# Basic Example
-
-Simply provide an array of words with valid `text` and `value` fields to begin!
-
-
-
-
diff --git a/docs/usage/callbacks.mdx b/docs/usage/callbacks.mdx
deleted file mode 100644
index 3acd8da..0000000
--- a/docs/usage/callbacks.mdx
+++ /dev/null
@@ -1,66 +0,0 @@
----
-name: Callbacks
-menu: Usage
-route: /usage/callbacks
----
-
-import { select } from 'd3-selection';
-import { Playground } from 'docz';
-
-import ReactWordcloud from '../react-wordcloud';
-import words from '../words';
-
-# Callbacks
-
-`react-wordcloud` provides a [`callbacks`](../props#callbacks) prop to configure detailed word colors, tooltips and events.
-
-## Colors and Tooltips
-
-By default, `react-wordcloud` randomnly applies colors to words using colors from the `colors` prop. It also defaults to using the `word.text` field for rendering tooltips.
-
-In the example below, we can pass custom `getWordColor` and `getWordTooltip` callbacks to update word colors and tooltips based on the `word` data.
-
-
- (value > 50 ? 'blue' : 'red'),
- getWordTooltip: ({ text, value }) =>
- `${text} (${value}) [${value > 50 ? 'good' : 'bad'}]`,
- }}
- />
-
-
-## Mouse Events
-
-You can pass callbacks such as `onWordClick`, `onWordMouseEnter` and `onWordMouseLeave` to capture the word and mouse events. The following example shows how we can work with the captured word and mouse events to create an enlarged word that opens an external link.
-
-
- {() => {
- const getCallback = callbackName => (word, event) => {
- const isActive = callbackName !== 'onWordMouseOut';
- const element = event.target;
- const text = select(element);
- text
- .on('click', () => {
- if (isActive) {
- window.open(`https://duckduckgo.com/?q=${word.text}`, '_blank');
- }
- })
- .transition()
- .attr('background', 'white')
- .attr('font-size', isActive ? '300%' : '100%')
- .attr('text-decoration', isActive ? 'underline' : 'none');
- };
- return (
-
- );
- }}
-
diff --git a/docs/usage/optimizations.mdx b/docs/usage/optimizations.mdx
deleted file mode 100644
index b40ecd3..0000000
--- a/docs/usage/optimizations.mdx
+++ /dev/null
@@ -1,26 +0,0 @@
----
-name: Optimizations
-menu: Usage
-route: /usage/optimizations
----
-
-import ReactWordcloud from '../react-wordcloud';
-import words from '../words';
-
-# Optimizations
-
-> [BETA] This feature is not formally supported, but is made available for improving performance in edge cases.
-
-By default, `react-wordcloud` uses the [`d3.cloud`](https://github.com/jasondavies/d3-cloud) layout algorithm. The algorithm as of [v1.2.5](https://github.com/jasondavies/d3-cloud/releases/tag/v1.2.5) is not optimized to handle rendering larger `words`.
-
-An optimized solution was explored by [WhoAteDaCake](https://github.com/WhoAteDaCake) in [#33](https://github.com/chrisrzhou/react-wordcloud/pull/33), and can be accessed by setting `options.enableOptimizations` to `true`. This feature is currently marked as `beta` and will be more formally supported if the underlying `d3-cloud` algorithm supports it.
-
-The following section shows how multiple wordclouds are rendered smoothly with `enableOptimizations` set to `true`.
-
-
- {Array(12).fill().map((_v, i) => (
-
-
-
- ))}
-
diff --git a/docs/usage/options.mdx b/docs/usage/options.mdx
deleted file mode 100644
index 6baebc5..0000000
--- a/docs/usage/options.mdx
+++ /dev/null
@@ -1,175 +0,0 @@
----
-name: Options
-menu: Usage
-route: /usage/options
----
-
-import { Playground } from 'docz';
-
-import ReactWordcloud from '../react-wordcloud';
-import words from '../words';
-
-# Options
-
-You can customize many visual and layout properties of `react-wordcloud` by using the [`options`](../props#options) prop.
-
-## Colors
-
-`react-wordcloud` will randomnly apply colors from an array of color hex codes.
-
-
-
-
-
-## Deterministic Behaviour
-
-`react-wordcloud` randomly positions and rotates words by default. If `options.deterministic` is `true`, `react-wordcloud` will produce the same positioning/rotation/color for a provided input. You can also provide a `randomSeed` string value to control the random seed behavior. Try resizing the wordcloud up and down in the example below to see the deterministic behavior.
-
-
-
-
-
-## Font Styles
-
-Configure word font styles using the `fontFamily`, `fontSizes`, `fontStyle`, `fontWeight` options.
-
-
-
-
-
-## Rotations
-
-By default `react-wordcloud` will apply random rotations if the `rotations` option is not specified. If `rotations` option is specified, it will use evenly-divided angles from the `rotationAngles` option based on the `rotations` value. The following example demonstrates common rotation angles of wordcloud layouts
-
-
-
Auto
-
-
0º
-
-
0º, 90º (negative angles work too)
-
-
0º, 45º, 90º
-
-
-
-## Layout
-
-Configure the wordcloud layout by using the `scale`, `spiral` options.
-
-
-
-
-
-## Attributes
-
-You can set custom attributes on the `svg` or `text` nodes by using the `svgAttributes` or `textAttributes`. You can either use a string or a function returning a string from a `Word` as values for attributes. You may also override the existing attributes that are set by the wordcloud algorithm. These features are demonstrated in the example below.
-
-
- `Word: '${word.text}', Count: '${word.value}'`,
- fill: 'red',
- role: 'img',
- },
- }}
- words={words}
- />
-
-
-## Interactive
-
-Use the Playground to edit and play around with some of these options!
-
-
- `Word: '${word.text}', Count: '${word.value}'`,
- role: 'img',
- },
- tooltipOptions: {
- allowHTML: true,
- arrow: false,
- placement: 'bottom',
- },
- transitionDuration: 1000,
- }}
- />
-
diff --git a/docs/usage/size.mdx b/docs/usage/size.mdx
deleted file mode 100644
index e9378f8..0000000
--- a/docs/usage/size.mdx
+++ /dev/null
@@ -1,40 +0,0 @@
----
-name: Size
-menu: Usage
-route: /usage/size
----
-
-import { Playground } from 'docz';
-
-import ReactWordcloud from '../react-wordcloud';
-import words from '../words';
-
-# Size
-
-By default, `react-wordcloud` will inherit the parent's size unless an explicit `size` prop is specified.
-
-## Responsive parent size
-
-This is the default behavior. You can resize the Playground container to watch the wordcloud update when parent size changes.
-
-
-