import React, { useState, Fragment } from 'react'; import { PieChart } from 'reaviz'; import { categoryData, randomNumber, browserData, icons } from 'reaviz-data-utils'; import { PieArc, PieArcLabel, PieArcSeries } from 'reaviz'; import { ChartShallowDataShape } from 'reaviz'; import { Gradient } from 'reaviz'; export default { tags: ['snapshot'], title: 'Charts/Pie Chart/Pie', component: PieChart, subcomponents: { PieArc, PieArcLabel, PieArcSeries } }; interface ChartDataItem extends ChartShallowDataShape { key: string; metadata: { description: string; Icon?: React.ComponentType; }; } const labelData: ChartDataItem[] = [ { key: 'Chrome', data: 25000, metadata: { description: 'Chrome description', Icon: icons.Chrome } }, { key: 'Safari', data: 2000, metadata: { description: 'Safari description', Icon: icons.Safari } }, { key: 'FireFox', data: 2000, metadata: { description: 'FireFox description', Icon: icons.FireFox } }, { key: 'Edge', data: 2000, metadata: { description: 'Edge description', Icon: icons.Edge } }, { key: 'Github', data: 2000, metadata: { description: 'Github description', Icon: icons.Github } }, { key: 'ReactJs', data: 2000, metadata: { description: 'React with really really long description', Icon: icons.ReactJs } }, { key: 'Android', data: 2000, metadata: { description: 'Android description', Icon: icons.Android } }, { key: 'Apple', data: 2000, metadata: { description: 'Apple description', Icon: icons.Apple } }, { key: 'Ubuntu', data: 2000, metadata: { description: 'Ubuntu description', Icon: icons.Ubuntu } }, { key: 'Windows', data: 2000, metadata: { description: 'Windows description', Icon: icons.Windows } }, { key: 'Other', data: 500, metadata: { description: 'Other item, that should not have label' } } ]; export const Simple = () => ( } /> ); export const Explode = () => ( } /> ); export const NoAnimation = () => ( } data={browserData} /> ); export const HtmlLabels = () => { return (
( : null} textAnchor={textAnchor} showText={false} /> )} /> } arc={} /> } />
); }; export const TextPlusIconLabels = () => { return (
( : null} textAnchor={textAnchor} showText /> )} /> } arc={} /> } />
); }; export const LabelOverlap = () => ( ({ key: index + 1, data: 1 }))} /> ); export const DisplayAllLabels = () => ( ); export const WithGradient = () => ( } />} />} /> ); export const LiveUpdating = () => ; export const Autosize = () => (
); const LiveUpdatingStory = () => { const [data, setData] = useState([...categoryData]); const updateData = () => { const newData = [...data]; const updateCount = randomNumber(1, 4); let idx = 0; while (idx <= updateCount) { const updateIndex = randomNumber(0, data.length - 1); newData[updateIndex] = { ...newData[updateIndex], data: randomNumber(10, 100) }; idx++; } setData(newData); }; return (
); }; const ArcLabel = React.memo(function ArcLabel({ title, description, data, icon, textAnchor, showText }: { title: string; description: string; data: number; // the chart data value we labeling icon: React.ReactElement | null; textAnchor: 'start' | 'end'; showText: boolean; }) { const iconContainer = (
{icon}
); const ellipsis: React.CSSProperties = { whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden' }; return (
{textAnchor === 'start' && iconContainer}
{title} - {data}
{description}
{textAnchor === 'end' && iconContainer}
); });