Skip to content

Commit

Permalink
feat(chord): update stories
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Jan 1, 2022
1 parent 90210e4 commit 73467c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
@@ -1,13 +1,20 @@
import { storiesOf } from '@storybook/react'
import { generateChordData } from '@nivo/generators'
import { TableTooltip, BasicTooltip, Chip } from '@nivo/tooltip'
import { Chord } from '../src'
// @ts-ignore
import { Chord, ArcDatum, ArcTooltipComponentProps, RibbonTooltipComponentProps } from '../src'

const generateData = (size: number) => {
const { matrix, keys } = generateChordData({ size })

return { data: matrix, keys }
}

const commonProperties = {
width: 900,
height: 500,
margin: { top: 60, right: 80, bottom: 60, left: 80 },
...generateChordData({ size: 7 }),
...generateData(7),
xPadding: 0.2,
}

Expand All @@ -17,9 +24,9 @@ stories.add('default', () => <Chord {...commonProperties} />)

stories.add('radial labels', () => <Chord {...commonProperties} labelRotation={-90} />)

const customLabel = d => `${d.id} [${d.value}]`
const customLabel = (arc: Omit<ArcDatum, 'label' | 'color'>) => `${arc.id} [${arc.value}]`
stories.add('custom labels text', () => (
<Chord {...commonProperties} {...generateChordData({ size: 5 })} label={customLabel} />
<Chord {...commonProperties} {...generateData(5)} label={customLabel} />
))

stories.add('angle padding', () => (
Expand All @@ -43,7 +50,7 @@ stories.add('alternative colors', () => (
stories.add('putting labels inside arcs', () => (
<Chord
{...commonProperties}
{...generateChordData({ size: 5 })}
{...generateData(5)}
padAngle={0.02}
innerRadiusRatio={0.8}
innerRadiusOffset={0.02}
Expand All @@ -55,7 +62,7 @@ stories.add('putting labels inside arcs', () => (
stories.add('with formatted values', () => (
<Chord
{...commonProperties}
{...generateChordData({ size: 5 })}
{...generateData(5)}
valueFormat={value =>
`${Number(value).toLocaleString('ru-RU', {
minimumFractionDigits: 2,
Expand All @@ -64,7 +71,7 @@ stories.add('with formatted values', () => (
/>
))

const ArcTooltip = ({ arc }) => (
const ArcTooltip = ({ arc }: ArcTooltipComponentProps) => (
<BasicTooltip
id={`Custom arc tooltip, ${arc.label}`}
value={arc.formattedValue}
Expand All @@ -73,7 +80,7 @@ const ArcTooltip = ({ arc }) => (
/>
)

const RibbonTooltip = ({ ribbon }) => (
const RibbonTooltip = ({ ribbon }: RibbonTooltipComponentProps) => (
<TableTooltip
rows={[
[
Expand All @@ -95,7 +102,7 @@ const RibbonTooltip = ({ ribbon }) => (
stories.add('custom tooltips', () => (
<Chord
{...commonProperties}
{...generateChordData({ size: 5 })}
{...generateData(5)}
arcTooltip={ArcTooltip}
ribbonTooltip={RibbonTooltip}
/>
Expand Down
4 changes: 3 additions & 1 deletion website/src/data/components/chord/meta.yml
Expand Up @@ -12,7 +12,9 @@ Chord:
- relational
- svg
- isomorphic
stories: []
stories:
- label: Custom arc & ribbon tooltip
link: chord--custom-tooltips
description: |
Chord diagram, uses [d3-chord](https://github.com/d3/d3-chord),
see [this demo](https://observablehq.com/@d3/chord-diagram).
Expand Down
4 changes: 2 additions & 2 deletions website/src/data/config.ts
@@ -1,9 +1,9 @@
export default {
// local
// nivoApiUrl: 'http://localhost:3030/nivo',
storybookUrl: 'http://localhost:6006/',
// storybookUrl: 'http://localhost:6006/',

// production
nivoApiUrl: 'https://nivo-api.herokuapp.com/nivo',
// storybookUrl: 'https://nivo.rocks/storybook/',
storybookUrl: 'https://nivo.rocks/storybook/',
}

0 comments on commit 73467c9

Please sign in to comment.