1- import React from 'react'
1+ import type { Meta , StoryObj } from '@storybook/react-vite'
2+ import { useState } from 'react'
3+ import { MapContainer , TileLayer } from 'react-leaflet'
24import { VelocityAggregation } from '../useVelocityAggregationData'
5+ import { VelocityHeatmapLegend } from './VelocityHeatmapLegend'
36import { VelocityHeatmapRectangles } from './VelocityHeatmapRectangles'
47
5- export default {
6- title : 'VelocityHeatmap/Rectangles' ,
7- component : VelocityHeatmapRectangles ,
8- }
9-
108const sampleData : VelocityAggregation [ ] = [
119 {
1210 rounded_lon : 34.92 ,
@@ -31,21 +29,76 @@ const sampleData: VelocityAggregation[] = [
3129 } ,
3230]
3331
34- export const Default = ( ) => (
35- < div style = { { height : 400 , width : 600 } } >
36- < svg width = "600" height = "400" style = { { position : 'absolute' , zIndex : 0 } } />
37- < VelocityHeatmapRectangles data = { sampleData } visMode = "avg" />
38- </ div >
39- )
40-
41- export const StdDev = ( ) => (
42- < div style = { { height : 400 , width : 600 } } >
43- < VelocityHeatmapRectangles data = { sampleData } visMode = "std" />
44- </ div >
45- )
46-
47- export const CoeffOfVar = ( ) => (
48- < div style = { { height : 400 , width : 600 } } >
49- < VelocityHeatmapRectangles data = { sampleData } visMode = "cv" />
50- </ div >
51- )
32+ const meta = {
33+ title : 'VelocityHeatmap/Rectangles' ,
34+ component : VelocityHeatmapRectangles ,
35+ argTypes : {
36+ visMode : {
37+ control : { type : 'select' } ,
38+ options : [ 'avg' , 'std' , 'cv' ] ,
39+ description :
40+ 'Visualization mode: avg for average velocity, std for standard deviation, cv for coefficient of variation' ,
41+ } ,
42+ data : {
43+ control : { type : 'object' } ,
44+ description :
45+ 'Array of velocity aggregation data points with lat, lon, sample count, average, and stddev' ,
46+ table : {
47+ type : { summary : 'VelocityAggregation[]' } ,
48+ } ,
49+ } ,
50+ setMinMax : {
51+ control : false ,
52+ description : 'Optional callback function to set min and max values for the legend' ,
53+ table : {
54+ type : { summary : '(min: number, max: number) => void) | undefined' } ,
55+ } ,
56+ } ,
57+ } ,
58+ args : {
59+ visMode : 'avg' ,
60+ data : sampleData ,
61+ } ,
62+ decorators : [
63+ ( Story , ctx ) => {
64+ const [ minMax , setMinMax ] = useState ( [ 0 , 1 ] )
65+
66+ return (
67+ < div style = { { height : '500px' , width : '100%' , margin : '16px 0' } } >
68+ < MapContainer
69+ center = { [ 29.57 , 34.93 ] }
70+ zoom = { 13 }
71+ scrollWheelZoom = { true }
72+ style = { { height : '100%' , width : '100%' } } >
73+ < TileLayer
74+ attribution = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
75+ url = "https://tile-a.openstreetmap.fr/hot/{z}/{x}/{y}.png"
76+ />
77+ < Story
78+ args = { {
79+ data : ctx . args . data ,
80+ visMode : ctx . args . visMode ,
81+ setMinMax : ( min , max ) => setMinMax ( [ min , max ] ) ,
82+ } }
83+ />
84+ < VelocityHeatmapLegend visMode = { ctx . args . visMode } min = { minMax [ 0 ] } max = { minMax [ 1 ] } />
85+ </ MapContainer >
86+ </ div >
87+ )
88+ } ,
89+ ] ,
90+ } satisfies Meta < typeof VelocityHeatmapRectangles >
91+
92+ export default meta
93+
94+ type Story = StoryObj < typeof meta >
95+
96+ export const Default : Story = { }
97+
98+ export const StdDev : Story = {
99+ args : { visMode : 'std' } ,
100+ }
101+
102+ export const CoeffOfVar : Story = {
103+ args : { visMode : 'cv' } ,
104+ }
0 commit comments