simple-as-pie
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

Contributors Forks Stargazers Issues Unlicense License


Simple-As-Pie

Simple-As-Pie is a simple and lightweight open-source React.js module for displaying SVG pie charts with a dynamic data set.
View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Installation
  3. Usage
  4. Interactive Demo
  5. Roadmap
  6. Contributing
  7. License
  8. Contact
  9. Acknowledgments

About The Project

For one of my own projects I needed to create multiple pie charts to display within a single SVG element, within a React app.

Whilst I found a few examples that I could use, they were a bit limited in that they would only show one sgement at once.

Rather than spending yet more time searching for a solution that met my needs, I instead decided to create my own.

(back to top)

Built With

React Typescript Rollup

(back to top)

Installation

Within your React app's directory, install the plugin via npm or yarn

  • npm

    npm install simple-as-pie
  • yarn

    yarn add simple-as-pie

(back to top)

Usage

Import the module into your component

import { PieChart, DataSet } from 'simple-as-pie';

Construct the data for the segments

const segmentData: DataSet[] = [
  {
    value: 24,
    colour: "red",
    events: {
      onClick: myOnClickHandler
    }
  },
  {
    value: 76,
    colour: "blue"
  }
];

Create an SVG component, and call the component within it

<svg width="200px" height="200px">
  <PieChart x={100} y={100} data={segmentData} radius={75} />
</svg>

(back to top)

In Depth

This library exports two members:

  • The "DataSet" interface
  • The "PieChart" component

The DataSet represents the data in the pie chart, and has three properties:

  • value - a number representing the value of the piece of data
  • colour - a string representation of what the colour for that segment should be in the chart
  • events - an object that stores event handlers for the supported events. Currently these are Mouse, Pointer, Keyboard, Focus and Touch events.

Since DataSet is an interface it can be extended to be used in other ways within your project.

The PieChart component accepts the following properties:

  • data - an array of DataSet objects
  • x - a number for the x co-ordinate of the centre of the Pie Chart
  • y - a number for the y co-ordinate of the centre of the Pie Chart
  • radius - a number representing the radius of the Pie Chart
  • backgroundColour - an optional string representation for the background colour of the chart

(back to top)

Styling & Animations

There are no styles or animations provided out of the box, but the following classes are on the various elements:

  • The Pie Chart component - a g (group) element with the class "SimplePieChart"
  • The background - a circle with the class "SimplePieChart-background-segment"
  • Each segment of the chart - a circle if there is only one, paths otherwise. They have the class "SimplePieChart-segment"

(back to top)

Interactive Demo

There is an interactive demo available here

(back to top)

Roadmap

  • [x] Enable background colour
  • [x] Switch to paths rather than circle elements
  • [x] Enable some functions
  • [ ] Enable all appropriate functions

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Top contributors:

Made with contrib.rocks.

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Project Link: https://github.com/Arad1el/simple-as-pie/

(back to top)

Acknowledgments

(back to top)

Package Sidebar

Install

npm i simple-as-pie

Weekly Downloads

26

Version

2.1.1

License

MIT

Unpacked Size

15.9 kB

Total Files

12

Last publish

Collaborators

  • aradiel