@perses-dev/components 0.8.0 → 0.9.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 (131) hide show
  1. package/dist/Drawer/Drawer.d.ts +3 -4
  2. package/dist/Drawer/Drawer.d.ts.map +1 -1
  3. package/dist/Drawer/Drawer.js +35 -1
  4. package/dist/Drawer/Drawer.js.map +1 -0
  5. package/dist/Drawer/index.js +15 -1
  6. package/dist/Drawer/index.js.map +1 -0
  7. package/dist/EChart.d.ts.map +1 -1
  8. package/dist/EChart.js +142 -1
  9. package/dist/EChart.js.map +1 -0
  10. package/dist/ErrorAlert.js +25 -1
  11. package/dist/ErrorAlert.js.map +1 -0
  12. package/dist/ErrorBoundary.js +16 -1
  13. package/dist/ErrorBoundary.js.map +1 -0
  14. package/dist/GaugeChart/GaugeChart.js +172 -1
  15. package/dist/GaugeChart/GaugeChart.js.map +1 -0
  16. package/dist/GaugeChart/index.js +15 -1
  17. package/dist/GaugeChart/index.js.map +1 -0
  18. package/dist/InfoTooltip/InfoTooltip.js +79 -1
  19. package/dist/InfoTooltip/InfoTooltip.js.map +1 -0
  20. package/dist/InfoTooltip/InfoTooltip.test.js +36 -1
  21. package/dist/InfoTooltip/InfoTooltip.test.js.map +1 -0
  22. package/dist/InfoTooltip/index.js +15 -1
  23. package/dist/InfoTooltip/index.js.map +1 -0
  24. package/dist/LineChart/LineChart.js +198 -1
  25. package/dist/LineChart/LineChart.js.map +1 -0
  26. package/dist/LineChart/index.js +15 -1
  27. package/dist/LineChart/index.js.map +1 -0
  28. package/dist/LineChart/utils.js +63 -1
  29. package/dist/LineChart/utils.js.map +1 -0
  30. package/dist/StatChart/StatChart.js +121 -1
  31. package/dist/StatChart/StatChart.js.map +1 -0
  32. package/dist/StatChart/StatChart.test.js +82 -1
  33. package/dist/StatChart/StatChart.test.js.map +1 -0
  34. package/dist/StatChart/index.js +15 -1
  35. package/dist/StatChart/index.js.map +1 -0
  36. package/dist/TimeRangeSelector/AbsoluteTimePicker.js +175 -1
  37. package/dist/TimeRangeSelector/AbsoluteTimePicker.js.map +1 -0
  38. package/dist/TimeRangeSelector/TimeRangeSelector.js +52 -1
  39. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -0
  40. package/dist/TimeRangeSelector/index.js +16 -1
  41. package/dist/TimeRangeSelector/index.js.map +1 -0
  42. package/dist/TimeRangeSelector/utils.js +36 -1
  43. package/dist/TimeRangeSelector/utils.js.map +1 -0
  44. package/dist/Tooltip/SeriesInfo.js +143 -1
  45. package/dist/Tooltip/SeriesInfo.js.map +1 -0
  46. package/dist/Tooltip/SeriesMarker.js +33 -1
  47. package/dist/Tooltip/SeriesMarker.js.map +1 -0
  48. package/dist/Tooltip/Tooltip.js +72 -1
  49. package/dist/Tooltip/Tooltip.js.map +1 -0
  50. package/dist/Tooltip/TooltipContent.js +89 -1
  51. package/dist/Tooltip/TooltipContent.js.map +1 -0
  52. package/dist/Tooltip/focused-series.js +108 -1
  53. package/dist/Tooltip/focused-series.js.map +1 -0
  54. package/dist/Tooltip/focused-series.test.js +75 -1
  55. package/dist/Tooltip/focused-series.test.js.map +1 -0
  56. package/dist/Tooltip/index.js +16 -1
  57. package/dist/Tooltip/index.js.map +1 -0
  58. package/dist/Tooltip/tooltip-model.js +80 -1
  59. package/dist/Tooltip/tooltip-model.js.map +1 -0
  60. package/dist/Tooltip/utils.js +46 -1
  61. package/dist/Tooltip/utils.js.map +1 -0
  62. package/dist/cjs/Drawer/Drawer.js +26 -13
  63. package/dist/cjs/Drawer/index.js +16 -17
  64. package/dist/cjs/EChart.js +114 -89
  65. package/dist/cjs/ErrorAlert.js +16 -12
  66. package/dist/cjs/ErrorBoundary.js +10 -6
  67. package/dist/cjs/GaugeChart/GaugeChart.js +90 -57
  68. package/dist/cjs/GaugeChart/index.js +16 -17
  69. package/dist/cjs/InfoTooltip/InfoTooltip.js +90 -33
  70. package/dist/cjs/InfoTooltip/InfoTooltip.test.js +27 -17
  71. package/dist/cjs/InfoTooltip/index.js +16 -17
  72. package/dist/cjs/LineChart/LineChart.js +122 -87
  73. package/dist/cjs/LineChart/index.js +16 -17
  74. package/dist/cjs/LineChart/utils.js +23 -23
  75. package/dist/cjs/StatChart/StatChart.js +107 -46
  76. package/dist/cjs/StatChart/StatChart.test.js +65 -21
  77. package/dist/cjs/StatChart/index.js +16 -17
  78. package/dist/cjs/TimeRangeSelector/AbsoluteTimePicker.js +144 -64
  79. package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +45 -22
  80. package/dist/cjs/TimeRangeSelector/index.js +17 -18
  81. package/dist/cjs/TimeRangeSelector/utils.js +19 -16
  82. package/dist/cjs/Tooltip/SeriesInfo.js +120 -48
  83. package/dist/cjs/Tooltip/SeriesMarker.js +20 -11
  84. package/dist/cjs/Tooltip/Tooltip.js +95 -67
  85. package/dist/cjs/Tooltip/TooltipContent.js +76 -31
  86. package/dist/cjs/Tooltip/focused-series.js +40 -36
  87. package/dist/cjs/Tooltip/focused-series.test.js +36 -16
  88. package/dist/cjs/Tooltip/index.js +17 -18
  89. package/dist/cjs/Tooltip/tooltip-model.js +46 -30
  90. package/dist/cjs/Tooltip/utils.js +13 -16
  91. package/dist/cjs/context/ChartsThemeProvider.js +65 -13
  92. package/dist/cjs/index.js +27 -28
  93. package/dist/cjs/model/graph.js +10 -5
  94. package/dist/cjs/model/index.js +18 -19
  95. package/dist/cjs/model/theme.js +4 -2
  96. package/dist/cjs/model/units.js +68 -51
  97. package/dist/cjs/test/index.js +16 -17
  98. package/dist/cjs/test/render.js +22 -12
  99. package/dist/cjs/test/setup-tests.js +4 -2
  100. package/dist/cjs/utils/combine-sx.js +15 -16
  101. package/dist/cjs/utils/index.js +17 -18
  102. package/dist/cjs/utils/theme-gen.js +64 -55
  103. package/dist/cjs/utils/theme-gen.test.js +14 -12
  104. package/dist/context/ChartsThemeProvider.js +36 -1
  105. package/dist/context/ChartsThemeProvider.js.map +1 -0
  106. package/dist/index.js +26 -1
  107. package/dist/index.js.map +1 -0
  108. package/dist/model/graph.js +15 -1
  109. package/dist/model/graph.js.map +1 -0
  110. package/dist/model/index.js +17 -1
  111. package/dist/model/index.js.map +1 -0
  112. package/dist/model/theme.js +15 -1
  113. package/dist/model/theme.js.map +1 -0
  114. package/dist/model/units.d.ts.map +1 -1
  115. package/dist/model/units.js +196 -1
  116. package/dist/model/units.js.map +1 -0
  117. package/dist/test/index.js +15 -1
  118. package/dist/test/index.js.map +1 -0
  119. package/dist/test/render.js +32 -1
  120. package/dist/test/render.js.map +1 -0
  121. package/dist/test/setup-tests.js +18 -1
  122. package/dist/test/setup-tests.js.map +1 -0
  123. package/dist/utils/combine-sx.js +27 -1
  124. package/dist/utils/combine-sx.js.map +1 -0
  125. package/dist/utils/index.js +16 -1
  126. package/dist/utils/index.js.map +1 -0
  127. package/dist/utils/theme-gen.js +183 -1
  128. package/dist/utils/theme-gen.js.map +1 -0
  129. package/dist/utils/theme-gen.test.js +196 -1
  130. package/dist/utils/theme-gen.test.js.map +1 -0
  131. package/package.json +8 -4
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LineChart = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
1
  // Copyright 2022 The Perses Authors
6
2
  // Licensed under the Apache License, Version 2.0 (the "License");
7
3
  // you may not use this file except in compliance with the License.
@@ -14,52 +10,61 @@ const jsx_runtime_1 = require("react/jsx-runtime");
14
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
11
  // See the License for the specific language governing permissions and
16
12
  // limitations under the License.
17
- const react_1 = require("react");
18
- const core_1 = require("@perses-dev/core");
19
- const material_1 = require("@mui/material");
20
- const core_2 = require("echarts/core");
21
- const charts_1 = require("echarts/charts");
22
- const components_1 = require("echarts/components");
23
- const renderers_1 = require("echarts/renderers");
24
- const EChart_1 = require("../EChart");
25
- const graph_1 = require("../model/graph");
26
- const units_1 = require("../model/units");
27
- const ChartsThemeProvider_1 = require("../context/ChartsThemeProvider");
28
- const Tooltip_1 = require("../Tooltip/Tooltip");
29
- const utils_1 = require("./utils");
30
- (0, core_2.use)([
31
- charts_1.LineChart,
32
- components_1.GridComponent,
33
- components_1.DataZoomComponent,
34
- components_1.MarkAreaComponent,
35
- components_1.MarkLineComponent,
36
- components_1.MarkPointComponent,
37
- components_1.TitleComponent,
38
- components_1.ToolboxComponent,
39
- components_1.TooltipComponent,
40
- components_1.LegendComponent,
41
- components_1.VisualMapComponent,
42
- renderers_1.CanvasRenderer,
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "LineChart", {
18
+ enumerable: true,
19
+ get: ()=>LineChart
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _core = require("@perses-dev/core");
24
+ const _material = require("@mui/material");
25
+ const _core1 = require("echarts/core");
26
+ const _charts = require("echarts/charts");
27
+ const _components = require("echarts/components");
28
+ const _renderers = require("echarts/renderers");
29
+ const _echart = require("../EChart");
30
+ const _graph = require("../model/graph");
31
+ const _units = require("../model/units");
32
+ const _chartsThemeProvider = require("../context/ChartsThemeProvider");
33
+ const _tooltip = require("../Tooltip/Tooltip");
34
+ const _utils = require("./utils");
35
+ (0, _core1.use)([
36
+ _charts.LineChart,
37
+ _components.GridComponent,
38
+ _components.DataZoomComponent,
39
+ _components.MarkAreaComponent,
40
+ _components.MarkLineComponent,
41
+ _components.MarkPointComponent,
42
+ _components.TitleComponent,
43
+ _components.ToolboxComponent,
44
+ _components.TooltipComponent,
45
+ _components.LegendComponent,
46
+ _components.VisualMapComponent,
47
+ _renderers.CanvasRenderer
43
48
  ]);
44
- function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom, onDoubleClick }) {
45
- const chartsTheme = (0, ChartsThemeProvider_1.useChartsTheme)();
46
- const chartRef = (0, react_1.useRef)();
47
- const [showTooltip, setShowTooltip] = (0, react_1.useState)(true);
48
- const [pinTooltip, setPinTooltip] = (0, react_1.useState)(false);
49
- const handleEvents = (0, react_1.useMemo)(() => {
49
+ function LineChart({ height , data , unit , grid , legend , visualMap , onDataZoom , onDoubleClick }) {
50
+ const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
51
+ const chartRef = (0, _react.useRef)();
52
+ const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
53
+ const [pinTooltip, setPinTooltip] = (0, _react.useState)(false);
54
+ const handleEvents = (0, _react.useMemo)(()=>{
50
55
  return {
51
- datazoom: (params) => {
52
- var _a, _b;
56
+ datazoom: (params)=>{
53
57
  if (onDataZoom === undefined) {
54
- setTimeout(() => {
58
+ setTimeout(()=>{
55
59
  // workaround so unpin happens after click event
56
60
  setPinTooltip(false);
57
61
  }, 10);
58
62
  }
59
- if (onDataZoom === undefined || params.batch[0] === undefined)
60
- return;
61
- const startIndex = (_a = params.batch[0].startValue) !== null && _a !== void 0 ? _a : 0;
62
- const endIndex = (_b = params.batch[0].endValue) !== null && _b !== void 0 ? _b : data.xAxis.length - 1;
63
+ if (onDataZoom === undefined || params.batch[0] === undefined) return;
64
+ var _startValue;
65
+ const startIndex = (_startValue = params.batch[0].startValue) !== null && _startValue !== void 0 ? _startValue : 0;
66
+ var _endValue;
67
+ const endIndex = (_endValue = params.batch[0].endValue) !== null && _endValue !== void 0 ? _endValue : data.xAxis.length - 1;
63
68
  const xAxisStartValue = data.xAxis[startIndex];
64
69
  const xAxisEndValue = data.xAxis[endIndex];
65
70
  if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {
@@ -67,54 +72,54 @@ function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom, on
67
72
  start: xAxisStartValue,
68
73
  end: xAxisEndValue,
69
74
  startIndex,
70
- endIndex,
75
+ endIndex
71
76
  };
72
77
  onDataZoom(zoomEvent);
73
78
  }
74
- },
75
- // TODO: use legendselectchanged event to fix tooltip when legend selected
79
+ }
76
80
  };
77
- }, [data, onDataZoom, setPinTooltip]);
81
+ }, [
82
+ data,
83
+ onDataZoom,
84
+ setPinTooltip
85
+ ]);
78
86
  if (chartRef.current !== undefined) {
79
- (0, utils_1.enableDataZoom)(chartRef.current);
87
+ (0, _utils.enableDataZoom)(chartRef.current);
80
88
  }
81
- const handleOnClick = () => setPinTooltip((current) => !current);
82
- const handleOnDoubleClick = (e) => {
89
+ const handleOnClick = ()=>setPinTooltip((current)=>!current);
90
+ const handleOnDoubleClick = (e)=>{
83
91
  setPinTooltip(false);
84
92
  // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
85
93
  if (onDoubleClick === undefined) {
86
94
  if (chartRef.current !== undefined) {
87
- (0, utils_1.restoreChart)(chartRef.current);
95
+ (0, _utils.restoreChart)(chartRef.current);
88
96
  }
89
- }
90
- else {
97
+ } else {
91
98
  onDoubleClick(e);
92
99
  }
93
100
  };
94
- const handleOnMouseDown = (e) => {
101
+ const handleOnMouseDown = (e)=>{
95
102
  // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
96
103
  if (e.target instanceof HTMLCanvasElement) {
97
104
  setShowTooltip(false);
98
105
  }
99
106
  };
100
- const handleOnMouseUp = () => {
107
+ const handleOnMouseUp = ()=>{
101
108
  setShowTooltip(true);
102
109
  };
103
- const handleOnMouseEnter = () => {
110
+ const handleOnMouseEnter = ()=>{
104
111
  setShowTooltip(true);
105
112
  };
106
- const handleOnMouseLeave = () => {
113
+ const handleOnMouseLeave = ()=>{
107
114
  setShowTooltip(false);
108
115
  setPinTooltip(false);
109
116
  };
110
- const option = (0, core_1.useDeepMemo)(() => {
111
- var _a;
112
- if (data.timeSeries === undefined)
113
- return {};
114
- if (data.timeSeries === null || data.timeSeries.length === 0)
115
- return chartsTheme.noDataOption;
116
- const showPointsOnHover = data.timeSeries.length < graph_1.PROGRESSIVE_MODE_SERIES_LIMIT;
117
- const rangeMs = (_a = data.rangeMs) !== null && _a !== void 0 ? _a : (0, utils_1.getDateRange)(data.xAxis);
117
+ const option = (0, _core.useDeepMemo)(()=>{
118
+ if (data.timeSeries === undefined) return {};
119
+ if (data.timeSeries === null || data.timeSeries.length === 0) return chartsTheme.noDataOption;
120
+ const showPointsOnHover = data.timeSeries.length < _graph.PROGRESSIVE_MODE_SERIES_LIMIT;
121
+ var _rangeMs;
122
+ const rangeMs = (_rangeMs = data.rangeMs) !== null && _rangeMs !== void 0 ? _rangeMs : (0, _utils.getDateRange)(data.xAxis);
118
123
  const option = {
119
124
  series: data.timeSeries,
120
125
  xAxis: {
@@ -122,19 +127,22 @@ function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom, on
122
127
  data: data.xAxis,
123
128
  max: data.xAxisMax,
124
129
  axisLabel: {
125
- formatter: (value) => {
126
- return (0, utils_1.getFormattedDate)(value, rangeMs);
127
- },
128
- },
130
+ formatter: (value)=>{
131
+ return (0, _utils.getFormattedDate)(value, rangeMs);
132
+ }
133
+ }
129
134
  },
130
135
  yAxis: {
131
136
  type: 'value',
132
- boundaryGap: [0, '10%'],
137
+ boundaryGap: [
138
+ 0,
139
+ '10%'
140
+ ],
133
141
  axisLabel: {
134
- formatter: (value) => {
135
- return (0, units_1.formatValue)(value, unit);
136
- },
137
- },
142
+ formatter: (value)=>{
143
+ return (0, _units.formatValue)(value, unit);
144
+ }
145
+ }
138
146
  },
139
147
  animation: false,
140
148
  tooltip: {
@@ -142,28 +150,55 @@ function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom, on
142
150
  trigger: 'axis',
143
151
  showContent: false,
144
152
  axisPointer: {
145
- type: 'none',
146
- },
153
+ type: 'none'
154
+ }
147
155
  },
148
156
  toolbox: {
149
157
  feature: {
150
158
  dataZoom: {
151
159
  icon: null,
152
- yAxisIndex: 'none',
153
- },
154
- },
160
+ yAxisIndex: 'none'
161
+ }
162
+ }
155
163
  },
156
164
  grid,
157
165
  legend,
158
- visualMap,
166
+ visualMap
159
167
  };
160
168
  return option;
161
- }, [data, grid, legend, visualMap]);
162
- return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
163
- height,
164
- }, onClick: handleOnClick, onDoubleClick: handleOnDoubleClick, onMouseDown: handleOnMouseDown, onMouseUp: handleOnMouseUp, onMouseLeave: handleOnMouseLeave, onMouseEnter: handleOnMouseEnter, children: [showTooltip === true && ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { chartRef: chartRef, chartData: data, wrapLabels: true, pinTooltip: pinTooltip })), (0, jsx_runtime_1.jsx)(EChart_1.EChart, { sx: {
169
+ }, [
170
+ data,
171
+ grid,
172
+ legend,
173
+ visualMap
174
+ ]);
175
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
176
+ sx: {
177
+ height
178
+ },
179
+ onClick: handleOnClick,
180
+ onDoubleClick: handleOnDoubleClick,
181
+ onMouseDown: handleOnMouseDown,
182
+ onMouseUp: handleOnMouseUp,
183
+ onMouseLeave: handleOnMouseLeave,
184
+ onMouseEnter: handleOnMouseEnter,
185
+ children: [
186
+ showTooltip === true && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltip.Tooltip, {
187
+ chartRef: chartRef,
188
+ chartData: data,
189
+ wrapLabels: true,
190
+ pinTooltip: pinTooltip
191
+ }),
192
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
193
+ sx: {
165
194
  width: '100%',
166
- height: '100%',
167
- }, option: option, theme: chartsTheme.themeName, onEvents: handleEvents, _instance: chartRef })] }));
195
+ height: '100%'
196
+ },
197
+ option: option,
198
+ theme: chartsTheme.themeName,
199
+ onEvents: handleEvents,
200
+ _instance: chartRef
201
+ })
202
+ ]
203
+ });
168
204
  }
169
- exports.LineChart = LineChart;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,19 +10,19 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- var desc = Object.getOwnPropertyDescriptor(m, k);
17
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
- desc = { enumerable: true, get: function() { return m[k]; } };
19
- }
20
- Object.defineProperty(o, k2, desc);
21
- }) : (function(o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- }));
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- __exportStar(require("./LineChart"), exports);
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./LineChart"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,57 +10,59 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getFormattedDate = exports.getDateRange = exports.restoreChart = exports.enableDataZoom = void 0;
16
- // enable dataZoom without requring user to click toolbox icon
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ enableDataZoom: ()=>enableDataZoom,
25
+ restoreChart: ()=>restoreChart,
26
+ getDateRange: ()=>getDateRange,
27
+ getFormattedDate: ()=>getFormattedDate
28
+ });
17
29
  function enableDataZoom(chart) {
18
30
  const chartModel = chart['_model'];
19
- if (chartModel === undefined)
20
- return;
31
+ if (chartModel === undefined) return;
21
32
  if (chartModel.option.toolbox !== undefined && chartModel.option.toolbox.length > 0) {
22
33
  // check if hidden data zoom icon is unselected (if selected it would be 'emphasis' instead of 'normal')
23
34
  if (chartModel.option.toolbox[0].feature.dataZoom.iconStatus.zoom === 'normal') {
24
35
  chart.dispatchAction({
25
36
  type: 'takeGlobalCursor',
26
37
  key: 'dataZoomSelect',
27
- dataZoomSelectActive: true,
38
+ dataZoomSelectActive: true
28
39
  });
29
40
  }
30
41
  }
31
42
  }
32
- exports.enableDataZoom = enableDataZoom;
33
- // restore chart to original state before zoom or other actions were dispatched
34
- // TODO: support incremental unzoom instead of restore to original state
35
43
  function restoreChart(chart) {
36
44
  chart.dispatchAction({
37
- type: 'restore', // https://echarts.apache.org/en/api.html#events.restore
45
+ type: 'restore'
38
46
  });
39
47
  }
40
- exports.restoreChart = restoreChart;
41
- // fallback when xAxis time range not passed as prop
42
48
  function getDateRange(data) {
43
49
  const defaultRange = 3600000; // hour in ms
44
- if (data.length === 0)
45
- return defaultRange;
50
+ if (data.length === 0) return defaultRange;
46
51
  const lastDatum = data[data.length - 1];
47
- if (data[0] === undefined || lastDatum === undefined)
48
- return defaultRange;
52
+ if (data[0] === undefined || lastDatum === undefined) return defaultRange;
49
53
  return lastDatum - data[0];
50
54
  }
51
- exports.getDateRange = getDateRange;
52
- // determines time granularity for axis labels, defaults to hh:mm
53
55
  function getFormattedDate(value, rangeMs) {
54
56
  const dateFormatOptions = {
55
57
  hour: 'numeric',
56
58
  minute: 'numeric',
57
- hourCycle: 'h23',
59
+ hourCycle: 'h23'
58
60
  };
59
61
  const thirtyMinMs = 1800000;
60
62
  const dayMs = 86400000;
61
63
  if (rangeMs <= thirtyMinMs) {
62
64
  dateFormatOptions.second = 'numeric';
63
- }
64
- else if (rangeMs >= dayMs) {
65
+ } else if (rangeMs >= dayMs) {
65
66
  dateFormatOptions.month = 'numeric';
66
67
  dateFormatOptions.day = 'numeric';
67
68
  }
@@ -69,4 +70,3 @@ function getFormattedDate(value, rangeMs) {
69
70
  // remove comma when month / day present
70
71
  return DATE_FORMAT.format(value).replace(/, /g, ' ');
71
72
  }
72
- exports.getFormattedDate = getFormattedDate;
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StatChart = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
1
  // Copyright 2022 The Perses Authors
6
2
  // Licensed under the Apache License, Version 2.0 (the "License");
7
3
  // you may not use this file except in compliance with the License.
@@ -14,53 +10,101 @@ const jsx_runtime_1 = require("react/jsx-runtime");
14
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
11
  // See the License for the specific language governing permissions and
16
12
  // limitations under the License.
17
- const react_1 = require("react");
18
- const material_1 = require("@mui/material");
19
- const lodash_es_1 = require("lodash-es");
20
- const core_1 = require("echarts/core");
21
- const charts_1 = require("echarts/charts");
22
- const charts_2 = require("echarts/charts");
23
- const components_1 = require("echarts/components");
24
- const renderers_1 = require("echarts/renderers");
25
- const ChartsThemeProvider_1 = require("../context/ChartsThemeProvider");
26
- const units_1 = require("../model/units");
27
- const EChart_1 = require("../EChart");
28
- (0, core_1.use)([
29
- charts_1.GaugeChart,
30
- charts_2.LineChart,
31
- components_1.GridComponent,
32
- components_1.DatasetComponent,
33
- components_1.TitleComponent,
34
- components_1.TooltipComponent,
35
- renderers_1.CanvasRenderer,
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "StatChart", {
18
+ enumerable: true,
19
+ get: ()=>StatChart
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
23
+ const _material = require("@mui/material");
24
+ const _lodashEs = require("lodash-es");
25
+ const _core = require("echarts/core");
26
+ const _charts = require("echarts/charts");
27
+ const _components = require("echarts/components");
28
+ const _renderers = require("echarts/renderers");
29
+ const _chartsThemeProvider = require("../context/ChartsThemeProvider");
30
+ const _units = require("../model/units");
31
+ const _echart = require("../EChart");
32
+ function _getRequireWildcardCache(nodeInterop) {
33
+ if (typeof WeakMap !== "function") return null;
34
+ var cacheBabelInterop = new WeakMap();
35
+ var cacheNodeInterop = new WeakMap();
36
+ return (_getRequireWildcardCache = function(nodeInterop) {
37
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
38
+ })(nodeInterop);
39
+ }
40
+ function _interopRequireWildcard(obj, nodeInterop) {
41
+ if (!nodeInterop && obj && obj.__esModule) {
42
+ return obj;
43
+ }
44
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
45
+ return {
46
+ default: obj
47
+ };
48
+ }
49
+ var cache = _getRequireWildcardCache(nodeInterop);
50
+ if (cache && cache.has(obj)) {
51
+ return cache.get(obj);
52
+ }
53
+ var newObj = {};
54
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
55
+ for(var key in obj){
56
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
57
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
58
+ if (desc && (desc.get || desc.set)) {
59
+ Object.defineProperty(newObj, key, desc);
60
+ } else {
61
+ newObj[key] = obj[key];
62
+ }
63
+ }
64
+ }
65
+ newObj.default = obj;
66
+ if (cache) {
67
+ cache.set(obj, newObj);
68
+ }
69
+ return newObj;
70
+ }
71
+ (0, _core.use)([
72
+ _charts.GaugeChart,
73
+ _charts.LineChart,
74
+ _components.GridComponent,
75
+ _components.DatasetComponent,
76
+ _components.TitleComponent,
77
+ _components.TooltipComponent,
78
+ _renderers.CanvasRenderer
36
79
  ]);
37
80
  const PANEL_PADDING = 32;
38
81
  const MIN_VALUE_SIZE = 12;
39
82
  const MAX_VALUE_SIZE = 36;
40
83
  function StatChart(props) {
41
- const { width, height, data, unit, sparkline } = props;
42
- const chartsTheme = (0, ChartsThemeProvider_1.useChartsTheme)();
43
- const formattedValue = data.calculatedValue === undefined ? 'No data' : (0, units_1.formatValue)(data.calculatedValue, unit);
44
- const option = (0, react_1.useMemo)(() => {
45
- if (data.seriesData === undefined)
46
- return chartsTheme.noDataOption;
84
+ const { width , height , data , unit , sparkline } = props;
85
+ const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
86
+ const formattedValue = data.calculatedValue === undefined ? 'No data' : (0, _units.formatValue)(data.calculatedValue, unit);
87
+ const option = (0, _react.useMemo)(()=>{
88
+ if (data.seriesData === undefined) return chartsTheme.noDataOption;
47
89
  const series = data.seriesData;
48
90
  const statSeries = [];
49
91
  if (sparkline !== undefined) {
50
92
  const lineSeries = {
51
93
  type: 'line',
52
- data: [...series.values],
94
+ data: [
95
+ ...series.values
96
+ ],
53
97
  zlevel: 1,
54
98
  symbol: 'none',
55
99
  animation: false,
56
- silent: true,
100
+ silent: true
57
101
  };
58
- const mergedSeries = (0, lodash_es_1.merge)(lineSeries, sparkline);
102
+ const mergedSeries = (0, _lodashEs.merge)(lineSeries, sparkline);
59
103
  statSeries.push(mergedSeries);
60
104
  }
61
105
  const option = {
62
106
  title: {
63
- show: false,
107
+ show: false
64
108
  },
65
109
  grid: {
66
110
  show: false,
@@ -68,37 +112,54 @@ function StatChart(props) {
68
112
  right: 0,
69
113
  bottom: 0,
70
114
  left: 0,
71
- containLabel: false,
115
+ containLabel: false
72
116
  },
73
117
  xAxis: {
74
118
  type: 'time',
75
119
  show: false,
76
- boundaryGap: false,
120
+ boundaryGap: false
77
121
  },
78
122
  yAxis: {
79
123
  type: 'value',
80
- show: false,
124
+ show: false
81
125
  },
82
126
  tooltip: {
83
- show: false,
127
+ show: false
84
128
  },
85
- series: statSeries,
129
+ series: statSeries
86
130
  };
87
131
  return option;
88
- }, [data, chartsTheme, sparkline]);
132
+ }, [
133
+ data,
134
+ chartsTheme,
135
+ sparkline
136
+ ]);
89
137
  const isLargePanel = width > 250 && height > 180;
90
138
  // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute
91
139
  const charactersAdjust = formattedValue.length;
92
140
  const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
93
- return ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h3", sx: (theme) => ({
94
- color: theme.palette.text.primary,
95
- fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
96
- }), children: formattedValue }), sparkline !== undefined && ((0, jsx_runtime_1.jsx)(EChart_1.EChart, { sx: {
141
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
142
+ children: [
143
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
144
+ variant: "h3",
145
+ sx: (theme)=>({
146
+ color: theme.palette.text.primary,
147
+ fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`
148
+ }),
149
+ children: formattedValue
150
+ }),
151
+ sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
152
+ sx: {
97
153
  width: width + PANEL_PADDING,
98
154
  height: height,
99
155
  position: 'absolute',
100
156
  bottom: 0,
101
- left: 0,
102
- }, option: option, theme: chartsTheme.themeName, renderer: "svg" }))] }));
157
+ left: 0
158
+ },
159
+ option: option,
160
+ theme: chartsTheme.themeName,
161
+ renderer: "svg"
162
+ })
163
+ ]
164
+ });
103
165
  }
104
- exports.StatChart = StatChart;