Skip to content

Commit

Permalink
feat(pie): add story to showcase the ability to use colors defined in…
Browse files Browse the repository at this point in the history
… dataset
  • Loading branch information
plouc committed Nov 4, 2020
1 parent ebaf86e commit 92f19c2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
45 changes: 40 additions & 5 deletions packages/pie/stories/pie.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ stories.add('fancy slices', () => (
innerRadius={0.6}
padAngle={0.5}
cornerRadius={5}
radialLabelsLinkColor="inherit"
radialLabelsLinkColor={{
from: 'color',
}}
radialLabelsLinkStrokeWidth={3}
radialLabelsTextColor="inherit:darker(1.2)"
radialLabelsTextColor={{
from: 'color',
modifiers: [['darker', 1.2]],
}}
/>
))

Expand All @@ -65,13 +70,43 @@ stories.add('custom radial label', () => (
padAngle={0.5}
cornerRadius={5}
radialLabel={d => `${d.id}: ${d.value}`}
radialLabelsLinkColor="inherit"
radialLabelsLinkColor={{
from: 'color',
}}
radialLabelsLinkStrokeWidth={3}
radialLabelsTextColor="inherit:darker(1.2)"
enableSlicesLabels={false}
radialLabelsTextColor={{
from: 'color',
modifiers: [['darker', 1.2]],
}}
enableSliceLabels={false}
/>
))

stories.add(
'using colors from data',
() => <Pie {...commonProperties} colors={{ datum: 'data.color' }} />,
{
info: {
text: `
It is possible to use colors coming from the provided dataset instead of using
a color scheme, to do so, you should pass:
\`\`\`
colors={{ datum: 'data.color' }}
\`\`\`
given that each data point you pass has a \`color\` property.
It's also possible to pass a function if you want to handle more advanced computation:
\`\`\`
colors={(datum) => datum.color }}
\`\`\`
`,
},
}
)

stories.add('formatted tooltip values', () => (
<Pie
{...commonProperties}
Expand Down
4 changes: 3 additions & 1 deletion website/src/data/components/pie/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Pie:
- radial
- svg
- isomorphic
stories: []
stories:
- label: Using colors from data
link: pie--using-colors-from-data
description: |
Generates a pie chart from an array of data, each datum must have an
id and a value property.
Expand Down
4 changes: 2 additions & 2 deletions website/src/data/components/pie/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const props = [
`,
type: 'string | (datum: any): string | number',
required: false,
defaultValue: 'id',
defaultValue: defaults.id,
},
{
key: 'value',
Expand All @@ -58,7 +58,7 @@ const props = [
`,
type: 'string | (datum: any): number',
required: false,
defaultValue: 'value',
defaultValue: defaults.id,
},
{
key: 'valueFormat',
Expand Down

0 comments on commit 92f19c2

Please sign in to comment.