import React from 'react' import { type Meta } from '@storybook/react-vite' import { createDataKeyLegend } from '../../services/GraphHelperServiceTyped' import { DocsTemplate } from '../../../.storybook' export const Example = (args: { obj: Record colorSet?: string[] }): React.JSX.Element => { const { obj, colorSet } = args const result = createDataKeyLegend(obj, colorSet) return ( <>
{JSON.stringify(result, null, 2)}
) } Example.storyName = 'createDataKeyLegend' Example.args = { obj: { revenue: 10000, visitors: 500, conversions: 50, tooltip: 'Sample Tooltip', date: 1681017600000, }, colorSet: ['var(--red)', 'var(--blue)', 'var(--green)'], } export default { title: 'Helper Functions/createDataKeyLegend', component: Example, argTypes: { obj: { control: 'object', description: 'The object containing data keys to generate the legend.', }, colorSet: { control: 'object', description: 'Optional array of colors to use for the legend.', }, }, parameters: { viewMode: 'docs', previewTabs: { canvas: { hidden: true }, }, docs: { page: () => ( <> createDataKeyLegend is used to create a legend for visualizations, mapping data keys to colors. , The function takes two arguments:
  • An object containing data keys.
  • An optional array of colors to use for the legend. If not provided, a default color palette is used.
, Returns an array of objects, each containing:
  • key: The data key name.
  • stroke: The corresponding color.
, Note: The function removes the tooltip and{' '} date properties from the input object before generating the legend. , ]} /> ), }, }, } as Meta