@dexteel/mesf-core 4.5.9 → 4.6.0

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.
Files changed (25) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/dist/components/shared/buttons/button-with-loading.d.ts +9 -0
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.esm.js +1282 -949
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/pages/trendings/TrendingsPage.d.ts +4 -0
  7. package/dist/pages/trendings/components/chart/TableComponent.d.ts +1 -5
  8. package/dist/pages/trendings/components/chart/Trending.d.ts +0 -2
  9. package/dist/pages/trendings/components/chart/components/modals/addTagModal/AddTagModal.d.ts +2 -2
  10. package/dist/pages/trendings/components/chart/components/modals/addTagModal/TagSelectionModal.d.ts +2 -2
  11. package/dist/pages/trendings/components/chart/components/modals/loadView/LoadViewModal.d.ts +7 -0
  12. package/dist/pages/trendings/components/chart/components/modals/saveAsView/SaveAsViewModal.d.ts +7 -0
  13. package/dist/pages/trendings/components/chart/context/TrendingContext.d.ts +47 -0
  14. package/dist/pages/trendings/components/chart/hooks/useTagsDataTable.d.ts +3 -3
  15. package/dist/pages/trendings/components/chart/hooks/useYAxisPlugin.d.ts +2 -0
  16. package/dist/pages/trendings/components/chart/models/TrendingModels.d.ts +21 -0
  17. package/dist/pages/trendings/components/chart/repository/TrendingRepository.d.ts +4 -5
  18. package/dist/pages/trendings/components/chart/sections/chart/hooks/useChartOptions.d.ts +106 -0
  19. package/dist/pages/trendings/components/chart/sections/header.d.ts +6 -0
  20. package/dist/pages/trendings/components/chart/sections/trending-chart.d.ts +11 -0
  21. package/dist/pages/trendings/components/chart/styles/TrendingStyles.d.ts +1 -1
  22. package/dist/pages/trendings/components/chart/utils/areRangeSimilar.d.ts +2 -2
  23. package/dist/pages/trendings/index.d.ts +3 -4
  24. package/dist/pages/trendings/reducers/trendings.reducer.d.ts +48 -0
  25. package/package.json +1 -1
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, Divider, 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';
23
+ import moment from 'moment';
24
24
  import axios from 'axios';
25
25
  import { _adapters, Chart, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip as Tooltip$1, Legend, TimeScale } from 'chart.js';
26
- 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
- import { Alert as Alert$3, TreeView as TreeView$1, TreeItem as TreeItem$1 } from '@material-ui/lab';
31
+ import { Alert as Alert$3, TreeView as TreeView$1, TreeItem as TreeItem$1, Autocomplete } 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';
@@ -1298,7 +1298,7 @@ var DialogTitle = withStyles(styles)(function (props) {
1298
1298
  var DialogContent = withStyles(function (theme) { return ({
1299
1299
  root: {
1300
1300
  padding: theme.spacing(2),
1301
- minWidth: 300
1301
+ minWidth: 600
1302
1302
  }
1303
1303
  }); })(DialogContent$1);
1304
1304
  var DialogActions = withStyles(function (theme) { return ({
@@ -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];
@@ -8283,6 +8283,210 @@ var Home = function () { return (React__default.createElement("div", { style: {
8283
8283
  position: "absolute"
8284
8284
  } })); };
8285
8285
 
8286
+ var TrendingsInitialState = {
8287
+ timeScopeStart: moment(new Date()).subtract(1, "days").toDate(),
8288
+ timeScopeEnd: new Date(),
8289
+ scope: "1 day",
8290
+ graphPan: false,
8291
+ graphShouldUpdate: 0,
8292
+ views: [
8293
+ {
8294
+ ViewId: 0,
8295
+ ViewName: '',
8296
+ UserName: null,
8297
+ IsPublic: false,
8298
+ LastModified: null,
8299
+ LastModifiedBy: null
8300
+ }
8301
+ ],
8302
+ viewSelected: null,
8303
+ viewTags: [
8304
+ {
8305
+ ViewId: 0,
8306
+ TagId: 0,
8307
+ TagName: '',
8308
+ Color: '',
8309
+ IsVisible: true,
8310
+ MinScale: 0,
8311
+ MaxScale: 0,
8312
+ IsAutoScale: true,
8313
+ Alias: '',
8314
+ TagType: '',
8315
+ Unit: ''
8316
+ }
8317
+ ]
8318
+ };
8319
+ var TrendingsReducer = createSlice({
8320
+ name: "__",
8321
+ initialState: TrendingsInitialState,
8322
+ reducers: {
8323
+ setTotalScope: function (state, _a) {
8324
+ var payload = _a.payload; _a.type;
8325
+ state.graphShouldUpdate += 1;
8326
+ if (!isNil$1(payload.start) && !isNil$1(payload.end) && !isNil$1(payload.scope)) {
8327
+ //from arrow navigators
8328
+ state.timeScopeStart = payload.start;
8329
+ state.timeScopeEnd = payload.end;
8330
+ state.scope = payload.scope;
8331
+ return;
8332
+ }
8333
+ if (!isNil$1(payload.scope)) {
8334
+ if (payload.scope !== "custom") {
8335
+ switch (payload.scope) {
8336
+ case "10 min":
8337
+ state.timeScopeStart = moment(state.timeScopeEnd)
8338
+ .subtract(10, "minutes")
8339
+ .toDate();
8340
+ break;
8341
+ case "1 hour":
8342
+ state.timeScopeStart = moment(state.timeScopeEnd)
8343
+ .subtract(1, "hours")
8344
+ .toDate();
8345
+ break;
8346
+ case "4 hours":
8347
+ state.timeScopeStart = moment(state.timeScopeEnd)
8348
+ .subtract(4, "hours")
8349
+ .toDate();
8350
+ break;
8351
+ case "12 hours":
8352
+ state.timeScopeStart = moment(state.timeScopeEnd)
8353
+ .subtract(12, "hours")
8354
+ .toDate();
8355
+ break;
8356
+ case "1 day":
8357
+ state.timeScopeStart = moment(state.timeScopeEnd)
8358
+ .subtract(1, "days")
8359
+ .toDate();
8360
+ break;
8361
+ case "10 days":
8362
+ state.timeScopeStart = moment(state.timeScopeEnd)
8363
+ .subtract(10, "days")
8364
+ .toDate();
8365
+ break;
8366
+ }
8367
+ }
8368
+ state.scope = payload.scope;
8369
+ return;
8370
+ }
8371
+ if (!isNil$1(payload.start) && !isNil$1(payload.end) && isNil$1(payload.graphPan)) {
8372
+ // from zoom
8373
+ state.timeScopeStart = payload.start;
8374
+ state.timeScopeEnd = payload.end;
8375
+ state.scope = "custom";
8376
+ return;
8377
+ }
8378
+ if (!isNil$1(payload.start) && !isNil$1(payload.end) && !isNil$1(payload.graphPan)) {
8379
+ // from pan
8380
+ state.timeScopeStart = payload.start;
8381
+ state.timeScopeEnd = payload.end;
8382
+ return;
8383
+ }
8384
+ if (!isNil$1(payload.start)) {
8385
+ state.timeScopeStart = payload.start;
8386
+ if (state.scope !== "custom") {
8387
+ switch (state.scope) {
8388
+ case "10 min":
8389
+ state.timeScopeEnd = moment(payload.start)
8390
+ .add(10, "minutes")
8391
+ .toDate();
8392
+ break;
8393
+ case "1 hour":
8394
+ state.timeScopeEnd = moment(payload.start)
8395
+ .add(1, "hours")
8396
+ .toDate();
8397
+ break;
8398
+ case "4 hours":
8399
+ state.timeScopeEnd = moment(payload.start)
8400
+ .add(4, "hours")
8401
+ .toDate();
8402
+ break;
8403
+ case "12 hours":
8404
+ state.timeScopeEnd = moment(payload.start)
8405
+ .add(12, "hours")
8406
+ .toDate();
8407
+ break;
8408
+ case "1 day":
8409
+ state.timeScopeEnd = moment(payload.start)
8410
+ .add(1, "days")
8411
+ .toDate();
8412
+ break;
8413
+ case "10 days":
8414
+ state.timeScopeEnd = moment(payload.start)
8415
+ .add(10, "days")
8416
+ .toDate();
8417
+ break;
8418
+ }
8419
+ }
8420
+ return;
8421
+ }
8422
+ if (!isNil$1(payload.end)) {
8423
+ state.timeScopeEnd = payload.end;
8424
+ if (state.scope !== "custom") {
8425
+ switch (state.scope) {
8426
+ case "10 min":
8427
+ state.timeScopeStart = moment(payload.end)
8428
+ .subtract(10, "minutes")
8429
+ .toDate();
8430
+ break;
8431
+ case "1 hour":
8432
+ state.timeScopeStart = moment(payload.end)
8433
+ .subtract(1, "hours")
8434
+ .toDate();
8435
+ break;
8436
+ case "4 hours":
8437
+ state.timeScopeStart = moment(payload.end)
8438
+ .subtract(4, "hours")
8439
+ .toDate();
8440
+ break;
8441
+ case "12 hours":
8442
+ state.timeScopeStart = moment(payload.end)
8443
+ .subtract(12, "hours")
8444
+ .toDate();
8445
+ break;
8446
+ case "1 day":
8447
+ state.timeScopeStart = moment(payload.end)
8448
+ .subtract(1, "days")
8449
+ .toDate();
8450
+ break;
8451
+ case "10 days":
8452
+ state.timeScopeStart = moment(payload.end)
8453
+ .subtract(10, "days")
8454
+ .toDate();
8455
+ break;
8456
+ }
8457
+ }
8458
+ return;
8459
+ }
8460
+ },
8461
+ setViews: function (state, _a) {
8462
+ var payload = _a.payload;
8463
+ state.views = payload;
8464
+ },
8465
+ setViewSelected: function (state, _a) {
8466
+ var payload = _a.payload;
8467
+ state.viewSelected = payload;
8468
+ },
8469
+ setViewTags: function (state, _a) {
8470
+ var payload = _a.payload;
8471
+ state.viewTags = payload;
8472
+ }
8473
+ }
8474
+ });
8475
+
8476
+ var TrendingContext = createContext({
8477
+ state: TrendingsReducer.getInitialState(),
8478
+ actions: TrendingsReducer.actions
8479
+ });
8480
+ var useTrendingContext = function () { return useContext(TrendingContext); };
8481
+ var TrendingProvider = function (_a) {
8482
+ var children = _a.children;
8483
+ var _b = useComplexState({
8484
+ initialState: TrendingsReducer.getInitialState(),
8485
+ reducers: TrendingsReducer.caseReducers
8486
+ }), state = _b[0], actions = _b[1];
8487
+ return (React__default.createElement(TrendingContext.Provider, { value: { state: state, actions: actions } }, children));
8488
+ };
8489
+
8286
8490
  /*!
8287
8491
  * chartjs-adapter-moment v1.0.1
8288
8492
  * https://www.chartjs.org
@@ -8422,8 +8626,9 @@ var ColorPicker = function (_a) {
8422
8626
  var TagSelectionModal = function (_a) {
8423
8627
  var isOpen = _a.isOpen; _a.onClose; var onTagSelect = _a.onTagSelect;
8424
8628
  var _b = useState(true), isLoading = _b[0], setIsLoading = _b[1];
8425
- var _c = useState([]), treeData = _c[0], setTreeData = _c[1];
8426
- var _d = useState([]), expanded = _d[0], setExpanded = _d[1];
8629
+ var _c = useState(''), error = _c[0], setError = _c[1];
8630
+ var _d = useState([]), treeData = _d[0], setTreeData = _d[1];
8631
+ var _e = useState([]), expanded = _e[0], setExpanded = _e[1];
8427
8632
  var currentColorIndex = useRef(0);
8428
8633
  useEffect(function () {
8429
8634
  var loadData = function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -8438,8 +8643,8 @@ var TagSelectionModal = function (_a) {
8438
8643
  children = _a.sent();
8439
8644
  setTreeData([
8440
8645
  {
8441
- tagId: null,
8442
- tagName: "root",
8646
+ TagId: null,
8647
+ TagName: "root",
8443
8648
  children: children,
8444
8649
  isLoaded: true,
8445
8650
  shortName: "Tags",
@@ -8488,20 +8693,19 @@ var TagSelectionModal = function (_a) {
8488
8693
  case 1:
8489
8694
  children = _a.sent();
8490
8695
  return [2 /*return*/, {
8491
- tagId: dbTag.tagId,
8492
- tagName: childTagName,
8696
+ TagId: dbTag.tagId,
8697
+ TagName: childTagName,
8493
8698
  shortName: dbTag.tagName,
8494
8699
  children: children,
8495
8700
  isLoaded: true,
8496
8701
  tag: {
8497
- tagId: dbTag.tagId,
8498
- tagName: dbTag.tagName,
8499
- tagType: dbTag.tagType,
8500
- color: getColor(),
8501
- autoScale: true,
8502
- minScale: null,
8503
- maxScale: null,
8504
- visible: true
8702
+ TagId: dbTag.tagId,
8703
+ TagName: dbTag.tagName,
8704
+ Color: getColor(),
8705
+ IsAutoScale: true,
8706
+ MinScale: dbTag.minScale,
8707
+ MaxScale: dbTag.maxScale,
8708
+ IsVisible: true
8505
8709
  }
8506
8710
  }];
8507
8711
  }
@@ -8514,7 +8718,7 @@ var TagSelectionModal = function (_a) {
8514
8718
  return [2 /*return*/, childrenData];
8515
8719
  case 4:
8516
8720
  error_1 = _a.sent();
8517
- console.error("Error fetching children:", error_1);
8721
+ setError(error_1.message);
8518
8722
  return [2 /*return*/, []];
8519
8723
  case 5: return [2 /*return*/];
8520
8724
  }
@@ -8533,7 +8737,7 @@ var TagSelectionModal = function (_a) {
8533
8737
  var node;
8534
8738
  return __generator(this, function (_a) {
8535
8739
  node = findNode(treeData, nodeId);
8536
- if (node === null || node === void 0 ? void 0 : node.tagId) {
8740
+ if (node === null || node === void 0 ? void 0 : node.TagId) {
8537
8741
  onTagSelect(node.tag);
8538
8742
  }
8539
8743
  return [2 /*return*/];
@@ -8542,7 +8746,7 @@ var TagSelectionModal = function (_a) {
8542
8746
  var findNode = function (nodes, tagName) {
8543
8747
  for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
8544
8748
  var node = nodes_1[_i];
8545
- if (node.tagName === tagName) {
8749
+ if (node.TagName === tagName) {
8546
8750
  return node;
8547
8751
  }
8548
8752
  else if (node.children) {
@@ -8553,100 +8757,383 @@ var TagSelectionModal = function (_a) {
8553
8757
  }
8554
8758
  return null;
8555
8759
  };
8556
- var renderTree = function (node) { return (React__default.createElement(TreeItem$1, { key: node.tagName, nodeId: node.tagName, label: node.shortName, endIcon: React__default.createElement(ArrowDropDownIcon, null), icon: node.children && node.children.length > 0 ? (React__default.createElement(FolderIcon, null)) : (React__default.createElement(InsertDriveFileIcon, null)) }, node.children && node.children.map(function (child) { return renderTree(child); }))); };
8557
- return (React__default.createElement("div", { style: {
8558
- display: isOpen ? "block" : "none",
8559
- minHeight: "400px",
8560
- minWidth: "600px"
8561
- } },
8562
- React__default.createElement("div", null, isLoading ? (React__default.createElement(Grid$1, { container: true, justifyContent: "center", alignItems: "center", style: { minHeight: "100px" } },
8563
- React__default.createElement(CircularProgress$1, { size: "2rem" }))) : (React__default.createElement(TreeView$1, { expanded: expanded, onNodeSelect: handleNodeSelect, onNodeToggle: handleNodeToggle }, treeData.map(function (tree) { return renderTree(tree); }))))));
8760
+ var renderTree = function (node) { return (React__default.createElement(TreeItem$1, { key: node.TagName, nodeId: node.TagName, label: node.shortName, endIcon: React__default.createElement(ArrowDropDownIcon, null), icon: node.children && node.children.length > 0 ? (React__default.createElement(FolderIcon, null)) : (React__default.createElement(InsertDriveFileIcon, null)) }, node.children && node.children.map(function (child) { return renderTree(child); }))); };
8761
+ return (React__default.createElement(React__default.Fragment, null,
8762
+ React__default.createElement("div", { style: {
8763
+ display: isOpen ? "block" : "none",
8764
+ minHeight: "400px",
8765
+ minWidth: "600px"
8766
+ } },
8767
+ React__default.createElement("div", null, isLoading ? (React__default.createElement(Grid$1, { container: true, justifyContent: "center", alignItems: "center", style: { minHeight: "100px" } },
8768
+ React__default.createElement(CircularProgress$1, { size: "2rem" }))) : (React__default.createElement(TreeView$1, { expanded: expanded, onNodeSelect: handleNodeSelect, onNodeToggle: handleNodeToggle }, treeData.map(function (tree) { return renderTree(tree); }))))),
8769
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); } })));
8564
8770
  };
8565
8771
 
8566
8772
  var AddTagModal = function (_a) {
8567
8773
  var open = _a.open, handleClose = _a.handleClose, onTagSelect = _a.onTagSelect;
8568
- return (React__default.createElement(MesfModal, { open: open, handleClose: handleClose, maxWidth: "lg", "aria-labelledby": "modal-modal-title", "aria-describedby": "modal-modal-description", title: 'Tags' },
8569
- React__default.createElement(MesfModal.Content, null,
8570
- React__default.createElement(Box, null,
8571
- React__default.createElement(Typography, { id: "modal-modal-description" },
8572
- React__default.createElement(TagSelectionModal, { isOpen: open, onClose: function () { return handleClose; }, onTagSelect: onTagSelect }))))));
8774
+ return (React__default.createElement(React__default.Fragment, null,
8775
+ React__default.createElement(MesfModal, { open: open, handleClose: handleClose, maxWidth: "lg", "aria-labelledby": "modal-modal-title", "aria-describedby": "modal-modal-description", title: 'Tags' },
8776
+ React__default.createElement(MesfModal.Content, null,
8777
+ React__default.createElement(Box, null,
8778
+ React__default.createElement(Typography, { id: "modal-modal-description" },
8779
+ React__default.createElement(TagSelectionModal, { isOpen: open, onClose: function () { return handleClose; }, onTagSelect: onTagSelect })))))));
8573
8780
  };
8574
8781
 
8575
- var useTagsDataTable = function (_a) {
8576
- var cursorData = _a.cursorData, tagList = _a.tagList, chartData = _a.chartData;
8577
- return useMemo(function () {
8578
- // calculo y1,y2,y2y1,ymin,ymax por cada tag
8579
- var _a;
8580
- var dataTable = {};
8581
- if (cursorData) {
8582
- var _loop_1 = function (idx) {
8583
- var tag = tagList[idx];
8584
- var datasetForTag = ((_a = chartData.datasets.find(function (ds) { return ds.tagId === tag.tagId; })) === null || _a === void 0 ? void 0 : _a.data) || [];
8585
- var p1 = { x: new Date('1900-01-01'), y: 0 };
8586
- var p2 = { x: new Date('1900-01-01'), y: 0 };
8587
- var p1Found = false;
8588
- var pmin = { x: 0, y: Number.POSITIVE_INFINITY };
8589
- var pmax = { x: 0, y: Number.NEGATIVE_INFINITY };
8590
- for (var idx_1 = 0; idx_1 < datasetForTag.length; idx_1++) {
8591
- var curr = datasetForTag[idx_1];
8592
- var currentVal = curr.x;
8593
- if (!p1Found) {
8594
- if (currentVal < cursorData.x1) {
8595
- p1 = curr;
8596
- p2 = JSON.parse(JSON.stringify(p1));
8597
- pmin = JSON.parse(JSON.stringify(p1));
8598
- pmax = JSON.parse(JSON.stringify(p1));
8599
- continue;
8600
- }
8601
- else {
8602
- p1Found = true;
8603
- }
8604
- }
8605
- else {
8606
- if (currentVal < cursorData.x2) {
8607
- p2 = curr;
8608
- if (pmin['y'] > curr['y']) {
8609
- pmin = JSON.parse(JSON.stringify(curr));
8610
- }
8611
- if (pmax['y'] < curr['y']) {
8612
- pmax = JSON.parse(JSON.stringify(curr));
8613
- }
8614
- }
8615
- else {
8616
- break;
8617
- }
8618
- }
8619
- }
8620
- dataTable[tag.tagName] = {
8621
- y1: p1.y,
8622
- y2: p2.y,
8623
- y2y1: Number(p2.y) - Number(p1.y),
8624
- pmin: pmin,
8625
- pmax: pmax
8626
- };
8627
- };
8628
- for (var idx = 0; idx < tagList.length; idx++) {
8629
- _loop_1(idx);
8630
- }
8631
- }
8632
- return dataTable;
8633
- }, [tagList, chartData, cursorData]);
8782
+ var ButtonWithLoading = function (_a) {
8783
+ var children = _a.children, isLoading = _a.isLoading, props = __rest(_a, ["children", "isLoading"]);
8784
+ return (React__default.createElement(Button$1, __assign({}, props, { disabled: isLoading }),
8785
+ isLoading && React__default.createElement(CircularProgress$1, { size: "1rem" }),
8786
+ children));
8634
8787
  };
8635
8788
 
8636
- var useTagsTableStyles = makeStyles$1(function (theme) { return ({
8637
- checkbox: {
8638
- '& input[type="checkbox"]': {
8639
- zoom: 1.5
8640
- },
8641
- textAlign: 'center'
8642
- },
8643
- rowHover: {
8644
- '&:hover': {
8645
- backgroundColor: "#f2f2f2"
8789
+ var saveTagDefaults = function (TagId, Alias, Color, MinScale, MaxScale, Unit) { return __awaiter(void 0, void 0, void 0, function () {
8790
+ var apiService, parameters, resp;
8791
+ return __generator(this, function (_a) {
8792
+ switch (_a.label) {
8793
+ case 0:
8794
+ apiService = new MESApiService();
8795
+ parameters = [];
8796
+ parameters.push({ name: "TagId", value: TagId });
8797
+ parameters.push({ name: "Alias", value: Alias });
8798
+ parameters.push({ name: "Color", value: Color });
8799
+ parameters.push({ name: "MinScale", value: MinScale });
8800
+ parameters.push({ name: "MaxScale", value: MaxScale });
8801
+ parameters.push({ name: "Unit", value: Unit });
8802
+ return [4 /*yield*/, apiService.callV2("[mssql2022].[IH_100020].[ih].[SaveTagDefaults]", parameters)];
8803
+ case 1:
8804
+ resp = _a.sent();
8805
+ return [2 /*return*/, resp];
8646
8806
  }
8647
- },
8648
- topTitles: {
8649
- border: "0.0625rem black solid",
8807
+ });
8808
+ }); };
8809
+ //views
8810
+ var getViews = function (Search) { return __awaiter(void 0, void 0, void 0, function () {
8811
+ var apiService, parameters, resp;
8812
+ return __generator(this, function (_a) {
8813
+ switch (_a.label) {
8814
+ case 0:
8815
+ apiService = new MESApiService();
8816
+ parameters = [];
8817
+ parameters.push({ name: "Search", value: Search });
8818
+ return [4 /*yield*/, apiService.callV2("[mssql2022].[IH_100020].[ih].[GetViews]", parameters)];
8819
+ case 1:
8820
+ resp = _a.sent();
8821
+ return [2 /*return*/, resp];
8822
+ }
8823
+ });
8824
+ }); };
8825
+ var getViewTags = function (ViewId) { return __awaiter(void 0, void 0, void 0, function () {
8826
+ var apiService, parameters, resp;
8827
+ return __generator(this, function (_a) {
8828
+ switch (_a.label) {
8829
+ case 0:
8830
+ apiService = new MESApiService();
8831
+ parameters = [];
8832
+ parameters.push({ name: "ViewId", value: ViewId });
8833
+ return [4 /*yield*/, apiService.callV2("[mssql2022].[IH_100020].[ih].[GetViewTags]", parameters)];
8834
+ case 1:
8835
+ resp = _a.sent();
8836
+ return [2 /*return*/, resp];
8837
+ }
8838
+ });
8839
+ }); };
8840
+ var upsertView = function (ViewId, ViewName, isPublic) { return __awaiter(void 0, void 0, void 0, function () {
8841
+ var apiService, parameters, resp;
8842
+ return __generator(this, function (_a) {
8843
+ switch (_a.label) {
8844
+ case 0:
8845
+ apiService = new MESApiService();
8846
+ parameters = [];
8847
+ parameters.push({ name: "ViewId", value: ViewId });
8848
+ parameters.push({ name: "ViewName", value: ViewName });
8849
+ parameters.push({ name: "isPublic", value: isPublic });
8850
+ return [4 /*yield*/, apiService.callV2("[mssql2022].[IH_100020].[ih].[UpsertView]", parameters)];
8851
+ case 1:
8852
+ resp = _a.sent();
8853
+ return [2 /*return*/, resp];
8854
+ }
8855
+ });
8856
+ }); };
8857
+ var upsertViewTag = function (ViewId, TagId, Color, MinScale, MaxScale, IsVisible, IsAutoScale) { return __awaiter(void 0, void 0, void 0, function () {
8858
+ var apiService, parameters, resp;
8859
+ return __generator(this, function (_a) {
8860
+ switch (_a.label) {
8861
+ case 0:
8862
+ apiService = new MESApiService();
8863
+ parameters = [];
8864
+ parameters.push({ name: "ViewId", value: ViewId });
8865
+ parameters.push({ name: "TagId", value: TagId });
8866
+ parameters.push({ name: "Color", value: Color });
8867
+ parameters.push({ name: "MinScale", value: MinScale });
8868
+ parameters.push({ name: "MaxScale", value: MaxScale });
8869
+ parameters.push({ name: "IsVisible", value: IsVisible });
8870
+ parameters.push({ name: "IsAutoScale", value: IsAutoScale });
8871
+ return [4 /*yield*/, apiService.callV2("[mssql2022].[IH_100020].[ih].[UpsertViewTag]", parameters)];
8872
+ case 1:
8873
+ resp = _a.sent();
8874
+ return [2 /*return*/, resp];
8875
+ }
8876
+ });
8877
+ }); };
8878
+
8879
+ var LoadViewModal = function (_a) {
8880
+ var open = _a.open, handleClose = _a.handleClose;
8881
+ var _b = useTrendingContext(), _c = _b.state; _c.viewTags; var views = _c.views, viewSelected = _c.viewSelected, _d = _b.actions; _d.setViews; var setViewTags = _d.setViewTags, setViewSelected = _d.setViewSelected;
8882
+ var _e = useState(false), isLoading = _e[0], setIsLoading = _e[1];
8883
+ var _f = useState(''), error = _f[0], setError = _f[1];
8884
+ var handleSelect = function () { return __awaiter(void 0, void 0, void 0, function () {
8885
+ var viewTagsResp;
8886
+ return __generator(this, function (_a) {
8887
+ switch (_a.label) {
8888
+ case 0:
8889
+ if (!viewSelected) return [3 /*break*/, 2];
8890
+ setIsLoading(true);
8891
+ return [4 /*yield*/, getViewTags(viewSelected.ViewId)];
8892
+ case 1:
8893
+ viewTagsResp = _a.sent();
8894
+ if (viewTagsResp.ok) {
8895
+ setViewTags(viewTagsResp.data.tables[0].rows);
8896
+ }
8897
+ else {
8898
+ setError(viewTagsResp.message);
8899
+ }
8900
+ setIsLoading(false);
8901
+ handleClose();
8902
+ _a.label = 2;
8903
+ case 2: return [2 /*return*/];
8904
+ }
8905
+ });
8906
+ }); };
8907
+ return (React__default.createElement("div", null,
8908
+ React__default.createElement(MesfModal, { open: open, handleClose: handleClose, maxWidth: "xl", "aria-labelledby": "modal-modal-title", "aria-describedby": "modal-modal-description", title: 'Tags' },
8909
+ React__default.createElement(MesfModal.Content, null,
8910
+ React__default.createElement(Grid$1, { container: true },
8911
+ React__default.createElement(Grid$1, { item: true, md: 12 }, views.length ? (React__default.createElement(Autocomplete, { size: 'small', id: "list-of-views", options: views, getOptionLabel: function (option) { return option.ViewName; }, onChange: function (ev, val) { return setViewSelected(val); }, style: { width: "100%" }, renderInput: function (params) { return React__default.createElement(TextField, __assign({}, params, { label: "Views", variant: "outlined" })); } })) :
8912
+ (React__default.createElement("div", null, "No tag views detected, please add one"))))),
8913
+ React__default.createElement(MesfModal.Actions, null,
8914
+ React__default.createElement("div", { style: { paddingTop: "1rem" } },
8915
+ React__default.createElement(Button$1, { variant: 'outlined', style: { marginRight: "1rem" }, color: 'secondary', onClick: handleClose }, "Cancel"),
8916
+ React__default.createElement(ButtonWithLoading, { onClick: handleSelect, variant: 'contained', color: 'primary', isLoading: isLoading, style: { marginRight: "1rem" } }, "Apply")))),
8917
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); } })));
8918
+ };
8919
+
8920
+ var useTrendingStyles = makeStyles$1(function (theme) { return ({
8921
+ datetimePicker: {
8922
+ alignItems: "center",
8923
+ "& .MuiInputBase-root": {
8924
+ color: "black",
8925
+ backgroundColor: "white",
8926
+ borderRadius: theme.shape.borderRadius,
8927
+ width: "90%",
8928
+ minWidth: "90%",
8929
+ maxWidth: "90%"
8930
+ },
8931
+ "& .MuiInputBase-input": {
8932
+ fontSize: "13px !important",
8933
+ height: "15px !important",
8934
+ paddingRight: "3px",
8935
+ paddingLeft: "5px"
8936
+ },
8937
+ "& .MuiInput-underline:before": {
8938
+ borderBottomColor: "rgba(0, 0, 0, 0.42)"
8939
+ }
8940
+ },
8941
+ select: {
8942
+ "& .MuiInput-root": {
8943
+ width: "100%"
8944
+ },
8945
+ "& .MuiInputBase-root": {
8946
+ color: "black",
8947
+ backgroundColor: "white",
8948
+ borderRadius: theme.shape.borderRadius,
8949
+ minWidth: "100%"
8950
+ },
8951
+ "& .MuiInputBase-input": {
8952
+ fontSize: "14px !important",
8953
+ height: "15px !important"
8954
+ },
8955
+ "& .MuiInput-underline:before": {
8956
+ borderBottomColor: "rgba(0, 0, 0, 0.42)"
8957
+ }
8958
+ },
8959
+ labelOptions: {
8960
+ paddingLeft: "2rem",
8961
+ userSelect: "none",
8962
+ "& > label": {
8963
+ display: "flex",
8964
+ alignItems: "center",
8965
+ gap: "5px"
8966
+ },
8967
+ '& input[type="checkbox"]': {
8968
+ zoom: 1.5
8969
+ }
8970
+ },
8971
+ isPublicCheckbox: {
8972
+ userSelect: "none",
8973
+ paddingLeft: '1rem',
8974
+ "& > label": {
8975
+ display: "flex",
8976
+ alignItems: "center",
8977
+ gap: "15px"
8978
+ },
8979
+ '& input[type="checkbox"]': {
8980
+ zoom: 1.5
8981
+ }
8982
+ },
8983
+ navigatorButton: {
8984
+ "& .MuiSvgIcon-root": {
8985
+ cursor: "pointer !important"
8986
+ }
8987
+ }
8988
+ }); });
8989
+
8990
+ var SaveAsViewModal = function (_a) {
8991
+ var open = _a.open, handleClose = _a.handleClose;
8992
+ var classes = useTrendingStyles();
8993
+ var _b = useState(false), isLoading = _b[0], setIsLoading = _b[1];
8994
+ var _c = useState(''), error = _c[0], setError = _c[1];
8995
+ var viewTags = useTrendingContext().state.viewTags;
8996
+ var _d = useState(true), isPublic = _d[0], setIsPublic = _d[1];
8997
+ var _e = useState(''), viewName = _e[0], setViewName = _e[1];
8998
+ var handleCheck = function () { return setIsPublic(!isPublic); };
8999
+ var handleInputChange = function (e) { return setViewName(e.target.value); };
9000
+ var handleSubmit = function () { return __awaiter(void 0, void 0, void 0, function () {
9001
+ var resp, ViewId_1, results;
9002
+ return __generator(this, function (_a) {
9003
+ switch (_a.label) {
9004
+ case 0:
9005
+ setIsLoading(true);
9006
+ return [4 /*yield*/, upsertView(null, viewName, isPublic)];
9007
+ case 1:
9008
+ resp = _a.sent();
9009
+ if (!resp.ok) return [3 /*break*/, 3];
9010
+ ViewId_1 = resp.data.returnValue;
9011
+ return [4 /*yield*/, Promise.allSettled(viewTags.map(function (_a) {
9012
+ var TagId = _a.TagId, Color = _a.Color, MinScale = _a.MinScale, MaxScale = _a.MaxScale, IsAutoScale = _a.IsAutoScale, IsVisible = _a.IsVisible;
9013
+ upsertViewTag(ViewId_1, TagId, Color, MinScale, MaxScale, IsVisible, IsAutoScale)
9014
+ .then(function (r) {
9015
+ if (!r.ok) {
9016
+ setError(r.message);
9017
+ }
9018
+ });
9019
+ }))];
9020
+ case 2:
9021
+ results = _a.sent();
9022
+ results.forEach(function (result, index) {
9023
+ if (result.status === "rejected") {
9024
+ setError("Tag ".concat(index, " failed with reason: ").concat(result.reason));
9025
+ }
9026
+ else {
9027
+ handleClose();
9028
+ }
9029
+ });
9030
+ return [3 /*break*/, 4];
9031
+ case 3:
9032
+ setError(resp.message);
9033
+ _a.label = 4;
9034
+ case 4:
9035
+ setIsLoading(false);
9036
+ return [2 /*return*/];
9037
+ }
9038
+ });
9039
+ }); };
9040
+ return (React__default.createElement(React__default.Fragment, null,
9041
+ React__default.createElement(MesfModal, { open: open, handleClose: handleClose, maxWidth: "xl", "aria-labelledby": "modal-modal-title", "aria-describedby": "modal-modal-description", title: 'Tags' },
9042
+ React__default.createElement(Divider, null),
9043
+ React__default.createElement(MesfModal.Content, null,
9044
+ React__default.createElement(Grid$1, { container: true, spacing: 5, style: { padding: "1rem" } },
9045
+ React__default.createElement(Grid$1, { item: true, md: 12, xs: 12, style: { padding: "10px", width: "100%" } },
9046
+ React__default.createElement(TextField, { size: 'small', id: "outlined-basic", label: "View Name", variant: "outlined", value: viewName, onChange: handleInputChange, style: { width: "100%" } }))),
9047
+ React__default.createElement(Grid$1, { item: true, md: 12, xs: 12, style: { paddingTop: "2rem" }, className: classes.isPublicCheckbox },
9048
+ React__default.createElement("label", null,
9049
+ "Public",
9050
+ React__default.createElement("input", { type: "checkbox", checked: isPublic, onChange: handleCheck })))),
9051
+ React__default.createElement(Divider, null),
9052
+ React__default.createElement(MesfModal.Actions, null,
9053
+ React__default.createElement(Grid$1, { container: true, spacing: 1, style: { display: 'flex', alignItems: 'flex-end', justifyContent: 'flex-end' } },
9054
+ React__default.createElement(Grid$1, { item: true },
9055
+ React__default.createElement(Button$1, { variant: 'outlined', color: 'secondary', onClick: handleClose }, "Cancel")),
9056
+ React__default.createElement(Grid$1, { item: true },
9057
+ React__default.createElement(ButtonWithLoading, { variant: 'contained', color: 'primary', onClick: handleSubmit, isLoading: isLoading }, "Save"))))),
9058
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); } })));
9059
+ };
9060
+
9061
+ var useTagsDataTable = function (_a) {
9062
+ var cursorData = _a.cursorData, viewTags = _a.viewTags, chartData = _a.chartData;
9063
+ return useMemo(function () {
9064
+ var _a;
9065
+ var dataTable = {};
9066
+ if (cursorData) {
9067
+ var _loop_1 = function (idx) {
9068
+ var tag = viewTags[idx];
9069
+ var datasetForTag = ((_a = chartData.datasets.find(function (ds) {
9070
+ return ds.tagId === (tag === null || tag === void 0 ? void 0 : tag.TagId);
9071
+ })) === null || _a === void 0 ? void 0 : _a.data) || [];
9072
+ var p1 = { x: new Date('1900-01-01'), y: 0 };
9073
+ var p2 = { x: new Date('1900-01-01'), y: 0 };
9074
+ var p1Found = false;
9075
+ var pmin = { x: 0, y: Number.POSITIVE_INFINITY };
9076
+ var pmax = { x: 0, y: Number.NEGATIVE_INFINITY };
9077
+ for (var idx_1 = 0; idx_1 < datasetForTag.length; idx_1++) {
9078
+ var curr = datasetForTag[idx_1];
9079
+ var currentVal = curr.x;
9080
+ if (!p1Found) {
9081
+ if (currentVal < cursorData.x1) {
9082
+ p1 = curr;
9083
+ p2 = JSON.parse(JSON.stringify(p1));
9084
+ pmin = JSON.parse(JSON.stringify(p1));
9085
+ pmax = JSON.parse(JSON.stringify(p1));
9086
+ continue;
9087
+ }
9088
+ else {
9089
+ p1Found = true;
9090
+ }
9091
+ }
9092
+ else {
9093
+ if (currentVal < cursorData.x2) {
9094
+ p2 = curr;
9095
+ if (pmin['y'] > curr['y']) {
9096
+ pmin = JSON.parse(JSON.stringify(curr));
9097
+ }
9098
+ if (pmax['y'] < curr['y']) {
9099
+ pmax = JSON.parse(JSON.stringify(curr));
9100
+ }
9101
+ }
9102
+ else {
9103
+ break;
9104
+ }
9105
+ }
9106
+ }
9107
+ dataTable[tag === null || tag === void 0 ? void 0 : tag.TagName] = {
9108
+ y1: p1.y,
9109
+ y2: p2.y,
9110
+ y2y1: Number(p2.y) - Number(p1.y),
9111
+ pmin: pmin,
9112
+ pmax: pmax
9113
+ };
9114
+ };
9115
+ for (var idx = 0; idx < viewTags.length; idx++) {
9116
+ _loop_1(idx);
9117
+ }
9118
+ }
9119
+ return dataTable;
9120
+ }, [viewTags, chartData, cursorData]);
9121
+ };
9122
+
9123
+ var useTagsTableStyles = makeStyles$1(function (theme) { return ({
9124
+ checkbox: {
9125
+ '& input[type="checkbox"]': {
9126
+ zoom: 1.5
9127
+ },
9128
+ textAlign: 'center'
9129
+ },
9130
+ rowHover: {
9131
+ '&:hover': {
9132
+ backgroundColor: "#f2f2f2"
9133
+ }
9134
+ },
9135
+ topTitles: {
9136
+ border: "0.0625rem black solid",
8650
9137
  borderBottom: "none",
8651
9138
  backgroundColor: "#e9ecef"
8652
9139
  },
@@ -8704,33 +9191,51 @@ var timeDifference = function (start, end) {
8704
9191
  };
8705
9192
 
8706
9193
  var TableComponent = function (_a) {
8707
- var tagList = _a.tagList, setTagList = _a.setTagList, chartData = _a.chartData, cursorData = _a.cursorData, onDeleteTag = _a.onDeleteTag, onAddTag = _a.onAddTag;
9194
+ var chartData = _a.chartData, cursorData = _a.cursorData;
8708
9195
  var classes = useTagsTableStyles();
8709
- var _b = useState(""); _b[0]; _b[1];
8710
- var dataTable = useTagsDataTable({ tagList: tagList, chartData: chartData, cursorData: cursorData });
8711
- var _c = useState({}), editableTagNames = _c[0], setEditableTagNames = _c[1];
8712
- var handleChange = function (index, value, property) {
8713
- setTagList(function (prev) { return prev.map(function (tag, currentIndex) {
9196
+ var _b = useTrendingContext(), _c = _b.state, viewTags = _c.viewTags, viewSelected = _c.viewSelected, setViewTags = _b.actions.setViewTags;
9197
+ var _d = useState(''), error = _d[0], setError = _d[1];
9198
+ var _e = useState(""); _e[0]; _e[1];
9199
+ var dataTable = useTagsDataTable({ viewTags: viewTags, chartData: chartData, cursorData: cursorData });
9200
+ var _f = useState({}), editableTagNames = _f[0], setEditableTagNames = _f[1];
9201
+ var handleChange = function (tagId, value, property) {
9202
+ var newTags = viewTags.map(function (tag) {
8714
9203
  var _a;
8715
- return currentIndex === index ? __assign(__assign({}, tag), (_a = {}, _a[property] = value, _a.autoScale = false, _a)) : tag;
8716
- }); });
9204
+ return tag.TagId === tagId ? __assign(__assign({}, tag), (_a = {}, _a[property] = value, _a.IsAutoScale = false, _a)) : tag;
9205
+ });
9206
+ setViewTags(newTags);
8717
9207
  };
8718
9208
  var handleChangeAlias = function (tagId, newName) {
8719
- setTagList(function (prevTagList) {
8720
- return prevTagList.map(function (tag) { return (tag.tagId === tagId ? __assign(__assign({}, tag), { tagName: newName }) : tag); });
8721
- });
9209
+ var newTags = viewTags.map(function (tag) { return (tag.TagId === tagId ? __assign(__assign({}, tag), { Alias: newName }) : tag); });
9210
+ setViewTags(newTags);
8722
9211
  };
8723
- var handleVisibilityChange = function (index, value) {
8724
- setTagList(function (prev) { return prev.map(function (tag, currentIndex) { return currentIndex === index ? __assign(__assign({}, tag), { visible: value }) : tag; }); });
9212
+ var handleVisibilityChange = function (tagId, value) {
9213
+ var newTags = viewTags.map(function (tag) { return tag.TagId === tagId ? __assign(__assign({}, tag), { IsVisible: value }) : tag; });
9214
+ setViewTags(newTags);
8725
9215
  };
8726
- var handleAutoScaleChange = function (index, value) {
8727
- setTagList(function (prev) { return prev.map(function (tag, currentIndex) { return currentIndex === index ? __assign(__assign({}, tag), { autoScale: value }) : tag; }); });
9216
+ var handleAutoScaleChange = function (tagId, checked) {
9217
+ var newTags = viewTags.map(function (t) { return t.TagId == tagId ? __assign(__assign({}, t), { IsAutoScale: !checked }) : t; });
9218
+ setViewTags(newTags);
8728
9219
  };
8729
9220
  var handleColorChange = function (tagId, value) {
8730
- setTagList(function (prev) { return prev.map(function (tag) { return tag.tagId === tagId ? __assign(__assign({}, tag), { color: value }) : tag; }); });
9221
+ var newTags = viewTags.map(function (tag) { return tag.TagId === tagId ? __assign(__assign({}, tag), { Color: value }) : tag; });
9222
+ setViewTags(newTags);
9223
+ };
9224
+ var handleDeleteTag = function (tagId) {
9225
+ var newTags = viewTags.filter(function (tag) { return tag.TagId !== tagId; });
9226
+ setViewTags(newTags);
8731
9227
  };
8732
- var _d = useState(null), selectedRowIndex = _d[0], setSelectedRowIndex = _d[1];
8733
- var _e = useState(false), addTagModalOpen = _e[0], setAddTagModalOpen = _e[1];
9228
+ var handleAddTag = function (newTag) {
9229
+ var newArr = __spreadArray([], viewTags, true);
9230
+ if (newTag) {
9231
+ newArr.push(newTag);
9232
+ setViewTags(newArr);
9233
+ }
9234
+ };
9235
+ var _g = useState(null), selectedRowIndex = _g[0], setSelectedRowIndex = _g[1];
9236
+ var _h = useState(false), addTagModalOpen = _h[0], setAddTagModalOpen = _h[1];
9237
+ var _j = useState(false), saveAsViewModalOpen = _j[0], setSaveAsViewModalOpen = _j[1];
9238
+ var _k = useState(false), loadViewOpen = _k[0], setLoadViewOpen = _k[1];
8734
9239
  var handleClose = function () { return setAddTagModalOpen(false); };
8735
9240
  var ContextMenu = function (_a) {
8736
9241
  var x = _a.x, y = _a.y, options = _a.options;
@@ -8741,64 +9246,33 @@ var TableComponent = function (_a) {
8741
9246
  React__default.createElement("ul", null, options.map(function (option) { return (React__default.createElement("li", { key: option.id, onClick: option.onClick }, option.label)); }))));
8742
9247
  };
8743
9248
  // Position state for the context menu
8744
- var _f = useState({ x: 0, y: 0 }), contextMenuPosition = _f[0], setContextMenuPosition = _f[1];
9249
+ var _l = useState({ x: 0, y: 0 }), contextMenuPosition = _l[0], setContextMenuPosition = _l[1];
8745
9250
  var contextMenuOptions = [
8746
9251
  { id: 'delete', label: 'Remove Tag', onClick: function () { return handleDelete(); } },
8747
9252
  { id: 'add', label: 'Add Tag', onClick: function () { return setAddTagModalOpen(true); } },
8748
- { id: 'saveDefault', label: 'Save Default To Tag', onClick: function () { } },
8749
- { id: 'saveAsView', label: 'Save as View', onClick: function () { } },
8750
- { id: 'loadView', label: 'Load View', onClick: function () { } },
8751
- // ... other options
9253
+ { id: 'saveDefault', label: 'Save Default To Tag', onClick: function () { return handleSaveDefaultToTag(); } },
9254
+ { id: 'saveAsView', label: 'Save as View', onClick: function () { return setSaveAsViewModalOpen(true); } },
9255
+ { id: 'loadView', label: 'Load View', onClick: function () { return setLoadViewOpen(true); } },
8752
9256
  ];
8753
- // const binarySearch = (arr: any, searchDate: Date): number | null => {
8754
- // let left = 0;
8755
- // let right = arr.length - 1;
8756
- // let closest: number | null = null;
8757
- // if (!arr.length) return null;
8758
- // while (left <= right) {
8759
- // const mid = Math.floor((left + right) / 2);
8760
- // const midDate = arr[mid].x; // Asegúrate de que esto es una instancia de Date
8761
- // const midTimestamp = midDate.getTime(); // Esto es un number
8762
- // const searchTimestamp = searchDate.getTime(); // Esto también es un number
8763
- // console.log(midTimestamp, searchTimestamp);
8764
- // if (midTimestamp === searchTimestamp) {
8765
- // return arr[mid].y;
8766
- // } else if (midTimestamp < searchTimestamp) {
8767
- // left = mid + 1;
8768
- // } else {
8769
- // right = mid - 1;
8770
- // }
8771
- // // Revisa si midDate está más cerca que el 'closest' actual
8772
- // if (closest === null || Math.abs(midTimestamp - searchTimestamp) < Math.abs(arr[closest].x.getTime() - searchTimestamp)) {
8773
- // closest = mid;
8774
- // }
8775
- // }
8776
- // return closest !== null ? arr[closest].y : null;
8777
- // };
8778
- // useEffect(() => {
8779
- // if (cursorData) {
8780
- // const yValue = binarySearch(chartData.datasets[0]?.data, new Date(cursorData.x1));
8781
- // if(yValue)console.log(yValue,"retorna binary")
8782
- // }
8783
- // else console.log("NULL")
8784
- // }, [cursorData,chartData.datasets[1]?.data])
8785
9257
  var handleTagSelect = function (selectedTag) {
8786
- onAddTag(selectedTag);
9258
+ handleAddTag(selectedTag);
8787
9259
  handleClose();
8788
9260
  };
8789
9261
  var handleDelete = function (index) {
8790
9262
  if (selectedRowIndex !== null) {
8791
- var tagToDelete = tagList[selectedRowIndex];
8792
- onDeleteTag(tagToDelete.tagId);
9263
+ var tagToDelete = viewTags[selectedRowIndex];
9264
+ handleDeleteTag(tagToDelete.TagId);
8793
9265
  setSelectedRowIndex(null); // Reset the selected row index
8794
9266
  }
8795
9267
  };
8796
9268
  useEffect(function () {
8797
- setEditableTagNames(tagList.reduce(function (acc, tag) {
8798
- acc[tag.tagId] = tag.tagName;
8799
- return acc;
8800
- }, {}));
8801
- }, [tagList]);
9269
+ if (Array.isArray(viewTags)) {
9270
+ setEditableTagNames(viewTags.reduce(function (acc, tag) {
9271
+ acc[tag.TagId] = tag.Alias || tag.TagName;
9272
+ return acc;
9273
+ }, {}));
9274
+ }
9275
+ }, [viewTags]);
8802
9276
  useEffect(function () {
8803
9277
  var handleGlobalClick = function (e) {
8804
9278
  if (selectedRowIndex !== null) {
@@ -8819,404 +9293,306 @@ var TableComponent = function (_a) {
8819
9293
  document.removeEventListener("keydown", handleKeyDown);
8820
9294
  };
8821
9295
  }, [selectedRowIndex]);
8822
- var handleRowClick = function (index) {
8823
- setSelectedRowIndex(index);
8824
- };
8825
9296
  var handleRightClick = function (event, index) {
8826
9297
  event.preventDefault();
8827
9298
  event.stopPropagation(); // Prevent the click event from propagating to the document
8828
9299
  setSelectedRowIndex(index);
8829
9300
  setContextMenuPosition({ x: event.clientX, y: event.clientY });
8830
9301
  };
8831
- return (React__default.createElement(Grid$1, { container: true, spacing: 1 },
8832
- React__default.createElement(Grid$1, { item: true, xs: 12 },
8833
- React__default.createElement("div", { style: { overflowX: 'auto', width: '100%' } },
8834
- React__default.createElement("table", { style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
8835
- React__default.createElement("thead", null,
8836
- React__default.createElement("tr", null,
8837
- React__default.createElement("th", { className: classes.visible }),
8838
- React__default.createElement("th", { className: classes.inputCol }),
8839
- React__default.createElement("th", { className: classes.color }),
8840
- React__default.createElement("th", { colSpan: 4, className: "".concat(classes.topTitles, " ").concat(classes.scale) }, "Scale"),
8841
- React__default.createElement("th", { className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? (function () {
8842
- var date = new Date(cursorData.x1);
8843
- // console.log(cursorData, "cursor data")
8844
- var formattedDate = date.toLocaleString('en-US', {
8845
- hour12: false,
8846
- month: 'short',
8847
- day: 'numeric',
8848
- hour: '2-digit',
8849
- minute: '2-digit',
8850
- second: '2-digit'
8851
- });
8852
- var milliseconds = date.getMilliseconds().toString().padStart(3, '0');
8853
- var dateText = "".concat(formattedDate, ".").concat(milliseconds);
8854
- return (React__default.createElement(React__default.Fragment, null,
8855
- React__default.createElement("span", { style: {
8856
- height: '10px',
8857
- width: '10px',
8858
- backgroundColor: "red",
8859
- borderRadius: '50%',
8860
- display: 'inline-block',
8861
- marginRight: '5px'
8862
- } }),
8863
- dateText));
8864
- })() : null),
8865
- React__default.createElement("th", { className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? (function () {
8866
- var date = new Date(cursorData.x2);
8867
- // console.log(cursorData, "cursor data")
8868
- var formattedDate = date.toLocaleString('en-US', {
8869
- hour12: false,
8870
- month: 'short',
8871
- day: 'numeric',
8872
- hour: '2-digit',
8873
- minute: '2-digit',
8874
- second: '2-digit'
8875
- });
8876
- var milliseconds = date.getMilliseconds().toString().padStart(3, '0');
8877
- var dateText = "".concat(formattedDate, ".").concat(milliseconds);
8878
- return (React__default.createElement(React__default.Fragment, null,
8879
- React__default.createElement("span", { style: {
8880
- height: '10px',
8881
- width: '10px',
8882
- backgroundColor: "blue",
8883
- borderRadius: '50%',
8884
- display: 'inline-block',
8885
- marginRight: '5px'
8886
- } }),
8887
- dateText));
8888
- })() : null),
8889
- React__default.createElement("th", { colSpan: 3, className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? timeDifference(cursorData.x2, cursorData.x1) : null)))),
8890
- React__default.createElement("table", { style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
8891
- React__default.createElement("thead", null,
8892
- React__default.createElement("tr", { className: classes.bottomTitlesRow },
8893
- React__default.createElement("th", { className: classes.visible }, "Visible"),
8894
- React__default.createElement("th", { className: classes.inputCol }, "Alias / Tagname"),
8895
- React__default.createElement("th", { className: classes.color }, "Color"),
8896
- React__default.createElement("th", { className: classes.inputCol }, "Min Scale"),
8897
- React__default.createElement("th", { className: classes.inputCol }, "Max Scale"),
8898
- React__default.createElement("th", { className: classes.unit }, "Unit"),
8899
- React__default.createElement("th", { className: classes.autoScale }, "AutoScale"),
8900
- React__default.createElement("th", null, " "),
8901
- React__default.createElement("th", null),
8902
- React__default.createElement("th", null, "Y2-Y1"),
8903
- React__default.createElement("th", null, "Min"),
8904
- React__default.createElement("th", null, "Max")))))),
8905
- React__default.createElement(Grid$1, { item: true, xs: 12 },
8906
- React__default.createElement("div", { style: { width: '100%', overflowY: 'auto', maxHeight: ' 20svh' } },
8907
- React__default.createElement("table", { cellPadding: '4px', style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
8908
- React__default.createElement("tbody", null, tagList.map(function (tag, index) {
8909
- var _a, _b, _c, _d, _e, _f, _g;
8910
- return (React__default.createElement("tr", { key: tag.tagName, onClick: function () { return handleRowClick(index); }, onContextMenu: function (e) { return handleRightClick(e, index); }, className: classes.rowHover },
8911
- React__default.createElement("td", { className: "".concat(classes.visible, " ").concat(classes.checkbox) },
8912
- React__default.createElement("input", { type: "checkbox", checked: tag.visible, onChange: function (e) { return handleVisibilityChange(index, e.target.checked); } })),
8913
- React__default.createElement("td", { className: classes.inputCol },
8914
- React__default.createElement(Tooltip, { title: tag.tagName, placement: "top", arrow: true, interactive: true, enterDelay: 500 },
8915
- React__default.createElement("div", null,
8916
- React__default.createElement("input", { type: "text", style: { width: '100%' }, value: editableTagNames[tag.tagId] || '', onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
8917
- var _a;
8918
- setEditableTagNames(__assign(__assign({}, editableTagNames), (_a = {}, _a[tag.tagId] = e.target.value, _a)));
8919
- }, onKeyDown: function (e) {
8920
- if (e.key === 'Enter') {
8921
- handleChangeAlias(tag.tagId, editableTagNames[tag.tagId]);
8922
- }
8923
- } })))),
8924
- React__default.createElement("td", { className: classes.color },
8925
- React__default.createElement(ColorPicker, { onChange: handleColorChange, color: tag.color, elementId: tag.tagId })),
8926
- React__default.createElement("td", { className: classes.inputCol },
8927
- React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: tag.autoScale, value: tag.minScale, onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
8928
- var value = e.target.value;
8929
- var numericValue = Number(value);
8930
- // Check if the value is a number and not empty
8931
- handleChange(index, numericValue, 'minScale');
8932
- } })),
8933
- React__default.createElement("td", { className: classes.inputCol },
8934
- React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: tag.autoScale, value: tag.maxScale, onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
8935
- var value = e.target.value;
8936
- var numericValue = Number(value);
8937
- // Check if the value is a number and not empty
8938
- if (!isNaN(numericValue) && value.trim() !== '') {
8939
- handleChange(index, numericValue, 'maxScale');
8940
- }
8941
- } })),
8942
- React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
8943
- React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: true, value: /* tag.unit */ "Unit ", onFocus: function (e) { return e.target.select(); } })),
8944
- React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
8945
- React__default.createElement("input", { type: "checkbox", checked: tag.autoScale, onChange: function (e) { return handleAutoScaleChange(index, e.target.checked); } })),
8946
- React__default.createElement("td", null, (_a = dataTable[tag.tagName]) === null || _a === void 0 ? void 0 : _a.y1),
8947
- React__default.createElement("td", { className: classes.doubleInput }, (_b = dataTable[tag.tagName]) === null || _b === void 0 ? void 0 : _b.y2),
8948
- React__default.createElement("td", null, (_c = dataTable[tag.tagName]) === null || _c === void 0 ? void 0 : _c.y2y1),
8949
- React__default.createElement("td", null,
8950
- !isNaN(((_d = dataTable[tag.tagName]) === null || _d === void 0 ? void 0 : _d.pmin.y) * 0) ? (_e = dataTable[tag.tagName]) === null || _e === void 0 ? void 0 : _e.pmin.y : 0,
8951
- " "),
8952
- React__default.createElement("td", null,
8953
- !isNaN(((_f = dataTable[tag.tagName]) === null || _f === void 0 ? void 0 : _f.pmax.y) * 0) ? (_g = dataTable[tag.tagName]) === null || _g === void 0 ? void 0 : _g.pmax.y : 0,
8954
- " ")));
8955
- }))))),
8956
- selectedRowIndex !== null && (React__default.createElement(ContextMenu, { x: contextMenuPosition.x, y: contextMenuPosition.y, options: contextMenuOptions })),
8957
- React__default.createElement(AddTagModal, { open: addTagModalOpen, handleClose: handleClose, onTagSelect: handleTagSelect })));
8958
- };
8959
-
8960
- var DraggableLineControl = function (_a) {
8961
- var initialLeft = _a.initialLeft, onUpdate = _a.onUpdate, color = _a.color, chartArea = _a.chartArea;
8962
- var _b = useState(false), isDragging = _b[0], setIsDragging = _b[1];
8963
- var _c = useState(initialLeft), left = _c[0], setLeft = _c[1];
8964
- var ref = useRef(null);
8965
- var handleMouseDown = function (e) {
8966
- setIsDragging(true);
8967
- e.stopPropagation();
8968
- e.preventDefault();
8969
- };
8970
- var handleMouseMove = function (e) {
8971
- if (!isDragging || !ref.current)
8972
- return;
8973
- chartArea.width - chartArea.right;
8974
- chartArea.left;
8975
- var newLeft = Math.min(Math.max(e.clientX - ref.current.offsetParent.getBoundingClientRect().left, chartArea.left), chartArea.right);
8976
- setLeft(newLeft);
8977
- onUpdate(newLeft); // Actualiza la posición de la línea en el gráfico
8978
- };
8979
- var handleMouseUp = function () {
8980
- setIsDragging(false);
8981
- };
8982
- useEffect(function () {
8983
- var mouseMoveHandler = function (e) { return handleMouseMove(e); };
8984
- var mouseUpHandler = function () { return handleMouseUp(); };
8985
- if (isDragging) {
8986
- window.addEventListener('mousemove', mouseMoveHandler);
8987
- window.addEventListener('mouseup', mouseUpHandler);
8988
- }
8989
- return function () {
8990
- window.removeEventListener('mousemove', mouseMoveHandler);
8991
- window.removeEventListener('mouseup', mouseUpHandler);
8992
- };
8993
- }, [isDragging]);
8994
- return (React__default.createElement("div", { ref: ref, style: { height: 20, width: 20, background: color, position: 'absolute', top: -10, left: left - 10 }, onMouseDown: handleMouseDown },
8995
- React__default.createElement("div", { style: { height: chartArea.height, width: 2, background: color, position: 'relative', top: 20, left: 0, right: 0, margin: 'auto' } })));
9302
+ var handleSaveDefaultToTag = function () { return __awaiter(void 0, void 0, void 0, function () {
9303
+ var promises, allResponses, error_1;
9304
+ return __generator(this, function (_a) {
9305
+ switch (_a.label) {
9306
+ case 0:
9307
+ _a.trys.push([0, 2, 3, 4]);
9308
+ promises = viewTags.map(function (vt) { return __awaiter(void 0, void 0, void 0, function () {
9309
+ var response;
9310
+ return __generator(this, function (_a) {
9311
+ switch (_a.label) {
9312
+ case 0: return [4 /*yield*/, saveTagDefaults(vt.TagId, vt.Alias, vt.Color, vt.MinScale, vt.MaxScale, vt.Unit)];
9313
+ case 1:
9314
+ response = _a.sent();
9315
+ return [2 /*return*/, response];
9316
+ }
9317
+ });
9318
+ }); });
9319
+ return [4 /*yield*/, Promise.all(promises)];
9320
+ case 1:
9321
+ allResponses = _a.sent();
9322
+ allResponses.forEach(function (r) {
9323
+ if (!r.ok) {
9324
+ setError(r.message);
9325
+ }
9326
+ });
9327
+ return [3 /*break*/, 4];
9328
+ case 2:
9329
+ error_1 = _a.sent();
9330
+ setError(error_1.message);
9331
+ return [3 /*break*/, 4];
9332
+ case 3:
9333
+ setSelectedRowIndex(null);
9334
+ return [7 /*endfinally*/];
9335
+ case 4: return [2 /*return*/];
9336
+ }
9337
+ });
9338
+ }); };
9339
+ return (React__default.createElement(React__default.Fragment, null,
9340
+ React__default.createElement(Grid$1, { container: true, spacing: 1 },
9341
+ React__default.createElement(Grid$1, { item: true, xs: 12 },
9342
+ React__default.createElement("div", { style: { overflowX: 'auto', width: '100%' } },
9343
+ React__default.createElement("table", { style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
9344
+ React__default.createElement("thead", null,
9345
+ React__default.createElement("tr", null,
9346
+ React__default.createElement("th", { className: classes.visible }, "View:"),
9347
+ React__default.createElement("th", { className: classes.inputCol }, viewSelected === null || viewSelected === void 0 ? void 0 : viewSelected.ViewName),
9348
+ React__default.createElement("th", { className: classes.color }),
9349
+ React__default.createElement("th", { colSpan: 4, className: "".concat(classes.topTitles, " ").concat(classes.scale) }, "Scale"),
9350
+ React__default.createElement("th", { className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? (function () {
9351
+ var date = new Date(cursorData.x1);
9352
+ var formattedDate = date.toLocaleString('en-US', {
9353
+ hour12: false,
9354
+ month: 'short',
9355
+ day: 'numeric',
9356
+ hour: '2-digit',
9357
+ minute: '2-digit',
9358
+ second: '2-digit'
9359
+ });
9360
+ var milliseconds = date.getMilliseconds().toString().padStart(3, '0');
9361
+ var dateText = "".concat(formattedDate, ".").concat(milliseconds);
9362
+ return (React__default.createElement(React__default.Fragment, null,
9363
+ React__default.createElement("span", { style: {
9364
+ height: '10px',
9365
+ width: '10px',
9366
+ backgroundColor: "red",
9367
+ borderRadius: '50%',
9368
+ display: 'inline-block',
9369
+ marginRight: '5px'
9370
+ } }),
9371
+ dateText));
9372
+ })() : null),
9373
+ React__default.createElement("th", { className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? (function () {
9374
+ var date = new Date(cursorData.x2);
9375
+ var formattedDate = date.toLocaleString('en-US', {
9376
+ hour12: false,
9377
+ month: 'short',
9378
+ day: 'numeric',
9379
+ hour: '2-digit',
9380
+ minute: '2-digit',
9381
+ second: '2-digit'
9382
+ });
9383
+ var milliseconds = date.getMilliseconds().toString().padStart(3, '0');
9384
+ var dateText = "".concat(formattedDate, ".").concat(milliseconds);
9385
+ return (React__default.createElement(React__default.Fragment, null,
9386
+ React__default.createElement("span", { style: {
9387
+ height: '10px',
9388
+ width: '10px',
9389
+ backgroundColor: "blue",
9390
+ borderRadius: '50%',
9391
+ display: 'inline-block',
9392
+ marginRight: '5px'
9393
+ } }),
9394
+ dateText));
9395
+ })() : null),
9396
+ React__default.createElement("th", { colSpan: 3, className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? timeDifference(cursorData.x2, cursorData.x1) : null)))),
9397
+ React__default.createElement("table", { style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
9398
+ React__default.createElement("thead", null,
9399
+ React__default.createElement("tr", { className: classes.bottomTitlesRow },
9400
+ React__default.createElement("th", { className: classes.visible }, "Visible"),
9401
+ React__default.createElement("th", { className: classes.inputCol }, "Alias / Tagname"),
9402
+ React__default.createElement("th", { className: classes.color }, "Color"),
9403
+ React__default.createElement("th", { className: classes.inputCol }, "Min Scale"),
9404
+ React__default.createElement("th", { className: classes.inputCol }, "Max Scale"),
9405
+ React__default.createElement("th", { className: classes.unit }, "Unit"),
9406
+ React__default.createElement("th", { className: classes.autoScale }, "AutoScale"),
9407
+ React__default.createElement("th", null, " "),
9408
+ React__default.createElement("th", null),
9409
+ React__default.createElement("th", null, "Y2-Y1"),
9410
+ React__default.createElement("th", null, "Min"),
9411
+ React__default.createElement("th", null, "Max")))))),
9412
+ React__default.createElement(Grid$1, { item: true, xs: 12 },
9413
+ React__default.createElement("div", { style: { width: '100%', overflowY: 'auto', maxHeight: ' 20svh' } },
9414
+ React__default.createElement("table", { cellPadding: '4px', style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
9415
+ React__default.createElement("tbody", null, viewTags && viewTags.length && Array.isArray(viewTags) ? viewTags.map(function (tag, index) {
9416
+ var _a, _b, _c, _d, _e, _f, _g;
9417
+ return (React__default.createElement("tr", { key: tag.TagName,
9418
+ // onClick={() => handleRowClick(index)}
9419
+ onContextMenu: function (e) { return handleRightClick(e, index); }, className: classes.rowHover },
9420
+ React__default.createElement("td", { className: "".concat(classes.visible, " ").concat(classes.checkbox) },
9421
+ React__default.createElement("input", { type: "checkbox", checked: tag.IsVisible, onChange: function (e) { return handleVisibilityChange(tag.TagId, e.target.checked); } })),
9422
+ React__default.createElement("td", { className: classes.inputCol },
9423
+ React__default.createElement(Tooltip, { title: tag.TagName, placement: "top", arrow: true, interactive: true, enterDelay: 500 },
9424
+ React__default.createElement("div", null,
9425
+ React__default.createElement("input", { type: "text", style: { width: '100%' }, value: editableTagNames[tag.TagId], onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
9426
+ var _a;
9427
+ setEditableTagNames(__assign(__assign({}, editableTagNames), (_a = {}, _a[tag.TagId] = e.target.value, _a)));
9428
+ }, onKeyDown: function (e) {
9429
+ if (e.key === 'Enter') {
9430
+ handleChangeAlias(tag.TagId, editableTagNames[tag.TagId]);
9431
+ }
9432
+ } })))),
9433
+ React__default.createElement("td", { className: classes.color },
9434
+ React__default.createElement(ColorPicker, { onChange: handleColorChange, color: tag.Color, elementId: tag.TagId })),
9435
+ React__default.createElement("td", { className: classes.inputCol },
9436
+ React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: tag.IsAutoScale, value: tag.MinScale, onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
9437
+ var value = e.target.value;
9438
+ var numericValue = Number(value);
9439
+ handleChange(tag.TagId, numericValue, 'MinScale');
9440
+ } })),
9441
+ React__default.createElement("td", { className: classes.inputCol },
9442
+ React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: tag.IsAutoScale, value: tag.MaxScale, onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
9443
+ var value = e.target.value;
9444
+ var numericValue = Number(value);
9445
+ // Check if the value is a number and not empty
9446
+ if (!isNaN(numericValue) && value.trim() !== '') {
9447
+ handleChange(tag.TagId, numericValue, 'MaxScale');
9448
+ }
9449
+ } })),
9450
+ React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
9451
+ React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: true, value: tag.Unit, onFocus: function (e) { return e.target.select(); } })),
9452
+ React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
9453
+ React__default.createElement("input", { type: "checkbox", checked: tag.IsAutoScale, onChange: function (e) { return handleAutoScaleChange(tag.TagId, tag.IsAutoScale); } })),
9454
+ React__default.createElement("td", null, (_a = dataTable[tag.TagName]) === null || _a === void 0 ? void 0 : _a.y1),
9455
+ React__default.createElement("td", { className: classes.doubleInput }, (_b = dataTable[tag.TagName]) === null || _b === void 0 ? void 0 : _b.y2),
9456
+ React__default.createElement("td", null, (_c = dataTable[tag.TagName]) === null || _c === void 0 ? void 0 : _c.y2y1),
9457
+ React__default.createElement("td", null,
9458
+ !isNaN(((_d = dataTable[tag.TagName]) === null || _d === void 0 ? void 0 : _d.pmin.y) * 0) ? (_e = dataTable[tag.TagName]) === null || _e === void 0 ? void 0 : _e.pmin.y : 0,
9459
+ " "),
9460
+ React__default.createElement("td", null,
9461
+ !isNaN(((_f = dataTable[tag.TagName]) === null || _f === void 0 ? void 0 : _f.pmax.y) * 0) ? (_g = dataTable[tag.TagName]) === null || _g === void 0 ? void 0 : _g.pmax.y : 0,
9462
+ " ")));
9463
+ }) : React__default.createElement("div", { style: { padding: '2rem' } },
9464
+ React__default.createElement("div", { style: { padding: "1rem" } }, "No tag view detected. "),
9465
+ React__default.createElement("div", { style: { padding: "1rem" } },
9466
+ React__default.createElement(Button$1, { onClick: function () { return setAddTagModalOpen(true); }, variant: 'contained', color: 'primary' }, " Add tag")),
9467
+ React__default.createElement("div", null,
9468
+ React__default.createElement(Button$1, { onClick: function () { return setLoadViewOpen(true); }, variant: 'outlined', color: 'primary' }, " Load view"))))))),
9469
+ selectedRowIndex !== null && (React__default.createElement(ContextMenu, { x: contextMenuPosition.x, y: contextMenuPosition.y, options: contextMenuOptions })),
9470
+ React__default.createElement(AddTagModal, { open: addTagModalOpen, handleClose: handleClose, onTagSelect: handleTagSelect }),
9471
+ React__default.createElement(SaveAsViewModal, { open: saveAsViewModalOpen, handleClose: function () { return setSaveAsViewModalOpen(false); } }),
9472
+ React__default.createElement(LoadViewModal, { open: loadViewOpen, handleClose: function () { return setLoadViewOpen(false); } })),
9473
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); } })));
8996
9474
  };
8997
9475
 
8998
- var TrendingsInitialState = {
8999
- timeScopeStart: moment(new Date()).subtract(1, "days").toDate(),
9000
- timeScopeEnd: new Date(),
9001
- scope: "1 day",
9002
- graphPan: false
9003
- };
9004
- var TrendingsReducer = createSlice({
9005
- name: "__",
9006
- initialState: TrendingsInitialState,
9007
- reducers: {
9008
- setTotalScope: function (state, _a) {
9009
- var payload = _a.payload; _a.type;
9010
- if (!isNil$1(payload.start) && !isNil$1(payload.end) && !isNil$1(payload.scope)) {
9011
- //from arrow navigators
9012
- state.timeScopeStart = payload.start;
9013
- state.timeScopeEnd = payload.end;
9014
- state.scope = payload.scope;
9015
- return;
9016
- }
9017
- if (!isNil$1(payload.scope)) {
9018
- if (payload.scope !== "custom") {
9019
- switch (payload.scope) {
9020
- case "10 min":
9021
- state.timeScopeStart = moment(state.timeScopeEnd)
9022
- .subtract(10, "minutes")
9023
- .toDate();
9024
- break;
9025
- case "1 hour":
9026
- state.timeScopeStart = moment(state.timeScopeEnd)
9027
- .subtract(1, "hours")
9028
- .toDate();
9029
- break;
9030
- case "4 hours":
9031
- state.timeScopeStart = moment(state.timeScopeEnd)
9032
- .subtract(4, "hours")
9033
- .toDate();
9034
- break;
9035
- case "12 hours":
9036
- state.timeScopeStart = moment(state.timeScopeEnd)
9037
- .subtract(12, "hours")
9038
- .toDate();
9039
- break;
9040
- case "1 day":
9041
- state.timeScopeStart = moment(state.timeScopeEnd)
9042
- .subtract(1, "days")
9043
- .toDate();
9044
- break;
9045
- case "10 days":
9046
- state.timeScopeStart = moment(state.timeScopeEnd)
9047
- .subtract(10, "days")
9048
- .toDate();
9049
- break;
9476
+ var formatDateTimeToString = function (date) {
9477
+ var hour = date.getHours().toString().padStart(2, '0');
9478
+ var minute = date.getMinutes().toString().padStart(2, '0');
9479
+ var second = date.getSeconds().toString().padStart(2, '0');
9480
+ if (hour === '24') {
9481
+ hour = '00';
9482
+ }
9483
+ var formattedDate = date.toLocaleDateString("en-US", {
9484
+ month: "short",
9485
+ day: "numeric"
9486
+ });
9487
+ var formattedTime = "".concat(hour, ":").concat(minute, ":").concat(second);
9488
+ return { formattedDate: formattedDate, formattedTime: formattedTime };
9489
+ };
9490
+
9491
+ var useChartOptions = function () {
9492
+ var _a = useTrendingContext(); _a.state; var actions = _a.actions;
9493
+ var debounceTimerRef = useRef(null);
9494
+ var handleZoom = function (_a) {
9495
+ var chart = _a.chart;
9496
+ if (debounceTimerRef.current) {
9497
+ clearTimeout(debounceTimerRef.current);
9498
+ }
9499
+ debounceTimerRef.current = setTimeout(function () {
9500
+ // Handle zoom event and execute fetch
9501
+ var newStart = new Date(chart.scales.x.min);
9502
+ var newEnd = new Date(chart.scales.x.max);
9503
+ actions.setTotalScope({
9504
+ start: newStart,
9505
+ end: newEnd
9506
+ });
9507
+ }, 1000);
9508
+ };
9509
+ var handlePan = function (_a) {
9510
+ var chart = _a.chart;
9511
+ if (debounceTimerRef.current) {
9512
+ clearTimeout(debounceTimerRef.current);
9513
+ }
9514
+ debounceTimerRef.current = setTimeout(function () {
9515
+ // Handle pan event and execute fetch
9516
+ var newStart = new Date(chart.scales.x.min);
9517
+ var newEnd = new Date(chart.scales.x.max);
9518
+ actions.setTotalScope({
9519
+ start: newStart,
9520
+ end: newEnd,
9521
+ graphPan: true
9522
+ });
9523
+ }, 1000);
9524
+ };
9525
+ return useState({
9526
+ animation: {
9527
+ duration: 0
9528
+ },
9529
+ responsive: true,
9530
+ maintainAspectRatio: false,
9531
+ scales: {
9532
+ x: {
9533
+ type: "time",
9534
+ ticks: {
9535
+ autoSkip: true,
9536
+ maxTicksLimit: 20,
9537
+ callback: function (value, index, ticks) {
9538
+ var currentDate = new Date(value);
9539
+ var time = formatDateTimeToString(currentDate).formattedTime;
9540
+ var date = formatDateTimeToString(currentDate).formattedDate;
9541
+ // Si es el primer tick, siempre muestra la fecha y hora
9542
+ if (index === 0) {
9543
+ return [time, date];
9544
+ }
9545
+ // De lo contrario, solo muestra la hora
9546
+ return time;
9050
9547
  }
9548
+ },
9549
+ grid: {
9550
+ display: true
9051
9551
  }
9052
- state.scope = payload.scope;
9053
- return;
9054
- }
9055
- if (!isNil$1(payload.start) && !isNil$1(payload.end) && isNil$1(payload.graphPan)) {
9056
- // from zoom
9057
- state.timeScopeStart = payload.start;
9058
- state.timeScopeEnd = payload.end;
9059
- state.scope = "custom";
9060
- return;
9061
- }
9062
- if (!isNil$1(payload.start) && !isNil$1(payload.end) && !isNil$1(payload.graphPan)) {
9063
- // from pan
9064
- state.timeScopeStart = payload.start;
9065
- state.timeScopeEnd = payload.end;
9066
- return;
9067
- }
9068
- if (!isNil$1(payload.start)) {
9069
- state.timeScopeStart = payload.start;
9070
- if (state.scope !== "custom") {
9071
- switch (state.scope) {
9072
- case "10 min":
9073
- state.timeScopeEnd = moment(payload.start)
9074
- .add(10, "minutes")
9075
- .toDate();
9076
- break;
9077
- case "1 hour":
9078
- state.timeScopeEnd = moment(payload.start)
9079
- .add(1, "hours")
9080
- .toDate();
9081
- break;
9082
- case "4 hours":
9083
- state.timeScopeEnd = moment(payload.start)
9084
- .add(4, "hours")
9085
- .toDate();
9086
- break;
9087
- case "12 hours":
9088
- state.timeScopeEnd = moment(payload.start)
9089
- .add(12, "hours")
9090
- .toDate();
9091
- break;
9092
- case "1 day":
9093
- state.timeScopeEnd = moment(payload.start)
9094
- .add(1, "days")
9095
- .toDate();
9096
- break;
9097
- case "10 days":
9098
- state.timeScopeEnd = moment(payload.start)
9099
- .add(10, "days")
9100
- .toDate();
9101
- break;
9552
+ },
9553
+ y: {
9554
+ grid: {
9555
+ display: true
9556
+ },
9557
+ afterUpdate: function (axis) {
9558
+ var chart = axis.chart;
9559
+ var keys = Object.keys(chart.scales).filter(function (sc) { return sc !== 'x'; });
9560
+ if (keys.length > 1) {
9561
+ for (var scaleKey in chart.scales) {
9562
+ var scale = chart.scales[scaleKey];
9563
+ if (scale.max === 1 && scale.min === 0) {
9564
+ chart.scales[scaleKey].display = false;
9565
+ chart.scales[scaleKey].options.display = false;
9566
+ }
9567
+ else {
9568
+ chart.scales[scaleKey].display = true;
9569
+ chart.scales[scaleKey].options.display = true;
9570
+ }
9571
+ }
9102
9572
  }
9103
9573
  }
9104
- return;
9105
9574
  }
9106
- if (!isNil$1(payload.end)) {
9107
- state.timeScopeEnd = payload.end;
9108
- if (state.scope !== "custom") {
9109
- switch (state.scope) {
9110
- case "10 min":
9111
- state.timeScopeStart = moment(payload.end)
9112
- .subtract(10, "minutes")
9113
- .toDate();
9114
- break;
9115
- case "1 hour":
9116
- state.timeScopeStart = moment(payload.end)
9117
- .subtract(1, "hours")
9118
- .toDate();
9119
- break;
9120
- case "4 hours":
9121
- state.timeScopeStart = moment(payload.end)
9122
- .subtract(4, "hours")
9123
- .toDate();
9124
- break;
9125
- case "12 hours":
9126
- state.timeScopeStart = moment(payload.end)
9127
- .subtract(12, "hours")
9128
- .toDate();
9129
- break;
9130
- case "1 day":
9131
- state.timeScopeStart = moment(payload.end)
9132
- .subtract(1, "days")
9133
- .toDate();
9134
- break;
9135
- case "10 days":
9136
- state.timeScopeStart = moment(payload.end)
9137
- .subtract(10, "days")
9138
- .toDate();
9139
- break;
9140
- }
9575
+ },
9576
+ plugins: {
9577
+ tooltip: { enabled: false },
9578
+ legend: { display: false },
9579
+ zoom: {
9580
+ zoom: {
9581
+ wheel: { enabled: true, mode: "x" },
9582
+ pinch: { enabled: true, mode: "x" },
9583
+ onZoom: handleZoom,
9584
+ mode: "x"
9585
+ },
9586
+ pan: {
9587
+ enabled: true,
9588
+ mode: "x",
9589
+ onPan: handlePan
9141
9590
  }
9142
- return;
9143
9591
  }
9144
9592
  }
9145
- }
9146
- });
9147
-
9148
- var TrendingContext = createContext({
9149
- state: TrendingsReducer.getInitialState(),
9150
- actions: TrendingsReducer.actions
9151
- });
9152
- var useTrendingContext = function () { return useContext(TrendingContext); };
9153
- var TrendingProvider = function (_a) {
9154
- var children = _a.children;
9155
- var _b = useComplexState({
9156
- initialState: TrendingsReducer.getInitialState(),
9157
- reducers: TrendingsReducer.caseReducers
9158
- }), state = _b[0], actions = _b[1];
9159
- return (React__default.createElement(TrendingContext.Provider, { value: { state: state, actions: actions } }, children));
9593
+ });
9160
9594
  };
9161
9595
 
9162
- var useTrendingStyles = makeStyles$1(function (theme) { return ({
9163
- datetimePicker: {
9164
- alignItems: "center",
9165
- "& .MuiInputBase-root": {
9166
- color: "black",
9167
- backgroundColor: "white",
9168
- borderRadius: theme.shape.borderRadius,
9169
- width: "90%",
9170
- minWidth: "90%",
9171
- maxWidth: "90%"
9172
- },
9173
- "& .MuiInputBase-input": {
9174
- fontSize: "13px !important",
9175
- height: "15px !important",
9176
- paddingRight: "3px",
9177
- paddingLeft: "5px"
9178
- },
9179
- "& .MuiInput-underline:before": {
9180
- borderBottomColor: "rgba(0, 0, 0, 0.42)"
9181
- }
9182
- },
9183
- select: {
9184
- "& .MuiInput-root": {
9185
- width: "100%"
9186
- },
9187
- "& .MuiInputBase-root": {
9188
- color: "black",
9189
- backgroundColor: "white",
9190
- borderRadius: theme.shape.borderRadius,
9191
- minWidth: "100%"
9192
- },
9193
- "& .MuiInputBase-input": {
9194
- fontSize: "14px !important",
9195
- height: "15px !important"
9196
- },
9197
- "& .MuiInput-underline:before": {
9198
- borderBottomColor: "rgba(0, 0, 0, 0.42)"
9199
- }
9200
- },
9201
- labelOptions: {
9202
- paddingLeft: "2rem",
9203
- userSelect: "none",
9204
- "& > label": {
9205
- display: "flex",
9206
- alignItems: "center",
9207
- gap: "5px"
9208
- },
9209
- '& input[type="checkbox"]': {
9210
- zoom: 1.5
9211
- }
9212
- },
9213
- navigatorButton: {
9214
- "& .MuiSvgIcon-root": {
9215
- cursor: "pointer !important"
9216
- }
9217
- }
9218
- }); });
9219
-
9220
9596
  var CustomOptionsComponent = function (_a) {
9221
9597
  var customOptions = _a.customOptions, setCustomOptions = _a.setCustomOptions;
9222
9598
  var classes = useTrendingStyles();
@@ -9237,6 +9613,129 @@ var CustomOptionsComponent = function (_a) {
9237
9613
  "Stepped"))));
9238
9614
  };
9239
9615
 
9616
+ var dateNavigator = function (startDate, endDate, scope, operator) {
9617
+ if (scope === "custom")
9618
+ return;
9619
+ else {
9620
+ var _a = scope.split(" "), quantity = _a[0], duration = _a[1];
9621
+ var newStartDate = moment(startDate)[operator](quantity, duration[0]).toDate();
9622
+ var newEndDate = moment(endDate)[operator](quantity, duration[0]).toDate();
9623
+ return { newStartDate: newStartDate, newEndDate: newEndDate };
9624
+ }
9625
+ };
9626
+
9627
+ var Header = function (_a) {
9628
+ var setChartOptions = _a.setChartOptions;
9629
+ var classes = useTrendingStyles();
9630
+ var _b = useTrendingContext(), state = _b.state, actions = _b.actions;
9631
+ var _c = useState({
9632
+ showGrid: true,
9633
+ stepped: false
9634
+ }), customOptions = _c[0], setCustomOptions = _c[1];
9635
+ var handleDateNavigator = function (operator) {
9636
+ var newDates = dateNavigator(state.timeScopeStart, state.timeScopeEnd, state.scope, operator);
9637
+ if (newDates) {
9638
+ actions.setTotalScope({ start: newDates.newStartDate, end: newDates.newEndDate, scope: state.scope });
9639
+ }
9640
+ };
9641
+ var handleDateChange = function (newValue, key) {
9642
+ var _a;
9643
+ //@ts-ignore
9644
+ actions.setTotalScope((_a = {}, _a[key] = moment(newValue).toDate(), _a));
9645
+ };
9646
+ var handleChangeScope = function (e) {
9647
+ var newScope = e.target.value;
9648
+ actions.setTotalScope({
9649
+ scope: newScope
9650
+ });
9651
+ };
9652
+ useEffect(function () {
9653
+ var changeOptions = function () {
9654
+ // console.log("change options");
9655
+ setChartOptions(function (prevOptions) { return (__assign(__assign({}, prevOptions), { elements: {
9656
+ line: {
9657
+ stepped: customOptions.stepped,
9658
+ lineTension: 0.1
9659
+ }
9660
+ }, 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 }) }) }) })); });
9661
+ };
9662
+ changeOptions();
9663
+ }, [customOptions]);
9664
+ useEffect(function () {
9665
+ 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() }) }) })); });
9666
+ }, [state.timeScopeStart, state.timeScopeEnd]);
9667
+ return (React__default.createElement(Grid$1, { item: true, xs: 12, container: true, justifyContent: "space-between", alignItems: "center", style: { height: "15%" } },
9668
+ React__default.createElement(Grid$1, { md: 5, item: true, container: true, justifyContent: "flex-start", alignItems: "center", spacing: 1, wrap: "wrap" },
9669
+ React__default.createElement(IconButton$1, { color: "primary", onClick: function () { return handleDateNavigator("subtract"); }, className: classes.navigatorButton },
9670
+ React__default.createElement(ChevronLeft, { fontSize: "large" })),
9671
+ React__default.createElement(Grid$1, { item: true },
9672
+ 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: {
9673
+ shrink: true,
9674
+ style: { marginLeft: "10px" }
9675
+ }, InputProps: {
9676
+ max: state.timeScopeEnd
9677
+ } })),
9678
+ React__default.createElement(Grid$1, { item: true, className: classes.select },
9679
+ React__default.createElement(FormControl$1, { variant: "outlined" },
9680
+ React__default.createElement(Select$1, { value: state.scope, onChange: handleChangeScope, displayEmpty: true },
9681
+ React__default.createElement(MenuItem$1, { value: "10 min" }, "10 min"),
9682
+ React__default.createElement(MenuItem$1, { value: "1 hour" }, "1 hour"),
9683
+ React__default.createElement(MenuItem$1, { value: "4 hours" }, "4 hours"),
9684
+ React__default.createElement(MenuItem$1, { value: "12 hours" }, "12 hours"),
9685
+ React__default.createElement(MenuItem$1, { value: "1 day" }, "1 day"),
9686
+ React__default.createElement(MenuItem$1, { value: "10 days" }, "10 days"),
9687
+ React__default.createElement(MenuItem$1, { value: "custom" }, "Custom")))),
9688
+ React__default.createElement(Grid$1, { item: true },
9689
+ 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: {
9690
+ shrink: true,
9691
+ style: { marginLeft: "10px" }
9692
+ } })),
9693
+ React__default.createElement(IconButton$1, { color: "primary", onClick: function () { return handleDateNavigator("add"); }, className: classes.navigatorButton },
9694
+ React__default.createElement(ChevronRight, { fontSize: "large" }))),
9695
+ React__default.createElement(Grid$1, { md: 7, item: true, container: true, justifyContent: "space-between" },
9696
+ React__default.createElement(Grid$1, { item: true, container: true, wrap: "nowrap", spacing: 1 },
9697
+ React__default.createElement(Grid$1, { item: true, container: true },
9698
+ React__default.createElement(CustomOptionsComponent, { customOptions: customOptions, setCustomOptions: setCustomOptions }))))));
9699
+ };
9700
+
9701
+ var DraggableLineControl = function (_a) {
9702
+ var initialLeft = _a.initialLeft, onUpdate = _a.onUpdate, color = _a.color, chartArea = _a.chartArea;
9703
+ var _b = useState(false), isDragging = _b[0], setIsDragging = _b[1];
9704
+ var _c = useState(initialLeft), left = _c[0], setLeft = _c[1];
9705
+ var ref = useRef(null);
9706
+ var handleMouseDown = function (e) {
9707
+ setIsDragging(true);
9708
+ e.stopPropagation();
9709
+ e.preventDefault();
9710
+ };
9711
+ var handleMouseMove = function (e) {
9712
+ if (!isDragging || !ref.current)
9713
+ return;
9714
+ chartArea.width - chartArea.right;
9715
+ chartArea.left;
9716
+ var newLeft = Math.min(Math.max(e.clientX - ref.current.offsetParent.getBoundingClientRect().left, chartArea.left), chartArea.right);
9717
+ setLeft(newLeft);
9718
+ onUpdate(newLeft); // Actualiza la posición de la línea en el gráfico
9719
+ };
9720
+ var handleMouseUp = function () {
9721
+ setIsDragging(false);
9722
+ };
9723
+ useEffect(function () {
9724
+ var mouseMoveHandler = function (e) { return handleMouseMove(e); };
9725
+ var mouseUpHandler = function () { return handleMouseUp(); };
9726
+ if (isDragging) {
9727
+ window.addEventListener('mousemove', mouseMoveHandler);
9728
+ window.addEventListener('mouseup', mouseUpHandler);
9729
+ }
9730
+ return function () {
9731
+ window.removeEventListener('mousemove', mouseMoveHandler);
9732
+ window.removeEventListener('mouseup', mouseUpHandler);
9733
+ };
9734
+ }, [isDragging]);
9735
+ return (React__default.createElement("div", { ref: ref, style: { height: 20, width: 20, background: color, position: 'absolute', top: -10, left: left - 10 }, onMouseDown: handleMouseDown },
9736
+ React__default.createElement("div", { style: { height: chartArea.height, width: 2, background: color, position: 'relative', top: 20, left: 0, right: 0, margin: 'auto' } })));
9737
+ };
9738
+
9240
9739
  var useGetVerticalLinePlugin = function (setChartArea, setCoords) {
9241
9740
  var chartPlugin = {
9242
9741
  id: "verticalLinePlugin",
@@ -9300,21 +9799,6 @@ var updateCursorData = function (chart, setCursorData) {
9300
9799
  });
9301
9800
  };
9302
9801
 
9303
- var formatDateTimeToString = function (date) {
9304
- var hour = date.getHours().toString().padStart(2, '0');
9305
- var minute = date.getMinutes().toString().padStart(2, '0');
9306
- var second = date.getSeconds().toString().padStart(2, '0');
9307
- if (hour === '24') {
9308
- hour = '00';
9309
- }
9310
- var formattedDate = date.toLocaleDateString("en-US", {
9311
- month: "short",
9312
- day: "numeric"
9313
- });
9314
- var formattedTime = "".concat(hour, ":").concat(minute, ":").concat(second);
9315
- return { formattedDate: formattedDate, formattedTime: formattedTime };
9316
- };
9317
-
9318
9802
  var useXAxisDatePlugin = function () {
9319
9803
  var chartPlugin = {
9320
9804
  id: 'xAxisDatePlugin',
@@ -9346,12 +9830,21 @@ var useXAxisDatePlugin = function () {
9346
9830
  return chartPlugin;
9347
9831
  };
9348
9832
 
9833
+ var useYAxisPlugin = function () {
9834
+ var chartPlugin = {
9835
+ id: 'yAxisPlugin'
9836
+ };
9837
+ return chartPlugin;
9838
+ };
9839
+
9349
9840
  var areRangesSimilar = function (tag1, tag2) {
9350
- var range1 = tag1.maxScale - tag1.minScale; // Rango de la primera etiqueta
9351
- var range2 = tag2.maxScale - tag2.minScale; // Rango de la segunda etiqueta
9841
+ if (isNil$1(tag1.MaxScale) || isNil$1(tag1.MinScale) || isNil$1(tag2.MaxScale) || isNil$1(tag2.MinScale))
9842
+ return;
9843
+ var range1 = tag1.MaxScale - tag1.MinScale; // Rango de la primera etiqueta
9844
+ var range2 = tag2.MaxScale - tag2.MinScale; // Rango de la segunda etiqueta
9352
9845
  // Determina los límites para la comparación
9353
- var lowerBound = Math.max(tag1.minScale, tag2.minScale);
9354
- var upperBound = Math.min(tag1.maxScale, tag2.maxScale);
9846
+ var lowerBound = Math.max(tag1.MinScale, tag2.MinScale);
9847
+ var upperBound = Math.min(tag1.MaxScale, tag2.MaxScale);
9355
9848
  // Calcula el solapamiento entre los dos rangos
9356
9849
  var overlap = Math.max(0, upperBound - lowerBound);
9357
9850
  // Determina si el solapamiento es significativo comparado con los rangos individuales
@@ -9359,290 +9852,104 @@ var areRangesSimilar = function (tag1, tag2) {
9359
9852
  return isSignificantOverlap;
9360
9853
  };
9361
9854
 
9362
- var calculateScales = function (min, max, sigDigits) {
9363
- var roundToSignificantDigits = function (num) {
9364
- if (num === 0)
9365
- return 0;
9366
- var multiplier = Math.pow(10, sigDigits - Math.floor(Math.log10(Math.abs(num))) - 1);
9367
- return Math.round(num * multiplier) / multiplier;
9368
- };
9369
- var minScale = roundToSignificantDigits(min);
9370
- var maxScale = roundToSignificantDigits(max);
9371
- // Adjust minScale and maxScale if necessary
9372
- if (minScale > min) {
9373
- minScale *= 0.9;
9374
- }
9375
- if (maxScale < max) {
9376
- maxScale *= 1.1;
9377
- }
9378
- return { minScale: minScale, maxScale: maxScale };
9379
- };
9380
-
9381
- var dateNavigator = function (startDate, endDate, scope, operator) {
9382
- if (scope === "custom")
9383
- return;
9384
- else {
9385
- var _a = scope.split(" "), quantity = _a[0], duration = _a[1];
9386
- var newStartDate = moment(startDate)[operator](quantity, duration[0]).toDate();
9387
- var newEndDate = moment(endDate)[operator](quantity, duration[0]).toDate();
9388
- return { newStartDate: newStartDate, newEndDate: newEndDate };
9389
- }
9390
- };
9391
-
9392
- Chart.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip$1, Legend, TimeScale, zoomPlugin);
9393
- var Trending = function (_a) {
9394
- _a.title; var tags = _a.tags;
9395
- var classes = useTrendingStyles();
9396
- var _b = useTrendingContext(), state = _b.state, actions = _b.actions;
9397
- var _c = useState(true), loading = _c[0], setLoading = _c[1];
9398
- var _d = useState(""), error = _d[0], setError = _d[1];
9399
- var _e = useState(tags), tagList = _e[0], setTagList = _e[1];
9400
- var _f = useState(null), cursorData = _f[0], setCursorData = _f[1];
9401
- var _g = useState(null), lineTabCoords = _g[0], setLineTabCoords = _g[1];
9402
- var _h = useState(null), chartArea = _h[0], setChartArea = _h[1];
9403
- var _j = useState(false), chartShouldInitCursors = _j[0], setChartShouldInitCursors = _j[1];
9855
+ var TrendingChart = function (_a) {
9856
+ var series = _a.series, chartOptions = _a.chartOptions, setChartOptions = _a.setChartOptions, chartData = _a.chartData, setCursorData = _a.setCursorData, setChartData = _a.setChartData;
9857
+ var _b = useTrendingContext(), state = _b.state, viewTags = _b.state.viewTags; _b.actions;
9858
+ var _c = useState(null), lineTabCoords = _c[0], setLineTabCoords = _c[1];
9859
+ var _d = useState(null), chartArea = _d[0], setChartArea = _d[1];
9404
9860
  var chartRef = useRef(null);
9405
- var _k = useState({
9406
- labels: [],
9407
- datasets: []
9408
- }), chartData = _k[0], setChartData = _k[1];
9409
- var verticalLinePlugin = useGetVerticalLinePlugin(setChartArea, setLineTabCoords);
9410
- var xAxisDatePlugin = useXAxisDatePlugin();
9411
- var _l = useState({
9412
- showGrid: true,
9413
- stepped: false
9414
- }), customOptions = _l[0], setCustomOptions = _l[1];
9415
- var debounceTimerRef = useRef(null);
9416
9861
  var debouncedUpdateChart = useRef(debounce(function () {
9417
9862
  if (chartRef.current) {
9418
9863
  updateCursorData(chartRef.current, setCursorData);
9419
9864
  chartRef.current.update();
9420
9865
  }
9421
9866
  }, 250)).current;
9422
- var handleDateChange = function (newValue, key) {
9423
- var _a;
9424
- //@ts-ignore
9425
- actions.setTotalScope((_a = {}, _a[key] = moment(newValue).toDate(), _a));
9426
- };
9427
- var handleChangeScope = function (e) {
9428
- var newScope = e.target.value;
9429
- actions.setTotalScope({
9430
- scope: newScope
9431
- });
9432
- };
9433
- var handleZoom = function (_a) {
9434
- var chart = _a.chart;
9435
- if (debounceTimerRef.current) {
9436
- clearTimeout(debounceTimerRef.current);
9437
- }
9438
- debounceTimerRef.current = setTimeout(function () {
9439
- // Handle zoom event and execute fetch
9440
- var newStart = new Date(chart.scales.x.min);
9441
- var newEnd = new Date(chart.scales.x.max);
9442
- actions.setTotalScope({
9443
- start: newStart,
9444
- end: newEnd
9445
- });
9446
- }, 1000);
9447
- };
9448
- var handlePan = function (_a) {
9449
- var chart = _a.chart;
9450
- if (debounceTimerRef.current) {
9451
- clearTimeout(debounceTimerRef.current);
9867
+ var _e = useState(false), chartShouldInitCursors = _e[0], setChartShouldInitCursors = _e[1];
9868
+ var verticalLinePlugin = useGetVerticalLinePlugin(setChartArea, setLineTabCoords);
9869
+ var xAxisDatePlugin = useXAxisDatePlugin();
9870
+ var yAxisPlugin = useYAxisPlugin();
9871
+ useEffect(function () {
9872
+ var axes = [];
9873
+ if (!series.length) {
9874
+ return;
9452
9875
  }
9453
- debounceTimerRef.current = setTimeout(function () {
9454
- // Handle pan event and execute fetch
9455
- var newStart = new Date(chart.scales.x.min);
9456
- var newEnd = new Date(chart.scales.x.max);
9457
- actions.setTotalScope({
9458
- start: newStart,
9459
- end: newEnd,
9460
- graphPan: true
9461
- });
9462
- }, 1000);
9463
- };
9464
- var handleDeleteTag = function (tagId) {
9465
- setTagList(function (prevTagList) {
9466
- return prevTagList.filter(function (tag) { return tag.tagId !== tagId; });
9467
- });
9468
- };
9469
- var handleAddTag = function (newTag) {
9470
- if (newTag) {
9471
- setTagList(function (prevTagList) {
9472
- // Check if the tag is already in the list to avoid duplicates
9473
- if (prevTagList.some(function (tag) { return tag.tagId === newTag.tagId; })) {
9474
- return prevTagList; // Return the existing list if the tag is already there
9876
+ viewTags.forEach(function (tag, index) {
9877
+ var _a;
9878
+ if ((_a = series[index]) === null || _a === void 0 ? void 0 : _a.length) {
9879
+ var existingAxis = axes.find(function (existingTag) {
9880
+ return areRangesSimilar(existingTag, tag);
9881
+ });
9882
+ if (!existingAxis) {
9883
+ axes.push(tag); // Add new axis if no similar one exists
9475
9884
  }
9476
- return __spreadArray(__spreadArray([], prevTagList, true), [newTag], false); // Add the new tag to the list
9477
- });
9478
- }
9479
- };
9480
- var handleDateNavigator = function (operator) {
9481
- var newDates = dateNavigator(state.timeScopeStart, state.timeScopeEnd, state.scope, operator);
9482
- if (newDates) {
9483
- actions.setTotalScope({ start: newDates.newStartDate, end: newDates.newEndDate, scope: state.scope });
9484
- }
9485
- };
9486
- var _m = useState({
9487
- animation: {
9488
- duration: 0
9489
- },
9490
- responsive: true,
9491
- maintainAspectRatio: false,
9492
- scales: {
9493
- x: {
9494
- type: "time",
9885
+ }
9886
+ });
9887
+ // Configure yAxes based on grouped axes
9888
+ var yAxesConfig = axes.map(function (axis, index) {
9889
+ return {
9890
+ id: "y-axis-".concat(index),
9891
+ type: "linear",
9892
+ display: axis.visible,
9893
+ scaleLabel: {
9894
+ display: true,
9895
+ labelString: axis.tagName
9896
+ },
9495
9897
  ticks: {
9496
- autoSkip: true,
9497
- maxTicksLimit: 20,
9498
- callback: function (value, index, ticks) {
9499
- var currentDate = new Date(value);
9500
- var time = formatDateTimeToString(currentDate).formattedTime;
9501
- var date = formatDateTimeToString(currentDate).formattedDate;
9502
- // Si es el primer tick, siempre muestra la fecha y hora
9503
- if (index === 0) {
9504
- return [time, date];
9505
- }
9506
- // De lo contrario, solo muestra la hora
9507
- return time;
9508
- }
9898
+ min: axis.autoScale ? undefined : axis.minScale,
9899
+ max: axis.autoScale ? undefined : axis.maxScale
9509
9900
  },
9510
9901
  grid: {
9511
9902
  display: true
9512
- }
9513
- },
9514
- y: {
9515
- grid: {
9516
- display: true
9517
- }
9518
- }
9519
- },
9520
- plugins: {
9521
- tooltip: { enabled: false },
9522
- legend: { display: false },
9523
- zoom: {
9524
- zoom: {
9525
- wheel: { enabled: true, mode: "x" },
9526
- pinch: { enabled: true, mode: "x" },
9527
- onZoom: handleZoom,
9528
- mode: "x"
9529
9903
  },
9530
- pan: {
9531
- enabled: true,
9532
- mode: "x",
9533
- onPan: handlePan
9534
- }
9535
- }
9536
- }
9537
- }), chartOptions = _m[0], setChartOptions = _m[1];
9538
- useEffect(function () {
9539
- var fetchData = function () { return __awaiter(void 0, void 0, void 0, function () {
9540
- var tagIds, response, series_1, axes_1, updatedSeries, error_1;
9541
- return __generator(this, function (_a) {
9542
- switch (_a.label) {
9543
- case 0:
9544
- _a.trys.push([0, 2, , 3]);
9545
- console.log("fetching data");
9546
- setLoading(true);
9547
- tagIds = tagList.map(function (tag) { return tag.tagId; });
9548
- return [4 /*yield*/, axios.post("/series?nodeName=null", {
9549
- start: state.timeScopeStart.getTime(),
9550
- end: state.timeScopeEnd.getTime(),
9551
- tagIds: tagIds,
9552
- sampleCount: 1000
9553
- })];
9554
- case 1:
9555
- response = _a.sent();
9556
- series_1 = response.data;
9557
- axes_1 = [];
9558
- tagList.forEach(function (tag, index) {
9559
- if (tag.autoScale && series_1[index]) {
9560
- var serieSamples = series_1[index].map(function (sample) { return sample.value; });
9561
- var _a = calculateScales(Math.min.apply(Math, serieSamples), Math.max.apply(Math, serieSamples), 3), minScale = _a.minScale, maxScale = _a.maxScale;
9562
- tag.minScale = minScale;
9563
- tag.maxScale = maxScale;
9904
+ afterUpdate: function (axis) {
9905
+ var chart = axis.chart;
9906
+ var keys = Object.keys(chart.scales).filter(function (sc) { return sc !== 'x'; });
9907
+ if (keys.length > 1) {
9908
+ for (var scaleKey in chart.scales) {
9909
+ var scale = chart.scales[scaleKey];
9910
+ if (scale.max === 1 && scale.min === 0) {
9911
+ chart.scales[scaleKey].display = false;
9912
+ chart.scales[scaleKey].options.display = false;
9564
9913
  }
9565
- var existingAxis = axes_1.find(function (existingTag) {
9566
- return areRangesSimilar(existingTag, tag);
9567
- });
9568
- if (!existingAxis) {
9569
- axes_1.push(tag); // Add new axis if no similar one exists
9914
+ else {
9915
+ chart.scales[scaleKey].display = true;
9916
+ chart.scales[scaleKey].options.display = true;
9570
9917
  }
9571
- });
9572
- axes_1.map(function (axis, index) {
9573
- return {
9574
- id: "y-axis-".concat(index),
9575
- type: "linear",
9576
- display: axis.visible,
9577
- scaleLabel: {
9578
- display: true,
9579
- labelString: axis.tagName
9580
- },
9581
- ticks: {
9582
- min: axis.autoScale ? undefined : axis.minScale,
9583
- max: axis.autoScale ? undefined : axis.maxScale
9584
- },
9585
- grid: {
9586
- display: true
9587
- }
9588
- };
9589
- });
9590
- setChartOptions(function (prevOptions) { return (__assign(__assign({}, prevOptions), { scales: __assign(__assign({}, prevOptions.scales), { y: { grid: { display: true } } }) })); });
9591
- updatedSeries = series_1.map(function (serie, index) {
9592
- var tag = tagList[index];
9593
- var axisIndex = axes_1.findIndex(function (existingTag) {
9594
- return areRangesSimilar(existingTag, tag);
9595
- });
9596
- return {
9597
- yAxisID: "y-axis-".concat(axisIndex),
9598
- data: serie.map(function (sample) { return ({
9599
- x: new Date(sample.timestamp),
9600
- y: sample.value
9601
- }); }),
9602
- tagId: tag.tagId,
9603
- borderColor: tag.color,
9604
- hidden: !tag.visible,
9605
- pointRadius: serie.length <= 50 ? 3 : 0
9606
- };
9607
- });
9608
- setChartShouldInitCursors(true);
9609
- setChartData({
9610
- labels: [],
9611
- datasets: updatedSeries
9612
- });
9613
- setLoading(false);
9614
- return [3 /*break*/, 3];
9615
- case 2:
9616
- error_1 = _a.sent();
9617
- console.error("Error fetching data:", error_1);
9618
- setError("Failed to fetch data");
9619
- setLoading(false);
9620
- return [3 /*break*/, 3];
9621
- case 3: return [2 /*return*/];
9918
+ }
9919
+ }
9622
9920
  }
9921
+ };
9922
+ });
9923
+ setChartOptions(function (prevOptions) {
9924
+ var newResp = (__assign(__assign({}, prevOptions), { scales: __assign({ x: __assign({}, prevOptions.scales.x) }, yAxesConfig.reduce(function (acc, cur) {
9925
+ var _a;
9926
+ return (__assign(__assign({}, acc), (_a = {}, _a[cur.id] = cur, _a)));
9927
+ }, {})) }));
9928
+ return newResp;
9929
+ });
9930
+ var updatedSeries = series.map(function (serie, index) {
9931
+ var tag = viewTags[index];
9932
+ var axisIndex = axes.findIndex(function (existingTag) {
9933
+ return areRangesSimilar(existingTag, tag);
9623
9934
  });
9624
- }); };
9625
- fetchData();
9626
- }, [JSON.stringify(state), tagList]);
9627
- useEffect(function () {
9628
- var changeOptions = function () {
9629
- // console.log("change options");
9630
- setChartOptions(function (prevOptions) { return (__assign(__assign({}, prevOptions), { elements: {
9631
- line: {
9632
- stepped: customOptions.stepped,
9633
- lineTension: 0.1
9634
- }
9635
- }, 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 }) }) }) })); });
9636
- };
9637
- changeOptions();
9638
- }, [customOptions]);
9639
- if (error)
9640
- return React__default.createElement("p", null,
9641
- "Error: ",
9642
- error);
9643
- useEffect(function () {
9644
- 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() }) }) })); });
9645
- }, [state.timeScopeStart, state.timeScopeEnd]);
9935
+ return {
9936
+ yAxisID: axisIndex >= 0 ? "y-axis-".concat(axisIndex) : undefined,
9937
+ data: serie.map(function (sample) { return ({
9938
+ x: new Date(sample.timestamp),
9939
+ y: sample.value
9940
+ }); }),
9941
+ tagId: tag === null || tag === void 0 ? void 0 : tag.TagId,
9942
+ borderColor: tag === null || tag === void 0 ? void 0 : tag.Color,
9943
+ hidden: !(tag === null || tag === void 0 ? void 0 : tag.IsVisible),
9944
+ pointRadius: serie.length <= 50 ? 3 : 0
9945
+ };
9946
+ });
9947
+ setChartShouldInitCursors(true);
9948
+ setChartData({
9949
+ labels: [],
9950
+ datasets: updatedSeries
9951
+ });
9952
+ }, [state.graphShouldUpdate, series]);
9646
9953
  useEffect(function () {
9647
9954
  if (chartShouldInitCursors) {
9648
9955
  if (chartRef.current) {
@@ -9650,116 +9957,141 @@ var Trending = function (_a) {
9650
9957
  chartRef.current.update();
9651
9958
  }
9652
9959
  }
9653
- }, [chartShouldInitCursors, state]);
9654
- return (React__default.createElement(Grid$1, { container: true, style: { width: "95svw", height: "81svh", margin: 0 } },
9655
- React__default.createElement(Grid$1, { item: true, xs: 12, container: true, justifyContent: "space-between", alignItems: "center", style: { height: "15%" } },
9656
- React__default.createElement(Grid$1, { md: 5, item: true, container: true, justifyContent: "flex-start", alignItems: "center", spacing: 1, wrap: "wrap" },
9657
- React__default.createElement(IconButton$1, { color: "primary", onClick: function () { return handleDateNavigator("subtract"); }, className: classes.navigatorButton },
9658
- React__default.createElement(ChevronLeft, { fontSize: "large" })),
9659
- React__default.createElement(Grid$1, { item: true },
9660
- 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: {
9661
- shrink: true,
9662
- style: { marginLeft: "10px" }
9663
- }, InputProps: {
9664
- max: state.timeScopeEnd
9665
- } })),
9666
- React__default.createElement(Grid$1, { item: true, className: classes.select },
9667
- React__default.createElement(FormControl$1, { variant: "outlined" },
9668
- React__default.createElement(Select$1, { value: state.scope, onChange: handleChangeScope, displayEmpty: true },
9669
- React__default.createElement(MenuItem$1, { value: "10 min" }, "10 min"),
9670
- React__default.createElement(MenuItem$1, { value: "1 hour" }, "1 hour"),
9671
- React__default.createElement(MenuItem$1, { value: "4 hours" }, "4 hours"),
9672
- React__default.createElement(MenuItem$1, { value: "12 hours" }, "12 hours"),
9673
- React__default.createElement(MenuItem$1, { value: "1 day" }, "1 day"),
9674
- React__default.createElement(MenuItem$1, { value: "10 days" }, "10 days"),
9675
- React__default.createElement(MenuItem$1, { value: "custom" }, "Custom")))),
9676
- React__default.createElement(Grid$1, { item: true },
9677
- 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: {
9678
- shrink: true,
9679
- style: { marginLeft: "10px" }
9680
- } })),
9681
- React__default.createElement(IconButton$1, { color: "primary", onClick: function () { return handleDateNavigator("add"); }, className: classes.navigatorButton },
9682
- React__default.createElement(ChevronRight, { fontSize: "large" }))),
9683
- React__default.createElement(Grid$1, { md: 7, item: true, container: true, justifyContent: "space-between" },
9684
- React__default.createElement(Grid$1, { item: true, container: true, wrap: "nowrap", spacing: 1 },
9685
- React__default.createElement(Grid$1, { item: true, container: true },
9686
- React__default.createElement(CustomOptionsComponent, { customOptions: customOptions, setCustomOptions: setCustomOptions }))))),
9687
- React__default.createElement(Grid$1, { item: true, xs: 12, style: { height: '45%' } },
9688
- React__default.createElement(Paper$1, { style: { height: '100%', position: 'relative' } },
9689
- lineTabCoords && chartArea ? (React__default.createElement(DraggableLineControl, { color: 'red', chartArea: chartArea, initialLeft: lineTabCoords === null || lineTabCoords === void 0 ? void 0 : lineTabCoords.x1, onUpdate: function (newLeft) {
9690
- setLineTabCoords(function (prevCoords) {
9691
- prevCoords.x1 = newLeft;
9692
- return prevCoords;
9693
- });
9694
- // @ts-ignore
9695
- chartRef.current.mouseX = newLeft;
9696
- debouncedUpdateChart();
9697
- } })) : null,
9698
- lineTabCoords && chartArea ? (React__default.createElement(DraggableLineControl, { color: 'blue', initialLeft: lineTabCoords === null || lineTabCoords === void 0 ? void 0 : lineTabCoords.x2, chartArea: chartArea, onUpdate: function (newLeft) {
9699
- setLineTabCoords(function (prevCoords) {
9700
- prevCoords.x2 = newLeft;
9701
- return prevCoords;
9702
- });
9703
- // @ts-ignore
9704
- chartRef.current.secondLineX = newLeft;
9705
- debouncedUpdateChart();
9706
- } })) : null,
9707
- React__default.createElement(Line, { ref: chartRef, data: chartData, options: chartOptions, plugins: [verticalLinePlugin, xAxisDatePlugin] }))),
9708
- React__default.createElement(Grid$1, { item: true, xs: 12, style: { height: '40%', minWidth: "100%", paddingTop: "3rem" } },
9709
- React__default.createElement(TableComponent, { tagList: tagList, chartData: chartData, setTagList: setTagList, cursorData: cursorData, onDeleteTag: handleDeleteTag, onAddTag: handleAddTag })),
9710
- loading && (React__default.createElement(Grid$1, { item: true, xs: 12, style: { textAlign: 'center' } },
9711
- React__default.createElement("p", null, "Loading...")))));
9960
+ }, [chartShouldInitCursors, state.graphShouldUpdate]);
9961
+ return (React__default.createElement(Paper$1, { style: { height: '100%', position: 'relative' } },
9962
+ lineTabCoords && chartArea ? (React__default.createElement(DraggableLineControl, { color: 'red', chartArea: chartArea, initialLeft: lineTabCoords === null || lineTabCoords === void 0 ? void 0 : lineTabCoords.x1, onUpdate: function (newLeft) {
9963
+ setLineTabCoords(function (prevCoords) {
9964
+ prevCoords.x1 = newLeft;
9965
+ return prevCoords;
9966
+ });
9967
+ // @ts-ignore
9968
+ chartRef.current.mouseX = newLeft;
9969
+ debouncedUpdateChart();
9970
+ } })) : null,
9971
+ lineTabCoords && chartArea ? (React__default.createElement(DraggableLineControl, { color: 'blue', initialLeft: lineTabCoords === null || lineTabCoords === void 0 ? void 0 : lineTabCoords.x2, chartArea: chartArea, onUpdate: function (newLeft) {
9972
+ setLineTabCoords(function (prevCoords) {
9973
+ prevCoords.x2 = newLeft;
9974
+ return prevCoords;
9975
+ });
9976
+ // @ts-ignore
9977
+ chartRef.current.secondLineX = newLeft;
9978
+ debouncedUpdateChart();
9979
+ } })) : null,
9980
+ React__default.createElement(Line, { ref: chartRef, data: chartData, options: chartOptions, plugins: [verticalLinePlugin, xAxisDatePlugin, yAxisPlugin] })));
9712
9981
  };
9713
9982
 
9714
- // @flow
9715
- var TrendingsIndex = function (props) {
9716
- return (React.createElement(TrendingProvider, null,
9717
- React.createElement(Box, { p: 3, style: { maxWidth: "100%" } },
9718
- React.createElement(Paper, null,
9719
- React.createElement(Grid$1, { container: true, spacing: 3, style: { padding: "20px" } },
9720
- React.createElement(Grid$1, { item: true, xs: 12 },
9721
- React.createElement(Trending, { title: "Trending Chart", tags: [
9722
- {
9723
- tagId: 29,
9724
- tagName: "t1",
9725
- tagType: "number",
9726
- color: "red",
9727
- autoScale: true,
9728
- minScale: 0,
9729
- maxScale: 100,
9730
- visible: true
9731
- },
9732
- {
9733
- tagId: 44,
9734
- tagName: "t2",
9735
- tagType: "number",
9736
- color: "blue",
9737
- autoScale: true,
9738
- minScale: 0,
9739
- maxScale: 100,
9740
- visible: true
9741
- },
9742
- {
9743
- tagId: 50,
9744
- tagName: "t3",
9745
- tagType: "number",
9746
- color: "green",
9747
- autoScale: true,
9748
- minScale: 0,
9749
- maxScale: 100,
9750
- visible: true
9751
- },
9752
- {
9753
- tagId: 46,
9754
- tagName: "t4",
9755
- tagType: "number",
9756
- color: "black",
9757
- autoScale: true,
9758
- minScale: 0,
9759
- maxScale: 100,
9760
- visible: true
9761
- },
9762
- ] })))))));
9983
+ Chart.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip$1, Legend, TimeScale, zoomPlugin);
9984
+ var Trending = function (_a) {
9985
+ _a.title;
9986
+ var _b = useTrendingContext(), state = _b.state, viewTags = _b.state.viewTags;
9987
+ var _c = useState(''), error = _c[0], setError = _c[1];
9988
+ var _d = useState(true), loading = _d[0], setLoading = _d[1];
9989
+ var _e = useState([]), series = _e[0], setSeries = _e[1];
9990
+ var _f = useChartOptions(), chartOptions = _f[0], setChartOptions = _f[1];
9991
+ var _g = useState({
9992
+ labels: [],
9993
+ datasets: []
9994
+ }), chartData = _g[0], setChartData = _g[1];
9995
+ var _h = useState(null), cursorData = _h[0], setCursorData = _h[1];
9996
+ var debounceForFetchingData = useRef(null);
9997
+ useEffect(function () {
9998
+ if (debounceForFetchingData.current) {
9999
+ clearTimeout(debounceForFetchingData.current);
10000
+ }
10001
+ debounceForFetchingData.current = setTimeout(function () {
10002
+ var fetchData = function () { return __awaiter(void 0, void 0, void 0, function () {
10003
+ var tagIds, response, error_1;
10004
+ return __generator(this, function (_a) {
10005
+ switch (_a.label) {
10006
+ case 0:
10007
+ _a.trys.push([0, 3, , 4]);
10008
+ setLoading(true);
10009
+ if (!(Array.isArray(viewTags) && viewTags.length)) return [3 /*break*/, 2];
10010
+ tagIds = viewTags.map(function (tag) { return tag.TagId; });
10011
+ return [4 /*yield*/, axios.post("/series?nodeName=null", {
10012
+ start: state.timeScopeStart.getTime(),
10013
+ end: state.timeScopeEnd.getTime(),
10014
+ tagIds: tagIds,
10015
+ sampleCount: 1000
10016
+ })];
10017
+ case 1:
10018
+ response = _a.sent();
10019
+ setSeries(response.data || []);
10020
+ _a.label = 2;
10021
+ case 2:
10022
+ setLoading(false);
10023
+ return [3 /*break*/, 4];
10024
+ case 3:
10025
+ error_1 = _a.sent();
10026
+ setError(error_1.message);
10027
+ setLoading(false);
10028
+ return [3 /*break*/, 4];
10029
+ case 4: return [2 /*return*/];
10030
+ }
10031
+ });
10032
+ }); };
10033
+ fetchData();
10034
+ }, 800);
10035
+ }, [state.graphShouldUpdate, viewTags]);
10036
+ return (React__default.createElement(React__default.Fragment, null,
10037
+ React__default.createElement(Grid$1, { container: true, style: { width: "95svw", height: "81svh", margin: 0 } },
10038
+ React__default.createElement(Header, { setChartOptions: setChartOptions }),
10039
+ React__default.createElement(Grid$1, { item: true, xs: 12, style: { height: '45%' } },
10040
+ React__default.createElement(TrendingChart, { series: series, chartData: chartData, setChartData: setChartData, chartOptions: chartOptions, setChartOptions: setChartOptions, setCursorData: setCursorData })),
10041
+ React__default.createElement(Grid$1, { item: true, xs: 12, style: { height: '40%', minWidth: "100%", paddingTop: "3rem" } },
10042
+ React__default.createElement(TableComponent, { chartData: chartData, cursorData: cursorData })),
10043
+ loading && (React__default.createElement(Grid$1, { item: true, xs: 12, style: { textAlign: 'center' } },
10044
+ React__default.createElement("p", null, "Loading...")))),
10045
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); }, title: "ERROR" })));
10046
+ };
10047
+
10048
+ var TrendingsPage = function (props) {
10049
+ var _a = useState(''), error = _a[0], setError = _a[1];
10050
+ var _b = useTrendingContext().actions, setViews = _b.setViews, setViewTags = _b.setViewTags, setViewSelected = _b.setViewSelected;
10051
+ useEffect(function () {
10052
+ var getTags = function () { return __awaiter(void 0, void 0, void 0, function () {
10053
+ var viewsResp, lastCreated, viewTagsResp;
10054
+ return __generator(this, function (_a) {
10055
+ switch (_a.label) {
10056
+ case 0: return [4 /*yield*/, getViews(null)];
10057
+ case 1:
10058
+ viewsResp = _a.sent();
10059
+ if (!viewsResp.ok) return [3 /*break*/, 3];
10060
+ setViews(viewsResp.data.tables[0].rows);
10061
+ lastCreated = viewsResp.data.tables[0].rows.reduce(function (prev, current) { return (prev.ViewId > current.ViewId) ? prev : current; });
10062
+ //viewSelected
10063
+ setViewSelected(lastCreated);
10064
+ return [4 /*yield*/, getViewTags(lastCreated.ViewId)];
10065
+ case 2:
10066
+ viewTagsResp = _a.sent();
10067
+ if (viewTagsResp.ok) {
10068
+ setViewTags(viewTagsResp.data.tables[0].rows);
10069
+ }
10070
+ else {
10071
+ setError(viewTagsResp.message);
10072
+ }
10073
+ return [3 /*break*/, 4];
10074
+ case 3:
10075
+ setError(viewsResp.message);
10076
+ _a.label = 4;
10077
+ case 4: return [2 /*return*/];
10078
+ }
10079
+ });
10080
+ }); };
10081
+ getTags();
10082
+ }, []);
10083
+ return (React__default.createElement(React__default.Fragment, null,
10084
+ React__default.createElement(Box, { p: 3, style: { maxWidth: "100%" } },
10085
+ React__default.createElement(Paper, null,
10086
+ React__default.createElement(Grid$1, { container: true, spacing: 3, style: { padding: "20px" } },
10087
+ React__default.createElement(Grid$1, { item: true, xs: 12 },
10088
+ React__default.createElement(Trending, { title: "Trending Chart" }))))),
10089
+ React__default.createElement(ErrorModal, { error: error, onHide: function () { return setError(''); }, size: "xl", title: "ERROR" })));
10090
+ };
10091
+
10092
+ var index = function () {
10093
+ return (React__default.createElement(TrendingProvider, null,
10094
+ React__default.createElement(TrendingsPage, null)));
9763
10095
  };
9764
10096
 
9765
10097
  var MESFMainRouter = function () {
@@ -9769,7 +10101,7 @@ var MESFMainRouter = function () {
9769
10101
  React__default.createElement(Route, { path: "/", element: React__default.createElement(Navigate, { replace: true, to: "/home" }) }),
9770
10102
  React__default.createElement(Route, { path: "/configuration/*", element: React__default.createElement(Configuration, null) }),
9771
10103
  React__default.createElement(Route, { path: "/account", element: React__default.createElement(Account, null) }),
9772
- React__default.createElement(Route, { path: "/trendings", element: React__default.createElement(TrendingsIndex, null) }),
10104
+ React__default.createElement(Route, { path: "/trendings", element: React__default.createElement(index, null) }),
9773
10105
  React__default.createElement(Route, { path: "/home", element: React__default.createElement(Home, null) })),
9774
10106
  React__default.createElement(CustomRoutes, null)));
9775
10107
  };
@@ -9794,7 +10126,7 @@ var Navigation = function (_a) {
9794
10126
  };
9795
10127
  }, [params.toString()]);
9796
10128
  return (React__default.createElement("div", { className: "wrapper" },
9797
- React__default.createElement(Header, { showAreaSelector: showAreaSelector, navbarTitle: navbarTitle }),
10129
+ React__default.createElement(Header$1, { showAreaSelector: showAreaSelector, navbarTitle: navbarTitle }),
9798
10130
  React__default.createElement(MESFMainContainer, null)));
9799
10131
  };
9800
10132
 
@@ -9956,4 +10288,5 @@ var areaSelector = /*#__PURE__*/Object.freeze({
9956
10288
  AreaSelector: AreaSelector
9957
10289
  });
9958
10290
 
9959
- 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 };
10291
+ export { Account, AssetProvider, AuthContext, AuthProvider, BarChartControl, ButtonWithLoading, 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, TrendingsPage, USER_LABELS, UTLSettingsProvider, UploadFileControl, UserProvider, axiosInstance, formatNumber, getCrewStyle, getError, getShiftStyle, getTokenFromLS, renewToken, useAssetContext, useToken, useUTLSettingsContext, useUserContext };
10292
+ //# sourceMappingURL=index.esm.js.map