@@ -14,7 +14,7 @@ import 'chartjs-adapter-date-fns'
14
14
// import { de, enGB } from "date-fns/locale";
15
15
import { Download , RefreshCcw , X } from 'lucide-react'
16
16
import { useMemo , useRef , useState , useEffect , useContext } from 'react'
17
- import { Line } from 'react-chartjs-2'
17
+ import { Scatter } from 'react-chartjs-2'
18
18
import { isBrowser , isTablet } from 'react-device-detect'
19
19
import Draggable , { type DraggableData } from 'react-draggable'
20
20
import { useNavigate , useNavigation , useSearchParams } from 'react-router'
@@ -59,11 +59,11 @@ const GraphWithZoom = (props: any) => {
59
59
} , [ ] )
60
60
61
61
return (
62
- < Line
63
- data = { props . lineData }
62
+ < Scatter
63
+ data = { props . chartData }
64
64
options = { props . options }
65
65
ref = { props . chartRef }
66
- > </ Line >
66
+ > </ Scatter >
67
67
)
68
68
}
69
69
@@ -98,7 +98,7 @@ export default function Graph({
98
98
const isAggregated = aggregation !== 'raw'
99
99
100
100
const nodeRef = useRef ( null )
101
- const chartRef = useRef < ChartJS < 'line ' > > ( null )
101
+ const chartRef = useRef < ChartJS < 'scatter ' > > ( null )
102
102
103
103
useEffect ( ( ) => {
104
104
if ( chartRef . current ) {
@@ -120,7 +120,7 @@ export default function Graph({
120
120
// get theme from tailwind
121
121
const [ theme ] = 'light' //useTheme();
122
122
123
- const [ lineData , setLineData ] = useState ( ( ) => {
123
+ const [ chartData , setChartData ] = useState ( ( ) => {
124
124
const includeDeviceName =
125
125
sensors . length === 2 && sensors [ 0 ] . device_name !== sensors [ 1 ] . device_name
126
126
@@ -145,7 +145,7 @@ export default function Graph({
145
145
y : measurement . value ,
146
146
locationId : measurement . locationId ,
147
147
} ) ) ,
148
- pointRadius : 0 ,
148
+ pointRadius : 3 ,
149
149
borderColor : sensor . color ,
150
150
backgroundColor : sensor . color ,
151
151
yAxisID : index === 0 ? 'y' : 'y1' ,
@@ -194,7 +194,7 @@ export default function Graph({
194
194
const includeDeviceName =
195
195
sensors . length === 2 && sensors [ 0 ] . device_name !== sensors [ 1 ] . device_name
196
196
197
- setLineData ( {
197
+ setChartData ( {
198
198
datasets : sensors
199
199
. map (
200
200
(
@@ -215,7 +215,7 @@ export default function Graph({
215
215
y : measurement . value ,
216
216
locationId : measurement . locationId ,
217
217
} ) ) ,
218
- pointRadius : 0 ,
218
+ pointRadius : 1 ,
219
219
borderColor : sensor . color ,
220
220
backgroundColor : sensor . color ,
221
221
yAxisID : index === 0 ? 'y' : 'y1' ,
@@ -260,7 +260,7 @@ export default function Graph({
260
260
} )
261
261
} , [ sensors , isAggregated ] )
262
262
263
- const options : ChartOptions < 'line ' > = useMemo ( ( ) => {
263
+ const options : ChartOptions < 'scatter ' > = useMemo ( ( ) => {
264
264
return {
265
265
maintainAspectRatio : false ,
266
266
responsive : true ,
@@ -324,7 +324,7 @@ export default function Graph({
324
324
display : true ,
325
325
text : sensors [ 0 ] . title + ' in ' + sensors [ 0 ] . unit ,
326
326
} ,
327
- type : 'linear' ,
327
+ // type: 'linear',
328
328
display : true ,
329
329
position : 'left' ,
330
330
grid : {
@@ -339,7 +339,7 @@ export default function Graph({
339
339
display : true ,
340
340
text : sensors [ 1 ] ? sensors [ 1 ] . title + ' in ' + sensors [ 1 ] . unit : '' , //data.sensors[1].unit
341
341
} ,
342
- type : 'linear' ,
342
+ // type: 'linear',
343
343
display : 'auto' ,
344
344
position : 'right' ,
345
345
grid : {
@@ -356,7 +356,7 @@ export default function Graph({
356
356
label : ( context : any ) => {
357
357
const dataIndex = context . dataIndex
358
358
const datasetIndex = context . datasetIndex
359
- const point = lineData . datasets [ datasetIndex ] . data [ dataIndex ]
359
+ const point = chartData . datasets [ datasetIndex ] . data [ dataIndex ]
360
360
const locationId = point . locationId
361
361
setHoveredPoint ( locationId )
362
362
return `${ context . dataset . label } : ${ context . raw . y } `
@@ -405,7 +405,7 @@ export default function Graph({
405
405
setColorPickerState ( {
406
406
open : ! colorPickerState . open ,
407
407
index,
408
- color : lineData . datasets [ index ] . borderColor as string ,
408
+ color : chartData . datasets [ index ] . borderColor as string ,
409
409
} )
410
410
} ,
411
411
labels : {
@@ -421,18 +421,18 @@ export default function Graph({
421
421
currentZoom ?. xMax ,
422
422
theme ,
423
423
sensors ,
424
- lineData . datasets ,
424
+ chartData . datasets ,
425
425
setHoveredPoint ,
426
426
colorPickerState . open ,
427
427
] )
428
428
429
429
function handleColorChange ( newColor : string ) {
430
- const updatedDatasets = [ ...lineData . datasets ]
430
+ const updatedDatasets = [ ...chartData . datasets ]
431
431
updatedDatasets [ colorPickerState . index ] . borderColor = newColor
432
432
updatedDatasets [ colorPickerState . index ] . backgroundColor = newColor
433
433
434
- // Update the lineData state with the new dataset colors
435
- setLineData ( ( prevData ) => ( {
434
+ // Update the chartData state with the new dataset colors
435
+ setChartData ( ( prevData ) => ( {
436
436
...prevData ,
437
437
datasets : updatedDatasets ,
438
438
} ) )
@@ -459,14 +459,14 @@ export default function Graph({
459
459
}
460
460
461
461
function handleCsvDownloadClick ( ) {
462
- const labels = lineData . datasets [ 0 ] . data . map ( ( point : any ) => point . x )
462
+ const labels = chartData . datasets [ 0 ] . data . map ( ( point : any ) => point . x )
463
463
464
464
let csvContent = 'timestamp,deviceId,sensorId,value,unit,phenomena\n'
465
465
466
466
// Loop through each timestamp and sensor data
467
467
labels . forEach ( ( timestamp : any , index : string | number ) => {
468
468
sensors . forEach ( ( sensor : any ) => {
469
- const dataset = lineData . datasets . find (
469
+ const dataset = chartData . datasets . find (
470
470
( ds : { label : string | any [ ] } ) => ds . label . includes ( sensor . title ) ,
471
471
)
472
472
if ( dataset ) {
@@ -598,7 +598,7 @@ export default function Graph({
598
598
< ClientOnly fallback = { < Spinner /> } >
599
599
{ ( ) => (
600
600
< GraphWithZoom
601
- lineData = { lineData }
601
+ chartData = { chartData }
602
602
options = { options }
603
603
chartRef = { chartRef } // Pass chartRef as a prop
604
604
/>
0 commit comments