# @alkihis/react-d3-cloud

> a word cloud component using d3-cloud

Latest version **0.7.0** (published 2020-01-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @alkihis/react-d3-cloud
pnpm add @alkihis/react-d3-cloud
yarn add @alkihis/react-d3-cloud
bun add @alkihis/react-d3-cloud
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.0 |
| Published | 2020-01-09 |
| First published | 2020-01-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 21.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 153 |
| Author | cph |
| Maintainers | alkihis |
| Keywords | d3, react, word-cloud |

## Links

- npm: https://www.npmjs.com/package/@alkihis/react-d3-cloud
- Repository: https://github.com/Yoctol/react-d3-cloud
- Homepage: https://github.com/Yoctol/react-d3-cloud#readme
- Issues: https://github.com/Yoctol/react-d3-cloud/issues
- npm.io page: https://npm.io/package/@alkihis/react-d3-cloud

## Dependencies (7)

- [d3-cloud](https://npm.io/package/d3-cloud.md) ^1.2.5
- [d3-scale](https://npm.io/package/d3-scale.md) ^2.1.2
- [prop-types](https://npm.io/package/prop-types.md) ^15.6.2
- [d3-selection](https://npm.io/package/d3-selection.md) ^1.3.2
- [react-faux-dom](https://npm.io/package/react-faux-dom.md) ^4.2.0
- [d3-scale-chromatic](https://npm.io/package/d3-scale-chromatic.md) ^1.3.3
- [enzyme-adapter-react-16](https://npm.io/package/enzyme-adapter-react-16.md) ^1.6.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.7.0 (latest) — 2020-01-09

## README

# react-d3-cloud

[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Dependency Status][david_img]][david_site]

A word cloud react component built with [d3-cloud](https://github.com/jasondavies/d3-cloud).

![image](https://cloud.githubusercontent.com/assets/6868283/20619528/fa83334c-b32f-11e6-81dd-6fe4fa6c52d9.png)

## Usage

```sh
npm install react-d3-cloud
```

```jsx
import React from "react";
import { render } from "react-dom";
import WordCloud from "react-d3-cloud";

const data = [
  { text: "Hey", value: 1000 },
  { text: "lol", value: 200 },
  { text: "first impression", value: 800 },
  { text: "very cool", value: 1000000 },
  { text: "duck", value: 10 }
];

const fontSizeMapper = word => Math.log2(word.value) * 5;
const rotate = word => word.value % 360;

render(
  <WordCloud data={data} fontSizeMapper={fontSizeMapper} rotate={rotate} />,
  document.getElementById("root")
);
```

Please checkout [demo](https://yoctol.github.com/react-d3-cloud)

for more detailed props, please refer to below:

## Props

| name            | description                                                                                                  | type                                            | required | default               |
| --------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------------------------- | -------- | --------------------- |
| data            | The input data for rendering                                                                                 | Array<{ text: string, value: number }>          | ✓        |
| width           | Width of component (px)                                                                                      | number                                          |          | 700                   |
| height          | Height of component (px)                                                                                     | number                                          |          | 600                   |
| fontSizeMapper  | Map each element of `data` to font size (px)                                                                 | Function: `(word: string, idx: number): number` |          | `word => word.value;` |
| rotate          | Map each element of `data` to font rotation degree. Or simply provide a number for global rotation. (degree) | Function \| number                              |          | 0                     |
| padding         | Map each element of `data` to font padding. Or simply provide a number for global padding. (px)              | Function \| number                              |          | 5                     |
| font            | The font of text shown                                                                                       | Function \| string                              |          | serif                 |
| onWordClick     | Function called when click event triggered on a word                                                         | Function: `word => {}`                          |          | null                  |
| onWordMouseOver | Function called when mouseover event triggered on a word                                                     | Function: `word => {}`                          |          | null                  |
| onWordMouseOut  | Function called when mouseout event triggered on a word                                                      | Function: `word => {}`                          |          | null                  |

## Build

```sh
npm run build
```

## Test

### pre-install

#### Mac OS X

```sh
brew install pkg-config cairo pango libpng jpeg giflib librsvg
npm install
```

#### Ubuntu and other Debian based systems

```sh
sudo apt-get update
sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++
npm install
```

For more details, please check out [Installation guides](https://github.com/Automattic/node-canvas/wiki) at node-canvas wiki.

### Run test

```sh
npm test
```

## License

MIT © [Yoctol](https://github.com/Yoctol/react-d3-cloud)

[npm-image]: https://img.shields.io/npm/v/react-d3-cloud.svg?style=flat-square
[npm-url]: https://npmjs.org/package/react-d3-cloud
[travis-image]: https://travis-ci.org/Yoctol/react-d3-cloud.svg?branch=master
[travis-url]: https://travis-ci.org/Yoctol/react-d3-cloud
[david_img]: https://david-dm.org/Yoctol/react-d3-cloud.svg
[david_site]: https://david-dm.org/Yoctol/react-d3-cloud

---
_Source: https://npm.io/package/@alkihis/react-d3-cloud · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
