Skip to content

Commit a4af12c

Browse files
authored
v1.2.0 (#37)
* update docs * swap eslint for xo * fix xo lint errors and convert ts->js * add husky, split `*.d.ts` from source code, add home page * update husky * add doc for common issues, add remaining types * fix build * use spaces over tabs... * cleanup * finalize v1.2.0 * add netlify.toml
1 parent 26c49f1 commit a4af12c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+9362
-4885
lines changed

.babelrc

-18
This file was deleted.

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ root = true
55
charset = utf-8
66
end_of_line = lf
77
indent_size = 2
8-
indent_style = space
8+
indent_style = tab
99
insert_final_newline = true
1010
max_line_length = 80
1111
trim_trailing_whitespace = true

.eslintignore

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Third party
2-
**/node_modules
3-
4-
# Build
5-
dist/
1+
node_modules
2+
dist
3+
optimized-d3-cloud.js

.eslintrc.js

-37
This file was deleted.

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
node_modules
33

44
# logs
5-
*.log*
5+
*.log
66

77
# files and IDE
88
.DS_STORE
@@ -11,5 +11,5 @@ node_modules
1111
*.swo
1212

1313
# project
14-
dist
1514
.docz
15+
dist

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
docs/
12
public/
23
node_modules/

.prettierrc.js

-5
This file was deleted.

CHANGELOG.md

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
# Change Log
1+
# Changelog
22

3-
All notable changes to this project will be documented in this file.
4-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
3+
## [1.2.0](https://github.com/chrisrzhou/react-wordcloud/compare/v1.1.1...v1.2.0) (2020-03-07)
4+
5+
This release is largely internal refactoring and updating dependencies, as well as 'de-typescripting' the codebase
6+
7+
### API additions:
8+
9+
- Improve rendering performance for larger clouds and multiple cloud instances with the `options.enableOptimizations` flag.
10+
11+
### Small Typescript breaking changes:
12+
13+
- `Spiral` and `Scale` enums are removed in favor of whitelisted string values. As part of moving to ambient declarations, these enums will not materialize in the compiled code.
14+
15+
### Internal code changes:
16+
17+
- Update underlying dependencies via `yarn upgrade --latest`. Remove a ton of unneeded dependencies and correctly move `@types/*` deps to `devDependencies`.
18+
- Remove custom `eslint`, `prettier` config and use `xo` for a simpler linting setup.
19+
- Add `husky` pre-push hook.
20+
- Update and improve documentation with `[email protected]`. Improved various doc pages (`Common Issues`) and added the `Optimizations` and `Home` page
21+
- Take the approach in various projects (e.g. [three](https://github.com/mrdoob/three.js/)) to "de-typescript" the codebase and use `*.d.ts` files for typing in development. Continue to expose Typescript types to consumers.
522

623
## [1.1.1](https://github.com/chrisrzhou/react-wordcloud/compare/v1.1.0...v1.1.1) (2019-09-27)
724

@@ -16,7 +33,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
1633
- Simplify typed code.
1734
- Expose `MouseEvent` object in `onWordClick`, `onWordMouseOut` and `onWordMouseOver` callbacks.
1835

19-
**Minor Typescript API Changes**
36+
### Minor Typescript API Changes
2037

2138
- Exported Typescript types for component props have been changed slightly due to refactoring.
2239

@@ -38,28 +55,28 @@ Fix emitted types.
3855

3956
## [1.0.5](https://github.com/chrisrzhou/react-wordcloud/compare/v1.0.4...v1.0.5) (2019-03-16)
4057

41-
### New:
58+
### New
4259

4360
- Added `FAQ` page explaining common 'bugs', and updated `Options` page with more examples
4461
- Handled recursive attempts to layout 'bad' clouds. Provide a console warning when max attempts have been made to layout 'bad' clouds.
4562
- Changed default `minSize` and `options.fontSizes` value to make things less buggy.
4663

47-
### Bug fixes:
64+
### Bug fixes
4865

4966
- Fixed a bug where `rotationAngles` was mutated.
5067

5168
## [1.0.4](https://github.com/chrisrzhou/react-wordcloud/compare/v1.0.3...v1.0.4) (2019-03-16)
5269

5370
Improve and simplify React hooks code after detailed understanding of: https://overreacted.io/a-complete-guide-to-useeffect/
5471

55-
### Bug fixes:
72+
### Bug fixes
5673

5774
- Handle words that don't fit in the boundary of the SVG by applying a font-size scale factor
5875
- Handle large number of words
5976

6077
## [1.0.3](https://github.com/chrisrzhou/react-wordcloud/compare/v1.0.2...v1.0.3) (2019-03-14)
6178

62-
### Bug fixes:
79+
### Bug fixes
6380

6481
- https://github.com/chrisrzhou/react-wordcloud/issues/5
6582
- https://github.com/chrisrzhou/react-wordcloud/issues/11

README.md

+8-31
Original file line numberDiff line numberDiff line change
@@ -10,67 +10,44 @@ Simple React + D3 wordcloud component with powerful features. Uses the [`d3-clou
1010
yarn add react-wordcloud
1111
```
1212

13-
Note that `react-wordcloud` requires `react^16.10.0` as a peer dependency.
13+
Note that `react-wordcloud` requires `react^16.13.0` as a peer dependency.
1414

1515
## Examples
1616

17-
### Documented Examples
18-
1917
View all documented examples and gallery of `react-wordcloud` applications at https://react-wordcloud.netlify.com/.
2018

21-
### Local Examples
22-
2319
You can also run the examples locally:
2420

2521
```bash
2622
git clone [email protected]:chrisrzhou/react-wordcloud
2723
cd react-wordcloud && yarn && yarn dev
2824
```
2925

30-
### Basic Example (no props)
26+
### Codesandbox examples
27+
28+
#### No props
3129

3230
[![Edit react-wordcloud-simple](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/bgov9)
3331

34-
### Responsive Example
32+
#### Responsive
3533

3634
[![Edit react-wordcloud-simple](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/55sb8)
3735

38-
### Configurable Options Example
36+
#### Configurable Options
3937

4038
[![Edit react-wordcloud-interactive](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/fnk8w)
4139

42-
### Callbacks Example
40+
#### Callbacks
4341

4442
[![Edit react-wordcloud-interactive](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/4lecp)
4543

46-
## Development
47-
48-
### Main Dependencies
49-
50-
- `react`
51-
- `d3`
52-
- `d3-cloud`
53-
- `tippy.js`
54-
55-
### Codebase Overview
56-
57-
- `index.tsx`: Pure React code that exposes an interface of props.
58-
- `render.ts`: Pure D3 code to render wordcloud given a valid D3 selection and other data.
59-
- `hooks.ts`: React hooks to construct and resize a responsive SVG container.
60-
- `types.ts`: Typescript types.
61-
- `utils.ts`: Various simple functions to compute derived data.
62-
63-
The code is written in `typescript`, linted with `eslint` + `prettier`, and bundled with `rollup`. Examples and documentations are built with `docz`.
64-
65-
Feel free to contribute by submitting a pull request.
66-
6744
## Wordcloud Generator
6845

6946
Create wordclouds using this wordcloud generator: https://wordcloud-generator.netlify.com/
7047

7148
Features supported:
7249

7350
- Edit and Upload text inputs
74-
- Various NLP methods (stopwords, ngrams)
51+
- Various NLP features (stopwords, ngrams)
7552
- Wordcloud configurations
7653
- Export/save/share wordclouds

docs/ReactWordcloud.tsx

-1
This file was deleted.

docs/changelog.mdx

-8
This file was deleted.

docs/common-issues.mdx

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
name: Common Issues
3+
route: /common-issues
4+
---
5+
6+
import { Playground } from "docz";
7+
import { useMemo, useState } from "react";
8+
9+
import ReactWordcloud from "../src";
10+
import words from "./words";
11+
12+
# Common Issues
13+
14+
## Re-rendering issues
15+
16+
It is a common scenario that
17+
`react-wordcloud` will unintentionally re-render (i.e. grow from the center) when the `size`, `callbacks`, `options` props are updated. Note that `react-wordcloud` is **unopinionated** about this rendering behavior since this is the default React behavior, namely that changes in props will re-render the component.
18+
19+
You should instead try to define these props statically (e.g. outside of the component) or memoize them accordingly. The comparison example below shows how to avoid this issue with `useMemo`.
20+
21+
<Playground>
22+
{() => {
23+
const [iteration, setIteration] = useState(0);
24+
const size = [600, 300]; // this creates a new array when state updates
25+
const memoizedSize = useMemo(() => [600, 300], []); // memoized. You can also simply just define the size variable itself outside of the componenet
26+
return (
27+
<div>
28+
<button onClick={() => setIteration(iteration + 1)}>
29+
Click to re-render
30+
</button>
31+
<h3>Will re-render because the "size" prop is always recreated</h3>
32+
<ReactWordcloud size={size} words={words} />
33+
<h3>Will not re-render because the "size" prop is memoized</h3>
34+
<ReactWordcloud size={memoizedSize} words={words} />
35+
</div>
36+
);
37+
}}
38+
</Playground>
39+
40+
## Performance issues
41+
42+
Performance issues in the underlying `d3-cloud` layout can be encountered in these common situations:
43+
44+
- Multiple instances of `react-wordcloud`.
45+
- Large `words` data.
46+
- High `maxWords` prop.
47+
- Large `fontSizes` with small `size` prop (or parent container size).
48+
49+
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.
50+
51+
## Dropped Words
52+
53+
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).
54+
55+
`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.
56+
57+
<Playground>
58+
<ReactWordcloud
59+
size={[200, 200]}
60+
words={[
61+
{ text: "this_is_a_long_word_and_also_the_most_frequent", value: 60 },
62+
{ text: "some_word", value: 30 },
63+
{ text: "another_word", value: 20 },
64+
]}
65+
/>
66+
</Playground>
67+
68+
If you see this console warning, it is recommended that you address it in the following ways:
69+
70+
- Increase the wordcloud size (either using the `size` prop or the parent container).
71+
- Reduce the `options.fontSizes` values.
72+
- 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.

docs/faq.mdx

-37
This file was deleted.

0 commit comments

Comments
 (0)