@dexteel/mesf-core 4.5.8 → 4.5.10

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/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Typography, TextField, makeStyles as makeStyles$1, Button as Button$1, Grid as Grid$1, Dialog as Dialog$1, DialogTitle as DialogTitle$2, DialogContent as DialogContent$2, DialogContentText, DialogActions as DialogActions$2, FormHelperText, CircularProgress as CircularProgress$1, Badge, FormControlLabel, Checkbox, Snackbar as Snackbar$1, Paper as Paper$1, MenuItem as MenuItem$1, useTheme as useTheme$1, Box, Tooltip, IconButton as IconButton$1, FormControl as FormControl$1, Select as Select$1, createStyles as createStyles$1, List, ListItem, ListItemText } from '@material-ui/core';
2
- import { values, get, isNil as isNil$1, isEmpty, isNaN, debounce } from 'lodash-es';
1
+ import { Typography, TextField, makeStyles as makeStyles$1, Button as Button$1, Grid as Grid$1, Dialog as Dialog$1, DialogTitle as DialogTitle$2, DialogContent as DialogContent$2, DialogContentText, DialogActions as DialogActions$2, FormHelperText, CircularProgress as CircularProgress$1, Badge, FormControlLabel, Checkbox, Snackbar as Snackbar$1, Paper as Paper$1, MenuItem as MenuItem$1, useTheme as useTheme$1, Box, Tooltip, IconButton as IconButton$1, FormControl as FormControl$1, Select as Select$1, debounce, createStyles as createStyles$1, List, ListItem, ListItemText } from '@material-ui/core';
2
+ import { values, get, isNil as isNil$1, isEmpty, isNaN } from 'lodash-es';
3
3
  import * as React from 'react';
4
4
  import React__default, { useState, useRef, useEffect, Component, createContext, useContext, useMemo, useCallback, lazy, Suspense } from 'react';
5
5
  import { Alert as Alert$1, Modal as Modal$1, Navbar, Container, Nav, NavDropdown } from 'react-bootstrap';
@@ -20,17 +20,17 @@ import Grid from '@material-ui/core/Grid';
20
20
  import { isNil, get as get$1 } from 'lodash';
21
21
  import { DndProvider } from 'react-dnd';
22
22
  import { HTML5Backend } from 'react-dnd-html5-backend';
23
- import { ArrowRight, ChevronLeft, ChevronRight } from '@material-ui/icons';
24
23
  import axios from 'axios';
25
24
  import { _adapters, Chart, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip as Tooltip$1, Legend, TimeScale } from 'chart.js';
26
25
  import moment from 'moment';
27
26
  import zoomPlugin from 'chartjs-plugin-zoom';
28
- import { Line } from 'react-chartjs-2';
29
27
  import Popover from '@material-ui/core/Popover';
30
28
  import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
31
29
  import FolderIcon from '@material-ui/icons/Folder';
32
30
  import InsertDriveFileIcon from '@material-ui/icons/InsertDriveFile';
33
31
  import { Alert as Alert$3, TreeView as TreeView$1, TreeItem as TreeItem$1 } from '@material-ui/lab';
32
+ import { ArrowRight, ChevronLeft, ChevronRight } from '@material-ui/icons';
33
+ import { Line } from 'react-chartjs-2';
34
34
  import PersonPinCircleIcon from '@material-ui/icons/PersonPinCircle';
35
35
  import PropTypes from 'prop-types';
36
36
  import { ResponsiveBar } from '@nivo/bar';
@@ -6966,7 +6966,7 @@ var MESApiService = /** @class */ (function () {
6966
6966
  return [2 /*return*/, { ok: true, data: resp }];
6967
6967
  case 4:
6968
6968
  err_1 = _a.sent();
6969
- console.log("fromCatch", err_1);
6969
+ // console.log("fromCatch", err);
6970
6970
  this.hasErrors = true;
6971
6971
  this.error = err_1;
6972
6972
  return [2 /*return*/, { ok: false, message: err_1.toString() }];
@@ -8155,7 +8155,7 @@ var AreaSelector$1 = lazy(function () {
8155
8155
  "default": mod.AreaSelector
8156
8156
  }); });
8157
8157
  });
8158
- function Header(_a) {
8158
+ function Header$1(_a) {
8159
8159
  var _b = _a.showAreaSelector, showAreaSelector = _b === void 0 ? false : _b, _c = _a.navbarTitle, navbarTitle = _c === void 0 ? "MESF" : _c;
8160
8160
  var getUserName = useToken().getUserName;
8161
8161
  var _d = useState(""), error = _d[0], setError = _d[1];
@@ -8524,7 +8524,7 @@ var TagSelectionModal = function (_a) {
8524
8524
  /* I have to get the grandchildren because the toggle action would not be triggered if no children */
8525
8525
  var handleNodeToggle = function (event, nodeIds) { return __awaiter(void 0, void 0, void 0, function () {
8526
8526
  return __generator(this, function (_a) {
8527
- console.log("Toggle:", nodeIds);
8527
+ // console.log("Toggle:", nodeIds);
8528
8528
  setExpanded(nodeIds);
8529
8529
  return [2 /*return*/];
8530
8530
  });
@@ -8532,8 +8532,6 @@ var TagSelectionModal = function (_a) {
8532
8532
  var handleNodeSelect = function (event, nodeId) { return __awaiter(void 0, void 0, void 0, function () {
8533
8533
  var node;
8534
8534
  return __generator(this, function (_a) {
8535
- // console.log('Selected Node ID:', nodeId);
8536
- console.log("treeData", treeData);
8537
8535
  node = findNode(treeData, nodeId);
8538
8536
  if (node === null || node === void 0 ? void 0 : node.tagId) {
8539
8537
  onTagSelect(node.tag);
@@ -8696,7 +8694,6 @@ var useTagsTableStyles = makeStyles$1(function (theme) { return ({
8696
8694
  }); });
8697
8695
 
8698
8696
  var timeDifference = function (start, end) {
8699
- console.log(start, end);
8700
8697
  var differenceMilliseconds = start - end;
8701
8698
  var seconds = Math.floor(differenceMilliseconds / 1000);
8702
8699
  var minutes = Math.floor(seconds / 60);
@@ -8707,7 +8704,7 @@ var timeDifference = function (start, end) {
8707
8704
  };
8708
8705
 
8709
8706
  var TableComponent = function (_a) {
8710
- var tagList = _a.tagList, setTagList = _a.setTagList, chartData = _a.chartData, cursorData = _a.cursorData, onDeleteTag = _a.onDeleteTag, onAddTag = _a.onAddTag;
8707
+ var tagList = _a.tagList, setTagList = _a.setTagList, chartData = _a.chartData, cursorData = _a.cursorData;
8711
8708
  var classes = useTagsTableStyles();
8712
8709
  var _b = useState(""); _b[0]; _b[1];
8713
8710
  var dataTable = useTagsDataTable({ tagList: tagList, chartData: chartData, cursorData: cursorData });
@@ -8732,6 +8729,22 @@ var TableComponent = function (_a) {
8732
8729
  var handleColorChange = function (tagId, value) {
8733
8730
  setTagList(function (prev) { return prev.map(function (tag) { return tag.tagId === tagId ? __assign(__assign({}, tag), { color: value }) : tag; }); });
8734
8731
  };
8732
+ var handleDeleteTag = function (tagId) {
8733
+ setTagList(function (prevTagList) {
8734
+ return prevTagList.filter(function (tag) { return tag.tagId !== tagId; });
8735
+ });
8736
+ };
8737
+ var handleAddTag = function (newTag) {
8738
+ if (newTag) {
8739
+ setTagList(function (prevTagList) {
8740
+ // Check if the tag is already in the list to avoid duplicates
8741
+ if (prevTagList.some(function (tag) { return tag.tagId === newTag.tagId; })) {
8742
+ return prevTagList; // Return the existing list if the tag is already there
8743
+ }
8744
+ return __spreadArray(__spreadArray([], prevTagList, true), [newTag], false); // Add the new tag to the list
8745
+ });
8746
+ }
8747
+ };
8735
8748
  var _d = useState(null), selectedRowIndex = _d[0], setSelectedRowIndex = _d[1];
8736
8749
  var _e = useState(false), addTagModalOpen = _e[0], setAddTagModalOpen = _e[1];
8737
8750
  var handleClose = function () { return setAddTagModalOpen(false); };
@@ -8751,48 +8764,15 @@ var TableComponent = function (_a) {
8751
8764
  { id: 'saveDefault', label: 'Save Default To Tag', onClick: function () { } },
8752
8765
  { id: 'saveAsView', label: 'Save as View', onClick: function () { } },
8753
8766
  { id: 'loadView', label: 'Load View', onClick: function () { } },
8754
- // ... other options
8755
8767
  ];
8756
- // const binarySearch = (arr: any, searchDate: Date): number | null => {
8757
- // let left = 0;
8758
- // let right = arr.length - 1;
8759
- // let closest: number | null = null;
8760
- // if (!arr.length) return null;
8761
- // while (left <= right) {
8762
- // const mid = Math.floor((left + right) / 2);
8763
- // const midDate = arr[mid].x; // Asegúrate de que esto es una instancia de Date
8764
- // const midTimestamp = midDate.getTime(); // Esto es un number
8765
- // const searchTimestamp = searchDate.getTime(); // Esto también es un number
8766
- // console.log(midTimestamp, searchTimestamp);
8767
- // if (midTimestamp === searchTimestamp) {
8768
- // return arr[mid].y;
8769
- // } else if (midTimestamp < searchTimestamp) {
8770
- // left = mid + 1;
8771
- // } else {
8772
- // right = mid - 1;
8773
- // }
8774
- // // Revisa si midDate está más cerca que el 'closest' actual
8775
- // if (closest === null || Math.abs(midTimestamp - searchTimestamp) < Math.abs(arr[closest].x.getTime() - searchTimestamp)) {
8776
- // closest = mid;
8777
- // }
8778
- // }
8779
- // return closest !== null ? arr[closest].y : null;
8780
- // };
8781
- // useEffect(() => {
8782
- // if (cursorData) {
8783
- // const yValue = binarySearch(chartData.datasets[0]?.data, new Date(cursorData.x1));
8784
- // if(yValue)console.log(yValue,"retorna binary")
8785
- // }
8786
- // else console.log("NULL")
8787
- // }, [cursorData,chartData.datasets[1]?.data])
8788
8768
  var handleTagSelect = function (selectedTag) {
8789
- onAddTag(selectedTag);
8769
+ handleAddTag(selectedTag);
8790
8770
  handleClose();
8791
8771
  };
8792
8772
  var handleDelete = function (index) {
8793
8773
  if (selectedRowIndex !== null) {
8794
8774
  var tagToDelete = tagList[selectedRowIndex];
8795
- onDeleteTag(tagToDelete.tagId);
8775
+ handleDeleteTag(tagToDelete.tagId);
8796
8776
  setSelectedRowIndex(null); // Reset the selected row index
8797
8777
  }
8798
8778
  };
@@ -8843,7 +8823,6 @@ var TableComponent = function (_a) {
8843
8823
  React__default.createElement("th", { colSpan: 4, className: "".concat(classes.topTitles, " ").concat(classes.scale) }, "Scale"),
8844
8824
  React__default.createElement("th", { className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? (function () {
8845
8825
  var date = new Date(cursorData.x1);
8846
- // console.log(cursorData, "cursor data")
8847
8826
  var formattedDate = date.toLocaleString('en-US', {
8848
8827
  hour12: false,
8849
8828
  month: 'short',
@@ -8867,7 +8846,6 @@ var TableComponent = function (_a) {
8867
8846
  })() : null),
8868
8847
  React__default.createElement("th", { className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? (function () {
8869
8848
  var date = new Date(cursorData.x2);
8870
- // console.log(cursorData, "cursor data")
8871
8849
  var formattedDate = date.toLocaleString('en-US', {
8872
8850
  hour12: false,
8873
8851
  month: 'short',
@@ -8960,44 +8938,6 @@ var TableComponent = function (_a) {
8960
8938
  React__default.createElement(AddTagModal, { open: addTagModalOpen, handleClose: handleClose, onTagSelect: handleTagSelect })));
8961
8939
  };
8962
8940
 
8963
- var DraggableLineControl = function (_a) {
8964
- var initialLeft = _a.initialLeft, onUpdate = _a.onUpdate, color = _a.color, chartArea = _a.chartArea;
8965
- var _b = useState(false), isDragging = _b[0], setIsDragging = _b[1];
8966
- var _c = useState(initialLeft), left = _c[0], setLeft = _c[1];
8967
- var ref = useRef(null);
8968
- var handleMouseDown = function (e) {
8969
- setIsDragging(true);
8970
- e.stopPropagation();
8971
- e.preventDefault();
8972
- };
8973
- var handleMouseMove = function (e) {
8974
- if (!isDragging || !ref.current)
8975
- return;
8976
- chartArea.width - chartArea.right;
8977
- chartArea.left;
8978
- var newLeft = Math.min(Math.max(e.clientX - ref.current.offsetParent.getBoundingClientRect().left, chartArea.left), chartArea.right);
8979
- setLeft(newLeft);
8980
- onUpdate(newLeft); // Actualiza la posición de la línea en el gráfico
8981
- };
8982
- var handleMouseUp = function () {
8983
- setIsDragging(false);
8984
- };
8985
- useEffect(function () {
8986
- var mouseMoveHandler = function (e) { return handleMouseMove(e); };
8987
- var mouseUpHandler = function () { return handleMouseUp(); };
8988
- if (isDragging) {
8989
- window.addEventListener('mousemove', mouseMoveHandler);
8990
- window.addEventListener('mouseup', mouseUpHandler);
8991
- }
8992
- return function () {
8993
- window.removeEventListener('mousemove', mouseMoveHandler);
8994
- window.removeEventListener('mouseup', mouseUpHandler);
8995
- };
8996
- }, [isDragging]);
8997
- return (React__default.createElement("div", { ref: ref, style: { height: 20, width: 20, background: color, position: 'absolute', top: -10, left: left - 10 }, onMouseDown: handleMouseDown },
8998
- React__default.createElement("div", { style: { height: chartArea.height, width: 2, background: color, position: 'relative', top: 20, left: 0, right: 0, margin: 'auto' } })));
8999
- };
9000
-
9001
8941
  var TrendingsInitialState = {
9002
8942
  timeScopeStart: moment(new Date()).subtract(1, "days").toDate(),
9003
8943
  timeScopeEnd: new Date(),
@@ -9162,6 +9102,129 @@ var TrendingProvider = function (_a) {
9162
9102
  return (React__default.createElement(TrendingContext.Provider, { value: { state: state, actions: actions } }, children));
9163
9103
  };
9164
9104
 
9105
+ var formatDateTimeToString = function (date) {
9106
+ var hour = date.getHours().toString().padStart(2, '0');
9107
+ var minute = date.getMinutes().toString().padStart(2, '0');
9108
+ var second = date.getSeconds().toString().padStart(2, '0');
9109
+ if (hour === '24') {
9110
+ hour = '00';
9111
+ }
9112
+ var formattedDate = date.toLocaleDateString("en-US", {
9113
+ month: "short",
9114
+ day: "numeric"
9115
+ });
9116
+ var formattedTime = "".concat(hour, ":").concat(minute, ":").concat(second);
9117
+ return { formattedDate: formattedDate, formattedTime: formattedTime };
9118
+ };
9119
+
9120
+ var useChartOptions = function () {
9121
+ var _a = useTrendingContext(); _a.state; var actions = _a.actions;
9122
+ var debounceTimerRef = useRef(null);
9123
+ var handleZoom = function (_a) {
9124
+ var chart = _a.chart;
9125
+ if (debounceTimerRef.current) {
9126
+ clearTimeout(debounceTimerRef.current);
9127
+ }
9128
+ debounceTimerRef.current = setTimeout(function () {
9129
+ // Handle zoom event and execute fetch
9130
+ var newStart = new Date(chart.scales.x.min);
9131
+ var newEnd = new Date(chart.scales.x.max);
9132
+ actions.setTotalScope({
9133
+ start: newStart,
9134
+ end: newEnd
9135
+ });
9136
+ }, 1000);
9137
+ };
9138
+ var handlePan = function (_a) {
9139
+ var chart = _a.chart;
9140
+ if (debounceTimerRef.current) {
9141
+ clearTimeout(debounceTimerRef.current);
9142
+ }
9143
+ debounceTimerRef.current = setTimeout(function () {
9144
+ // Handle pan event and execute fetch
9145
+ var newStart = new Date(chart.scales.x.min);
9146
+ var newEnd = new Date(chart.scales.x.max);
9147
+ actions.setTotalScope({
9148
+ start: newStart,
9149
+ end: newEnd,
9150
+ graphPan: true
9151
+ });
9152
+ }, 1000);
9153
+ };
9154
+ return useState({
9155
+ animation: {
9156
+ duration: 0
9157
+ },
9158
+ responsive: true,
9159
+ maintainAspectRatio: false,
9160
+ scales: {
9161
+ x: {
9162
+ type: "time",
9163
+ ticks: {
9164
+ autoSkip: true,
9165
+ maxTicksLimit: 20,
9166
+ callback: function (value, index, ticks) {
9167
+ var currentDate = new Date(value);
9168
+ var time = formatDateTimeToString(currentDate).formattedTime;
9169
+ var date = formatDateTimeToString(currentDate).formattedDate;
9170
+ // Si es el primer tick, siempre muestra la fecha y hora
9171
+ if (index === 0) {
9172
+ return [time, date];
9173
+ }
9174
+ // De lo contrario, solo muestra la hora
9175
+ return time;
9176
+ }
9177
+ },
9178
+ grid: {
9179
+ display: true
9180
+ }
9181
+ },
9182
+ y: {
9183
+ grid: {
9184
+ display: true
9185
+ },
9186
+ afterUpdate: function (axis) {
9187
+ var chart = axis.chart;
9188
+ var keys = Object.keys(chart.scales).filter(function (sc) { return sc !== 'x'; });
9189
+ if (keys.length > 1) {
9190
+ for (var scaleKey in chart.scales) {
9191
+ var scale = chart.scales[scaleKey];
9192
+ if (scale.max === 1 && scale.min === 0) {
9193
+ chart.scales[scaleKey].display = false;
9194
+ chart.scales[scaleKey].options.display = false;
9195
+ }
9196
+ else {
9197
+ chart.scales[scaleKey].display = true;
9198
+ chart.scales[scaleKey].options.display = true;
9199
+ }
9200
+ }
9201
+ }
9202
+ else {
9203
+ console.log('sin y', keys);
9204
+ }
9205
+ }
9206
+ }
9207
+ },
9208
+ plugins: {
9209
+ tooltip: { enabled: false },
9210
+ legend: { display: false },
9211
+ zoom: {
9212
+ zoom: {
9213
+ wheel: { enabled: true, mode: "x" },
9214
+ pinch: { enabled: true, mode: "x" },
9215
+ onZoom: handleZoom,
9216
+ mode: "x"
9217
+ },
9218
+ pan: {
9219
+ enabled: true,
9220
+ mode: "x",
9221
+ onPan: handlePan
9222
+ }
9223
+ }
9224
+ }
9225
+ });
9226
+ };
9227
+
9165
9228
  var useTrendingStyles = makeStyles$1(function (theme) { return ({
9166
9229
  datetimePicker: {
9167
9230
  alignItems: "center",
@@ -9240,8 +9303,131 @@ var CustomOptionsComponent = function (_a) {
9240
9303
  "Stepped"))));
9241
9304
  };
9242
9305
 
9306
+ var dateNavigator = function (startDate, endDate, scope, operator) {
9307
+ if (scope === "custom")
9308
+ return;
9309
+ else {
9310
+ var _a = scope.split(" "), quantity = _a[0], duration = _a[1];
9311
+ var newStartDate = moment(startDate)[operator](quantity, duration[0]).toDate();
9312
+ var newEndDate = moment(endDate)[operator](quantity, duration[0]).toDate();
9313
+ return { newStartDate: newStartDate, newEndDate: newEndDate };
9314
+ }
9315
+ };
9316
+
9317
+ var Header = function (_a) {
9318
+ var setChartOptions = _a.setChartOptions;
9319
+ var classes = useTrendingStyles();
9320
+ var _b = useTrendingContext(), state = _b.state, actions = _b.actions;
9321
+ var _c = useState({
9322
+ showGrid: true,
9323
+ stepped: false
9324
+ }), customOptions = _c[0], setCustomOptions = _c[1];
9325
+ var handleDateNavigator = function (operator) {
9326
+ var newDates = dateNavigator(state.timeScopeStart, state.timeScopeEnd, state.scope, operator);
9327
+ if (newDates) {
9328
+ actions.setTotalScope({ start: newDates.newStartDate, end: newDates.newEndDate, scope: state.scope });
9329
+ }
9330
+ };
9331
+ var handleDateChange = function (newValue, key) {
9332
+ var _a;
9333
+ //@ts-ignore
9334
+ actions.setTotalScope((_a = {}, _a[key] = moment(newValue).toDate(), _a));
9335
+ };
9336
+ var handleChangeScope = function (e) {
9337
+ var newScope = e.target.value;
9338
+ actions.setTotalScope({
9339
+ scope: newScope
9340
+ });
9341
+ };
9342
+ useEffect(function () {
9343
+ var changeOptions = function () {
9344
+ // console.log("change options");
9345
+ setChartOptions(function (prevOptions) { return (__assign(__assign({}, prevOptions), { elements: {
9346
+ line: {
9347
+ stepped: customOptions.stepped,
9348
+ lineTension: 0.1
9349
+ }
9350
+ }, scales: __assign(__assign({}, prevOptions.scales), { x: __assign(__assign({}, prevOptions.scales.x), { grid: __assign(__assign({}, prevOptions.scales.x.grid), { display: customOptions.showGrid }) }), y: __assign(__assign({}, prevOptions.scales.y), { grid: __assign(__assign({}, prevOptions.scales.y.grid), { display: customOptions.showGrid }) }) }) })); });
9351
+ };
9352
+ changeOptions();
9353
+ }, [customOptions]);
9354
+ useEffect(function () {
9355
+ setChartOptions(function (prevOptions) { return (__assign(__assign({}, prevOptions), { scales: __assign(__assign({}, prevOptions.scales), { x: __assign(__assign({}, prevOptions.scales.x), { min: state.timeScopeStart.getTime(), max: state.timeScopeEnd.getTime() }) }) })); });
9356
+ }, [state.timeScopeStart, state.timeScopeEnd]);
9357
+ return (React__default.createElement(Grid$1, { item: true, xs: 12, container: true, justifyContent: "space-between", alignItems: "center", style: { height: "15%" } },
9358
+ React__default.createElement(Grid$1, { md: 5, item: true, container: true, justifyContent: "flex-start", alignItems: "center", spacing: 1, wrap: "wrap" },
9359
+ React__default.createElement(IconButton$1, { color: "primary", onClick: function () { return handleDateNavigator("subtract"); }, className: classes.navigatorButton },
9360
+ React__default.createElement(ChevronLeft, { fontSize: "large" })),
9361
+ React__default.createElement(Grid$1, { item: true },
9362
+ React__default.createElement(TextField, { type: "datetime-local", className: classes.datetimePicker, label: "Start", variant: "outlined", value: moment(state.timeScopeStart).format("YYYY-MM-DDTHH:mm:ss"), onChange: function (e) { return handleDateChange(e.target.value, "start"); }, InputLabelProps: {
9363
+ shrink: true,
9364
+ style: { marginLeft: "10px" }
9365
+ }, InputProps: {
9366
+ max: state.timeScopeEnd
9367
+ } })),
9368
+ React__default.createElement(Grid$1, { item: true, className: classes.select },
9369
+ React__default.createElement(FormControl$1, { variant: "outlined" },
9370
+ React__default.createElement(Select$1, { value: state.scope, onChange: handleChangeScope, displayEmpty: true },
9371
+ React__default.createElement(MenuItem$1, { value: "10 min" }, "10 min"),
9372
+ React__default.createElement(MenuItem$1, { value: "1 hour" }, "1 hour"),
9373
+ React__default.createElement(MenuItem$1, { value: "4 hours" }, "4 hours"),
9374
+ React__default.createElement(MenuItem$1, { value: "12 hours" }, "12 hours"),
9375
+ React__default.createElement(MenuItem$1, { value: "1 day" }, "1 day"),
9376
+ React__default.createElement(MenuItem$1, { value: "10 days" }, "10 days"),
9377
+ React__default.createElement(MenuItem$1, { value: "custom" }, "Custom")))),
9378
+ React__default.createElement(Grid$1, { item: true },
9379
+ React__default.createElement(TextField, { label: "End", variant: "outlined", className: classes.datetimePicker, type: "datetime-local", value: moment(state.timeScopeEnd).format("YYYY-MM-DDTHH:mm:ss"), onChange: function (e) { return handleDateChange(e.target.value, "end"); }, InputLabelProps: {
9380
+ shrink: true,
9381
+ style: { marginLeft: "10px" }
9382
+ } })),
9383
+ React__default.createElement(IconButton$1, { color: "primary", onClick: function () { return handleDateNavigator("add"); }, className: classes.navigatorButton },
9384
+ React__default.createElement(ChevronRight, { fontSize: "large" }))),
9385
+ React__default.createElement(Grid$1, { md: 7, item: true, container: true, justifyContent: "space-between" },
9386
+ React__default.createElement(Grid$1, { item: true, container: true, wrap: "nowrap", spacing: 1 },
9387
+ React__default.createElement(Grid$1, { item: true, container: true },
9388
+ React__default.createElement(CustomOptionsComponent, { customOptions: customOptions, setCustomOptions: setCustomOptions }))))));
9389
+ };
9390
+
9391
+ var DraggableLineControl = function (_a) {
9392
+ var initialLeft = _a.initialLeft, onUpdate = _a.onUpdate, color = _a.color, chartArea = _a.chartArea;
9393
+ var _b = useState(false), isDragging = _b[0], setIsDragging = _b[1];
9394
+ var _c = useState(initialLeft), left = _c[0], setLeft = _c[1];
9395
+ var ref = useRef(null);
9396
+ var handleMouseDown = function (e) {
9397
+ setIsDragging(true);
9398
+ e.stopPropagation();
9399
+ e.preventDefault();
9400
+ };
9401
+ var handleMouseMove = function (e) {
9402
+ if (!isDragging || !ref.current)
9403
+ return;
9404
+ chartArea.width - chartArea.right;
9405
+ chartArea.left;
9406
+ var newLeft = Math.min(Math.max(e.clientX - ref.current.offsetParent.getBoundingClientRect().left, chartArea.left), chartArea.right);
9407
+ setLeft(newLeft);
9408
+ onUpdate(newLeft); // Actualiza la posición de la línea en el gráfico
9409
+ };
9410
+ var handleMouseUp = function () {
9411
+ setIsDragging(false);
9412
+ };
9413
+ useEffect(function () {
9414
+ var mouseMoveHandler = function (e) { return handleMouseMove(e); };
9415
+ var mouseUpHandler = function () { return handleMouseUp(); };
9416
+ if (isDragging) {
9417
+ window.addEventListener('mousemove', mouseMoveHandler);
9418
+ window.addEventListener('mouseup', mouseUpHandler);
9419
+ }
9420
+ return function () {
9421
+ window.removeEventListener('mousemove', mouseMoveHandler);
9422
+ window.removeEventListener('mouseup', mouseUpHandler);
9423
+ };
9424
+ }, [isDragging]);
9425
+ return (React__default.createElement("div", { ref: ref, style: { height: 20, width: 20, background: color, position: 'absolute', top: -10, left: left - 10 }, onMouseDown: handleMouseDown },
9426
+ React__default.createElement("div", { style: { height: chartArea.height, width: 2, background: color, position: 'relative', top: 20, left: 0, right: 0, margin: 'auto' } })));
9427
+ };
9428
+
9243
9429
  var useGetVerticalLinePlugin = function (setChartArea, setCoords) {
9244
- return {
9430
+ var chartPlugin = {
9245
9431
  id: "verticalLinePlugin",
9246
9432
  afterUpdate: function (chart) {
9247
9433
  if (chart.chartArea) {
@@ -9267,6 +9453,7 @@ var useGetVerticalLinePlugin = function (setChartArea, setCoords) {
9267
9453
  setCoords({ x1: x1, x2: x2 });
9268
9454
  }
9269
9455
  };
9456
+ return chartPlugin;
9270
9457
  };
9271
9458
 
9272
9459
  var getValuesAtCursor = function (chart, timeAtCursor) {
@@ -9302,6 +9489,44 @@ var updateCursorData = function (chart, setCursorData) {
9302
9489
  });
9303
9490
  };
9304
9491
 
9492
+ var useXAxisDatePlugin = function () {
9493
+ var chartPlugin = {
9494
+ id: 'xAxisDatePlugin',
9495
+ afterBuildTicks: function (chart) {
9496
+ var oldTicks = chart.scales.x.ticks;
9497
+ var newTicks = [];
9498
+ newTicks.push(oldTicks[0]);
9499
+ for (var i = 1; i < oldTicks.length; i++) {
9500
+ var current = new Date(oldTicks[i].value);
9501
+ var previous = new Date(oldTicks[i - 1].value);
9502
+ var time = formatDateTimeToString(current).formattedTime;
9503
+ var date = formatDateTimeToString(current).formattedDate;
9504
+ var newLabel = void 0;
9505
+ if (current.getDate() !== previous.getDate()) {
9506
+ newLabel = [time, date];
9507
+ }
9508
+ else {
9509
+ newLabel = time;
9510
+ }
9511
+ newTicks.push({
9512
+ value: oldTicks[i].value,
9513
+ major: oldTicks[i].major,
9514
+ label: newLabel
9515
+ });
9516
+ }
9517
+ chart.scales.x.ticks = newTicks;
9518
+ }
9519
+ };
9520
+ return chartPlugin;
9521
+ };
9522
+
9523
+ var useYAxisPlugin = function () {
9524
+ var chartPlugin = {
9525
+ id: 'yAxisPlugin'
9526
+ };
9527
+ return chartPlugin;
9528
+ };
9529
+
9305
9530
  var areRangesSimilar = function (tag1, tag2) {
9306
9531
  var range1 = tag1.maxScale - tag1.minScale; // Rango de la primera etiqueta
9307
9532
  var range2 = tag2.maxScale - tag2.minScale; // Rango de la segunda etiqueta
@@ -9334,288 +9559,109 @@ var calculateScales = function (min, max, sigDigits) {
9334
9559
  return { minScale: minScale, maxScale: maxScale };
9335
9560
  };
9336
9561
 
9337
- var dateNavigator = function (startDate, endDate, scope, operator) {
9338
- if (scope === "custom")
9339
- return;
9340
- else {
9341
- var _a = scope.split(" "), quantity = _a[0], duration = _a[1];
9342
- var newStartDate = moment(startDate)[operator](quantity, duration[0]).toDate();
9343
- var newEndDate = moment(endDate)[operator](quantity, duration[0]).toDate();
9344
- return { newStartDate: newStartDate, newEndDate: newEndDate };
9345
- }
9346
- };
9347
-
9348
- Chart.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip$1, Legend, TimeScale, zoomPlugin);
9349
- var Trending = function (_a) {
9350
- _a.title; var tags = _a.tags;
9351
- var classes = useTrendingStyles();
9352
- var _b = useTrendingContext(), state = _b.state, actions = _b.actions;
9353
- var _c = useState(true), loading = _c[0], setLoading = _c[1];
9354
- var _d = useState(""), error = _d[0], setError = _d[1];
9355
- var _e = useState(tags), tagList = _e[0], setTagList = _e[1];
9356
- var _f = useState(null), cursorData = _f[0], setCursorData = _f[1];
9357
- var _g = useState(null), lineTabCoords = _g[0], setLineTabCoords = _g[1];
9358
- var _h = useState(null), chartArea = _h[0], setChartArea = _h[1];
9359
- var _j = useState(false), chartShouldInitCursors = _j[0], setChartShouldInitCursors = _j[1];
9562
+ var TrendingChart = function (_a) {
9563
+ var tagList = _a.tagList, series = _a.series, chartOptions = _a.chartOptions, setChartOptions = _a.setChartOptions, chartData = _a.chartData, setCursorData = _a.setCursorData, setChartData = _a.setChartData;
9564
+ var _b = useTrendingContext(), state = _b.state; _b.actions;
9565
+ var _c = useState(null), lineTabCoords = _c[0], setLineTabCoords = _c[1];
9566
+ var _d = useState(null), chartArea = _d[0], setChartArea = _d[1];
9360
9567
  var chartRef = useRef(null);
9361
- var _k = useState({
9362
- labels: [],
9363
- datasets: []
9364
- }), chartData = _k[0], setChartData = _k[1];
9365
- var verticalLinePlugin = useGetVerticalLinePlugin(setChartArea, setLineTabCoords);
9366
- var _l = useState({
9367
- showGrid: true,
9368
- stepped: false
9369
- }), customOptions = _l[0], setCustomOptions = _l[1];
9370
- var debounceTimerRef = useRef(null);
9371
9568
  var debouncedUpdateChart = useRef(debounce(function () {
9372
9569
  if (chartRef.current) {
9373
9570
  updateCursorData(chartRef.current, setCursorData);
9374
9571
  chartRef.current.update();
9375
9572
  }
9376
9573
  }, 250)).current;
9377
- var handleDateChange = function (newValue, key) {
9378
- var _a;
9379
- //@ts-ignore
9380
- actions.setTotalScope((_a = {}, _a[key] = moment(newValue).toDate(), _a));
9381
- };
9382
- var handleChangeScope = function (e) {
9383
- var newScope = e.target.value;
9384
- actions.setTotalScope({
9385
- scope: newScope
9386
- });
9387
- };
9388
- var handleZoom = function (_a) {
9389
- var chart = _a.chart;
9390
- if (debounceTimerRef.current) {
9391
- clearTimeout(debounceTimerRef.current);
9392
- }
9393
- debounceTimerRef.current = setTimeout(function () {
9394
- // Handle zoom event and execute fetch
9395
- var newStart = new Date(chart.scales.x.min);
9396
- var newEnd = new Date(chart.scales.x.max);
9397
- actions.setTotalScope({
9398
- start: newStart,
9399
- end: newEnd
9400
- });
9401
- }, 1000);
9402
- };
9403
- var handlePan = function (_a) {
9404
- var chart = _a.chart;
9405
- if (debounceTimerRef.current) {
9406
- clearTimeout(debounceTimerRef.current);
9574
+ var _e = useState(false), chartShouldInitCursors = _e[0], setChartShouldInitCursors = _e[1];
9575
+ var verticalLinePlugin = useGetVerticalLinePlugin(setChartArea, setLineTabCoords);
9576
+ var xAxisDatePlugin = useXAxisDatePlugin();
9577
+ var yAxisPlugin = useYAxisPlugin();
9578
+ useEffect(function () {
9579
+ var axes = [];
9580
+ if (!series.length) {
9581
+ return;
9407
9582
  }
9408
- debounceTimerRef.current = setTimeout(function () {
9409
- // Handle pan event and execute fetch
9410
- var newStart = new Date(chart.scales.x.min);
9411
- var newEnd = new Date(chart.scales.x.max);
9412
- actions.setTotalScope({
9413
- start: newStart,
9414
- end: newEnd,
9415
- graphPan: true
9416
- });
9417
- }, 1000);
9418
- };
9419
- var handleDeleteTag = function (tagId) {
9420
- setTagList(function (prevTagList) {
9421
- return prevTagList.filter(function (tag) { return tag.tagId !== tagId; });
9422
- });
9423
- };
9424
- var handleAddTag = function (newTag) {
9425
- if (newTag) {
9426
- setTagList(function (prevTagList) {
9427
- // Check if the tag is already in the list to avoid duplicates
9428
- if (prevTagList.some(function (tag) { return tag.tagId === newTag.tagId; })) {
9429
- return prevTagList; // Return the existing list if the tag is already there
9583
+ tagList.forEach(function (tag, index) {
9584
+ if (series[index].length) {
9585
+ if (tag.autoScale && series[index]) {
9586
+ var serieSamples = series[index].map(function (sample) { return sample.value; });
9587
+ var _a = calculateScales(Math.min.apply(Math, serieSamples), Math.max.apply(Math, serieSamples), 3), minScale = _a.minScale, maxScale = _a.maxScale;
9588
+ tag.minScale = minScale;
9589
+ tag.maxScale = maxScale;
9430
9590
  }
9431
- return __spreadArray(__spreadArray([], prevTagList, true), [newTag], false); // Add the new tag to the list
9432
- });
9433
- }
9434
- };
9435
- var handleDateNavigator = function (operator) {
9436
- var newDates = dateNavigator(state.timeScopeStart, state.timeScopeEnd, state.scope, operator);
9437
- if (newDates) {
9438
- actions.setTotalScope({ start: newDates.newStartDate, end: newDates.newEndDate, scope: state.scope });
9439
- }
9440
- };
9441
- var _m = useState({
9442
- animation: {
9443
- duration: 0
9444
- },
9445
- responsive: true,
9446
- maintainAspectRatio: false,
9447
- scales: {
9448
- x: {
9449
- type: "time",
9591
+ var existingAxis = axes.find(function (existingTag) {
9592
+ return areRangesSimilar(existingTag, tag);
9593
+ });
9594
+ if (!existingAxis) {
9595
+ axes.push(tag); // Add new axis if no similar one exists
9596
+ }
9597
+ }
9598
+ });
9599
+ // Configure yAxes based on grouped axes
9600
+ var yAxesConfig = axes.map(function (axis, index) {
9601
+ return {
9602
+ id: "y-axis-".concat(index),
9603
+ type: "linear",
9604
+ display: axis.visible,
9605
+ scaleLabel: {
9606
+ display: true,
9607
+ labelString: axis.tagName
9608
+ },
9450
9609
  ticks: {
9451
- // Customize tick behavior if needed
9452
- autoSkip: true,
9453
- maxTicksLimit: 20,
9454
- callback: function (value, index, values) {
9455
- // Extract the time and date from the current value
9456
- var currentDate = new Date(value);
9457
- var time = currentDate.toLocaleTimeString("en-US", {
9458
- hour12: false,
9459
- hour: "2-digit",
9460
- minute: "2-digit",
9461
- second: "2-digit"
9462
- });
9463
- var date = currentDate.toLocaleDateString("en-US", {
9464
- month: "short",
9465
- day: "numeric"
9466
- });
9467
- // For the first tick, return both date and time
9468
- if (index === 0) {
9469
- return [time, date];
9470
- }
9471
- // For subsequent ticks, compare the date with the previous tick
9472
- var previousDate = new Date(values[index - 1].value);
9473
- if (currentDate.getDate() !== previousDate.getDate() ||
9474
- currentDate.getMonth() !== previousDate.getMonth() ||
9475
- currentDate.getFullYear() !== previousDate.getFullYear()) {
9476
- // If the date has changed, return both time and date
9477
- return [time, date];
9478
- }
9479
- // If the date hasn't changed, return only the time
9480
- return [time, ""];
9481
- }
9610
+ min: axis.autoScale ? undefined : axis.minScale,
9611
+ max: axis.autoScale ? undefined : axis.maxScale
9482
9612
  },
9483
9613
  grid: {
9484
9614
  display: true
9485
- }
9486
- },
9487
- y: {
9488
- grid: {
9489
- display: true
9490
- }
9491
- }
9492
- },
9493
- plugins: {
9494
- tooltip: { enabled: false },
9495
- legend: { display: false },
9496
- zoom: {
9497
- zoom: {
9498
- wheel: { enabled: true, mode: "x" },
9499
- pinch: { enabled: true, mode: "x" },
9500
- onZoom: handleZoom,
9501
- mode: "x"
9502
9615
  },
9503
- pan: {
9504
- enabled: true,
9505
- mode: "x",
9506
- onPan: handlePan
9507
- }
9508
- }
9509
- }
9510
- }), chartOptions = _m[0], setChartOptions = _m[1];
9511
- useEffect(function () {
9512
- var fetchData = function () { return __awaiter(void 0, void 0, void 0, function () {
9513
- var tagIds, response, series_1, axes_1, updatedSeries, error_1;
9514
- return __generator(this, function (_a) {
9515
- switch (_a.label) {
9516
- case 0:
9517
- _a.trys.push([0, 2, , 3]);
9518
- console.log("fetching data");
9519
- setLoading(true);
9520
- tagIds = tagList.map(function (tag) { return tag.tagId; });
9521
- return [4 /*yield*/, axios.post("/series?nodeName=null", {
9522
- start: state.timeScopeStart.getTime(),
9523
- end: state.timeScopeEnd.getTime(),
9524
- tagIds: tagIds,
9525
- sampleCount: 1000
9526
- })];
9527
- case 1:
9528
- response = _a.sent();
9529
- series_1 = response.data;
9530
- axes_1 = [];
9531
- tagList.forEach(function (tag, index) {
9532
- if (tag.autoScale && series_1[index]) {
9533
- var serieSamples = series_1[index].map(function (sample) { return sample.value; });
9534
- var _a = calculateScales(Math.min.apply(Math, serieSamples), Math.max.apply(Math, serieSamples), 3), minScale = _a.minScale, maxScale = _a.maxScale;
9535
- tag.minScale = minScale;
9536
- tag.maxScale = maxScale;
9616
+ afterUpdate: function (axis) {
9617
+ var chart = axis.chart;
9618
+ var keys = Object.keys(chart.scales).filter(function (sc) { return sc !== 'x'; });
9619
+ if (keys.length > 1) {
9620
+ for (var scaleKey in chart.scales) {
9621
+ var scale = chart.scales[scaleKey];
9622
+ if (scale.max === 1 && scale.min === 0) {
9623
+ chart.scales[scaleKey].display = false;
9624
+ chart.scales[scaleKey].options.display = false;
9537
9625
  }
9538
- var existingAxis = axes_1.find(function (existingTag) {
9539
- return areRangesSimilar(existingTag, tag);
9540
- });
9541
- if (!existingAxis) {
9542
- axes_1.push(tag); // Add new axis if no similar one exists
9626
+ else {
9627
+ chart.scales[scaleKey].display = true;
9628
+ chart.scales[scaleKey].options.display = true;
9543
9629
  }
9544
- });
9545
- axes_1.map(function (axis, index) {
9546
- return {
9547
- id: "y-axis-".concat(index),
9548
- type: "linear",
9549
- display: axis.visible,
9550
- scaleLabel: {
9551
- display: true,
9552
- labelString: axis.tagName
9553
- },
9554
- ticks: {
9555
- min: axis.autoScale ? undefined : axis.minScale,
9556
- max: axis.autoScale ? undefined : axis.maxScale
9557
- },
9558
- grid: {
9559
- display: true
9560
- }
9561
- };
9562
- });
9563
- setChartOptions(function (prevOptions) { return (__assign(__assign({}, prevOptions), { scales: __assign(__assign({}, prevOptions.scales), { y: { grid: { display: true } } }) })); });
9564
- updatedSeries = series_1.map(function (serie, index) {
9565
- var tag = tagList[index];
9566
- var axisIndex = axes_1.findIndex(function (existingTag) {
9567
- return areRangesSimilar(existingTag, tag);
9568
- });
9569
- return {
9570
- yAxisID: "y-axis-".concat(axisIndex),
9571
- data: serie.map(function (sample) { return ({
9572
- x: new Date(sample.timestamp),
9573
- y: sample.value
9574
- }); }),
9575
- tagId: tag.tagId,
9576
- borderColor: tag.color,
9577
- hidden: !tag.visible,
9578
- pointRadius: serie.length <= 50 ? 3 : 0
9579
- };
9580
- });
9581
- setChartShouldInitCursors(true);
9582
- setChartData({
9583
- labels: [],
9584
- datasets: updatedSeries
9585
- });
9586
- setLoading(false);
9587
- return [3 /*break*/, 3];
9588
- case 2:
9589
- error_1 = _a.sent();
9590
- console.error("Error fetching data:", error_1);
9591
- setError("Failed to fetch data");
9592
- setLoading(false);
9593
- return [3 /*break*/, 3];
9594
- case 3: return [2 /*return*/];
9630
+ }
9631
+ }
9595
9632
  }
9633
+ };
9634
+ });
9635
+ setChartOptions(function (prevOptions) {
9636
+ var newResp = (__assign(__assign({}, prevOptions), { scales: __assign({ x: __assign({}, prevOptions.scales.x) }, yAxesConfig.reduce(function (acc, cur) {
9637
+ var _a;
9638
+ return (__assign(__assign({}, acc), (_a = {}, _a[cur.id] = cur, _a)));
9639
+ }, {})) }));
9640
+ return newResp;
9641
+ });
9642
+ var updatedSeries = series.map(function (serie, index) {
9643
+ var tag = tagList[index];
9644
+ var axisIndex = axes.findIndex(function (existingTag) {
9645
+ return areRangesSimilar(existingTag, tag);
9596
9646
  });
9597
- }); };
9598
- fetchData();
9599
- }, [JSON.stringify(state), tagList]);
9600
- useEffect(function () {
9601
- var changeOptions = function () {
9602
- // console.log("change options");
9603
- setChartOptions(function (prevOptions) { return (__assign(__assign({}, prevOptions), { elements: {
9604
- line: {
9605
- stepped: customOptions.stepped,
9606
- lineTension: 0.1
9607
- }
9608
- }, scales: __assign(__assign({}, prevOptions.scales), { x: __assign(__assign({}, prevOptions.scales.x), { grid: __assign(__assign({}, prevOptions.scales.x.grid), { display: customOptions.showGrid }) }), y: __assign(__assign({}, prevOptions.scales.y), { grid: __assign(__assign({}, prevOptions.scales.y.grid), { display: customOptions.showGrid }) }) }) })); });
9609
- };
9610
- changeOptions();
9611
- }, [customOptions]);
9612
- if (error)
9613
- return React__default.createElement("p", null,
9614
- "Error: ",
9615
- error);
9616
- useEffect(function () {
9617
- setChartOptions(function (prevOptions) { return (__assign(__assign({}, prevOptions), { scales: __assign(__assign({}, prevOptions.scales), { x: __assign(__assign({}, prevOptions.scales.x), { min: state.timeScopeStart.getTime(), max: state.timeScopeEnd.getTime() }) }) })); });
9618
- }, [state.timeScopeStart, state.timeScopeEnd]);
9647
+ return {
9648
+ yAxisID: axisIndex >= 0 ? "y-axis-".concat(axisIndex) : undefined,
9649
+ data: serie.map(function (sample) { return ({
9650
+ x: new Date(sample.timestamp),
9651
+ y: sample.value
9652
+ }); }),
9653
+ tagId: tag.tagId,
9654
+ borderColor: tag.color,
9655
+ hidden: !tag.visible,
9656
+ pointRadius: serie.length <= 50 ? 3 : 0
9657
+ };
9658
+ });
9659
+ setChartShouldInitCursors(true);
9660
+ setChartData({
9661
+ labels: [],
9662
+ datasets: updatedSeries
9663
+ });
9664
+ }, [JSON.stringify(state), tagList, series]);
9619
9665
  useEffect(function () {
9620
9666
  if (chartShouldInitCursors) {
9621
9667
  if (chartRef.current) {
@@ -9624,98 +9670,97 @@ var Trending = function (_a) {
9624
9670
  }
9625
9671
  }
9626
9672
  }, [chartShouldInitCursors, state]);
9673
+ return (React__default.createElement(Paper$1, { style: { height: '100%', position: 'relative' } },
9674
+ lineTabCoords && chartArea ? (React__default.createElement(DraggableLineControl, { color: 'red', chartArea: chartArea, initialLeft: lineTabCoords === null || lineTabCoords === void 0 ? void 0 : lineTabCoords.x1, onUpdate: function (newLeft) {
9675
+ setLineTabCoords(function (prevCoords) {
9676
+ prevCoords.x1 = newLeft;
9677
+ return prevCoords;
9678
+ });
9679
+ // @ts-ignore
9680
+ chartRef.current.mouseX = newLeft;
9681
+ debouncedUpdateChart();
9682
+ } })) : null,
9683
+ lineTabCoords && chartArea ? (React__default.createElement(DraggableLineControl, { color: 'blue', initialLeft: lineTabCoords === null || lineTabCoords === void 0 ? void 0 : lineTabCoords.x2, chartArea: chartArea, onUpdate: function (newLeft) {
9684
+ setLineTabCoords(function (prevCoords) {
9685
+ prevCoords.x2 = newLeft;
9686
+ return prevCoords;
9687
+ });
9688
+ // @ts-ignore
9689
+ chartRef.current.secondLineX = newLeft;
9690
+ debouncedUpdateChart();
9691
+ } })) : null,
9692
+ React__default.createElement(Line, { ref: chartRef, data: chartData, options: chartOptions, plugins: [verticalLinePlugin, xAxisDatePlugin, yAxisPlugin] })));
9693
+ };
9694
+
9695
+ Chart.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip$1, Legend, TimeScale, zoomPlugin);
9696
+ var Trending = function (_a) {
9697
+ _a.title; var tags = _a.tags;
9698
+ var _b = useTrendingContext(), state = _b.state; _b.actions;
9699
+ var _c = useState(true), loading = _c[0], setLoading = _c[1];
9700
+ var _d = useState(""), error = _d[0], setError = _d[1];
9701
+ var _e = useState(tags), tagList = _e[0], setTagList = _e[1];
9702
+ var _f = useState([]), series = _f[0], setSeries = _f[1];
9703
+ var _g = useChartOptions(), chartOptions = _g[0], setChartOptions = _g[1];
9704
+ var _h = useState({
9705
+ labels: [],
9706
+ datasets: []
9707
+ }), chartData = _h[0], setChartData = _h[1];
9708
+ var _j = useState(null), cursorData = _j[0], setCursorData = _j[1];
9709
+ var debounceForFetchingData = useRef(null);
9710
+ useEffect(function () {
9711
+ if (debounceForFetchingData.current) {
9712
+ clearTimeout(debounceForFetchingData.current);
9713
+ }
9714
+ debounceForFetchingData.current = setTimeout(function () {
9715
+ var fetchData = function () { return __awaiter(void 0, void 0, void 0, function () {
9716
+ var tagIds, response, error_1;
9717
+ return __generator(this, function (_a) {
9718
+ switch (_a.label) {
9719
+ case 0:
9720
+ _a.trys.push([0, 2, , 3]);
9721
+ console.log("fetching data");
9722
+ setLoading(true);
9723
+ tagIds = tagList.map(function (tag) { return tag.tagId; });
9724
+ return [4 /*yield*/, axios.post("/series?nodeName=null", {
9725
+ start: state.timeScopeStart.getTime(),
9726
+ end: state.timeScopeEnd.getTime(),
9727
+ tagIds: tagIds,
9728
+ sampleCount: 1000
9729
+ })];
9730
+ case 1:
9731
+ response = _a.sent();
9732
+ setSeries(response.data || []);
9733
+ setLoading(false);
9734
+ return [3 /*break*/, 3];
9735
+ case 2:
9736
+ error_1 = _a.sent();
9737
+ console.error("Error fetching data:", error_1);
9738
+ setError("Failed to fetch data");
9739
+ setLoading(false);
9740
+ return [3 /*break*/, 3];
9741
+ case 3: return [2 /*return*/];
9742
+ }
9743
+ });
9744
+ }); };
9745
+ fetchData();
9746
+ }, 800);
9747
+ }, [JSON.stringify(state), tagList]);
9748
+ if (error)
9749
+ return React__default.createElement("p", null,
9750
+ "Error: ",
9751
+ error);
9627
9752
  return (React__default.createElement(Grid$1, { container: true, style: { width: "95svw", height: "81svh", margin: 0 } },
9628
- React__default.createElement(Grid$1, { item: true, xs: 12, container: true, justifyContent: "space-between", alignItems: "center", style: { height: "15%" } },
9629
- React__default.createElement(Grid$1, { md: 5, item: true, container: true, justifyContent: "flex-start", alignItems: "center", spacing: 1, wrap: "wrap" },
9630
- React__default.createElement(IconButton$1, { color: "primary", onClick: function () { return handleDateNavigator("subtract"); }, className: classes.navigatorButton },
9631
- React__default.createElement(ChevronLeft, { fontSize: "large" })),
9632
- React__default.createElement(Grid$1, { item: true },
9633
- React__default.createElement(TextField, { type: "datetime-local", className: classes.datetimePicker, label: "Start", variant: "outlined", value: moment(state.timeScopeStart).format("YYYY-MM-DDTHH:mm:ss"), onChange: function (e) { return handleDateChange(e.target.value, "start"); }, InputLabelProps: {
9634
- shrink: true,
9635
- style: { marginLeft: "10px" }
9636
- }, InputProps: {
9637
- max: state.timeScopeEnd
9638
- } })),
9639
- React__default.createElement(Grid$1, { item: true, className: classes.select },
9640
- React__default.createElement(FormControl$1, { variant: "outlined" },
9641
- React__default.createElement(Select$1, { value: state.scope, onChange: handleChangeScope, displayEmpty: true },
9642
- React__default.createElement(MenuItem$1, { value: "10 min" }, "10 min"),
9643
- React__default.createElement(MenuItem$1, { value: "1 hour" }, "1 hour"),
9644
- React__default.createElement(MenuItem$1, { value: "4 hours" }, "4 hours"),
9645
- React__default.createElement(MenuItem$1, { value: "12 hours" }, "12 hours"),
9646
- React__default.createElement(MenuItem$1, { value: "1 day" }, "1 day"),
9647
- React__default.createElement(MenuItem$1, { value: "10 days" }, "10 days"),
9648
- React__default.createElement(MenuItem$1, { value: "custom" }, "Custom")))),
9649
- React__default.createElement(Grid$1, { item: true },
9650
- React__default.createElement(TextField, { label: "End", variant: "outlined", className: classes.datetimePicker, type: "datetime-local", value: moment(state.timeScopeEnd).format("YYYY-MM-DDTHH:mm:ss"), onChange: function (e) { return handleDateChange(e.target.value, "end"); }, InputLabelProps: {
9651
- shrink: true,
9652
- style: { marginLeft: "10px" }
9653
- } })),
9654
- React__default.createElement(IconButton$1, { color: "primary", onClick: function () { return handleDateNavigator("add"); }, className: classes.navigatorButton },
9655
- React__default.createElement(ChevronRight, { fontSize: "large" }))),
9656
- React__default.createElement(Grid$1, { md: 7, item: true, container: true, justifyContent: "space-between" },
9657
- React__default.createElement(Grid$1, { item: true, container: true, wrap: "nowrap", spacing: 1 },
9658
- React__default.createElement(Grid$1, { item: true, container: true },
9659
- React__default.createElement(CustomOptionsComponent, { customOptions: customOptions, setCustomOptions: setCustomOptions }))))),
9753
+ React__default.createElement(Header, { setChartOptions: setChartOptions }),
9660
9754
  React__default.createElement(Grid$1, { item: true, xs: 12, style: { height: '45%' } },
9661
- React__default.createElement(Paper$1, { style: { height: '100%', position: 'relative' } },
9662
- lineTabCoords && chartArea ? (React__default.createElement(DraggableLineControl, { color: 'red', chartArea: chartArea, initialLeft: lineTabCoords === null || lineTabCoords === void 0 ? void 0 : lineTabCoords.x1, onUpdate: function (newLeft) {
9663
- setLineTabCoords(function (prevCoords) {
9664
- prevCoords.x1 = newLeft;
9665
- return prevCoords;
9666
- });
9667
- // @ts-ignore
9668
- chartRef.current.mouseX = newLeft;
9669
- debouncedUpdateChart();
9670
- } })) : null,
9671
- lineTabCoords && chartArea ? (React__default.createElement(DraggableLineControl, { color: 'blue', initialLeft: lineTabCoords === null || lineTabCoords === void 0 ? void 0 : lineTabCoords.x2, chartArea: chartArea, onUpdate: function (newLeft) {
9672
- setLineTabCoords(function (prevCoords) {
9673
- prevCoords.x2 = newLeft;
9674
- return prevCoords;
9675
- });
9676
- // @ts-ignore
9677
- chartRef.current.secondLineX = newLeft;
9678
- debouncedUpdateChart();
9679
- } })) : null,
9680
- React__default.createElement(Line, { ref: chartRef, data: chartData, options: chartOptions, plugins: [verticalLinePlugin] }))),
9755
+ React__default.createElement(TrendingChart, { setChartData: setChartData, series: series, tagList: tagList, chartOptions: chartOptions, setChartOptions: setChartOptions, chartData: chartData, setCursorData: setCursorData })),
9681
9756
  React__default.createElement(Grid$1, { item: true, xs: 12, style: { height: '40%', minWidth: "100%", paddingTop: "3rem" } },
9682
- React__default.createElement(TableComponent, { tagList: tagList, chartData: chartData, setTagList: setTagList, cursorData: cursorData, onDeleteTag: handleDeleteTag, onAddTag: handleAddTag })),
9757
+ React__default.createElement(TableComponent, { tagList: tagList, chartData: chartData, setTagList: setTagList, cursorData: cursorData })),
9683
9758
  loading && (React__default.createElement(Grid$1, { item: true, xs: 12, style: { textAlign: 'center' } },
9684
9759
  React__default.createElement("p", null, "Loading...")))));
9685
9760
  };
9686
9761
 
9687
- //tags
9688
- var getTags = function (NodeName) { return __awaiter(void 0, void 0, void 0, function () {
9689
- var apiService, parameters, resp;
9690
- return __generator(this, function (_a) {
9691
- switch (_a.label) {
9692
- case 0:
9693
- apiService = new MESApiService();
9694
- parameters = [];
9695
- parameters.push({ name: "NodeName", value: NodeName });
9696
- return [4 /*yield*/, apiService.callV2("[mssql2022].[IH_100020].[dbo].[GetTagDirectChildren]", parameters)];
9697
- case 1:
9698
- resp = _a.sent();
9699
- return [2 /*return*/, resp];
9700
- }
9701
- });
9702
- }); };
9703
-
9762
+ // @flow
9704
9763
  var TrendingsIndex = function (props) {
9705
- React.useEffect(function () {
9706
- (function () { return __awaiter(void 0, void 0, void 0, function () {
9707
- var tags;
9708
- return __generator(this, function (_a) {
9709
- switch (_a.label) {
9710
- case 0: return [4 /*yield*/, getTags(null)];
9711
- case 1:
9712
- tags = _a.sent();
9713
- console.log(tags);
9714
- return [2 /*return*/];
9715
- }
9716
- });
9717
- }); })();
9718
- }, []);
9719
9764
  return (React.createElement(TrendingProvider, null,
9720
9765
  React.createElement(Box, { p: 3, style: { maxWidth: "100%" } },
9721
9766
  React.createElement(Paper, null,
@@ -9797,7 +9842,7 @@ var Navigation = function (_a) {
9797
9842
  };
9798
9843
  }, [params.toString()]);
9799
9844
  return (React__default.createElement("div", { className: "wrapper" },
9800
- React__default.createElement(Header, { showAreaSelector: showAreaSelector, navbarTitle: navbarTitle }),
9845
+ React__default.createElement(Header$1, { showAreaSelector: showAreaSelector, navbarTitle: navbarTitle }),
9801
9846
  React__default.createElement(MESFMainContainer, null)));
9802
9847
  };
9803
9848
 
@@ -9960,3 +10005,4 @@ var areaSelector = /*#__PURE__*/Object.freeze({
9960
10005
  });
9961
10006
 
9962
10007
  export { Account, AssetProvider, AuthContext, AuthProvider, BarChartControl, ChangePassword, CheckBoxControl, Configuration$1 as Configuration, CurrencyFormatter, DataGridControl, DateFormatter, DateTimeFormatter, ErrorModal, FetchError, FilterPanel, GenericPanel, GenericTable, GetCrewColor, GetShiftColor, HorizontalTextControl, IntegerFormatter, Login, Logout, LongFilterPanel, MESApiService, MESFMain, MESSAGE_API, MESSAGE_ERRORS, MasterDetailPanel, MesfModal, ModalTreeFilterControl, MultipleSelectorControl, NumberFormatter, NumericTextControl, SimplePasswordControl, SimpleSelectorControl, SimpleTextAreaControl, SimpleTextControl, TimeFormatter, TreePickerControl, TrendingsIndex, USER_LABELS, UTLSettingsProvider, UploadFileControl, UserProvider, axiosInstance, formatNumber, getCrewStyle, getError, getShiftStyle, getTokenFromLS, renewToken, useAssetContext, useToken, useUTLSettingsContext, useUserContext };
10008
+ //# sourceMappingURL=index.esm.js.map