diff --git a/src/ArcPieChart/ArcPieChart.js b/src/ArcPieChart/ArcPieChart.js new file mode 100644 index 00000000..57d7ba13 --- /dev/null +++ b/src/ArcPieChart/ArcPieChart.js @@ -0,0 +1,119 @@ +import React, { PropTypes } from 'react'; +import { PieChart, Pie, ResponsiveContainer, Text, Cell, Legend } from 'recharts'; +import styles from './ArcPieChart.styles.css'; + +class ArcPieChart extends React.Component { + constructor(props) { + super(props); + this.state = { + selectedSet: props.dataSets[0], + selectedData: props.dataSets[0].data[0], + colors: ['#75568D', '#AAA4AB'], + }; + this.getColor = this.getColor.bind(this); + this.pieLabel = this.pieLabel.bind(this); + this.selectData = this.selectData.bind(this); + this.selectSet = this.selectSet.bind(this); + } + getColor(name) { + return name === this.state.selectedData.name ? this.state.colors[0] : this.state.colors[1]; + } + pieLabel(options) { + const { cx, cy, payload } = options; + if (payload.name !== this.state.selectedData.name) { + return null; + } + return ( + + {`${payload.value}%`} + + ); + } + selectData(payload) { + this.setState(prevState => ({ + ...prevState, + selectedData: this.state.selectedSet.data.find(data => data.name === payload.name), + })); + } + selectSet(name) { + const newSet = this.props.dataSets.find(set => set.name === name); + this.setState(prevState => ({ + ...prevState, + selectedSet: newSet, + selectedData: newSet.data[0], + })); + } + render() { + return ( +
+
+ +
+ + + + { + this.state.selectedSet.data.map(data => + ) + } + + ({ + color: this.getColor(data.name), + type: 'circle', + value: data.name, + name: data.name, + }))} + wrapperStyle={{ bottom: '-35px' }} + onClick={this.selectData} + /> + + +
+ ); + } +} + +ArcPieChart.propTypes = { + dataSets: PropTypes.array, +}; + +export default ArcPieChart; diff --git a/src/ArcPieChart/ArcPieChart.styles.css b/src/ArcPieChart/ArcPieChart.styles.css new file mode 100644 index 00000000..f8cbc461 --- /dev/null +++ b/src/ArcPieChart/ArcPieChart.styles.css @@ -0,0 +1,37 @@ +.container { + color:#726371; + font-weight: bold; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +.yearsContainer { + display: flex; + justify-content: space-between; +} + +.listItem { + display: inline; + padding: 10px; + color: #AAA4AB; + flex: inherit; +} + +.link { + display: inline-block; + padding:5px; + font-size: 1.3em; +} + +.link:hover { + color: black; + cursor: pointer; +} + +.linkActive { + font-weight: bold; + color: black; + border-bottom: 3px solid black; +} diff --git a/src/index.js b/src/index.js index 5cfa8b0e..d2496798 100644 --- a/src/index.js +++ b/src/index.js @@ -17,6 +17,7 @@ export LeafletMap from './LeafletMap/LeafletMap'; export Dropdown from './Dropdown/Dropdown'; export Icon from './Icon/Icon'; export Scatterplot from './Scatterplot/Scatterplot'; +export ArcPieChart from './ArcPieChart/ArcPieChart'; // export utils as well for broader use export isClient from './utils/isClient'; diff --git a/stories/ArcPieChart.story.js b/stories/ArcPieChart.story.js new file mode 100644 index 00000000..87f453db --- /dev/null +++ b/stories/ArcPieChart.story.js @@ -0,0 +1,44 @@ +import React from 'react'; +import { storiesOf } from '@kadira/storybook'; +import { ArcPieChart } from '../src'; + +const displayName = ArcPieChart.displayName || 'ArcPieChart'; +const title = 'Simple usage'; +const description = 'Arc pie chart'; + +const dataSets = [ + { + name: 'Monsters', + data: [ + { name: 'Boggarts', value: 86 }, + { name: 'Acromantula', value: 14 }, + ], + }, + { + name: 'People', + data: [ + { name: 'Muggles', value: 50 }, + { name: 'Witches', value: 25 }, + { name: 'Wizards', value: 25 }, + ], + }, + { + name: 'Other', + data: [ + { name: 'Giants', value: 20 }, + { name: 'House Elves', value: 15 }, + { name: 'Goblins', value: 65 }, + ], + }, +]; + +const demoCode = () => ( + +); + +export default () => storiesOf(displayName, module) + .addWithInfo( + title, + description, + demoCode, + ); diff --git a/stories/index.js b/stories/index.js index fa551296..fadabd7a 100644 --- a/stories/index.js +++ b/stories/index.js @@ -19,6 +19,7 @@ import dropdownStory from './Dropdown.story'; import rechartsPie from './RechartsPie.story'; import heroStory from './Hero.story'; import scatterplotStory from './Scatterplot.story'; +import arcPieChartStory from './ArcPieChart.story'; import '../src/global.styles.css'; import '../assets/leaflet.css'; @@ -48,3 +49,4 @@ rechartsPie(); leafletMap(); heroStory(); scatterplotStory(); +arcPieChartStory();