@perses-dev/components 0.15.0 → 0.17.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/LineChart/LineChart.d.ts +3 -2
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +6 -16
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/LineChart/utils.d.ts +18 -0
- package/dist/LineChart/utils.d.ts.map +1 -1
- package/dist/LineChart/utils.js +35 -9
- package/dist/LineChart/utils.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorColumn.d.ts +13 -0
- package/dist/OptionsEditorLayout/OptionsEditorColumn.d.ts.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js +28 -0
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts +5 -0
- package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +50 -0
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorGrid.d.ts +13 -0
- package/dist/OptionsEditorLayout/OptionsEditorGrid.d.ts.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js +26 -0
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts +13 -0
- package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js +36 -0
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -0
- package/dist/OptionsEditorLayout/index.d.ts +5 -0
- package/dist/OptionsEditorLayout/index.d.ts.map +1 -0
- package/dist/OptionsEditorLayout/index.js +18 -0
- package/dist/OptionsEditorLayout/index.js.map +1 -0
- package/dist/Tooltip/SeriesInfo.d.ts +1 -0
- package/dist/Tooltip/SeriesInfo.d.ts.map +1 -1
- package/dist/Tooltip/SeriesInfo.js +3 -3
- package/dist/Tooltip/SeriesInfo.js.map +1 -1
- package/dist/Tooltip/Tooltip.d.ts +2 -1
- package/dist/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip/Tooltip.js +2 -2
- package/dist/Tooltip/Tooltip.js.map +1 -1
- package/dist/Tooltip/TooltipContent.d.ts.map +1 -1
- package/dist/Tooltip/TooltipContent.js +2 -1
- package/dist/Tooltip/TooltipContent.js.map +1 -1
- package/dist/Tooltip/focused-series.d.ts +4 -3
- package/dist/Tooltip/focused-series.d.ts.map +1 -1
- package/dist/Tooltip/focused-series.js +6 -3
- package/dist/Tooltip/focused-series.js.map +1 -1
- package/dist/Tooltip/focused-series.test.js +20 -2
- package/dist/Tooltip/focused-series.test.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.d.ts +8 -0
- package/dist/UnitSelector/UnitSelector.d.ts.map +1 -0
- package/dist/UnitSelector/UnitSelector.js +112 -0
- package/dist/UnitSelector/UnitSelector.js.map +1 -0
- package/dist/UnitSelector/UnitSelector.test.d.ts +2 -0
- package/dist/UnitSelector/UnitSelector.test.d.ts.map +1 -0
- package/dist/UnitSelector/UnitSelector.test.js +211 -0
- package/dist/UnitSelector/UnitSelector.test.js.map +1 -0
- package/dist/UnitSelector/index.d.ts +2 -0
- package/dist/UnitSelector/index.d.ts.map +1 -0
- package/dist/UnitSelector/index.js +15 -0
- package/dist/UnitSelector/index.js.map +1 -0
- package/dist/YAxisLabel.d.ts +8 -0
- package/dist/YAxisLabel.d.ts.map +1 -0
- package/dist/YAxisLabel.js +39 -0
- package/dist/YAxisLabel.js.map +1 -0
- package/dist/cjs/LineChart/LineChart.js +5 -15
- package/dist/cjs/LineChart/utils.js +23 -1
- package/dist/cjs/OptionsEditorLayout/OptionsEditorColumn.js +32 -0
- package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +61 -0
- package/dist/cjs/OptionsEditorLayout/OptionsEditorGrid.js +29 -0
- package/dist/cjs/OptionsEditorLayout/OptionsEditorGroup.js +40 -0
- package/dist/cjs/OptionsEditorLayout/index.js +31 -0
- package/dist/cjs/Tooltip/SeriesInfo.js +3 -3
- package/dist/cjs/Tooltip/Tooltip.js +2 -2
- package/dist/cjs/Tooltip/TooltipContent.js +2 -1
- package/dist/cjs/Tooltip/focused-series.js +6 -3
- package/dist/cjs/Tooltip/focused-series.test.js +20 -2
- package/dist/cjs/UnitSelector/UnitSelector.js +118 -0
- package/dist/cjs/UnitSelector/UnitSelector.test.js +218 -0
- package/dist/cjs/UnitSelector/index.js +28 -0
- package/dist/cjs/YAxisLabel.js +45 -0
- package/dist/cjs/index.js +5 -2
- package/dist/cjs/model/units/bytes.js +60 -0
- package/dist/cjs/model/units/constants.js +23 -0
- package/dist/cjs/model/units/decimal.js +67 -0
- package/dist/cjs/model/units/index.js +30 -0
- package/dist/cjs/model/units/percent.js +64 -0
- package/dist/cjs/model/units/time.js +138 -0
- package/dist/cjs/model/units/types.js +28 -0
- package/dist/cjs/model/units/units.js +104 -0
- package/dist/cjs/utils/component-ids.js +31 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/model/units/bytes.d.ts +12 -0
- package/dist/model/units/bytes.d.ts.map +1 -0
- package/dist/model/units/bytes.js +48 -0
- package/dist/model/units/bytes.js.map +1 -0
- package/dist/model/units/constants.d.ts +2 -0
- package/dist/model/units/constants.d.ts.map +1 -0
- package/dist/model/units/constants.js +17 -0
- package/dist/model/units/constants.js.map +1 -0
- package/dist/model/units/decimal.d.ts +24 -0
- package/dist/model/units/decimal.d.ts.map +1 -0
- package/dist/model/units/decimal.js +59 -0
- package/dist/model/units/decimal.js.map +1 -0
- package/dist/model/units/index.d.ts +4 -0
- package/dist/model/units/index.d.ts.map +1 -0
- package/dist/model/units/index.js +17 -0
- package/dist/model/units/index.js.map +1 -0
- package/dist/model/units/percent.d.ts +12 -0
- package/dist/model/units/percent.d.ts.map +1 -0
- package/dist/model/units/percent.js +51 -0
- package/dist/model/units/percent.js.map +1 -0
- package/dist/model/units/time.d.ts +11 -0
- package/dist/model/units/time.d.ts.map +1 -0
- package/dist/model/units/time.js +125 -0
- package/dist/model/units/time.js.map +1 -0
- package/dist/model/units/types.d.ts +38 -0
- package/dist/model/units/types.d.ts.map +1 -0
- package/dist/model/units/types.js +22 -0
- package/dist/model/units/types.js.map +1 -0
- package/dist/model/units/units.d.ts +40 -0
- package/dist/model/units/units.d.ts.map +1 -0
- package/dist/model/units/units.js +83 -0
- package/dist/model/units/units.js.map +1 -0
- package/dist/utils/component-ids.d.ts +8 -0
- package/dist/utils/component-ids.d.ts.map +1 -0
- package/dist/utils/component-ids.js +27 -0
- package/dist/utils/component-ids.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 +2 -2
- package/dist/cjs/model/units.js +0 -203
- package/dist/model/units.d.ts +0 -36
- package/dist/model/units.d.ts.map +0 -1
- package/dist/model/units.js +0 -196
- package/dist/model/units.js.map +0 -1
|
@@ -64,14 +64,14 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
64
64
|
}
|
|
65
65
|
return newObj;
|
|
66
66
|
}
|
|
67
|
-
const Tooltip = /*#__PURE__*/ _react.default.memo(function Tooltip({ chartRef , chartData , wrapLabels , pinTooltip }) {
|
|
67
|
+
const Tooltip = /*#__PURE__*/ _react.default.memo(function Tooltip({ chartRef , chartData , wrapLabels , pinTooltip , unit }) {
|
|
68
68
|
const [pinnedPos, setPinnedPos] = (0, _react.useState)(null);
|
|
69
69
|
const mousePos = (0, _tooltipModel.useMousePosition)();
|
|
70
70
|
if (mousePos === null || mousePos.target === null) return null;
|
|
71
71
|
// ensure user is hovering over a chart before checking for nearby series
|
|
72
72
|
if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS') return null;
|
|
73
73
|
const chart = chartRef.current;
|
|
74
|
-
const focusedSeries = (0, _focusedSeries.getFocusedSeriesData)(mousePos, chartData, pinnedPos, chart);
|
|
74
|
+
const focusedSeries = (0, _focusedSeries.getFocusedSeriesData)(mousePos, chartData, pinnedPos, chart, unit);
|
|
75
75
|
var ref;
|
|
76
76
|
const chartWidth = (ref = chart === null || chart === void 0 ? void 0 : chart.getWidth()) !== null && ref !== void 0 ? ref : 750;
|
|
77
77
|
var ref1;
|
|
@@ -75,12 +75,13 @@ function TooltipContent(props) {
|
|
|
75
75
|
sx: {
|
|
76
76
|
display: 'table'
|
|
77
77
|
},
|
|
78
|
-
children: sortedFocusedSeries.map(({ datumIdx , seriesIdx , seriesName , y , markerColor })=>{
|
|
78
|
+
children: sortedFocusedSeries.map(({ datumIdx , seriesIdx , seriesName , y , formattedY , markerColor })=>{
|
|
79
79
|
if (datumIdx === null || seriesIdx === null) return null;
|
|
80
80
|
const key = seriesIdx.toString() + datumIdx.toString();
|
|
81
81
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_seriesInfo.SeriesInfo, {
|
|
82
82
|
seriesName: seriesName,
|
|
83
83
|
y: y,
|
|
84
|
+
formattedY: formattedY,
|
|
84
85
|
markerColor: markerColor,
|
|
85
86
|
totalSeries: sortedFocusedSeries.length,
|
|
86
87
|
wrapLabels: wrapLabels
|
|
@@ -24,8 +24,9 @@ _export(exports, {
|
|
|
24
24
|
getNearbySeries: ()=>getNearbySeries,
|
|
25
25
|
getFocusedSeriesData: ()=>getFocusedSeriesData
|
|
26
26
|
});
|
|
27
|
+
const _model = require("../model");
|
|
27
28
|
const _tooltipModel = require("./tooltip-model");
|
|
28
|
-
function getNearbySeries(data, pointInGrid, yBuffer) {
|
|
29
|
+
function getNearbySeries(data, pointInGrid, yBuffer, unit) {
|
|
29
30
|
const currentFocusedData = [];
|
|
30
31
|
var ref;
|
|
31
32
|
const focusedX = (ref = pointInGrid[0]) !== null && ref !== void 0 ? ref : null;
|
|
@@ -53,6 +54,7 @@ function getNearbySeries(data, pointInGrid, yBuffer) {
|
|
|
53
54
|
// determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
|
|
54
55
|
const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
|
|
55
56
|
const formattedDate = _tooltipModel.TOOLTIP_DATE_FORMAT.format(xValueMilliSeconds);
|
|
57
|
+
const formattedY = (0, _model.formatValue)(yValue, unit);
|
|
56
58
|
currentFocusedData.push({
|
|
57
59
|
seriesIdx: seriesIdx,
|
|
58
60
|
datumIdx: datumIdx,
|
|
@@ -60,6 +62,7 @@ function getNearbySeries(data, pointInGrid, yBuffer) {
|
|
|
60
62
|
date: formattedDate,
|
|
61
63
|
x: xValue,
|
|
62
64
|
y: yValue,
|
|
65
|
+
formattedY: formattedY,
|
|
63
66
|
markerColor: markerColor.toString()
|
|
64
67
|
});
|
|
65
68
|
}
|
|
@@ -71,7 +74,7 @@ function getNearbySeries(data, pointInGrid, yBuffer) {
|
|
|
71
74
|
}
|
|
72
75
|
return currentFocusedData;
|
|
73
76
|
}
|
|
74
|
-
function getFocusedSeriesData(mousePos, chartData, pinnedPos, chart) {
|
|
77
|
+
function getFocusedSeriesData(mousePos, chartData, pinnedPos, chart, unit) {
|
|
75
78
|
if (chart === undefined || mousePos === null) return [];
|
|
76
79
|
// prevents multiple tooltips showing from adjacent charts
|
|
77
80
|
let cursorTargetMatchesChart = false;
|
|
@@ -107,7 +110,7 @@ function getFocusedSeriesData(mousePos, chartData, pinnedPos, chart) {
|
|
|
107
110
|
if (chart.containPixel('grid', pointInPixel)) {
|
|
108
111
|
const pointInGrid = chart.convertFromPixel('grid', pointInPixel);
|
|
109
112
|
if (pointInGrid[0] !== undefined && pointInGrid[1] !== undefined) {
|
|
110
|
-
return getNearbySeries(chartData, pointInGrid, yBuffer);
|
|
113
|
+
return getNearbySeries(chartData, pointInGrid, yBuffer, unit);
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
return [];
|
|
@@ -68,10 +68,28 @@ describe('getNearbySeries', ()=>{
|
|
|
68
68
|
seriesName: 'env="demo", instance="demo.do.prometheus", job="node", mode="test alt"',
|
|
69
69
|
seriesIdx: 1,
|
|
70
70
|
x: 1654007895000,
|
|
71
|
-
y: 0.0524463040446356
|
|
71
|
+
y: 0.0524463040446356,
|
|
72
|
+
formattedY: '0.05'
|
|
72
73
|
}
|
|
73
74
|
];
|
|
74
75
|
it('should return focused series data for points nearby the cursor', ()=>{
|
|
75
|
-
|
|
76
|
+
const decimalUnit = {
|
|
77
|
+
kind: 'Decimal',
|
|
78
|
+
decimal_places: 2
|
|
79
|
+
};
|
|
80
|
+
expect((0, _focusedSeries.getNearbySeries)(chartData, pointInGrid, yBuffer, decimalUnit)).toEqual(focusedSeriesOutput);
|
|
81
|
+
});
|
|
82
|
+
it('should return series values formatted as a percent', ()=>{
|
|
83
|
+
const percentFormattedOutput = [
|
|
84
|
+
...focusedSeriesOutput
|
|
85
|
+
];
|
|
86
|
+
if (percentFormattedOutput[0]) {
|
|
87
|
+
percentFormattedOutput[0].formattedY = '5%';
|
|
88
|
+
}
|
|
89
|
+
const percentFormattedUnit = {
|
|
90
|
+
kind: 'PercentDecimal',
|
|
91
|
+
decimal_places: 0
|
|
92
|
+
};
|
|
93
|
+
expect((0, _focusedSeries.getNearbySeries)(chartData, pointInGrid, yBuffer, percentFormattedUnit)).toEqual(percentFormattedOutput);
|
|
76
94
|
});
|
|
77
95
|
});
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
Object.defineProperty(exports, "UnitSelector", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>UnitSelector
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
const _model = require("../model");
|
|
24
|
+
const _optionsEditorLayout = require("../OptionsEditorLayout");
|
|
25
|
+
const KIND_OPTIONS = Object.entries(_model.UNIT_CONFIG).map(([id, config])=>{
|
|
26
|
+
return {
|
|
27
|
+
id: id,
|
|
28
|
+
...config
|
|
29
|
+
};
|
|
30
|
+
}).filter((config)=>!config.disableSelectorOption);
|
|
31
|
+
const DECIMAL_OPTIONS = [
|
|
32
|
+
0,
|
|
33
|
+
1,
|
|
34
|
+
2,
|
|
35
|
+
3,
|
|
36
|
+
4
|
|
37
|
+
];
|
|
38
|
+
function UnitSelector({ value , onChange }) {
|
|
39
|
+
const hasDecimalPlaces = (0, _model.isUnitWithDecimalPlaces)(value);
|
|
40
|
+
const hasAbbreviate = (0, _model.isUnitWithAbbreviate)(value);
|
|
41
|
+
const handleKindChange = (_, newValue)=>{
|
|
42
|
+
onChange({
|
|
43
|
+
kind: newValue.id
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const handleDecimalChange = (_, newValue)=>{
|
|
47
|
+
if (hasDecimalPlaces) {
|
|
48
|
+
onChange({
|
|
49
|
+
...value,
|
|
50
|
+
decimal_places: newValue
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const handleAbbreviateChange = (_, checked)=>{
|
|
55
|
+
if (hasAbbreviate) {
|
|
56
|
+
onChange({
|
|
57
|
+
...value,
|
|
58
|
+
abbreviate: checked
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const kindConfig = _model.UNIT_CONFIG[value.kind];
|
|
63
|
+
var _decimal_places;
|
|
64
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
65
|
+
children: [
|
|
66
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
|
|
67
|
+
label: "Abbreviate",
|
|
68
|
+
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
|
|
69
|
+
checked: hasAbbreviate ? !!value.abbreviate : false,
|
|
70
|
+
onChange: handleAbbreviateChange,
|
|
71
|
+
disabled: !hasAbbreviate
|
|
72
|
+
})
|
|
73
|
+
}),
|
|
74
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
|
|
75
|
+
label: "Units",
|
|
76
|
+
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
|
|
77
|
+
value: {
|
|
78
|
+
id: value.kind,
|
|
79
|
+
...kindConfig
|
|
80
|
+
},
|
|
81
|
+
options: KIND_OPTIONS,
|
|
82
|
+
isOptionEqualToValue: (option, value)=>option.id === value.id,
|
|
83
|
+
groupBy: (option)=>option.group,
|
|
84
|
+
renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
85
|
+
...params
|
|
86
|
+
}),
|
|
87
|
+
renderOption: (renderOptsProps, option)=>{
|
|
88
|
+
// Custom option needed to get some increased left padding to make
|
|
89
|
+
// the items more distinct from the group label.
|
|
90
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)("li", {
|
|
91
|
+
...renderOptsProps,
|
|
92
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
93
|
+
paddingLeft: (theme)=>theme.spacing(1),
|
|
94
|
+
children: option.label
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
onChange: handleKindChange,
|
|
99
|
+
disableClearable: true
|
|
100
|
+
})
|
|
101
|
+
}),
|
|
102
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
|
|
103
|
+
label: "Decimal",
|
|
104
|
+
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
|
|
105
|
+
value: hasDecimalPlaces ? (_decimal_places = value.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _model.DEFAULT_DECIMAL_PLACES : 0,
|
|
106
|
+
options: DECIMAL_OPTIONS,
|
|
107
|
+
getOptionLabel: (option)=>`${option}`,
|
|
108
|
+
renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
109
|
+
...params
|
|
110
|
+
}),
|
|
111
|
+
onChange: handleDecimalChange,
|
|
112
|
+
disabled: !hasDecimalPlaces,
|
|
113
|
+
disableClearable: true
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
]
|
|
117
|
+
});
|
|
118
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
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 _unitSelector = require("./UnitSelector");
|
|
21
|
+
function _interopRequireDefault(obj) {
|
|
22
|
+
return obj && obj.__esModule ? obj : {
|
|
23
|
+
default: obj
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
describe('UnitSelector', ()=>{
|
|
27
|
+
const renderUnitSelector = (value, onChange = jest.fn())=>{
|
|
28
|
+
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
29
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_unitSelector.UnitSelector, {
|
|
30
|
+
value: value,
|
|
31
|
+
onChange: onChange
|
|
32
|
+
})
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
const getUnitSelector = ()=>{
|
|
36
|
+
return _react.screen.getByRole('combobox', {
|
|
37
|
+
name: 'Units'
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const getDecimalSelector = ()=>{
|
|
41
|
+
return _react.screen.getByRole('combobox', {
|
|
42
|
+
name: 'Decimal'
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const getAbbreviateSwitch = ()=>{
|
|
46
|
+
return _react.screen.getByRole('checkbox', {
|
|
47
|
+
name: 'Abbreviate'
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
it('can change the unit kind by clicking', ()=>{
|
|
51
|
+
const onChange = jest.fn();
|
|
52
|
+
renderUnitSelector({
|
|
53
|
+
kind: 'Minutes'
|
|
54
|
+
}, onChange);
|
|
55
|
+
const unitSelector = getUnitSelector();
|
|
56
|
+
_userEvent.default.click(unitSelector);
|
|
57
|
+
const decimalOption = _react.screen.getByRole('option', {
|
|
58
|
+
name: 'Decimal'
|
|
59
|
+
});
|
|
60
|
+
_userEvent.default.click(decimalOption);
|
|
61
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
62
|
+
kind: 'Decimal'
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it('can change the unit kind using a keyboard', ()=>{
|
|
66
|
+
const onChange = jest.fn();
|
|
67
|
+
renderUnitSelector({
|
|
68
|
+
kind: 'Bytes'
|
|
69
|
+
}, onChange);
|
|
70
|
+
const unitSelector = getUnitSelector();
|
|
71
|
+
// Note that this tab order can change depending on the type because the
|
|
72
|
+
// abbreviate comes first and is disabled in some cases.
|
|
73
|
+
_userEvent.default.tab();
|
|
74
|
+
expect(unitSelector).toHaveFocus();
|
|
75
|
+
_userEvent.default.clear(unitSelector);
|
|
76
|
+
_userEvent.default.keyboard('years');
|
|
77
|
+
_react.screen.getByRole('option', {
|
|
78
|
+
name: 'Years'
|
|
79
|
+
});
|
|
80
|
+
_userEvent.default.keyboard('{arrowup}{enter}');
|
|
81
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
82
|
+
kind: 'Years'
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
it('can change the decimal places by clicking', ()=>{
|
|
86
|
+
const onChange = jest.fn();
|
|
87
|
+
renderUnitSelector({
|
|
88
|
+
kind: 'Decimal',
|
|
89
|
+
decimal_places: 0,
|
|
90
|
+
abbreviate: true
|
|
91
|
+
}, onChange);
|
|
92
|
+
_userEvent.default.click(getDecimalSelector());
|
|
93
|
+
const decimalOption = _react.screen.getByRole('option', {
|
|
94
|
+
name: '1'
|
|
95
|
+
});
|
|
96
|
+
_userEvent.default.click(decimalOption);
|
|
97
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
98
|
+
kind: 'Decimal',
|
|
99
|
+
decimal_places: 1,
|
|
100
|
+
abbreviate: true
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
it('can change the decimal places using a keyboard', ()=>{
|
|
104
|
+
const onChange = jest.fn();
|
|
105
|
+
renderUnitSelector({
|
|
106
|
+
kind: 'Percent'
|
|
107
|
+
}, onChange);
|
|
108
|
+
const decimalSelector = getDecimalSelector();
|
|
109
|
+
_userEvent.default.tab();
|
|
110
|
+
_userEvent.default.tab();
|
|
111
|
+
expect(decimalSelector).toHaveFocus();
|
|
112
|
+
_userEvent.default.clear(decimalSelector);
|
|
113
|
+
_userEvent.default.keyboard('3');
|
|
114
|
+
_react.screen.getByRole('option', {
|
|
115
|
+
name: '3'
|
|
116
|
+
});
|
|
117
|
+
_userEvent.default.keyboard('{arrowup}{enter}');
|
|
118
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
119
|
+
kind: 'Percent',
|
|
120
|
+
decimal_places: 3
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
it('can change abbreviate by clicking', ()=>{
|
|
124
|
+
const onChange = jest.fn();
|
|
125
|
+
renderUnitSelector({
|
|
126
|
+
kind: 'Decimal',
|
|
127
|
+
decimal_places: 3,
|
|
128
|
+
abbreviate: true
|
|
129
|
+
}, onChange);
|
|
130
|
+
_userEvent.default.click(getAbbreviateSwitch());
|
|
131
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
132
|
+
kind: 'Decimal',
|
|
133
|
+
decimal_places: 3,
|
|
134
|
+
abbreviate: false
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
it('can change abbreviate using a keyboard', ()=>{
|
|
138
|
+
const onChange = jest.fn();
|
|
139
|
+
renderUnitSelector({
|
|
140
|
+
kind: 'Decimal',
|
|
141
|
+
decimal_places: 0
|
|
142
|
+
}, onChange);
|
|
143
|
+
_userEvent.default.tab();
|
|
144
|
+
_userEvent.default.keyboard('{space}');
|
|
145
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
146
|
+
kind: 'Decimal',
|
|
147
|
+
decimal_places: 0,
|
|
148
|
+
abbreviate: true
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
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
|
+
it('does not allow the user to set abbreviate', ()=>{
|
|
159
|
+
renderUnitSelector({
|
|
160
|
+
kind: 'Minutes'
|
|
161
|
+
});
|
|
162
|
+
expect(getAbbreviateSwitch()).toBeDisabled();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
describe('with a percent unit selected', ()=>{
|
|
166
|
+
it('allows the user to modify the decimal places', ()=>{
|
|
167
|
+
renderUnitSelector({
|
|
168
|
+
kind: 'Percent'
|
|
169
|
+
});
|
|
170
|
+
expect(getDecimalSelector()).toBeEnabled();
|
|
171
|
+
});
|
|
172
|
+
it('does not allow the user to set abbreviate', ()=>{
|
|
173
|
+
renderUnitSelector({
|
|
174
|
+
kind: 'PercentDecimal'
|
|
175
|
+
});
|
|
176
|
+
expect(getAbbreviateSwitch()).toBeDisabled();
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
describe('with a decimal unit selected', ()=>{
|
|
180
|
+
it('allows the user to modify the decimal places', ()=>{
|
|
181
|
+
renderUnitSelector({
|
|
182
|
+
kind: 'Decimal'
|
|
183
|
+
});
|
|
184
|
+
expect(getDecimalSelector()).toBeEnabled();
|
|
185
|
+
});
|
|
186
|
+
it('allows the user to set abbreviate', ()=>{
|
|
187
|
+
renderUnitSelector({
|
|
188
|
+
kind: 'Decimal'
|
|
189
|
+
});
|
|
190
|
+
expect(getAbbreviateSwitch()).toBeEnabled();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
describe('with a bytes unit selected', ()=>{
|
|
194
|
+
it('allows the user to modify the decimal places', ()=>{
|
|
195
|
+
renderUnitSelector({
|
|
196
|
+
kind: 'Bytes'
|
|
197
|
+
});
|
|
198
|
+
expect(getDecimalSelector()).toBeEnabled();
|
|
199
|
+
});
|
|
200
|
+
it('does not allow the user to set abbreviate', ()=>{
|
|
201
|
+
renderUnitSelector({
|
|
202
|
+
kind: 'Bytes'
|
|
203
|
+
});
|
|
204
|
+
expect(getAbbreviateSwitch()).toBeDisabled();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
it('should not show an option for disabled units', ()=>{
|
|
208
|
+
const onChange = jest.fn();
|
|
209
|
+
renderUnitSelector({
|
|
210
|
+
kind: 'Decimal'
|
|
211
|
+
}, onChange);
|
|
212
|
+
_userEvent.default.click(getUnitSelector());
|
|
213
|
+
const percentShorthandOption = _react.screen.queryByRole('option', {
|
|
214
|
+
name: '%'
|
|
215
|
+
});
|
|
216
|
+
expect(percentShorthandOption).not.toBeInTheDocument();
|
|
217
|
+
});
|
|
218
|
+
});
|
|
@@ -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("./UnitSelector"), 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
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
Object.defineProperty(exports, "YAxisLabel", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>YAxisLabel
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
function YAxisLabel({ name , height }) {
|
|
24
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
25
|
+
sx: {
|
|
26
|
+
display: 'inline-block',
|
|
27
|
+
maxWidth: height,
|
|
28
|
+
position: 'absolute',
|
|
29
|
+
top: '45%',
|
|
30
|
+
transform: 'translateX(-50%) rotate(-90deg)',
|
|
31
|
+
transformOrigin: 'top',
|
|
32
|
+
textAlign: 'center',
|
|
33
|
+
zIndex: 1
|
|
34
|
+
},
|
|
35
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
|
|
36
|
+
variant: "body1",
|
|
37
|
+
sx: {
|
|
38
|
+
whiteSpace: 'nowrap',
|
|
39
|
+
overflow: 'hidden',
|
|
40
|
+
textOverflow: 'ellipsis'
|
|
41
|
+
},
|
|
42
|
+
children: name
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,17 +14,20 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
+
_exportStar(require("./DateTimeRangePicker"), exports);
|
|
17
18
|
_exportStar(require("./Drawer"), exports);
|
|
18
19
|
_exportStar(require("./EChart"), exports);
|
|
19
20
|
_exportStar(require("./ErrorAlert"), exports);
|
|
20
21
|
_exportStar(require("./ErrorBoundary"), exports);
|
|
22
|
+
_exportStar(require("./GaugeChart"), exports);
|
|
21
23
|
_exportStar(require("./InfoTooltip"), exports);
|
|
22
24
|
_exportStar(require("./JSONEditor"), exports);
|
|
23
25
|
_exportStar(require("./Legend"), exports);
|
|
24
26
|
_exportStar(require("./LineChart"), exports);
|
|
25
|
-
_exportStar(require("./
|
|
27
|
+
_exportStar(require("./OptionsEditorLayout"), exports);
|
|
26
28
|
_exportStar(require("./StatChart"), exports);
|
|
27
|
-
_exportStar(require("./
|
|
29
|
+
_exportStar(require("./UnitSelector"), exports);
|
|
30
|
+
_exportStar(require("./YAxisLabel"), exports);
|
|
28
31
|
_exportStar(require("./context/ChartsThemeProvider"), exports);
|
|
29
32
|
_exportStar(require("./utils"), exports);
|
|
30
33
|
_exportStar(require("./model"), exports);
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
BYTES_GROUP_CONFIG: ()=>BYTES_GROUP_CONFIG,
|
|
25
|
+
BYTES_UNIT_CONFIG: ()=>BYTES_UNIT_CONFIG,
|
|
26
|
+
formatBytes: ()=>formatBytes
|
|
27
|
+
});
|
|
28
|
+
const bytesUnitKinds = [
|
|
29
|
+
'Bytes'
|
|
30
|
+
];
|
|
31
|
+
const BYTES_GROUP_CONFIG = {
|
|
32
|
+
label: 'Bytes',
|
|
33
|
+
decimal_places: true
|
|
34
|
+
};
|
|
35
|
+
const BYTES_UNIT_CONFIG = {
|
|
36
|
+
Bytes: {
|
|
37
|
+
group: 'Bytes',
|
|
38
|
+
label: 'Bytes'
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
function formatBytes(bytes, decimals = 2) {
|
|
42
|
+
if (bytes === 0) return '0 Bytes';
|
|
43
|
+
const k = 1024;
|
|
44
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
45
|
+
const sizes = [
|
|
46
|
+
'Bytes',
|
|
47
|
+
'KB',
|
|
48
|
+
'MB',
|
|
49
|
+
'GB',
|
|
50
|
+
'TB',
|
|
51
|
+
'PB',
|
|
52
|
+
'EB',
|
|
53
|
+
'ZB',
|
|
54
|
+
'YB'
|
|
55
|
+
];
|
|
56
|
+
// Math.max(0, ...) ensures that we don't return -1 as a value for the index.
|
|
57
|
+
// Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.
|
|
58
|
+
const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));
|
|
59
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
60
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
// Common constants needed across individual unit groups and the overall
|
|
14
|
+
// combined units.
|
|
15
|
+
"use strict";
|
|
16
|
+
Object.defineProperty(exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "DEFAULT_DECIMAL_PLACES", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: ()=>DEFAULT_DECIMAL_PLACES
|
|
22
|
+
});
|
|
23
|
+
const DEFAULT_DECIMAL_PLACES = 2;
|