import React, { useState, Fragment } from 'react';
import { PieChart } from 'reaviz';
import { categoryData, randomNumber } from 'reaviz-data-utils';
import { PieArc, PieArcLabel, PieArcSeries } from 'reaviz';
import { Gradient } from 'reaviz';
export default {
tags: ['snapshot'],
title: 'Charts/Pie Chart/Donut',
component: PieChart,
subcomponents: {
PieArc,
PieArcLabel,
PieArcSeries
}
};
export const Simple = () => (
}
/>
);
export const WithGradient = () => (
} />}
/>
}
/>
);
export const RoundedAndSpaced = () => (
}
/>
);
RoundedAndSpaced.story = {
name: 'Rounded and spaced'
};
export const Labels = () => (
}
/>
);
export const InnerLabel = () => (
{categoryData.length} Attacks
);
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}
);
});