tsichart-core 1.0.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 (126) hide show
  1. package/LICENSE +22 -0
  2. package/README.MD +189 -0
  3. package/dist/AggregateExpression.d.ts +13 -0
  4. package/dist/AggregateExpression.js +70 -0
  5. package/dist/AvailabilityChart-i_efwXCX.js +488 -0
  6. package/dist/AvailabilityChart.d.ts +59 -0
  7. package/dist/AvailabilityChart.js +26 -0
  8. package/dist/ChartComponent-DTcc6aED.d.ts +80 -0
  9. package/dist/ChartComponent-DnKLTxWe.js +302 -0
  10. package/dist/ChartComponentData-D5wuQmmZ.d.ts +47 -0
  11. package/dist/ChartDataOptions-DBS28b1-.d.ts +38 -0
  12. package/dist/ChartDataOptions-DRd8NHra.js +49 -0
  13. package/dist/ChartVisualizationComponent-CG7e5xlc.js +23 -0
  14. package/dist/ChartVisualizationComponent-DBjiqR1n.d.ts +8 -0
  15. package/dist/ColorPicker-CH__K8xm.js +120 -0
  16. package/dist/ColorPicker.d.ts +28 -0
  17. package/dist/ColorPicker.js +6 -0
  18. package/dist/Component-CofgyEw0.js +401 -0
  19. package/dist/Component-Rp30sSAW.d.ts +226 -0
  20. package/dist/ContextMenu-DABSkTA2.js +197 -0
  21. package/dist/DateTimeButton-CMcCxc8x.d.ts +16 -0
  22. package/dist/DateTimeButton-Ca1487GR.js +38 -0
  23. package/dist/DateTimeButtonRange-DpgfhHQt.js +71 -0
  24. package/dist/DateTimeButtonRange.d.ts +19 -0
  25. package/dist/DateTimeButtonRange.js +15 -0
  26. package/dist/DateTimeButtonSingle-C6cTx5VO.js +48 -0
  27. package/dist/DateTimeButtonSingle.d.ts +17 -0
  28. package/dist/DateTimeButtonSingle.js +14 -0
  29. package/dist/DateTimePicker-BH6qiVfQ.js +532 -0
  30. package/dist/DateTimePicker.d.ts +69 -0
  31. package/dist/DateTimePicker.js +13 -0
  32. package/dist/EllipsisMenu-30FNqoIv.js +116 -0
  33. package/dist/EllipsisMenu.d.ts +20 -0
  34. package/dist/EllipsisMenu.js +6 -0
  35. package/dist/Enums-ChUuTtHV.d.ts +12 -0
  36. package/dist/EventsTable-a0XLbsMF.js +553 -0
  37. package/dist/EventsTable.d.ts +34 -0
  38. package/dist/EventsTable.js +10 -0
  39. package/dist/GeoProcessGraphic-AVAzyF7k.js +145 -0
  40. package/dist/GeoProcessGraphic.d.ts +34 -0
  41. package/dist/GeoProcessGraphic.js +7 -0
  42. package/dist/Grid-DfFAkeeV.js +874 -0
  43. package/dist/Grid.d.ts +43 -0
  44. package/dist/Grid.js +6 -0
  45. package/dist/GroupedBarChart-BspwM8r2.js +579 -0
  46. package/dist/GroupedBarChart.d.ts +22 -0
  47. package/dist/GroupedBarChart.js +17 -0
  48. package/dist/GroupedBarChartData-BRCyDxbA.js +121 -0
  49. package/dist/GroupedBarChartData-C0YQydrP.d.ts +20 -0
  50. package/dist/Heatmap-D8ET8Ue8.js +524 -0
  51. package/dist/Heatmap.d.ts +31 -0
  52. package/dist/Heatmap.js +14 -0
  53. package/dist/Hierarchy-QkWLHkxo.js +260 -0
  54. package/dist/Hierarchy.d.ts +39 -0
  55. package/dist/Hierarchy.js +6 -0
  56. package/dist/HierarchyNavigation-CR6YUilh.js +336 -0
  57. package/dist/HierarchyNavigation.d.ts +34 -0
  58. package/dist/HierarchyNavigation.js +6 -0
  59. package/dist/HistoryPlayback-BmA-54lT.d.ts +68 -0
  60. package/dist/HistoryPlayback-SjeQbAPq.js +175 -0
  61. package/dist/Interfaces-BKRQ685G.d.ts +6 -0
  62. package/dist/Legend-DlSXQXHF.js +497 -0
  63. package/dist/LineChart-CExEyjZa.js +3181 -0
  64. package/dist/LineChart.d.ts +163 -0
  65. package/dist/LineChart.js +18 -0
  66. package/dist/ModelAutocomplete-TRD16egq.js +100 -0
  67. package/dist/ModelAutocomplete.d.ts +12 -0
  68. package/dist/ModelAutocomplete.js +7 -0
  69. package/dist/ModelSearch-WEa7Ud20.js +189 -0
  70. package/dist/ModelSearch.d.ts +23 -0
  71. package/dist/ModelSearch.js +9 -0
  72. package/dist/PieChart-B1ZXk13Q.js +258 -0
  73. package/dist/PieChart.d.ts +26 -0
  74. package/dist/PieChart.js +17 -0
  75. package/dist/PlaybackControls-Dwt6dif9.js +195 -0
  76. package/dist/PlaybackControls.d.ts +39 -0
  77. package/dist/PlaybackControls.js +13 -0
  78. package/dist/ProcessGraphic-CixT-zZl.js +154 -0
  79. package/dist/ProcessGraphic.d.ts +31 -0
  80. package/dist/ProcessGraphic.js +7 -0
  81. package/dist/README.MD +189 -0
  82. package/dist/ScatterPlot-DrPoHNDJ.js +924 -0
  83. package/dist/ScatterPlot.d.ts +115 -0
  84. package/dist/ScatterPlot.js +17 -0
  85. package/dist/SingleDateTimePicker-7anflEq8.js +213 -0
  86. package/dist/SingleDateTimePicker.d.ts +45 -0
  87. package/dist/SingleDateTimePicker.js +12 -0
  88. package/dist/Slider-BtSdC4fj.js +186 -0
  89. package/dist/Slider.d.ts +31 -0
  90. package/dist/Slider.js +6 -0
  91. package/dist/TemporalXAxisComponent-CyiM5EH0.d.ts +23 -0
  92. package/dist/TemporalXAxisComponent-DkyVvASs.js +129 -0
  93. package/dist/TimezonePicker-ClfP1lBL.js +58 -0
  94. package/dist/TimezonePicker.d.ts +16 -0
  95. package/dist/TimezonePicker.js +10 -0
  96. package/dist/Tooltip-Fa-0Xekn.js +104 -0
  97. package/dist/TsqExpression.d.ts +36 -0
  98. package/dist/TsqExpression.js +89 -0
  99. package/dist/UXClient-DydSPZwM.js +230 -0
  100. package/dist/UXClient.d.ts +74 -0
  101. package/dist/UXClient.js +47 -0
  102. package/dist/Utils-BsPLzJBC.d.ts +104 -0
  103. package/dist/Utils-C_j8IgZh.js +1138 -0
  104. package/dist/Utils.d.ts +7 -0
  105. package/dist/Utils.js +7 -0
  106. package/dist/_tslib-5_9pMg1F.js +96 -0
  107. package/dist/package.json +106 -0
  108. package/dist/pikaday-DMSzaLH6.js +1252 -0
  109. package/dist/tsiclient.cjs.js +3 -0
  110. package/dist/tsiclient.cjs.js.LICENSE.txt +19 -0
  111. package/dist/tsiclient.cjs.js.map +1 -0
  112. package/dist/tsiclient.css +17323 -0
  113. package/dist/tsiclient.d.ts +46 -0
  114. package/dist/tsiclient.esm.js +3 -0
  115. package/dist/tsiclient.esm.js.LICENSE.txt +19 -0
  116. package/dist/tsiclient.esm.js.map +1 -0
  117. package/dist/tsiclient.js +58 -0
  118. package/dist/tsiclient.min.css +6 -0
  119. package/dist/tsiclient.min.css.map +1 -0
  120. package/dist/tsiclient.umd.js +3 -0
  121. package/dist/tsiclient.umd.js.LICENSE.txt +19 -0
  122. package/dist/tsiclient.umd.js.map +1 -0
  123. package/dist/tsiclient.umd.min.js +3 -0
  124. package/dist/tsiclient.umd.min.js.LICENSE.txt +19 -0
  125. package/dist/tsiclient.umd.min.js.map +1 -0
  126. package/package.json +106 -0
@@ -0,0 +1,260 @@
1
+ import { _ as __extends } from './_tslib-5_9pMg1F.js';
2
+ import * as d3 from 'd3';
3
+ import { U as Utils } from './Utils-C_j8IgZh.js';
4
+ import { C as Component } from './Component-CofgyEw0.js';
5
+
6
+ var HierarchyNode = /** @class */ (function () {
7
+ function HierarchyNode(name, level) {
8
+ this.children = [];
9
+ this.isExpanded = false;
10
+ this.isSelected = false;
11
+ this.isLeaf = false;
12
+ this.childrenInFilter = false;
13
+ this.selfInFilter = false;
14
+ this.color = function () { return null; };
15
+ this.click = function (n) { };
16
+ this.isLeafParent = false; // used in the event of context menut to denote that we should use a context menu for children
17
+ this.name = name;
18
+ this.level = level;
19
+ this.markedName = name;
20
+ }
21
+ HierarchyNode.prototype.filter = function (filterText) {
22
+ var regExp = new RegExp(filterText, 'i');
23
+ var isInFilter = function (node) {
24
+ var childrenInFilter = node.children.reduce(function (p, c) {
25
+ p = isInFilter(c) || p;
26
+ return p;
27
+ }, false);
28
+ var selfInFilter = regExp.test(node.name);
29
+ node.markedName = selfInFilter ? Utils.mark(filterText, node.name) : node.name;
30
+ if (node.parent != null)
31
+ node.parent.childrenInFilter = (selfInFilter || childrenInFilter) && filterText.length > 0;
32
+ node.selfInFilter = selfInFilter && filterText.length > 0;
33
+ node.childrenInFilter = childrenInFilter && filterText.length > 0;
34
+ return childrenInFilter || selfInFilter;
35
+ };
36
+ isInFilter(this);
37
+ };
38
+ HierarchyNode.prototype.traverse = function (condition) {
39
+ var traversal = [];
40
+ if (condition(this))
41
+ traversal.push(this);
42
+ this.children.forEach(function (n) {
43
+ traversal = traversal.concat(n.traverse(condition));
44
+ });
45
+ return traversal;
46
+ };
47
+ HierarchyNode.prototype.colorify = function (el) {
48
+ if (this.isLeaf && this.isSelected && this.color(this))
49
+ el.style('background-color', this.color(this));
50
+ if (!this.isSelected && this.isLeaf)
51
+ el.style('background-color', null);
52
+ };
53
+ return HierarchyNode;
54
+ }());
55
+
56
+ var Hierarchy = /** @class */ (function (_super) {
57
+ __extends(Hierarchy, _super);
58
+ function Hierarchy(renderTarget) {
59
+ var _this = _super.call(this, renderTarget) || this;
60
+ _this.filterText = '';
61
+ _this.withContextMenu = false;
62
+ _this.expandCollapseList = function (node, el, isFromClick, event) {
63
+ if (isFromClick === void 0) { isFromClick = false; }
64
+ _this.closeContextMenu();
65
+ if (el.classed('tsi-expanded') && !(_this.withContextMenu && node.isLeafParent)) {
66
+ el.selectAll('ul').remove();
67
+ el.classed('tsi-expanded', false);
68
+ node.isExpanded = false;
69
+ }
70
+ else {
71
+ if (_this.withContextMenu && node.isLeafParent) {
72
+ if (_this.clickedNode != el.node()) {
73
+ _this.clickedNode = el.node();
74
+ _this.contextMenu = _this.hierarchyList.append('div');
75
+ node.children.filter(function (n) { return n.name[0] !== '~'; }).forEach(function (n) {
76
+ _this.contextMenu.append('div').text("".concat(n.name)).on('click', function () { return n.click(n); });
77
+ });
78
+ _this.contextMenu.append('div').classed('tsi-break', true);
79
+ node.children.filter(function (n) { return n.name[0] === '~'; }).forEach(function (n) {
80
+ var noTildeName = n.name.slice(1);
81
+ _this.contextMenu.append('div').text("".concat(noTildeName)).on('click', function () { return n.click(n); });
82
+ });
83
+ _this.contextMenu.classed('tsi-hierarchyContextMenu', true);
84
+ if (event) {
85
+ var mouseWrapper_1 = d3.pointer(event, _this.hierarchyList.node());
86
+ var mouseElt_1 = d3.pointer(event, el.node());
87
+ _this.contextMenu.attr('style', function () { return "top: ".concat(mouseWrapper_1[1] - mouseElt_1[1], "px"); });
88
+ }
89
+ el.classed('tsi-resultSelected', true);
90
+ _this.hierarchyList.selectAll('.tsi-noPad').on('scroll', function () { _this.closeContextMenu(); });
91
+ }
92
+ else {
93
+ _this.clickedNode = null;
94
+ }
95
+ }
96
+ else {
97
+ var list = el.append('ul');
98
+ node.children.forEach(function (n) {
99
+ if (isFromClick || n.selfInFilter || n.childrenInFilter || (node.isExpanded && _this.filterText.length == 0)) {
100
+ var self = _this;
101
+ var clickMethod = function () {
102
+ if (n.isLeaf) {
103
+ var parent = n.parent;
104
+ while (parent != this.root) {
105
+ parent.isExpanded = true;
106
+ parent = parent.parent;
107
+ }
108
+ n.isSelected = !n.isSelected;
109
+ n.click(n);
110
+ var selector = d3.select(this);
111
+ n.colorify(selector);
112
+ selector.classed('tsi-selected', n.isSelected);
113
+ }
114
+ else {
115
+ self.expandCollapseList(n, d3.select(this), true, event);
116
+ }
117
+ event.stopPropagation();
118
+ };
119
+ var li = list.append('li').classed('tsi-leaf', n.isLeaf)
120
+ .classed('tsi-leafParent', n.isLeafParent && _this.withContextMenu)
121
+ .classed('tsi-selected', n.isSelected).on('click', clickMethod);
122
+ li.append('span').classed('tsi-caret', true).attr('style', "left: ".concat((n.level - 1) * 18, "px"));
123
+ li.append('span').classed('tsi-markedName', true).html(n.markedName) // known unsafe usage of .html
124
+ .attr('style', "padding-left: ".concat(40 + (n.level - 1) * 18 - (n.isLeafParent && _this.withContextMenu ? 16 : 0), "px"))
125
+ .attr('title', n.isLeafParent && _this.withContextMenu ? n.name : '');
126
+ n.colorify(li);
127
+ if ((n.isExpanded || n.childrenInFilter) && !n.isLeaf) {
128
+ _this.expandCollapseList(n, li, isFromClick, event);
129
+ }
130
+ }
131
+ });
132
+ node.isExpanded = (node.isExpanded || isFromClick) || (node == _this.root);
133
+ el.classed('tsi-expanded', true);
134
+ }
135
+ }
136
+ };
137
+ return _this;
138
+ }
139
+ Hierarchy.prototype.render = function (data, options) {
140
+ var _this = this;
141
+ var self = this;
142
+ var targetElement = d3.select(this.renderTarget).classed('tsi-hierarchy', true);
143
+ targetElement.html('');
144
+ this.chartOptions.setOptions(options);
145
+ _super.prototype.themify.call(this, targetElement, this.chartOptions.theme);
146
+ this.withContextMenu = this.chartOptions.withContextMenu;
147
+ this.root = this.buildTree(data);
148
+ this.root.isExpanded = true;
149
+ d3.select("html").on("click." + Utils.guid(), function (event) {
150
+ if (_this.clickedNode && event.target != _this.clickedNode && _this.contextMenu) {
151
+ _this.closeContextMenu();
152
+ _this.clickedNode = null;
153
+ }
154
+ });
155
+ var inputDebounceTimeout;
156
+ var filter = targetElement.append('div').classed('tsi-filterWrapper', true).append('input').attr('placeholder', 'Search...').on('input', function (event) {
157
+ var _this = this;
158
+ clearTimeout(inputDebounceTimeout);
159
+ inputDebounceTimeout = setTimeout(function () {
160
+ self.filterText = _this.value.trim();
161
+ if (self.filterText.length == 1)
162
+ return; // quick return for small sets
163
+ var splitFilterText = self.filterText.split('/');
164
+ self.root.filter(splitFilterText[0]);
165
+ if (splitFilterText.length > 1) {
166
+ for (var i = 1; i < splitFilterText.length; i++) {
167
+ if (splitFilterText[i].length) {
168
+ var nodesInFilter = self.root.traverse(function (n) { return n.selfInFilter; });
169
+ nodesInFilter.forEach(function (n) {
170
+ var markedName = n.markedName;
171
+ n.filter(splitFilterText[i], false);
172
+ n.markedName = markedName;
173
+ });
174
+ nodesInFilter.forEach(function (n) {
175
+ if (!n.childrenInFilter)
176
+ n.selfInFilter = false;
177
+ });
178
+ }
179
+ }
180
+ }
181
+ list.selectAll('ul').remove();
182
+ list.classed('tsi-expanded', false);
183
+ self.root.childrenInFilter = self.root.childrenInFilter || self.filterText.length == 0;
184
+ if (self.root.childrenInFilter == false)
185
+ list.append('ul').append('div').text(self.getString('No filter results'));
186
+ else
187
+ self.expandCollapseList(self.root, list, false, event);
188
+ list.select('ul').classed('tsi-noPad', true);
189
+ }, 250);
190
+ });
191
+ var navTabs = targetElement.append('div').classed('tsi-navTabWrapper', true);
192
+ var allTab = navTabs.append('div').classed('tsi-navTab tsi-selected', true).text(this.getString('All hierarchies'));
193
+ var selectedTab = navTabs.append('div').classed('tsi-navTab', true).text(this.getString('Selected'));
194
+ var list = targetElement.append('div').classed('tsi-hierarchyList', true);
195
+ this.hierarchyList = list;
196
+ allTab.on('click', function (event) {
197
+ if (!allTab.classed('tsi-selected')) {
198
+ allTab.classed('tsi-selected', true);
199
+ selectedTab.classed('tsi-selected', false);
200
+ list.html('').classed('tsi-expanded', false);
201
+ _this.expandCollapseList(_this.root, list, true, event);
202
+ list.select('ul').classed('tsi-noPad', true);
203
+ filter.attr('disabled', null);
204
+ }
205
+ });
206
+ selectedTab.on('click', function () {
207
+ if (!selectedTab.classed('tsi-selected')) {
208
+ allTab.classed('tsi-selected', false);
209
+ selectedTab.classed('tsi-selected', true);
210
+ list.html('');
211
+ var ul = list.append('ul').classed('tsi-noPad', true);
212
+ var leafs = _this.root.traverse(function (n) { return n.isSelected; });
213
+ leafs.forEach(function (n) {
214
+ var li = ul.append('li').classed('tsi-leaf', n.isLeaf).classed('tsi-selected', n.isSelected).on('click', function () {
215
+ n.isSelected = !n.isSelected;
216
+ d3.select(this).classed('tsi-selected', n.isSelected);
217
+ n.click(n);
218
+ n.colorify(d3.select(this));
219
+ });
220
+ li.append('span').text(n.name).classed('tsi-markedName', true);
221
+ n.colorify(li);
222
+ });
223
+ filter.attr('disabled', true);
224
+ }
225
+ });
226
+ this.expandCollapseList(this.root, list, false);
227
+ list.select('ul').classed('tsi-noPad', true);
228
+ };
229
+ Hierarchy.prototype.buildTree = function (data) {
230
+ var traverse = function (data, key, level, parent) {
231
+ if (parent === void 0) { parent = null; }
232
+ var node = new HierarchyNode(key, level);
233
+ node.parent = parent;
234
+ if (data.hasOwnProperty('$leaf')) {
235
+ node.isLeaf = true;
236
+ if (data.hasOwnProperty('click'))
237
+ node.click = data.click;
238
+ if (data.hasOwnProperty('color'))
239
+ node.color = data.color;
240
+ node.parent.isLeafParent = true;
241
+ }
242
+ else {
243
+ Object.keys(data).sort().forEach(function (k) {
244
+ node.children.push(traverse(data[k], k, level + 1, node));
245
+ });
246
+ }
247
+ return node;
248
+ };
249
+ return traverse(data, '', 0);
250
+ };
251
+ Hierarchy.prototype.closeContextMenu = function () {
252
+ if (this.contextMenu) {
253
+ this.contextMenu.remove();
254
+ }
255
+ d3.selectAll('.tsi-resultSelected').classed('tsi-resultSelected', false);
256
+ };
257
+ return Hierarchy;
258
+ }(Component));
259
+
260
+ export { Hierarchy as H };
@@ -0,0 +1,39 @@
1
+ import { C as Component } from './Component-Rp30sSAW.js';
2
+ import './Enums-ChUuTtHV.js';
3
+ import './Interfaces-BKRQ685G.js';
4
+
5
+ declare class HierarchyNode {
6
+ name: string;
7
+ markedName: string;
8
+ children: Array<HierarchyNode>;
9
+ parent: HierarchyNode;
10
+ isExpanded: boolean;
11
+ isSelected: boolean;
12
+ isLeaf: boolean;
13
+ childrenInFilter: boolean;
14
+ selfInFilter: boolean;
15
+ color: (n: HierarchyNode) => string;
16
+ click: (n: any) => void;
17
+ isLeafParent: boolean;
18
+ level: number;
19
+ constructor(name: string, level: number);
20
+ filter(filterText: any): void;
21
+ traverse(condition: (n: HierarchyNode) => boolean): any[];
22
+ colorify(el: any): void;
23
+ }
24
+
25
+ declare class Hierarchy extends Component {
26
+ private filterText;
27
+ private root;
28
+ private withContextMenu;
29
+ private contextMenu;
30
+ private clickedNode;
31
+ private hierarchyList;
32
+ constructor(renderTarget: Element);
33
+ render(data: any, options: any): void;
34
+ expandCollapseList: (node: HierarchyNode, el: any, isFromClick?: boolean, event?: any) => void;
35
+ buildTree(data: any): HierarchyNode;
36
+ private closeContextMenu;
37
+ }
38
+
39
+ export { Hierarchy as default };
@@ -0,0 +1,6 @@
1
+ export { H as default } from './Hierarchy-QkWLHkxo.js';
2
+ import './_tslib-5_9pMg1F.js';
3
+ import 'd3';
4
+ import './Utils-C_j8IgZh.js';
5
+ import 'moment-timezone';
6
+ import './Component-CofgyEw0.js';
@@ -0,0 +1,336 @@
1
+ import { _ as __extends, a as __assign, b as __awaiter, c as __generator } from './_tslib-5_9pMg1F.js';
2
+ import * as d3 from 'd3';
3
+ import { U as Utils } from './Utils-C_j8IgZh.js';
4
+ import { C as Component } from './Component-CofgyEw0.js';
5
+
6
+ var HierarchyNavigation = /** @class */ (function (_super) {
7
+ __extends(HierarchyNavigation, _super);
8
+ function HierarchyNavigation(renderTarget) {
9
+ var _this = _super.call(this, renderTarget) || this;
10
+ _this.path = [];
11
+ //selectedIds
12
+ _this.selectedIds = [];
13
+ _this.searchEnabled = true;
14
+ _this.renderSearchResult = function (r, payload, target) {
15
+ var _a, _b, _c, _d, _e, _f;
16
+ var hierarchyData = ((_b = (_a = r.hierarchyNodes) === null || _a === void 0 ? void 0 : _a.hits) === null || _b === void 0 ? void 0 : _b.length)
17
+ ? _this.fillDataRecursively(r.hierarchyNodes, payload, payload)
18
+ : {};
19
+ var instancesData = ((_d = (_c = r.instances) === null || _c === void 0 ? void 0 : _c.hits) === null || _d === void 0 ? void 0 : _d.length)
20
+ ? r.instances.hits.reduce(function (acc, i) {
21
+ acc[_this.instanceNodeIdentifier(i)] = new InstanceNode(i.timeSeriesId, i.name, payload.path.length - _this.path.length, i.id, i.description);
22
+ return acc;
23
+ }, {})
24
+ : {};
25
+ if ((_f = (_e = r.hierarchyNodes) === null || _e === void 0 ? void 0 : _e.hits) === null || _f === void 0 ? void 0 : _f.length) {
26
+ var hitCountElem = target.select(".tsi-hitCount");
27
+ if (hitCountElem.size() === 0) {
28
+ hitCountElem = target.append('span').classed('tsi-hitCount', true).text('');
29
+ }
30
+ hitCountElem.text(r.hierarchyNodes.hitCount);
31
+ }
32
+ _this.renderTree(__assign(__assign({}, hierarchyData), instancesData), target);
33
+ };
34
+ _this.hierarchyNodeIdentifier = function (hName) {
35
+ return hName ? hName : '(' + _this.getString("Empty") + ')';
36
+ };
37
+ _this.instanceNodeIdentifier = function (instance) {
38
+ return "instance-".concat(Utils.getInstanceKey(instance));
39
+ };
40
+ _this.instanceNodeStringToDisplay = function (instance) {
41
+ var _a;
42
+ return ((_a = instance.highlights) === null || _a === void 0 ? void 0 : _a.name) || Utils.getHighlightedTimeSeriesIdToDisplay(instance)
43
+ || instance.name || Utils.getTimeSeriesIdToDisplay(instance, _this.getString('Empty'));
44
+ };
45
+ _this.instanceNodeString = function (instance) {
46
+ return instance.name || Utils.getTimeSeriesIdString(instance);
47
+ };
48
+ return _this;
49
+ }
50
+ HierarchyNavigation.prototype.render = function (searchF_1) {
51
+ return __awaiter(this, arguments, void 0, function (searchF, hierarchyNavOptions, preselectedIds) {
52
+ var targetElement, results;
53
+ if (hierarchyNavOptions === void 0) { hierarchyNavOptions = {}; }
54
+ return __generator(this, function (_a) {
55
+ this.chartOptions.setOptions(hierarchyNavOptions);
56
+ this.searchFunction = searchF;
57
+ targetElement = d3.select(this.renderTarget).text('');
58
+ this.hierarchyNavWrapper = this.createHierarchyNavWrapper(targetElement);
59
+ this.selectedIds = preselectedIds;
60
+ //render search wrapper
61
+ //this.renderSearchBox()
62
+ _super.prototype.themify.call(this, this.hierarchyNavWrapper, this.chartOptions.theme);
63
+ results = this.createResultsWrapper(this.hierarchyNavWrapper);
64
+ this.hierarchyElem = this.createHierarchyElem(results);
65
+ this.pathSearchAndRenderResult({ search: { payload: this.requestPayload() }, render: { target: this.hierarchyElem } });
66
+ return [2 /*return*/];
67
+ });
68
+ });
69
+ };
70
+ HierarchyNavigation.prototype.createHierarchyNavWrapper = function (targetElement) {
71
+ return targetElement.append('div').attr('class', 'tsi-hierarchy-nav-wrapper');
72
+ };
73
+ HierarchyNavigation.prototype.createResultsWrapper = function (hierarchyNavWrapper) {
74
+ return hierarchyNavWrapper.append('div').classed('tsi-hierarchy-or-list-wrapper', true);
75
+ };
76
+ HierarchyNavigation.prototype.createHierarchyElem = function (results) {
77
+ return results.append('div').classed('tsi-hierarchy', true).attr("role", "navigation").on('scroll', function () { });
78
+ };
79
+ // prepares the parameters for search request
80
+ HierarchyNavigation.prototype.requestPayload = function (hierarchy) {
81
+ var _a;
82
+ if (hierarchy === void 0) { hierarchy = null; }
83
+ var path = (_a = hierarchy === null || hierarchy === void 0 ? void 0 : hierarchy.path) !== null && _a !== void 0 ? _a : this.path;
84
+ return { path: path, hierarchy: hierarchy };
85
+ };
86
+ // renders tree for both 'Navigate' and 'Filter' mode (with Hierarchy View option selected), locInTarget refers to the 'show more' element -either hierarchy or instance- within the target
87
+ HierarchyNavigation.prototype.renderTree = function (data, target) {
88
+ var _this = this;
89
+ var list = target.append('ul').attr("role", target === this.hierarchyElem ? "tree" : "group");
90
+ Object.keys(data).forEach(function (el) {
91
+ var nodeNameToCheckIfExists = data[el] instanceof InstanceNode ? _this.instanceNodeString(data[el]) : el;
92
+ var li;
93
+ if (list.selectAll(".tsi-name").nodes().find(function (e) { return e.innerText === nodeNameToCheckIfExists; })) {
94
+ li = null;
95
+ }
96
+ else {
97
+ li = list.append('li').classed('tsi-leaf', data[el].isLeaf);
98
+ //if the node is already selected, we want to highlight it
99
+ if (_this.selectedIds && _this.selectedIds.includes(data[el].id)) {
100
+ li.classed('tsi-selected', true);
101
+ }
102
+ }
103
+ if (!li)
104
+ return;
105
+ li.attr("role", "none");
106
+ var newListElem = _this.createHierarchyItemElem(data[el], el);
107
+ li.node().appendChild(newListElem.node());
108
+ data[el].node = li;
109
+ if (data[el].children) {
110
+ data[el].isExpanded = true;
111
+ data[el].node.classed('tsi-expanded', true);
112
+ _this.renderTree(data[el].children, data[el].node);
113
+ }
114
+ });
115
+ };
116
+ HierarchyNavigation.prototype.renderSearchBox = function () {
117
+ var _this = this;
118
+ this.searchWrapperElem = this.hierarchyNavWrapper.append('div').classed('tsi-hierarchy-search', true);
119
+ var inputWrapper = this.searchWrapperElem.append("div").attr("class", "tsi-search");
120
+ inputWrapper.append("i").classed("tsi-search-icon", true);
121
+ var input = inputWrapper
122
+ .append("input")
123
+ .attr("class", "tsi-searchInput")
124
+ .attr("aria-label", this.getString("Search Time Series Instances"))
125
+ .attr("aria-describedby", "tsi-search-desc")
126
+ .attr("role", "combobox")
127
+ .attr("aria-owns", "tsi-search-results")
128
+ .attr("aria-expanded", "false")
129
+ .attr("aria-haspopup", "listbox")
130
+ .attr("placeholder", this.getString("Search Time Series Instances") + "...");
131
+ var self = this;
132
+ input.on("keydown", function (event) {
133
+ _this.chartOptions.onKeydown(event, _this.ap);
134
+ });
135
+ var searchText;
136
+ input.on("input", function (event) {
137
+ searchText = event.target.value;
138
+ if (searchText.length === 0) {
139
+ //clear the tree
140
+ self.hierarchyElem.selectAll('ul').remove();
141
+ self.pathSearchAndRenderResult({ search: { payload: self.requestPayload() }, render: { target: self.hierarchyElem } });
142
+ }
143
+ else {
144
+ //filter the tree
145
+ self.filterTree(searchText);
146
+ }
147
+ });
148
+ };
149
+ HierarchyNavigation.prototype.pathSearchAndRenderResult = function (_a) {
150
+ return __awaiter(this, arguments, void 0, function (_b) {
151
+ var result, err_1;
152
+ var _c = _b.search, payload = _c.payload, _d = _c.bubbleUpReject, bubbleUpReject = _d === void 0 ? false : _d, _e = _b.render, target = _e.target; _e.locInTarget;
153
+ return __generator(this, function (_g) {
154
+ switch (_g.label) {
155
+ case 0:
156
+ _g.trys.push([0, 2, , 3]);
157
+ return [4 /*yield*/, this.searchFunction(payload)];
158
+ case 1:
159
+ result = _g.sent();
160
+ if (result.error) {
161
+ throw result.error;
162
+ }
163
+ this.renderSearchResult(result, payload, target);
164
+ return [3 /*break*/, 3];
165
+ case 2:
166
+ err_1 = _g.sent();
167
+ this.chartOptions.onError("Error in hierarchy navigation", "Failed to complete search", err_1 instanceof XMLHttpRequest ? err_1 : null);
168
+ if (bubbleUpReject) {
169
+ throw err_1;
170
+ }
171
+ return [3 /*break*/, 3];
172
+ case 3: return [2 /*return*/];
173
+ }
174
+ });
175
+ });
176
+ };
177
+ HierarchyNavigation.prototype.filterTree = function (searchText) {
178
+ var tree = this.hierarchyElem.selectAll('ul').nodes()[0];
179
+ var list = tree.querySelectorAll('li');
180
+ list.forEach(function (li) {
181
+ var name = li.querySelector('.tsi-name').innerText;
182
+ if (name.toLowerCase().includes(searchText.toLowerCase())) {
183
+ li.style.display = 'block';
184
+ }
185
+ else {
186
+ li.style.display = 'none';
187
+ }
188
+ });
189
+ };
190
+ // creates in-depth data object using the server response for hierarchyNodes to show in the tree all expanded, considering UntilChildren
191
+ HierarchyNavigation.prototype.fillDataRecursively = function (hierarchyNodes, payload, payloadForContinuation) {
192
+ var _this = this;
193
+ if (payloadForContinuation === void 0) { payloadForContinuation = null; }
194
+ var data = {};
195
+ hierarchyNodes.hits.forEach(function (h) {
196
+ var _a;
197
+ var hierarchy = new HierarchyNode(h.name, payload.path, payload.path.length - _this.path.length, h.cumulativeInstanceCount, h.id);
198
+ hierarchy.expand = function () {
199
+ hierarchy.isExpanded = true;
200
+ hierarchy.node.classed('tsi-expanded', true);
201
+ return _this.pathSearchAndRenderResult({
202
+ search: { payload: _this.requestPayload(hierarchy), bubbleUpReject: true },
203
+ render: { target: hierarchy.node }
204
+ });
205
+ };
206
+ data[_this.hierarchyNodeIdentifier(h.name)] = hierarchy;
207
+ if ((_a = h.hierarchyNodes) === null || _a === void 0 ? void 0 : _a.hits.length) {
208
+ hierarchy.children = _this.fillDataRecursively(h.hierarchyNodes, _this.requestPayload(hierarchy), payloadForContinuation);
209
+ }
210
+ });
211
+ return data;
212
+ };
213
+ //returns the dom element of one hierarchy level item for tree rendering
214
+ HierarchyNavigation.prototype.createHierarchyItemElem = function (hORi, key) {
215
+ var self = this;
216
+ var isHierarchyNode = hORi instanceof HierarchyNode;
217
+ var hierarchyItemElem = d3.create('div').classed('tsi-hierarchyItem', true)
218
+ .attr('style', "padding-left: ".concat(hORi.isLeaf ? hORi.level * 18 + 20 : (hORi.level + 1) * 18 + 20, "px"))
219
+ .attr('tabindex', 0)
220
+ //.attr('arialabel', isHierarchyNode ? key : Utils.getTimeSeriesIdString(hORi))
221
+ .attr('arialabel', isHierarchyNode ? key : self.getAriaLabel(hORi))
222
+ .attr('title', isHierarchyNode ? key : self.getAriaLabel(hORi))
223
+ .attr("role", "treeitem").attr('aria-expanded', hORi.isExpanded)
224
+ .on('click keydown', function (event) {
225
+ return __awaiter(this, void 0, void 0, function () {
226
+ return __generator(this, function (_a) {
227
+ switch (_a.label) {
228
+ case 0:
229
+ if (Utils.isKeyDownAndNotEnter(event)) {
230
+ return [2 /*return*/];
231
+ }
232
+ if (!!isHierarchyNode) return [3 /*break*/, 1];
233
+ event.stopPropagation();
234
+ //we want to store clicked instance and hightlight it in the hierarchy
235
+ //if the instance is already selected, we want to deselect it
236
+ if (self.chartOptions.onInstanceClick) {
237
+ if (self.selectedIds && self.selectedIds.includes(hORi.id)) {
238
+ self.selectedIds = self.selectedIds.filter(function (id) { return id !== hORi.id; });
239
+ hORi.node.classed('tsi-selected', false);
240
+ }
241
+ else {
242
+ self.selectedIds.push(hORi.id);
243
+ hORi.node.classed('tsi-selected', true);
244
+ }
245
+ }
246
+ self.chartOptions.onInstanceClick(hORi);
247
+ return [3 /*break*/, 4];
248
+ case 1:
249
+ if (!hORi.isExpanded) return [3 /*break*/, 2];
250
+ hORi.collapse();
251
+ return [3 /*break*/, 4];
252
+ case 2: return [4 /*yield*/, hORi.expand()];
253
+ case 3:
254
+ _a.sent();
255
+ _a.label = 4;
256
+ case 4: return [2 /*return*/];
257
+ }
258
+ });
259
+ });
260
+ });
261
+ if (isHierarchyNode) {
262
+ hierarchyItemElem.append('span').classed('tsi-caret-icon', true).attr('style', "left: ".concat((hORi.level) * 18 + 20, "px"));
263
+ hierarchyItemElem.append('span').classed('tsi-name', true).text(key);
264
+ hierarchyItemElem.append('span').classed('tsi-instanceCount', true).text(hORi.cumulativeInstanceCount);
265
+ hierarchyItemElem.append('span').classed('tsi-hitCount', true).text(''); // hit count is the number of hierarchy nodes below, it is filled after expand is clicked for this node (after search is done for this path)
266
+ }
267
+ else {
268
+ var spanElem = hierarchyItemElem.append('span').classed('tsi-name', true);
269
+ Utils.appendFormattedElementsFromString(spanElem, this.instanceNodeStringToDisplay(hORi));
270
+ }
271
+ return hierarchyItemElem;
272
+ };
273
+ HierarchyNavigation.prototype.getAriaLabel = function (hORi) {
274
+ if (hORi instanceof HierarchyNode) {
275
+ return hORi.name;
276
+ }
277
+ //check description first then name then id
278
+ return hORi.description || hORi.name || hORi.id || Utils.getTimeSeriesIdString(hORi);
279
+ };
280
+ return HierarchyNavigation;
281
+ }(Component));
282
+ var HierarchyNode = /** @class */ (function () {
283
+ function HierarchyNode(name, parentPath, level, cumulativeInstanceCount, id) {
284
+ if (cumulativeInstanceCount === void 0) { cumulativeInstanceCount = null; }
285
+ if (id === void 0) { id = null; }
286
+ this.name = name;
287
+ this.id = id;
288
+ this.path = parentPath.concat([name]);
289
+ this.level = level;
290
+ this.cumulativeInstanceCount = cumulativeInstanceCount;
291
+ this.node = null;
292
+ this.children = null;
293
+ this.isExpanded = false;
294
+ }
295
+ HierarchyNode.prototype.expand = function () { };
296
+ HierarchyNode.prototype.collapse = function () {
297
+ this.isExpanded = false;
298
+ this.node.classed('tsi-expanded', false);
299
+ this.node.selectAll('ul').remove();
300
+ };
301
+ return HierarchyNode;
302
+ }());
303
+ var InstanceNode = /** @class */ (function () {
304
+ function InstanceNode(tsId, name, level, id, description) {
305
+ if (name === void 0) { name = null; }
306
+ if (id === void 0) { id = null; }
307
+ if (description === void 0) { description = null; }
308
+ this.timeSeriesId = tsId;
309
+ this.name = name;
310
+ this.suppressDrawContextMenu = false;
311
+ this.isLeaf = true;
312
+ this.level = level;
313
+ this.node = null;
314
+ this.id = id;
315
+ this.description = description;
316
+ }
317
+ return InstanceNode;
318
+ }());
319
+ var HierarchySelectionValues;
320
+ (function (HierarchySelectionValues) {
321
+ HierarchySelectionValues["All"] = "0";
322
+ HierarchySelectionValues["Unparented"] = "-1";
323
+ })(HierarchySelectionValues || (HierarchySelectionValues = {}));
324
+ var ViewType;
325
+ (function (ViewType) {
326
+ ViewType[ViewType["Hierarchy"] = 0] = "Hierarchy";
327
+ ViewType[ViewType["List"] = 1] = "List";
328
+ })(ViewType || (ViewType = {}));
329
+ var State;
330
+ (function (State) {
331
+ State[State["Navigate"] = 0] = "Navigate";
332
+ State[State["Search"] = 1] = "Search";
333
+ State[State["Filter"] = 2] = "Filter";
334
+ })(State || (State = {}));
335
+
336
+ export { HierarchyNavigation as H };