@@ -82,12 +82,15 @@ const updateChart = <
82
82
> (
83
83
chart : Chart ,
84
84
keyValues : ChartAxes ,
85
+ additionalValues : ChartAxes [ ] , // more values to display on the same chart
85
86
rotate : boolean ,
86
87
event : d3 . D3ZoomEvent < Element , Datum >
87
88
) => {
88
89
// recover the new scale & test if movement under 0
89
90
const xAxis = getAxis ( keyValues , 'x' , rotate ) ;
91
+ const supplementaryXAxis = additionalValues . map ( ( value ) => getAxis ( value , 'x' , rotate ) ) ;
90
92
const yAxis = getAxis ( keyValues , 'y' , rotate ) ;
93
+ const supplementaryYAxis = additionalValues . map ( ( value ) => getAxis ( value , 'y' , rotate ) ) ;
91
94
const xAxisStart = `${ xAxis } _start` as const ;
92
95
const xAxisEnd = `${ xAxis } _end` as const ;
93
96
const yAxisStart = `${ yAxis } _start` as 'time_start' | 'position_start' ;
@@ -120,12 +123,19 @@ const updateChart = <
120
123
chart . yAxisGrid . call ( gridY ( newY , chart . width ) ) ;
121
124
122
125
// update lines & areas
126
+
123
127
chart . drawZone . selectAll < SVGLineElement , T [ ] > ( '.line' ) . attr (
124
128
'd' ,
125
129
d3
126
130
. line < T > ( )
127
- . x ( ( d ) => newX ( d [ xAxis as keyof T ] as number | Date ) )
128
- . y ( ( d ) => newY ( d [ yAxis as keyof T ] as number | Date ) )
131
+ . x ( ( d ) => {
132
+ const key = supplementaryXAxis . find ( ( axis ) => d [ axis as keyof T ] !== undefined ) || xAxis ;
133
+ return newX ( d [ key as keyof T ] as number | Date ) ;
134
+ } )
135
+ . y ( ( d ) => {
136
+ const key = supplementaryYAxis . find ( ( axis ) => d [ axis as keyof T ] !== undefined ) || yAxis ;
137
+ return newY ( d [ key as keyof T ] as number | Date ) ;
138
+ } )
129
139
) ;
130
140
131
141
chart . drawZone
@@ -246,10 +256,10 @@ export const enableInteractivity = <
246
256
setChart : React . Dispatch < React . SetStateAction < T | undefined > > ,
247
257
simulationIsPlaying : boolean ,
248
258
dispatchUpdateTimePositionValues : ( newTimePositionValues : Date ) => void ,
249
- chartDimensions : [ Date , Date ]
259
+ chartDimensions : [ Date , Date ] ,
260
+ additionalValues : ChartAxes [ ] = [ ] // more values to display on the same chart
250
261
) => {
251
262
if ( ! chart ) return ;
252
-
253
263
const zoom = d3zoom < SVGGElement , unknown > ( )
254
264
. scaleExtent ( [ 0.3 , 20 ] ) // This controls how much you can unzoom (x0.5) and zoom (x20)
255
265
. extent ( [
@@ -259,7 +269,7 @@ export const enableInteractivity = <
259
269
. wheelDelta ( wheelDelta )
260
270
. on ( 'zoom' , ( event ) => {
261
271
event . sourceEvent . preventDefault ( ) ;
262
- const zoomFunctions = updateChart ( chart , keyValues , rotate , event ) ;
272
+ const zoomFunctions = updateChart ( chart , keyValues , additionalValues , rotate , event ) ;
263
273
const newChart = { ...chart , x : zoomFunctions . newX , y : zoomFunctions . newY } ;
264
274
setChart ( newChart ) ;
265
275
} )
0 commit comments