@iotready/nextjs-components-library 1.0.0-preview23 → 1.0.0-preview24
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.
|
@@ -21,6 +21,7 @@ import { ThemeProvider } from '@mui/material/styles';
|
|
|
21
21
|
import TimelineIcon from '@mui/icons-material/Timeline';
|
|
22
22
|
import MuiTooltip from '@mui/material/Tooltip';
|
|
23
23
|
import EditNoteIcon from '@mui/icons-material/EditNote';
|
|
24
|
+
// import AspectRatioIcon from '@mui/icons-material/AspectRatio';
|
|
24
25
|
import { FilterTagMode } from '../../server-actions/types';
|
|
25
26
|
const lineOptions = {
|
|
26
27
|
parsing: false,
|
|
@@ -126,15 +127,6 @@ const chartConfigByPeriod = {
|
|
|
126
127
|
scaleUnit: 'year',
|
|
127
128
|
}
|
|
128
129
|
};
|
|
129
|
-
// function getChartPoints(data: any): Point[] {
|
|
130
|
-
// const points: Point[] = data.results[0].series[0].values.map((row: any) => {
|
|
131
|
-
// return {
|
|
132
|
-
// x: moment.unix(row[0]),
|
|
133
|
-
// y: row[1]
|
|
134
|
-
// }
|
|
135
|
-
// });
|
|
136
|
-
// return points;
|
|
137
|
-
// }
|
|
138
130
|
function getPollTime(intervalInSeconds, pollTime) {
|
|
139
131
|
const CalculatedPollTime = Math.round(intervalInSeconds / 2880);
|
|
140
132
|
if (CalculatedPollTime <= pollTime) {
|
|
@@ -196,7 +188,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
196
188
|
const [chartJsLoaded, setChartJsLoaded] = useState(false);
|
|
197
189
|
// Dichiarazione di annotationsData come funzione che ritorna una Promise<any>
|
|
198
190
|
const [annotationsData, setAnnotationsData] = useState([]);
|
|
199
|
-
const [
|
|
191
|
+
const [annotationsEnabled, setAnnotationsEnabled] = useState(true);
|
|
200
192
|
const [dataMeasures, setDataMeasures] = useState(null);
|
|
201
193
|
const [chartPeriod, setChartPeriod] = useState('1D');
|
|
202
194
|
const [chartPeriodConfig, setChartPeriodConfig] = useState(chartConfigByPeriod['1D']);
|
|
@@ -318,13 +310,13 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
318
310
|
}
|
|
319
311
|
}, [csvData]);
|
|
320
312
|
useEffect(() => {
|
|
321
|
-
if (annotationsDataFn &&
|
|
313
|
+
if (annotationsDataFn && annotationsEnabled) {
|
|
322
314
|
(async () => {
|
|
323
315
|
const resp = await annotationsDataFn();
|
|
324
316
|
setAnnotationsData(resp);
|
|
325
317
|
})();
|
|
326
318
|
}
|
|
327
|
-
}, [annotationsDataFn,
|
|
319
|
+
}, [annotationsDataFn, annotationsEnabled]);
|
|
328
320
|
function getDwSlotsFromValues(dwValues) {
|
|
329
321
|
const slots = [];
|
|
330
322
|
let start = null;
|
|
@@ -368,11 +360,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
368
360
|
dwPoints = rawDwPoints;
|
|
369
361
|
}
|
|
370
362
|
}
|
|
371
|
-
const
|
|
372
|
-
// Mappa sul formato Point
|
|
373
|
-
const stdPoints = stdRaw
|
|
374
|
-
.map((r) => ({ x: Number(r.x), y: r.y }))
|
|
375
|
-
.filter((p) => p.y !== null);
|
|
363
|
+
const stdPoints = await handleGetInfluxData(measure.name, timeStart, timeEnd, deviceId, polltime, !measure.polltime && rawQuery, !measure.polltime ? "none" : "null", 100, FilterTagMode.Exclude);
|
|
376
364
|
const filtered = dwSlots.length
|
|
377
365
|
? stdPoints.filter((p) => !dwSlots.some(slot => p.x >= slot.start && p.x <= slot.end))
|
|
378
366
|
: stdPoints;
|
|
@@ -443,7 +431,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
443
431
|
const { paddedMin: paddedMin2, paddedMax: paddedMax2 } = getPaddedMinMax(min2, max2);
|
|
444
432
|
// Handle undefined/null annotationsData
|
|
445
433
|
let dynamicAnnotations = {};
|
|
446
|
-
if (Array.isArray(annotationsData) && annotationsData.length > 0 &&
|
|
434
|
+
if (Array.isArray(annotationsData) && annotationsData.length > 0 && annotationsEnabled) {
|
|
447
435
|
dynamicAnnotations = annotationsData.reduce((acc, [timestamp, label], index) => {
|
|
448
436
|
const yVal = paddedMin1 !== null && paddedMin1 !== undefined
|
|
449
437
|
? paddedMin1 + 0.01 * (paddedMax1 - paddedMin1)
|
|
@@ -579,7 +567,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
579
567
|
loadDatasets(chartPeriod).then(() => {
|
|
580
568
|
setChartLoading(false);
|
|
581
569
|
});
|
|
582
|
-
}, [measures1, timeEnd, timeStart, measures2,
|
|
570
|
+
}, [measures1, timeEnd, timeStart, measures2, annotationsEnabled, annotationsData]);
|
|
583
571
|
useEffect(() => {
|
|
584
572
|
const loadZoomPlugin = async () => {
|
|
585
573
|
const zoomPlugin = (await import('chartjs-plugin-zoom')).default;
|
|
@@ -671,7 +659,7 @@ const TrendChart = ({ deviceId, measures1, annotationsDataFn, measures2, enableD
|
|
|
671
659
|
'& .MuiToggleButton-root': {
|
|
672
660
|
color: 'text.primary', fontSize: '0.95rem', fontWeight: 'normal', paddingTop: '6px', paddingBottom: '6px'
|
|
673
661
|
}
|
|
674
|
-
}, disabled: chartLoading, children: [_jsx(ToggleButton, { value: "1D", sx: { px: 1 }, children: "1d" }), _jsx(ToggleButton, { value: "1W", sx: { px: 1 }, children: "1w" }), _jsx(ToggleButton, { value: "1M", sx: { px: 1 }, children: "1M" }), _jsx(ToggleButton, { value: "3M", sx: { px: 1 }, children: "3M" }), _jsx(ToggleButton, { value: "6M", sx: { px: 1 }, children: "6M" }), _jsx(ToggleButton, { value: "1Y", sx: { px: 1 }, children: "1Y" }), _jsx(ToggleButton, { value: "ALL", sx: { px: 1 }, children: "ALL" })] }), _jsx(MuiTooltip, { placement: "top", arrow: true, title: "Connect point values", children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected: spanGapsOption, disabled: chartLoading, onChange: () => handleSpanGaps(!spanGapsOption), sx: { ml: 1 }, children: _jsx(TimelineIcon, {}) }) }), annotationsData !== undefined && (_jsx(MuiTooltip, { placement: "top", arrow: true, title: "Show annotations", children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected:
|
|
662
|
+
}, disabled: chartLoading, children: [_jsx(ToggleButton, { value: "1D", sx: { px: 1 }, children: "1d" }), _jsx(ToggleButton, { value: "1W", sx: { px: 1 }, children: "1w" }), _jsx(ToggleButton, { value: "1M", sx: { px: 1 }, children: "1M" }), _jsx(ToggleButton, { value: "3M", sx: { px: 1 }, children: "3M" }), _jsx(ToggleButton, { value: "6M", sx: { px: 1 }, children: "6M" }), _jsx(ToggleButton, { value: "1Y", sx: { px: 1 }, children: "1Y" }), _jsx(ToggleButton, { value: "ALL", sx: { px: 1 }, children: "ALL" })] }), _jsx(MuiTooltip, { placement: "top", arrow: true, title: "Connect point values", children: _jsx("span", { children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected: spanGapsOption, disabled: chartLoading, onChange: () => handleSpanGaps(!spanGapsOption), sx: { ml: 1 }, children: _jsx(TimelineIcon, {}) }) }) }), annotationsData !== undefined && (_jsx(MuiTooltip, { placement: "top", arrow: true, title: "Show annotations", children: _jsx("span", { children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected: annotationsEnabled, disabled: chartLoading, onChange: () => setAnnotationsEnabled(!annotationsEnabled), sx: { ml: 1 }, children: _jsx(EditNoteIcon, {}) }) }) }))] })] }), _jsx(Box, { component: 'div', className: "chart-container", sx: { mt: 2, height: '100%' }, children: chartJsLoaded && !chartLoading && typeof window !== 'undefined' ?
|
|
675
663
|
_jsx(_Fragment, { children: dataMeasures && (dataMeasures.length > 1 || (dataMeasures.length === 1 && dataMeasures[0].data?.length)) ?
|
|
676
664
|
(_jsx(Line, { options: options, data: {
|
|
677
665
|
// datasets: dataMeasures || [{ data: [] }]
|
package/package.json
CHANGED
package/server-actions/influx.js
CHANGED
|
@@ -155,7 +155,7 @@ export async function getInfluxDataV1(influxConfig, field, timeStart, timeEnd, d
|
|
|
155
155
|
query += ` fill(null)`;
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
if (fill) {
|
|
158
|
+
if (fill !== "null") {
|
|
159
159
|
// Query to get the last data point before timeStart
|
|
160
160
|
const preStartQuery = `SELECT last("value") FROM "${influxConfig.measurement}" WHERE "deviceid" = '${deviceID}' AND "valueName" = '${field}'${filterTagCondition} AND time < '${moment
|
|
161
161
|
.unix(timeStart)
|
|
@@ -196,7 +196,7 @@ export async function getInfluxDataV1(influxConfig, field, timeStart, timeEnd, d
|
|
|
196
196
|
series.name = field; // Force the series name to be the field name
|
|
197
197
|
});
|
|
198
198
|
// 1000000 REMOVED AND ADDED TO MOVE THE POINT AWAY IN THE CHART
|
|
199
|
-
if (fill) {
|
|
199
|
+
if (fill !== "null") {
|
|
200
200
|
if (preStartValue !== null && preStartValue !== undefined) {
|
|
201
201
|
// Insert the pre-start value at the beginning of the dataset
|
|
202
202
|
data.results[0].series[0].values.unshift([
|