Skip to content

Commit

Permalink
feat(heatmap): adjust stories
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Jan 12, 2022
1 parent 2cbda76 commit 1867b60
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 258 deletions.
2 changes: 1 addition & 1 deletion packages/funnel/stories/funnel.stories.tsx
@@ -1,6 +1,6 @@
import { withKnobs } from '@storybook/addon-knobs'
import { storiesOf } from '@storybook/react'

// @ts-ignore
import { ResponsiveFunnel } from '../src'

const commonProps = {
Expand Down
26 changes: 26 additions & 0 deletions packages/heatmap/stories/CustomTooltip.tsx
@@ -0,0 +1,26 @@
// @ts-ignore
import { ComputedCell } from '../src'

export const CustomTooltip = ({ cell }: { cell: ComputedCell<any> }) => {
return (
<div
style={{
backgroundColor: cell.color,
color: '#ffffff',
padding: '6px 9px',
borderRadius: '2px',
minWidth: '160px',
boxShadow: '0 3px 5px rgba(0, 0, 0, .25)',
whiteSpace: 'pre',
}}
>
{'id '}&nbsp;<strong>{cell.id}</strong>
<br />
{'serie'}&nbsp;<strong>{cell.serieId}</strong>
<br />
{'x '}&nbsp;<strong>{cell.data.x}</strong>
<br />
{'value'}&nbsp;<strong>{cell.formattedValue}</strong>
</div>
)
}
14 changes: 14 additions & 0 deletions packages/heatmap/stories/data.ts
@@ -0,0 +1,14 @@
import { generateXYSeries } from '@nivo/generators'

export const sampleData = generateXYSeries({
serieIds: ['Japan', 'France', 'US', 'Germany', 'Norway', 'Iceland', 'UK', 'Vietnam'],
x: {
values: ['Train', 'Subway', 'Bus', 'Car', 'Boat', 'Moto', 'Moped', 'Bicycle', 'Others'],
},
y: {
length: NaN,
min: -100_000,
max: 100_000,
round: true,
},
})
150 changes: 0 additions & 150 deletions packages/heatmap/stories/heatmap.stories.js

This file was deleted.

87 changes: 87 additions & 0 deletions packages/heatmap/stories/heatmap.stories.tsx
@@ -0,0 +1,87 @@
import { storiesOf } from '@storybook/react'
// @ts-ignore
import { HeatMap, ComputedCell } from '../src'
// @ts-ignore
import { sampleData } from './data'
// @ts-ignore
import { CustomTooltip } from './CustomTooltip'

const commonProperties = {
width: 900,
height: 500,
margin: { top: 60, right: 80, bottom: 60, left: 80 },
data: sampleData,
}

const stories = storiesOf('HeatMap', module)

stories.add('default', () => <HeatMap<any, Record<string, unknown>> {...commonProperties} />)

stories.add('Variable Cell Size', () => (
<HeatMap<any, Record<string, unknown>>
{...commonProperties}
valueFormat=">-.2s"
cellComponent="circle"
sizeVariation={{
sizes: [0.6, 1],
}}
forceSquare
enableGridX={true}
enableGridY={true}
/>
))

const CustomCell = ({ cell, borderWidth }: { cell: ComputedCell<any>; borderWidth: number }) => {
if (cell.value === null) return null

return (
<g transform={`translate(${cell.x}, ${cell.y})`}>
<path
transform={`rotate(${cell.value < 50 ? 180 : 0})`}
fill={cell.color}
fillOpacity={cell.opacity}
strokeWidth={borderWidth}
stroke={cell.borderColor}
d={`
M0 -${Math.round(cell.height / 2)}
L${Math.round(cell.width / 2)} ${Math.round(cell.height / 2)}
L-${Math.round(cell.width / 2)} ${Math.round(cell.height / 2)}
L0 -${Math.round(cell.height / 2)}
`}
/>
<text
dominantBaseline="central"
textAnchor="middle"
style={{ fill: cell.labelTextColor }}
dy={cell.value < 50 ? -6 : 6}
>
{cell.formattedValue}
</text>
</g>
)
}

stories.add('Custom Cell Component', () => (
<HeatMap<any, Record<string, unknown>>
{...commonProperties}
enableGridY
cellComponent={CustomCell}
labelTextColor="inherit:darker(1.6)"
/>
))

stories.add('Custom Tooltip', () => (
<HeatMap<any, Record<string, unknown>>
{...commonProperties}
colors={{
type: 'quantize',
scheme: 'cividis',
steps: 7,
}}
tooltip={CustomTooltip}
labelTextColor={{
from: 'color',
modifiers: [['brighter', 2.6]],
}}
/>
))
103 changes: 0 additions & 103 deletions packages/heatmap/stories/heatmapCanvas.stories.js

This file was deleted.

0 comments on commit 1867b60

Please sign in to comment.