@perses-dev/components 0.0.0-snapshot-test-internal-dep-dd238ac → 0.0.0-snapshot-color-palette-gen-test-bc1b508

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/Dialog/Dialog.d.ts +2 -1
  2. package/dist/Dialog/Dialog.d.ts.map +1 -1
  3. package/dist/Dialog/Dialog.js +12 -1
  4. package/dist/Dialog/Dialog.js.map +1 -1
  5. package/dist/InfoTooltip/InfoTooltip.d.ts.map +1 -1
  6. package/dist/InfoTooltip/InfoTooltip.js +10 -3
  7. package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
  8. package/dist/Legend/CompactLegend.d.ts +3 -1
  9. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  10. package/dist/Legend/CompactLegend.js +3 -1
  11. package/dist/Legend/CompactLegend.js.map +1 -1
  12. package/dist/Legend/Legend.d.ts +11 -3
  13. package/dist/Legend/Legend.d.ts.map +1 -1
  14. package/dist/Legend/Legend.js +24 -7
  15. package/dist/Legend/Legend.js.map +1 -1
  16. package/dist/Legend/ListLegend.d.ts +14 -4
  17. package/dist/Legend/ListLegend.d.ts.map +1 -1
  18. package/dist/Legend/ListLegend.js +111 -15
  19. package/dist/Legend/ListLegend.js.map +1 -1
  20. package/dist/Legend/ListLegendItem.d.ts +14 -2
  21. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  22. package/dist/Legend/ListLegendItem.js +31 -3
  23. package/dist/Legend/ListLegendItem.js.map +1 -1
  24. package/dist/LineChart/LineChart.d.ts +8 -2
  25. package/dist/LineChart/LineChart.d.ts.map +1 -1
  26. package/dist/LineChart/LineChart.js +11 -4
  27. package/dist/LineChart/LineChart.js.map +1 -1
  28. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts +4 -2
  29. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -1
  30. package/dist/OptionsEditorLayout/OptionsEditorControl.js +34 -5
  31. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  32. package/dist/StatChart/StatChart.d.ts +1 -0
  33. package/dist/StatChart/StatChart.d.ts.map +1 -1
  34. package/dist/StatChart/StatChart.js +2 -2
  35. package/dist/StatChart/StatChart.js.map +1 -1
  36. package/dist/ThresholdsEditor/ThresholdInput.d.ts +3 -1
  37. package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -1
  38. package/dist/ThresholdsEditor/ThresholdInput.js +9 -3
  39. package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
  40. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -1
  41. package/dist/ThresholdsEditor/ThresholdsEditor.js +57 -35
  42. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  43. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
  44. package/dist/TimeSeriesTooltip/SeriesInfo.js +4 -4
  45. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  46. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +1 -9
  47. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  48. package/dist/TimeSeriesTooltip/tooltip-model.js +3 -7
  49. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  50. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  51. package/dist/TimeSeriesTooltip/utils.js +9 -6
  52. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  53. package/dist/cjs/Dialog/Dialog.js +11 -0
  54. package/dist/cjs/InfoTooltip/InfoTooltip.js +10 -3
  55. package/dist/cjs/Legend/Legend.js +24 -7
  56. package/dist/cjs/Legend/ListLegend.js +106 -13
  57. package/dist/cjs/Legend/ListLegendItem.js +30 -2
  58. package/dist/cjs/LineChart/LineChart.js +11 -4
  59. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +33 -4
  60. package/dist/cjs/StatChart/StatChart.js +2 -2
  61. package/dist/cjs/ThresholdsEditor/ThresholdInput.js +8 -2
  62. package/dist/cjs/ThresholdsEditor/ThresholdsEditor.js +56 -34
  63. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +4 -4
  64. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +3 -7
  65. package/dist/cjs/TimeSeriesTooltip/utils.js +9 -6
  66. package/dist/cjs/model/units/bytes.js +33 -39
  67. package/dist/cjs/model/units/decimal.js +15 -26
  68. package/dist/cjs/model/units/time.js +2 -3
  69. package/dist/cjs/theme/component-overrides/alert.js +102 -0
  70. package/dist/cjs/theme/theme.js +2 -11
  71. package/dist/cjs/utils/theme-gen.js +13 -5
  72. package/dist/model/legend.d.ts +1 -1
  73. package/dist/model/legend.d.ts.map +1 -1
  74. package/dist/model/legend.js.map +1 -1
  75. package/dist/model/units/bytes.d.ts +1 -5
  76. package/dist/model/units/bytes.d.ts.map +1 -1
  77. package/dist/model/units/bytes.js +28 -42
  78. package/dist/model/units/bytes.js.map +1 -1
  79. package/dist/model/units/decimal.d.ts +1 -12
  80. package/dist/model/units/decimal.d.ts.map +1 -1
  81. package/dist/model/units/decimal.js +14 -30
  82. package/dist/model/units/decimal.js.map +1 -1
  83. package/dist/model/units/time.d.ts.map +1 -1
  84. package/dist/model/units/time.js +2 -3
  85. package/dist/model/units/time.js.map +1 -1
  86. package/dist/theme/component-overrides/alert.d.ts +3 -0
  87. package/dist/theme/component-overrides/alert.d.ts.map +1 -0
  88. package/dist/theme/component-overrides/alert.js +96 -0
  89. package/dist/theme/component-overrides/alert.js.map +1 -0
  90. package/dist/theme/theme.d.ts.map +1 -1
  91. package/dist/theme/theme.js +3 -12
  92. package/dist/theme/theme.js.map +1 -1
  93. package/dist/utils/theme-gen.d.ts.map +1 -1
  94. package/dist/utils/theme-gen.js +13 -5
  95. package/dist/utils/theme-gen.js.map +1 -1
  96. package/package.json +11 -5
@@ -20,25 +20,118 @@ Object.defineProperty(exports, "ListLegend", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
+ const _reactWindow = require("react-window");
24
+ const _react = require("react");
23
25
  const _listLegendItem = require("./ListLegendItem");
24
- function ListLegend({ items }) {
26
+ const DEFAULT_INITIAL_ROW_HEIGHT = 26;
27
+ function ListLegend({ items , height , width , initialRowHeight =DEFAULT_INITIAL_ROW_HEIGHT }) {
28
+ // Storing a ref to the react-window `VariableSizeList`, so we can call
29
+ // `resetAfterIndex` to resize the list after mouseover/out events to account
30
+ // for the change in list items on hover.
31
+ const listRef = (0, _react.useRef)(null);
32
+ // Storing row heights, so we can use dynamic heights, which enables the
33
+ // user the hover to show the full label, while still having a virtualized
34
+ // list.
35
+ const rowHeights = (0, _react.useRef)({});
36
+ const theme = (0, _material.useTheme)();
37
+ // Padding value used throughout to adjust the react-window virtual layouts
38
+ // to simulate padding per the guidance from:
39
+ // https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list
40
+ const LIST_PADDING = parseInt(theme.spacing(1), 10);
25
41
  // show full labels on hover when there are many total series
26
42
  const truncateLabels = items.length > 5;
27
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.List, {
28
- children: items.map((item)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegendItem.ListLegendItem, {
43
+ // Gets the row height for a given item to enable the virtualized list to
44
+ // render the row properly.
45
+ function getRowHeight(index) {
46
+ const currentHeight = rowHeights.current[index];
47
+ return currentHeight !== null && currentHeight !== void 0 ? currentHeight : initialRowHeight;
48
+ }
49
+ // Set the height for a given item to enable the virtualized list to
50
+ // adjust to size changes.
51
+ function setRowHeight(index, size) {
52
+ var // Tell the virtualized list that items changed size and need to be
53
+ // re-evaluated.
54
+ ref;
55
+ (ref = listRef.current) === null || ref === void 0 ? void 0 : ref.resetAfterIndex(0);
56
+ rowHeights.current = {
57
+ ...rowHeights.current,
58
+ [index]: size
59
+ };
60
+ }
61
+ // Renderer for virtualized rows in `VariableSizeList`.
62
+ function ListLegendRow({ index , style }) {
63
+ // Storing a ref to the row's `ListLegendItem`, so we can get the "real"
64
+ // height and adjust the height of the row based on it, enabling the dynamic
65
+ // heights on hover.
66
+ const rowRef = (0, _react.useRef)(null);
67
+ // useCallback is important here to avoid constantly running the useEffect
68
+ // that calls this in `ListLegendItem`.
69
+ const handleRowLayoutChange = (0, _react.useCallback)(()=>{
70
+ // Handle size changes from hovering on a list item.
71
+ if (rowRef.current) {
72
+ setRowHeight(index, rowRef.current.clientHeight);
73
+ }
74
+ }, [
75
+ index
76
+ ]);
77
+ // Adjust row heights when the row being rendered changes.
78
+ (0, _react.useEffect)(()=>{
79
+ handleRowLayoutChange();
80
+ }, [
81
+ handleRowLayoutChange
82
+ ]);
83
+ const item = items[index];
84
+ if (!item) {
85
+ // This shouldn't happen if configured correctly, but covering
86
+ // the case to appease the type checking and to cover any edge
87
+ // cases.
88
+ return null;
89
+ }
90
+ const originalTop = parseFloat(`${style.top}`);
91
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
92
+ style: {
93
+ ...style,
94
+ // Adjust the top position to simulate top padding on the list.
95
+ top: `${originalTop + LIST_PADDING}px`
96
+ },
97
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegendItem.ListLegendItem, {
98
+ ref: rowRef,
29
99
  item: item,
100
+ truncateLabel: truncateLabels,
101
+ onLayoutChange: handleRowLayoutChange,
30
102
  sx: {
31
- width: 190,
32
- textOverflow: 'ellipsis',
103
+ // Having an explicit width is important for the ellipsizing to
104
+ // work correctly. Subtract padding to simulate padding.
105
+ width: width - LIST_PADDING,
33
106
  wordBreak: 'break-word',
34
- overflow: truncateLabels ? 'hidden' : 'visible',
35
- whiteSpace: truncateLabels ? 'nowrap' : 'normal',
36
- // TODO: add optional hover effect to show unformatted label
37
- '&:hover': {
38
- overflow: 'visible',
39
- whiteSpace: 'normal'
40
- }
107
+ overflow: 'hidden'
41
108
  }
42
- }, item.id))
109
+ }, item.id)
110
+ });
111
+ }
112
+ // Renderer for the inner container element of the `VariableSizeList` used
113
+ // to adjust styles to simulate padding on the list per:
114
+ // https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list
115
+ const InnerElementType = /*#__PURE__*/ (0, _react.forwardRef)(function InnerElementType({ style , ...rest }, ref) {
116
+ const originalHeight = (style === null || style === void 0 ? void 0 : style.height) ? parseFloat(`${style === null || style === void 0 ? void 0 : style.height}`) : 0;
117
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
118
+ ref: ref,
119
+ role: "list",
120
+ style: {
121
+ ...style,
122
+ // Adjust height to account for simulated padding.
123
+ height: `${originalHeight + LIST_PADDING * 2}px`
124
+ },
125
+ ...rest
126
+ });
127
+ });
128
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactWindow.VariableSizeList, {
129
+ height: height,
130
+ width: width,
131
+ itemCount: items.length,
132
+ itemSize: getRowHeight,
133
+ innerElementType: InnerElementType,
134
+ ref: listRef,
135
+ children: ListLegendRow
43
136
  });
44
137
  }
@@ -62,9 +62,30 @@ function _interopRequireWildcard(obj, nodeInterop) {
62
62
  }
63
63
  return newObj;
64
64
  }
65
- const ListLegendItem = /*#__PURE__*/ _react.default.memo(function ListLegendItem({ item , sx , ...others }) {
65
+ const ListLegendItemBase = /*#__PURE__*/ (0, _react.forwardRef)(function ListLegendItem({ item , sx , truncateLabel , onLayoutChange , ...others }, ref) {
66
+ const [noWrap, setNoWrap] = (0, _react.useState)(truncateLabel);
67
+ function handleMouseOver() {
68
+ if (truncateLabel) {
69
+ setNoWrap(false);
70
+ }
71
+ }
72
+ function handleMouseOut() {
73
+ if (truncateLabel) {
74
+ setNoWrap(true);
75
+ }
76
+ }
77
+ (0, _react.useEffect)(()=>{
78
+ // When `noWrap` changes, so does the layout of the component. Notifies the
79
+ // parent, so it can handle those changes.
80
+ onLayoutChange === null || onLayoutChange === void 0 ? void 0 : onLayoutChange();
81
+ }, [
82
+ noWrap,
83
+ onLayoutChange
84
+ ]);
66
85
  return /*#__PURE__*/ (0, _react.createElement)(_material.ListItem, {
67
86
  ...others,
87
+ component: "div",
88
+ role: "listitem",
68
89
  sx: (0, _utils.combineSx)({
69
90
  padding: 0,
70
91
  cursor: 'pointer'
@@ -73,6 +94,7 @@ const ListLegendItem = /*#__PURE__*/ _react.default.memo(function ListLegendItem
73
94
  key: item.id,
74
95
  onClick: item.onClick,
75
96
  selected: item.isSelected,
97
+ ref: ref,
76
98
  children: [
77
99
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
78
100
  sx: {
@@ -84,8 +106,14 @@ const ListLegendItem = /*#__PURE__*/ _react.default.memo(function ListLegendItem
84
106
  })
85
107
  }),
86
108
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.ListItemText, {
87
- primary: item.label
109
+ primary: item.label,
110
+ primaryTypographyProps: {
111
+ noWrap: noWrap
112
+ },
113
+ onMouseOver: handleMouseOver,
114
+ onMouseOut: handleMouseOut
88
115
  })
89
116
  ]
90
117
  });
91
118
  });
119
+ const ListLegendItem = /*#__PURE__*/ _react.default.memo(ListLegendItemBase);
@@ -83,7 +83,10 @@ function _interopRequireWildcard(obj, nodeInterop) {
83
83
  _components.LegendComponent,
84
84
  _renderers.CanvasRenderer
85
85
  ]);
86
- function LineChart({ height , data , yAxis , unit , grid , legend , onDataZoom , onDoubleClick }) {
86
+ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfig ={
87
+ wrapLabels: true
88
+ } , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
89
+ var ref;
87
90
  const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
88
91
  const chartRef = (0, _react.useRef)();
89
92
  const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
@@ -177,6 +180,9 @@ function LineChart({ height , data , yAxis , unit , grid , legend , onDataZoom ,
177
180
  grid,
178
181
  legend
179
182
  };
183
+ if (__experimentalEChartsOptionsOverride) {
184
+ return __experimentalEChartsOptionsOverride(option);
185
+ }
180
186
  return option;
181
187
  }, [
182
188
  data,
@@ -185,7 +191,8 @@ function LineChart({ height , data , yAxis , unit , grid , legend , onDataZoom ,
185
191
  grid,
186
192
  legend,
187
193
  noDataOption,
188
- timeZone
194
+ timeZone,
195
+ __experimentalEChartsOptionsOverride
189
196
  ]);
190
197
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
191
198
  sx: {
@@ -215,10 +222,10 @@ function LineChart({ height , data , yAxis , unit , grid , legend , onDataZoom ,
215
222
  },
216
223
  onDoubleClick: handleOnDoubleClick,
217
224
  children: [
218
- showTooltip === true && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeSeriesTooltip.TimeSeriesTooltip, {
225
+ showTooltip === true && ((ref = option.tooltip) === null || ref === void 0 ? void 0 : ref.showContent) === false && tooltipConfig.hidden !== true && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeSeriesTooltip.TimeSeriesTooltip, {
219
226
  chartRef: chartRef,
220
227
  chartData: data,
221
- wrapLabels: true,
228
+ wrapLabels: tooltipConfig.wrapLabels,
222
229
  pinTooltip: pinTooltip,
223
230
  unit: unit
224
231
  }),
@@ -21,13 +21,15 @@ Object.defineProperty(exports, "OptionsEditorControl", {
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
23
  const _react = /*#__PURE__*/ _interopRequireDefault(require("react"));
24
+ const _informationOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/InformationOutline"));
24
25
  const _utils = require("../utils");
26
+ const _infoTooltip = require("../InfoTooltip");
25
27
  function _interopRequireDefault(obj) {
26
28
  return obj && obj.__esModule ? obj : {
27
29
  default: obj
28
30
  };
29
31
  }
30
- const OptionsEditorControl = ({ label , control })=>{
32
+ const OptionsEditorControl = ({ label , control , description })=>{
31
33
  // Make sure we have a unique ID we can use for associating labels and
32
34
  // controls for a11y.
33
35
  const generatedControlId = (0, _utils.useId)('EditorSectionControl');
@@ -41,9 +43,36 @@ const OptionsEditorControl = ({ label , control })=>{
41
43
  alignItems: "center",
42
44
  justifyContent: "space-between",
43
45
  children: [
44
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormLabel, {
45
- htmlFor: controlId,
46
- children: label
46
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
47
+ direction: "row",
48
+ alignItems: "center",
49
+ justifyContent: "center",
50
+ children: [
51
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormLabel, {
52
+ htmlFor: controlId,
53
+ children: label
54
+ }),
55
+ description && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_infoTooltip.InfoTooltip, {
56
+ description: description,
57
+ enterDelay: 100,
58
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
59
+ size: "small",
60
+ sx: (theme)=>({
61
+ borderRadius: theme.shape.borderRadius,
62
+ padding: '4x',
63
+ margin: '0 2px'
64
+ }),
65
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_informationOutline.default, {
66
+ "aria-describedby": "info-tooltip",
67
+ "aria-hidden": false,
68
+ fontSize: "inherit",
69
+ sx: {
70
+ color: (theme)=>theme.palette.grey[700]
71
+ }
72
+ })
73
+ })
74
+ })
75
+ ]
47
76
  }),
48
77
  /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
49
78
  sx: {
@@ -40,7 +40,7 @@ const _echart = require("../EChart");
40
40
  const MIN_VALUE_SIZE = 12;
41
41
  const MAX_VALUE_SIZE = 36;
42
42
  function StatChart(props) {
43
- const { width , height , data , unit , sparkline } = props;
43
+ const { width , height , data , unit , color , sparkline } = props;
44
44
  const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
45
45
  const formattedValue = data.calculatedValue === undefined ? '' : (0, _units.formatValue)(data.calculatedValue, unit);
46
46
  const option = (0, _react.useMemo)(()=>{
@@ -109,7 +109,7 @@ function StatChart(props) {
109
109
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
110
110
  variant: "h3",
111
111
  sx: (theme)=>({
112
- color: theme.palette.text.primary,
112
+ color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
113
113
  fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
114
114
  padding: `${containerPadding} ${containerPadding} 0 ${containerPadding}`
115
115
  }),
@@ -28,7 +28,7 @@ function _interopRequireDefault(obj) {
28
28
  default: obj
29
29
  };
30
30
  }
31
- function ThresholdInput({ inputRef , label , color , value , onChange , onColorChange , onBlur , onDelete }) {
31
+ function ThresholdInput({ inputRef , label , color , value , mode , onChange , onColorChange , onBlur , onDelete }) {
32
32
  const [key, setKey] = (0, _react.useState)(0); // use key to cause input to lose focus when pressing enter
33
33
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
34
34
  flex: 1,
@@ -50,7 +50,7 @@ function ThresholdInput({ inputRef , label , color , value , onChange , onColorC
50
50
  id: label,
51
51
  inputRef: inputRef,
52
52
  type: "number",
53
- value: value === 0 ? undefined : value,
53
+ value: value === 0 ? '' : value,
54
54
  placeholder: "0",
55
55
  onChange: onChange,
56
56
  onBlur: onBlur,
@@ -59,6 +59,12 @@ function ThresholdInput({ inputRef , label , color , value , onChange , onColorC
59
59
  onBlur();
60
60
  setKey(key + 1);
61
61
  }
62
+ },
63
+ InputProps: {
64
+ endAdornment: mode === 'Percent' ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
65
+ paddingX: 1,
66
+ children: "%"
67
+ }) : undefined
62
68
  }
63
69
  }, key),
64
70
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
@@ -24,9 +24,9 @@ const _immer = /*#__PURE__*/ _interopRequireDefault(require("immer"));
24
24
  const _material = require("@mui/material");
25
25
  const _plus = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Plus"));
26
26
  const _system = require("@mui/system");
27
- const _infoTooltip = require("../InfoTooltip");
28
27
  const _chartsThemeProvider = require("../context/ChartsThemeProvider");
29
28
  const _optionsEditorLayout = require("../OptionsEditorLayout");
29
+ const _infoTooltip = require("../InfoTooltip");
30
30
  const _thresholdColorPicker = require("./ThresholdColorPicker");
31
31
  const _thresholdInput = require("./ThresholdInput");
32
32
  function _interopRequireDefault(obj) {
@@ -120,6 +120,10 @@ function ThresholdsEditor({ thresholds , onChange , hideDefault , disablePercent
120
120
  onChange((0, _immer.default)(thresholds, (draft)=>{
121
121
  draft.default_color = color;
122
122
  }));
123
+ } else {
124
+ onChange({
125
+ default_color: color
126
+ });
123
127
  }
124
128
  };
125
129
  // sort thresholds in ascending order every time an input blurs
@@ -156,6 +160,14 @@ function ThresholdsEditor({ thresholds , onChange , hideDefault , disablePercent
156
160
  }
157
161
  ]
158
162
  });
163
+ } else if (thresholds && thresholds.steps === undefined) {
164
+ onChange((0, _immer.default)(thresholds, (draft)=>{
165
+ draft.steps = [
166
+ {
167
+ value: DEFAULT_STEP
168
+ }
169
+ ];
170
+ }));
159
171
  } else {
160
172
  onChange((0, _immer.default)(thresholds, (draft)=>{
161
173
  const steps = draft.steps;
@@ -191,46 +203,55 @@ function ThresholdsEditor({ thresholds , onChange , hideDefault , disablePercent
191
203
  var ref1, _color, ref2;
192
204
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_optionsEditorLayout.OptionsEditorGroup, {
193
205
  title: "Thresholds",
194
- icon: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
195
- size: "small",
196
- "aria-label": "add threshold",
197
- onClick: addThresholdInput,
198
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_plus.default, {})
206
+ icon: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_infoTooltip.InfoTooltip, {
207
+ description: 'Add threshold',
208
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
209
+ size: "small",
210
+ "aria-label": "add threshold",
211
+ onClick: addThresholdInput,
212
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_plus.default, {})
213
+ })
199
214
  }),
200
215
  children: [
201
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.ToggleButtonGroup, {
202
- exclusive: true,
203
- disabled: disablePercentMode,
204
- value: (ref1 = thresholds === null || thresholds === void 0 ? void 0 : thresholds.mode) !== null && ref1 !== void 0 ? ref1 : 'Absolute',
205
- onChange: handleModeChange,
206
- sx: {
207
- height: '36px',
208
- marginLeft: 'auto'
209
- },
210
- children: [
211
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.ToggleButton, {
212
- "aria-label": "absolute",
213
- value: "Absolute",
214
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_infoTooltip.InfoTooltip, {
215
- description: "Absolute",
216
- children: "#"
217
- })
218
- }),
219
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.ToggleButton, {
220
- "aria-label": "percent",
221
- value: "Percent",
222
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_infoTooltip.InfoTooltip, {
223
- description: "Percentage means thresholds relative to min & max",
224
- children: "%"
216
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
217
+ label: "Mode",
218
+ description: "Percentage means thresholds relative to min & max",
219
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.ToggleButtonGroup, {
220
+ exclusive: true,
221
+ disabled: disablePercentMode,
222
+ value: (ref1 = thresholds === null || thresholds === void 0 ? void 0 : thresholds.mode) !== null && ref1 !== void 0 ? ref1 : 'Absolute',
223
+ onChange: handleModeChange,
224
+ sx: {
225
+ height: '36px',
226
+ marginLeft: 'auto'
227
+ },
228
+ children: [
229
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.ToggleButton, {
230
+ "aria-label": "absolute",
231
+ value: "Absolute",
232
+ sx: {
233
+ fontWeight: 500
234
+ },
235
+ children: "Absolute"
236
+ }),
237
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.ToggleButton, {
238
+ "aria-label": "percent",
239
+ value: "Percent",
240
+ sx: {
241
+ fontWeight: 500
242
+ },
243
+ children: "Percent"
225
244
  })
226
- })
227
- ]
245
+ ]
246
+ })
228
247
  }),
229
- steps && steps.map((step, i)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_thresholdInput.ThresholdInput, {
248
+ steps && steps.map((step, i)=>{
249
+ /*#__PURE__*/ return (0, _jsxRuntime.jsx)(_thresholdInput.ThresholdInput, {
230
250
  inputRef: i === steps.length - 1 ? recentlyAddedInputRef : undefined,
231
251
  label: `T${i + 1}`,
232
252
  color: (ref2 = (_color = step.color) !== null && _color !== void 0 ? _color : palette[i]) !== null && ref2 !== void 0 ? ref2 : defaultThresholdColor,
233
253
  value: step.value,
254
+ mode: thresholds === null || thresholds === void 0 ? void 0 : thresholds.mode,
234
255
  onColorChange: (color)=>handleThresholdColorChange(color, i),
235
256
  onChange: (e)=>{
236
257
  handleThresholdValueChange(e, i);
@@ -239,7 +260,8 @@ function ThresholdsEditor({ thresholds , onChange , hideDefault , disablePercent
239
260
  deleteThreshold(i);
240
261
  },
241
262
  onBlur: handleThresholdBlur
242
- }, i)).reverse(),
263
+ }, i);
264
+ }).reverse(),
243
265
  !hideDefault && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_system.Stack, {
244
266
  flex: 1,
245
267
  direction: "row",
@@ -24,7 +24,7 @@ const _seriesMarker = require("./SeriesMarker");
24
24
  const _seriesLabelsStack = require("./SeriesLabelsStack");
25
25
  const _tooltipModel = require("./tooltip-model");
26
26
  function SeriesInfo(props) {
27
- const { seriesName , formattedY , markerColor , totalSeries , wrapLabels } = props;
27
+ const { seriesName , formattedY , markerColor , totalSeries , wrapLabels =true } = props;
28
28
  // metric __name__ comes before opening curly brace, ignore if not populated
29
29
  // ex with metric name: node_load15{env="demo",job="node"}
30
30
  // ex without metric name: {env="demo",job="node"}
@@ -44,8 +44,8 @@ function SeriesInfo(props) {
44
44
  markerColor: markerColor
45
45
  });
46
46
  }
47
- // add space after commas when more than one focused series
48
- const inlineSeriesLabels = formattedSeriesLabels.replace(/[,]/g, ', ');
47
+ // add space after commas so wrapLabels works
48
+ const formattedSeriesInfo = seriesName.replace(/[,]/g, ', ');
49
49
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
50
50
  sx: {
51
51
  display: 'table-row',
@@ -76,7 +76,7 @@ function SeriesInfo(props) {
76
76
  textOverflow: 'ellipsis',
77
77
  whiteSpace: wrapLabels ? 'normal' : 'nowrap'
78
78
  }),
79
- children: inlineSeriesLabels
79
+ children: formattedSeriesInfo
80
80
  })
81
81
  ]
82
82
  }),
@@ -46,10 +46,6 @@ const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
46
46
  });
47
47
  const defaultCursorData = {
48
48
  coords: {
49
- viewport: {
50
- x: 0,
51
- y: 0
52
- },
53
49
  plotCanvas: {
54
50
  x: 0,
55
51
  y: 0
@@ -71,9 +67,9 @@ const useMousePosition = ()=>{
71
67
  (0, _react.useEffect)(()=>{
72
68
  const setFromEvent = (e)=>{
73
69
  return setCoords({
74
- viewport: {
75
- x: e.clientX,
76
- y: e.clientY
70
+ page: {
71
+ x: e.pageX,
72
+ y: e.pageY
77
73
  },
78
74
  plotCanvas: {
79
75
  x: e.offsetX,
@@ -28,19 +28,22 @@ function assembleTransform(mousePos, seriesNum, chartWidth, chartHeight, pinnedP
28
28
  }
29
29
  const cursorPaddingX = 32;
30
30
  const cursorPaddingY = 16;
31
- const x = mousePos.viewport.x;
32
- let y = mousePos.viewport.y + cursorPaddingY;
33
- const isCloseToBottom = mousePos.viewport.y > window.innerHeight * 0.8;
31
+ // Tooltip is located in a Portal attached to the body.
32
+ // Using page coordinates instead of viewport ensures the tooltip is
33
+ // absolutely positioned correctly as the user scrolls
34
+ const x = mousePos.page.x;
35
+ let y = mousePos.page.y + cursorPaddingY;
36
+ const isCloseToBottom = mousePos.page.y > window.innerHeight * 0.8;
34
37
  const yPosAdjustThreshold = chartHeight * 0.75;
35
38
  // adjust so tooltip does not get cut off at bottom of chart, reduce multiplier to move up
36
39
  if (isCloseToBottom === true) {
37
40
  if (seriesNum > 6) {
38
- y = mousePos.viewport.y * 0.65;
41
+ y = mousePos.page.y * 0.75;
39
42
  } else {
40
- y = mousePos.viewport.y * 0.75;
43
+ y = mousePos.page.y * 0.9;
41
44
  }
42
45
  } else if (mousePos.plotCanvas.y > yPosAdjustThreshold) {
43
- y = mousePos.viewport.y * 0.85;
46
+ y = mousePos.page.y * 0.95;
44
47
  }
45
48
  // use tooltip width to determine when to repos from right to left (width is narrower when only 1 focused series since labels wrap)
46
49
  const tooltipWidth = seriesNum > 1 ? _tooltipModel.TOOLTIP_MAX_WIDTH : _tooltipModel.TOOLTIP_MAX_WIDTH / 2;
@@ -25,7 +25,13 @@ _export(exports, {
25
25
  BYTES_UNIT_CONFIG: ()=>BYTES_UNIT_CONFIG,
26
26
  formatBytes: ()=>formatBytes
27
27
  });
28
+ const _numbro = /*#__PURE__*/ _interopRequireDefault(require("numbro"));
28
29
  const _constants = require("./constants");
30
+ function _interopRequireDefault(obj) {
31
+ return obj && obj.__esModule ? obj : {
32
+ default: obj
33
+ };
34
+ }
29
35
  const bytesUnitKinds = [
30
36
  'Bytes'
31
37
  ];
@@ -35,52 +41,40 @@ const BYTES_GROUP_CONFIG = {
35
41
  abbreviate: true
36
42
  };
37
43
  const BYTES_UNIT_CONFIG = {
44
+ // This uses units that are powers of 1000.
45
+ // In other words, 1KB = 1000 bytes.
38
46
  Bytes: {
39
47
  group: 'Bytes',
40
48
  label: 'Bytes'
41
49
  }
42
50
  };
43
- function formatBytes(bytes, unitOptions) {
51
+ function formatBytes(bytes, { abbreviate , decimal_places }) {
44
52
  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
+ decimal_places = decimal_places !== null && decimal_places !== void 0 ? decimal_places : _constants.DEFAULT_DECIMAL_PLACES;
54
+ // Avoids maximumFractionDigits value is out of range error. Possible values are 0 to 20.
53
55
  // 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;
56
+ if (decimal_places < 0) {
57
+ decimal_places = 0;
58
+ } else if (decimal_places > 20) {
59
+ decimal_places = 20;
58
60
  }
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`;
61
+ const showFullNumber = abbreviate == false || bytes < 1000;
62
+ if (showFullNumber) {
63
+ const formatter = new Intl.NumberFormat('en-US', {
64
+ style: 'unit',
65
+ unit: 'byte',
66
+ unitDisplay: 'long',
67
+ maximumFractionDigits: decimal_places,
68
+ useGrouping: true
69
+ });
70
+ return formatter.format(bytes);
68
71
  }
69
- const k = 1024;
70
- const sizes = [
71
- 'bytes',
72
- 'KB',
73
- 'MB',
74
- 'GB',
75
- 'TB',
76
- 'PB',
77
- 'EB',
78
- 'ZB',
79
- 'YB'
80
- ];
81
- // Math.max(0, ...) ensures that we don't return -1 as a value for the index.
82
- // Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.
83
- const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));
84
- const abbreviatedValue = bytes / Math.pow(k, i);
85
- return `${formatter.format(abbreviatedValue)} ${sizes[i]}`;
72
+ return (0, _numbro.default)(bytes).format({
73
+ output: 'byte',
74
+ base: 'decimal',
75
+ spaceSeparated: true,
76
+ mantissa: decimal_places,
77
+ trimMantissa: true,
78
+ optionalMantissa: true
79
+ });
86
80
  }