• Stars
    star
    426
  • Rank 101,884 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Interactive multi-layer pie chart

cake-chart

Interactive multi-layer pie chart

Demo

Webpack Chart

Install

> npm i -S cake-chart

Simple Example

import CakeChart from 'cake-chart';

const TREE = {
  value: 100,
  label: 'SUM = 100',
  children: [{
    value: 50,
    children: [{
      value: 10
    },
    {
      value: 20
    }]
  }, {
    value: 30
  }, {
    value: 20
  }]
};

...

render () {
  return (
    <CakeChart data={TREE} />
  );
}

Advanced Example

Tree Navigation

CakeChart is a quite dumb component that renders provided tree, but doesn't navigate through it, so you have to implement that part yourself. Which is not hard though.

const TREE = { ... };

/* finds parent of the selected node -
   you can just store parent in the node itself, for example */
function findParentNode(node, child, parent = null) {
  if (node === child) return parent;
  for (let c of child.children || []) {
    const p = findParent(node, c, child);
    if (p) return p;
  }
}

class InteractiveCakeChart extends React.Component {
  constructor(props) {
    super(props);
    
    this.state = {
      selectedNode: TREE
    }
  }
  
  render() {
    return (
      <CakeChart data={this.state.selectedNode}
                 onClick={this.handleClick} />
    );
  }
  
  handleClick = (node) => {
    if (node === this.state.selectedNode) {
      /* user clicked on the chart center - rendering parent node */
      this.setState({ selectedNode: findParentNode(node, TREE) || TREE });
    } else {
      this.setState({ selectedNode: node });
    }
  }
}

Customization

function getSliceProps(slice, props) {
  return { ...props, fill: (slice.level % 2) ? '#FF0000' : '#0000FF' };
}

function getLabel(slice, label) {
  return slice.level === 0 ? `Value: ${slice.node.value}` : label;
}

function getLabelProps(slice, props) {
  return { ...props, style: { background: (slice.level % 2) ? '#FF0000' : '#0000FF' } };
}

class CustomizedCakeChart extends React.Component {
  render() {
    return (
      <CakeChart data={TREE}
                 coreRadius={120}
                 ringWidth={80}
                 ringWidthFactor={0.6}
                 getSliceProps={getSliceProps}
                 getLabelProps={getLabelProps}
                 getLabel={getLabel} />
    );
  }
}

More Repositories

1

react-input-enhancements

Set of enhancements for input control
JavaScript
1,376
star
2

react-json-tree

React JSON Viewer Component, Extracted from redux-devtools
JavaScript
992
star
3

react-dock

Resizable dockable react component
JavaScript
544
star
4

webpack-chart

Webpack Chart
JavaScript
437
star
5

flask-react-boilerplate

JavaScript
368
star
6

redux-devtools-inspector

Another Redux DevTools Monitor
JavaScript
240
star
7

script-progress

Estimate script execution time
JavaScript
177
star
8

nyan-progress-webpack-plugin

Meow
JavaScript
172
star
9

markdown-react-js

Markdown to React Component converter
JavaScript
104
star
10

stellar-webpack

A little experiment
JavaScript
92
star
11

redux-pagan

managing internationalization via redux
JavaScript
78
star
12

restore-source-tree

Restores file structure from source map
JavaScript
62
star
13

additive-animation

Additive animation npm module
JavaScript
46
star
14

react-transform-debug-inspector

React inspector tranformation function for babel-plugin-wrap-react-components
JavaScript
29
star
15

react-base16-styling

React styling with base16 color scheme support
JavaScript
21
star
16

export-files-webpack-plugin

Exports files to FS (even in devserver mode)
JavaScript
17
star
17

SublimeLinter-inline-errors

Shows linting errors inline with Phantom API
Python
15
star
18

react-bootstrap-breadcrumbs

Breadcrumbs for React-Router and Bootstrap
JavaScript
15
star
19

react-pagan

JavaScript
14
star
20

jss-css

JavaScript
14
star
21

Tomato

Pebble pomodoro app
C
7
star
22

pg_unidecode

Postgres Unidecode extension
C
7
star
23

git-swap

Interactive, pure-shell menu for switching between git branches
Shell
5
star
24

sublime-bun

Bun binary files viewer and other Bun-related stuff
Python
5
star
25

sublime-yarn-lock

Syntax highlighting for yarn.lock and bun.lockb files
4
star
26

shittify-js

So you can honestly say your code is full of shit
JavaScript
4
star
27

babel-plugin-jss-css

JavaScript
4
star
28

svg-flag-editor

Online tool for editing flag svg image source
JavaScript
2
star
29

react-component-boilerplate

React component template
JavaScript
2
star
30

tslint-no-commented-code-rule

TSLint rule that bans commented code
TypeScript
2
star
31

sqlalchemy-flux-serializer

Serialize sqlalchemy models into flux-friendly json
Python
2
star
32

nodejs-dashboard-layout-progress

Layout for nodejs-dashboard with progress and status
JavaScript
2
star
33

alexkuz

HTML
2
star
34

eslint-plugin-jinja

This plugin treats Jinja template expressions as Javascript literals and ignores template statements and comments
JavaScript
2
star
35

mono-coffeescript-addin

CoffeeScript language addin for MonoDevelop
C#
1
star
36

custom-stickers

Python
1
star
37

SublimeLinter-contrib-zig-check

SublimeLinter plugin for Zig built-in linter (zig ast-check)
Python
1
star
38

alexkuz.github.io

HTML
1
star
39

bun-playground

Test repo to reproduce bun errors
TypeScript
1
star
40

python-rust-dprint

JavaScript
1
star
41

wds-ws-proxy-example

JavaScript
1
star
42

next-netlify-starter

JavaScript
1
star
43

nextjs-netlify-blog-template

TypeScript
1
star
44

shell-menu

Shell function for interactive menu
Shell
1
star
45

promisegate

Limits promise concurrency
JavaScript
1
star
46

micro-flag-icons

Collection of minimal country flag svg images
HTML
1
star