@scality/core-ui 0.186.0 → 0.187.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 +73 -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 +180 -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,579 +0,0 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- // @ts-nocheck
3
- import { useMemo, useRef, useLayoutEffect, Fragment } from 'react';
4
- import styled, { useTheme } from 'styled-components';
5
- import { lighten, darken } from 'polished';
6
- import { expressionFunction } from 'vega';
7
- import { lineColor1, lineColor2, lineColor3, lineColor4, lineColor5, lineColor6, lineColor7, lineColor8, } from '../../style/theme';
8
- import { VegaChart } from '../vegachartv2/VegaChartV2.component';
9
- import { useCursorX } from '../vegachartv2/SyncedCursorCharts';
10
- import { ChartTitleText } from '../text/Text.component';
11
- import { convert2VegaData, getUnitLabel, convertDataBaseValue, addMissingDataPoint, getRelativeValue, getColorDomains, relativeDatumToOriginalDatum, normlizeVegaFieldName, } from './ChartUtil';
12
- import { useMetricsTimeSpan } from './MetricTimespanProvider';
13
- import { spacing } from '../../spacing';
14
- import { SmallerText } from '../text/Text.component';
15
- import { Loader } from '../loader/Loader.component';
16
- import { formatValue } from './tooltip/index';
17
- import { Tooltip as TooltipComponent } from '../tooltip/Tooltip.component';
18
- import { Icon } from '../icon/Icon.component';
19
- // some predefined values
20
- export const YAXIS_TITLE_READ_WRITE = 'write(+) / read(-)';
21
- export const YAXIS_TITLE_IN_OUT = 'in(+) / out(-)';
22
- export const UNIT_RANGE_BS = [
23
- {
24
- threshold: 0,
25
- label: 'B/s',
26
- },
27
- {
28
- threshold: 1024,
29
- label: 'KiB/s',
30
- },
31
- {
32
- threshold: 1024 * 1024,
33
- label: 'MiB/s',
34
- },
35
- {
36
- threshold: 1024 * 1024 * 1024,
37
- label: 'GiB/s',
38
- },
39
- {
40
- threshold: 1024 * 1024 * 1024 * 1024,
41
- label: 'TiB/s',
42
- },
43
- ];
44
- const LineTemporalChartWrapper = styled.div `
45
- display: flex;
46
- flex-direction: column;
47
- justify-content: flex-start; // to make sure the header, the graph itself and legend are aligned
48
- `;
49
- const Legends = styled.div `
50
- display: flex;
51
- align-items: center;
52
- `;
53
- const LegendStroke = styled.div `
54
- margin: 0 ${spacing.r8} 0 ${spacing.r16};
55
- height: ${spacing.r2};
56
- background: ${(props) => props.isLineDashed
57
- ? `repeating-linear-gradient(to right,${props.lineColor} 0,${props.lineColor} ${spacing.r1},transparent ${spacing.r1},transparent ${spacing.r2})`
58
- : props.lineColor};
59
- width: ${spacing.r8};
60
- `;
61
- const ChartHeader = styled.div `
62
- display: flex;
63
- align-items: center;
64
- `;
65
- // Custom formatter to display negative value as an absolute value in read/write, in/out chart
66
- expressionFunction('negativeValueFormatter', function (datum) {
67
- return Math.abs(datum).toFixed(2);
68
- });
69
- // We use 8 main color from the palette and decline them (lighter/ darker) when we have more than 8 datasets
70
- const colorRange = [
71
- lineColor1,
72
- lineColor2,
73
- lineColor3,
74
- lineColor4,
75
- lineColor5,
76
- lineColor6,
77
- lineColor7,
78
- lineColor8,
79
- lighten(0.3, lineColor1),
80
- lighten(0.3, lineColor2),
81
- lighten(0.3, lineColor3),
82
- lighten(0.3, lineColor4),
83
- lighten(0.3, lineColor5),
84
- lighten(0.3, lineColor6),
85
- lighten(0.3, lineColor7),
86
- lighten(0.3, lineColor8),
87
- darken(0.2, lineColor1),
88
- darken(0.2, lineColor2),
89
- darken(0.2, lineColor3),
90
- darken(0.2, lineColor4),
91
- darken(0.3, lineColor5),
92
- darken(0.3, lineColor6),
93
- darken(0.3, lineColor7),
94
- darken(0.3, lineColor8),
95
- ];
96
- // Note: we need to make sure the start time and end timefor the prometheus query between the series are the same.
97
- /**
98
- * @deprecated Use LineTimeSerieChart instead
99
- * @example import { LineTimeSerieChart } from '@scality/core-ui/dist/next';
100
- */
101
- function LineTemporalChart({ series, title, height, startingTimeStamp, unitRange, isLoading = false, isLegendHidden = false, yAxisType = 'default', yAxisTitle, helpText, renderTooltipSerie, onHover, ...rest }) {
102
- // property validation
103
- if (!['default', 'percentage', 'symmetrical'].includes(yAxisType)) {
104
- console.error(`Invalid yAxisType props, expected default, percentage or symmetrical but received ${yAxisType}`);
105
- }
106
- if (!height) {
107
- console.error('Please specify the height of the chart.');
108
- }
109
- if (!title) {
110
- console.error('Please specify the title of the chart.');
111
- }
112
- // we have to make sure that when prop unitRange exists, there is at least one item defined.
113
- if (unitRange) {
114
- if (unitRange.length === 0) {
115
- console.error('Please provide at least one entry in unitRange.');
116
- }
117
- }
118
- const vegaViewRef = useRef();
119
- const theme = useTheme();
120
- const { frequency, duration } = useMetricsTimeSpan();
121
- //##### Data Transformation Start
122
- /**
123
- * 1. Add missing data points
124
- * During the downtime of the platform, there is no data returned by Prometheus API.
125
- * Hence, we can see a line link the last data point before the downtime and the first data point once the platform restarts.
126
- * However, this is not what we expect to see.
127
- * So we need to manually add the missing data points with the value `null` to make sure there is nothing displayed on the graph during the downtime.
128
- */
129
- const addedMissingDataPointSeries = useMemo(() => {
130
- return series.map((line) => {
131
- return {
132
- ...line,
133
- data: addMissingDataPoint(line.data, startingTimeStamp, duration, frequency),
134
- };
135
- });
136
- }, [series, startingTimeStamp, duration, frequency]);
137
- // 2. Change the data structure to a flat array which is required by Vega-lite
138
- const vegaData = useMemo(() => {
139
- return convert2VegaData(addedMissingDataPointSeries);
140
- }, [addedMissingDataPointSeries]);
141
- // 3. Search for the biggest value in order to define the unit for the chart, if the unit is needed.
142
- const maxValue = useMemo(() => {
143
- return Math.max.apply(Math, vegaData.map(function (datum) {
144
- if (datum.value && typeof datum.value === 'number') {
145
- return datum.value;
146
- }
147
- return 0;
148
- }));
149
- }, [vegaData]);
150
- // 4. Recompute the value base on the unit
151
- const valueBase = useMemo(() => {
152
- return unitRange ? getUnitLabel(unitRange, maxValue).valueBase : 1;
153
- }, [maxValue, unitRange]);
154
- const vegaDataWithUnit = unitRange
155
- ? convertDataBaseValue(vegaData, valueBase)
156
- : vegaData;
157
- // 5. Convert the values of metric prefix `read` and `out` to negative.
158
- const vegaSpecValues = vegaDataWithUnit.map((data) => {
159
- if (data.isNegativeValue &&
160
- data.value &&
161
- typeof data.value === 'number') {
162
- return { ...data, value: 0 - data.value };
163
- }
164
- else
165
- return { ...data };
166
- });
167
- //##### Data Transformation End
168
- const customizedColorRange = useMemo(() => {
169
- const customizedColors = [];
170
- series.map((line) => {
171
- if (line.color) {
172
- return customizedColors.push(line.color);
173
- }
174
- });
175
- return customizedColors;
176
- }, [series]);
177
- // $FlowFixMe
178
- const seriesResources = [...new Set(series.map((serie) => serie.resource))];
179
- // for the series with the same resource, the color of legend and tooltip should be the same.
180
- const legendLabels = useMemo(() => {
181
- const uniqueLabel = [];
182
- series.forEach((serie, index) => {
183
- if (serie.getLegendLabel) {
184
- const legend = serie.getLegendLabel(serie.metricPrefix, serie.resource);
185
- if (!uniqueLabel.find((uLabel) => uLabel === legend)) {
186
- const serieIndex = yAxisType === 'symmetrical' && !customizedColorRange.length
187
- ? seriesResources.findIndex((serieResource) => serieResource === serie.resource)
188
- : index;
189
- uniqueLabel.push({
190
- legend,
191
- serie,
192
- serieIndex,
193
- });
194
- }
195
- }
196
- });
197
- return uniqueLabel;
198
- }, [series]);
199
- const tooltipLabels = useMemo(() => series.map((line) => {
200
- return line.getTooltipLabel(line.metricPrefix, line.resource);
201
- }), [series]);
202
- const syncedVerticalRuler = {
203
- mark: 'rule',
204
- encoding: {
205
- x: {
206
- datum: {
207
- expr: 'toDate(cursorX)',
208
- }, // convert the timestamp in milliseconds to Date object
209
- //https://vega.github.io/vega-lite/docs/datetime.html
210
- },
211
- color: {
212
- value: theme.selectedActive,
213
- },
214
- /*
215
- According to the design, the vertical ruler should be hided when the mouse points out of the graph area.
216
- We can use param `isCursorDisplayed` to control the size of the vertical line.
217
- */
218
- size: {
219
- value: 0,
220
- condition: {
221
- test: 'isCursorDisplayed',
222
- value: 1,
223
- },
224
- },
225
- },
226
- };
227
- const syncedVerticalRulerPercentage = {
228
- mark: 'rule',
229
- encoding: {
230
- x: {
231
- datum: {
232
- expr: 'toDate(cursorX)',
233
- }, // convert the timestamp to Date object
234
- },
235
- // We draw the line manually for the percentage chart to solve the issue that the synced vertical line can
236
- // only reach the max value one the line.
237
- y: {
238
- datum: 0,
239
- },
240
- y2: {
241
- datum: 100,
242
- },
243
- color: {
244
- value: theme.highlight,
245
- opacity: 0.3,
246
- },
247
- /*
248
- According to the design, the vertical ruler should be hided when the mouse points out of the graph area.
249
- We can use param `isCursorDisplayed` to control the size of the vertical line.
250
- */
251
- size: {
252
- value: 0,
253
- condition: {
254
- test: 'isCursorDisplayed',
255
- value: 1,
256
- },
257
- },
258
- },
259
- };
260
- const syncedVerticalRulerSymmetrical = {
261
- mark: 'rule',
262
- encoding: {
263
- x: {
264
- datum: {
265
- expr: 'toDate(cursorX)',
266
- }, // convert the timestamp to Date object
267
- },
268
- y: {
269
- expr: '-yAxisMaxValue',
270
- },
271
- y2: {
272
- expr: 'yAxisMaxValue',
273
- },
274
- color: {
275
- value: theme.highlight,
276
- opacity: 0.3,
277
- },
278
- /*
279
- According to the design, the vertical ruler should be hided when the mouse points out of the graph area.
280
- We can use param `isCursorDisplayed` to control the size of the vertical line.
281
- */
282
- size: {
283
- value: 0,
284
- condition: {
285
- test: 'isCursorDisplayed',
286
- value: 1,
287
- },
288
- },
289
- },
290
- };
291
- const xAxis = {
292
- field: 'timestamp',
293
- type: 'temporal',
294
- axis: {
295
- // Refer to all the available time format: https://github.com/d3/d3-time-format#locale_format
296
- format: '%d %b %H:%M',
297
- ticks: true,
298
- tickCount: 5,
299
- labelColor: theme.textSecondary,
300
- // TODO: labelFontSize is not responsiveness
301
- labelSeparation: 12, // The minimum separation that must be between label bounding boxes for them to be considered non-overlapping (default 0). This property is ignored if labelOverlap resolution is not enabled.
302
- },
303
- title: null,
304
- };
305
- const yAxis = useMemo(() => {
306
- return {
307
- field: 'value',
308
- type: 'quantitative',
309
- axis: {
310
- title: yAxisTitle ? yAxisTitle : ' ',
311
- orient: 'right',
312
- translate: -5,
313
- // translate both the x and y coordinates by 5 pixel
314
- tickOffset: 5,
315
- // shift back the y translate to make sure the tick align with the 0 seperation line
316
- labelBaseline: 'middle',
317
- labelPadding: 6,
318
- labelFlush: true,
319
- },
320
- scale: yAxisType === 'symmetrical'
321
- ? {
322
- domain: [
323
- {
324
- expr: '-yAxisMaxValue',
325
- },
326
- {
327
- expr: 'yAxisMaxValue',
328
- },
329
- ],
330
- }
331
- : yAxisType === 'percentage'
332
- ? {
333
- domain: [0, 100],
334
- }
335
- : undefined,
336
- };
337
- }, [yAxisTitle, yAxisType]);
338
- const symmetricalColorRange = yAxisType !== 'symmetrical'
339
- ? colorRange
340
- : series.map((serie) => colorRange[seriesResources.indexOf(serie.resource)]);
341
- const color = {
342
- field: 'label',
343
- type: 'nominal',
344
- scale: {
345
- domain: getColorDomains(series),
346
- // the order of the domain should be the same as the order of colorRange, otherwise the colors will be assigned to the line base on the alphabetical order: ;
347
- range: customizedColorRange.length
348
- ? customizedColorRange
349
- : symmetricalColorRange, //if there is no customized color range, we will use the default the line color
350
- },
351
- legend: null,
352
- };
353
- // In order to add the tooltip we refered this example
354
- // https://vega.github.io/vega-lite/examples/interactive_multi_line_pivot_tooltip.html
355
- const getTooltipConfig = (fields) => {
356
- const tooltipConfigBase = {
357
- // The pivot transform maps unique values from a field to new aggregated fields (columns) in the output stream.
358
- // https://vega.github.io/vega-lite/docs/pivot.html
359
- transform: [
360
- {
361
- pivot: 'label',
362
- value: 'value',
363
- groupby: ['timestamp'],
364
- },
365
- ],
366
- mark: 'rule',
367
- encoding: {
368
- x: xAxis,
369
- opacity: {
370
- // to be check if we can remove this channel, since we don't need to have a rule next to the tooltip
371
- condition: {
372
- value: 0,
373
- selection: 'hover',
374
- },
375
- value: 0,
376
- },
377
- tooltip: [
378
- {
379
- field: 'timestamp',
380
- type: 'temporal',
381
- axis: {
382
- format: '%d %b %H:%M:%S',
383
- ticks: true,
384
- tickCount: 4,
385
- labelAngle: -50,
386
- labelColor: '#B5B5B5',
387
- },
388
- title: 'title',
389
- },
390
- ],
391
- },
392
- selection: {
393
- hover: {
394
- type: 'single',
395
- fields: ['timestamp'],
396
- nearest: true,
397
- on: 'mouseover',
398
- empty: 'none',
399
- clear: 'mouseout',
400
- },
401
- },
402
- };
403
- if (fields.length) {
404
- const newFields = [...tooltipConfigBase.encoding.tooltip, ...fields];
405
- const newConfig = Object.assign({}, tooltipConfigBase);
406
- newConfig.encoding.tooltip = newFields;
407
- return newConfig;
408
- }
409
- return tooltipConfigBase;
410
- };
411
- const tooltipConfig = useMemo(() => getTooltipConfig((() => {
412
- const res = [];
413
- tooltipLabels.forEach((label) => {
414
- res.push({
415
- field: `${normlizeVegaFieldName(label)}`,
416
- type: 'quantitative',
417
- title: `${label}`,
418
- format: '.2f',
419
- formatType: 'negativeValueFormatter',
420
- });
421
- });
422
- return res;
423
- })()), [tooltipLabels]);
424
- // we need to retrieve the vega view in order to update the signal
425
- useLayoutEffect(() => {
426
- if (vegaViewRef.current && yAxisType === 'symmetrical') {
427
- vegaViewRef.current
428
- .signal('yAxisMaxValue', Math.ceil(getRelativeValue(maxValue, valueBase)))
429
- .run();
430
- }
431
- }, [maxValue, valueBase, vegaViewRef, yAxisType]);
432
- // $FlowFixMe
433
- const cursorX = useCursorX().cursorX;
434
- // the specification of the Vega-lite chart
435
- const spec = {
436
- data: {
437
- values: vegaSpecValues,
438
- },
439
- height,
440
- width: 'container',
441
- // set responsive width
442
- mark: {
443
- type: 'line',
444
- tooltip: true,
445
- },
446
- // Add two params to control the display of the vertical ruler.
447
- params: [
448
- {
449
- name: 'cursorX',
450
- value: cursorX || Date.now(), // the value of signal can't be null
451
- },
452
- {
453
- name: 'isCursorDisplayed',
454
- value: false,
455
- },
456
- ],
457
- layer: [
458
- {
459
- encoding: {
460
- x: xAxis,
461
- y: yAxis,
462
- strokeDash: {
463
- field: 'isDashed',
464
- type: 'nominal',
465
- legend: null,
466
- condition: {
467
- test: 'datum.isDashed === true',
468
- value: [4, 2], // Change the value here if the dash is not visible. https://vega.github.io/vega-lite/docs/mark.html#stroke
469
- },
470
- },
471
- color: color,
472
- opacity: {
473
- condition: {
474
- test: 'datum.isDashed === true',
475
- // for the dashed line, set the opacity to 0.5
476
- value: 0.6,
477
- },
478
- value: 1,
479
- },
480
- },
481
- layer: [
482
- {
483
- mark: {
484
- type: 'line',
485
- strokeWidth: 1,
486
- },
487
- }, // the width of the line should be 1px
488
- {
489
- mark: 'point',
490
- encoding: {
491
- size: {
492
- value: 0,
493
- condition: {
494
- selection: 'hover',
495
- value: 10,
496
- },
497
- },
498
- },
499
- },
500
- yAxisType === 'percentage'
501
- ? {
502
- // for percentage chart we need to manually draw the line from 0-100
503
- ...syncedVerticalRuler,
504
- encoding: {
505
- ...syncedVerticalRuler.encoding,
506
- ...syncedVerticalRulerPercentage.encoding,
507
- },
508
- }
509
- : yAxisType === 'symmetrical'
510
- ? {
511
- // for symmetrical chart we manually draw the line from minValue to maxValue
512
- ...syncedVerticalRuler,
513
- encoding: {
514
- ...syncedVerticalRuler.encoding,
515
- ...syncedVerticalRulerSymmetrical.encoding,
516
- },
517
- }
518
- : syncedVerticalRuler,
519
- ],
520
- },
521
- tooltipConfig,
522
- ],
523
- ...rest,
524
- };
525
- // the seperation line for symmetrical charts
526
- const seperationLine = {
527
- mark: 'rule',
528
- encoding: {
529
- y: {
530
- datum: 0,
531
- },
532
- color: {
533
- value: theme.border,
534
- opacity: 1,
535
- },
536
- },
537
- };
538
- if (yAxisType === 'symmetrical') {
539
- spec.layer.unshift(seperationLine);
540
- spec.params.push({
541
- name: 'yAxisMaxValue',
542
- value: Math.ceil(getRelativeValue(maxValue, valueBase)),
543
- });
544
- }
545
- const seriesNames = series
546
- .map((serie) => title + serie.resource + (serie.metricPrefix ? serie.metricPrefix : ''))
547
- .join(',');
548
- const unitLabel = unitRange
549
- ? getUnitLabel(unitRange, maxValue).unitLabel
550
- : yAxisType === 'percentage'
551
- ? '%'
552
- : '';
553
- return (_jsxs(LineTemporalChartWrapper, { children: [_jsxs(ChartHeader, { children: [unitLabel ? (_jsxs(ChartTitleText, { children: [title, " (", unitLabel, ")"] }) // for the chart doesn't have title
554
- ) : (_jsx(ChartTitleText, { children: title })), helpText && (_jsx(TooltipComponent, { placement: "bottom-right", overlay: _jsx(SmallerText, { style: {
555
- minWidth: '15rem',
556
- display: 'block',
557
- }, children: helpText }), children: _jsx(Icon, { name: "Info", color: theme.buttonSecondary }) })), isLoading && (_jsx(Loader, { style: {
558
- paddingLeft: `${spacing.r4}`,
559
- } }))] }), _jsx(VegaChart, { spec: spec, onHover: (datum) => {
560
- if (onHover) {
561
- onHover({
562
- ...datum,
563
- metadata: {
564
- unitLabel,
565
- valueBase,
566
- },
567
- originalData: {
568
- ...relativeDatumToOriginalDatum(datum, valueBase),
569
- timestamp: datum.timestamp,
570
- },
571
- });
572
- }
573
- }, theme: 'custom', ref: vegaViewRef, formatTooltip: useMemo(() => formatValue(series, customizedColorRange, colorRange, unitLabel, yAxisType, renderTooltipSerie), [unitLabel, seriesNames, renderTooltipSerie]) }, seriesNames), !isLegendHidden && (_jsx(Legends, { children: legendLabels.map(({ legend, serie, serieIndex }, index) => {
574
- return (_jsxs(Fragment, { children: [_jsx(LegendStroke, { lineColor: customizedColorRange.length
575
- ? customizedColorRange[serieIndex]
576
- : colorRange[serieIndex], isLineDashed: serie.isLineDashed }), _jsx(SmallerText, { children: legend })] }, `${title}-${legend}-${index}`));
577
- }) }))] }));
578
- }
579
- export { LineTemporalChart };
@@ -1 +0,0 @@
1
- {"version":3,"file":"MetricTimespanProvider.d.ts","sourceRoot":"","sources":["../../../src/lib/components/linetemporalchart/MetricTimespanProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAuB,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,eAAO,MAAM,sBAAsB,+CAA4C,CAAC;AAChF,eAAO,MAAM,uBAAuB,4BAGjC;IACD,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;CAC3C,4CA4BA,CAAC;AACF,eAAO,MAAM,kBAAkB,QAAO,aAUrC,CAAC"}
@@ -1,30 +0,0 @@
1
- import { Options } from 'vega-tooltip';
2
- import { Handler } from 'vega-tooltip';
3
- import { Serie } from '../LineTemporalChart.component';
4
- export declare function defaultRenderTooltipSerie({ color, isLineDashed, name, value, key, }: {
5
- color?: string;
6
- isLineDashed?: boolean;
7
- name: string;
8
- value: string;
9
- key: string;
10
- }): string;
11
- export declare class TooltipHandlerWithPaint extends Handler {
12
- constructor(options?: Options, onHover?: (datum: any) => void);
13
- newCall(handler: any, event: MouseEvent, item: any, value: any): void;
14
- paint(): void;
15
- }
16
- /**
17
- * Format the value to be shown in the tooltip.
18
- *
19
- * @param value The value to show in the tooltip.
20
- * @param valueToHtml Function to convert a single cell value to an HTML string
21
- */
22
- export declare function formatValue(series: Serie[], customizedColorRange: string[], colorRange: string[], unitLabel: string, yAxisType?: 'default' | 'percentage' | 'symmetrical', renderTooltipSerie?: (arg0: {
23
- color?: string;
24
- isLineDashed?: boolean;
25
- name: string;
26
- value: string;
27
- key: string;
28
- unitLabel: string;
29
- }, tooltipData: any) => string): (value: any, valueToHtml: (value: any) => string, maxDepth: number) => string;
30
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/linetemporalchart/tooltip/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,wBAAgB,yBAAyB,CAAC,EACxC,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,KAAK,EACL,GAAG,GACJ,EAAE;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,UAsBA;AACD,qBAAa,uBAAwB,SAAQ,OAAO;gBACtC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI;IAO7D,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG;IAgB9D,KAAK;CAGN;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,KAAK,EAAE,EACf,oBAAoB,EAAE,MAAM,EAAE,EAC9B,UAAU,EAAE,MAAM,EAAE,EACpB,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,aAAa,EACpD,kBAAkB,GAAE,CAClB,IAAI,EAAE;IACJ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB,EACD,WAAW,EAAE,GAAG,KACb,MAAkC,WAG9B,GAAG,eACG,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,YACzB,MAAM,KACf,MAAM,CA8EV"}