Giter VIP home page Giter VIP logo

react-d3-cloud's Introduction

react-d3-cloud

NPM version Build Status Dependency Status

A word cloud react component built with d3-cloud.

image

Usage

npm install @diego.caceres/react-d3-cloud
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

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
colors Array of colors to use in the world cloud (optional) Array []
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

npm run build

Test

pre-install

Mac OS X

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

Ubuntu and other Debian based systems

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 at node-canvas wiki.

Run test

npm test

License

MIT ยฉ Yoctol

react-d3-cloud's People

Contributors

andycanderson avatar chentsulin avatar greenkeeperio-bot avatar hilb-aibod avatar kpman avatar stegben avatar tw0517tw avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.