From 1151077a5101b4c156f80263c85b5e0230fedd5a Mon Sep 17 00:00:00 2001 From: plouc Date: Wed, 1 May 2024 09:31:12 +0900 Subject: [PATCH] feat(bump): add stories for custom line/point tooltips --- storybook/stories/bump/Bump.stories.tsx | 105 +++++++++++++++++++++--- 1 file changed, 92 insertions(+), 13 deletions(-) diff --git a/storybook/stories/bump/Bump.stories.tsx b/storybook/stories/bump/Bump.stories.tsx index cc6547b1e..cdd53f67c 100644 --- a/storybook/stories/bump/Bump.stories.tsx +++ b/storybook/stories/bump/Bump.stories.tsx @@ -1,7 +1,7 @@ import type { Meta, StoryObj } from '@storybook/react' import range from 'lodash/range' import shuffle from 'lodash/shuffle' -import { Bump, BumpPoint, BumpSvgProps } from '@nivo/bump' +import { Bump, BumpPoint, BumpSvgProps, BumpComputedSerie } from '@nivo/bump' const meta: Meta = { title: 'Bump', @@ -149,17 +149,96 @@ export const MissingData: Story = { ), } +const generateDataWithHoles = (): Array<{ + id: string + data: Array<{ x: number; y: number | null }> +}> => + generateData().map(series => ({ + ...series, + data: series.data.map(datum => ({ + x: datum.x, + y: datum.y >= 5 ? null : datum.y, + })), + })) + export const MoreSeriesThanRanks: Story = { - render: () => ( - - {...commonProps} - data={generateData().map(series => ({ - ...series, - data: series.data.map(datum => ({ - x: datum.x, - y: datum.y >= 5 ? null : datum.y, - })), - }))} - /> - ), + render: () => { + const data = generateDataWithHoles() + + return {...commonProps} data={data} /> + }, +} + +const LineTooltip = ({ serie }: { serie: BumpComputedSerie }) => ( +
+ Series: {serie.id} +
+ Color: {serie.color} +
+ {serie.points.length} points +
+) + +export const CustomLineTooltip: Story = { + render: () => { + const data = generateDataWithHoles() + + return ( + + {...commonProps} + lineTooltip={LineTooltip} + data={data} + /> + ) + }, +} + +const PointTooltip = ({ point }: { point: BumpPoint }) => { + console.log(point) + + return ( +
+ Series: {point.serie.id} +
+ x: {point.data.x} ({point.x}px) +
+ y: {point.data.y} ({point.y}px) +
+ ) +} + +export const CustomPointTooltip: Story = { + render: () => { + const data = generateDataWithHoles() + + return ( + + {...commonProps} + useMesh={true} + debugMesh={true} + pointTooltip={PointTooltip} + data={data} + /> + ) + }, }