🎨 Ne pas afficher les barres vides dans StackedBarChart

pull/950/head
Maxime Quandalle 2020-03-26 11:19:33 +01:00
parent 978f3ed759
commit 31d3a67614
No known key found for this signature in database
GPG Key ID: 428641C03D29CA10
1 changed files with 15 additions and 13 deletions

View File

@ -87,10 +87,8 @@ export default function StackedBarChart({ data }: StackedBarChartProps) {
const [intersectionRef, displayChart] = useDisplayOnIntersecting({
threshold: 0.5
})
data = data.filter(datum => datum.nodeValue != undefined)
const percentages = roundedPercentages(
data.map(d => d.nodeValue) as Array<number>
)
data = data.filter(d => d.nodeValue != undefined)
const percentages = roundedPercentages(data.map(d => d.nodeValue as number))
const dataWithPercentage = data.map((data, index) => ({
...data,
percentage: percentages[index]
@ -100,15 +98,19 @@ export default function StackedBarChart({ data }: StackedBarChartProps) {
return (
<animated.div ref={intersectionRef} style={styles}>
<BarStack>
{dataWithPercentage.map(({ dottedName, color, percentage }) => (
<BarItem
style={{
width: `${percentage}%`,
backgroundColor: color || 'green'
}}
key={dottedName}
/>
))}
{dataWithPercentage
// <BarItem /> has a border so we don't want to display empty bars
// (even with width 0).
.filter(({ percentage }) => percentage !== 0)
.map(({ dottedName, color, percentage }) => (
<BarItem
style={{
width: `${percentage}%`,
backgroundColor: color || 'green'
}}
key={dottedName}
/>
))}
</BarStack>
<BarStackLegend>
{dataWithPercentage.map(({ percentage, color, ...rule }) => (