@scality/core-ui 0.186.0 → 0.188.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 (171) hide show
  1. package/dist/components/{linetemporalchart/MetricTimespanProvider.d.ts → charts/MetricsTimeSpanProvider.d.ts} +1 -1
  2. package/dist/components/charts/MetricsTimeSpanProvider.d.ts.map +1 -0
  3. package/dist/components/{barchartv2/Barchart.component.d.ts → charts/barchart/Barchart.d.ts} +2 -33
  4. package/dist/components/charts/barchart/Barchart.d.ts.map +1 -0
  5. package/dist/components/charts/barchart/Barchart.js +56 -0
  6. package/dist/components/{barchartv2/utils.d.ts → charts/barchart/Barchart.utils.d.ts} +8 -35
  7. package/dist/components/charts/barchart/Barchart.utils.d.ts.map +1 -0
  8. package/dist/components/{barchartv2/utils.js → charts/barchart/Barchart.utils.js} +7 -88
  9. package/dist/components/{barchartv2 → charts/barchart}/BarchartTooltip.d.ts +2 -1
  10. package/dist/components/charts/barchart/BarchartTooltip.d.ts.map +1 -0
  11. package/dist/components/{barchartv2 → charts/barchart}/BarchartTooltip.js +3 -3
  12. package/dist/components/{charttooltip → charts/common}/ChartTooltip.d.ts +9 -2
  13. package/dist/components/charts/common/ChartTooltip.d.ts.map +1 -0
  14. package/dist/components/{charttooltip → charts/common}/ChartTooltip.js +11 -15
  15. package/dist/components/charts/common/SharedComponents.d.ts +47 -0
  16. package/dist/components/charts/common/SharedComponents.d.ts.map +1 -0
  17. package/dist/components/charts/common/SharedComponents.js +83 -0
  18. package/dist/components/charts/common/chartUtils.d.ts +91 -0
  19. package/dist/components/charts/common/chartUtils.d.ts.map +1 -0
  20. package/dist/components/charts/common/chartUtils.js +243 -0
  21. package/dist/components/{globalhealthbar/GlobalHealthBarRecharts.component.d.ts → charts/globalhealthbar/GlobalHealthBar.d.ts} +2 -2
  22. package/dist/components/charts/globalhealthbar/GlobalHealthBar.d.ts.map +1 -0
  23. package/dist/components/{globalhealthbar/useHealthBarData.d.ts → charts/globalhealthbar/GlobalHealthBar.hooks.d.ts} +1 -1
  24. package/dist/components/charts/globalhealthbar/GlobalHealthBar.hooks.d.ts.map +1 -0
  25. package/dist/components/{globalhealthbar/GlobalHealthBarRecharts.component.js → charts/globalhealthbar/GlobalHealthBar.js} +4 -4
  26. package/dist/components/{globalhealthbar/healthBarUtils.d.ts → charts/globalhealthbar/GlobalHealthBar.utils.d.ts} +1 -1
  27. package/dist/components/charts/globalhealthbar/GlobalHealthBar.utils.d.ts.map +1 -0
  28. package/dist/components/{globalhealthbar/healthBarUtils.js → charts/globalhealthbar/GlobalHealthBar.utils.js} +1 -1
  29. package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/GlobalHealthBarTooltip.d.ts +1 -1
  30. package/dist/components/charts/globalhealthbar/GlobalHealthBarTooltip.d.ts.map +1 -0
  31. package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/GlobalHealthBarTooltip.js +7 -3
  32. package/dist/components/charts/globalhealthbar/HealthBarXAxis.d.ts.map +1 -0
  33. package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/HealthBarXAxis.js +1 -1
  34. package/dist/components/charts/index.d.ts +16 -0
  35. package/dist/components/charts/index.d.ts.map +1 -0
  36. package/dist/components/charts/index.js +15 -0
  37. package/dist/components/{chartlegend → charts/legend}/ChartLegend.d.ts +1 -1
  38. package/dist/components/charts/legend/ChartLegend.d.ts.map +1 -0
  39. package/dist/components/{chartlegend → charts/legend}/ChartLegend.js +2 -2
  40. package/dist/components/{chartlegend → charts/legend}/ChartLegendWrapper.d.ts +1 -1
  41. package/dist/components/charts/legend/ChartLegendWrapper.d.ts.map +1 -0
  42. package/dist/components/{linetimeseriechart/linetimeseriechart.component.d.ts → charts/linetimeseries/LineTimeSerieChart.d.ts} +12 -2
  43. package/dist/components/charts/linetimeseries/LineTimeSerieChart.d.ts.map +1 -0
  44. package/dist/components/{linetimeseriechart/linetimeseriechart.component.js → charts/linetimeseries/LineTimeSerieChart.js} +34 -35
  45. package/dist/components/charts/linetimeseries/LineTimeSerieChart.utils.d.ts +14 -0
  46. package/dist/components/charts/linetimeseries/LineTimeSerieChart.utils.d.ts.map +1 -0
  47. package/dist/components/{linetimeseriechart/utils.js → charts/linetimeseries/LineTimeSerieChart.utils.js} +4 -6
  48. package/dist/components/charts/sparkline/Sparkline.d.ts +23 -0
  49. package/dist/components/charts/sparkline/Sparkline.d.ts.map +1 -0
  50. package/dist/components/{sparkline/sparkline.component.js → charts/sparkline/Sparkline.js} +12 -6
  51. package/dist/components/charts/types.d.ts +34 -0
  52. package/dist/components/charts/types.d.ts.map +1 -0
  53. package/dist/components/charts/types.js +4 -0
  54. package/dist/components/icon/Icon.component.d.ts +1 -0
  55. package/dist/components/icon/Icon.component.d.ts.map +1 -1
  56. package/dist/components/icon/Icon.component.js +2 -2
  57. package/dist/components/textbadge/TextBadge.component.d.ts +1 -1
  58. package/dist/components/textbadge/TextBadge.component.d.ts.map +1 -1
  59. package/dist/index.d.ts +0 -2
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +4 -2
  62. package/dist/next.d.ts +3 -11
  63. package/dist/next.d.ts.map +1 -1
  64. package/dist/next.js +4 -11
  65. package/package.json +2 -6
  66. package/src/lib/components/{barchartv2/Barchart.component.test.tsx → charts/barchart/Barchart.test.tsx} +35 -10
  67. package/src/lib/components/{barchartv2/Barchart.component.tsx → charts/barchart/Barchart.tsx} +42 -207
  68. package/src/lib/components/{barchartv2/utils.test.ts → charts/barchart/Barchart.utils.test.ts} +2 -141
  69. package/src/lib/components/{barchartv2/utils.ts → charts/barchart/Barchart.utils.ts} +17 -143
  70. package/src/lib/components/{barchartv2 → charts/barchart}/BarchartTooltip.tsx +5 -9
  71. package/src/lib/components/{charttooltip → charts/common}/ChartTooltip.tsx +13 -20
  72. package/src/lib/components/charts/common/SharedComponents.tsx +193 -0
  73. package/src/lib/components/charts/common/chartUtils.test.ts +402 -0
  74. package/src/lib/components/charts/common/chartUtils.ts +334 -0
  75. package/src/lib/components/{globalhealthbar/useHealthBarData.spec.tsx → charts/globalhealthbar/GlobalHealthBar.hooks.test.tsx} +1 -1
  76. package/src/lib/components/{globalhealthbar/GlobalHealthBarRecharts.component.tsx → charts/globalhealthbar/GlobalHealthBar.tsx} +4 -4
  77. package/src/lib/components/{globalhealthbar/healthBarUtils.spec.ts → charts/globalhealthbar/GlobalHealthBar.utils.test.ts} +1 -1
  78. package/src/lib/components/{globalhealthbar/healthBarUtils.ts → charts/globalhealthbar/GlobalHealthBar.utils.ts} +1 -1
  79. package/src/lib/components/{globalhealthbar/components → charts/globalhealthbar}/GlobalHealthBarTooltip.tsx +8 -4
  80. package/src/lib/components/{globalhealthbar/components → charts/globalhealthbar}/HealthBarXAxis.tsx +1 -1
  81. package/src/lib/components/charts/index.ts +59 -0
  82. package/src/lib/components/{chartlegend → charts/legend}/ChartLegend.tsx +2 -2
  83. package/src/lib/components/{chartlegend → charts/legend}/ChartLegendWrapper.tsx +1 -1
  84. package/src/lib/components/{linetimeseriechart/linetimeseriechart.test.tsx → charts/linetimeseries/LineTimeSerieChart.test.tsx} +3 -6
  85. package/src/lib/components/{linetimeseriechart/linetimeseriechart.component.tsx → charts/linetimeseries/LineTimeSerieChart.tsx} +48 -44
  86. package/src/lib/components/{linetimeseriechart/utils.test.ts → charts/linetimeseries/LineTimeSerieChart.utils.test.ts} +1 -1
  87. package/src/lib/components/{linetimeseriechart/utils.ts → charts/linetimeseries/LineTimeSerieChart.utils.ts} +4 -6
  88. package/src/lib/components/charts/sparkline/Sparkline.tsx +80 -0
  89. package/src/lib/components/charts/types.ts +36 -0
  90. package/src/lib/components/icon/Icon.component.tsx +12 -8
  91. package/src/lib/components/textbadge/TextBadge.component.tsx +1 -1
  92. package/src/lib/index.ts +4 -2
  93. package/src/lib/next.ts +26 -13
  94. package/stories/BarChart/barchart.stories.tsx +10 -9
  95. package/stories/GlobalHealthBar/{globalhealthbarRecharts.stories.tsx → globalhealthbar.stories.tsx} +3 -21
  96. package/stories/GlobalHealthBar/globalheathbarrecharts.guideline.mdx +2 -2
  97. package/stories/guideline/chart-guideline.mdx +1 -38
  98. package/stories/linetimeseriechart.stories.tsx +4 -6
  99. package/stories/sparkline.stories.tsx +13 -11
  100. package/stories/textbadge.stories.tsx +15 -0
  101. package/dist/components/barchart/BarChart.component.d.ts +0 -17
  102. package/dist/components/barchart/BarChart.component.d.ts.map +0 -1
  103. package/dist/components/barchart/BarChart.component.js +0 -27
  104. package/dist/components/barchartv2/Barchart.component.d.ts.map +0 -1
  105. package/dist/components/barchartv2/Barchart.component.js +0 -122
  106. package/dist/components/barchartv2/BarchartTooltip.d.ts.map +0 -1
  107. package/dist/components/barchartv2/utils.d.ts.map +0 -1
  108. package/dist/components/chartlegend/ChartLegend.d.ts.map +0 -1
  109. package/dist/components/chartlegend/ChartLegendWrapper.d.ts.map +0 -1
  110. package/dist/components/charttooltip/ChartTooltip.d.ts.map +0 -1
  111. package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts +0 -23
  112. package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts.map +0 -1
  113. package/dist/components/globalhealthbar/GlobalHealthBar.component.js +0 -173
  114. package/dist/components/globalhealthbar/GlobalHealthBarRecharts.component.d.ts.map +0 -1
  115. package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.d.ts.map +0 -1
  116. package/dist/components/globalhealthbar/components/HealthBarXAxis.d.ts.map +0 -1
  117. package/dist/components/globalhealthbar/healthBarUtils.d.ts.map +0 -1
  118. package/dist/components/globalhealthbar/healthBarUtils.spec.d.ts +0 -2
  119. package/dist/components/globalhealthbar/healthBarUtils.spec.d.ts.map +0 -1
  120. package/dist/components/globalhealthbar/healthBarUtils.spec.js +0 -391
  121. package/dist/components/globalhealthbar/tooltip/index.d.ts +0 -8
  122. package/dist/components/globalhealthbar/tooltip/index.d.ts.map +0 -1
  123. package/dist/components/globalhealthbar/tooltip/index.js +0 -55
  124. package/dist/components/globalhealthbar/useHealthBarData.d.ts.map +0 -1
  125. package/dist/components/globalhealthbar/useHealthBarData.spec.d.ts +0 -2
  126. package/dist/components/globalhealthbar/useHealthBarData.spec.d.ts.map +0 -1
  127. package/dist/components/globalhealthbar/useHealthBarData.spec.js +0 -209
  128. package/dist/components/linetemporalchart/ChartUtil.d.ts +0 -41
  129. package/dist/components/linetemporalchart/ChartUtil.d.ts.map +0 -1
  130. package/dist/components/linetemporalchart/ChartUtil.js +0 -148
  131. package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts +0 -46
  132. package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts.map +0 -1
  133. package/dist/components/linetemporalchart/LineTemporalChart.component.js +0 -579
  134. package/dist/components/linetemporalchart/MetricTimespanProvider.d.ts.map +0 -1
  135. package/dist/components/linetemporalchart/tooltip/index.d.ts +0 -30
  136. package/dist/components/linetemporalchart/tooltip/index.d.ts.map +0 -1
  137. package/dist/components/linetemporalchart/tooltip/index.js +0 -104
  138. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +0 -1
  139. package/dist/components/linetimeseriechart/utils.d.ts +0 -16
  140. package/dist/components/linetimeseriechart/utils.d.ts.map +0 -1
  141. package/dist/components/sparkline/sparkline.component.d.ts +0 -17
  142. package/dist/components/sparkline/sparkline.component.d.ts.map +0 -1
  143. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts +0 -12
  144. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts.map +0 -1
  145. package/dist/components/vegachartv2/SyncedCursorCharts.js +0 -15
  146. package/dist/components/vegachartv2/VegaChartV2.component.d.ts +0 -15
  147. package/dist/components/vegachartv2/VegaChartV2.component.d.ts.map +0 -1
  148. package/dist/components/vegachartv2/VegaChartV2.component.js +0 -218
  149. package/src/lib/components/barchart/BarChart.component.tsx +0 -51
  150. package/src/lib/components/globalhealthbar/GlobalHealthBar.component.tsx +0 -204
  151. package/src/lib/components/globalhealthbar/tooltip/index.ts +0 -72
  152. package/src/lib/components/linetemporalchart/ChartUtil.test.ts +0 -250
  153. package/src/lib/components/linetemporalchart/ChartUtil.ts +0 -225
  154. package/src/lib/components/linetemporalchart/LineTemporalChart.component.tsx +0 -800
  155. package/src/lib/components/linetemporalchart/tooltip/index.ts +0 -178
  156. package/src/lib/components/sparkline/sparkline.component.tsx +0 -56
  157. package/src/lib/components/vegachartv2/SyncedCursorCharts.tsx +0 -28
  158. package/src/lib/components/vegachartv2/VegaChartV2.component.tsx +0 -276
  159. package/stories/barchart.stories.tsx +0 -142
  160. package/stories/globalhealthbar.stories.tsx +0 -191
  161. package/stories/guideline/mdxExampleComponents.tsx +0 -57
  162. package/stories/linecharttemporal.stories.tsx +0 -88
  163. /package/dist/components/{linetemporalchart/MetricTimespanProvider.js → charts/MetricsTimeSpanProvider.js} +0 -0
  164. /package/dist/components/{globalhealthbar/useHealthBarData.js → charts/globalhealthbar/GlobalHealthBar.hooks.js} +0 -0
  165. /package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/HealthBarXAxis.d.ts +0 -0
  166. /package/dist/components/{chartlegend → charts/legend}/ChartLegendWrapper.js +0 -0
  167. /package/src/lib/components/{linetemporalchart/MetricTimespanProvider.tsx → charts/MetricsTimeSpanProvider.tsx} +0 -0
  168. /package/src/lib/components/{barchartv2 → charts/barchart}/BarchartTooltip.test.tsx +0 -0
  169. /package/src/lib/components/{globalhealthbar/useHealthBarData.ts → charts/globalhealthbar/GlobalHealthBar.hooks.ts} +0 -0
  170. /package/src/lib/components/{chartlegend → charts/legend}/ChartLegend.test.tsx +0 -0
  171. /package/src/lib/components/{chartlegend → charts/legend}/ChartLegendWrapper.test.tsx +0 -0
@@ -1,72 +0,0 @@
1
- // @ts-nocheck
2
- import { stringify } from 'vega-lite';
3
- import { isArray, isObject, isString } from 'vega-util';
4
-
5
- /**
6
- * Format the value to be shown in the tooltip.
7
- *
8
- * @param value The value to show in the tooltip.
9
- * @param valueToHtml Function to convert a single cell value to an HTML string
10
- */
11
- export function formatValue() {
12
- return (
13
- value: any,
14
- valueToHtml: (value: any) => string,
15
- maxDepth: number,
16
- ): string => {
17
- if (isArray(value)) {
18
- return `[${value
19
- .map((v) => valueToHtml(isString(v) ? v : stringify(v, maxDepth)))
20
- .join(', ')}]`;
21
- }
22
-
23
- if (isObject(value)) {
24
- let content = '';
25
- const { title, image, ...rest } = value;
26
-
27
- if (title) {
28
- content += `<h2 style="text-align: center;">${valueToHtml(title)}</h2>`;
29
- }
30
-
31
- if (image) {
32
- content += `<img src="${valueToHtml(image)}">`;
33
- }
34
-
35
- const keys = Object.keys(rest);
36
-
37
- if (keys.length > 0) {
38
- content += '<table>';
39
-
40
- for (const key of keys) {
41
- let val = rest[key];
42
-
43
- // ignore undefined properties
44
- if (val === undefined) {
45
- continue;
46
- }
47
-
48
- if (isObject(val)) {
49
- val = stringify(val, maxDepth);
50
- }
51
-
52
- if (val && val !== 'undefined' && val !== 'null') {
53
- content += `<tr>
54
- <td class="key" style="text-align: left;">
55
- ${valueToHtml(key)}:
56
- </td>
57
- <td class="value" style="text-align: right;">
58
- ${valueToHtml(val)}
59
- </td>
60
- </tr>`;
61
- }
62
- }
63
-
64
- content += `</table>`;
65
- }
66
-
67
- return content || '{}'; // show empty object if there are no properties
68
- }
69
-
70
- return valueToHtml(value);
71
- };
72
- }
@@ -1,250 +0,0 @@
1
- import {
2
- convert2VegaData,
3
- getUnitLabel,
4
- addMissingDataPoint,
5
- } from './ChartUtil';
6
- import { Serie } from './LineTemporalChart.component';
7
- const series: Serie[] = [
8
- {
9
- resource: 'node1',
10
- data: [
11
- [1627460232, '18.73333333333335'],
12
- [1627460952, '18.73333333333335'],
13
- ],
14
- getTooltipLabel: (metricPrefix, resource) => {
15
- return `${resource}`;
16
- },
17
- isLineDashed: false,
18
- },
19
- {
20
- resource: 'node2',
21
- data: [
22
- [1627460232, '18.73333333333335'],
23
- [1627460952, null],
24
- ],
25
- getTooltipLabel: (metricPrefix, resource) => {
26
- return `${resource}`;
27
- },
28
- isLineDashed: false,
29
- },
30
- ];
31
- const seriesSymmetrical: Serie[] = [
32
- {
33
- metricPrefix: 'read',
34
- resource: 'node1',
35
- data: [
36
- [1627460232, '18.73333333333335'],
37
- [1627460952, '18.73333333333335'],
38
- ],
39
- getTooltipLabel: (metricPrefix, resource) => {
40
- return `${resource}-${metricPrefix}`;
41
- },
42
- isLineDashed: false,
43
- },
44
- {
45
- metricPrefix: 'write',
46
- resource: 'node1',
47
- data: [
48
- [1627460232, '18.73333333333335'],
49
- [1627460952, '18.73333333333335'],
50
- ],
51
- getTooltipLabel: (metricPrefix, resource) => {
52
- return `${resource}-${metricPrefix}`;
53
- },
54
- isLineDashed: false,
55
- },
56
- ];
57
- it('converts the series to a flat data structure', () => {
58
- const result = convert2VegaData(series);
59
- expect(result).toEqual([
60
- {
61
- timestamp: 1627460232000,
62
- label: 'node1',
63
- resource: 'node1',
64
- value: 18.73333333333335,
65
- isNegativeValue: false,
66
- isDashed: false,
67
- },
68
- {
69
- timestamp: 1627460952000,
70
- label: 'node1',
71
- resource: 'node1',
72
- value: 18.73333333333335,
73
- isNegativeValue: false,
74
- isDashed: false,
75
- },
76
- {
77
- timestamp: 1627460232000,
78
- label: 'node2',
79
- resource: 'node2',
80
- value: 18.73333333333335,
81
- isNegativeValue: false,
82
- isDashed: false,
83
- },
84
- {
85
- timestamp: 1627460952000,
86
- label: 'node2',
87
- resource: 'node2',
88
- value: 'NAN',
89
- isNegativeValue: false,
90
- isDashed: false,
91
- },
92
- ]);
93
- });
94
- it('converts the series to a flat data structure for symmetrical chart', () => {
95
- const result = convert2VegaData(seriesSymmetrical);
96
- expect(result).toEqual([
97
- {
98
- timestamp: 1627460232000,
99
- label: 'node1-read',
100
- resource: 'node1',
101
- value: 18.73333333333335,
102
- isNegativeValue: true,
103
- isDashed: false,
104
- },
105
- {
106
- timestamp: 1627460952000,
107
- label: 'node1-read',
108
- resource: 'node1',
109
- value: 18.73333333333335,
110
- isNegativeValue: true,
111
- isDashed: false,
112
- },
113
- {
114
- timestamp: 1627460232000,
115
- label: 'node1-write',
116
- resource: 'node1',
117
- value: 18.73333333333335,
118
- isNegativeValue: false,
119
- isDashed: false,
120
- },
121
- {
122
- timestamp: 1627460952000,
123
- label: 'node1-write',
124
- resource: 'node1',
125
- value: 18.73333333333335,
126
- isNegativeValue: false,
127
- isDashed: false,
128
- },
129
- ]);
130
- });
131
- const unitRange = [
132
- {
133
- threshold: 0,
134
- label: 'B/Sec',
135
- },
136
- {
137
- threshold: 1024,
138
- label: 'KiB/Sec',
139
- },
140
- {
141
- threshold: 1024 * 1024,
142
- label: 'MiB/Sec',
143
- },
144
- {
145
- threshold: 1024 * 1024 * 1024,
146
- label: 'GiB/Sec',
147
- },
148
- ];
149
- it('returns the unit label B/Sec with 0 as valueBase', () => {
150
- const maxValue = 1023;
151
- const { unitLabel, valueBase } = getUnitLabel(unitRange, maxValue);
152
- expect(unitLabel).toEqual('B/Sec');
153
- expect(valueBase).toEqual(0);
154
- });
155
- it('returns the unit label KiB/Sec', () => {
156
- const maxValue = 1024;
157
- const { unitLabel, valueBase } = getUnitLabel(unitRange, maxValue);
158
- expect(unitLabel).toEqual('KiB/Sec');
159
- expect(valueBase).toEqual(1024);
160
- });
161
- it('returns the unit label GiB/Sec', () => {
162
- const maxValue = 1024 * 1024 * 1024 + 1;
163
- const { unitLabel, valueBase } = getUnitLabel(unitRange, maxValue);
164
- expect(unitLabel).toEqual('GiB/Sec');
165
- expect(valueBase).toEqual(1024 * 1024 * 1024);
166
- });
167
- // test for addMissingDataPoint function
168
- const originalValue: [number, number | string | null][] = [
169
- [0, '0'],
170
- [1, '1'],
171
- [2, '2'],
172
- [3, '3'],
173
- [4, '4'],
174
- [5, '5'],
175
- [6, '6'],
176
- [8, '8'],
177
- [9, '9'],
178
- [10, '10'],
179
- ];
180
- const startingTimeStamp = 0;
181
- const sampleDuration = 10;
182
- const sampleFrequency = 1;
183
- const newValues = [
184
- [0, '0'],
185
- [1, '1'],
186
- [2, '2'],
187
- [3, '3'],
188
- [4, '4'],
189
- [5, '5'],
190
- [6, '6'],
191
- [7, 'NAN'],
192
- [8, '8'],
193
- [9, '9'],
194
- [10, '10'],
195
- ];
196
- it('should add missing data point with null', () => {
197
- const result = addMissingDataPoint(
198
- originalValue,
199
- startingTimeStamp,
200
- sampleDuration,
201
- sampleFrequency,
202
- );
203
- expect(result).toEqual(newValues);
204
- });
205
- // We manually add
206
- it('should return the array with string NAN when the original dataset is empty', () => {
207
- const result = addMissingDataPoint(
208
- [],
209
- startingTimeStamp,
210
- sampleDuration,
211
- sampleFrequency,
212
- );
213
- expect(result).toEqual([]);
214
- });
215
- it('should return an empty array when the starting timestamp is undefined', () => {
216
- const result = addMissingDataPoint(
217
- originalValue,
218
- undefined,
219
- sampleDuration,
220
- sampleFrequency,
221
- );
222
- expect(result).toEqual([]);
223
- });
224
- it('should return an empty array when sample duration is less than or equal to zero', () => {
225
- const result = addMissingDataPoint(
226
- originalValue,
227
- startingTimeStamp,
228
- 0,
229
- sampleFrequency,
230
- );
231
- expect(result).toEqual([]);
232
- });
233
- it('should return an empty array when sample frequency is less than or equal to zero', () => {
234
- const result = addMissingDataPoint(
235
- originalValue,
236
- startingTimeStamp,
237
- sampleDuration,
238
- -1,
239
- );
240
- expect(result).toEqual([]);
241
- });
242
- it('should return an empty array when sample frequency is undefined', () => {
243
- const result = addMissingDataPoint(
244
- originalValue,
245
- startingTimeStamp,
246
- sampleDuration,
247
- undefined,
248
- );
249
- expect(result).toEqual([]);
250
- });
@@ -1,225 +0,0 @@
1
- // @ts-nocheck
2
- import { Serie } from './LineTemporalChart.component';
3
- import './LineTemporalChart.component';
4
- import { NAN_STRING } from '../constants';
5
- export type VegaData = {
6
- timestamp: number;
7
- label: string;
8
- // same as the tooltip label
9
- value: number | 'NAN';
10
- // the "NAN" is used by the tooltip to display a dash for the data which are not exist.
11
- isNegativeValue: boolean;
12
- // if the metricPrefix is read and out, we need to convert the value to negative before assigning it to the vega-lite spec
13
- isDashed: boolean;
14
- }[];
15
- //Given a field containing dots ".", vega is interpreting this as an accessor
16
- //for nested objects, breaking then the internal mechnism to retrieve tooltip
17
- //data from the mouse position. We are fixing it by replacing the dots by a
18
- //well-known string that we expect no one would use to label a serie.
19
- export function normlizeVegaFieldName(fieldName: string) {
20
- return fieldName.replace(/(\.)/g, 'VEGADOESNTSUPPORTDOTINFIELDNAME');
21
- }
22
- export function convert2VegaData(
23
- addedMissingDataPointSeries: Serie[],
24
- ): VegaData {
25
- const flatArr = [];
26
- addedMissingDataPointSeries.forEach((line) => {
27
- line.data.forEach((datum) => {
28
- const obj = {
29
- timestamp: datum[0] * 1000,
30
- // convert to million second
31
- label: normlizeVegaFieldName(
32
- line.getTooltipLabel(line.metricPrefix, line.resource),
33
- ),
34
- resource: line.resource,
35
- value:
36
- datum[1] && datum[1] !== NAN_STRING ? Number(datum[1]) : NAN_STRING,
37
- isNegativeValue:
38
- line.metricPrefix === 'read' || line.metricPrefix === 'out',
39
- isDashed: line.isLineDashed || false,
40
- };
41
- flatArr.push(obj);
42
- });
43
- });
44
- return flatArr;
45
- }
46
- // base on the current base value, convert the original vegadata to
47
- export function convertDataBaseValue(data: VegaData, base: number): VegaData {
48
- return data.map((datum) => {
49
- return {
50
- ...datum,
51
- value:
52
- typeof datum.value === 'number'
53
- ? getRelativeValue(datum.value, base)
54
- : NAN_STRING,
55
- };
56
- });
57
- }
58
-
59
- /**
60
- * Return the unit label base on the current dataset, and the valueBase which is used to convert the data
61
- * @param {any} unitRange
62
- * @param {any} maxValue the maximum value among the data set
63
- * @returns {any}
64
- */
65
- export function getUnitLabel(
66
- unitRange: {
67
- threshold: number;
68
- label: string;
69
- }[],
70
- maxValue: number,
71
- ): {
72
- valueBase: number;
73
- unitLabel: string;
74
- } {
75
- if (!unitRange || unitRange.length === 0) {
76
- return {
77
- valueBase: 1,
78
- unitLabel: '',
79
- };
80
- }
81
- // first sort the unitRange
82
- unitRange.sort(
83
- (
84
- unitA: {
85
- threshold: number;
86
- label: string;
87
- },
88
- unitB: {
89
- threshold: number;
90
- label: string;
91
- },
92
- ) => {
93
- return unitA.threshold - unitB.threshold;
94
- },
95
- );
96
- let index = unitRange.findIndex((range) => range.threshold > maxValue);
97
-
98
- // last unit
99
- if (index === -1) {
100
- index = unitRange.length;
101
- }
102
-
103
- if (index === 0) {
104
- return {
105
- valueBase: unitRange[index].threshold,
106
- unitLabel: unitRange[index].label,
107
- };
108
- }
109
-
110
- return {
111
- valueBase: unitRange[index - 1].threshold,
112
- unitLabel: unitRange[index - 1].label,
113
- };
114
- }
115
-
116
- /**
117
- * This function manually adds the missing data points with `null` value caused by downtime of the VMs
118
- * Missing data points are only added when the gap between consecutive data points is bigger than 2 intervals
119
- *
120
- * @param {array} orginalValues - The array of the data points are already sorted according to the time series
121
- * @param {number} startingTimeStamp - The starting timestamp in seconds
122
- * @param {number} sampleDuration - The time span value in seconds
123
- * @param {number} sampleInterval - The time difference between two data points in seconds
124
- *
125
- */
126
- export function addMissingDataPoint(
127
- orginalValues: [number, number | string | null][],
128
- startingTimeStamp?: number,
129
- sampleDuration?: number,
130
- sampleInterval?: number,
131
- ): [number, number | string | null][] {
132
- if (
133
- !orginalValues ||
134
- startingTimeStamp === undefined ||
135
- !sampleDuration ||
136
- !sampleInterval ||
137
- startingTimeStamp < 0 ||
138
- sampleDuration <= 0 ||
139
- sampleInterval <= 0
140
- ) {
141
- return [];
142
- }
143
-
144
- // If there are no original values, return empty array
145
- if (orginalValues.length === 0) {
146
- return [];
147
- }
148
-
149
- const newValues: [number, number | string | null][] = [];
150
-
151
- // add missing data points for the starting time
152
- for (
153
- let i = startingTimeStamp;
154
- i < orginalValues[0][0];
155
- i += sampleInterval
156
- ) {
157
- newValues.push([i, NAN_STRING]);
158
- }
159
-
160
- // Process all but the last element
161
- for (let i = 0; i < orginalValues.length - 1; i++) {
162
- if (
163
- orginalValues[i][0] < startingTimeStamp ||
164
- orginalValues[i][0] > startingTimeStamp + sampleDuration
165
- ) {
166
- continue;
167
- }
168
-
169
- // Always add the current data point
170
- newValues.push(orginalValues[i]);
171
-
172
- const currentTimestamp = orginalValues[i][0];
173
- const nextTimestamp = orginalValues[i + 1][0];
174
- const gap = nextTimestamp - currentTimestamp;
175
-
176
- // Calculate how many missing points to add
177
- const missingIntervals = Math.floor(gap / sampleInterval) - 1;
178
-
179
- // Add missing data points with NAN_STRING (only executes if missingIntervals > 0)
180
- for (let j = 1; j <= missingIntervals; j++) {
181
- const missingTimestamp = currentTimestamp + j * sampleInterval;
182
- newValues.push([missingTimestamp, NAN_STRING]);
183
- }
184
- }
185
-
186
- // Add the last element
187
- newValues.push(orginalValues[orginalValues.length - 1]);
188
-
189
- // add missing data points for the ending time
190
- for (
191
- let i = orginalValues[orginalValues.length - 1][0] + sampleInterval;
192
- i < startingTimeStamp + sampleDuration;
193
- i += sampleInterval
194
- ) {
195
- newValues.push([i, NAN_STRING]);
196
- }
197
-
198
- return newValues;
199
- }
200
-
201
- // get the value for the based value
202
- // TODO: We need to handle the negative value in the future
203
- export const getRelativeValue = (value: number, base: number) => {
204
- return value / (base || 1);
205
- };
206
- export const relativeDatumToOriginalDatum = <T>(datum: T, base: number): T => {
207
- // $FlowFixMe
208
- return Object.fromEntries(
209
- Object.entries(datum).map(([key, value]) => [
210
- key,
211
- getAbsoluteValue(value, base),
212
- ]),
213
- );
214
- };
215
- export const getAbsoluteValue = (relativeValue: number, base: number) => {
216
- return relativeValue * (base || 1);
217
- };
218
- // extract the labels from getTooltipLabel function to define the domain in color
219
- export const getColorDomains = (series: Serie[]): string[] => {
220
- return series.map((serie) => {
221
- return normlizeVegaFieldName(
222
- serie.getTooltipLabel(serie.metricPrefix, serie.resource),
223
- );
224
- });
225
- };