Git Product home page Git Product logo

react-minimal-pie-chart's Introduction

React minimal pie chart

Build Status Npm version Coveralls Bundle size

Lightweight React SVG pie charts, with versatile options and CSS animation included. < 2kB gzipped. πŸ‘ Demo πŸ‘.

React minimal pie chart preview

Why?

Because Recharts is awesome, but when you just need a simple pie/donought chart, 3kB 2kB are usually enough.

Size
by Bundlefobia
Benchmark Size * Loading time
on a slow 3g *
react-minimal-pie-chart (v8.4.0) Bundle size: React minimal pie chart 1.93 KB ~39 ms
rechart (v1.8.5) Bundle size: Recharts 96.9 KB ~1900 ms
victory-pie (v34.1.3) Bundle size: Victory pie 50.5 KB ~1100 ms
react-apexcharts (v1.3.7) Bundle size: React apec charts 114.6 KB ~2300 ms
react-vis (v1.11.7) Bundle size: React vis 78.3 KB ~1600 ms

* Benchmark carried out with size-limit with a "real-world" setup: see benchmark repo. (What matter here are not absolute values but the relation between magnitudes)

Features

  • < 2kB gzipped
  • Versatile: Pie, Donut, Loading, Completion charts (see Demo)
  • Customizable chart labels and CSS animations
  • Written in Typescript
  • No dependencies

Installation

npm install react-minimal-pie-chart

If you don't use a package manager, react-minimal-pie-chart exposes also an UMD module ready for the browser.

https://unpkg.com/react-minimal-pie-chart/dist/index.js

Minimum supported Typescript version: >= 3.8

Usage

import { PieChart } from 'react-minimal-pie-chart';

<PieChart
  data={[
    { title: 'One', value: 10, color: '#E38627' },
    { title: 'Two', value: 15, color: '#C13C37' },
    { title: 'Three', value: 20, color: '#6A2135' },
  ]}
/>;

Options

Property Type Description Default
data DataEntry[] Source data. Each entry represents a chart segment []
lineWidth number (%) Line width of each segment. Percentage of chart's radius 100
startAngle number Start angle of first segment 0
lengthAngle number Total angle taken by the chart (can be negative to make the chart clockwise!) 360
totalValue number Total value represented by the full chart -
paddingAngle number Angle between two segments -
rounded boolean Round line caps of each segment -
segmentsShift number
or:
(segmentIndex) => number
Translates segments radially. If number set, provide shift value relative to viewBoxSize space. If function, return a value for each segment.
(radius prop might be adjusted to prevent segments from overflowing chart's boundaries)
-
segmentsStyle CSSObject
or:
(segmentIndex) => CSSObject
Style object assigned to each segment. If function, return a value for each segment. (Warning: SVG only supports its own CSS props). -
segmentsTabIndex number tabindex attribute assigned to segments -
label (labelRenderProps) => string | number | ReactElement A function returning a label value or the SVG element to be rendered as label -
labelPosition number (%) Label position from origin. Percentage of chart's radius (50 === middle point) 50
labelStyle CSSObject
or:
(segmentIndex) => CSSObject
Style object assigned to each label. If function set, return style for each label. (Warning: SVG only supports its own CSS props). -
animate boolean Animate segments on component mount -
animationDuration number Animation duration in ms 500
animationEasing string A CSS easing function ease-out
reveal number (%) Turn on CSS animation and reveal just a percentage of each segment -
background string Segments' background color -
children ReactElement (svg) Elements rendered as children of SVG element (eg. SVG defs and gradient elements) -
radius number (user units) Radius of the pie (relative to viewBoxSize space) 50
center [number, number] x and y coordinates of center (relative to viewBoxSize space) [50, 50]
viewBoxSize [number, number] width and height of SVG viewBox attribute [100, 100]
onBlur (e, segmentIndex) => void onBlur event handler for each segment -
onClick (e, segmentIndex) => void onClick event handler for each segment -
onFocus (e, segmentIndex) => void onFocus event handler for each segment -
onKeyDown (e, segmentIndex) => void onKeyDown event handler for each segment -
onMouseOut (e, segmentIndex) => void onMouseOut event handler for each segment -
onMouseOver (e, segmentIndex) => void onMouseOver event handler for each segment -
.oOo.oOo.oOo.oOo.oOo.oOo.oOo.

Prop types are exposed for convenience:

import type { PieChartProps } from 'react-minimal-pie-chart';

About data prop

data prop expects an array of chart entries as follows:

type Data = {
  color: string;
  value: number;
  key?: string | number;
  title?: string | number;
  [key: string]: any;
}[];

Each entry accepts any custom property plus the following optional ones:

Custom labels with label render prop

label prop accepts a function returning the string, number or element rendered as label for each segment:

<PieChart
  label={(labelRenderProps: LabelRenderProps) =>
    number | string | React.ReactElement | undefined | null
  }
/>

The function receives labelRenderProps object as single argument:

type LabelRenderProps = {
  x: number;
  y: number;
  dx: number;
  dy: number;
  textAnchor: string;
  dataEntry: {
    ...props.data[dataIndex]
    // props.data entry relative to the label extended with:
    startAngle: number;
    degrees: number;
    percentage: number;
  };
  dataIndex: number;
  style: React.CSSProperties;
};

Label prop, common scenarios

Render entries' values as labels:

label={({ dataEntry }) => dataEntry.value}

Render segment's percentage as labels:

label={({ dataEntry }) => `${Math.round(dataEntry.percentage)} %`}

See examples in the demo source.

How to

User interactions with the chart

See demo and relative source here and here.

Custom tooltip

See demo and relative source.

Browsers support

Here is an updated browsers support list πŸ”.

The main requirement of this library is an accurate rendering of SVG Stroke properties.

Please consider that Math.sign and Object.assign polyfills are required to support legacy browsers.

Misc

How svg arc paths work?

How SVG animations work?

This library uses the stroke-dasharray + stroke-dashoffset animation strategy described here.

Todo's

  • Consider moving storybook deployment to CI
  • Consider using transform to mutate segments/labels positions
  • Consider abstracting React bindings to re-use business logic with other frameworks
  • Provide a way to supply svg element with any extra prop
  • Find a better solution to assign default props

Contributors

Thanks to you all (emoji key):


Andrea Carraro

πŸ’» πŸ“– πŸš‡ ⚠️ πŸ‘€

Stephane Rufer

πŸ› πŸ’»

JΓΈrgen Aaberg

πŸ’»

Tobiah Rex

πŸ›

Edward Xiao

πŸ›

David Konsumer

πŸ’» πŸ“– πŸ’‘ πŸ€”

Ori

πŸ€”

Emmanouil Konstantinidis

πŸ›

yuruc

πŸ’»

luca-esse

πŸ›

Oscar Mendoza

πŸ› πŸ’»

damien-git

πŸ› πŸ€”

Vianney Stroebel

πŸ› πŸ€”

Maxime Zielony

πŸ› πŸ’»

Raz Kedem

πŸ›

Blocksmith

πŸ›

Jamie Talbot

πŸ›

Oscar Yixuan Chen

πŸ›

RuiRocha1991

πŸ›

Roman Kushyn

πŸ›

Divjot Singh

πŸ’»

react-minimal-pie-chart's People

Contributors

jaaberg avatar jonasws avatar konsumer avatar osuka42g avatar renovate-bot avatar renovate[bot] avatar rufman avatar toomuchdesign avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-minimal-pie-chart's Issues

Typescript error: Generic type 'ReactElement<P>' requires 1 type argument(s)

Do you want to request a feature or report a bug?

Bug

What is the current behaviour?

When building in a typescript environment, Typescript throws an error:

/my-project/node_modules/react-minimal-pie-chart/src/types/index.d.ts
Type error: Generic type 'ReactElement<P>' requires 1 type argument(s).  TS2314

    35 | declare type LabelPropAsFunction = (
    36 |   labelProps: LabelProps
  > 37 | ) => number | string | React.ReactElement;
       |                        ^
    38 |
    39 | declare type EventHandler = (
    40 |   event: React.MouseEvent,

What is the expected behaviour?

I expect Typescript to compile the library successfully.

Steps to Reproduce the Problem

Attempt to compile the library in a Typescript environment with React at ^16.8.4.

label block onClick

Do you want to request a feature or report a bug?

bug

What is the current behaviour?

when label and onClick props are used, clicks on label do nothing

What is the expected behaviour?

onClick function call

Steps to Reproduce the Problem

  1. Create PieChart with label and onClick props
  2. click
  3. ...

Specifications

  • Version: 5.0.1
  • Platform: Google Chrome 77.0.3865.90
  • Subsystem: Windows10

Chartboost delegate issue react native

I have integrated chartboost in my react native app. I am facing an issue. When i go to my screen where i have implemented chartboost delegate and came back to previous screen and then go again to that screen delegated methods will call 2 times and it keeps on increasing as i go back and forth. Result is i get multiple callbacks in rewarded video. Can anyone help how to disable chartboost on ComponentwillUnmount? (https://gyazo.com/2a3628505aed02abcf08f8999ef8a363) Here is my code (https://gyazo.com/506b50259b475302e991155e0e91efc4).

Export issue

Used example code to check to see if it works:

import { ReactMinimalPieChart } from "react-minimal-pie-chart";

<ReactMinimalPieChart
animationDuration={500}
animationEasing="ease-out"
center={[50, 50]}
data={[
{
color: "#E38627",
title: "One",
value: 10,
},
{
color: "#C13C37",
title: "Two",
value: 15,
},
{
color: "#6A2135",
title: "Three",
value: 20,
},
]}
labelPosition={50}
lengthAngle={360}
lineWidth={15}
paddingAngle={0}
radius={50}
rounded
startAngle={0}
viewBoxSize={[100, 100]}
/>

got this error:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Percentage labels example causes Typescript errors

Do you want to request a feature or report a bug?

report a bug
...

What is the current behaviour?

set props like the Percentage labels story:

<PieChart
      data={dataMock}
      label={({ data, dataIndex }) =>
        Math.round(data[dataIndex].percentage) + '%'
      }
      labelStyle={defaultLabelStyle}
    />

Typescript complains with:

Type '({ data, dataIndex }: Props) => string' is not assignable to type 'boolean | (false & LabelPropAsReactElement) | (false & LabelPropAsFunction) | (true & LabelPropAsReactElement) | (true & LabelPropAsFunction) | undefined'.
  Type '({ data, dataIndex }: Props) => string' is not assignable to type 'false & LabelPropAsFunction'.
    Type '({ data, dataIndex }: Props) => string' is not assignable to type 'false'.ts(2322)

...

What is the expected behaviour?

The example works as expected.
...

Steps to Reproduce the Problem

  1. use label={({ data, dataIndex }) => Math.round(data[dataIndex].percentage) + '%'}
  2. Observe the error in VSCode

Specifications

  • Version: 7.3.0
  • Platform: Typescript 3.8.3

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

Bad display on Edge / Firefox

When the Pie is animated, the drawing part is not properly display on Firefox and Edge.

Screenshot_2019-09-02 Storybook

Specifications

  • Version: 5.0.0
  • Platforms: Firefox Quantum 68.0.2/Microsoft Edge 44.17763.1.0
  • Subsystem: Windows 10

Link in README.md to source code of demo is broken

Do you want to request a feature or report a bug?

bug
...

What is the current behaviour?

Link in README.md to source code of demo is broken.
...

What is the expected behaviour?

Link should go to source code file page (github.com/...../stories/index.js);
...

Steps to Reproduce the Problem

  1. in README.md file, change current link stored in variable [demo-interaction-source] from:
    "https://github.com/toomuchdesign/react-minimal-pie-chart/blob/v3.1.0/stories/index.js#L25"
    to:
    "https://github.com/toomuchdesign/react-minimal-pie-chart/blob/master/stories/index.js".

Specifications

  • Version:
  • Platform:
  • Subsystem:

Thanks for this cool component!!

Tiny slices are not rendered correctly on Chrome

Do you want to request a feature or report a bug?

This is a rendering bug

What is the current behaviour?

When rendering a lot of really small slices weird artefacts are drawn

Screenshot 2020-03-25 at 19 27 41

What is the expected behaviour?

No artefacts, maybe provide an option to ignore/hide super small slice (below a ceiling % value)

Steps to Reproduce the Problem

<ReactPieChart data={ [{"value":2421,"title":"a","color":"rgb(33, 150, 243)"},{"value":2413,"title":"a","color":"rgb(34, 150, 243)"},{"value":2403,"title":"a","color":"rgb(34, 151, 243)"},{"value":2399,"title":"a","color":"rgb(34, 151, 243)"},{"value":2395,"title":"a","color":"rgb(35, 151, 243)"},{"value":2387,"title":"a","color":"rgb(35, 151, 243)"},{"value":2383,"title":"a","color":"rgb(35, 151, 243)"},{"value":2380,"title":"a","color":"rgb(36, 151, 243)"},{"value":2373,"title":"a","color":"rgb(36, 151, 243)"},{"value":2373,"title":"a","color":"rgb(36, 151, 243)"},{"value":2360,"title":"a","color":"rgb(37, 152, 243)"},{"value":2359,"title":"a","color":"rgb(37, 152, 243)"},{"value":2354,"title":"a","color":"rgb(37, 152, 243)"},{"value":2349,"title":"a","color":"rgb(38, 152, 243)"},{"value":2345,"title":"a","color":"rgb(38, 152, 243)"},{"value":2312,"title":"a","color":"rgb(40, 153, 243)"},{"value":136,"title":"a","color":"rgb(178, 218, 251)"},{"value":136,"title":"a","color":"rgb(178, 218, 251)"},{"value":103,"title":"a","color":"rgb(181, 219, 251)"},{"value":101,"title":"a","color":"rgb(181, 219, 251)"},{"value":101,"title":"a","color":"rgb(181, 219, 251)"},{"value":101,"title":"a","color":"rgb(181, 219, 251)"},{"value":34,"title":"a","color":"rgb(185, 221, 251)"},{"value":34,"title":"a","color":"rgb(185, 221, 251)"},{"value":34,"title":"a","color":"rgb(185, 221, 251)"},{"value":33,"title":"a","color":"rgb(185, 221, 251)"},{"value":33,"title":"a","color":"rgb(185, 221, 251)"},{"value":33,"title":"a","color":"rgb(185, 221, 251)"},{"value":33,"title":"a","color":"rgb(185, 221, 251)"},{"value":33,"title":"a","color":"rgb(185, 221, 251)"},{"value":33,"title":"a","color":"rgb(185, 221, 251)"},{"value":32,"title":"a","color":"rgb(185, 221, 251)"},{"value":32,"title":"a","color":"rgb(185, 221, 251)"},{"value":8,"title":"a","color":"rgb(187, 222, 251)"},{"value":7,"title":"a","color":"rgb(187, 222, 251)"},{"value":7,"title":"a","color":"rgb(187, 222, 251)"},{"value":5,"title":"a","color":"rgb(187, 222, 251)"},{"value":4,"title":"a","color":"rgb(187, 222, 251)"},{"value":2,"title":"a","color":"rgb(187, 222, 251)"},{"value":2,"title":"a","color":"rgb(187, 222, 251)"},{"value":2,"title":"a","color":"rgb(187, 222, 251)"},{"value":2,"title":"a","color":"rgb(187, 222, 251)"},{"value":2,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"},{"value":1,"title":"a","color":"rgb(187, 222, 251)"}] } />

Suggested fix

Rounding the percent seems to be fixing the issue.
Line 266
const valueInPercentage = total === 0 ? 0 : ( dataEntry.value / total * 100 ).toFixed();

Specifications

  • Version: 6.0.1 (latest available
  • Platform: OSX Mojave, Chrome (80.0.3987.132)

First sector not at 0 degrees

https://i.imgur.com/RIIGOJA.png

                    <PieChart lineWidth={30} startAngle={0}
                        data={[
                            { value: 69, key: 0, color: '#10ac84' }, // green
                            { value: 25, key: 1, color: '#2e86de' }, // db
                            { value: 23, key: 2, color: '#ee5253' }, // red
                            { value: 4, key: 3, color: '#0abde3' }, // lb
                        ]}
                    />

The green sector should start at 0 degrees, although it is not. It is at the bottom? Why is this and can it be fixed?

not showing data labels

Do you want to request a feature or report a bug?

bug

What is the current behaviour?

not showing data labels
<PieChart data={[ { title: 'One', value: 10, color: '#E38627' }, { title: 'Two', value: 15, color: '#C13C37' }, { title: 'Three', value: 20, color: '#6A2135' }, ]} />;
https://i.imgur.com/RvnjwzU.png

What is the expected behaviour?

https://imgur.com/V3cYNEP

Steps to Reproduce the Problem

  1. npm install react-minimal-pie-chart
  2. run example code
  3. ...

How i partially solved

Adding
label={(props) => { return props.dataEntry.title;}}

Example
<PieChart label={(props) => { return props.dataEntry.title;}} data={[{ title: "One", value: 10, color: "#E38627" }, { title: "Two", value: 15, color: "#C13C37" }, { title: "Three", value: 20, color: "#6A2135" }, ]} />

Specifications

  • Version: "react": "^16.13.1",
  • Platform: windows 10
  • Subsystem: none

Slices disappearing in Safari

Do you want to request a feature or report a bug?

Reporting a bug.

What is the current behaviour?

Slices disappear on package v6.0.1 | Safari Version 13.0.5 (14608.5.12)

Rolled back to package v5.0.2 and the issue is gone.

Steps to Reproduce the Problem

<PieChart animate animationDuration={500} animationEasing="ease-out" data={data} />

Kapture 2020-03-09 at 13 45 57

IE support

I suggest that modify your "animate Description" markdown to "Animate sectors on component mount(IE9 would not work properly if set to true)" kind of instruction, which could save a lot of times for people that searching for IE support.

Feature Request: Animate on data change

Do you want to request a feature or report a bug?

Feature

If I set the "animate" Poperty to true, the chart will be nicely built up at start. Now the user can change the data of the chart and I would like to animate these changes.Now if I only change the data of the chart, it will be displayed correctly, but unfortunately no animation happens.

[Question] Is there a way to trigger animation when chart comes into view?

Do you want to request a feature or report a bug?

A question

What is the current behaviour?

When animating a chart, is there a way to have the animation only run when the chart is scrolled into view, not just straight away on page load? If it's out of viewport, you miss the animation.

What is the expected behaviour?

Some way to "delay" the animation until the chart is in view?

Steps to Reproduce the Problem

  1. I added a pie chart (donut) to my site, towards the bottom of the page, using the following code:
<div className="chart php">
    <PieChart
        data={[{
	    value: 65,
	    color: '#E38627'
	}]}
	totalValue={100}
	lineWidth={20}
	label
	labelStyle={{
	    fontSize: '25px',
	    fontFamily: 'sans-serif'
	}}
	labelPosition={0}
	rounded
	animate
    />
    <h3>PHP</h3>
</div>
  1. Load the page, scroll down and the chart is already sat there happily
  2. Load the page pre-scrolled down and the chart animates on load?

Specifications

  • Version:
  • Platform:
  • Subsystem:

`reveal` draws segment in the wrong direction

Do you want to request a feature or report a bug?

Bug

What is the current behaviour?

reveal prop doesn't reveal segments in the same direction as the segment itself is drawn.

In this example segments are drawn counterclockwise while reveal works clockwise.

What is the expected behaviour?

reveal should respect segment drawing direction.

Accessibility issue with browser minimum font size

Do you want to request a feature or report a bug?

Bug.

What is the current behaviour?

When a user chooses a reasonable minimum font size in Firefox, labels look enormous.
This happens because of the very small font size in labelStyle, made necessary by the small viewBox for the SVG which is not configurable. It is visible with the demo with labels, which uses a 5px font size.
I was not able to reproduce that behavior with Chromium, somehow it calculate font sizes differently in this case. But it should be possible to make it work in both browsers.

What is the expected behaviour?

Font sizes given in labelStyle should match font sizes outside of the component, so that labels are rendered in the desired size when a minimum font size in chosen by users.

Steps to Reproduce the Problem

  1. Firefox preferences - language and appearance - advanced - minimum font size: select 12px.
  2. Check the label size at https://toomuchdesign.github.io/react-minimal-pie-chart/index.html?path=/story/labels--default-labels
  3. See how different it is when no minimum font size is selected, even though it never matches the expected minimum size visually.

Specifications

  • Version: 5.0.1
  • Platform: Node 12, Firefox 70
  • Subsystem:

View config not found for name path

Do you want to request a feature or report a bug?

Report a bug
...

What is the current behaviour?

Getting issue in rendering PieChart. After deep debugging and stackoverflow it seems path component in ReactMinimalPieChartPath should be capitalised. Please look into this.

`Invariant Violation: Invariant Violation: Invariant Violation: View config not found for name path

This error is located at:
in path (created by ReactMinimalPieChartPath)
in ReactMinimalPieChartPath (created by ReactMinimalPieChart)
in svg (created by ReactMinimalPieChart)
in div (created by ReactMinimalPieChart)
in ReactMinimalPieChart (at StandardScreen.js:30)
in RCTView (at View.js:60)
in View (at StandardScreen.js:17)
in StandardScreen (at SceneView.js:9)
in SceneView (at createTabNavigator.js:38)
in RCTView (at View.js:60)
in View (created by ViewPagerAndroid)
in AndroidViewPager (at ViewPagerAndroid.android.js:236)
in ViewPagerAndroid (at PagerAndroid.js:148)
in PagerAndroid (at TabView.js:60)
in RCTView (at View.js:60)
in View (at TabView.js:191)
in RCTView (at View.js:60)
in View (at TabView.js:189)
in TabView (at createMaterialTopTabNavigator.js:246)
in MaterialTabView (at createTabNavigator.js:177)
in NavigationView (at createNavigator.js:62)
in Navigator (at createAppContainer.js:383)
in NavigationContainer (at EmiCalculatorTabScreen.js:64)
in WrapperScreen (created by Connect(WrapperScreen))
in Connect(WrapperScreen) (at EmiCalculatorBaseContainer.js:51)
in EmiCalculatorBaseContainer (created by Connect(EmiCalculatorBaseContainer))
in Connect(EmiCalculatorBaseContainer) (at EmiCalculatorEntryPoint.js:74)
in Provider (at EmiCalculatorEntryPoint.js:73)
in EmiCalculatorEntryPoint (at SceneView.js:9)
in SceneView (at StackViewLayout.js:763)
in RCTView (at View.js:60)
in View (at StackViewLayout.js:762)
in RCTView (at View.js:60)
in View (at StackViewLayout.js:761)
in RCTView (at View.js:60)
in View (at createAnimatedComponent.js:154)`
...

What is the expected behaviour?

It should be rendered properly. I believe this path needs to be capitalised.
...

Steps to Reproduce the Problem

  1. I just added this library and this code
    `import PieChart from 'react-minimal-pie-chart';

<PieChart
data={[
{ title: 'One', value: 10, color: '#E38627' },
{ title: 'Two', value: 15, color: '#C13C37' },
{ title: 'Three', value: 20, color: '#6A2135' },
]}
/>;`

Specifications

  • react-minimal-pie-chart : ^3.3.0
  • react-native: 0.55.4

Segments edges rendering issues

The way some browsers render SVG paths cause a few visual issues especially when when full pies are rendered:

64119904-2d96e700-cd9b-11e9-9663-fa4cb1425524

More specifically a few OS/browser combinations seem to not being able to render SVG stroke line caps precisely enough. Here is a list browsers where issues where reported and reproduced.

OS Browser Issue
iOS iOS Safari full pie charts visual glitch when animate !== true
Windows 10 Firefox v68+ full pie charts visual glitch when animate === true

Somehow SVG stroke-dasharray property is the key here but different browsers react in opposite ways so that I can't currently see an easy patch not involving browser detection.

stroke-dasharray + stroke-dashoffset are currently only appended when animation is enabled.

Partially supported

OS Browser Issue
Windows 10 Edge ≀ v44 animation === true breaks visually

Not supported

  • IE ≀ 10

Related issues

Math.sign doesn't get polyfilled

Do you want to request a feature or report a bug?

Bug

What is the current behaviour?

Math.sign is not supported by any ie version and it gets bundled not transpiled nor polyfilled.

What is the expected behaviour?

ie11 compatibility.

CustomLabel issue

Hello i have an issue with CustomLabel, because it's not shown.
I want to use it as a ReactElement

const data = [
        { value: 20, key: 1, color: '#23e4ad',}, 
    ];
return <PieChart 
                data={data}
                reveal={percantage}
                lineWidth={10}
                background="#555862"
                lengthAngle={280}
                totalValue={100}
                startAngle={130}
                labelPosition={0}
                radius={40}
                rounded
                animate
                label={<ChartLabel/>}

and here is my CustomLabel, ChartLabel

export default function ChartLabel(labelProps) {
    console.log(labelProps );
    return <div>
        <span>100%</span>
        <span>extra data</span>
    </div>
}

Thanks)

Allow float/string `0.0`

I need to use strings like 12.5 and 0.0 which works fine but fills the console with errors.
Is there a way to ignore this?

Warning: Failed prop type: Invalid prop `data[0].value` of 
type `string` supplied to `ReactMinimalPieChart`, expected `number`.

Gradients for pie chart segments

Do you want to request a feature or report a bug?

Requesting a feature.

What is the current behaviour?

Currently, gradients are not supported. That is, segments in the pie chart can only be of a single color.

What is the expected behaviour?

I know that you're trying to keep things simple (it is minimal after all), but even the possibility of injecting defs into the SVG via another property on the PieChart component to define our own gradients (and then reference them with the color property) would be awesome. Just an idea!

renderLabel is not a function

Do you want to request a feature or report a bug?

bug
...

What is the current behaviour?

renderLabel is not a function

...

What is the expected behaviour?

label renders

...

Steps to Reproduce the Problem

            <PieChart
                animationDuration={500}
                animationEasing="ease-out"
                center={[50, 50]}
                data={[
                    {
                        color: '#009CDE',
                        title: 'Two',
                        value: 50,
                    },
                    {
                        color: '#71C5E8',
                        title: 'Three',
                        value: 50,
                    },
                ]}
                labelPosition={50}
                label={'hi'}
                lengthAngle={360}
                lineWidth={15}
                paddingAngle={0}
                radius={50}
                startAngle={0}
                viewBoxSize={[100, 100]}
            />
        </div>

Specifications

  • Version:
  • Platform:
  • Subsystem:

IE syntax error

Do you want to request a feature or report a bug?

Bug

What is the current behaviour?

Importing react-minimal-pie-chart causes a syntax error on IE 11

Steps to Reproduce the Problem

The problem is reproducible even in the storybook with IE 11

Specifications

  • Version: 4.1.0, 4.0.0
  • Platform: IE 11

Piechart is 300px by default, how can I make it smaller ?

Do you want to request a feature or report a bug?

Info request

What is the current behaviour?

The piechart has a default size of 300px and I cannot make it smaller

What is the expected behaviour?

A smaller piechart. I couldn't find any setting to reduce it

Steps to Reproduce the Problem

  1. Make a piechart
  2. The piechart is too big
  3. Sadness

not able to add custom classNames to define color by variable

Do you want to request a feature or report a bug?

...not able to add custom classNames to define color by variable

What is the current behaviour?

...data={[{
title: 'One',
value: 82,
color: '#007DCD'
}]}

What is the expected behaviour?

...data={[{
title: 'One',
value: 82,
color: {theme.palette.secondary.main}
}]}

Steps to Reproduce the Problem

Specifications

Import package with react-scripts-ts

Do you want to request a feature or report a bug?

A bug?

What is the current behaviour?

I am trying to render a PieChart component in a test, something like this:

import { mount } from "enzyme";
import * as React from "react";
import PieChart from "react-minimal-pie-chart";

it("renders a pie chart", () => {
  mount(<PieChart data={[{ value: 1, color: "blue" }]} />);
});

But when I try to execute it I get:

    Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

I think the error is related to how the code is imported but I am not sure what could be the reason.

I am using "typescript": "^3.7.2" and "react-minimal-pie-chart": "^6.0.1".

What is the expected behaviour?

To be able to render a PieChart using jest

Steps to Reproduce the Problem

(Explained above, let me know if it's not reproducible)

Note that the code works as expected in the functional code, which is why I am confused.

labelPosition is broken in 7.3.0

Do you want to request a feature or report a bug?

report a bug
...

What is the current behaviour?

Run the default labels example and observe the labels are all collapsed in the middle of the image.

...

What is the expected behaviour?

The labels appear in the correctly specified position.

...

Steps to Reproduce the Problem

  1. Copy the props defined the default labels story.
  2. Observe all the labels collapsed on top of each other.

The issue doesn't occur in 7.2.0

Specifications

  • Version: 7.3.0

Adding custom generic labels like in recharts library

Hi,
I would like to thank you for the great work on the library. We are currently using recharts library to draw a donut chart in our project. It works as expected, but its bundle size is extremely huge for visualizing only donut chart. We decided to move away from it and I was happy to find this library. It has the smallest bundle size among pie chart libraries.

I've tried to implement the same donut chart using react-minimal-pie-chart library, but I stuck with the following issue. It seems that rendering of a label is applied to every data item. I have attached our current implementation of the donut chart using recharts.
Donut chart 1
Donut chart 2

  1. Is it possible to add generic label outside of the chart that is rendered only once? (refer to the 1st rectangle on the picture)
  2. Is it possible to add a generic label in the middle of the chart that is rendered only once? ( refer to the 2nd rectangle on the picture)
  3. For some reason, I cannot add stroke property to donut segment on the chart. Is it possible to do it in the current release of the library
  4. I have tested animation feature on IE11 browser and it doesn't work. Are there any solutions to make it work in IE11?

Pie Chart parts are losing proportions after animation

Do you want to request a feature or report a bug?

I believe this is a bug
...

What is the current behaviour?

when animation prop is set to TRUE the first Pie Chart part is losing his propotion and his not Straight as without animation.
I checked this on both Chrome and Firefox.

also, I have seen this behaviour in the documentation.
...

What is the expected behaviour?

Straight-line as without the animation when animation prop is set to TRUE
...

Steps to Reproduce the Problem

  1. ...
    with animation

no-animation

  1. ...
  2. ...

Specifications

  • Version: Latest one
  • Platform:
  • Subsystem:

Assign random colors to segments

Hi,

I look for implement Dynamically Allocate Colors in my project with React minimal pie chart.

Have you an exemple?

What do you think to add a Dynamically Allocate Colors example in storybook?

Best regards,
StΓ©phane

Labels vertical alignment: dominant-baseline middle vs. central

Do you want to request a feature or report a bug?

Probably a bug

What is the current behaviour?

Labels vertical alignment relies on CSS prop dominant-baseline](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/dominant-baseline) === middle

What is the expected behaviour?

Labels might use dominant-baseline === central which seems to better align vertically.

It would be a breaking change. Therefore let's wait for the next major.

Doughnut chart

chart

Hi, thanks for your library :)
I wanna create chart like on image above

blue progress should always start from 12 oclock
other part of chart should be filled with silver

is it possible?

I tried a bit with code below, but its not what I need

    <ReactMinimalPieChart
            className="chart-shadow"
            data={[
              {
                title: 'Your progress',
                value: 10,
                color: '#40d3e3'
              }
            ]}
            lineWidth={40}
            rounded
            animate
            totalValue={100}
            lengthAngle={-360}
       />

Typescript error when importing

Bit easier to say it without issue template:

I used create-react-app with --template typescript, it installs typescript v3.7.3, and using this version I got:

import {PieChart} from "react-minimal-pie-chart"

Is causing this error:

TypeScript error in .../node_modules/react-minimal-pie-chart/types/Chart/Chart.d.ts(1,13):
'=' expected.  TS1005

  > 1 | import type { CSSProperties, FocusEvent, KeyboardEvent, MouseEvent, ReactNode } from 'react';
      |             ^
    2 | import type { Data, EventHandler, LabelRenderFunction } from '../commonTypes';
    3 | declare type Props = {
    4 |     animate?: boolean;

Fixed it by changing typescript version to 3.8.3, in fact it's not a bad thing to not support older version, but it was confusing

cancel all subscriptions and asynchronous tasks in the componentWillUnmount method

I've encountered this problem

image

Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
in ReactMinimalPieChart (created by Index)
in div (created by Index)
in div (created by Index)
in div (created by Index)
in div (created by Index)
in div (created by Index)
in div (created by Index)
in div (created by Index)
in div (created by Index)
in div (created by Index)
in Index (created by Connect(Index))
in Connect(Index) (created by AsyncRoute)
in AsyncRoute (created by Route)

Not sure if is the component issue. If it is, maybe you can cancel the asynchronous tasks in the componentWillUnmount?

Thx

Prop type for Chart enforces optional props

Do you want to request a feature or report a bug?

Bug

What is the current behaviour?

Omitting optional props throws warnings in the IDE

What is the expected behaviour?

To not throw any warnings if I omit optional props

Steps to Reproduce the Problem

Create any Chart component and omit any of the props defined here

The change to the props was introduced in this commit and effectively makes these props required.

Specifications

  • Version: 8.0.0

It would be my pleasure to open a PR in order to fix this

image

Using string instead of a numeric for slice labels

How can a string be used for a label text? I was expecting "Placeholder" to be displayed in all slices using the code below.

               <ReactMinimalPieChart
                  cx={50}
                  cy={40}
                  data={this.state.piechart_data}
                  label={"Placeholder"}
                  labelPosition={72}
                  labelStyle={{
                    fill: 'white',
                    fontFamily: 'Arial',
                    fontSize: '2.5px'
                  }}

Bad Import

import PieChart from 'react-minimal-pie-chart'

Throws error: Unable to resolve path to module 'react-minimal-pie-chart'.

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.