@sme.up/ketchup 5.0.0 → 5.1.1

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 (196) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/{cell-utils-720be0c8.js → cell-utils-5b16c180.js} +4 -4
  3. package/dist/cjs/{f-button-dbf3cd3a.js → f-button-3b9f32af.js} +2 -2
  4. package/dist/cjs/{f-cell-93d984ad.js → f-cell-c6ad973a.js} +6 -6
  5. package/dist/cjs/{f-chip-438213eb.js → f-chip-bed86c4a.js} +3 -3
  6. package/dist/cjs/{f-image-21865ab7.js → f-image-08a3d340.js} +2 -2
  7. package/dist/cjs/{index-ab119fad.js → index-8d7bb3be.js} +4 -1
  8. package/dist/cjs/ketchup.cjs.js +3 -3
  9. package/dist/cjs/kup-accordion.cjs.entry.js +5 -5
  10. package/dist/cjs/kup-autocomplete_27.cjs.entry.js +412 -353
  11. package/dist/cjs/kup-calendar.cjs.entry.js +8 -8
  12. package/dist/cjs/kup-cell.cjs.entry.js +8 -8
  13. package/dist/cjs/kup-dash-list.cjs.entry.js +5 -5
  14. package/dist/cjs/kup-dash_2.cjs.entry.js +5 -5
  15. package/dist/cjs/kup-drawer.cjs.entry.js +8 -5
  16. package/dist/cjs/kup-echart.cjs.entry.js +210 -60
  17. package/dist/cjs/kup-field.cjs.entry.js +3 -3
  18. package/dist/cjs/kup-iframe.cjs.entry.js +4 -4
  19. package/dist/cjs/kup-lazy.cjs.entry.js +4 -4
  20. package/dist/cjs/kup-magic-box.cjs.entry.js +7 -7
  21. package/dist/cjs/{kup-manager-09c0c1fc.js → kup-manager-4227f0a2.js} +2804 -2598
  22. package/dist/cjs/kup-nav-bar.cjs.entry.js +6 -6
  23. package/dist/cjs/kup-photo-frame.cjs.entry.js +179 -0
  24. package/dist/cjs/kup-probe.cjs.entry.js +3 -3
  25. package/dist/cjs/kup-qlik.cjs.entry.js +3 -3
  26. package/dist/cjs/kup-snackbar.cjs.entry.js +7 -7
  27. package/dist/cjs/loader.cjs.js +3 -3
  28. package/dist/cjs/{utils-a60ab5fa.js → utils-b9df398c.js} +4 -38
  29. package/dist/collection/assets/card.js +30 -30
  30. package/dist/collection/assets/data-table.js +24 -30
  31. package/dist/collection/assets/echart.js +481 -0
  32. package/dist/collection/assets/index.js +79 -79
  33. package/dist/collection/assets/kupdata.js +29 -41
  34. package/dist/collection/assets/list.js +6 -6
  35. package/dist/collection/assets/nav-bar.js +4 -4
  36. package/dist/collection/assets/probe.js +18 -18
  37. package/dist/collection/collection-manifest.json +2 -1
  38. package/dist/collection/components/kup-autocomplete/kup-autocomplete.js +5 -5
  39. package/dist/collection/components/kup-box/kup-box.js +9 -9
  40. package/dist/collection/components/kup-button-list/kup-button-list.js +4 -4
  41. package/dist/collection/components/kup-card/built-in/kup-card-clock.js +1 -1
  42. package/dist/collection/components/kup-card/built-in/kup-card-column-drop-menu.js +21 -22
  43. package/dist/collection/components/kup-card/kup-card.js +1 -2
  44. package/dist/collection/components/kup-chip/kup-chip.js +4 -4
  45. package/dist/collection/components/kup-combobox/kup-combobox.js +6 -6
  46. package/dist/collection/components/kup-data-table/kup-data-table-declarations.js +0 -2
  47. package/dist/collection/components/kup-data-table/kup-data-table-helper.js +31 -32
  48. package/dist/collection/components/kup-data-table/kup-data-table.js +124 -164
  49. package/dist/collection/components/kup-drawer/kup-drawer.js +4 -1
  50. package/dist/collection/components/kup-dropdown-button/kup-dropdown-button.css +3 -3
  51. package/dist/collection/components/kup-dropdown-button/kup-dropdown-button.js +14 -14
  52. package/dist/collection/components/kup-echart/kup-echart-declarations.js +3 -0
  53. package/dist/collection/components/kup-echart/kup-echart.js +246 -58
  54. package/dist/collection/components/kup-image/assets/svg/instagram.svg +1 -0
  55. package/dist/collection/components/kup-image/assets/svg/pinterest.svg +1 -0
  56. package/dist/collection/components/kup-image/assets/svg/reddit.svg +1 -0
  57. package/dist/collection/components/kup-list/kup-list-helper.js +26 -26
  58. package/dist/collection/components/kup-list/kup-list.css +35 -3
  59. package/dist/collection/components/kup-list/kup-list.js +52 -44
  60. package/dist/collection/components/kup-magic-box/kup-magic-box.js +3 -3
  61. package/dist/collection/components/kup-nav-bar/kup-nav-bar.js +2 -2
  62. package/dist/collection/components/kup-photo-frame/kup-photo-frame-declarations.js +10 -0
  63. package/dist/collection/components/kup-photo-frame/kup-photo-frame.css +70 -0
  64. package/dist/collection/components/kup-photo-frame/kup-photo-frame.js +382 -0
  65. package/dist/collection/components/kup-snackbar/kup-snackbar.css +4 -0
  66. package/dist/collection/components/kup-tab-bar/kup-tab-bar.css +1 -1
  67. package/dist/collection/components/kup-time-picker/kup-time-picker.js +10 -10
  68. package/dist/collection/components/kup-tree/kup-tree.js +100 -51
  69. package/dist/collection/f-components/f-paginator/f-paginator.js +6 -6
  70. package/dist/collection/managers/kup-data/kup-data-cell-helper.js +2 -2
  71. package/dist/collection/managers/kup-data/kup-data-column-helper.js +27 -3
  72. package/dist/collection/managers/kup-data/kup-data-declarations.js +2 -1
  73. package/dist/collection/managers/kup-data/kup-data-node-helper.js +1 -1
  74. package/dist/collection/managers/kup-data/kup-data-row-helper.js +2 -2
  75. package/dist/collection/managers/kup-data/kup-data.js +337 -155
  76. package/dist/collection/managers/kup-dates/kup-dates.js +2 -2
  77. package/dist/collection/managers/kup-debug/kup-debug.js +6 -6
  78. package/dist/collection/managers/kup-dynamic-position/kup-dynamic-position.js +1 -1
  79. package/dist/collection/managers/kup-language/kup-language.js +2 -2
  80. package/dist/collection/managers/kup-manager/kup-manager.js +13 -0
  81. package/dist/collection/managers/kup-math/kup-math-declarations.js +13 -0
  82. package/dist/collection/managers/kup-math/kup-math-helper.js +39 -0
  83. package/dist/collection/managers/kup-math/kup-math.js +151 -0
  84. package/dist/collection/managers/kup-objects/kup-objects.js +48 -1
  85. package/dist/collection/managers/kup-theme/kup-theme.js +2 -2
  86. package/dist/collection/utils/cell-utils.js +2 -3
  87. package/dist/collection/utils/kup-column-menu/kup-column-menu.js +1 -1
  88. package/dist/collection/utils/utils.js +3 -74
  89. package/dist/esm/{cell-utils-b80ccb8c.js → cell-utils-69f75e2e.js} +4 -4
  90. package/dist/esm/{f-button-9e835467.js → f-button-7e7607d8.js} +2 -2
  91. package/dist/esm/{f-cell-f8bb2e04.js → f-cell-e4d83c27.js} +6 -6
  92. package/dist/esm/{f-chip-953c6915.js → f-chip-51dfefaf.js} +3 -3
  93. package/dist/esm/{f-image-78c5265e.js → f-image-de331954.js} +2 -2
  94. package/dist/esm/{index-78f3699d.js → index-aeec9835.js} +4 -1
  95. package/dist/esm/ketchup.js +3 -3
  96. package/dist/esm/kup-accordion.entry.js +5 -5
  97. package/dist/esm/kup-autocomplete_27.entry.js +412 -353
  98. package/dist/esm/kup-calendar.entry.js +8 -8
  99. package/dist/esm/kup-cell.entry.js +8 -8
  100. package/dist/esm/kup-dash-list.entry.js +5 -5
  101. package/dist/esm/kup-dash_2.entry.js +5 -5
  102. package/dist/esm/kup-drawer.entry.js +8 -5
  103. package/dist/esm/kup-echart.entry.js +210 -60
  104. package/dist/esm/kup-field.entry.js +3 -3
  105. package/dist/esm/kup-iframe.entry.js +4 -4
  106. package/dist/esm/kup-lazy.entry.js +4 -4
  107. package/dist/esm/kup-magic-box.entry.js +7 -7
  108. package/dist/esm/{kup-manager-bba62291.js → kup-manager-0ab94726.js} +2805 -2598
  109. package/dist/esm/kup-nav-bar.entry.js +6 -6
  110. package/dist/esm/kup-photo-frame.entry.js +175 -0
  111. package/dist/esm/kup-probe.entry.js +3 -3
  112. package/dist/esm/kup-qlik.entry.js +3 -3
  113. package/dist/esm/kup-snackbar.entry.js +7 -7
  114. package/dist/esm/loader.js +3 -3
  115. package/dist/esm/{utils-d1569956.js → utils-35c7a90d.js} +5 -37
  116. package/dist/ketchup/assets/svg/instagram.svg +1 -0
  117. package/dist/ketchup/assets/svg/pinterest.svg +1 -0
  118. package/dist/ketchup/assets/svg/reddit.svg +1 -0
  119. package/dist/ketchup/ketchup.esm.js +1 -1
  120. package/dist/ketchup/p-0751aaf6.entry.js +1 -0
  121. package/dist/ketchup/p-10c8d755.js +1 -0
  122. package/dist/ketchup/{p-aa27f9f7.entry.js → p-24df4f29.entry.js} +2 -2
  123. package/dist/ketchup/{p-29800a2e.js → p-2d4f19f4.js} +1 -1
  124. package/dist/ketchup/p-33073f4a.js +1 -0
  125. package/dist/ketchup/p-3445be1e.entry.js +1 -0
  126. package/dist/ketchup/p-3813281b.entry.js +1 -0
  127. package/dist/ketchup/p-4081f5f7.entry.js +1 -0
  128. package/dist/ketchup/p-47b57d97.js +1 -0
  129. package/dist/ketchup/p-5186885c.entry.js +1 -0
  130. package/dist/ketchup/{p-f993f813.js → p-5d190cf5.js} +1 -1
  131. package/dist/ketchup/p-67c64257.entry.js +1 -0
  132. package/dist/ketchup/p-68fc1428.entry.js +1 -0
  133. package/dist/ketchup/p-8be1337b.js +1 -0
  134. package/dist/ketchup/p-8f735633.entry.js +1 -0
  135. package/dist/ketchup/p-96101f09.entry.js +39 -0
  136. package/dist/ketchup/p-9bcda66f.entry.js +1 -0
  137. package/dist/ketchup/p-b5e1dbfa.entry.js +1 -0
  138. package/dist/ketchup/{p-ebf4cf56.js → p-c314b1e6.js} +1 -1
  139. package/dist/ketchup/p-d7af8156.entry.js +1 -0
  140. package/dist/ketchup/p-dbe87a3f.entry.js +143 -0
  141. package/dist/ketchup/p-ee33cbe9.js +9 -0
  142. package/dist/ketchup/p-f250d42b.entry.js +1 -0
  143. package/dist/ketchup/p-f9c41e20.entry.js +1 -0
  144. package/dist/ketchup/p-fea316ab.entry.js +1 -0
  145. package/dist/types/components/kup-button-list/kup-button-list-declarations.d.ts +2 -1
  146. package/dist/types/components/kup-data-table/kup-data-table-declarations.d.ts +0 -2
  147. package/dist/types/components/kup-data-table/kup-data-table.d.ts +8 -15
  148. package/dist/types/components/kup-dropdown-button/kup-dropdown-button.d.ts +1 -1
  149. package/dist/types/components/kup-echart/kup-echart-declarations.d.ts +3 -0
  150. package/dist/types/components/kup-echart/kup-echart.d.ts +12 -1
  151. package/dist/types/components/kup-list/kup-list-declarations.d.ts +3 -7
  152. package/dist/types/components/kup-list/kup-list-helper.d.ts +6 -6
  153. package/dist/types/components/kup-list/kup-list.d.ts +2 -2
  154. package/dist/types/components/kup-photo-frame/kup-photo-frame-declarations.d.ts +9 -0
  155. package/dist/types/components/kup-photo-frame/kup-photo-frame.d.ts +61 -0
  156. package/dist/types/components/kup-tree/kup-tree-declarations.d.ts +1 -1
  157. package/dist/types/components/kup-tree/kup-tree.d.ts +1 -1
  158. package/dist/types/components.d.ts +110 -28
  159. package/dist/types/managers/kup-data/kup-data-column-helper.d.ts +9 -1
  160. package/dist/types/managers/kup-data/kup-data-declarations.d.ts +4 -25
  161. package/dist/types/managers/kup-data/kup-data-node-helper.d.ts +1 -1
  162. package/dist/types/managers/kup-data/kup-data.d.ts +63 -27
  163. package/dist/types/managers/kup-manager/kup-manager-declarations.d.ts +11 -0
  164. package/dist/types/managers/kup-manager/kup-manager.d.ts +2 -0
  165. package/dist/types/managers/kup-math/kup-math-declarations.d.ts +21 -0
  166. package/dist/types/managers/kup-math/kup-math-helper.d.ts +17 -0
  167. package/dist/types/managers/kup-math/kup-math.d.ts +60 -0
  168. package/dist/types/managers/kup-objects/kup-objects.d.ts +22 -0
  169. package/dist/types/utils/utils.d.ts +0 -18
  170. package/package.json +2 -2
  171. package/dist/collection/managers/kup-data/kup-data-dataset-helper.js +0 -262
  172. package/dist/collection/managers/kup-data/kup-data-helper.js +0 -61
  173. package/dist/collection/utils/state-utils.js +0 -9
  174. package/dist/ketchup/p-0032a782.entry.js +0 -1
  175. package/dist/ketchup/p-18c4d083.entry.js +0 -1
  176. package/dist/ketchup/p-199c972e.entry.js +0 -1
  177. package/dist/ketchup/p-34aa8d8a.entry.js +0 -1
  178. package/dist/ketchup/p-542279e9.entry.js +0 -1
  179. package/dist/ketchup/p-5b26a7a8.entry.js +0 -39
  180. package/dist/ketchup/p-5c97e7ab.js +0 -1
  181. package/dist/ketchup/p-6817ca85.entry.js +0 -1
  182. package/dist/ketchup/p-76e674ca.entry.js +0 -1
  183. package/dist/ketchup/p-78aa6f1b.js +0 -1
  184. package/dist/ketchup/p-842b66aa.entry.js +0 -1
  185. package/dist/ketchup/p-894981c0.entry.js +0 -143
  186. package/dist/ketchup/p-8ac2fa75.entry.js +0 -1
  187. package/dist/ketchup/p-907c9e11.entry.js +0 -1
  188. package/dist/ketchup/p-9ae9149b.entry.js +0 -1
  189. package/dist/ketchup/p-b0d1bdd8.js +0 -9
  190. package/dist/ketchup/p-e1e4c951.entry.js +0 -1
  191. package/dist/ketchup/p-eba369d9.entry.js +0 -1
  192. package/dist/ketchup/p-ed0b8666.js +0 -1
  193. package/dist/ketchup/p-fa540f82.js +0 -1
  194. package/dist/types/managers/kup-data/kup-data-dataset-helper.d.ts +0 -42
  195. package/dist/types/managers/kup-data/kup-data-helper.d.ts +0 -11
  196. package/dist/types/utils/state-utils.d.ts +0 -1
@@ -1,200 +1,382 @@
1
- import numeral from 'numeral';
2
- import 'numeral/locales/chs';
3
- import 'numeral/locales/es';
4
- import 'numeral/locales/fr';
5
- import 'numeral/locales/it';
6
- import 'numeral/locales/pl';
7
- import 'numeral/locales/ru';
8
- import { KupDebugCategory } from '../kup-debug/kup-debug-declarations';
9
- import { distinctDataset, newDataset, rangedDistinctDataset, sortDataset, transposeDataset, } from './kup-data-dataset-helper';
1
+ import { KupDataNewColumnTypes, } from './kup-data-declarations';
10
2
  import { findCell, getCellValue, replaceCell } from './kup-data-cell-helper';
11
3
  import { findColumns, hideColumns, newColumn } from './kup-data-column-helper';
12
4
  import { findRow, toNode } from './kup-data-row-helper';
13
5
  import { removeNode, setPropertiesNode, toStreamNode, } from './kup-data-node-helper';
6
+ import { fieldColumn } from '../../components/kup-data-table/kup-data-table-declarations';
7
+ import { KupDebugCategory } from '../kup-debug/kup-debug-declarations';
14
8
  const dom = document.documentElement;
15
9
  /**
16
10
  * Handles data operations.
17
11
  * @module KupData
18
12
  */
19
13
  export class KupData {
20
- /**
21
- * Initializes KupData.
22
- */
23
14
  constructor() {
24
- this.datasetOperations = null;
25
- this.formulas = null;
26
- this.numeral = numeral;
27
- this.datasetOperations = {
28
- cell: {
29
- find(dataset, filters) {
30
- return findCell(dataset, filters);
31
- },
32
- getValue(dataset, columns) {
33
- return getCellValue(dataset, columns);
34
- },
35
- replace(dataset, cell, columns) {
36
- return replaceCell(dataset, cell, columns);
37
- },
15
+ this.cell = {
16
+ find(dataset, filters) {
17
+ return findCell(dataset, filters);
38
18
  },
39
- column: {
40
- find(dataset, filters) {
41
- return findColumns(dataset, filters);
42
- },
43
- hide(dataset, columns2hide) {
44
- return hideColumns(dataset, columns2hide);
45
- },
46
- new(dataset, type, options) {
47
- return newColumn(dataset, type, options);
48
- },
19
+ getValue(dataset, columns) {
20
+ return getCellValue(dataset, columns);
49
21
  },
50
- node: {
51
- remove(nodes, node2remove) {
52
- return removeNode(nodes, node2remove);
53
- },
54
- setProperties(nodes, properties, recursively, exclude) {
55
- return setPropertiesNode(nodes, properties, recursively, exclude);
56
- },
57
- toStream(nodes) {
58
- return toStreamNode(nodes);
59
- },
22
+ replace(dataset, cell, columns) {
23
+ return replaceCell(dataset, cell, columns);
60
24
  },
61
- row: {
62
- find(dataset, filters) {
63
- return findRow(dataset, filters);
64
- },
65
- toNode(dataset) {
66
- return toNode(dataset);
67
- },
25
+ };
26
+ this.column = {
27
+ find(dataset, filters) {
28
+ return findColumns(dataset, filters);
68
29
  },
69
- distinct(dataset, columns, valuesColumn) {
70
- return distinctDataset(dataset, columns, valuesColumn);
30
+ hide(dataset, columns2hide) {
31
+ return hideColumns(dataset, columns2hide);
71
32
  },
72
- new(dataset, newColumns) {
73
- return newDataset(dataset, newColumns);
33
+ new(dataset, type, options) {
34
+ return newColumn(dataset, type, options);
74
35
  },
75
- rangedDistinct(dataset, rangeColumns, resultingColumn, valuesColumn) {
76
- return rangedDistinctDataset(dataset, rangeColumns, resultingColumn, valuesColumn);
36
+ };
37
+ this.node = {
38
+ remove(nodes, node2remove) {
39
+ return removeNode(nodes, node2remove);
77
40
  },
78
- sort(dataset, sortType, headerColumn) {
79
- return sortDataset(dataset, sortType, headerColumn);
41
+ setProperties(nodes, properties, recursively, exclude) {
42
+ return setPropertiesNode(nodes, properties, recursively, exclude);
80
43
  },
81
- transpose(dataset, headerColumn) {
82
- return transposeDataset(dataset, headerColumn);
44
+ toStream(nodes) {
45
+ return toStreamNode(nodes);
83
46
  },
84
47
  };
85
- this.formulas = {
86
- /**
87
- * Takes a mathematical formula as string in input, with column names between brackets, and returns the result as a number.
88
- * @param {string} formula - Mathematical operation (i.e.: ([COL1] - [COL2]) * 100 / [COL3]).
89
- * @param {{ [index: string]: number }} row - Object containing column names as indexes and the related values as keys.
90
- * @returns {number} Result of the formula.
91
- */
92
- custom(formula, row) {
93
- const keys = Object.keys(row);
94
- for (let i = 0; i < keys.length; i++) {
95
- let key = keys[i];
96
- let value = row[key];
97
- if (value != null && !isNaN(value)) {
98
- let re = new RegExp(key, 'g');
99
- formula = formula.replace(re, value.toString());
100
- }
101
- }
102
- formula = formula.replace(/[\[\]']+/g, '');
103
- try {
104
- const result = Function('"use strict"; return (' + formula + ')')();
105
- return result;
106
- }
107
- catch (e) {
108
- dom.ketchup.debug.logMessage('kup-data', 'Error while evaluating the following formula!(' +
109
- formula +
110
- ')', KupDebugCategory.ERROR);
111
- return NaN;
112
- }
48
+ this.row = {
49
+ find(dataset, filters) {
50
+ return findRow(dataset, filters);
113
51
  },
114
- /**
115
- * Calculates a single Y point of a normal distribution.
116
- * @param {number} average - Average.
117
- * @param {number} variance - Variance.
118
- * @param {number} x - X coordinate.
119
- * @returns {number} Result.
120
- */
121
- normalDistribution(average, variance, x) {
122
- return ((1 / Math.sqrt(variance * 2 * Math.PI)) *
123
- Math.exp(-Math.pow(x - average, 2) / (2 * variance)));
52
+ toNode(dataset) {
53
+ return toNode(dataset);
124
54
  },
125
55
  };
126
56
  }
127
57
  /**
128
- * Calculates the normal distribution on a set of values.
129
- * @param {string[] | number[] | String[]} values - Array of values.
130
- * @param {number} precision - Number of iterations to run (points). When not specified, defaults to 201.
131
- * @returns {number[][]} Returns an array of arrays containing numbers, which are the representation of the calculated normal distribution.
58
+ * Utility used by findRow and findCell.
59
+ * @param {KupDataDataset} dataset - Input dataset.
60
+ * @param {KupDataFindCellFilters} filters - Filters of the research.
61
+ * @returns {{cells: KupDataCell[], rows: KupDataRow[]}} Object containing rows and cells.
62
+ */
63
+ finder(dataset, filters) {
64
+ const columns = filters ? filters.columns : null;
65
+ const range = filters ? filters.range : null;
66
+ const value = filters ? filters.value : null;
67
+ const min = range && range.min ? range.min : null;
68
+ const max = range && range.max ? range.max : null;
69
+ const result = {
70
+ cells: [],
71
+ rows: [],
72
+ };
73
+ for (let index = 0; index < dataset.rows.length; index++) {
74
+ const row = dataset.rows[index];
75
+ const cells = row.cells;
76
+ for (const key in cells) {
77
+ const cell = cells[key];
78
+ if (!columns || !columns.length || columns.includes(key)) {
79
+ if (min && max) {
80
+ let d = null, s = '', n = 0;
81
+ if (dom.ketchup.objects.isDate(cell.obj)) {
82
+ d = dom.ketchup.dates.toDate(cell.value);
83
+ const dMax = dom.ketchup.dates.toDate(max instanceof String ? max.valueOf() : max);
84
+ const dMin = dom.ketchup.dates.toDate(min instanceof String ? min.valueOf() : min);
85
+ if (d === dMax ||
86
+ d === dMin ||
87
+ (d < dMax && d > dMin)) {
88
+ result.cells.push(cell);
89
+ result.rows.push(row);
90
+ }
91
+ }
92
+ else if (typeof min === 'string' ||
93
+ min instanceof String) {
94
+ s = cell.value;
95
+ if (s === max ||
96
+ s === min ||
97
+ (s < max && s > min)) {
98
+ result.cells.push(cell);
99
+ result.rows.push(row);
100
+ }
101
+ }
102
+ else {
103
+ n = dom.ketchup.math.numberify(cell.value);
104
+ if (n === max ||
105
+ n === min ||
106
+ (n < max && n > min)) {
107
+ result.cells.push(cell);
108
+ result.rows.push(row);
109
+ }
110
+ }
111
+ }
112
+ else if (value === cell.value) {
113
+ result.cells.push(cell);
114
+ result.rows.push(row);
115
+ }
116
+ }
117
+ }
118
+ }
119
+ return result;
120
+ }
121
+ /**
122
+ * Creates a new dataset with an amount of cells equal to a distinct calculation applied to the given columns.
123
+ * The original value of cells will be stored in the title property of the new cells.
124
+ * @param {KupDataDataset} dataset - Input dataset.
125
+ * @param {string[]} columns - Column names to manage. When missing, defaults to all columns.
126
+ * @param {KupDataColumn} valuesColumn - When present, this column will be included in the final dataset containing the original values of the cells.
127
+ * @returns {KupDataDataset} New dataset with processed data.
132
128
  */
133
- normalDistribution(values, precision) {
134
- if (!precision) {
135
- precision = 201;
129
+ distinct(dataset, columns, valuesColumn) {
130
+ const occurrencies = {};
131
+ const rows = dataset.rows;
132
+ for (let index = 0; index < rows.length; index++) {
133
+ const row = rows[index];
134
+ const cells = row.cells;
135
+ for (const key in cells) {
136
+ const cell = cells[key];
137
+ if (!columns ||
138
+ !columns.length ||
139
+ (columns && columns.includes(key))) {
140
+ if (!occurrencies[key]) {
141
+ occurrencies[key] = {};
142
+ }
143
+ const occurrency = occurrencies[key];
144
+ occurrency[cell.value] = occurrency[cell.value]
145
+ ? occurrency[cell.value] + 1
146
+ : 1;
147
+ }
148
+ }
136
149
  }
137
- const data = [];
138
- let max = Math.max.apply(Math, values);
139
- let min = Math.min.apply(Math, values);
140
- let average = 0;
141
- let variance = 0;
142
- for (let index = 0; index < values.length; index++) {
143
- const value = values[index];
144
- average += this.numberify(value);
150
+ const newColumns = [];
151
+ const newRows = [];
152
+ if (valuesColumn) {
153
+ newColumns.push(valuesColumn);
145
154
  }
146
- average = average / values.length;
147
- for (let index = 0; index < values.length; index++) {
148
- const value = values[index];
149
- variance += Math.pow(this.numberify(value) - average, 2);
155
+ for (const key in occurrencies) {
156
+ const occurrency = occurrencies[key];
157
+ const column = Object.assign({}, dataset.columns.find((col) => col.name === key));
158
+ column.obj = {
159
+ t: 'NR',
160
+ p: '',
161
+ k: '',
162
+ };
163
+ let rowIndex = 0;
164
+ newColumns.push(column);
165
+ for (const j in occurrency) {
166
+ const value = occurrency[j];
167
+ let row = null;
168
+ if (!newRows[rowIndex]) {
169
+ newRows[rowIndex] = { cells: {} };
170
+ }
171
+ row = newRows[rowIndex];
172
+ row.cells[key] = {
173
+ obj: {
174
+ t: 'NR',
175
+ p: '',
176
+ k: value.toString(),
177
+ },
178
+ title: j,
179
+ value: value.toString(),
180
+ };
181
+ if (valuesColumn) {
182
+ row.cells[valuesColumn.name] = {
183
+ value: j,
184
+ };
185
+ }
186
+ rowIndex++;
187
+ }
150
188
  }
151
- variance = variance / values.length;
152
- if (!variance) {
153
- variance = 0.001;
189
+ return {
190
+ columns: newColumns,
191
+ rows: newRows,
192
+ };
193
+ }
194
+ /**
195
+ * Creates a new dataset from the input one.
196
+ * The new columns are to be specified in the columns argument along with their creation criteria.
197
+ * @param {KupDataDataset} dataset - Input dataset.
198
+ * @param {KupDataNewColumn[]} newColumns - Array containing the specifics of the new columns to be created.
199
+ * @returns {KupDataDataset} Resulting dataset.
200
+ */
201
+ new(dataset, newColumns) {
202
+ const outputColumns = [];
203
+ const outputRows = [];
204
+ for (let index = 0; index < newColumns.length; index++) {
205
+ const newColumn = newColumns[index].column;
206
+ const criteria = newColumns[index].criteria;
207
+ const cells = findCell(dataset, criteria);
208
+ let rowIndex = 0;
209
+ for (let index = 0; index < cells.length; index++) {
210
+ const cell = cells[index];
211
+ let outputRow = null;
212
+ if (!outputRows[rowIndex]) {
213
+ outputRows[rowIndex] = { cells: {} };
214
+ }
215
+ outputRow = outputRows[rowIndex];
216
+ outputRow.cells[newColumn.name] = JSON.parse(JSON.stringify(cell));
217
+ rowIndex++;
218
+ }
219
+ outputColumns.push(newColumn);
154
220
  }
155
- max = max + ((average / 100) * 50 + (variance / average) * 3);
156
- min = min - ((average / 100) * 50 + (variance / average) * 3);
157
- for (let i = 0; i < precision; i++) {
158
- const x = ((max - min) * i) / precision + min;
159
- data.push([
160
- x,
161
- this.formulas.normalDistribution(average, variance, x),
162
- ]);
221
+ return {
222
+ columns: outputColumns,
223
+ rows: outputRows,
224
+ };
225
+ }
226
+ /**
227
+ * Performs a distinct/count after previously grouping columns by ranges.
228
+ * @param {KupDataDataset} dataset - Input dataset.
229
+ * @param {KupDataNewColumn[]} rangeColumns - A list of columns coupled with their criteria for creation. These are used to define ranges.
230
+ * @param {KupDataColumn} resultingColumn - The resulting column.
231
+ * @param {KupDataColumn} valuesColumn - When present, this column will be included in the final dataset containing the original values of the cells.
232
+ * @returns {KupDataDataset} New dataset with processed data.
233
+ */
234
+ rangedDistinct(dataset, rangeColumns, resultingColumn, valuesColumn) {
235
+ const newD = this.new(dataset, rangeColumns);
236
+ const columnNames = [];
237
+ for (let index = 0; index < rangeColumns.length; index++) {
238
+ const newColumn = rangeColumns[index].column;
239
+ columnNames.push(newColumn.name);
240
+ replaceCell(newD, { value: newColumn.title }, [newColumn.name]);
163
241
  }
164
- return data;
242
+ newColumn(newD, KupDataNewColumnTypes.MERGE, {
243
+ columns: columnNames,
244
+ newColumn: resultingColumn,
245
+ });
246
+ return this.distinct(newD, null, valuesColumn);
165
247
  }
166
248
  /**
167
- * Returns a number from a non-specified input type between string, number, or String.
168
- * @param {string | String | number} input - Input value to numberify.
169
- * @returns {number} Resulting number or NaN (when not a number).
249
+ * Creates a new dataset with sorted elements.
250
+ * @param {KupDataDataset} dataset Input dataset.
251
+ * @param {KupDataDatasetSort} sortType Type of sort to apply.
252
+ * @param {string} headerColumn The column used for sorting.
253
+ * @returns {KupDataDataset} Sorted dataset.
170
254
  */
171
- numberify(input) {
172
- const n = this.numeral(input).value();
173
- if (n === null) {
174
- return NaN;
255
+ sort(dataset, sortType, headerColumn) {
256
+ if (sortType != 'normalDistribution') {
257
+ const message = 'Wrong sort type! (' + sortType + ')';
258
+ dom.ketchup.debug.logMessage('kup-data', message, KupDebugCategory.WARNING);
259
+ return dataset;
260
+ }
261
+ const output = {
262
+ columns: JSON.parse(JSON.stringify(dataset.columns)),
263
+ rows: [],
264
+ };
265
+ const length = dataset.rows.length;
266
+ // sort all columns values by descending
267
+ let values = getCellValue(dataset, [headerColumn]);
268
+ values.sort(function (a, b) {
269
+ return Number(a) - Number(b);
270
+ });
271
+ values.reverse();
272
+ // excluding duplicates values.
273
+ values = [...new Set(values)];
274
+ // calculating middle index
275
+ const idx = Math.floor(length / 2);
276
+ let lastIdx = idx - 1;
277
+ let leftIdx = idx - 1;
278
+ let rightIdx = idx + 1;
279
+ // sort the rows like a "mountain", the greatest is in the middle and the other ones are splitted left and right
280
+ for (let i = 0; i < length; i++) {
281
+ const value = values[i];
282
+ // looping the rows because we have many rows with same value.
283
+ this.finder(dataset, {
284
+ columns: [headerColumn],
285
+ value: value,
286
+ }).rows.forEach((row) => {
287
+ const xC = output.rows[idx];
288
+ if (xC == null) {
289
+ output.rows[idx] = JSON.parse(JSON.stringify(row));
290
+ }
291
+ else {
292
+ output.rows[lastIdx] = JSON.parse(JSON.stringify(row));
293
+ if (lastIdx > idx) {
294
+ // right from the middle index.
295
+ lastIdx = leftIdx;
296
+ rightIdx++;
297
+ }
298
+ else {
299
+ // left from the middle index.
300
+ lastIdx = rightIdx;
301
+ leftIdx--;
302
+ }
303
+ }
304
+ });
175
305
  }
176
- return n;
306
+ return output;
177
307
  }
178
308
  /**
179
- * Formats the input number with the specified format of the currently set locale.
180
- * @param {string | String | number} input - Input number which will be automatically "numberified".
181
- * @param {string} format - Desired format. Defaults to '0,0.0' (i.e.: 2,000,000.51)
182
- * @returns {string} Formatted number.
309
+ * Creates a new dataset with transposed columns and rows.
310
+ * @param {KupDataDataset} dataset - Input dataset.
311
+ * @param {string} headerColumn - When specified, it will be the column used as header. When missing, the header will be a series of progressive numbers.
312
+ * @returns {KupDataDataset} Transposed dataset.
183
313
  */
184
- format(input, format) {
185
- const n = this.numberify(input);
186
- if (!format) {
187
- const positiveN = Math.abs(n);
188
- const decimals = positiveN - Math.floor(positiveN);
189
- if (decimals) {
190
- format = '0,0.0';
314
+ transpose(dataset, headerColumn) {
315
+ const transposed = { columns: [], rows: [] };
316
+ let firstColumn = null;
317
+ if (headerColumn) {
318
+ firstColumn = findColumns(dataset, { name: headerColumn })[0];
319
+ transposed.columns.push(firstColumn);
320
+ for (let index = 0; index < dataset.rows.length; index++) {
321
+ const row = dataset.rows[index];
322
+ const cell = row.cells[firstColumn.name];
323
+ const title = cell.displayedValue
324
+ ? cell.displayedValue
325
+ : cell.value;
326
+ transposed.columns.push({
327
+ name: cell.value + '_' + row.id,
328
+ title,
329
+ });
330
+ }
331
+ }
332
+ else {
333
+ firstColumn = {
334
+ name: fieldColumn.toUpperCase(),
335
+ title: fieldColumn,
336
+ };
337
+ transposed.columns.push(firstColumn);
338
+ for (let index = 0; index < dataset.rows.length; index++) {
339
+ const row = dataset.rows[index];
340
+ transposed.columns.push({
341
+ name: row.id,
342
+ title: '#' + index,
343
+ });
344
+ }
345
+ }
346
+ for (let index = headerColumn ? 1 : 0; index < dataset.columns.length; index++) {
347
+ const oldColumn = dataset.columns[index];
348
+ const cells = {};
349
+ cells[firstColumn.name] = {
350
+ value: oldColumn.title,
351
+ };
352
+ for (let index = 1; index < transposed.columns.length; index++) {
353
+ const newColumn = transposed.columns[index];
354
+ const oldRow = dataset.rows[index - 1];
355
+ const cellName = headerColumn ? newColumn.name : oldRow.id;
356
+ cells[cellName] = oldRow.cells[oldColumn.name];
357
+ if (oldColumn.icon && !cells[cellName].icon) {
358
+ cells[cellName].icon = oldColumn.icon;
359
+ }
360
+ if (oldColumn.shape && !cells[cellName].shape) {
361
+ cells[cellName].shape = oldColumn.shape;
362
+ }
363
+ }
364
+ // If a record is key and no column argument is provided, it will be placed on top
365
+ if (!headerColumn && oldColumn.isKey) {
366
+ transposed.rows.unshift({
367
+ id: String(index),
368
+ cells,
369
+ transposedColumnName: oldColumn.name,
370
+ });
191
371
  }
192
372
  else {
193
- format = '0,0';
373
+ transposed.rows.push({
374
+ id: String(index),
375
+ cells,
376
+ transposedColumnName: oldColumn.name,
377
+ });
194
378
  }
195
379
  }
196
- const formatted = this.numeral(n).format(format);
197
- this.numeral.locale('en'); // TODO: Remove when KupData locale is handled [KupDataLocale]
198
- return formatted;
380
+ return transposed;
199
381
  }
200
382
  }
@@ -314,7 +314,7 @@ export class KupDates {
314
314
  * @param {any} component - The Ketchup component to be registered.
315
315
  */
316
316
  register(component) {
317
- this.managedComponents.add(component.rootElement);
317
+ this.managedComponents.add(component.rootElement ? component.rootElement : component);
318
318
  }
319
319
  /**
320
320
  * Unregisters a KupComponent, so it won't be refreshed when the locale changes.
@@ -323,7 +323,7 @@ export class KupDates {
323
323
  */
324
324
  unregister(component) {
325
325
  if (this.managedComponents) {
326
- this.managedComponents.delete(component.rootElement);
326
+ this.managedComponents.delete(component.rootElement ? component.rootElement : component);
327
327
  }
328
328
  }
329
329
  }
@@ -64,29 +64,29 @@ export class KupDebug {
64
64
  const languagesListData = [];
65
65
  for (let index = 0; index < languages.length; index++) {
66
66
  languagesListData.push({
67
- text: languages[index],
68
- value: languages[index],
67
+ id: languages[index],
69
68
  selected: languages[index] === dom.ketchup.language.name
70
69
  ? true
71
70
  : false,
71
+ value: languages[index],
72
72
  });
73
73
  }
74
74
  const themes = dom.ketchup.theme.getThemes();
75
75
  const themesListData = [];
76
76
  for (let index = 0; index < themes.length; index++) {
77
77
  themesListData.push({
78
- text: themes[index],
79
- value: themes[index],
78
+ id: themes[index],
80
79
  selected: themes[index] === dom.ketchup.theme.name ? true : false,
80
+ value: themes[index],
81
81
  });
82
82
  }
83
83
  const locales = dom.ketchup.dates.getLocales();
84
84
  const localesListData = [];
85
85
  for (let index = 0; index < locales.length; index++) {
86
86
  localesListData.push({
87
- text: locales[index],
88
- value: locales[index],
87
+ id: locales[index],
89
88
  selected: locales[index] === dom.ketchup.dates.locale ? true : false,
89
+ value: locales[index],
90
90
  });
91
91
  }
92
92
  debugWidget.data = {
@@ -40,7 +40,7 @@ export class KupDynamicPosition {
40
40
  if (this.anchorIsHTMLElement(anchorEl)) {
41
41
  anchorEl.setAttribute(kupDynamicPositionAnchorAttribute, '');
42
42
  }
43
- el.style.zIndex = `calc(var(--kup-navbar-zindex) - 1)`;
43
+ el.style.zIndex = `calc(var(--kup-navbar-zindex) + 1)`;
44
44
  const originalPath = [];
45
45
  if (detach) {
46
46
  let currentEl = el;
@@ -136,7 +136,7 @@ export class KupLanguage {
136
136
  * @param {any} component - The component calling this function.
137
137
  */
138
138
  register(component) {
139
- this.managedComponents.add(component.rootElement);
139
+ this.managedComponents.add(component.rootElement ? component.rootElement : component);
140
140
  }
141
141
  /**
142
142
  * Unregisters a KupComponent, so it won't be refreshed when the language changes.
@@ -145,7 +145,7 @@ export class KupLanguage {
145
145
  */
146
146
  unregister(component) {
147
147
  if (this.managedComponents) {
148
- this.managedComponents.delete(component.rootElement);
148
+ this.managedComponents.delete(component.rootElement ? component.rootElement : component);
149
149
  }
150
150
  }
151
151
  }
@@ -13,6 +13,8 @@ import { KupDates } from '../kup-dates/kup-dates';
13
13
  import { KupDatesLocales } from '../kup-dates/kup-dates-declarations';
14
14
  import { KupDebugCategory } from '../kup-debug/kup-debug-declarations';
15
15
  import { KupSearch } from '../kup-search/kup-search';
16
+ import { KupMathLocales } from '../kup-math/kup-math-declarations';
17
+ import { KupMath } from '../kup-math/kup-math';
16
18
  const dom = document.documentElement;
17
19
  /**
18
20
  * This class controls every other Ketchup utility suite.
@@ -73,6 +75,7 @@ export class KupManager {
73
75
  this.interact = new KupInteract(dialogZIndex, dialogRestrictContainer);
74
76
  this.language = new KupLanguage(languageList, languageName);
75
77
  this.magicBox = null;
78
+ this.math = new KupMath();
76
79
  this.overrides = overrides ? overrides : null;
77
80
  this.objects = new KupObjects(objectsList);
78
81
  this.resize = new ResizeObserver((entries) => {
@@ -198,6 +201,7 @@ export class KupManager {
198
201
  }
199
202
  this.dates.setLocale(locale);
200
203
  this.language.set(KupLanguageDefaults[locale]);
204
+ this.math.setLocale(KupMathLocales[locale]);
201
205
  }
202
206
  /**
203
207
  * Adds a new click callback.
@@ -237,6 +241,15 @@ export function kupManagerInstance() {
237
241
  dom.ketchup.debug.toggle(dom.ketchup.debug.active);
238
242
  }
239
243
  globalThis.kupManager = dom.ketchup;
244
+ if (overrides && overrides.autoSetLocalization) {
245
+ const locale = dom.ketchup.dates.locale;
246
+ if (!overrides.language || !overrides.language.name) {
247
+ dom.ketchup.language.set(KupLanguageDefaults[locale]);
248
+ }
249
+ if (!overrides.math || !overrides.math.locale) {
250
+ dom.ketchup.math.setLocale(KupMathLocales[locale]);
251
+ }
252
+ }
240
253
  document.dispatchEvent(new CustomEvent('kup-manager-ready'));
241
254
  }
242
255
  return dom.ketchup;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Locales available for KupMath.
3
+ */
4
+ export var KupMathLocales;
5
+ (function (KupMathLocales) {
6
+ KupMathLocales["cn"] = "chs";
7
+ KupMathLocales["en"] = "en";
8
+ KupMathLocales["es"] = "es";
9
+ KupMathLocales["it"] = "it";
10
+ KupMathLocales["fr"] = "fr";
11
+ KupMathLocales["pl"] = "pl";
12
+ KupMathLocales["ru"] = "ru";
13
+ })(KupMathLocales || (KupMathLocales = {}));