Giter VIP home page Giter VIP logo

ring-chart's Issues

[Suggestion] using css radial-gradient instead of creating elements for sections

you can simplify your current implementation, by removing the creation of sections as elements in the DOM.
(because then you need to actually style them, rotate them etc.)

you can use the css radial-gradient property (it even has very good browser support)
to style a single DOM element in the desired pie/ring effect, by using multiple stops (of different sizes) on the same linear gradient.

a demo of how its done can be seen here: https://bennettfeely.com/csspiechart/

[Suggestion] allowing sum of sections to be different than 1.

Sum of section percentages must be equal to 1

you should be able to draw a pie chart even if the sum of total sections is not equal to 1,
by normalizing the given percentages to 1.

example 1 (when the total sum is greater than 1):
[{"color": red, "percentage": 1}, {"color": blue, "percentage": 1}] => should resolve into 0.5 for each of the sections.

example 2 (when the sum is smaller than 1):
[{"color": red, "percentage": 0.5}, {"color": blue, "percentage": 0.25}] => should resolve into 0.66 for red, and 0.33 for blue.

the general way to do that calculation:
you can calculate the total sum of all percentages.
const allPercentages = sections.map(s => s.percentage).reduce((sum, i) => sum + i, 0);

and then recalculate the normalized percentage for each section to be: const normalizedPercentage = percentage / allPercentages.

as a side-effect, you also gain the ability to pass the percentage as "whole numbers" like 50, 75 etc. (representing 50%, 75%).
because now they don't have a restriction that force then to sum to 1.

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.