@dexteel/mesf-core 4.5.7 → 4.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # CHANGELOG
2
+ ## 4.5.8
3
+ - Fix table data in Trendings
4
+ - Fix cursors
2
5
  ## 4.5.6
3
6
  - Fix login with Windows Auth
4
7
  ## 4.5.5
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
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, debounce } from 'lodash-es';
2
+ import { values, get, isNil as isNil$1, isEmpty, isNaN, debounce } 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';
@@ -27,10 +27,10 @@ import moment from 'moment';
27
27
  import zoomPlugin from 'chartjs-plugin-zoom';
28
28
  import { Line } from 'react-chartjs-2';
29
29
  import Popover from '@material-ui/core/Popover';
30
- import { Alert as Alert$3, TreeView as TreeView$1, TreeItem as TreeItem$1 } from '@material-ui/lab';
31
30
  import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
32
31
  import FolderIcon from '@material-ui/icons/Folder';
33
32
  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';
34
34
  import PersonPinCircleIcon from '@material-ui/icons/PersonPinCircle';
35
35
  import PropTypes from 'prop-types';
36
36
  import { ResponsiveBar } from '@nivo/bar';
@@ -8419,66 +8419,6 @@ var ColorPicker = function (_a) {
8419
8419
  } })); })))));
8420
8420
  };
8421
8421
 
8422
- var useTagsTableStyles = makeStyles$1(function (theme) { return ({
8423
- checkbox: {
8424
- '& input[type="checkbox"]': {
8425
- zoom: 1.5
8426
- },
8427
- textAlign: 'center'
8428
- },
8429
- rowHover: {
8430
- '&:hover': {
8431
- backgroundColor: "#f2f2f2"
8432
- }
8433
- },
8434
- topTitles: {
8435
- border: "0.0625rem black solid",
8436
- borderBottom: "none",
8437
- backgroundColor: "#e9ecef"
8438
- },
8439
- bottomTitlesRow: {
8440
- '& th': {
8441
- border: "1px black solid"
8442
- },
8443
- backgroundColor: "#e9ecef"
8444
- },
8445
- doubleInput: {
8446
- padding: "0",
8447
- '& input[type="text"] ': {
8448
- width: "100%",
8449
- height: "17px",
8450
- display: "block",
8451
- margin: "0",
8452
- padding: "0"
8453
- }
8454
- },
8455
- inputCol: {
8456
- width: "11.25rem",
8457
- overflow: 'hidden',
8458
- textOverflow: 'ellipsis',
8459
- whiteSpace: 'nowrap'
8460
- },
8461
- autoScale: {
8462
- width: '7.5rem'
8463
- },
8464
- scale: {
8465
- width: '37.5rem',
8466
- padding: "0"
8467
- },
8468
- visible: {
8469
- width: '3.75rem'
8470
- },
8471
- color: {
8472
- width: '4.375rem'
8473
- },
8474
- unit: {
8475
- width: '7.5rem'
8476
- },
8477
- xStats: {
8478
- // ...
8479
- }
8480
- }); });
8481
-
8482
8422
  var TagSelectionModal = function (_a) {
8483
8423
  var isOpen = _a.isOpen; _a.onClose; var onTagSelect = _a.onTagSelect;
8484
8424
  var _b = useState(true), isLoading = _b[0], setIsLoading = _b[1];
@@ -8634,10 +8574,143 @@ var AddTagModal = function (_a) {
8634
8574
  React__default.createElement(TagSelectionModal, { isOpen: open, onClose: function () { return handleClose; }, onTagSelect: onTagSelect }))))));
8635
8575
  };
8636
8576
 
8577
+ var useTagsDataTable = function (_a) {
8578
+ var cursorData = _a.cursorData, tagList = _a.tagList, chartData = _a.chartData;
8579
+ return useMemo(function () {
8580
+ // calculo y1,y2,y2y1,ymin,ymax por cada tag
8581
+ var _a;
8582
+ var dataTable = {};
8583
+ if (cursorData) {
8584
+ var _loop_1 = function (idx) {
8585
+ var tag = tagList[idx];
8586
+ var datasetForTag = ((_a = chartData.datasets.find(function (ds) { return ds.tagId === tag.tagId; })) === null || _a === void 0 ? void 0 : _a.data) || [];
8587
+ var p1 = { x: new Date('1900-01-01'), y: 0 };
8588
+ var p2 = { x: new Date('1900-01-01'), y: 0 };
8589
+ var p1Found = false;
8590
+ var pmin = { x: 0, y: Number.POSITIVE_INFINITY };
8591
+ var pmax = { x: 0, y: Number.NEGATIVE_INFINITY };
8592
+ for (var idx_1 = 0; idx_1 < datasetForTag.length; idx_1++) {
8593
+ var curr = datasetForTag[idx_1];
8594
+ var currentVal = curr.x;
8595
+ if (!p1Found) {
8596
+ if (currentVal < cursorData.x1) {
8597
+ p1 = curr;
8598
+ p2 = JSON.parse(JSON.stringify(p1));
8599
+ pmin = JSON.parse(JSON.stringify(p1));
8600
+ pmax = JSON.parse(JSON.stringify(p1));
8601
+ continue;
8602
+ }
8603
+ else {
8604
+ p1Found = true;
8605
+ }
8606
+ }
8607
+ else {
8608
+ if (currentVal < cursorData.x2) {
8609
+ p2 = curr;
8610
+ if (pmin['y'] > curr['y']) {
8611
+ pmin = JSON.parse(JSON.stringify(curr));
8612
+ }
8613
+ if (pmax['y'] < curr['y']) {
8614
+ pmax = JSON.parse(JSON.stringify(curr));
8615
+ }
8616
+ }
8617
+ else {
8618
+ break;
8619
+ }
8620
+ }
8621
+ }
8622
+ dataTable[tag.tagName] = {
8623
+ y1: p1.y,
8624
+ y2: p2.y,
8625
+ y2y1: Number(p2.y) - Number(p1.y),
8626
+ pmin: pmin,
8627
+ pmax: pmax
8628
+ };
8629
+ };
8630
+ for (var idx = 0; idx < tagList.length; idx++) {
8631
+ _loop_1(idx);
8632
+ }
8633
+ }
8634
+ return dataTable;
8635
+ }, [tagList, chartData, cursorData]);
8636
+ };
8637
+
8638
+ var useTagsTableStyles = makeStyles$1(function (theme) { return ({
8639
+ checkbox: {
8640
+ '& input[type="checkbox"]': {
8641
+ zoom: 1.5
8642
+ },
8643
+ textAlign: 'center'
8644
+ },
8645
+ rowHover: {
8646
+ '&:hover': {
8647
+ backgroundColor: "#f2f2f2"
8648
+ }
8649
+ },
8650
+ topTitles: {
8651
+ border: "0.0625rem black solid",
8652
+ borderBottom: "none",
8653
+ backgroundColor: "#e9ecef"
8654
+ },
8655
+ bottomTitlesRow: {
8656
+ '& th': {
8657
+ border: "1px black solid"
8658
+ },
8659
+ backgroundColor: "#e9ecef"
8660
+ },
8661
+ doubleInput: {
8662
+ padding: "0",
8663
+ '& input[type="text"] ': {
8664
+ width: "100%",
8665
+ height: "17px",
8666
+ display: "block",
8667
+ margin: "0",
8668
+ padding: "0"
8669
+ }
8670
+ },
8671
+ inputCol: {
8672
+ width: "11.25rem",
8673
+ overflow: 'hidden',
8674
+ textOverflow: 'ellipsis',
8675
+ whiteSpace: 'nowrap'
8676
+ },
8677
+ autoScale: {
8678
+ width: '7.5rem'
8679
+ },
8680
+ scale: {
8681
+ width: '37.5rem',
8682
+ padding: "0"
8683
+ },
8684
+ visible: {
8685
+ width: '3.75rem'
8686
+ },
8687
+ color: {
8688
+ width: '4.375rem'
8689
+ },
8690
+ unit: {
8691
+ width: '7.5rem'
8692
+ },
8693
+ xStats: {
8694
+ // ...
8695
+ }
8696
+ }); });
8697
+
8698
+ var timeDifference = function (start, end) {
8699
+ console.log(start, end);
8700
+ var differenceMilliseconds = start - end;
8701
+ var seconds = Math.floor(differenceMilliseconds / 1000);
8702
+ var minutes = Math.floor(seconds / 60);
8703
+ var hours = Math.floor(minutes / 60);
8704
+ var remainingMinutes = minutes % 60;
8705
+ var remainingSeconds = seconds % 60;
8706
+ return "".concat(hours, "h ").concat(remainingMinutes, "m ").concat(remainingSeconds, "s");
8707
+ };
8708
+
8637
8709
  var TableComponent = function (_a) {
8638
- var tagList = _a.tagList, setTagList = _a.setTagList; _a.chartData; var cursorData = _a.cursorData, onDeleteTag = _a.onDeleteTag, onAddTag = _a.onAddTag;
8710
+ var tagList = _a.tagList, setTagList = _a.setTagList, chartData = _a.chartData, cursorData = _a.cursorData, onDeleteTag = _a.onDeleteTag, onAddTag = _a.onAddTag;
8639
8711
  var classes = useTagsTableStyles();
8640
8712
  var _b = useState(""); _b[0]; _b[1];
8713
+ var dataTable = useTagsDataTable({ tagList: tagList, chartData: chartData, cursorData: cursorData });
8641
8714
  var _c = useState({}), editableTagNames = _c[0], setEditableTagNames = _c[1];
8642
8715
  var handleChange = function (index, value, property) {
8643
8716
  setTagList(function (prev) { return prev.map(function (tag, currentIndex) {
@@ -8780,7 +8853,17 @@ var TableComponent = function (_a) {
8780
8853
  second: '2-digit'
8781
8854
  });
8782
8855
  var milliseconds = date.getMilliseconds().toString().padStart(3, '0');
8783
- return "".concat(formattedDate, ".").concat(milliseconds);
8856
+ var dateText = "".concat(formattedDate, ".").concat(milliseconds);
8857
+ return (React__default.createElement(React__default.Fragment, null,
8858
+ React__default.createElement("span", { style: {
8859
+ height: '10px',
8860
+ width: '10px',
8861
+ backgroundColor: "red",
8862
+ borderRadius: '50%',
8863
+ display: 'inline-block',
8864
+ marginRight: '5px'
8865
+ } }),
8866
+ dateText));
8784
8867
  })() : null),
8785
8868
  React__default.createElement("th", { className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? (function () {
8786
8869
  var date = new Date(cursorData.x2);
@@ -8794,9 +8877,19 @@ var TableComponent = function (_a) {
8794
8877
  second: '2-digit'
8795
8878
  });
8796
8879
  var milliseconds = date.getMilliseconds().toString().padStart(3, '0');
8797
- return "".concat(formattedDate, ".").concat(milliseconds);
8880
+ var dateText = "".concat(formattedDate, ".").concat(milliseconds);
8881
+ return (React__default.createElement(React__default.Fragment, null,
8882
+ React__default.createElement("span", { style: {
8883
+ height: '10px',
8884
+ width: '10px',
8885
+ backgroundColor: "blue",
8886
+ borderRadius: '50%',
8887
+ display: 'inline-block',
8888
+ marginRight: '5px'
8889
+ } }),
8890
+ dateText));
8798
8891
  })() : null),
8799
- React__default.createElement("th", { colSpan: 3, className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, "X2-X1 Stats")))),
8892
+ React__default.createElement("th", { colSpan: 3, className: "".concat(classes.topTitles, " ").concat(classes.xStats) }, cursorData ? timeDifference(cursorData.x2, cursorData.x1) : null)))),
8800
8893
  React__default.createElement("table", { style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
8801
8894
  React__default.createElement("thead", null,
8802
8895
  React__default.createElement("tr", { className: classes.bottomTitlesRow },
@@ -8807,59 +8900,104 @@ var TableComponent = function (_a) {
8807
8900
  React__default.createElement("th", { className: classes.inputCol }, "Max Scale"),
8808
8901
  React__default.createElement("th", { className: classes.unit }, "Unit"),
8809
8902
  React__default.createElement("th", { className: classes.autoScale }, "AutoScale"),
8810
- React__default.createElement("th", null, " Y1"),
8811
- React__default.createElement("th", null, "Y2"),
8903
+ React__default.createElement("th", null, " "),
8904
+ React__default.createElement("th", null),
8812
8905
  React__default.createElement("th", null, "Y2-Y1"),
8813
8906
  React__default.createElement("th", null, "Min"),
8814
- React__default.createElement("th", null, "May")))))),
8907
+ React__default.createElement("th", null, "Max")))))),
8815
8908
  React__default.createElement(Grid$1, { item: true, xs: 12 },
8816
8909
  React__default.createElement("div", { style: { width: '100%', overflowY: 'auto', maxHeight: ' 20svh' } },
8817
8910
  React__default.createElement("table", { cellPadding: '4px', style: { width: '100%', tableLayout: 'fixed', textAlign: "center" } },
8818
- React__default.createElement("tbody", null, tagList.map(function (tag, index) { return (React__default.createElement("tr", { key: tag.tagName, onClick: function () { return handleRowClick(index); }, onContextMenu: function (e) { return handleRightClick(e, index); }, className: classes.rowHover },
8819
- React__default.createElement("td", { className: "".concat(classes.visible, " ").concat(classes.checkbox) },
8820
- React__default.createElement("input", { type: "checkbox", checked: tag.visible, onChange: function (e) { return handleVisibilityChange(index, e.target.checked); } })),
8821
- React__default.createElement("td", { className: classes.inputCol },
8822
- React__default.createElement(Tooltip, { title: tag.tagName, placement: "top", arrow: true, interactive: true, enterDelay: 500 },
8823
- React__default.createElement("div", null,
8824
- React__default.createElement("input", { type: "text", style: { width: '100%' }, value: editableTagNames[tag.tagId] || '', onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
8825
- var _a;
8826
- setEditableTagNames(__assign(__assign({}, editableTagNames), (_a = {}, _a[tag.tagId] = e.target.value, _a)));
8827
- }, onKeyDown: function (e) {
8828
- if (e.key === 'Enter') {
8829
- handleChangeAlias(tag.tagId, editableTagNames[tag.tagId]);
8830
- }
8831
- } })))),
8832
- React__default.createElement("td", { className: classes.color },
8833
- React__default.createElement(ColorPicker, { onChange: handleColorChange, color: tag.color, elementId: tag.tagId })),
8834
- React__default.createElement("td", { className: classes.inputCol },
8835
- 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) {
8836
- var value = e.target.value;
8837
- var numericValue = Number(value);
8838
- // Check if the value is a number and not empty
8839
- handleChange(index, numericValue, 'minScale');
8840
- } })),
8841
- React__default.createElement("td", { className: classes.inputCol },
8842
- 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) {
8843
- var value = e.target.value;
8844
- var numericValue = Number(value);
8845
- // Check if the value is a number and not empty
8846
- if (!isNaN(numericValue) && value.trim() !== '') {
8847
- handleChange(index, numericValue, 'maxScale');
8848
- }
8849
- } })),
8850
- React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
8851
- React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: true, value: /* tag.unit */ "Unit ", onFocus: function (e) { return e.target.select(); } })),
8852
- React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
8853
- React__default.createElement("input", { type: "checkbox", checked: tag.autoScale, onChange: function (e) { return handleAutoScaleChange(index, e.target.checked); } })),
8854
- React__default.createElement("td", null),
8855
- React__default.createElement("td", { className: classes.doubleInput }),
8856
- React__default.createElement("td", null, "y1y2"),
8857
- React__default.createElement("td", null, "min"),
8858
- React__default.createElement("td", null, "max"))); }))))),
8911
+ React__default.createElement("tbody", null, tagList.map(function (tag, index) {
8912
+ var _a, _b, _c, _d, _e, _f, _g;
8913
+ return (React__default.createElement("tr", { key: tag.tagName, onClick: function () { return handleRowClick(index); }, onContextMenu: function (e) { return handleRightClick(e, index); }, className: classes.rowHover },
8914
+ React__default.createElement("td", { className: "".concat(classes.visible, " ").concat(classes.checkbox) },
8915
+ React__default.createElement("input", { type: "checkbox", checked: tag.visible, onChange: function (e) { return handleVisibilityChange(index, e.target.checked); } })),
8916
+ React__default.createElement("td", { className: classes.inputCol },
8917
+ React__default.createElement(Tooltip, { title: tag.tagName, placement: "top", arrow: true, interactive: true, enterDelay: 500 },
8918
+ React__default.createElement("div", null,
8919
+ React__default.createElement("input", { type: "text", style: { width: '100%' }, value: editableTagNames[tag.tagId] || '', onFocus: function (e) { return e.target.select(); }, onChange: function (e) {
8920
+ var _a;
8921
+ setEditableTagNames(__assign(__assign({}, editableTagNames), (_a = {}, _a[tag.tagId] = e.target.value, _a)));
8922
+ }, onKeyDown: function (e) {
8923
+ if (e.key === 'Enter') {
8924
+ handleChangeAlias(tag.tagId, editableTagNames[tag.tagId]);
8925
+ }
8926
+ } })))),
8927
+ React__default.createElement("td", { className: classes.color },
8928
+ React__default.createElement(ColorPicker, { onChange: handleColorChange, color: tag.color, elementId: tag.tagId })),
8929
+ React__default.createElement("td", { className: classes.inputCol },
8930
+ 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) {
8931
+ var value = e.target.value;
8932
+ var numericValue = Number(value);
8933
+ // Check if the value is a number and not empty
8934
+ handleChange(index, numericValue, 'minScale');
8935
+ } })),
8936
+ React__default.createElement("td", { className: classes.inputCol },
8937
+ 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) {
8938
+ var value = e.target.value;
8939
+ var numericValue = Number(value);
8940
+ // Check if the value is a number and not empty
8941
+ if (!isNaN(numericValue) && value.trim() !== '') {
8942
+ handleChange(index, numericValue, 'maxScale');
8943
+ }
8944
+ } })),
8945
+ React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
8946
+ React__default.createElement("input", { type: "text", style: { width: '100%' }, disabled: true, value: /* tag.unit */ "Unit ", onFocus: function (e) { return e.target.select(); } })),
8947
+ React__default.createElement("td", { className: "".concat(classes.autoScale, " ").concat(classes.checkbox) },
8948
+ React__default.createElement("input", { type: "checkbox", checked: tag.autoScale, onChange: function (e) { return handleAutoScaleChange(index, e.target.checked); } })),
8949
+ React__default.createElement("td", null, (_a = dataTable[tag.tagName]) === null || _a === void 0 ? void 0 : _a.y1),
8950
+ React__default.createElement("td", { className: classes.doubleInput }, (_b = dataTable[tag.tagName]) === null || _b === void 0 ? void 0 : _b.y2),
8951
+ React__default.createElement("td", null, (_c = dataTable[tag.tagName]) === null || _c === void 0 ? void 0 : _c.y2y1),
8952
+ React__default.createElement("td", null,
8953
+ !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,
8954
+ " "),
8955
+ React__default.createElement("td", null,
8956
+ !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,
8957
+ " ")));
8958
+ }))))),
8859
8959
  selectedRowIndex !== null && (React__default.createElement(ContextMenu, { x: contextMenuPosition.x, y: contextMenuPosition.y, options: contextMenuOptions })),
8860
8960
  React__default.createElement(AddTagModal, { open: addTagModalOpen, handleClose: handleClose, onTagSelect: handleTagSelect })));
8861
8961
  };
8862
8962
 
8963
+ var DraggableLineControl = function (_a) {
8964
+ var initialLeft = _a.initialLeft, onUpdate = _a.onUpdate, color = _a.color, chartArea = _a.chartArea;
8965
+ var _b = useState(false), isDragging = _b[0], setIsDragging = _b[1];
8966
+ var _c = useState(initialLeft), left = _c[0], setLeft = _c[1];
8967
+ var ref = useRef(null);
8968
+ var handleMouseDown = function (e) {
8969
+ setIsDragging(true);
8970
+ e.stopPropagation();
8971
+ e.preventDefault();
8972
+ };
8973
+ var handleMouseMove = function (e) {
8974
+ if (!isDragging || !ref.current)
8975
+ return;
8976
+ chartArea.width - chartArea.right;
8977
+ chartArea.left;
8978
+ var newLeft = Math.min(Math.max(e.clientX - ref.current.offsetParent.getBoundingClientRect().left, chartArea.left), chartArea.right);
8979
+ setLeft(newLeft);
8980
+ onUpdate(newLeft); // Actualiza la posición de la línea en el gráfico
8981
+ };
8982
+ var handleMouseUp = function () {
8983
+ setIsDragging(false);
8984
+ };
8985
+ useEffect(function () {
8986
+ var mouseMoveHandler = function (e) { return handleMouseMove(e); };
8987
+ var mouseUpHandler = function () { return handleMouseUp(); };
8988
+ if (isDragging) {
8989
+ window.addEventListener('mousemove', mouseMoveHandler);
8990
+ window.addEventListener('mouseup', mouseUpHandler);
8991
+ }
8992
+ return function () {
8993
+ window.removeEventListener('mousemove', mouseMoveHandler);
8994
+ window.removeEventListener('mouseup', mouseUpHandler);
8995
+ };
8996
+ }, [isDragging]);
8997
+ return (React__default.createElement("div", { ref: ref, style: { height: 20, width: 20, background: color, position: 'absolute', top: -10, left: left - 10 }, onMouseDown: handleMouseDown },
8998
+ React__default.createElement("div", { style: { height: chartArea.height, width: 2, background: color, position: 'relative', top: 20, left: 0, right: 0, margin: 'auto' } })));
8999
+ };
9000
+
8863
9001
  var TrendingsInitialState = {
8864
9002
  timeScopeStart: moment(new Date()).subtract(1, "days").toDate(),
8865
9003
  timeScopeEnd: new Date(),
@@ -9102,57 +9240,36 @@ var CustomOptionsComponent = function (_a) {
9102
9240
  "Stepped"))));
9103
9241
  };
9104
9242
 
9105
- var DraggableLineControl = function (_a) {
9106
- var initialLeft = _a.initialLeft, onUpdate = _a.onUpdate, color = _a.color, chartArea = _a.chartArea;
9107
- var _b = useState(false), isDragging = _b[0], setIsDragging = _b[1];
9108
- var _c = useState(initialLeft), left = _c[0], setLeft = _c[1];
9109
- var ref = useRef(null);
9110
- var handleMouseDown = function (e) {
9111
- setIsDragging(true);
9112
- e.stopPropagation();
9113
- e.preventDefault();
9114
- };
9115
- var handleMouseMove = function (e) {
9116
- if (!isDragging || !ref.current)
9117
- return;
9118
- chartArea.width - chartArea.right;
9119
- chartArea.left;
9120
- var newLeft = Math.min(Math.max(e.clientX - ref.current.offsetParent.getBoundingClientRect().left, chartArea.left), chartArea.right);
9121
- setLeft(newLeft);
9122
- onUpdate(newLeft); // Actualiza la posición de la línea en el gráfico
9123
- };
9124
- var handleMouseUp = function () {
9125
- setIsDragging(false);
9126
- };
9127
- useEffect(function () {
9128
- var mouseMoveHandler = function (e) { return handleMouseMove(e); };
9129
- var mouseUpHandler = function () { return handleMouseUp(); };
9130
- if (isDragging) {
9131
- window.addEventListener('mousemove', mouseMoveHandler);
9132
- window.addEventListener('mouseup', mouseUpHandler);
9243
+ var useGetVerticalLinePlugin = function (setChartArea, setCoords) {
9244
+ return {
9245
+ id: "verticalLinePlugin",
9246
+ afterUpdate: function (chart) {
9247
+ if (chart.chartArea) {
9248
+ // console.log("after update");
9249
+ if (chart.mouseX === null) {
9250
+ chart.mouseX = chart.chartArea.left + (chart.chartArea.width / 10);
9251
+ // chart.mouseX = chart.chartArea.left + 30.9
9252
+ }
9253
+ if (chart.secondLineX === null) {
9254
+ chart.secondLineX = chart.chartArea.left + (chart.chartArea.width * 0.90);
9255
+ // chart.secondLineX = chart.chartArea.right
9256
+ }
9257
+ }
9258
+ },
9259
+ beforeInit: function (chart) {
9260
+ chart.mouseX = null;
9261
+ chart.secondLineX = null;
9262
+ },
9263
+ afterDatasetsDraw: function (chart) {
9264
+ var x1 = chart.mouseX;
9265
+ var x2 = chart.secondLineX;
9266
+ setChartArea(chart.chartArea);
9267
+ setCoords({ x1: x1, x2: x2 });
9133
9268
  }
9134
- return function () {
9135
- window.removeEventListener('mousemove', mouseMoveHandler);
9136
- window.removeEventListener('mouseup', mouseUpHandler);
9137
- };
9138
- }, [isDragging]);
9139
- return (React__default.createElement("div", { ref: ref, style: { height: 20, width: 20, background: color, position: 'absolute', top: -10, left: left - 10 }, onMouseDown: handleMouseDown },
9140
- React__default.createElement("div", { style: { height: chartArea.height, width: 2, background: color, position: 'relative', top: 20, left: 0, right: 0, margin: 'auto' } })));
9141
- };
9142
-
9143
- var dateNavigator = function (startDate, endDate, scope, operator) {
9144
- if (scope === "custom")
9145
- return;
9146
- else {
9147
- var _a = scope.split(" "), quantity = _a[0], duration = _a[1];
9148
- var newStartDate = moment(startDate)[operator](quantity, duration[0]).toDate();
9149
- var newEndDate = moment(endDate)[operator](quantity, duration[0]).toDate();
9150
- return { newStartDate: newStartDate, newEndDate: newEndDate };
9151
- }
9269
+ };
9152
9270
  };
9153
9271
 
9154
- Chart.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip$1, Legend, TimeScale, zoomPlugin);
9155
- function getValuesAtCursor(chart, timeAtCursor) {
9272
+ var getValuesAtCursor = function (chart, timeAtCursor) {
9156
9273
  var valuesAtCursor = [];
9157
9274
  chart.data.datasets.forEach(function (dataset) {
9158
9275
  var previousDataPoint = null;
@@ -9169,15 +9286,13 @@ function getValuesAtCursor(chart, timeAtCursor) {
9169
9286
  }
9170
9287
  });
9171
9288
  return valuesAtCursor;
9172
- }
9173
- function updateCursorData(chart, setCursorData) {
9289
+ };
9290
+ var updateCursorData = function (chart, setCursorData) {
9174
9291
  var xScale = chart.scales.x;
9175
- chart.scales.y;
9176
- // Coordenadas para la primera línea
9292
+ // Coordenadas para la primera y segunda línea
9177
9293
  var timeAtCursor1 = xScale.getValueForPixel(chart.mouseX);
9178
- // Coordenadas para la segunda línea
9179
9294
  var timeAtCursor2 = xScale.getValueForPixel(chart.secondLineX);
9180
- // Los valores en el punto del cursor pueden ser diferentes para cada línea si corresponden a diferentes series de datos
9295
+ // Los valores en el punto del cursor pueden ser diferentes
9181
9296
  var valuesAtCursor1 = getValuesAtCursor(chart, timeAtCursor1);
9182
9297
  var valuesAtCursor2 = getValuesAtCursor(chart, timeAtCursor2);
9183
9298
  setCursorData({
@@ -9185,51 +9300,74 @@ function updateCursorData(chart, setCursorData) {
9185
9300
  x2: timeAtCursor2,
9186
9301
  values: __spreadArray(__spreadArray([], valuesAtCursor1, true), valuesAtCursor2, true)
9187
9302
  });
9188
- }
9189
- function getVerticalLinePlugin(setChartArea, setCoords) {
9190
- return {
9191
- id: "verticalLinePlugin",
9192
- afterUpdate: function (chart) {
9193
- if (chart.secondLineX === null) {
9194
- chart.secondLineX = chart.scales.x.left + (chart.scales.x.width * 0.75);
9195
- }
9196
- if (chart.mouseX === null) {
9197
- chart.mouseX = chart.scales.x.left + (chart.scales.x.width / 4);
9198
- }
9199
- },
9200
- beforeInit: function (chart) {
9201
- chart.mouseX = null;
9202
- chart.secondLineX = null;
9203
- },
9204
- afterDatasetsDraw: function (chart) {
9205
- var x1 = chart.mouseX;
9206
- var x2 = chart.secondLineX;
9207
- setChartArea(chart.chartArea);
9208
- setCoords({ x1: x1, x2: x2 });
9209
- }
9210
- };
9211
- }
9303
+ };
9304
+
9305
+ var areRangesSimilar = function (tag1, tag2) {
9306
+ var range1 = tag1.maxScale - tag1.minScale; // Rango de la primera etiqueta
9307
+ var range2 = tag2.maxScale - tag2.minScale; // Rango de la segunda etiqueta
9308
+ // Determina los límites para la comparación
9309
+ var lowerBound = Math.max(tag1.minScale, tag2.minScale);
9310
+ var upperBound = Math.min(tag1.maxScale, tag2.maxScale);
9311
+ // Calcula el solapamiento entre los dos rangos
9312
+ var overlap = Math.max(0, upperBound - lowerBound);
9313
+ // Determina si el solapamiento es significativo comparado con los rangos individuales
9314
+ var isSignificantOverlap = (overlap / range1 > 0.5) && (overlap / range2 > 0.5);
9315
+ return isSignificantOverlap;
9316
+ };
9317
+
9318
+ var calculateScales = function (min, max, sigDigits) {
9319
+ var roundToSignificantDigits = function (num) {
9320
+ if (num === 0)
9321
+ return 0;
9322
+ var multiplier = Math.pow(10, sigDigits - Math.floor(Math.log10(Math.abs(num))) - 1);
9323
+ return Math.round(num * multiplier) / multiplier;
9324
+ };
9325
+ var minScale = roundToSignificantDigits(min);
9326
+ var maxScale = roundToSignificantDigits(max);
9327
+ // Adjust minScale and maxScale if necessary
9328
+ if (minScale > min) {
9329
+ minScale *= 0.9;
9330
+ }
9331
+ if (maxScale < max) {
9332
+ maxScale *= 1.1;
9333
+ }
9334
+ return { minScale: minScale, maxScale: maxScale };
9335
+ };
9336
+
9337
+ var dateNavigator = function (startDate, endDate, scope, operator) {
9338
+ if (scope === "custom")
9339
+ return;
9340
+ else {
9341
+ var _a = scope.split(" "), quantity = _a[0], duration = _a[1];
9342
+ var newStartDate = moment(startDate)[operator](quantity, duration[0]).toDate();
9343
+ var newEndDate = moment(endDate)[operator](quantity, duration[0]).toDate();
9344
+ return { newStartDate: newStartDate, newEndDate: newEndDate };
9345
+ }
9346
+ };
9347
+
9348
+ Chart.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip$1, Legend, TimeScale, zoomPlugin);
9212
9349
  var Trending = function (_a) {
9213
9350
  _a.title; var tags = _a.tags;
9351
+ var classes = useTrendingStyles();
9214
9352
  var _b = useTrendingContext(), state = _b.state, actions = _b.actions;
9353
+ var _c = useState(true), loading = _c[0], setLoading = _c[1];
9354
+ var _d = useState(""), error = _d[0], setError = _d[1];
9355
+ var _e = useState(tags), tagList = _e[0], setTagList = _e[1];
9356
+ var _f = useState(null), cursorData = _f[0], setCursorData = _f[1];
9357
+ var _g = useState(null), lineTabCoords = _g[0], setLineTabCoords = _g[1];
9358
+ var _h = useState(null), chartArea = _h[0], setChartArea = _h[1];
9359
+ var _j = useState(false), chartShouldInitCursors = _j[0], setChartShouldInitCursors = _j[1];
9215
9360
  var chartRef = useRef(null);
9216
- var _c = useState({
9361
+ var _k = useState({
9217
9362
  labels: [],
9218
9363
  datasets: []
9219
- }), chartData = _c[0], setChartData = _c[1];
9220
- var _d = useState(null), lineTabCoords = _d[0], setLineTabCoords = _d[1];
9221
- var _e = useState(null), chartArea = _e[0], setChartArea = _e[1];
9222
- var _f = useState(tags), tagList = _f[0], setTagList = _f[1];
9223
- var _g = useState(null), cursorData = _g[0], setCursorData = _g[1];
9224
- var verticalLinePlugin = getVerticalLinePlugin(setChartArea, setLineTabCoords);
9225
- var _h = useState({
9364
+ }), chartData = _k[0], setChartData = _k[1];
9365
+ var verticalLinePlugin = useGetVerticalLinePlugin(setChartArea, setLineTabCoords);
9366
+ var _l = useState({
9226
9367
  showGrid: true,
9227
9368
  stepped: false
9228
- }), customOptions = _h[0], setCustomOptions = _h[1];
9229
- var _j = useState(true), loading = _j[0], setLoading = _j[1];
9230
- var _k = useState(""), error = _k[0], setError = _k[1];
9369
+ }), customOptions = _l[0], setCustomOptions = _l[1];
9231
9370
  var debounceTimerRef = useRef(null);
9232
- var classes = useTrendingStyles();
9233
9371
  var debouncedUpdateChart = useRef(debounce(function () {
9234
9372
  if (chartRef.current) {
9235
9373
  updateCursorData(chartRef.current, setCursorData);
@@ -9300,7 +9438,7 @@ var Trending = function (_a) {
9300
9438
  actions.setTotalScope({ start: newDates.newStartDate, end: newDates.newEndDate, scope: state.scope });
9301
9439
  }
9302
9440
  };
9303
- var _l = useState({
9441
+ var _m = useState({
9304
9442
  animation: {
9305
9443
  duration: 0
9306
9444
  },
@@ -9369,7 +9507,7 @@ var Trending = function (_a) {
9369
9507
  }
9370
9508
  }
9371
9509
  }
9372
- }), chartOptions = _l[0], setChartOptions = _l[1];
9510
+ }), chartOptions = _m[0], setChartOptions = _m[1];
9373
9511
  useEffect(function () {
9374
9512
  var fetchData = function () { return __awaiter(void 0, void 0, void 0, function () {
9375
9513
  var tagIds, response, series_1, axes_1, updatedSeries, error_1;
@@ -9434,11 +9572,13 @@ var Trending = function (_a) {
9434
9572
  x: new Date(sample.timestamp),
9435
9573
  y: sample.value
9436
9574
  }); }),
9575
+ tagId: tag.tagId,
9437
9576
  borderColor: tag.color,
9438
9577
  hidden: !tag.visible,
9439
9578
  pointRadius: serie.length <= 50 ? 3 : 0
9440
9579
  };
9441
9580
  });
9581
+ setChartShouldInitCursors(true);
9442
9582
  setChartData({
9443
9583
  labels: [],
9444
9584
  datasets: updatedSeries
@@ -9459,7 +9599,7 @@ var Trending = function (_a) {
9459
9599
  }, [JSON.stringify(state), tagList]);
9460
9600
  useEffect(function () {
9461
9601
  var changeOptions = function () {
9462
- console.log("change options");
9602
+ // console.log("change options");
9463
9603
  setChartOptions(function (prevOptions) { return (__assign(__assign({}, prevOptions), { elements: {
9464
9604
  line: {
9465
9605
  stepped: customOptions.stepped,
@@ -9469,36 +9609,6 @@ var Trending = function (_a) {
9469
9609
  };
9470
9610
  changeOptions();
9471
9611
  }, [customOptions]);
9472
- function areRangesSimilar(tag1, tag2) {
9473
- var range1 = tag1.maxScale - tag1.minScale; // Rango de la primera etiqueta
9474
- var range2 = tag2.maxScale - tag2.minScale; // Rango de la segunda etiqueta
9475
- // Determina los límites para la comparación
9476
- var lowerBound = Math.max(tag1.minScale, tag2.minScale);
9477
- var upperBound = Math.min(tag1.maxScale, tag2.maxScale);
9478
- // Calcula el solapamiento entre los dos rangos
9479
- var overlap = Math.max(0, upperBound - lowerBound);
9480
- // Determina si el solapamiento es significativo comparado con los rangos individuales
9481
- var isSignificantOverlap = (overlap / range1 > 0.5) && (overlap / range2 > 0.5);
9482
- return isSignificantOverlap;
9483
- }
9484
- function calculateScales(min, max, sigDigits) {
9485
- var roundToSignificantDigits = function (num) {
9486
- if (num === 0)
9487
- return 0;
9488
- var multiplier = Math.pow(10, sigDigits - Math.floor(Math.log10(Math.abs(num))) - 1);
9489
- return Math.round(num * multiplier) / multiplier;
9490
- };
9491
- var minScale = roundToSignificantDigits(min);
9492
- var maxScale = roundToSignificantDigits(max);
9493
- // Adjust minScale and maxScale if necessary
9494
- if (minScale > min) {
9495
- minScale *= 0.9;
9496
- }
9497
- if (maxScale < max) {
9498
- maxScale *= 1.1;
9499
- }
9500
- return { minScale: minScale, maxScale: maxScale };
9501
- }
9502
9612
  if (error)
9503
9613
  return React__default.createElement("p", null,
9504
9614
  "Error: ",
@@ -9506,6 +9616,14 @@ var Trending = function (_a) {
9506
9616
  useEffect(function () {
9507
9617
  setChartOptions(function (prevOptions) { return (__assign(__assign({}, prevOptions), { scales: __assign(__assign({}, prevOptions.scales), { x: __assign(__assign({}, prevOptions.scales.x), { min: state.timeScopeStart.getTime(), max: state.timeScopeEnd.getTime() }) }) })); });
9508
9618
  }, [state.timeScopeStart, state.timeScopeEnd]);
9619
+ useEffect(function () {
9620
+ if (chartShouldInitCursors) {
9621
+ if (chartRef.current) {
9622
+ updateCursorData(chartRef.current, setCursorData);
9623
+ chartRef.current.update();
9624
+ }
9625
+ }
9626
+ }, [chartShouldInitCursors, state]);
9509
9627
  return (React__default.createElement(Grid$1, { container: true, style: { width: "95svw", height: "81svh", margin: 0 } },
9510
9628
  React__default.createElement(Grid$1, { item: true, xs: 12, container: true, justifyContent: "space-between", alignItems: "center", style: { height: "15%" } },
9511
9629
  React__default.createElement(Grid$1, { md: 5, item: true, container: true, justifyContent: "flex-start", alignItems: "center", spacing: 1, wrap: "wrap" },
@@ -1,7 +1,7 @@
1
+ import { ChartData } from 'chart.js';
1
2
  import React from 'react';
2
3
  import './ContextMenu.css';
3
- import { CursorData, TagList } from './Trending';
4
- import { ChartData } from 'chart.js';
4
+ import { CursorData, TagList } from './models/TrendingModels';
5
5
  interface TableComponentProps {
6
6
  tagList: TagList;
7
7
  setTagList: React.Dispatch<React.SetStateAction<TagList>>;
@@ -1,37 +1,9 @@
1
1
  import "chartjs-adapter-moment/dist/chartjs-adapter-moment.esm.js";
2
2
  import React from "react";
3
+ import { Tag } from "./models/TrendingModels";
3
4
  interface TrendingProps {
4
5
  title: string;
5
6
  tags: Tag[];
6
7
  }
7
- interface Sample {
8
- timestamp: number;
9
- value: number;
10
- }
11
- export type SampleArray = Sample[][];
12
- export interface Tag {
13
- tagId: number;
14
- tagName: string;
15
- tagType: string;
16
- color: string;
17
- autoScale: boolean;
18
- minScale: number;
19
- maxScale: number;
20
- visible: boolean;
21
- }
22
- export interface CursorData {
23
- x1: Date;
24
- x2: Date;
25
- values: number[];
26
- }
27
- export interface LineCoords {
28
- x1: number;
29
- x2: number;
30
- }
31
- export interface CustomOptions {
32
- showGrid: boolean;
33
- stepped: boolean;
34
- }
35
- export type TagList = Tag[];
36
8
  declare const Trending: React.FC<TrendingProps>;
37
9
  export default Trending;
@@ -0,0 +1,11 @@
1
+ import { ChartData } from 'chart.js';
2
+ import React from 'react';
3
+ import { Tag } from '../models/TrendingModels';
4
+ interface Props {
5
+ tag: Tag;
6
+ chartData: ChartData;
7
+ index: number;
8
+ limitX: number;
9
+ }
10
+ export declare const CellComponent: ({ tag, chartData, index, limitX }: Props) => React.JSX.Element;
11
+ export {};
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { Tag } from '../../../Trending';
2
+ import { Tag } from '../../../models/TrendingModels';
3
3
  interface Props {
4
4
  open: boolean;
5
5
  handleClose: () => void;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { Tag } from "../../../Trending";
2
+ import { Tag } from "../../../models/TrendingModels";
3
3
  interface TagSelectionModalProps {
4
4
  isOpen: boolean;
5
5
  onClose: () => void;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { CustomOptions } from "./Trending";
2
+ import { CustomOptions } from "./models/TrendingModels";
3
3
  interface CustomOptionsComponentProps {
4
4
  customOptions: CustomOptions;
5
5
  setCustomOptions: React.Dispatch<React.SetStateAction<CustomOptions>>;
@@ -0,0 +1,2 @@
1
+ import { Plugin } from 'chart.js';
2
+ export declare const useGetVerticalLinePlugin: (setChartArea: (param: any) => void, setCoords: any) => Plugin;
@@ -0,0 +1,24 @@
1
+ import { ChartData } from "chart.js";
2
+ import { CursorData, TagList } from "../models/TrendingModels";
3
+ interface Props {
4
+ cursorData: CursorData;
5
+ tagList: TagList;
6
+ chartData: ChartData;
7
+ }
8
+ interface TagsDataTable {
9
+ [tagName: string]: {
10
+ y1: number;
11
+ y2: number;
12
+ y2y1: number;
13
+ pmin: {
14
+ x: number | Date;
15
+ y: number;
16
+ };
17
+ pmax: {
18
+ x: number | Date;
19
+ y: number;
20
+ };
21
+ };
22
+ }
23
+ export declare const useTagsDataTable: ({ cursorData, tagList, chartData }: Props) => TagsDataTable;
24
+ export {};
@@ -0,0 +1,2 @@
1
+ import { CursorData } from '../models/TrendingModels';
2
+ export declare const updateCursorData: (chart: any, setCursorData: (cursorData: CursorData) => void) => void;
@@ -0,0 +1,33 @@
1
+ export interface TimeScope {
2
+ start: Date;
3
+ end: Date;
4
+ }
5
+ export interface Sample {
6
+ timestamp: number;
7
+ value: number;
8
+ }
9
+ export type SampleArray = Sample[][];
10
+ export interface Tag {
11
+ tagId: number;
12
+ tagName: string;
13
+ tagType: string;
14
+ color: string;
15
+ autoScale: boolean;
16
+ minScale: number;
17
+ maxScale: number;
18
+ visible: boolean;
19
+ }
20
+ export interface CursorData {
21
+ x1: Date;
22
+ x2: Date;
23
+ values: number[];
24
+ }
25
+ export interface LineCoords {
26
+ x1: number;
27
+ x2: number;
28
+ }
29
+ export interface CustomOptions {
30
+ showGrid: boolean;
31
+ stepped: boolean;
32
+ }
33
+ export type TagList = Tag[];
@@ -1,3 +1,5 @@
1
+ import { TagList } from "../models/TrendingModels";
2
+ export declare const fetchDataFunction: (tagList: TagList[], state: any, actions: any) => Promise<void>;
1
3
  export declare const getTags: (NodeName: string | null) => Promise<import("../../../../../services").ResponseMESF>;
2
4
  export declare const getSeriesData: (TagIds: string, Start: number | null, End: number | null, SampleCount: number) => Promise<import("../../../../../services").ResponseMESF>;
3
5
  export declare const saveTagDefaults: (TagId: number, Alias: string, Color: string, MinScale: number, MaxScale: number, Unit: string) => Promise<import("../../../../../services").ResponseMESF>;
@@ -0,0 +1,2 @@
1
+ import { Tag } from "../models/TrendingModels";
2
+ export declare const areRangesSimilar: (tag1: Tag, tag2: Tag) => boolean;
@@ -0,0 +1,4 @@
1
+ export declare const calculateScales: (min: any, max: any, sigDigits: any) => {
2
+ minScale: number;
3
+ maxScale: number;
4
+ };
@@ -0,0 +1 @@
1
+ export declare const timeDifference: (start: number, end: number) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexteel/mesf-core",
3
- "version": "4.5.7",
3
+ "version": "4.5.8",
4
4
  "author": "Dexteel Team",
5
5
  "module": "dist/index.esm.js",
6
6
  "typings": "dist/index.d.ts",