@iotready/nextjs-components-library 1.0.0-preview13 → 1.0.0-preview15
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.
@@ -7,7 +7,7 @@ type Measure = {
|
|
7
7
|
unit: string;
|
8
8
|
stepped: boolean;
|
9
9
|
};
|
10
|
-
declare const TrendChart: ({ deviceId, measures1, measures2, enableDatePicker, handleGetInfluxData, handleExportDataCB, theme }: {
|
10
|
+
declare const TrendChart: ({ deviceId, measures1, measures2, enableDatePicker, handleGetInfluxData, handleExportDataCB, theme, initialTimeStart, initialTimeEnd }: {
|
11
11
|
deviceId: string;
|
12
12
|
measures1?: Array<Measure>;
|
13
13
|
measures2?: Array<Measure>;
|
@@ -15,5 +15,7 @@ declare const TrendChart: ({ deviceId, measures1, measures2, enableDatePicker, h
|
|
15
15
|
handleGetInfluxData: (measure: string, timeStart: number, timeEnd: number, deviceId: string, timeGroup: string, raw: boolean, fill?: boolean) => Promise<any>;
|
16
16
|
handleExportDataCB?: (measure: string, timeStart: number, timeEnd: number, deviceId: string) => Promise<any>;
|
17
17
|
theme: Theme;
|
18
|
+
initialTimeStart?: number;
|
19
|
+
initialTimeEnd?: number;
|
18
20
|
}) => import("react/jsx-runtime").JSX.Element;
|
19
21
|
export default TrendChart;
|
@@ -186,18 +186,18 @@ function getCsvData(data, measures) {
|
|
186
186
|
return csvData.map(row => row.join(',')).join('\n');
|
187
187
|
}
|
188
188
|
// eslint-disable-next-line no-unused-vars
|
189
|
-
const TrendChart = ({ deviceId, measures1, measures2, enableDatePicker, handleGetInfluxData, handleExportDataCB, theme }) => {
|
189
|
+
const TrendChart = ({ deviceId, measures1, measures2, enableDatePicker, handleGetInfluxData, handleExportDataCB, theme, initialTimeStart, initialTimeEnd }) => {
|
190
190
|
const [chartJsLoaded, setChartJsLoaded] = useState(false);
|
191
191
|
const [dataMeasures, setDataMeasures] = useState(null);
|
192
192
|
const [chartPeriod, setChartPeriod] = useState('1D');
|
193
193
|
const [chartPeriodConfig, setChartPeriodConfig] = useState(chartConfigByPeriod['1D']);
|
194
194
|
const [chartLoading, setChartLoading] = useState(false);
|
195
|
-
const [timeStartPicker, setTimeStartPicker] = useState(moment().subtract(1, 'day').unix());
|
196
|
-
const [timeStart, setTimeStart] = useState(moment().subtract(1, 'day').unix());
|
197
|
-
const [timeEnd, setTimeEnd] = useState(moment().unix());
|
198
|
-
const [datePickerUsed, setDatePickerUsed] = useState(false);
|
199
|
-
const [pickerTimeStart, setPickerTimeStart] = useState(moment().subtract(1, 'day').unix());
|
200
|
-
const [pickerTimeEnd, setPickerTimeEnd] = useState(moment().unix());
|
195
|
+
const [timeStartPicker, setTimeStartPicker] = useState(initialTimeStart || moment().subtract(1, 'day').unix());
|
196
|
+
const [timeStart, setTimeStart] = useState(initialTimeStart || moment().subtract(1, 'day').unix());
|
197
|
+
const [timeEnd, setTimeEnd] = useState(initialTimeEnd || moment().unix());
|
198
|
+
const [datePickerUsed, setDatePickerUsed] = useState(initialTimeStart || initialTimeEnd ? true : false);
|
199
|
+
const [pickerTimeStart, setPickerTimeStart] = useState(initialTimeStart || moment().subtract(1, 'day').unix());
|
200
|
+
const [pickerTimeEnd, setPickerTimeEnd] = useState(initialTimeEnd || moment().unix());
|
201
201
|
const [loadingButton, setLoadingButton] = useState(false);
|
202
202
|
const csvLinkRef = useRef(null);
|
203
203
|
const [csvData, setCsvData] = useState('');
|
@@ -314,7 +314,6 @@ const TrendChart = ({ deviceId, measures1, measures2, enableDatePicker, handleGe
|
|
314
314
|
pointHoverBackgroundColor: 'rgba(52, 125, 236, 0.5)',
|
315
315
|
change: !measure.polltime,
|
316
316
|
stepped: measure.stepped,
|
317
|
-
fill: false,
|
318
317
|
yAxisID: measure.source === 'measures1' ? 'y1' : 'y2'
|
319
318
|
};
|
320
319
|
});
|
package/package.json
CHANGED
package/server-actions/influx.js
CHANGED
@@ -88,7 +88,13 @@ export async function getInfluxDataV1(influxConfig, field, timeStart, timeEnd, d
|
|
88
88
|
.unix(timeStart)
|
89
89
|
.toISOString()}' AND time <= '${moment
|
90
90
|
.unix(timeEnd)
|
91
|
-
.toISOString()}' GROUP BY time(${timeGroup})
|
91
|
+
.toISOString()}' GROUP BY time(${timeGroup})`;
|
92
|
+
if (fill) {
|
93
|
+
query += ` fill(none)`;
|
94
|
+
}
|
95
|
+
else {
|
96
|
+
query += ` fill(null)`;
|
97
|
+
}
|
92
98
|
}
|
93
99
|
if (fill) {
|
94
100
|
// Query to get the last data point before timeStart
|
@@ -131,21 +137,23 @@ export async function getInfluxDataV1(influxConfig, field, timeStart, timeEnd, d
|
|
131
137
|
series.name = field; // Force the series name to be the field name
|
132
138
|
});
|
133
139
|
// 1000000 REMOVED AND ADDED TO MOVE THE POINT AWAY IN THE CHART
|
134
|
-
if (
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
+
if (fill) {
|
141
|
+
if (preStartValue !== null && preStartValue !== undefined) {
|
142
|
+
// Insert the pre-start value at the beginning of the dataset
|
143
|
+
data.results[0].series[0].values.unshift([
|
144
|
+
timeStart - 1000000,
|
145
|
+
preStartValue
|
146
|
+
]);
|
147
|
+
}
|
148
|
+
// Set the last point as the timeEnd and last value of the dataset
|
149
|
+
const lastSeries = data.results[0].series[0];
|
150
|
+
const lastValue = lastSeries?.values &&
|
151
|
+
lastSeries.values.length > 0 &&
|
152
|
+
lastSeries.values.slice(-1)[0].length > 1
|
153
|
+
? lastSeries.values.slice(-1)[0][1]
|
154
|
+
: null;
|
155
|
+
data.results[0].series[0].values.push([timeEnd + 1000000, lastValue]);
|
140
156
|
}
|
141
|
-
// Set the last point as the timeEnd and last value of the dataset
|
142
|
-
const lastSeries = data.results[0].series[0];
|
143
|
-
const lastValue = lastSeries?.values &&
|
144
|
-
lastSeries.values.length > 0 &&
|
145
|
-
lastSeries.values.slice(-1)[0].length > 1
|
146
|
-
? lastSeries.values.slice(-1)[0][1]
|
147
|
-
: null;
|
148
|
-
data.results[0].series[0].values.push([timeEnd + 1000000, lastValue]);
|
149
157
|
return data;
|
150
158
|
}
|
151
159
|
export async function exportDataV1(influxConfig, field, timeStart, timeEnd, deviceID) {
|