@iotready/nextjs-components-library 1.0.0-preview4 → 1.0.0-preview5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/charts/TrendChart.js +11 -14
- package/package.json +1 -1
@@ -37,7 +37,7 @@ const lineOptions = {
|
|
37
37
|
tooltip: {
|
38
38
|
callbacks: {
|
39
39
|
label: (context) => {
|
40
|
-
return `${context.dataset.label}: ${context.parsed.y.toFixed(
|
40
|
+
return `${context.dataset.label}: ${context.parsed.y.toFixed(3)} ${context.dataset.unit}`;
|
41
41
|
}
|
42
42
|
},
|
43
43
|
},
|
@@ -278,11 +278,12 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
278
278
|
}, [csvData]);
|
279
279
|
const loadDatasets = async (chartPeriod) => {
|
280
280
|
setChartLoading(true);
|
281
|
-
|
281
|
+
let intervalInSeconds = chartPeriod === "ALL" && !datePickerUsed && !zoomed ? 31536000 : timeEnd - timeStart;
|
282
|
+
const rawQuery = intervalInSeconds < 86400; //
|
282
283
|
// Inizializza un array di promesse per ottenere i dati per ciascuna misura
|
283
284
|
const datasetsPromises = measures.map(async (measure) => {
|
284
|
-
const polltime =
|
285
|
-
const influxData = await handleGetInfluxData(measure.name, timeStart, timeEnd, deviceId, polltime,
|
285
|
+
const polltime = getPollTime(intervalInSeconds, measure.polltime || 30);
|
286
|
+
const influxData = await handleGetInfluxData(measure.name, timeStart, timeEnd, deviceId, polltime, !measure.polltime && rawQuery);
|
286
287
|
const points = GetPoints(influxData);
|
287
288
|
return {
|
288
289
|
label: measure.name,
|
@@ -337,17 +338,13 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
337
338
|
x: {
|
338
339
|
...options.scales.x,
|
339
340
|
min: moment.unix(minTime || timeStart).toString(),
|
340
|
-
max: moment.unix(timeEnd).toString()
|
341
|
-
time: {
|
342
|
-
...options.scales.x.time,
|
343
|
-
unit: chartPeriod.scaleUnit
|
344
|
-
}
|
341
|
+
max: moment.unix(timeEnd).toString()
|
345
342
|
}
|
346
343
|
}
|
347
344
|
});
|
348
345
|
};
|
349
346
|
useEffect(() => {
|
350
|
-
const timeDifference = Math.abs(moment(
|
347
|
+
const timeDifference = Math.abs(moment(timeEnd).valueOf() - moment(timeStart).valueOf()); // Convert milliseconds to seconds
|
351
348
|
let newChartPeriod = '1D'; // Default to 1 day
|
352
349
|
if (timeDifference < 86400) { // Less than 1 day
|
353
350
|
newChartPeriod = '1H'; // Set to 1 day
|
@@ -355,16 +352,16 @@ const TrendChart = ({ deviceId, measures, enableExportData, enableDatePicker, ha
|
|
355
352
|
else if (timeDifference < 604800) { // Less than 1 week
|
356
353
|
newChartPeriod = '1D'; // Set to 1 day
|
357
354
|
}
|
358
|
-
else if (timeDifference <
|
355
|
+
else if (timeDifference < 2678400) { // Less than 1 month
|
359
356
|
newChartPeriod = '1W'; // Set to 1 week
|
360
357
|
}
|
361
|
-
else if (timeDifference <
|
358
|
+
else if (timeDifference < 8035200) { // Less than 3 months
|
362
359
|
newChartPeriod = '1M'; // Set to 1 month
|
363
360
|
}
|
364
|
-
else if (timeDifference <
|
361
|
+
else if (timeDifference < 16070400) { // Less than 6 months
|
365
362
|
newChartPeriod = '3M'; // Set to 3 months
|
366
363
|
}
|
367
|
-
else if (timeDifference <
|
364
|
+
else if (timeDifference < 31536000) { // Less than 1 year
|
368
365
|
newChartPeriod = '6M'; // Set to 6 months
|
369
366
|
}
|
370
367
|
else {
|