# cake-chart

> Interactive multi-layer pie chart

Latest version **0.2.3** (published 2015-09-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install cake-chart
pnpm add cake-chart
yarn add cake-chart
bun add cake-chart
```

## 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.2.3 |
| Published | 2015-09-03 |
| First published | 2015-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 427 |
| Author | Alexander |
| Maintainers | alexkuz |
| Keywords | pie-chart, react |

## Links

- npm: https://www.npmjs.com/package/cake-chart
- Repository: https://github.com/alexkuz/cake-chart
- Homepage: https://github.com/alexkuz/cake-chart#readme
- Issues: https://github.com/alexkuz/cake-chart/issues
- npm.io page: https://npm.io/package/cake-chart

## Dependencies (6)

- [jss](https://npm.io/package/jss.md) ^2.1.3
- [react-jss](https://npm.io/package/react-jss.md) ^1.0.4
- [classnames](https://npm.io/package/classnames.md) ^2.1.3
- [lodash.throttle](https://npm.io/package/lodash.throttle.md) ^3.0.4
- [react-pure-render](https://npm.io/package/react-pure-render.md) ^1.0.2
- [jss-vendor-prefixer](https://npm.io/package/jss-vendor-prefixer.md) ^0.2.2

## 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.2.3 (latest) — 2015-09-03
- 0.2.2 — 2015-08-15
- 0.2.1 — 2015-08-15
- 0.2.0 — 2015-08-15
- 0.1.6 — 2015-08-10
- 0.1.5 — 2015-08-10
- 0.1.4 — 2015-08-09
- 0.1.3 — 2015-08-09
- 0.1.2 — 2015-08-09
- 0.1.1 — 2015-08-09

## README

# cake-chart

Interactive multi-layer pie chart

![](cake.png)

### Demo

[Webpack Chart](http://alexkuz.github.io/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.

```js
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

```js

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} />
    );
  }
}

---
_Source: https://npm.io/package/cake-chart · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
