Sparkline.stories.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import type { Meta, StoryObj } from '@storybook/react-vite';
  2. import Sparkline from './Sparkline';
  3. const wave = Array.from({ length: 48 }, (_, i) => 45 + Math.round(28 * Math.sin(i / 4) + (i % 5) * 3));
  4. const inverse = wave.map((v) => Math.max(0, 100 - v));
  5. const meta = {
  6. title: 'Viz/Sparkline',
  7. component: Sparkline,
  8. tags: ['autodocs'],
  9. parameters: {
  10. layout: 'padded',
  11. docs: {
  12. description: {
  13. component:
  14. 'Compact canvas line chart (uPlot) for CPU, memory, and traffic trends. Supports up to three series, optional axes/grid, a hover tooltip, min/max markers, reference lines, and light/dark theming.',
  15. },
  16. },
  17. },
  18. argTypes: {
  19. data: { description: 'Primary series values, oldest to newest.' },
  20. data2: { description: 'Optional second series (e.g. download vs upload).' },
  21. data3: { description: 'Optional third series.' },
  22. height: { description: 'Chart height in pixels.' },
  23. name1: { description: 'Legend/tooltip label for the primary series.' },
  24. name2: { description: 'Legend/tooltip label for the second series.' },
  25. showAxes: { description: 'Render x/y axes and tick labels.' },
  26. showGrid: { description: 'Draw horizontal grid lines.' },
  27. showTooltip: { description: 'Show a value tooltip on hover.' },
  28. extrema: { description: 'Highlight the min and max points (single-series only).' },
  29. },
  30. } satisfies Meta<typeof Sparkline>;
  31. export default meta;
  32. type Story = StoryObj<typeof meta>;
  33. export const Default: Story = {
  34. args: { data: wave, height: 80 },
  35. };
  36. export const AxesAndGrid: Story = {
  37. args: { data: wave, height: 140, showAxes: true, showGrid: true, name1: 'CPU' },
  38. };
  39. export const Extrema: Story = {
  40. args: { data: wave, height: 140, name1: 'CPU', extrema: { show: true } },
  41. };
  42. export const MultiSeriesTooltip: Story = {
  43. args: {
  44. data: wave,
  45. data2: inverse,
  46. name1: 'Upload',
  47. name2: 'Download',
  48. height: 140,
  49. showTooltip: true,
  50. showAxes: true,
  51. },
  52. };