@perses-dev/components 0.23.1 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/dist/ColorPicker/ColorPicker.d.ts +12 -0
  2. package/dist/ColorPicker/ColorPicker.d.ts.map +1 -0
  3. package/dist/ColorPicker/ColorPicker.js +78 -0
  4. package/dist/ColorPicker/ColorPicker.js.map +1 -0
  5. package/dist/ColorPicker/index.d.ts +2 -0
  6. package/dist/ColorPicker/index.d.ts.map +1 -0
  7. package/dist/ColorPicker/index.js +15 -0
  8. package/dist/ColorPicker/index.js.map +1 -0
  9. package/dist/Dialog/Dialog.d.ts +2 -1
  10. package/dist/Dialog/Dialog.d.ts.map +1 -1
  11. package/dist/Dialog/Dialog.js +12 -1
  12. package/dist/Dialog/Dialog.js.map +1 -1
  13. package/dist/{EChart.d.ts → EChart/EChart.d.ts} +3 -3
  14. package/dist/EChart/EChart.d.ts.map +1 -0
  15. package/dist/EChart/EChart.js.map +1 -0
  16. package/dist/EChart/index.d.ts +2 -0
  17. package/dist/EChart/index.d.ts.map +1 -0
  18. package/dist/EChart/index.js +15 -0
  19. package/dist/EChart/index.js.map +1 -0
  20. package/dist/GaugeChart/GaugeChart.d.ts +1 -2
  21. package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
  22. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  23. package/dist/InfoTooltip/InfoTooltip.d.ts.map +1 -1
  24. package/dist/InfoTooltip/InfoTooltip.js +7 -3
  25. package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
  26. package/dist/Legend/Legend.d.ts +1 -2
  27. package/dist/Legend/Legend.d.ts.map +1 -1
  28. package/dist/Legend/Legend.js +6 -9
  29. package/dist/Legend/Legend.js.map +1 -1
  30. package/dist/LineChart/LineChart.d.ts +4 -2
  31. package/dist/LineChart/LineChart.d.ts.map +1 -1
  32. package/dist/LineChart/LineChart.js +1 -1
  33. package/dist/LineChart/LineChart.js.map +1 -1
  34. package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  35. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  36. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts +3 -2
  37. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts.map +1 -1
  38. package/dist/OptionsEditorLayout/OptionsEditorGroup.js +17 -5
  39. package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
  40. package/dist/StatChart/StatChart.d.ts +1 -3
  41. package/dist/StatChart/StatChart.d.ts.map +1 -1
  42. package/dist/StatChart/StatChart.js +1 -3
  43. package/dist/StatChart/StatChart.js.map +1 -1
  44. package/dist/ThresholdsEditor/ThresholdColorPicker.d.ts +4 -0
  45. package/dist/ThresholdsEditor/ThresholdColorPicker.d.ts.map +1 -0
  46. package/dist/ThresholdsEditor/ThresholdColorPicker.js +76 -0
  47. package/dist/ThresholdsEditor/ThresholdColorPicker.js.map +1 -0
  48. package/dist/ThresholdsEditor/ThresholdInput.d.ts +13 -0
  49. package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -0
  50. package/dist/ThresholdsEditor/ThresholdInput.js +61 -0
  51. package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -0
  52. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts +10 -0
  53. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -0
  54. package/dist/ThresholdsEditor/ThresholdsEditor.js +215 -0
  55. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -0
  56. package/dist/ThresholdsEditor/index.d.ts +2 -0
  57. package/dist/ThresholdsEditor/index.d.ts.map +1 -0
  58. package/dist/ThresholdsEditor/index.js +15 -0
  59. package/dist/ThresholdsEditor/index.js.map +1 -0
  60. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +1 -1
  61. package/dist/TimeSeriesTooltip/focused-series.js +3 -3
  62. package/dist/TimeSeriesTooltip/focused-series.js.map +1 -1
  63. package/dist/cjs/ColorPicker/ColorPicker.js +128 -0
  64. package/dist/cjs/{model/legend.test.js → ColorPicker/index.js} +11 -12
  65. package/dist/cjs/Dialog/Dialog.js +11 -0
  66. package/dist/{model/legend.test.js → cjs/EChart/index.js} +15 -14
  67. package/dist/cjs/InfoTooltip/InfoTooltip.js +7 -3
  68. package/dist/cjs/Legend/Legend.js +5 -8
  69. package/dist/cjs/LineChart/LineChart.js +40 -1
  70. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  71. package/dist/cjs/OptionsEditorLayout/OptionsEditorGroup.js +22 -5
  72. package/dist/cjs/StatChart/StatChart.js +1 -41
  73. package/dist/cjs/ThresholdsEditor/ThresholdColorPicker.js +87 -0
  74. package/dist/cjs/ThresholdsEditor/ThresholdInput.js +72 -0
  75. package/dist/cjs/ThresholdsEditor/ThresholdsEditor.js +265 -0
  76. package/dist/cjs/ThresholdsEditor/index.js +28 -0
  77. package/dist/cjs/TimeSeriesTooltip/focused-series.js +3 -3
  78. package/dist/cjs/index.js +2 -0
  79. package/dist/cjs/test-utils/theme.js +8 -0
  80. package/dist/cjs/theme/component-overrides/alert.js +102 -0
  81. package/dist/cjs/theme/theme.js +4 -8
  82. package/dist/cjs/utils/theme-gen.js +8 -0
  83. package/dist/index.d.ts +2 -0
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +2 -0
  86. package/dist/index.js.map +1 -1
  87. package/dist/model/graph.d.ts +2 -2
  88. package/dist/model/graph.d.ts.map +1 -1
  89. package/dist/model/graph.js.map +1 -1
  90. package/dist/model/legend.d.ts +1 -1
  91. package/dist/model/legend.d.ts.map +1 -1
  92. package/dist/model/legend.js.map +1 -1
  93. package/dist/model/theme.d.ts +5 -0
  94. package/dist/model/theme.d.ts.map +1 -1
  95. package/dist/model/theme.js.map +1 -1
  96. package/dist/model/units/bytes.d.ts +1 -1
  97. package/dist/model/units/bytes.d.ts.map +1 -1
  98. package/dist/model/units/bytes.js.map +1 -1
  99. package/dist/model/units/decimal.d.ts +1 -1
  100. package/dist/model/units/decimal.d.ts.map +1 -1
  101. package/dist/model/units/decimal.js.map +1 -1
  102. package/dist/model/units/percent.d.ts +1 -1
  103. package/dist/model/units/percent.d.ts.map +1 -1
  104. package/dist/model/units/percent.js.map +1 -1
  105. package/dist/model/units/time.d.ts +1 -1
  106. package/dist/model/units/time.d.ts.map +1 -1
  107. package/dist/model/units/time.js.map +1 -1
  108. package/dist/model/units/types.d.ts +1 -1
  109. package/dist/model/units/types.d.ts.map +1 -1
  110. package/dist/model/units/types.js.map +1 -1
  111. package/dist/test-utils/theme.d.ts.map +1 -1
  112. package/dist/test-utils/theme.js +8 -0
  113. package/dist/test-utils/theme.js.map +1 -1
  114. package/dist/theme/component-overrides/alert.d.ts +3 -0
  115. package/dist/theme/component-overrides/alert.d.ts.map +1 -0
  116. package/dist/theme/component-overrides/alert.js +96 -0
  117. package/dist/theme/component-overrides/alert.js.map +1 -0
  118. package/dist/theme/theme.d.ts.map +1 -1
  119. package/dist/theme/theme.js +5 -9
  120. package/dist/theme/theme.js.map +1 -1
  121. package/dist/utils/theme-gen.d.ts.map +1 -1
  122. package/dist/utils/theme-gen.js +8 -0
  123. package/dist/utils/theme-gen.js.map +1 -1
  124. package/package.json +8 -3
  125. package/dist/EChart.d.ts.map +0 -1
  126. package/dist/EChart.js.map +0 -1
  127. package/dist/InfoTooltip/InfoTooltip.test.d.ts +0 -2
  128. package/dist/InfoTooltip/InfoTooltip.test.d.ts.map +0 -1
  129. package/dist/InfoTooltip/InfoTooltip.test.js +0 -36
  130. package/dist/InfoTooltip/InfoTooltip.test.js.map +0 -1
  131. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts +0 -2
  132. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts.map +0 -1
  133. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js +0 -62
  134. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js.map +0 -1
  135. package/dist/StatChart/StatChart.test.d.ts +0 -2
  136. package/dist/StatChart/StatChart.test.d.ts.map +0 -1
  137. package/dist/StatChart/StatChart.test.js +0 -94
  138. package/dist/StatChart/StatChart.test.js.map +0 -1
  139. package/dist/TimeSeriesTooltip/SeriesInfo.test.d.ts +0 -2
  140. package/dist/TimeSeriesTooltip/SeriesInfo.test.d.ts.map +0 -1
  141. package/dist/TimeSeriesTooltip/SeriesInfo.test.js +0 -52
  142. package/dist/TimeSeriesTooltip/SeriesInfo.test.js.map +0 -1
  143. package/dist/TimeSeriesTooltip/TooltipContent.test.d.ts +0 -2
  144. package/dist/TimeSeriesTooltip/TooltipContent.test.d.ts.map +0 -1
  145. package/dist/TimeSeriesTooltip/TooltipContent.test.js +0 -78
  146. package/dist/TimeSeriesTooltip/TooltipContent.test.js.map +0 -1
  147. package/dist/TimeSeriesTooltip/focused-series.test.d.ts +0 -2
  148. package/dist/TimeSeriesTooltip/focused-series.test.d.ts.map +0 -1
  149. package/dist/TimeSeriesTooltip/focused-series.test.js +0 -93
  150. package/dist/TimeSeriesTooltip/focused-series.test.js.map +0 -1
  151. package/dist/UnitSelector/UnitSelector.test.d.ts +0 -2
  152. package/dist/UnitSelector/UnitSelector.test.d.ts.map +0 -1
  153. package/dist/UnitSelector/UnitSelector.test.js +0 -204
  154. package/dist/UnitSelector/UnitSelector.test.js.map +0 -1
  155. package/dist/cjs/InfoTooltip/InfoTooltip.test.js +0 -43
  156. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.test.js +0 -69
  157. package/dist/cjs/StatChart/StatChart.test.js +0 -96
  158. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.test.js +0 -54
  159. package/dist/cjs/TimeSeriesTooltip/TooltipContent.test.js +0 -80
  160. package/dist/cjs/TimeSeriesTooltip/focused-series.test.js +0 -95
  161. package/dist/cjs/UnitSelector/UnitSelector.test.js +0 -211
  162. package/dist/cjs/model/units/units.test.js +0 -206
  163. package/dist/cjs/utils/format.test.js +0 -47
  164. package/dist/cjs/utils/theme-gen.test.js +0 -202
  165. package/dist/model/legend.test.d.ts +0 -2
  166. package/dist/model/legend.test.d.ts.map +0 -1
  167. package/dist/model/legend.test.js.map +0 -1
  168. package/dist/model/units/units.test.d.ts +0 -2
  169. package/dist/model/units/units.test.d.ts.map +0 -1
  170. package/dist/model/units/units.test.js +0 -204
  171. package/dist/model/units/units.test.js.map +0 -1
  172. package/dist/utils/format.test.d.ts +0 -2
  173. package/dist/utils/format.test.d.ts.map +0 -1
  174. package/dist/utils/format.test.js +0 -45
  175. package/dist/utils/format.test.js.map +0 -1
  176. package/dist/utils/theme-gen.test.d.ts +0 -2
  177. package/dist/utils/theme-gen.test.d.ts.map +0 -1
  178. package/dist/utils/theme-gen.test.js +0 -200
  179. package/dist/utils/theme-gen.test.js.map +0 -1
  180. /package/dist/{EChart.js → EChart/EChart.js} +0 -0
  181. /package/dist/cjs/{EChart.js → EChart/EChart.js} +0 -0
@@ -0,0 +1,215 @@
1
+ // Copyright 2023 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
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import React, { useEffect, useRef, useState } from 'react';
15
+ import produce from 'immer';
16
+ import { IconButton, ToggleButton, ToggleButtonGroup, Typography } from '@mui/material';
17
+ import PlusIcon from 'mdi-material-ui/Plus';
18
+ import { Stack } from '@mui/system';
19
+ import { InfoTooltip } from '../InfoTooltip';
20
+ import { useChartsTheme } from '../context/ChartsThemeProvider';
21
+ import { OptionsEditorGroup } from '../OptionsEditorLayout';
22
+ import { ThresholdColorPicker } from './ThresholdColorPicker';
23
+ import { ThresholdInput } from './ThresholdInput';
24
+ const DEFAULT_STEP = 10;
25
+ export function ThresholdsEditor({ thresholds , onChange , hideDefault , disablePercentMode }) {
26
+ const { thresholds: { defaultColor , palette } , } = useChartsTheme();
27
+ var ref;
28
+ const defaultThresholdColor = (ref = thresholds === null || thresholds === void 0 ? void 0 : thresholds.default_color) !== null && ref !== void 0 ? ref : defaultColor;
29
+ const [steps, setSteps] = useState(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps);
30
+ useEffect(()=>{
31
+ setSteps(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps);
32
+ }, [
33
+ thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps
34
+ ]);
35
+ // every time a new threshold is added, we want to focus the recently added input
36
+ const recentlyAddedInputRef = useRef(null);
37
+ const focusRef = useRef(false);
38
+ useEffect(()=>{
39
+ var ref;
40
+ if (!recentlyAddedInputRef.current || !focusRef.current) return;
41
+ (ref = recentlyAddedInputRef.current) === null || ref === void 0 ? void 0 : ref.focus();
42
+ focusRef.current = false;
43
+ }, [
44
+ steps === null || steps === void 0 ? void 0 : steps.length
45
+ ]);
46
+ const handleThresholdValueChange = (e, i)=>{
47
+ setSteps(produce(steps, (draft)=>{
48
+ const step = draft === null || draft === void 0 ? void 0 : draft[i];
49
+ if (step) {
50
+ step.value = Number(e.target.value);
51
+ }
52
+ }));
53
+ };
54
+ const handleThresholdColorChange = (color, i)=>{
55
+ if (thresholds !== undefined) {
56
+ onChange(produce(thresholds, (draft)=>{
57
+ if (draft.steps !== undefined) {
58
+ const step = draft.steps[i];
59
+ if (step) {
60
+ step.color = color;
61
+ }
62
+ }
63
+ }));
64
+ }
65
+ };
66
+ const handleDefaultColorChange = (color)=>{
67
+ if (thresholds !== undefined) {
68
+ onChange(produce(thresholds, (draft)=>{
69
+ draft.default_color = color;
70
+ }));
71
+ }
72
+ };
73
+ // sort thresholds in ascending order every time an input blurs
74
+ const handleThresholdBlur = ()=>{
75
+ if (steps !== undefined) {
76
+ const sortedSteps = [
77
+ ...steps
78
+ ];
79
+ sortedSteps.sort((a, b)=>a.value - b.value);
80
+ if (thresholds !== undefined) {
81
+ onChange(produce(thresholds, (draft)=>{
82
+ draft.steps = sortedSteps;
83
+ }));
84
+ }
85
+ }
86
+ };
87
+ const deleteThreshold = (i)=>{
88
+ if (thresholds !== undefined) {
89
+ const updatedThresholds = produce(thresholds, (draft)=>{
90
+ if (draft.steps) {
91
+ draft.steps.splice(i, 1);
92
+ }
93
+ });
94
+ onChange(updatedThresholds);
95
+ }
96
+ };
97
+ const addThresholdInput = ()=>{
98
+ focusRef.current = true;
99
+ if (thresholds === undefined) {
100
+ onChange({
101
+ steps: [
102
+ {
103
+ value: DEFAULT_STEP
104
+ }
105
+ ]
106
+ });
107
+ } else {
108
+ onChange(produce(thresholds, (draft)=>{
109
+ const steps = draft.steps;
110
+ if (steps === null || steps === void 0 ? void 0 : steps.length) {
111
+ const lastStep = steps[steps.length - 1];
112
+ var _length;
113
+ const color = (_length = palette[steps.length]) !== null && _length !== void 0 ? _length : getRandomColor(); // we will assign color from the palette first, then generate random color
114
+ var ref;
115
+ steps.push({
116
+ color,
117
+ value: ((ref = lastStep === null || lastStep === void 0 ? void 0 : lastStep.value) !== null && ref !== void 0 ? ref : 0) + DEFAULT_STEP
118
+ }); // set new threshold value to last step value + 10
119
+ } else if (steps) {
120
+ steps.push({
121
+ value: DEFAULT_STEP
122
+ });
123
+ }
124
+ }));
125
+ }
126
+ };
127
+ const handleModeChange = (event, value)=>{
128
+ const mode = value === 'Percent' ? 'Percent' : undefined;
129
+ if (thresholds !== undefined) {
130
+ onChange(produce(thresholds, (draft)=>{
131
+ draft.mode = mode;
132
+ }));
133
+ } else {
134
+ onChange({
135
+ mode
136
+ });
137
+ }
138
+ };
139
+ var ref1, _color, ref2;
140
+ return /*#__PURE__*/ _jsxs(OptionsEditorGroup, {
141
+ title: "Thresholds",
142
+ icon: /*#__PURE__*/ _jsx(IconButton, {
143
+ size: "small",
144
+ "aria-label": "add threshold",
145
+ onClick: addThresholdInput,
146
+ children: /*#__PURE__*/ _jsx(PlusIcon, {})
147
+ }),
148
+ children: [
149
+ /*#__PURE__*/ _jsxs(ToggleButtonGroup, {
150
+ exclusive: true,
151
+ disabled: disablePercentMode,
152
+ value: (ref1 = thresholds === null || thresholds === void 0 ? void 0 : thresholds.mode) !== null && ref1 !== void 0 ? ref1 : 'Absolute',
153
+ onChange: handleModeChange,
154
+ sx: {
155
+ height: '36px',
156
+ marginLeft: 'auto'
157
+ },
158
+ children: [
159
+ /*#__PURE__*/ _jsx(ToggleButton, {
160
+ "aria-label": "absolute",
161
+ value: "Absolute",
162
+ children: /*#__PURE__*/ _jsx(InfoTooltip, {
163
+ description: "Absolute",
164
+ children: "#"
165
+ })
166
+ }),
167
+ /*#__PURE__*/ _jsx(ToggleButton, {
168
+ "aria-label": "percent",
169
+ value: "Percent",
170
+ children: /*#__PURE__*/ _jsx(InfoTooltip, {
171
+ description: "Percentage means thresholds relative to min & max",
172
+ children: "%"
173
+ })
174
+ })
175
+ ]
176
+ }),
177
+ steps && steps.map((step, i)=>/*#__PURE__*/ _jsx(ThresholdInput, {
178
+ inputRef: i === steps.length - 1 ? recentlyAddedInputRef : undefined,
179
+ label: `T${i + 1}`,
180
+ color: (ref2 = (_color = step.color) !== null && _color !== void 0 ? _color : palette[i]) !== null && ref2 !== void 0 ? ref2 : defaultThresholdColor,
181
+ value: step.value,
182
+ onColorChange: (color)=>handleThresholdColorChange(color, i),
183
+ onChange: (e)=>{
184
+ handleThresholdValueChange(e, i);
185
+ },
186
+ onDelete: ()=>{
187
+ deleteThreshold(i);
188
+ },
189
+ onBlur: handleThresholdBlur
190
+ }, i)).reverse(),
191
+ !hideDefault && /*#__PURE__*/ _jsxs(Stack, {
192
+ flex: 1,
193
+ direction: "row",
194
+ alignItems: "center",
195
+ spacing: 1,
196
+ children: [
197
+ /*#__PURE__*/ _jsx(ThresholdColorPicker, {
198
+ label: "default",
199
+ color: defaultThresholdColor,
200
+ onColorChange: handleDefaultColorChange
201
+ }),
202
+ /*#__PURE__*/ _jsx(Typography, {
203
+ children: "Default"
204
+ })
205
+ ]
206
+ })
207
+ ]
208
+ });
209
+ }
210
+ // https://www.paulirish.com/2009/random-hex-color-code-snippets/
211
+ const getRandomColor = ()=>{
212
+ return '#' + Math.floor(Math.random() * 16777216).toString(16).padStart(6, '0');
213
+ };
214
+
215
+ //# sourceMappingURL=ThresholdsEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ThresholdsEditor/ThresholdsEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { useEffect, useRef, useState } from 'react';\nimport produce from 'immer';\nimport { IconButton, ToggleButton, ToggleButtonGroup, Typography } from '@mui/material';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport { Stack } from '@mui/system';\nimport { ThresholdOptions } from '@perses-dev/core';\nimport { InfoTooltip } from '../InfoTooltip';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { OptionsEditorGroup } from '../OptionsEditorLayout';\nimport { ThresholdColorPicker } from './ThresholdColorPicker';\nimport { ThresholdInput } from './ThresholdInput';\n\nexport interface ThresholdsEditorProps {\n onChange: (thresholds: ThresholdOptions) => void;\n thresholds?: ThresholdOptions;\n hideDefault?: boolean;\n disablePercentMode?: boolean;\n}\n\nconst DEFAULT_STEP = 10;\n\nexport function ThresholdsEditor({ thresholds, onChange, hideDefault, disablePercentMode }: ThresholdsEditorProps) {\n const {\n thresholds: { defaultColor, palette },\n } = useChartsTheme();\n const defaultThresholdColor = thresholds?.default_color ?? defaultColor;\n\n const [steps, setSteps] = useState(thresholds?.steps);\n useEffect(() => {\n setSteps(thresholds?.steps);\n }, [thresholds?.steps]);\n\n // every time a new threshold is added, we want to focus the recently added input\n const recentlyAddedInputRef = useRef<HTMLInputElement | null>(null);\n const focusRef = useRef(false);\n useEffect(() => {\n if (!recentlyAddedInputRef.current || !focusRef.current) return;\n recentlyAddedInputRef.current?.focus();\n focusRef.current = false;\n }, [steps?.length]);\n\n const handleThresholdValueChange = (e: React.ChangeEvent<HTMLInputElement>, i: number) => {\n setSteps(\n produce(steps, (draft) => {\n const step = draft?.[i];\n if (step) {\n step.value = Number(e.target.value);\n }\n })\n );\n };\n\n const handleThresholdColorChange = (color: string, i: number) => {\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n if (draft.steps !== undefined) {\n const step = draft.steps[i];\n if (step) {\n step.color = color;\n }\n }\n })\n );\n }\n };\n\n const handleDefaultColorChange = (color: string) => {\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n draft.default_color = color;\n })\n );\n }\n };\n\n // sort thresholds in ascending order every time an input blurs\n const handleThresholdBlur = () => {\n if (steps !== undefined) {\n const sortedSteps = [...steps];\n sortedSteps.sort((a, b) => a.value - b.value);\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n draft.steps = sortedSteps;\n })\n );\n }\n }\n };\n\n const deleteThreshold = (i: number): void => {\n if (thresholds !== undefined) {\n const updatedThresholds = produce(thresholds, (draft) => {\n if (draft.steps) {\n draft.steps.splice(i, 1);\n }\n });\n onChange(updatedThresholds);\n }\n };\n\n const addThresholdInput = (): void => {\n focusRef.current = true;\n if (thresholds === undefined) {\n onChange({\n steps: [{ value: DEFAULT_STEP }],\n });\n } else {\n onChange(\n produce(thresholds, (draft) => {\n const steps = draft.steps;\n if (steps?.length) {\n const lastStep = steps[steps.length - 1];\n const color = palette[steps.length] ?? getRandomColor(); // we will assign color from the palette first, then generate random color\n steps.push({ color, value: (lastStep?.value ?? 0) + DEFAULT_STEP }); // set new threshold value to last step value + 10\n } else if (steps) {\n steps.push({ value: DEFAULT_STEP });\n }\n })\n );\n }\n };\n\n const handleModeChange = (event: React.MouseEvent, value: string): void => {\n const mode = value === 'Percent' ? 'Percent' : undefined;\n if (thresholds !== undefined) {\n onChange(\n produce(thresholds, (draft) => {\n draft.mode = mode;\n })\n );\n } else {\n onChange({ mode });\n }\n };\n\n return (\n <OptionsEditorGroup\n title=\"Thresholds\"\n icon={\n <IconButton size=\"small\" aria-label=\"add threshold\" onClick={addThresholdInput}>\n <PlusIcon />\n </IconButton>\n }\n >\n <ToggleButtonGroup\n exclusive\n disabled={disablePercentMode}\n value={thresholds?.mode ?? 'Absolute'}\n onChange={handleModeChange}\n sx={{ height: '36px', marginLeft: 'auto' }}\n >\n <ToggleButton aria-label=\"absolute\" value=\"Absolute\">\n <InfoTooltip description=\"Absolute\">#</InfoTooltip>\n </ToggleButton>\n <ToggleButton aria-label=\"percent\" value=\"Percent\">\n <InfoTooltip description=\"Percentage means thresholds relative to min & max\">%</InfoTooltip>\n </ToggleButton>\n </ToggleButtonGroup>\n {steps &&\n steps\n .map((step, i) => (\n <ThresholdInput\n inputRef={i === steps.length - 1 ? recentlyAddedInputRef : undefined}\n key={i}\n label={`T${i + 1}`}\n color={step.color ?? palette[i] ?? defaultThresholdColor}\n value={step.value}\n onColorChange={(color) => handleThresholdColorChange(color, i)}\n onChange={(e) => {\n handleThresholdValueChange(e, i);\n }}\n onDelete={() => {\n deleteThreshold(i);\n }}\n onBlur={handleThresholdBlur}\n />\n ))\n .reverse()}\n {!hideDefault && (\n <Stack flex={1} direction=\"row\" alignItems=\"center\" spacing={1}>\n <ThresholdColorPicker\n label=\"default\"\n color={defaultThresholdColor}\n onColorChange={handleDefaultColorChange}\n />\n <Typography>Default</Typography>\n </Stack>\n )}\n </OptionsEditorGroup>\n );\n}\n\n// https://www.paulirish.com/2009/random-hex-color-code-snippets/\nconst getRandomColor = () => {\n return (\n '#' +\n Math.floor(Math.random() * 16777216)\n .toString(16)\n .padStart(6, '0')\n );\n};\n"],"names":["React","useEffect","useRef","useState","produce","IconButton","ToggleButton","ToggleButtonGroup","Typography","PlusIcon","Stack","InfoTooltip","useChartsTheme","OptionsEditorGroup","ThresholdColorPicker","ThresholdInput","DEFAULT_STEP","ThresholdsEditor","thresholds","onChange","hideDefault","disablePercentMode","defaultColor","palette","defaultThresholdColor","default_color","steps","setSteps","recentlyAddedInputRef","focusRef","current","focus","length","handleThresholdValueChange","e","i","draft","step","value","Number","target","handleThresholdColorChange","color","undefined","handleDefaultColorChange","handleThresholdBlur","sortedSteps","sort","a","b","deleteThreshold","updatedThresholds","splice","addThresholdInput","lastStep","getRandomColor","push","handleModeChange","event","mode","title","icon","size","aria-label","onClick","exclusive","disabled","sx","height","marginLeft","description","map","inputRef","label","onColorChange","onDelete","onBlur","reverse","flex","direction","alignItems","spacing","Math","floor","random","toString","padStart"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAC3D,OAAOC,OAAO,MAAM,OAAO,CAAC;AAC5B,SAASC,UAAU,EAAEC,YAAY,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACxF,OAAOC,QAAQ,MAAM,sBAAsB,CAAC;AAC5C,SAASC,KAAK,QAAQ,aAAa,CAAC;AAEpC,SAASC,WAAW,QAAQ,gBAAgB,CAAC;AAC7C,SAASC,cAAc,QAAQ,gCAAgC,CAAC;AAChE,SAASC,kBAAkB,QAAQ,wBAAwB,CAAC;AAC5D,SAASC,oBAAoB,QAAQ,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CAAC,EAAE,GAAG,CAAC,CACnB;AACJ,CAAC,AAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './ThresholdsEditor';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ThresholdsEditor/index.ts"],"names":[],"mappings":"AAaA,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 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
+ export * from './ThresholdsEditor';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ThresholdsEditor/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './ThresholdsEditor';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,oBAAoB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"focused-series.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/focused-series.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAe,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,UAAU,EAA0C,MAAM,iBAAiB,CAAC;AAErF,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,oBAAY,kBAAkB,GAAG,iBAAiB,EAAE,CAAC;AAErD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,iBAAiB,EACvB,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,WAAW,GACjB,kBAAkB,CA4CpB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,SAAS,EAAE,iBAAiB,EAC5B,SAAS,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC/B,KAAK,CAAC,EAAE,eAAe,EACvB,IAAI,CAAC,EAAE,WAAW,sBA2CnB"}
1
+ {"version":3,"file":"focused-series.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/focused-series.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAe,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,UAAU,EAA0C,MAAM,iBAAiB,CAAC;AAErF,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,oBAAY,kBAAkB,GAAG,iBAAiB,EAAE,CAAC;AAErD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,iBAAiB,EACvB,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,WAAW,GACjB,kBAAkB,CA6CpB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,SAAS,EAAE,iBAAiB,EAC5B,SAAS,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC/B,KAAK,CAAC,EAAE,eAAe,EACvB,IAAI,CAAC,EAAE,WAAW,sBA2CnB"}
@@ -36,9 +36,9 @@ import { TOOLTIP_DATE_FORMAT, TOOLTIP_MAX_ITEMS } from './tooltip-model';
36
36
  for(let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++){
37
37
  var _datumIdx;
38
38
  const xValue = (_datumIdx = data.xAxis[datumIdx]) !== null && _datumIdx !== void 0 ? _datumIdx : 0;
39
- var _datumIdx1;
40
- const yValue = (_datumIdx1 = currentSeries.data[datumIdx]) !== null && _datumIdx1 !== void 0 ? _datumIdx1 : 0;
41
- if (focusedX === datumIdx) {
39
+ const yValue = currentSeries.data[datumIdx];
40
+ // ensure null values not displayed in tooltip
41
+ if (yValue !== undefined && yValue !== null && focusedX === datumIdx) {
42
42
  if (yValue !== '-' && focusedY <= yValue + yBuffer && focusedY >= yValue - yBuffer) {
43
43
  // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
44
44
  const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/TimeSeriesTooltip/focused-series.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ECharts as EChartsInstance } from 'echarts/core';\nimport { formatValue, UnitOptions, EChartsDataFormat } from '../model';\nimport { CursorData, TOOLTIP_DATE_FORMAT, TOOLTIP_MAX_ITEMS } from './tooltip-model';\n\nexport interface FocusedSeriesInfo {\n seriesIdx: number | null;\n datumIdx: number | null;\n seriesName: string;\n date: string;\n markerColor: string;\n x: number;\n y: number;\n formattedY: string;\n}\n\nexport type FocusedSeriesArray = FocusedSeriesInfo[];\n\n/**\n * Returns formatted series data for the points that are close to the user's cursor\n * Adjust yBuffer to increase or decrease number of series shown\n */\nexport function getNearbySeries(\n data: EChartsDataFormat,\n pointInGrid: number[],\n yBuffer: number,\n unit?: UnitOptions\n): FocusedSeriesArray {\n const currentFocusedData: FocusedSeriesArray = [];\n const focusedX: number | null = pointInGrid[0] ?? null;\n const focusedY: number | null = pointInGrid[1] ?? null;\n\n if (focusedX === null || focusedY === null) {\n return currentFocusedData;\n }\n\n if (Array.isArray(data.xAxis) && Array.isArray(data.timeSeries)) {\n for (let seriesIdx = 0; seriesIdx < data.timeSeries.length; seriesIdx++) {\n const currentSeries = data.timeSeries[seriesIdx];\n if (currentFocusedData.length >= TOOLTIP_MAX_ITEMS) break;\n if (currentSeries !== undefined) {\n const currentSeriesName = currentSeries.name ? currentSeries.name.toString() : '';\n const markerColor = currentSeries.color ?? '#000';\n if (Array.isArray(currentSeries.data)) {\n for (let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++) {\n const xValue = data.xAxis[datumIdx] ?? 0;\n const yValue = currentSeries.data[datumIdx] ?? 0;\n if (focusedX === datumIdx) {\n if (yValue !== '-' && focusedY <= yValue + yBuffer && focusedY >= yValue - yBuffer) {\n // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201\n const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;\n const formattedDate = TOOLTIP_DATE_FORMAT.format(xValueMilliSeconds);\n const formattedY = formatValue(yValue, unit);\n currentFocusedData.push({\n seriesIdx: seriesIdx,\n datumIdx: datumIdx,\n seriesName: currentSeriesName,\n date: formattedDate,\n x: xValue,\n y: yValue,\n formattedY: formattedY,\n markerColor: markerColor.toString(),\n });\n }\n }\n }\n }\n }\n }\n }\n return currentFocusedData;\n}\n\n/**\n * Uses mouse position to determine whether user is hovering over a chart canvas\n * If yes, convert from pixel values to logical cartesian coordinates and return all focused series\n */\nexport function getFocusedSeriesData(\n mousePos: CursorData['coords'],\n chartData: EChartsDataFormat,\n pinnedPos: CursorData['coords'],\n chart?: EChartsInstance,\n unit?: UnitOptions\n) {\n if (chart === undefined || mousePos === null) return [];\n\n // prevents multiple tooltips showing from adjacent charts\n let cursorTargetMatchesChart = false;\n if (mousePos.target !== null) {\n const currentParent = (<HTMLElement>mousePos.target).parentElement;\n if (currentParent !== null) {\n const currentGrandparent = currentParent.parentElement;\n if (currentGrandparent !== null) {\n const chartDom = chart.getDom();\n if (chartDom === currentGrandparent) {\n cursorTargetMatchesChart = true;\n }\n }\n }\n }\n\n // allows moving cursor inside tooltip\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n cursorTargetMatchesChart = true;\n }\n\n if (cursorTargetMatchesChart === false) return [];\n\n if (chart['_model'] === undefined) return [];\n const chartModel = chart['_model'];\n const yAxisInterval = chartModel.getComponent('yAxis').axis.scale._interval;\n\n // tooltip trigger area gets smaller with more series, increase yAxisInterval multiplier to expand nearby series range\n const seriesNum = chartData.timeSeries.length;\n const yBuffer = seriesNum > TOOLTIP_MAX_ITEMS ? yAxisInterval * 0.5 : yAxisInterval * 5;\n\n const pointInPixel = [mousePos.plotCanvas.x ?? 0, mousePos.plotCanvas.y ?? 0];\n if (chart.containPixel('grid', pointInPixel)) {\n const pointInGrid = chart.convertFromPixel('grid', pointInPixel);\n if (pointInGrid[0] !== undefined && pointInGrid[1] !== undefined) {\n return getNearbySeries(chartData, pointInGrid, yBuffer, unit);\n }\n }\n return [];\n}\n"],"names":["formatValue","TOOLTIP_DATE_FORMAT","TOOLTIP_MAX_ITEMS","getNearbySeries","data","pointInGrid","yBuffer","unit","currentFocusedData","focusedX","focusedY","Array","isArray","xAxis","timeSeries","seriesIdx","length","currentSeries","undefined","currentSeriesName","name","toString","markerColor","color","datumIdx","xValue","yValue","xValueMilliSeconds","formattedDate","format","formattedY","push","seriesName","date","x","y","getFocusedSeriesData","mousePos","chartData","pinnedPos","chart","cursorTargetMatchesChart","target","currentParent","parentElement","currentGrandparent","chartDom","getDom","chartModel","yAxisInterval","getComponent","axis","scale","_interval","seriesNum","pointInPixel","plotCanvas","containPixel","convertFromPixel"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,WAAW,QAAwC,UAAU,CAAC;AACvE,SAAqBC,mBAAmB,EAAEC,iBAAiB,QAAQ,iBAAiB,CAAC;AAerF;;;CAGC,GACD,OAAO,SAASC,eAAe,CAC7BC,IAAuB,EACvBC,WAAqB,EACrBC,OAAe,EACfC,IAAkB,EACE;IACpB,MAAMC,kBAAkB,GAAuB,EAAE,AAAC;QAClBH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,EAAqB,EAAOA,EAAqB;IAAvE,MAAMkB,YAAY,GAAG;QAAClB,CAAAA,EAAqB,GAArBA,QAAQ,CAACmB,UAAU,CAACtB,CAAC,cAArBG,EAAqB,cAArBA,EAAqB,GAAI,CAAC;QAAEA,CAAAA,EAAqB,GAArBA,QAAQ,CAACmB,UAAU,CAACrB,CAAC,cAArBE,EAAqB,cAArBA,EAAqB,GAAI,CAAC;KAAC,AAAC;IAC9E,IAAIG,KAAK,CAACiB,YAAY,CAAC,MAAM,EAAEF,YAAY,CAAC,EAAE;QAC5C,MAAMlD,WAAW,GAAGmC,KAAK,CAACkB,gBAAgB,CAAC,MAAM,EAAEH,YAAY,CAAC,AAAC;QACjE,IAAIlD,WAAW,CAAC,CAAC,CAAC,KAAKa,SAAS,IAAIb,WAAW,CAAC,CAAC,CAAC,KAAKa,SAAS,EAAE;YAChE,OAAOf,eAAe,CAACmC,SAAS,EAAEjC,WAAW,EAAEC,OAAO,EAAEC,IAAI,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
1
+ {"version":3,"sources":["../../src/TimeSeriesTooltip/focused-series.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ECharts as EChartsInstance } from 'echarts/core';\nimport { formatValue, UnitOptions, EChartsDataFormat } from '../model';\nimport { CursorData, TOOLTIP_DATE_FORMAT, TOOLTIP_MAX_ITEMS } from './tooltip-model';\n\nexport interface FocusedSeriesInfo {\n seriesIdx: number | null;\n datumIdx: number | null;\n seriesName: string;\n date: string;\n markerColor: string;\n x: number;\n y: number;\n formattedY: string;\n}\n\nexport type FocusedSeriesArray = FocusedSeriesInfo[];\n\n/**\n * Returns formatted series data for the points that are close to the user's cursor\n * Adjust yBuffer to increase or decrease number of series shown\n */\nexport function getNearbySeries(\n data: EChartsDataFormat,\n pointInGrid: number[],\n yBuffer: number,\n unit?: UnitOptions\n): FocusedSeriesArray {\n const currentFocusedData: FocusedSeriesArray = [];\n const focusedX: number | null = pointInGrid[0] ?? null;\n const focusedY: number | null = pointInGrid[1] ?? null;\n\n if (focusedX === null || focusedY === null) {\n return currentFocusedData;\n }\n\n if (Array.isArray(data.xAxis) && Array.isArray(data.timeSeries)) {\n for (let seriesIdx = 0; seriesIdx < data.timeSeries.length; seriesIdx++) {\n const currentSeries = data.timeSeries[seriesIdx];\n if (currentFocusedData.length >= TOOLTIP_MAX_ITEMS) break;\n if (currentSeries !== undefined) {\n const currentSeriesName = currentSeries.name ? currentSeries.name.toString() : '';\n const markerColor = currentSeries.color ?? '#000';\n if (Array.isArray(currentSeries.data)) {\n for (let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++) {\n const xValue = data.xAxis[datumIdx] ?? 0;\n const yValue = currentSeries.data[datumIdx];\n // ensure null values not displayed in tooltip\n if (yValue !== undefined && yValue !== null && focusedX === datumIdx) {\n if (yValue !== '-' && focusedY <= yValue + yBuffer && focusedY >= yValue - yBuffer) {\n // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201\n const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;\n const formattedDate = TOOLTIP_DATE_FORMAT.format(xValueMilliSeconds);\n const formattedY = formatValue(yValue, unit);\n currentFocusedData.push({\n seriesIdx: seriesIdx,\n datumIdx: datumIdx,\n seriesName: currentSeriesName,\n date: formattedDate,\n x: xValue,\n y: yValue,\n formattedY: formattedY,\n markerColor: markerColor.toString(),\n });\n }\n }\n }\n }\n }\n }\n }\n return currentFocusedData;\n}\n\n/**\n * Uses mouse position to determine whether user is hovering over a chart canvas\n * If yes, convert from pixel values to logical cartesian coordinates and return all focused series\n */\nexport function getFocusedSeriesData(\n mousePos: CursorData['coords'],\n chartData: EChartsDataFormat,\n pinnedPos: CursorData['coords'],\n chart?: EChartsInstance,\n unit?: UnitOptions\n) {\n if (chart === undefined || mousePos === null) return [];\n\n // prevents multiple tooltips showing from adjacent charts\n let cursorTargetMatchesChart = false;\n if (mousePos.target !== null) {\n const currentParent = (<HTMLElement>mousePos.target).parentElement;\n if (currentParent !== null) {\n const currentGrandparent = currentParent.parentElement;\n if (currentGrandparent !== null) {\n const chartDom = chart.getDom();\n if (chartDom === currentGrandparent) {\n cursorTargetMatchesChart = true;\n }\n }\n }\n }\n\n // allows moving cursor inside tooltip\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n cursorTargetMatchesChart = true;\n }\n\n if (cursorTargetMatchesChart === false) return [];\n\n if (chart['_model'] === undefined) return [];\n const chartModel = chart['_model'];\n const yAxisInterval = chartModel.getComponent('yAxis').axis.scale._interval;\n\n // tooltip trigger area gets smaller with more series, increase yAxisInterval multiplier to expand nearby series range\n const seriesNum = chartData.timeSeries.length;\n const yBuffer = seriesNum > TOOLTIP_MAX_ITEMS ? yAxisInterval * 0.5 : yAxisInterval * 5;\n\n const pointInPixel = [mousePos.plotCanvas.x ?? 0, mousePos.plotCanvas.y ?? 0];\n if (chart.containPixel('grid', pointInPixel)) {\n const pointInGrid = chart.convertFromPixel('grid', pointInPixel);\n if (pointInGrid[0] !== undefined && pointInGrid[1] !== undefined) {\n return getNearbySeries(chartData, pointInGrid, yBuffer, unit);\n }\n }\n return [];\n}\n"],"names":["formatValue","TOOLTIP_DATE_FORMAT","TOOLTIP_MAX_ITEMS","getNearbySeries","data","pointInGrid","yBuffer","unit","currentFocusedData","focusedX","focusedY","Array","isArray","xAxis","timeSeries","seriesIdx","length","currentSeries","undefined","currentSeriesName","name","toString","markerColor","color","datumIdx","xValue","yValue","xValueMilliSeconds","formattedDate","format","formattedY","push","seriesName","date","x","y","getFocusedSeriesData","mousePos","chartData","pinnedPos","chart","cursorTargetMatchesChart","target","currentParent","parentElement","currentGrandparent","chartDom","getDom","chartModel","yAxisInterval","getComponent","axis","scale","_interval","seriesNum","pointInPixel","plotCanvas","containPixel","convertFromPixel"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,WAAW,QAAwC,UAAU,CAAC;AACvE,SAAqBC,mBAAmB,EAAEC,iBAAiB,QAAQ,iBAAiB,CAAC;AAerF;;;CAGC,GACD,OAAO,SAASC,eAAe,CAC7BC,IAAuB,EACvBC,WAAqB,EACrBC,OAAe,EACfC,IAAkB,EACE;IACpB,MAAMC,kBAAkB,GAAuB,EAAE,AAAC;QAClBH,GAAc;IAA9C,MAAMI,QAAQ,GAAkBJ,CAAAA,GAAc,GAAdA,WAAW,CAAC,CAAC,CAAC,cAAdA,GAAc,cAAdA,GAAc,GAAI,IAAI,AAAC;QACvBA,IAAc;IAA9C,MAAMK,QAAQ,GAAkBL,CAAAA,IAAc,GAAdA,WAAW,CAAC,CAAC,CAAC,cAAdA,IAAc,cAAdA,IAAc,GAAI,IAAI,AAAC;IAEvD,IAAII,QAAQ,KAAK,IAAI,IAAIC,QAAQ,KAAK,IAAI,EAAE;QAC1C,OAAOF,kBAAkB,CAAC;IAC5B,CAAC;IAED,IAAIG,KAAK,CAACC,OAAO,CAACR,IAAI,CAACS,KAAK,CAAC,IAAIF,KAAK,CAACC,OAAO,CAACR,IAAI,CAACU,UAAU,CAAC,EAAE;QAC/D,IAAK,IAAIC,SAAS,GAAG,CAAC,EAAEA,SAAS,GAAGX,IAAI,CAACU,UAAU,CAACE,MAAM,EAAED,SAAS,EAAE,CAAE;YACvE,MAAME,aAAa,GAAGb,IAAI,CAACU,UAAU,CAAC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AC;AACZ,CAAC"}
@@ -0,0 +1,128 @@
1
+ // Copyright 2023 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, "ColorPicker", {
18
+ enumerable: true,
19
+ get: ()=>ColorPicker
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
24
+ const _reactColorful = require("react-colorful");
25
+ const _circle = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Circle"));
26
+ function _interopRequireDefault(obj) {
27
+ return obj && obj.__esModule ? obj : {
28
+ default: obj
29
+ };
30
+ }
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 ColorPicker = ({ color , onChange , palette })=>{
71
+ // value is the visible value for the controlled text input
72
+ const [value, setValue] = (0, _react.useState)(color);
73
+ const handleColorChange = (color)=>{
74
+ setValue(color);
75
+ onChange && onChange(color);
76
+ };
77
+ // we should update this if https://github.com/omgovich/react-colorful/issues/157 is resolved
78
+ const handleInputChange = (e)=>{
79
+ const inputValue = e.target.value.replace(/([^0-9A-F]+)/gi, '').substring(0, 8);
80
+ setValue(`#${inputValue}`); // always prefix input value with # to indicate hex format
81
+ // only set color if input value is a valid hex color
82
+ if (isValidHex(e.target.value)) {
83
+ onChange && onChange(e.target.value);
84
+ }
85
+ };
86
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
87
+ spacing: 1,
88
+ children: [
89
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactColorful.HexColorPicker, {
90
+ color: color,
91
+ onChange: handleColorChange
92
+ }),
93
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Stack, {
94
+ direction: "row",
95
+ flexWrap: "wrap",
96
+ justifyContent: "space-evenly",
97
+ width: '200px',
98
+ children: palette && palette.map((color, i)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
99
+ size: "small",
100
+ "aria-label": `change color to ${color}`,
101
+ sx: {
102
+ color
103
+ },
104
+ onClick: ()=>handleColorChange(color),
105
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_circle.default, {})
106
+ }, i))
107
+ }),
108
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
109
+ inputProps: {
110
+ 'aria-label': 'enter hex color'
111
+ },
112
+ fullWidth: true,
113
+ value: value,
114
+ onChange: handleInputChange
115
+ })
116
+ ]
117
+ });
118
+ };
119
+ const isValidHex = (value, alpha)=>{
120
+ const matcher = /^#?([0-9A-F]{3,8})$/i;
121
+ const match = matcher.exec(value);
122
+ const length = match && match[1] ? match[1].length : 0;
123
+ return length === 3 || // '#rgb' format
124
+ length === 6 || // '#rrggbb' format
125
+ !!alpha && length === 4 || // '#rgba' format
126
+ !!alpha && length === 8 // '#rrggbbaa' format
127
+ ;
128
+ };
@@ -14,16 +14,15 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- const _legend = require("./legend");
18
- describe('validateLegendSpec', ()=>{
19
- it('should check if a legend spec is valid', ()=>{
20
- const invalidLegend = {
21
- position: 'bottom'
22
- };
23
- expect((0, _legend.validateLegendSpec)(invalidLegend)).toEqual(false);
24
- expect((0, _legend.validateLegendSpec)({
25
- position: 'Bottom'
26
- })).toEqual(true);
27
- expect((0, _legend.validateLegendSpec)(undefined)).toEqual(true);
17
+ _exportStar(require("./ColorPicker"), 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
+ });
28
26
  });
29
- });
27
+ return from;
28
+ }
@@ -64,6 +64,16 @@ const SecondaryButton = ({ children , ...props })=>/*#__PURE__*/ (0, _jsxRuntime
64
64
  ...props,
65
65
  children: children
66
66
  });
67
+ /*
68
+ * Material-ui has a prop "scroll=paper" that is specifically for dialog header and actions to be sticky and body to scroll,
69
+ * but that doesn't work when dialog content is wrapped in form.
70
+ * https://github.com/mui-org/material-ui/issues/13253
71
+ * This component adds style to get expected behavior & should be used whenever we have a Form inside a Dialog
72
+ */ const Form = (0, _material.styled)('form')({
73
+ overflowY: 'auto',
74
+ display: 'flex',
75
+ flexDirection: 'column'
76
+ });
67
77
  /**
68
78
  * Render the CSS of the dialog's close button, according to the given material theme.
69
79
  * @param theme material theme
@@ -79,6 +89,7 @@ const Dialog = ({ children , ...props })=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_ma
79
89
  children: children
80
90
  });
81
91
  Dialog.Header = Header;
92
+ Dialog.Form = Form;
82
93
  Dialog.Content = Content;
83
94
  Dialog.PrimaryButton = PrimaryButton;
84
95
  Dialog.SecondaryButton = SecondaryButton;
@@ -10,18 +10,19 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { validateLegendSpec } from './legend';
14
- describe('validateLegendSpec', ()=>{
15
- it('should check if a legend spec is valid', ()=>{
16
- const invalidLegend = {
17
- position: 'bottom'
18
- };
19
- expect(validateLegendSpec(invalidLegend)).toEqual(false);
20
- expect(validateLegendSpec({
21
- position: 'Bottom'
22
- })).toEqual(true);
23
- expect(validateLegendSpec(undefined)).toEqual(true);
24
- });
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
25
16
  });
26
-
27
- //# sourceMappingURL=legend.test.js.map
17
+ _exportStar(require("./EChart"), 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
+ }
@@ -27,6 +27,12 @@ function _interopRequireDefault(obj) {
27
27
  };
28
28
  }
29
29
  const InfoTooltip = ({ id , title , description , placement , children , enterDelay , enterNextDelay })=>{
30
+ // Only wrap in a div if passed a non-element. This enables the tooltip to
31
+ // support text with a wrapper div while avoiding breaking css on element
32
+ // children by unnecessarily wrapping them.
33
+ const formattedChildren = /*#__PURE__*/ _react.default.isValidElement(children) ? children : /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
34
+ children: children
35
+ });
30
36
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(StyledTooltip, {
31
37
  arrow: true,
32
38
  id: id,
@@ -37,9 +43,7 @@ const InfoTooltip = ({ id , title , description , placement , children , enterDe
37
43
  }),
38
44
  enterDelay: enterDelay !== null && enterDelay !== void 0 ? enterDelay : 500,
39
45
  enterNextDelay: enterNextDelay !== null && enterNextDelay !== void 0 ? enterNextDelay : 500,
40
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
41
- children: children
42
- })
46
+ children: formattedChildren
43
47
  });
44
48
  };
45
49
  const TooltipContent = ({ title , description })=>{
@@ -39,19 +39,16 @@ function Legend({ width , height , options , data }) {
39
39
  })
40
40
  });
41
41
  }
42
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
42
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
43
43
  sx: {
44
44
  width: width,
45
45
  height: height,
46
46
  position: 'absolute',
47
47
  bottom: 0
48
48
  },
49
- children: [
50
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_compactLegend.CompactLegend, {
51
- items: data,
52
- height: height
53
- }),
54
- ";"
55
- ]
49
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_compactLegend.CompactLegend, {
50
+ items: data,
51
+ height: height
52
+ })
56
53
  });
57
54
  }