diff --git a/packages/charts/src/components/DonutChart/index.tsx b/packages/charts/src/components/DonutChart/index.tsx index e8408c82ff8..01d9377ac5b 100644 --- a/packages/charts/src/components/DonutChart/index.tsx +++ b/packages/charts/src/components/DonutChart/index.tsx @@ -1,9 +1,10 @@ import React, { PureComponent } from 'react'; import { ChartInternalProps } from '../../interfaces/ChartInternalProps'; import { ChartBaseProps } from '../../interfaces/ChartBaseProps'; -import { mergeConfig } from '../../util/utils'; +import { populateData } from '../../util/populateData'; +import { formatTooltipLabelForPieCharts, mergeConfig } from '../../util/utils'; import { ChartBaseDefaultProps } from '../../util/ChartBaseDefaultProps'; -import { PieChart } from '../PieChart'; +import { Pie } from 'react-chartjs-2'; import { withChartContainer } from '../ChartContainer/withChartContainer'; import { PieChartPlaceholder } from '../PieChart/Placeholder'; @@ -20,15 +21,57 @@ export class DonutChart extends PureComponent { static LoadingPlaceholder = PieChartPlaceholder; render() { - const { options, ...otherProps } = this.props as DonutChartPropTypes & ChartInternalProps; + const { + labels, + datasets, + colors, + theme, + categoryAxisFormatter, + getDatasetAtEvent, + getElementAtEvent, + valueAxisFormatter, + options + } = this.props as DonutChartPropTypes & ChartInternalProps; + + const doughnut = populateData(labels, datasets, colors, theme.theme, true); const mergedOptions = mergeConfig( { - cutoutPercentage: 70 + cutoutPercentage: 70, + tooltips: { + callbacks: { + label: formatTooltipLabelForPieCharts(categoryAxisFormatter, valueAxisFormatter) + } + }, + plugins: { + datalabels: { + anchor: 'center', + align: 'center', + offset: 0, + color: (context) => { + return parseInt(context.dataset.backgroundColor[context.datasetIndex], 16) > 0xffffff / 2 + ? '#666' + : '#fff'; + }, + formatter: valueAxisFormatter + } + } }, options ); - return ; + return ( + + ); } } diff --git a/packages/charts/src/components/RadialChart/demo.stories.tsx b/packages/charts/src/components/RadialChart/demo.stories.tsx index 34581da53eb..4e735a2b29b 100644 --- a/packages/charts/src/components/RadialChart/demo.stories.tsx +++ b/packages/charts/src/components/RadialChart/demo.stories.tsx @@ -1,9 +1,18 @@ -import React from 'react'; import { storiesOf } from '@storybook/react'; +import { number, text } from '@storybook/addon-knobs'; +import React from 'react'; import { RadialChart } from './index'; function renderStory() { - return ; + return ; } -storiesOf('Charts | RadialChart', module).add('Default', renderStory); +const renderInContainer = () => ( +
+ +
+); + +storiesOf('Charts | RadialChart', module) + .add('Default', renderStory) + .add('In Container', renderInContainer); diff --git a/packages/charts/src/components/RadialChart/index.tsx b/packages/charts/src/components/RadialChart/index.tsx index 7cabbf2f2f9..9edd386d94c 100644 --- a/packages/charts/src/components/RadialChart/index.tsx +++ b/packages/charts/src/components/RadialChart/index.tsx @@ -18,7 +18,7 @@ export interface RadialChartPropTypes extends CommonProps { innerChartRef?: Ref; } -const styles = () => ({ +const styles = { radialChart: { position: 'relative' }, @@ -34,7 +34,7 @@ const styles = () => ({ pointerEvents: 'none', fontSize: '2rem' } -}); +}; @withStyles(styles) export class RadialChart extends PureComponent { @@ -46,7 +46,7 @@ export class RadialChart extends PureComponent { }; render() { - const { maxValue, value, displayValue, classes, style, className, colors, options } = this + const { maxValue, value, displayValue, classes, style, className, colors, options, width, height } = this .props as RadialChartPropTypes & ChartInternalProps; const data = [value, maxValue - value]; @@ -66,23 +66,29 @@ export class RadialChart extends PureComponent { options ); + const radialChartContainerStyles = { + width: `${width}px`, + height: `${height}px`, + ...style + }; + const outerClasses = StyleClassHelper.of(classes.radialChart); if (className) { outerClasses.put(className); } return ( -
+
-
+