@perses-dev/components 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +38 -32
- 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 +9 -2
- 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 -4
- 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 +37 -31
- package/dist/cjs/LineChart/utils.js +4 -3
- package/dist/cjs/StatChart/StatChart.test.js +9 -2
- package/dist/cjs/Tooltip/TooltipContent.js +8 -9
- package/dist/cjs/UnitSelector/UnitSelector.test.js +3 -4
- 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 +1 -1
- package/dist/cjs/model/units/units.js +1 -4
- package/dist/cjs/model/units/units.test.js +153 -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.js +1 -1
- 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/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
|
@@ -26,8 +26,10 @@ const _charts = require("echarts/charts");
|
|
|
26
26
|
const _components = require("echarts/components");
|
|
27
27
|
const _renderers = require("echarts/renderers");
|
|
28
28
|
const _echart = require("../EChart");
|
|
29
|
+
const _graph = require("../model/graph");
|
|
29
30
|
const _chartsThemeProvider = require("../context/ChartsThemeProvider");
|
|
30
31
|
const _tooltip = require("../Tooltip/Tooltip");
|
|
32
|
+
const _timeZoneProvider = require("../context/TimeZoneProvider");
|
|
31
33
|
const _utils = require("./utils");
|
|
32
34
|
(0, _core.use)([
|
|
33
35
|
_charts.LineChart,
|
|
@@ -40,14 +42,14 @@ const _utils = require("./utils");
|
|
|
40
42
|
_components.ToolboxComponent,
|
|
41
43
|
_components.TooltipComponent,
|
|
42
44
|
_components.LegendComponent,
|
|
43
|
-
_components.VisualMapComponent,
|
|
44
45
|
_renderers.CanvasRenderer
|
|
45
46
|
]);
|
|
46
|
-
function LineChart({ height , data , yAxis , unit , grid , legend ,
|
|
47
|
+
function LineChart({ height , data , yAxis , unit , grid , legend , onDataZoom , onDoubleClick }) {
|
|
47
48
|
const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
|
|
48
49
|
const chartRef = (0, _react.useRef)();
|
|
49
50
|
const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
|
|
50
51
|
const [pinTooltip, setPinTooltip] = (0, _react.useState)(false);
|
|
52
|
+
const { timeZone } = (0, _timeZoneProvider.useTimeZone)();
|
|
51
53
|
const handleEvents = (0, _react.useMemo)(()=>{
|
|
52
54
|
return {
|
|
53
55
|
datazoom: (params)=>{
|
|
@@ -83,7 +85,6 @@ function LineChart({ height , data , yAxis , unit , grid , legend , visualMap ,
|
|
|
83
85
|
if (chartRef.current !== undefined) {
|
|
84
86
|
(0, _utils.enableDataZoom)(chartRef.current);
|
|
85
87
|
}
|
|
86
|
-
const handleOnClick = ()=>setPinTooltip((current)=>!current);
|
|
87
88
|
const handleOnDoubleClick = (e)=>{
|
|
88
89
|
setPinTooltip(false);
|
|
89
90
|
// either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
|
|
@@ -95,25 +96,12 @@ function LineChart({ height , data , yAxis , unit , grid , legend , visualMap ,
|
|
|
95
96
|
onDoubleClick(e);
|
|
96
97
|
}
|
|
97
98
|
};
|
|
98
|
-
const
|
|
99
|
-
// hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
|
|
100
|
-
if (e.target instanceof HTMLCanvasElement) {
|
|
101
|
-
setShowTooltip(false);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const handleOnMouseUp = ()=>{
|
|
105
|
-
setShowTooltip(true);
|
|
106
|
-
};
|
|
107
|
-
const handleOnMouseEnter = ()=>{
|
|
108
|
-
setShowTooltip(true);
|
|
109
|
-
};
|
|
110
|
-
const handleOnMouseLeave = ()=>{
|
|
111
|
-
setShowTooltip(false);
|
|
112
|
-
setPinTooltip(false);
|
|
113
|
-
};
|
|
99
|
+
const { noDataOption } = chartsTheme;
|
|
114
100
|
const option = (0, _react.useMemo)(()=>{
|
|
115
101
|
if (data.timeSeries === undefined) return {};
|
|
116
|
-
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;
|
|
117
105
|
var _rangeMs;
|
|
118
106
|
const rangeMs = (_rangeMs = data.rangeMs) !== null && _rangeMs !== void 0 ? _rangeMs : (0, _utils.getDateRange)(data.xAxis);
|
|
119
107
|
const option = {
|
|
@@ -124,18 +112,18 @@ function LineChart({ height , data , yAxis , unit , grid , legend , visualMap ,
|
|
|
124
112
|
max: data.xAxisMax,
|
|
125
113
|
axisLabel: {
|
|
126
114
|
formatter: (value)=>{
|
|
127
|
-
return (0, _utils.getFormattedDate)(value, rangeMs);
|
|
115
|
+
return (0, _utils.getFormattedDate)(value, rangeMs, timeZone);
|
|
128
116
|
}
|
|
129
117
|
}
|
|
130
118
|
},
|
|
131
119
|
yAxis: (0, _utils.getYAxes)(yAxis, unit),
|
|
132
120
|
animation: false,
|
|
133
121
|
tooltip: {
|
|
134
|
-
show:
|
|
122
|
+
show: !isOptimizedMode,
|
|
135
123
|
trigger: 'axis',
|
|
136
124
|
showContent: false,
|
|
137
125
|
axisPointer: {
|
|
138
|
-
type: 'line',
|
|
126
|
+
type: isOptimizedMode ? 'none' : 'line',
|
|
139
127
|
z: 0
|
|
140
128
|
}
|
|
141
129
|
},
|
|
@@ -148,27 +136,45 @@ function LineChart({ height , data , yAxis , unit , grid , legend , visualMap ,
|
|
|
148
136
|
}
|
|
149
137
|
},
|
|
150
138
|
grid,
|
|
151
|
-
legend
|
|
152
|
-
visualMap
|
|
139
|
+
legend
|
|
153
140
|
};
|
|
154
141
|
return option;
|
|
155
142
|
}, [
|
|
156
143
|
data,
|
|
157
144
|
yAxis,
|
|
145
|
+
unit,
|
|
158
146
|
grid,
|
|
159
147
|
legend,
|
|
160
|
-
|
|
148
|
+
noDataOption,
|
|
149
|
+
timeZone
|
|
161
150
|
]);
|
|
162
151
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
163
152
|
sx: {
|
|
164
153
|
height
|
|
165
154
|
},
|
|
166
|
-
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
|
+
},
|
|
167
177
|
onDoubleClick: handleOnDoubleClick,
|
|
168
|
-
onMouseDown: handleOnMouseDown,
|
|
169
|
-
onMouseUp: handleOnMouseUp,
|
|
170
|
-
onMouseLeave: handleOnMouseLeave,
|
|
171
|
-
onMouseEnter: handleOnMouseEnter,
|
|
172
178
|
children: [
|
|
173
179
|
showTooltip === true && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltip.Tooltip, {
|
|
174
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) {
|
|
@@ -72,14 +72,21 @@ describe('StatChart', ()=>{
|
|
|
72
72
|
renderChart(unit);
|
|
73
73
|
expect(_react.screen.getByText('7.73')).toBeInTheDocument();
|
|
74
74
|
});
|
|
75
|
-
it('show value with
|
|
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', ()=>{
|
|
76
83
|
const unit = {
|
|
77
84
|
kind: 'Seconds'
|
|
78
85
|
};
|
|
79
86
|
renderChart(unit);
|
|
80
87
|
expect(_react.screen.getByText('7.73 seconds')).toBeInTheDocument();
|
|
81
88
|
});
|
|
82
|
-
it('show value with time unit formatting', ()=>{
|
|
89
|
+
it('show value with months time unit formatting', ()=>{
|
|
83
90
|
const unit = {
|
|
84
91
|
kind: 'Months'
|
|
85
92
|
};
|
|
@@ -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);
|
|
@@ -191,11 +190,11 @@ describe('UnitSelector', ()=>{
|
|
|
191
190
|
});
|
|
192
191
|
expect(getDecimalSelector()).toBeEnabled();
|
|
193
192
|
});
|
|
194
|
-
it('
|
|
193
|
+
it('allows the user to set abbreviate', ()=>{
|
|
195
194
|
renderUnitSelector({
|
|
196
195
|
kind: 'Bytes'
|
|
197
196
|
});
|
|
198
|
-
expect(getAbbreviateSwitch()).
|
|
197
|
+
expect(getAbbreviateSwitch()).toBeEnabled();
|
|
199
198
|
});
|
|
200
199
|
});
|
|
201
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
|
}
|
|
@@ -91,7 +91,7 @@ function formatTime(value, unitOptions) {
|
|
|
91
91
|
var _decimal_places;
|
|
92
92
|
const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _constants.DEFAULT_DECIMAL_PLACES;
|
|
93
93
|
const timeUnit = TimeIntlDuration[unitOptions.kind];
|
|
94
|
-
const formatter = new Intl.NumberFormat('en', {
|
|
94
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
95
95
|
style: 'unit',
|
|
96
96
|
unit: timeUnit,
|
|
97
97
|
unitDisplay: 'long',
|
|
@@ -35,7 +35,6 @@ _export(exports, {
|
|
|
35
35
|
isUnitWithAbbreviate: ()=>isUnitWithAbbreviate
|
|
36
36
|
});
|
|
37
37
|
const _bytes = require("./bytes");
|
|
38
|
-
const _constants = require("./constants");
|
|
39
38
|
const _decimal = require("./decimal");
|
|
40
39
|
const _percent = require("./percent");
|
|
41
40
|
const _time = require("./time");
|
|
@@ -65,9 +64,7 @@ function formatValue(value, unitOptions) {
|
|
|
65
64
|
return (0, _percent.formatPercent)(value, unitOptions);
|
|
66
65
|
}
|
|
67
66
|
if (isBytesUnit(unitOptions)) {
|
|
68
|
-
|
|
69
|
-
const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _constants.DEFAULT_DECIMAL_PLACES;
|
|
70
|
-
return (0, _bytes.formatBytes)(value, decimals);
|
|
67
|
+
return (0, _bytes.formatBytes)(value, unitOptions);
|
|
71
68
|
}
|
|
72
69
|
const exhaustive = unitOptions;
|
|
73
70
|
throw new Error(`Unknown unit options ${exhaustive}`);
|
|
@@ -0,0 +1,153 @@
|
|
|
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 _units = require("./units");
|
|
18
|
+
describe('formatValue()', ()=>{
|
|
19
|
+
const tests = [
|
|
20
|
+
{
|
|
21
|
+
value: 100000,
|
|
22
|
+
unit: {
|
|
23
|
+
kind: 'Decimal'
|
|
24
|
+
},
|
|
25
|
+
expected: '100,000.00'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
value: 155900,
|
|
29
|
+
unit: {
|
|
30
|
+
kind: 'Decimal',
|
|
31
|
+
decimal_places: 4
|
|
32
|
+
},
|
|
33
|
+
expected: '155,900.0000'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
value: 10,
|
|
37
|
+
unit: {
|
|
38
|
+
kind: 'Percent'
|
|
39
|
+
},
|
|
40
|
+
expected: '10.00%'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
value: 50,
|
|
44
|
+
unit: {
|
|
45
|
+
kind: 'Percent',
|
|
46
|
+
decimal_places: 0
|
|
47
|
+
},
|
|
48
|
+
expected: '50%'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
value: 0.1,
|
|
52
|
+
unit: {
|
|
53
|
+
kind: 'PercentDecimal'
|
|
54
|
+
},
|
|
55
|
+
expected: '10.00%'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
value: 100,
|
|
59
|
+
unit: {
|
|
60
|
+
kind: 'Bytes',
|
|
61
|
+
decimal_places: 0,
|
|
62
|
+
abbreviate: false
|
|
63
|
+
},
|
|
64
|
+
expected: '100 bytes'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
value: 100,
|
|
68
|
+
unit: {
|
|
69
|
+
kind: 'Bytes',
|
|
70
|
+
decimal_places: -1,
|
|
71
|
+
abbreviate: false
|
|
72
|
+
},
|
|
73
|
+
expected: '100 bytes'
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
value: 225000,
|
|
77
|
+
unit: {
|
|
78
|
+
kind: 'Bytes',
|
|
79
|
+
decimal_places: 0,
|
|
80
|
+
abbreviate: true
|
|
81
|
+
},
|
|
82
|
+
expected: '220 KB'
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
value: 505200,
|
|
86
|
+
unit: {
|
|
87
|
+
kind: 'Bytes'
|
|
88
|
+
},
|
|
89
|
+
expected: '505,200.00 bytes'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
value: 8000,
|
|
93
|
+
unit: {
|
|
94
|
+
kind: 'Milliseconds'
|
|
95
|
+
},
|
|
96
|
+
expected: '8,000.00 milliseconds'
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
value: 200900,
|
|
100
|
+
unit: {
|
|
101
|
+
kind: 'Seconds'
|
|
102
|
+
},
|
|
103
|
+
expected: '200,900.00 seconds'
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
value: 300,
|
|
107
|
+
unit: {
|
|
108
|
+
kind: 'Minutes'
|
|
109
|
+
},
|
|
110
|
+
expected: '300.00 minutes'
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
value: 300,
|
|
114
|
+
unit: {
|
|
115
|
+
kind: 'Hours'
|
|
116
|
+
},
|
|
117
|
+
expected: '300.00 hours'
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
value: 300,
|
|
121
|
+
unit: {
|
|
122
|
+
kind: 'Days'
|
|
123
|
+
},
|
|
124
|
+
expected: '300.00 days'
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
value: 300,
|
|
128
|
+
unit: {
|
|
129
|
+
kind: 'Weeks'
|
|
130
|
+
},
|
|
131
|
+
expected: '300.00 weeks'
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
value: 300,
|
|
135
|
+
unit: {
|
|
136
|
+
kind: 'Months'
|
|
137
|
+
},
|
|
138
|
+
expected: '300.00 months'
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
value: 300,
|
|
142
|
+
unit: {
|
|
143
|
+
kind: 'Years'
|
|
144
|
+
},
|
|
145
|
+
expected: '300.00 years'
|
|
146
|
+
}
|
|
147
|
+
];
|
|
148
|
+
tests.forEach(({ value , unit , expected })=>{
|
|
149
|
+
it(`formats ${value} as ${JSON.stringify(unit)}`, ()=>{
|
|
150
|
+
expect((0, _units.formatValue)(value, unit)).toEqual(expected);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|