Skip to content

Commit

Permalink
feat(pie): add story to showcase custom layers
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Nov 4, 2020
1 parent 92f19c2 commit 17b129d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/pie/stories/pie.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,38 @@ stories.add(
}
)

const CenteredMetric = ({ dataWithArc, centerX, centerY }) => {
let total = 0
dataWithArc.forEach(datum => {
total += datum.value
})

return (
<text
x={centerX}
y={centerY}
textAnchor="middle"
dominantBaseline="central"
style={{
fontSize: '52px',
fontWeight: '600',
}}
>
{total}
</text>
)
}

stories.add('adding a metric in the center using a custom layer', () => (
<Pie
{...commonProperties}
innerRadius={0.8}
enableSliceLabels={false}
radialLabel={d => `${d.id} (${d.formattedValue})`}
layers={['slices', 'sliceLabels', 'radialLabels', 'legends', CenteredMetric]}
/>
))

stories.add('formatted tooltip values', () => (
<Pie
{...commonProperties}
Expand Down
2 changes: 2 additions & 0 deletions website/src/data/components/pie/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Pie:
stories:
- label: Using colors from data
link: pie--using-colors-from-data
- label: Adding a metric in the center using a custom layer
link: pie--adding-a-metric-in-the-center-using-a-custom-layer
description: |
Generates a pie chart from an array of data, each datum must have an
id and a value property.
Expand Down

0 comments on commit 17b129d

Please sign in to comment.