@perses-dev/components 0.19.0 → 0.21.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.
- package/dist/DateTimeRangePicker/AbsoluteTimePicker.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/AbsoluteTimePicker.js +4 -3
- package/dist/DateTimeRangePicker/AbsoluteTimePicker.js.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -0
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.js +3 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +1 -0
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js +9 -3
- package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
- package/dist/DateTimeRangePicker/utils.d.ts +1 -1
- package/dist/DateTimeRangePicker/utils.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/utils.js +5 -4
- package/dist/DateTimeRangePicker/utils.js.map +1 -1
- package/dist/GaugeChart/GaugeChart.d.ts +11 -2
- package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
- package/dist/GaugeChart/GaugeChart.js +58 -10
- package/dist/GaugeChart/GaugeChart.js.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.d.ts +3 -1
- package/dist/InfoTooltip/InfoTooltip.d.ts.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.js +4 -2
- package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts +8 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js +82 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts +2 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js +41 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js.map +1 -0
- package/dist/LegendOptionsEditor/index.d.ts +2 -0
- package/dist/LegendOptionsEditor/index.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/index.js +15 -0
- package/dist/LegendOptionsEditor/index.js.map +1 -0
- package/dist/LineChart/LineChart.d.ts +2 -3
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +39 -34
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/LineChart/utils.d.ts +1 -1
- package/dist/LineChart/utils.d.ts.map +1 -1
- package/dist/LineChart/utils.js +4 -3
- package/dist/LineChart/utils.js.map +1 -1
- package/dist/StatChart/StatChart.test.js +42 -21
- package/dist/StatChart/StatChart.test.js.map +1 -1
- package/dist/Tooltip/TooltipContent.d.ts.map +1 -1
- package/dist/Tooltip/TooltipContent.js +8 -9
- package/dist/Tooltip/TooltipContent.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.test.js +3 -10
- package/dist/UnitSelector/UnitSelector.test.js.map +1 -1
- package/dist/cjs/DateTimeRangePicker/AbsoluteTimePicker.js +4 -3
- package/dist/cjs/DateTimeRangePicker/DateTimeRangePicker.js +3 -1
- package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +9 -3
- package/dist/cjs/DateTimeRangePicker/utils.js +4 -3
- package/dist/cjs/GaugeChart/GaugeChart.js +66 -15
- package/dist/cjs/InfoTooltip/InfoTooltip.js +4 -2
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +88 -0
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.test.js +48 -0
- package/dist/cjs/LegendOptionsEditor/index.js +28 -0
- package/dist/cjs/LineChart/LineChart.js +40 -35
- package/dist/cjs/LineChart/utils.js +4 -3
- package/dist/cjs/StatChart/StatChart.test.js +43 -27
- package/dist/cjs/Tooltip/TooltipContent.js +8 -9
- package/dist/cjs/UnitSelector/UnitSelector.test.js +3 -10
- package/dist/cjs/context/TimeZoneProvider.js +90 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/model/graph.js +14 -3
- package/dist/cjs/model/units/bytes.js +32 -6
- package/dist/cjs/model/units/time.js +26 -62
- package/dist/cjs/model/units/units.js +1 -4
- package/dist/cjs/model/units/units.test.js +153 -0
- package/dist/cjs/theme/theme.js +19 -0
- package/dist/cjs/utils/format.js +56 -0
- package/dist/cjs/utils/format.test.js +47 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/context/TimeZoneProvider.d.ts +13 -0
- package/dist/context/TimeZoneProvider.d.ts.map +1 -0
- package/dist/context/TimeZoneProvider.js +38 -0
- package/dist/context/TimeZoneProvider.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +4 -2
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js +4 -0
- package/dist/model/graph.js.map +1 -1
- package/dist/model/units/bytes.d.ts +6 -1
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +35 -7
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/time.d.ts +11 -0
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +25 -62
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +1 -4
- package/dist/model/units/units.js.map +1 -1
- package/dist/model/units/units.test.d.ts +2 -0
- package/dist/model/units/units.test.d.ts.map +1 -0
- package/dist/model/units/units.test.js +151 -0
- package/dist/model/units/units.test.js.map +1 -0
- package/dist/theme/theme.d.ts +2 -2
- package/dist/theme/theme.d.ts.map +1 -1
- package/dist/theme/theme.js +19 -0
- package/dist/theme/theme.js.map +1 -1
- package/dist/utils/format.d.ts +3 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +44 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/format.test.d.ts +2 -0
- package/dist/utils/format.test.d.ts.map +1 -0
- package/dist/utils/format.test.js +45 -0
- package/dist/utils/format.test.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
const _react = require("@testing-library/react");
|
|
19
|
+
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
20
|
+
const _legendOptionsEditor = require("./LegendOptionsEditor");
|
|
21
|
+
function _interopRequireDefault(obj) {
|
|
22
|
+
return obj && obj.__esModule ? obj : {
|
|
23
|
+
default: obj
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
describe('LegendOptionsEditor', ()=>{
|
|
27
|
+
const renderLegendOptionsEditor = (value, onChange = jest.fn())=>{
|
|
28
|
+
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
29
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_legendOptionsEditor.LegendOptionsEditor, {
|
|
30
|
+
value: value,
|
|
31
|
+
onChange: onChange
|
|
32
|
+
})
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
const getLegendShowSwitch = ()=>{
|
|
36
|
+
return _react.screen.getByRole('checkbox', {
|
|
37
|
+
name: 'Show'
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
it('can change legend visibility by clicking', ()=>{
|
|
41
|
+
const onChange = jest.fn();
|
|
42
|
+
renderLegendOptionsEditor(undefined, onChange);
|
|
43
|
+
_userEvent.default.click(getLegendShowSwitch());
|
|
44
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
45
|
+
position: 'bottom'
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
_exportStar(require("./LegendOptionsEditor"), 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
|
+
}
|
|
@@ -20,17 +20,18 @@ Object.defineProperty(exports, "LineChart", {
|
|
|
20
20
|
});
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
22
|
const _react = require("react");
|
|
23
|
-
const _core = require("@perses-dev/core");
|
|
24
23
|
const _material = require("@mui/material");
|
|
25
|
-
const
|
|
24
|
+
const _core = require("echarts/core");
|
|
26
25
|
const _charts = require("echarts/charts");
|
|
27
26
|
const _components = require("echarts/components");
|
|
28
27
|
const _renderers = require("echarts/renderers");
|
|
29
28
|
const _echart = require("../EChart");
|
|
29
|
+
const _graph = require("../model/graph");
|
|
30
30
|
const _chartsThemeProvider = require("../context/ChartsThemeProvider");
|
|
31
31
|
const _tooltip = require("../Tooltip/Tooltip");
|
|
32
|
+
const _timeZoneProvider = require("../context/TimeZoneProvider");
|
|
32
33
|
const _utils = require("./utils");
|
|
33
|
-
(0,
|
|
34
|
+
(0, _core.use)([
|
|
34
35
|
_charts.LineChart,
|
|
35
36
|
_components.GridComponent,
|
|
36
37
|
_components.DataZoomComponent,
|
|
@@ -41,14 +42,14 @@ const _utils = require("./utils");
|
|
|
41
42
|
_components.ToolboxComponent,
|
|
42
43
|
_components.TooltipComponent,
|
|
43
44
|
_components.LegendComponent,
|
|
44
|
-
_components.VisualMapComponent,
|
|
45
45
|
_renderers.CanvasRenderer
|
|
46
46
|
]);
|
|
47
|
-
function LineChart({ height , data , yAxis , unit , grid , legend ,
|
|
47
|
+
function LineChart({ height , data , yAxis , unit , grid , legend , onDataZoom , onDoubleClick }) {
|
|
48
48
|
const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
|
|
49
49
|
const chartRef = (0, _react.useRef)();
|
|
50
50
|
const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
|
|
51
51
|
const [pinTooltip, setPinTooltip] = (0, _react.useState)(false);
|
|
52
|
+
const { timeZone } = (0, _timeZoneProvider.useTimeZone)();
|
|
52
53
|
const handleEvents = (0, _react.useMemo)(()=>{
|
|
53
54
|
return {
|
|
54
55
|
datazoom: (params)=>{
|
|
@@ -84,7 +85,6 @@ function LineChart({ height , data , yAxis , unit , grid , legend , visualMap ,
|
|
|
84
85
|
if (chartRef.current !== undefined) {
|
|
85
86
|
(0, _utils.enableDataZoom)(chartRef.current);
|
|
86
87
|
}
|
|
87
|
-
const handleOnClick = ()=>setPinTooltip((current)=>!current);
|
|
88
88
|
const handleOnDoubleClick = (e)=>{
|
|
89
89
|
setPinTooltip(false);
|
|
90
90
|
// either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
|
|
@@ -96,25 +96,12 @@ function LineChart({ height , data , yAxis , unit , grid , legend , visualMap ,
|
|
|
96
96
|
onDoubleClick(e);
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
if (e.target instanceof HTMLCanvasElement) {
|
|
102
|
-
setShowTooltip(false);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
const handleOnMouseUp = ()=>{
|
|
106
|
-
setShowTooltip(true);
|
|
107
|
-
};
|
|
108
|
-
const handleOnMouseEnter = ()=>{
|
|
109
|
-
setShowTooltip(true);
|
|
110
|
-
};
|
|
111
|
-
const handleOnMouseLeave = ()=>{
|
|
112
|
-
setShowTooltip(false);
|
|
113
|
-
setPinTooltip(false);
|
|
114
|
-
};
|
|
115
|
-
const option = (0, _core.useDeepMemo)(()=>{
|
|
99
|
+
const { noDataOption } = chartsTheme;
|
|
100
|
+
const option = (0, _react.useMemo)(()=>{
|
|
116
101
|
if (data.timeSeries === undefined) return {};
|
|
117
|
-
if (data.timeSeries === null || data.timeSeries.length === 0) return
|
|
102
|
+
if (data.timeSeries === null || data.timeSeries.length === 0) return noDataOption;
|
|
103
|
+
// show symbols and axisPointer dashed line on hover
|
|
104
|
+
const isOptimizedMode = data.timeSeries.length > _graph.OPTIMIZED_MODE_SERIES_LIMIT;
|
|
118
105
|
var _rangeMs;
|
|
119
106
|
const rangeMs = (_rangeMs = data.rangeMs) !== null && _rangeMs !== void 0 ? _rangeMs : (0, _utils.getDateRange)(data.xAxis);
|
|
120
107
|
const option = {
|
|
@@ -125,18 +112,18 @@ function LineChart({ height , data , yAxis , unit , grid , legend , visualMap ,
|
|
|
125
112
|
max: data.xAxisMax,
|
|
126
113
|
axisLabel: {
|
|
127
114
|
formatter: (value)=>{
|
|
128
|
-
return (0, _utils.getFormattedDate)(value, rangeMs);
|
|
115
|
+
return (0, _utils.getFormattedDate)(value, rangeMs, timeZone);
|
|
129
116
|
}
|
|
130
117
|
}
|
|
131
118
|
},
|
|
132
119
|
yAxis: (0, _utils.getYAxes)(yAxis, unit),
|
|
133
120
|
animation: false,
|
|
134
121
|
tooltip: {
|
|
135
|
-
show:
|
|
122
|
+
show: !isOptimizedMode,
|
|
136
123
|
trigger: 'axis',
|
|
137
124
|
showContent: false,
|
|
138
125
|
axisPointer: {
|
|
139
|
-
type: 'line',
|
|
126
|
+
type: isOptimizedMode ? 'none' : 'line',
|
|
140
127
|
z: 0
|
|
141
128
|
}
|
|
142
129
|
},
|
|
@@ -149,27 +136,45 @@ function LineChart({ height , data , yAxis , unit , grid , legend , visualMap ,
|
|
|
149
136
|
}
|
|
150
137
|
},
|
|
151
138
|
grid,
|
|
152
|
-
legend
|
|
153
|
-
visualMap
|
|
139
|
+
legend
|
|
154
140
|
};
|
|
155
141
|
return option;
|
|
156
142
|
}, [
|
|
157
143
|
data,
|
|
158
144
|
yAxis,
|
|
145
|
+
unit,
|
|
159
146
|
grid,
|
|
160
147
|
legend,
|
|
161
|
-
|
|
148
|
+
noDataOption,
|
|
149
|
+
timeZone
|
|
162
150
|
]);
|
|
163
151
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
164
152
|
sx: {
|
|
165
153
|
height
|
|
166
154
|
},
|
|
167
|
-
onClick:
|
|
155
|
+
onClick: ()=>{
|
|
156
|
+
setPinTooltip((current)=>!current);
|
|
157
|
+
},
|
|
158
|
+
onMouseDown: (e)=>{
|
|
159
|
+
// hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
|
|
160
|
+
if (e.target instanceof HTMLCanvasElement) {
|
|
161
|
+
setShowTooltip(false);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
onMouseUp: ()=>{
|
|
165
|
+
setShowTooltip(true);
|
|
166
|
+
},
|
|
167
|
+
onMouseLeave: ()=>{
|
|
168
|
+
setShowTooltip(false);
|
|
169
|
+
setPinTooltip(false);
|
|
170
|
+
},
|
|
171
|
+
onMouseEnter: ()=>{
|
|
172
|
+
setShowTooltip(true);
|
|
173
|
+
if (chartRef.current !== undefined) {
|
|
174
|
+
(0, _utils.enableDataZoom)(chartRef.current);
|
|
175
|
+
}
|
|
176
|
+
},
|
|
168
177
|
onDoubleClick: handleOnDoubleClick,
|
|
169
|
-
onMouseDown: handleOnMouseDown,
|
|
170
|
-
onMouseUp: handleOnMouseUp,
|
|
171
|
-
onMouseLeave: handleOnMouseLeave,
|
|
172
|
-
onMouseEnter: handleOnMouseEnter,
|
|
173
178
|
children: [
|
|
174
179
|
showTooltip === true && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltip.Tooltip, {
|
|
175
180
|
chartRef: chartRef,
|
|
@@ -29,6 +29,7 @@ _export(exports, {
|
|
|
29
29
|
});
|
|
30
30
|
const _lodashEs = require("lodash-es");
|
|
31
31
|
const _model = require("../model");
|
|
32
|
+
const _utils = require("../utils");
|
|
32
33
|
function enableDataZoom(chart) {
|
|
33
34
|
const chartModel = chart['_model'];
|
|
34
35
|
if (chartModel === undefined) return;
|
|
@@ -56,12 +57,12 @@ function getDateRange(data) {
|
|
|
56
57
|
if (data[0] === undefined || lastDatum === undefined) return defaultRange;
|
|
57
58
|
return lastDatum - data[0];
|
|
58
59
|
}
|
|
59
|
-
function getFormattedDate(value, rangeMs) {
|
|
60
|
-
const dateFormatOptions = {
|
|
60
|
+
function getFormattedDate(value, rangeMs, timeZone) {
|
|
61
|
+
const dateFormatOptions = (0, _utils.dateFormatOptionsWithTimeZone)({
|
|
61
62
|
hour: 'numeric',
|
|
62
63
|
minute: 'numeric',
|
|
63
64
|
hourCycle: 'h23'
|
|
64
|
-
};
|
|
65
|
+
}, timeZone);
|
|
65
66
|
const thirtyMinMs = 1800000;
|
|
66
67
|
const dayMs = 86400000;
|
|
67
68
|
if (rangeMs <= thirtyMinMs) {
|
|
@@ -15,24 +15,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
17
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _react =
|
|
19
|
-
const _react1 = require("@testing-library/react");
|
|
18
|
+
const _react = require("@testing-library/react");
|
|
20
19
|
const _chartsThemeProvider = require("../context/ChartsThemeProvider");
|
|
21
20
|
const _testUtils = require("../test-utils");
|
|
22
21
|
const _statChart = require("./StatChart");
|
|
23
|
-
function _interopRequireDefault(obj) {
|
|
24
|
-
return obj && obj.__esModule ? obj : {
|
|
25
|
-
default: obj
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
22
|
describe('StatChart', ()=>{
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
const renderChart = (unit)=>{
|
|
24
|
+
const contentDimensions = {
|
|
25
|
+
width: 200,
|
|
26
|
+
height: 200
|
|
27
|
+
};
|
|
28
|
+
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_chartsThemeProvider.ChartsThemeProvider, {
|
|
29
|
+
chartsTheme: _testUtils.testChartsTheme,
|
|
30
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_statChart.StatChart, {
|
|
31
|
+
width: contentDimensions.width,
|
|
32
|
+
height: contentDimensions.height,
|
|
33
|
+
data: mockStatData,
|
|
34
|
+
unit: unit
|
|
35
|
+
})
|
|
36
|
+
}));
|
|
36
37
|
};
|
|
37
38
|
const mockStatData = {
|
|
38
39
|
calculatedValue: 7.72931659687181,
|
|
@@ -63,18 +64,33 @@ describe('StatChart', ()=>{
|
|
|
63
64
|
]
|
|
64
65
|
}
|
|
65
66
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
it('render default options (no sparkline)', ()=>{
|
|
68
|
+
const unit = {
|
|
69
|
+
kind: 'Decimal',
|
|
70
|
+
decimal_places: 2
|
|
71
|
+
};
|
|
72
|
+
renderChart(unit);
|
|
73
|
+
expect(_react.screen.getByText('7.73')).toBeInTheDocument();
|
|
74
|
+
});
|
|
75
|
+
it('show value with bytes unit formatting', ()=>{
|
|
76
|
+
const unit = {
|
|
77
|
+
kind: 'Bytes'
|
|
78
|
+
};
|
|
79
|
+
renderChart(unit);
|
|
80
|
+
expect(_react.screen.getByText('7.73 bytes')).toBeInTheDocument();
|
|
81
|
+
});
|
|
82
|
+
it('show value with seconds time unit formatting', ()=>{
|
|
83
|
+
const unit = {
|
|
84
|
+
kind: 'Seconds'
|
|
85
|
+
};
|
|
86
|
+
renderChart(unit);
|
|
87
|
+
expect(_react.screen.getByText('7.73 seconds')).toBeInTheDocument();
|
|
88
|
+
});
|
|
89
|
+
it('show value with months time unit formatting', ()=>{
|
|
90
|
+
const unit = {
|
|
91
|
+
kind: 'Months'
|
|
92
|
+
};
|
|
93
|
+
renderChart(unit);
|
|
94
|
+
expect(_react.screen.getByText('7.73 months')).toBeInTheDocument();
|
|
79
95
|
});
|
|
80
96
|
});
|
|
@@ -21,30 +21,29 @@ Object.defineProperty(exports, "TooltipContent", {
|
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
22
|
const _react = require("react");
|
|
23
23
|
const _material = require("@mui/material");
|
|
24
|
+
const _timeZoneProvider = require("../context/TimeZoneProvider");
|
|
24
25
|
const _seriesInfo = require("./SeriesInfo");
|
|
25
26
|
function TooltipContent(props) {
|
|
26
27
|
const { focusedSeries , wrapLabels } = props;
|
|
28
|
+
const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
|
|
27
29
|
const seriesTime = focusedSeries && focusedSeries[0] && focusedSeries[0].date ? focusedSeries[0].date : null;
|
|
28
30
|
const formatTimeSeriesHeader = (timeString)=>{
|
|
29
|
-
const
|
|
31
|
+
const date = new Date(timeString);
|
|
32
|
+
const formattedDate = formatWithUserTimeZone(date, 'MMM dd, yyyy - ');
|
|
33
|
+
const formattedTime = formatWithUserTimeZone(date, 'HH:mm:ss');
|
|
30
34
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
31
35
|
children: [
|
|
32
|
-
/*#__PURE__*/ (0, _jsxRuntime.
|
|
36
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
|
|
33
37
|
variant: "caption",
|
|
34
38
|
sx: (theme)=>({
|
|
35
39
|
color: theme.palette.common.white
|
|
36
40
|
}),
|
|
37
|
-
children:
|
|
38
|
-
month,
|
|
39
|
-
", ",
|
|
40
|
-
year,
|
|
41
|
-
" –"
|
|
42
|
-
]
|
|
41
|
+
children: formattedDate
|
|
43
42
|
}),
|
|
44
43
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
|
|
45
44
|
variant: "caption",
|
|
46
45
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)("strong", {
|
|
47
|
-
children:
|
|
46
|
+
children: formattedTime
|
|
48
47
|
})
|
|
49
48
|
})
|
|
50
49
|
]
|
|
@@ -68,8 +68,7 @@ describe('UnitSelector', ()=>{
|
|
|
68
68
|
kind: 'Bytes'
|
|
69
69
|
}, onChange);
|
|
70
70
|
const unitSelector = getUnitSelector();
|
|
71
|
-
|
|
72
|
-
// abbreviate comes first and is disabled in some cases.
|
|
71
|
+
_userEvent.default.tab();
|
|
73
72
|
_userEvent.default.tab();
|
|
74
73
|
expect(unitSelector).toHaveFocus();
|
|
75
74
|
_userEvent.default.clear(unitSelector);
|
|
@@ -149,12 +148,6 @@ describe('UnitSelector', ()=>{
|
|
|
149
148
|
});
|
|
150
149
|
});
|
|
151
150
|
describe('with a time unit selected', ()=>{
|
|
152
|
-
it('does not allow the user to modify the decimal places', ()=>{
|
|
153
|
-
renderUnitSelector({
|
|
154
|
-
kind: 'Hours'
|
|
155
|
-
});
|
|
156
|
-
expect(getDecimalSelector()).toBeDisabled();
|
|
157
|
-
});
|
|
158
151
|
it('does not allow the user to set abbreviate', ()=>{
|
|
159
152
|
renderUnitSelector({
|
|
160
153
|
kind: 'Minutes'
|
|
@@ -197,11 +190,11 @@ describe('UnitSelector', ()=>{
|
|
|
197
190
|
});
|
|
198
191
|
expect(getDecimalSelector()).toBeEnabled();
|
|
199
192
|
});
|
|
200
|
-
it('
|
|
193
|
+
it('allows the user to set abbreviate', ()=>{
|
|
201
194
|
renderUnitSelector({
|
|
202
195
|
kind: 'Bytes'
|
|
203
196
|
});
|
|
204
|
-
expect(getAbbreviateSwitch()).
|
|
197
|
+
expect(getAbbreviateSwitch()).toBeEnabled();
|
|
205
198
|
});
|
|
206
199
|
});
|
|
207
200
|
it('should not show an option for disabled units', ()=>{
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
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
|
+
TimeZoneContext: ()=>TimeZoneContext,
|
|
25
|
+
TimeZoneProvider: ()=>TimeZoneProvider,
|
|
26
|
+
useTimeZone: ()=>useTimeZone
|
|
27
|
+
});
|
|
28
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
29
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
30
|
+
const _utils = require("../utils");
|
|
31
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
32
|
+
if (typeof WeakMap !== "function") return null;
|
|
33
|
+
var cacheBabelInterop = new WeakMap();
|
|
34
|
+
var cacheNodeInterop = new WeakMap();
|
|
35
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
36
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
37
|
+
})(nodeInterop);
|
|
38
|
+
}
|
|
39
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
40
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
44
|
+
return {
|
|
45
|
+
default: obj
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
49
|
+
if (cache && cache.has(obj)) {
|
|
50
|
+
return cache.get(obj);
|
|
51
|
+
}
|
|
52
|
+
var newObj = {};
|
|
53
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
54
|
+
for(var key in obj){
|
|
55
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
56
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
57
|
+
if (desc && (desc.get || desc.set)) {
|
|
58
|
+
Object.defineProperty(newObj, key, desc);
|
|
59
|
+
} else {
|
|
60
|
+
newObj[key] = obj[key];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
newObj.default = obj;
|
|
65
|
+
if (cache) {
|
|
66
|
+
cache.set(obj, newObj);
|
|
67
|
+
}
|
|
68
|
+
return newObj;
|
|
69
|
+
}
|
|
70
|
+
const TimeZoneContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
|
|
71
|
+
function TimeZoneProvider(props) {
|
|
72
|
+
const { children , timeZone } = props;
|
|
73
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(TimeZoneContext.Provider, {
|
|
74
|
+
value: timeZone,
|
|
75
|
+
children: children
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function useTimeZone() {
|
|
79
|
+
const timeZone = (0, _react.useContext)(TimeZoneContext);
|
|
80
|
+
return {
|
|
81
|
+
// fallback to "local" timezone if TimeZoneProvider is not present in the React tree
|
|
82
|
+
timeZone: timeZone !== null && timeZone !== void 0 ? timeZone : 'local',
|
|
83
|
+
formatWithUserTimeZone (date, formatString) {
|
|
84
|
+
return (0, _utils.formatWithTimeZone)(date, formatString, timeZone);
|
|
85
|
+
},
|
|
86
|
+
dateFormatOptionsWithUserTimeZone (dateFormatOptions) {
|
|
87
|
+
return (0, _utils.dateFormatOptionsWithTimeZone)(dateFormatOptions, timeZone);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -23,12 +23,14 @@ _exportStar(require("./GaugeChart"), exports);
|
|
|
23
23
|
_exportStar(require("./InfoTooltip"), exports);
|
|
24
24
|
_exportStar(require("./JSONEditor"), exports);
|
|
25
25
|
_exportStar(require("./Legend"), exports);
|
|
26
|
+
_exportStar(require("./LegendOptionsEditor"), exports);
|
|
26
27
|
_exportStar(require("./LineChart"), exports);
|
|
27
28
|
_exportStar(require("./OptionsEditorLayout"), exports);
|
|
28
29
|
_exportStar(require("./StatChart"), exports);
|
|
29
30
|
_exportStar(require("./UnitSelector"), exports);
|
|
30
31
|
_exportStar(require("./YAxisLabel"), exports);
|
|
31
32
|
_exportStar(require("./context/ChartsThemeProvider"), exports);
|
|
33
|
+
_exportStar(require("./context/TimeZoneProvider"), exports);
|
|
32
34
|
_exportStar(require("./utils"), exports);
|
|
33
35
|
_exportStar(require("./model"), exports);
|
|
34
36
|
_exportStar(require("./test-utils"), exports);
|
package/dist/cjs/model/graph.js
CHANGED
|
@@ -14,8 +14,19 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
OPTIMIZED_MODE_SERIES_LIMIT: ()=>OPTIMIZED_MODE_SERIES_LIMIT,
|
|
25
|
+
DEFAULT_LEGEND_POSITION: ()=>DEFAULT_LEGEND_POSITION,
|
|
26
|
+
DEFAULT_LEGEND: ()=>DEFAULT_LEGEND
|
|
20
27
|
});
|
|
21
28
|
const OPTIMIZED_MODE_SERIES_LIMIT = 1000;
|
|
29
|
+
const DEFAULT_LEGEND_POSITION = 'bottom';
|
|
30
|
+
const DEFAULT_LEGEND = {
|
|
31
|
+
position: DEFAULT_LEGEND_POSITION
|
|
32
|
+
};
|
|
@@ -25,12 +25,14 @@ _export(exports, {
|
|
|
25
25
|
BYTES_UNIT_CONFIG: ()=>BYTES_UNIT_CONFIG,
|
|
26
26
|
formatBytes: ()=>formatBytes
|
|
27
27
|
});
|
|
28
|
+
const _constants = require("./constants");
|
|
28
29
|
const bytesUnitKinds = [
|
|
29
30
|
'Bytes'
|
|
30
31
|
];
|
|
31
32
|
const BYTES_GROUP_CONFIG = {
|
|
32
33
|
label: 'Bytes',
|
|
33
|
-
decimal_places: true
|
|
34
|
+
decimal_places: true,
|
|
35
|
+
abbreviate: true
|
|
34
36
|
};
|
|
35
37
|
const BYTES_UNIT_CONFIG = {
|
|
36
38
|
Bytes: {
|
|
@@ -38,12 +40,35 @@ const BYTES_UNIT_CONFIG = {
|
|
|
38
40
|
label: 'Bytes'
|
|
39
41
|
}
|
|
40
42
|
};
|
|
41
|
-
function formatBytes(bytes,
|
|
42
|
-
if (bytes === 0) return '0
|
|
43
|
+
function formatBytes(bytes, unitOptions) {
|
|
44
|
+
if (bytes === 0) return '0 bytes';
|
|
45
|
+
// default to full 'Bytes' formatting
|
|
46
|
+
const options = unitOptions.abbreviate === undefined ? {
|
|
47
|
+
...unitOptions,
|
|
48
|
+
abbreviate: false
|
|
49
|
+
} : unitOptions;
|
|
50
|
+
var _decimal_places;
|
|
51
|
+
let decimals = (_decimal_places = options.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _constants.DEFAULT_DECIMAL_PLACES;
|
|
52
|
+
// avoids minimumFractionDigits value is out of range error, possible values are 0 to 20
|
|
53
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits
|
|
54
|
+
if (decimals < 0) {
|
|
55
|
+
decimals = 0;
|
|
56
|
+
} else if (decimals > 20) {
|
|
57
|
+
decimals = 20;
|
|
58
|
+
}
|
|
59
|
+
const formatParams = {
|
|
60
|
+
style: 'decimal',
|
|
61
|
+
minimumFractionDigits: decimals,
|
|
62
|
+
maximumFractionDigits: decimals,
|
|
63
|
+
useGrouping: true
|
|
64
|
+
};
|
|
65
|
+
const formatter = new Intl.NumberFormat('en-US', formatParams);
|
|
66
|
+
if (options.abbreviate === false) {
|
|
67
|
+
return `${formatter.format(bytes)} bytes`;
|
|
68
|
+
}
|
|
43
69
|
const k = 1024;
|
|
44
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
45
70
|
const sizes = [
|
|
46
|
-
'
|
|
71
|
+
'bytes',
|
|
47
72
|
'KB',
|
|
48
73
|
'MB',
|
|
49
74
|
'GB',
|
|
@@ -56,5 +81,6 @@ function formatBytes(bytes, decimals = 2) {
|
|
|
56
81
|
// Math.max(0, ...) ensures that we don't return -1 as a value for the index.
|
|
57
82
|
// Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.
|
|
58
83
|
const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));
|
|
59
|
-
|
|
84
|
+
const abbreviatedValue = bytes / Math.pow(k, i);
|
|
85
|
+
return `${formatter.format(abbreviatedValue)} ${sizes[i]}`;
|
|
60
86
|
}
|