@perses-dev/components 0.0.0-snapshot-saving-defaults-refinements-1b25cec → 0.0.0-snapshot-time-chart-rewrite-4667058

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 (307) hide show
  1. package/dist/ContentWithLegend/ContentWithLegend.d.ts +1 -1
  2. package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -1
  3. package/dist/ContentWithLegend/ContentWithLegend.js +5 -3
  4. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
  5. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +10 -4
  6. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
  7. package/dist/ContentWithLegend/model/content-with-legend-model.js +27 -8
  8. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
  9. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -1
  10. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
  11. package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
  12. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +2 -5
  13. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
  14. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
  15. package/dist/Drawer/Drawer.js +1 -1
  16. package/dist/Drawer/Drawer.js.map +1 -1
  17. package/dist/EChart/EChart.d.ts +2 -1
  18. package/dist/EChart/EChart.d.ts.map +1 -1
  19. package/dist/EChart/EChart.js +15 -3
  20. package/dist/EChart/EChart.js.map +1 -1
  21. package/dist/GaugeChart/GaugeChart.d.ts +2 -2
  22. package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
  23. package/dist/GaugeChart/GaugeChart.js +7 -5
  24. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  25. package/dist/Legend/CompactLegend.d.ts +4 -2
  26. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  27. package/dist/Legend/CompactLegend.js +6 -3
  28. package/dist/Legend/CompactLegend.js.map +1 -1
  29. package/dist/Legend/Legend.d.ts +17 -3
  30. package/dist/Legend/Legend.d.ts.map +1 -1
  31. package/dist/Legend/Legend.js +7 -4
  32. package/dist/Legend/Legend.js.map +1 -1
  33. package/dist/Legend/ListLegend.d.ts +4 -2
  34. package/dist/Legend/ListLegend.d.ts.map +1 -1
  35. package/dist/Legend/ListLegend.js +6 -5
  36. package/dist/Legend/ListLegend.js.map +1 -1
  37. package/dist/Legend/ListLegendItem.d.ts +16 -3
  38. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  39. package/dist/Legend/ListLegendItem.js +17 -5
  40. package/dist/Legend/ListLegendItem.js.map +1 -1
  41. package/dist/Legend/TableLegend.d.ts +6 -3
  42. package/dist/Legend/TableLegend.d.ts.map +1 -1
  43. package/dist/Legend/TableLegend.js +17 -3
  44. package/dist/Legend/TableLegend.js.map +1 -1
  45. package/dist/Legend/index.d.ts +1 -0
  46. package/dist/Legend/index.d.ts.map +1 -1
  47. package/dist/Legend/index.js +1 -0
  48. package/dist/Legend/index.js.map +1 -1
  49. package/dist/Legend/legend-model.d.ts +24 -0
  50. package/dist/Legend/legend-model.d.ts.map +1 -0
  51. package/dist/Legend/legend-model.js +19 -0
  52. package/dist/Legend/legend-model.js.map +1 -0
  53. package/dist/LineChart/LineChart.d.ts +6 -11
  54. package/dist/LineChart/LineChart.d.ts.map +1 -1
  55. package/dist/LineChart/LineChart.js +36 -9
  56. package/dist/LineChart/LineChart.js.map +1 -1
  57. package/dist/LineChart/index.d.ts +0 -1
  58. package/dist/LineChart/index.d.ts.map +1 -1
  59. package/dist/LineChart/index.js.map +1 -1
  60. package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  61. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  62. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts +12 -0
  63. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts.map +1 -0
  64. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +45 -0
  65. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -0
  66. package/dist/RefreshIntervalPicker/index.d.ts +2 -0
  67. package/dist/RefreshIntervalPicker/index.d.ts.map +1 -0
  68. package/dist/{model/units → RefreshIntervalPicker}/index.js +1 -3
  69. package/dist/RefreshIntervalPicker/index.js.map +1 -0
  70. package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts +36 -0
  71. package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts.map +1 -0
  72. package/dist/SettingsAutocomplete/SettingsAutocomplete.js +65 -0
  73. package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -0
  74. package/dist/SettingsAutocomplete/index.d.ts +2 -0
  75. package/dist/SettingsAutocomplete/index.d.ts.map +1 -0
  76. package/dist/{model/units/constants.js → SettingsAutocomplete/index.js} +2 -4
  77. package/dist/SettingsAutocomplete/index.js.map +1 -0
  78. package/dist/StatChart/StatChart.d.ts +3 -2
  79. package/dist/StatChart/StatChart.d.ts.map +1 -1
  80. package/dist/StatChart/StatChart.js +75 -22
  81. package/dist/StatChart/StatChart.js.map +1 -1
  82. package/dist/StatChart/calculateFontSize.d.ts +14 -0
  83. package/dist/StatChart/calculateFontSize.d.ts.map +1 -0
  84. package/dist/StatChart/calculateFontSize.js +47 -0
  85. package/dist/StatChart/calculateFontSize.js.map +1 -0
  86. package/dist/Table/InnerTable.js +3 -3
  87. package/dist/Table/InnerTable.js.map +1 -1
  88. package/dist/Table/Table.d.ts +1 -1
  89. package/dist/Table/Table.d.ts.map +1 -1
  90. package/dist/Table/Table.js +58 -10
  91. package/dist/Table/Table.js.map +1 -1
  92. package/dist/Table/TableCell.d.ts +16 -3
  93. package/dist/Table/TableCell.d.ts.map +1 -1
  94. package/dist/Table/TableCell.js +13 -5
  95. package/dist/Table/TableCell.js.map +1 -1
  96. package/dist/Table/TableCheckbox.js +1 -1
  97. package/dist/Table/TableCheckbox.js.map +1 -1
  98. package/dist/Table/TableHeaderCell.d.ts +23 -0
  99. package/dist/Table/TableHeaderCell.d.ts.map +1 -0
  100. package/dist/Table/TableHeaderCell.js +53 -0
  101. package/dist/Table/TableHeaderCell.js.map +1 -0
  102. package/dist/Table/TableRow.d.ts.map +1 -1
  103. package/dist/Table/TableRow.js +3 -3
  104. package/dist/Table/TableRow.js.map +1 -1
  105. package/dist/Table/VirtualizedTable.d.ts +3 -3
  106. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  107. package/dist/Table/VirtualizedTable.js +51 -10
  108. package/dist/Table/VirtualizedTable.js.map +1 -1
  109. package/dist/Table/model/table-model.d.ts +81 -3
  110. package/dist/Table/model/table-model.d.ts.map +1 -1
  111. package/dist/Table/model/table-model.js +22 -7
  112. package/dist/Table/model/table-model.js.map +1 -1
  113. package/dist/TimeChart/TimeChart.d.ts +23 -0
  114. package/dist/TimeChart/TimeChart.d.ts.map +1 -0
  115. package/dist/TimeChart/TimeChart.js +314 -0
  116. package/dist/TimeChart/TimeChart.js.map +1 -0
  117. package/dist/TimeChart/index.d.ts +2 -0
  118. package/dist/TimeChart/index.d.ts.map +1 -0
  119. package/dist/{LegendOptionsEditor → TimeChart}/index.js +1 -1
  120. package/dist/TimeChart/index.js.map +1 -0
  121. package/dist/TimeSeriesTooltip/{TimeSeriesTooltip.d.ts → LineChartTooltip.d.ts} +5 -4
  122. package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts.map +1 -0
  123. package/dist/TimeSeriesTooltip/{TimeSeriesTooltip.js → LineChartTooltip.js} +7 -6
  124. package/dist/TimeSeriesTooltip/LineChartTooltip.js.map +1 -0
  125. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts +16 -0
  126. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -0
  127. package/dist/TimeSeriesTooltip/TimeChartTooltip.js +76 -0
  128. package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -0
  129. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +2 -2
  130. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -1
  131. package/dist/TimeSeriesTooltip/TooltipHeader.js +10 -8
  132. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
  133. package/dist/TimeSeriesTooltip/index.d.ts +2 -1
  134. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  135. package/dist/TimeSeriesTooltip/index.js +2 -1
  136. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  137. package/dist/TimeSeriesTooltip/nearby-series.d.ts +23 -4
  138. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  139. package/dist/TimeSeriesTooltip/nearby-series.js +175 -17
  140. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  141. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +4 -0
  142. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  143. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  144. package/dist/TimeSeriesTooltip/utils.d.ts +25 -0
  145. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  146. package/dist/TimeSeriesTooltip/utils.js +29 -1
  147. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  148. package/dist/UnitSelector/UnitSelector.d.ts +1 -1
  149. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  150. package/dist/UnitSelector/UnitSelector.js +11 -24
  151. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  152. package/dist/YAxisLabel.js +1 -1
  153. package/dist/YAxisLabel.js.map +1 -1
  154. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +5 -3
  155. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +28 -9
  156. package/dist/cjs/Drawer/Drawer.js +1 -1
  157. package/dist/cjs/EChart/EChart.js +22 -5
  158. package/dist/cjs/GaugeChart/GaugeChart.js +7 -5
  159. package/dist/cjs/Legend/CompactLegend.js +7 -4
  160. package/dist/cjs/Legend/Legend.js +8 -5
  161. package/dist/cjs/Legend/ListLegend.js +7 -6
  162. package/dist/cjs/Legend/ListLegendItem.js +17 -5
  163. package/dist/cjs/Legend/TableLegend.js +17 -3
  164. package/dist/cjs/Legend/index.js +1 -0
  165. package/dist/cjs/{model/units/types.js → Legend/legend-model.js} +7 -10
  166. package/dist/cjs/LineChart/LineChart.js +35 -47
  167. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  168. package/dist/cjs/RefreshIntervalPicker/RefreshIntervalPicker.js +51 -0
  169. package/dist/cjs/{model/units → RefreshIntervalPicker}/index.js +1 -3
  170. package/dist/cjs/SettingsAutocomplete/SettingsAutocomplete.js +66 -0
  171. package/dist/cjs/SettingsAutocomplete/index.js +28 -0
  172. package/dist/cjs/StatChart/StatChart.js +82 -24
  173. package/dist/cjs/StatChart/calculateFontSize.js +51 -0
  174. package/dist/cjs/Table/InnerTable.js +3 -3
  175. package/dist/cjs/Table/Table.js +57 -9
  176. package/dist/cjs/Table/TableCell.js +13 -5
  177. package/dist/cjs/Table/TableCheckbox.js +1 -1
  178. package/dist/cjs/Table/TableHeaderCell.js +59 -0
  179. package/dist/cjs/Table/TableRow.js +2 -2
  180. package/dist/cjs/Table/VirtualizedTable.js +51 -10
  181. package/dist/cjs/Table/model/table-model.js +22 -7
  182. package/dist/cjs/TimeChart/TimeChart.js +320 -0
  183. package/dist/cjs/{LegendOptionsEditor → TimeChart}/index.js +1 -1
  184. package/dist/cjs/TimeSeriesTooltip/{TimeSeriesTooltip.js → LineChartTooltip.js} +7 -45
  185. package/dist/cjs/TimeSeriesTooltip/TimeChartTooltip.js +87 -0
  186. package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +10 -8
  187. package/dist/cjs/TimeSeriesTooltip/index.js +2 -1
  188. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +171 -17
  189. package/dist/cjs/TimeSeriesTooltip/utils.js +35 -3
  190. package/dist/cjs/UnitSelector/UnitSelector.js +15 -28
  191. package/dist/cjs/YAxisLabel.js +1 -1
  192. package/dist/cjs/index.js +3 -1
  193. package/dist/cjs/model/index.js +1 -2
  194. package/dist/cjs/model/timeOption.js +16 -0
  195. package/dist/cjs/{model/units/constants.js → theme/component-overrides/paper.js} +9 -5
  196. package/dist/cjs/theme/palette/background.js +2 -2
  197. package/dist/cjs/theme/theme.js +2 -0
  198. package/dist/cjs/utils/axis.js +58 -0
  199. package/dist/cjs/{LineChart/utils.js → utils/chart-actions.js} +9 -47
  200. package/dist/cjs/utils/format.js +47 -1
  201. package/dist/cjs/utils/index.js +3 -1
  202. package/dist/cjs/utils/theme-gen.js +44 -2
  203. package/dist/index.d.ts +3 -1
  204. package/dist/index.d.ts.map +1 -1
  205. package/dist/index.js +3 -1
  206. package/dist/index.js.map +1 -1
  207. package/dist/model/graph.d.ts +20 -3
  208. package/dist/model/graph.d.ts.map +1 -1
  209. package/dist/model/graph.js.map +1 -1
  210. package/dist/model/index.d.ts +1 -2
  211. package/dist/model/index.d.ts.map +1 -1
  212. package/dist/model/index.js +1 -2
  213. package/dist/model/index.js.map +1 -1
  214. package/dist/model/theme.d.ts +4 -6
  215. package/dist/model/theme.d.ts.map +1 -1
  216. package/dist/model/theme.js.map +1 -1
  217. package/dist/model/timeOption.d.ts +6 -0
  218. package/dist/model/timeOption.d.ts.map +1 -0
  219. package/dist/model/{units/types.js → timeOption.js} +2 -9
  220. package/dist/model/timeOption.js.map +1 -0
  221. package/dist/theme/component-overrides/paper.d.ts +3 -0
  222. package/dist/theme/component-overrides/paper.d.ts.map +1 -0
  223. package/dist/theme/component-overrides/paper.js +21 -0
  224. package/dist/theme/component-overrides/paper.js.map +1 -0
  225. package/dist/theme/palette/background.js +2 -2
  226. package/dist/theme/palette/background.js.map +1 -1
  227. package/dist/theme/theme.d.ts.map +1 -1
  228. package/dist/theme/theme.js +2 -0
  229. package/dist/theme/theme.js.map +1 -1
  230. package/dist/utils/axis.d.ts +14 -0
  231. package/dist/utils/axis.d.ts.map +1 -0
  232. package/dist/utils/axis.js +45 -0
  233. package/dist/utils/axis.js.map +1 -0
  234. package/dist/utils/chart-actions.d.ts +18 -0
  235. package/dist/utils/chart-actions.d.ts.map +1 -0
  236. package/dist/utils/chart-actions.js +52 -0
  237. package/dist/utils/chart-actions.js.map +1 -0
  238. package/dist/utils/format.d.ts +6 -0
  239. package/dist/utils/format.d.ts.map +1 -1
  240. package/dist/utils/format.js +47 -0
  241. package/dist/utils/format.js.map +1 -1
  242. package/dist/utils/index.d.ts +3 -1
  243. package/dist/utils/index.d.ts.map +1 -1
  244. package/dist/utils/index.js +3 -1
  245. package/dist/utils/index.js.map +1 -1
  246. package/dist/utils/theme-gen.d.ts.map +1 -1
  247. package/dist/utils/theme-gen.js +38 -1
  248. package/dist/utils/theme-gen.js.map +1 -1
  249. package/package.json +5 -9
  250. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts +0 -8
  251. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +0 -1
  252. package/dist/LegendOptionsEditor/LegendOptionsEditor.js +0 -109
  253. package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +0 -1
  254. package/dist/LegendOptionsEditor/index.d.ts +0 -2
  255. package/dist/LegendOptionsEditor/index.d.ts.map +0 -1
  256. package/dist/LegendOptionsEditor/index.js.map +0 -1
  257. package/dist/LineChart/utils.d.ts +0 -30
  258. package/dist/LineChart/utils.d.ts.map +0 -1
  259. package/dist/LineChart/utils.js +0 -90
  260. package/dist/LineChart/utils.js.map +0 -1
  261. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +0 -1
  262. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +0 -1
  263. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +0 -115
  264. package/dist/cjs/model/legend.js +0 -102
  265. package/dist/cjs/model/units/bytes.js +0 -84
  266. package/dist/cjs/model/units/decimal.js +0 -62
  267. package/dist/cjs/model/units/percent.js +0 -73
  268. package/dist/cjs/model/units/time.js +0 -105
  269. package/dist/cjs/model/units/units.js +0 -101
  270. package/dist/cjs/model/units/utils.js +0 -42
  271. package/dist/model/legend.d.ts +0 -36
  272. package/dist/model/legend.d.ts.map +0 -1
  273. package/dist/model/legend.js +0 -81
  274. package/dist/model/legend.js.map +0 -1
  275. package/dist/model/units/bytes.d.ts +0 -13
  276. package/dist/model/units/bytes.d.ts.map +0 -1
  277. package/dist/model/units/bytes.js +0 -66
  278. package/dist/model/units/bytes.js.map +0 -1
  279. package/dist/model/units/constants.d.ts +0 -2
  280. package/dist/model/units/constants.d.ts.map +0 -1
  281. package/dist/model/units/constants.js.map +0 -1
  282. package/dist/model/units/decimal.d.ts +0 -13
  283. package/dist/model/units/decimal.d.ts.map +0 -1
  284. package/dist/model/units/decimal.js +0 -49
  285. package/dist/model/units/decimal.js.map +0 -1
  286. package/dist/model/units/index.d.ts +0 -4
  287. package/dist/model/units/index.d.ts.map +0 -1
  288. package/dist/model/units/index.js.map +0 -1
  289. package/dist/model/units/percent.d.ts +0 -12
  290. package/dist/model/units/percent.d.ts.map +0 -1
  291. package/dist/model/units/percent.js +0 -60
  292. package/dist/model/units/percent.js.map +0 -1
  293. package/dist/model/units/time.d.ts +0 -22
  294. package/dist/model/units/time.d.ts.map +0 -1
  295. package/dist/model/units/time.js +0 -91
  296. package/dist/model/units/time.js.map +0 -1
  297. package/dist/model/units/types.d.ts +0 -47
  298. package/dist/model/units/types.d.ts.map +0 -1
  299. package/dist/model/units/types.js.map +0 -1
  300. package/dist/model/units/units.d.ts +0 -40
  301. package/dist/model/units/units.d.ts.map +0 -1
  302. package/dist/model/units/units.js +0 -80
  303. package/dist/model/units/units.js.map +0 -1
  304. package/dist/model/units/utils.d.ts +0 -4
  305. package/dist/model/units/utils.d.ts.map +0 -1
  306. package/dist/model/units/utils.js +0 -32
  307. package/dist/model/units/utils.js.map +0 -1
@@ -0,0 +1,65 @@
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 { Autocomplete, TextField, Typography, createFilterOptions } from '@mui/material';
15
+ /**
16
+ * Opinionated autocomplete component useful for providing users with a dropdown
17
+ * for settings that require selecting one or more options from a list.
18
+ *
19
+ * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**
20
+ */ export function SettingsAutocomplete({ options , renderInput =(params)=>/*#__PURE__*/ _jsx(TextField, {
21
+ ...params
22
+ }) , ...otherProps }) {
23
+ const getOptionLabel = (option)=>{
24
+ var _label;
25
+ return (_label = option.label) !== null && _label !== void 0 ? _label : option.id;
26
+ };
27
+ // Note: this component currently is not virtualized because it is specific
28
+ // to being used for settings, which generally have a pretty small list of
29
+ // options. If this changes to include values with many options, virtualization
30
+ // should be added using react-virtuoso.
31
+ return /*#__PURE__*/ _jsx(Autocomplete, {
32
+ isOptionEqualToValue: (option, value)=>option.id === value.id,
33
+ getOptionDisabled: (option)=>!!option.disabled,
34
+ getOptionLabel: getOptionLabel,
35
+ options: options,
36
+ renderInput: renderInput,
37
+ renderOption: (props, option)=>{
38
+ return /*#__PURE__*/ _jsx("li", {
39
+ ...props,
40
+ children: /*#__PURE__*/ _jsxs("div", {
41
+ children: [
42
+ /*#__PURE__*/ _jsx(Typography, {
43
+ variant: "body1",
44
+ component: "div",
45
+ children: getOptionLabel(option)
46
+ }),
47
+ option.description && /*#__PURE__*/ _jsx(Typography, {
48
+ variant: "body2",
49
+ component: "div",
50
+ color: (theme)=>theme.palette.text.secondary,
51
+ children: option.description
52
+ })
53
+ ]
54
+ })
55
+ });
56
+ },
57
+ filterOptions: createFilterOptions({
58
+ // Include the label and the description in search.
59
+ stringify: (option)=>`${getOptionLabel(option)} ${option.description || ''}`
60
+ }),
61
+ ...otherProps
62
+ });
63
+ }
64
+
65
+ //# sourceMappingURL=SettingsAutocomplete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/SettingsAutocomplete/SettingsAutocomplete.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 {\n Autocomplete,\n AutocompleteProps,\n TextField,\n Typography,\n UseAutocompleteProps,\n createFilterOptions,\n} from '@mui/material';\nimport { ReactNode } from 'react';\n\n/**\n * Interface to extend from for `options` when using `SettingsAutocomplete`.\n */\nexport interface SettingsAutocompleteOption {\n /**\n * Unique identifier for the option.\n */\n id: string;\n\n /**\n * Optional value that is presented to the user for each option. If not set,\n * the `id` will be used instead.\n */\n label?: string;\n\n /**\n * Optional description that will be rendered below the `label` to provide the\n * user with additional information about the option.\n */\n description?: ReactNode;\n\n /**\n * When `true`, the option will be disabled.\n */\n disabled?: boolean;\n}\n\nexport interface SettingsAutocompleteProps<\n OptionType extends SettingsAutocompleteOption,\n Multiple extends boolean | undefined,\n DisableClearable extends boolean | undefined\n // Note that the last `false` in the generic arguments sets the `freeSolo` option to `false`.\n // This component is intended to be used with a discrete list of options, so `freeSolo` never\n // needs to be `true`.\n> extends Omit<AutocompleteProps<OptionType, Multiple, DisableClearable, false>, 'renderInput'> {\n // Modifying this to optional, so we can define a sensible default below that\n // is used in many of the simple cases.\n renderInput?: AutocompleteProps<OptionType, Multiple, DisableClearable, false>['renderInput'];\n}\n\n/**\n * Opinionated autocomplete component useful for providing users with a dropdown\n * for settings that require selecting one or more options from a list.\n *\n * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**\n */\nexport function SettingsAutocomplete<\n OptionType extends SettingsAutocompleteOption,\n Multiple extends boolean | undefined = false,\n DisableClearable extends boolean | undefined = false\n>({\n options,\n renderInput = (params) => <TextField {...params} />,\n ...otherProps\n}: SettingsAutocompleteProps<OptionType, Multiple, DisableClearable>) {\n const getOptionLabel: UseAutocompleteProps<OptionType, undefined, boolean, undefined>['getOptionLabel'] = (\n option\n ) => {\n return option.label ?? option.id;\n };\n\n // Note: this component currently is not virtualized because it is specific\n // to being used for settings, which generally have a pretty small list of\n // options. If this changes to include values with many options, virtualization\n // should be added using react-virtuoso.\n return (\n <Autocomplete\n isOptionEqualToValue={(option, value) => option.id === value.id}\n getOptionDisabled={(option) => !!option.disabled}\n getOptionLabel={getOptionLabel}\n options={options}\n renderInput={renderInput}\n renderOption={(props, option) => {\n return (\n <li {...props}>\n <div>\n <Typography variant=\"body1\" component=\"div\">\n {getOptionLabel(option)}\n </Typography>\n {option.description && (\n <Typography variant=\"body2\" component=\"div\" color={(theme) => theme.palette.text.secondary}>\n {option.description}\n </Typography>\n )}\n </div>\n </li>\n );\n }}\n filterOptions={createFilterOptions({\n // Include the label and the description in search.\n stringify: (option) => `${getOptionLabel(option)} ${option.description || ''}`,\n })}\n {...otherProps}\n />\n );\n}\n"],"names":["Autocomplete","TextField","Typography","createFilterOptions","SettingsAutocomplete","options","renderInput","params","otherProps","getOptionLabel","option","label","id","isOptionEqualToValue","value","getOptionDisabled","disabled","renderOption","props","li","div","variant","component","description","color","theme","palette","text","secondary","filterOptions","stringify"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF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ACC,OAAO,CAACC,IAAI,CAACC,SAAS;sCACvFlB,MAAM,CAACa,WAAW;0BACR,AACd;;kBACG;cACH,CACL;QACJ,CAAC;QACDM,aAAa,EAAE1B,mBAAmB,CAAC;YACjC,mDAAmD;YACnD2B,SAAS,EAAE,CAACpB,MAAM,GAAK,CAAC,EAAED,cAAc,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEA,MAAM,CAACa,WAAW,IAAI,EAAE,CAAC,CAAC;SAC/E,CAAC;QACD,GAAGf,UAAU;MACd,CACF;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './SettingsAutocomplete';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/SettingsAutocomplete/index.ts"],"names":[],"mappings":"AAaA,cAAc,wBAAwB,CAAC"}
@@ -10,8 +10,6 @@
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
- // Common constants needed across individual unit groups and the overall
14
- // combined units.
15
- export const MAX_SIGNIFICANT_DIGITS = 3;
13
+ export * from './SettingsAutocomplete';
16
14
 
17
- //# sourceMappingURL=constants.js.map
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/SettingsAutocomplete/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 './SettingsAutocomplete';\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,wBAAwB,CAAC"}
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
+ import { UnitOptions } from '@perses-dev/core';
2
3
  import { LineSeriesOption } from 'echarts/charts';
3
- import { UnitOptions } from '../model/units';
4
4
  import { GraphSeries } from '../model/graph';
5
5
  export interface StatChartData {
6
- calculatedValue?: number;
6
+ calculatedValue?: number | null;
7
7
  seriesData?: GraphSeries;
8
8
  }
9
9
  export interface StatChartProps {
@@ -13,6 +13,7 @@ export interface StatChartProps {
13
13
  unit: UnitOptions;
14
14
  color?: string;
15
15
  sparkline?: LineSeriesOption;
16
+ showSeriesName?: boolean;
16
17
  }
17
18
  export declare function StatChart(props: StatChartProps): JSX.Element;
18
19
  //# sourceMappingURL=StatChart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StatChart.d.ts","sourceRoot":"","sources":["../../src/StatChart/StatChart.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAiC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIjF,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAwG9C"}
1
+ {"version":3,"file":"StatChart.d.ts","sourceRoot":"","sources":["../../src/StatChart/StatChart.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAe,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI5D,OAAO,EAAiC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAKjF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAU7C,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAkI9C"}
@@ -12,15 +12,16 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { useMemo } from 'react';
15
- import { Box, Typography } from '@mui/material';
16
- import { merge } from 'lodash-es';
15
+ import { formatValue } from '@perses-dev/core';
16
+ import { Box, Typography, styled } from '@mui/material';
17
+ import merge from 'lodash/merge';
17
18
  import { use } from 'echarts/core';
18
19
  import { LineChart as EChartsLineChart } from 'echarts/charts';
19
20
  import { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';
20
21
  import { CanvasRenderer } from 'echarts/renderers';
21
22
  import { useChartsTheme } from '../context/ChartsThemeProvider';
22
- import { formatValue } from '../model/units';
23
23
  import { EChart } from '../EChart';
24
+ import { useOptimalFontSize } from './calculateFontSize';
24
25
  use([
25
26
  EChartsLineChart,
26
27
  GridComponent,
@@ -29,12 +30,48 @@ use([
29
30
  TooltipComponent,
30
31
  CanvasRenderer
31
32
  ]);
32
- const MIN_VALUE_SIZE = 12;
33
- const MAX_VALUE_SIZE = 36;
33
+ const LINE_HEIGHT = 1.2;
34
+ const SERIES_NAME_MAX_FONT_SIZE = 30;
35
+ const SERIES_NAME_FONT_WEIGHT = 400;
36
+ const VALUE_FONT_WEIGHT = 700;
34
37
  export function StatChart(props) {
35
- const { width , height , data , unit , color , sparkline } = props;
38
+ var ref, ref1;
39
+ const { width , height , data , unit , color , sparkline , showSeriesName } = props;
36
40
  const chartsTheme = useChartsTheme();
37
- const formattedValue = data.calculatedValue === undefined ? '' : formatValue(data.calculatedValue, unit);
41
+ let formattedValue = '';
42
+ if (data.calculatedValue === null) {
43
+ formattedValue = 'null';
44
+ } else if (typeof data.calculatedValue === 'number') {
45
+ formattedValue = formatValue(data.calculatedValue, unit);
46
+ }
47
+ const containerPadding = chartsTheme.container.padding.default;
48
+ var ref2;
49
+ // calculate series name font size and height
50
+ let seriesNameFontSize = useOptimalFontSize({
51
+ text: (ref2 = data === null || data === void 0 ? void 0 : (ref = data.seriesData) === null || ref === void 0 ? void 0 : ref.name) !== null && ref2 !== void 0 ? ref2 : '',
52
+ fontWeight: SERIES_NAME_FONT_WEIGHT,
53
+ width,
54
+ height: height * 0.125,
55
+ lineHeight: LINE_HEIGHT,
56
+ maxSize: SERIES_NAME_MAX_FONT_SIZE
57
+ });
58
+ const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;
59
+ // calculate value font size and height
60
+ const availableWidth = width - containerPadding * 2;
61
+ const availableHeight = height - seriesNameHeight;
62
+ const valueFontSize = useOptimalFontSize({
63
+ text: formattedValue,
64
+ fontWeight: VALUE_FONT_WEIGHT,
65
+ // without sparkline, use only 50% of the available width so it looks better for multiseries
66
+ width: sparkline ? availableWidth : availableWidth * 0.5,
67
+ // with sparkline, use only 25% of available height to leave room for chart
68
+ // without sparkline, value should take up 90% of available space
69
+ height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,
70
+ lineHeight: LINE_HEIGHT
71
+ });
72
+ const valueFontHeight = valueFontSize * LINE_HEIGHT;
73
+ // make sure the series name font size is slightly smaller than value font size
74
+ seriesNameFontSize = Math.min(valueFontSize * 0.7, seriesNameFontSize);
38
75
  const option = useMemo(()=>{
39
76
  if (data.seriesData === undefined) return chartsTheme.noDataOption;
40
77
  const series = data.seriesData;
@@ -42,9 +79,8 @@ export function StatChart(props) {
42
79
  if (sparkline !== undefined) {
43
80
  const lineSeries = {
44
81
  type: 'line',
45
- data: [
46
- ...series.values
47
- ],
82
+ name: series.name,
83
+ data: series.values,
48
84
  zlevel: 1,
49
85
  symbol: 'none',
50
86
  animation: false,
@@ -92,11 +128,6 @@ export function StatChart(props) {
92
128
  chartsTheme,
93
129
  sparkline
94
130
  ]);
95
- const isLargePanel = width > 250 && height > 180;
96
- // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute
97
- const charactersAdjust = formattedValue.length;
98
- const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
99
- const containerPadding = `${chartsTheme.container.padding.default}px`;
100
131
  const textAlignment = sparkline ? 'auto' : 'center';
101
132
  const textStyles = {
102
133
  display: 'flex',
@@ -111,19 +142,22 @@ export function StatChart(props) {
111
142
  ...textStyles
112
143
  },
113
144
  children: [
114
- /*#__PURE__*/ _jsx(Typography, {
145
+ showSeriesName && /*#__PURE__*/ _jsx(SeriesName, {
146
+ padding: containerPadding,
147
+ fontSize: seriesNameFontSize,
148
+ children: (ref1 = data.seriesData) === null || ref1 === void 0 ? void 0 : ref1.name
149
+ }),
150
+ /*#__PURE__*/ _jsx(Value, {
115
151
  variant: "h3",
116
- sx: (theme)=>({
117
- color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
118
- fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
119
- padding: sparkline ? `${containerPadding} ${containerPadding} 0 ${containerPadding}` : ` 0 ${containerPadding}`
120
- }),
152
+ color: color,
153
+ fontSize: valueFontSize,
154
+ padding: containerPadding,
121
155
  children: formattedValue
122
156
  }),
123
157
  sparkline !== undefined && /*#__PURE__*/ _jsx(EChart, {
124
158
  sx: {
125
159
  width: '100%',
126
- height: '100%'
160
+ height: height - seriesNameHeight - valueFontHeight
127
161
  },
128
162
  option: option,
129
163
  theme: chartsTheme.echartsTheme,
@@ -132,5 +166,24 @@ export function StatChart(props) {
132
166
  ]
133
167
  });
134
168
  }
169
+ const SeriesName = styled(Typography, {
170
+ shouldForwardProp: (prop)=>prop !== 'padding' && prop !== 'fontSize'
171
+ })(({ theme , padding , fontSize })=>({
172
+ color: theme.palette.text.secondary,
173
+ padding: `${padding}px`,
174
+ fontSize: `${fontSize}px`,
175
+ overflow: 'hidden',
176
+ textOverflow: 'ellipsis',
177
+ whiteSpace: 'nowrap'
178
+ }));
179
+ const Value = styled(Typography, {
180
+ shouldForwardProp: (prop)=>prop !== 'color' && prop !== 'padding' && prop !== 'fontSize' && prop !== 'sparkline'
181
+ })(({ theme , color , padding , fontSize , sparkline })=>({
182
+ color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
183
+ fontSize: `${fontSize}px`,
184
+ padding: sparkline ? `${padding}px ${padding}px 0 ${padding}px` : ` 0 ${padding}px`,
185
+ whiteSpace: 'nowrap',
186
+ lineHeight: LINE_HEIGHT
187
+ }));
135
188
 
136
189
  //# sourceMappingURL=StatChart.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/StatChart/StatChart.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 { useMemo } from 'react';\nimport { Box, Typography } from '@mui/material';\nimport { merge } from 'lodash-es';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { formatValue, UnitOptions } from '../model/units';\nimport { EChart } from '../EChart';\nimport { GraphSeries } from '../model/graph';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst MIN_VALUE_SIZE = 12;\nconst MAX_VALUE_SIZE = 36;\n\nexport interface StatChartData {\n calculatedValue?: number;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n unit: UnitOptions;\n color?: string;\n sparkline?: LineSeriesOption;\n}\n\nexport function StatChart(props: StatChartProps) {\n const { width, height, data, unit, color, sparkline } = props;\n const chartsTheme = useChartsTheme();\n\n const formattedValue = data.calculatedValue === undefined ? '' : formatValue(data.calculatedValue, unit);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.seriesData === undefined) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline !== undefined) {\n const lineSeries = {\n type: 'line',\n data: [...series.values],\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n const mergedSeries = merge(lineSeries, sparkline);\n statSeries.push(mergedSeries);\n }\n\n const option = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n min: (value: { min: number; max: number }) => {\n if (value.min >= 0 && value.min <= 1) {\n // helps with PercentDecimal units, or datasets that return 0 or 1 booleans\n return 0;\n }\n return value.min;\n },\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline]);\n\n const isLargePanel = width > 250 && height > 180;\n // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute\n const charactersAdjust = formattedValue.length;\n const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;\n\n const containerPadding = `${chartsTheme.container.padding.default}px`;\n\n const textAlignment = sparkline ? 'auto' : 'center';\n const textStyles = {\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n };\n\n return (\n <Box sx={{ height: '100%', width: '100%', ...textStyles }}>\n <Typography\n variant=\"h3\"\n sx={(theme) => ({\n color: color ?? theme.palette.text.primary,\n fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,\n padding: sparkline\n ? `${containerPadding} ${containerPadding} 0 ${containerPadding}`\n : ` 0 ${containerPadding}`,\n })}\n >\n {formattedValue}\n </Typography>\n {sparkline !== undefined && (\n <EChart\n sx={{\n width: '100%',\n height: '100%',\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n renderer=\"svg\"\n />\n )}\n </Box>\n );\n}\n"],"names":["useMemo","Box","Typography","merge","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","formatValue","EChart","MIN_VALUE_SIZE","MAX_VALUE_SIZE","StatChart","props","width","height","data","unit","color","sparkline","chartsTheme","formattedValue","calculatedValue","undefined","option","seriesData","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","min","value","tooltip","isLargePanel","charactersAdjust","length","valueSize","Math","containerPadding","container","padding","default","textAlignment","textStyles","display","flexDirection","justifyContent","alignItems","sx","vari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,cAAc,CAAC,IAAI,EAAE6C,SAAS,CAAC,IAAI,EAAE5C,cAAc,CAAC,GAAG,CAAC;wBAC3EgD,OAAO,EAAExC,SAAS,GACd,CAAC,EAAEsC,gBAAgB,CAAC,CAAC,EAAEA,gBAAgB,CAAC,GAAG,EAAEA,gBAAgB,CAAC,CAAC,GAC/D,CAAC,GAAG,EAAEA,gBAAgB,CAAC,CAAC;qBAC7B,CAAA,AAAC;0BAEDpC,cAAc;cACJ;YACZF,SAAS,KAAKI,SAAS,kBACtB,KAACd,MAAM;gBACL0D,EAAE,EAAE;oBACFrD,KAAK,EAAE,MAAM;oBACbC,MAAM,EAAE,MAAM;iBACf;gBACDS,MAAM,EAAEA,MAAM;gBACd6C,KAAK,EAAEjD,WAAW,CAACsD,YAAY;gBAC/BC,QAAQ,EAAC,KAAK;cACd,AACH;;MACG,CACN;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../src/StatChart/StatChart.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 { useMemo } from 'react';\nimport { formatValue, UnitOptions } from '@perses-dev/core';\nimport { Box, Typography, styled } from '@mui/material';\nimport merge from 'lodash/merge';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { EChart } from '../EChart';\nimport { GraphSeries } from '../model/graph';\nimport { useOptimalFontSize } from './calculateFontSize';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst LINE_HEIGHT = 1.2;\nconst SERIES_NAME_MAX_FONT_SIZE = 30;\nconst SERIES_NAME_FONT_WEIGHT = 400;\nconst VALUE_FONT_WEIGHT = 700;\n\nexport interface StatChartData {\n calculatedValue?: number | null;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n unit: UnitOptions;\n color?: string;\n sparkline?: LineSeriesOption;\n showSeriesName?: boolean;\n}\n\nexport function StatChart(props: StatChartProps) {\n const { width, height, data, unit, color, sparkline, showSeriesName } = props;\n const chartsTheme = useChartsTheme();\n\n let formattedValue = '';\n if (data.calculatedValue === null) {\n formattedValue = 'null';\n } else if (typeof data.calculatedValue === 'number') {\n formattedValue = formatValue(data.calculatedValue, unit);\n }\n\n const containerPadding = chartsTheme.container.padding.default;\n\n // calculate series name font size and height\n let seriesNameFontSize = useOptimalFontSize({\n text: data?.seriesData?.name ?? '',\n fontWeight: SERIES_NAME_FONT_WEIGHT,\n width,\n height: height * 0.125, // assume series name will take 12.5% of available height\n lineHeight: LINE_HEIGHT,\n maxSize: SERIES_NAME_MAX_FONT_SIZE,\n });\n const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;\n\n // calculate value font size and height\n const availableWidth = width - containerPadding * 2;\n const availableHeight = height - seriesNameHeight;\n const valueFontSize = useOptimalFontSize({\n text: formattedValue,\n fontWeight: VALUE_FONT_WEIGHT,\n // without sparkline, use only 50% of the available width so it looks better for multiseries\n width: sparkline ? availableWidth : availableWidth * 0.5,\n // with sparkline, use only 25% of available height to leave room for chart\n // without sparkline, value should take up 90% of available space\n height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,\n lineHeight: LINE_HEIGHT,\n });\n const valueFontHeight = valueFontSize * LINE_HEIGHT;\n\n // make sure the series name font size is slightly smaller than value font size\n seriesNameFontSize = Math.min(valueFontSize * 0.7, seriesNameFontSize);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.seriesData === undefined) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline !== undefined) {\n const lineSeries = {\n type: 'line',\n name: series.name,\n data: series.values,\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n const mergedSeries = merge(lineSeries, sparkline);\n statSeries.push(mergedSeries);\n }\n\n const option = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n min: (value: { min: number; max: number }) => {\n if (value.min >= 0 && value.min <= 1) {\n // helps with PercentDecimal units, or datasets that return 0 or 1 booleans\n return 0;\n }\n return value.min;\n },\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline]);\n\n const textAlignment = sparkline ? 'auto' : 'center';\n const textStyles = {\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n };\n\n return (\n <Box sx={{ height: '100%', width: '100%', ...textStyles }}>\n {showSeriesName && (\n <SeriesName padding={containerPadding} fontSize={seriesNameFontSize}>\n {data.seriesData?.name}\n </SeriesName>\n )}\n <Value variant=\"h3\" color={color} fontSize={valueFontSize} padding={containerPadding}>\n {formattedValue}\n </Value>\n {sparkline !== undefined && (\n <EChart\n sx={{\n width: '100%',\n height: height - seriesNameHeight - valueFontHeight,\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n renderer=\"svg\"\n />\n )}\n </Box>\n );\n}\n\nconst SeriesName = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'padding' && prop !== 'fontSize',\n})<{ padding?: number; fontSize?: number; textAlignment?: string }>(({ theme, padding, fontSize }) => ({\n color: theme.palette.text.secondary,\n padding: `${padding}px`,\n fontSize: `${fontSize}px`,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n}));\n\nconst Value = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'color' && prop !== 'padding' && prop !== 'fontSize' && prop !== 'sparkline',\n})<{ color?: string; padding?: number; fontSize?: number; sparkline?: boolean }>(\n ({ theme, color, padding, fontSize, sparkline }) => ({\n color: color ?? theme.palette.text.primary,\n fontSize: `${fontSize}px`,\n padding: sparkline ? `${padding}px ${padding}px 0 ${padding}px` : ` 0 ${padding}px`,\n whiteSpace: 'nowrap',\n lineHeight: LINE_HEIGHT,\n })\n);\n"],"names":["useMemo","formatValue","Box","Typography","styled","merge","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","EChart","useOptimalFontSize","LINE_HEIGHT","SERIES_NAME_MAX_FONT_SIZE","SERIES_NAME_FONT_WEIGHT","VALUE_FONT_WEIGHT","StatChart","props","data","width","height","unit","color","sparkline","showSeriesName","chartsTheme","formattedValue","calculatedValue","containerPadding","container","padding","default","seriesNameFontSize","text","seriesData","name","fontWeight","lineHeight","maxSize","seriesNameHeight","availableWidth","availableHeight","valueFontSize","valueFontHeight","Math","min","option","undefined","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","value","tooltip","textAlignment","textStyles","display","flexDirection","justifyContent","alignItems","sx","SeriesName","fontSize","Value","variant","theme","echartsTheme","renderer","shouldForwardProp","prop","palette","secondary","overflow","textOverflow","whiteSpace","primary"],"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,SA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AO,CAACxD,IAAI,CAAC6D,OAAO;QAC1Cb,QAAQ,EAAE,CAAC,EAAEA,QAAQ,CAAC,EAAE,CAAC;QACzBnD,OAAO,EAAEP,SAAS,GAAG,CAAC,EAAEO,OAAO,CAAC,GAAG,EAAEA,OAAO,CAAC,KAAK,EAAEA,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,EAAEA,OAAO,CAAC,EAAE,CAAC;QACnF+D,UAAU,EAAE,QAAQ;QACpBxD,UAAU,EAAEzB,WAAW;KACxB,CAAA,AAAC,CACH,AAAC"}
@@ -0,0 +1,14 @@
1
+ interface CalculateFontSize {
2
+ text: string;
3
+ fontWeight: number;
4
+ width: number;
5
+ height: number;
6
+ lineHeight: number;
7
+ maxSize?: number;
8
+ }
9
+ /**
10
+ * Find the optimal font size given available space
11
+ */
12
+ export declare function useOptimalFontSize({ text, fontWeight, width, height, lineHeight, maxSize }: CalculateFontSize): number;
13
+ export {};
14
+ //# sourceMappingURL=calculateFontSize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculateFontSize.d.ts","sourceRoot":"","sources":["../../src/StatChart/calculateFontSize.ts"],"names":[],"mappings":"AAeA,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAcD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,iBAAiB,UAqB7G"}
@@ -0,0 +1,47 @@
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 { useChartsTheme } from '../context/ChartsThemeProvider';
14
+ let canvasContext;
15
+ function getGlobalCanvasContext() {
16
+ if (!canvasContext) {
17
+ canvasContext = document.createElement('canvas').getContext('2d');
18
+ if (canvasContext === null) {
19
+ throw new Error('Canvas context is null.');
20
+ }
21
+ }
22
+ return canvasContext;
23
+ }
24
+ /**
25
+ * Find the optimal font size given available space
26
+ */ export function useOptimalFontSize({ text , fontWeight , width , height , lineHeight , maxSize }) {
27
+ const ctx = getGlobalCanvasContext();
28
+ const chartsTheme = useChartsTheme();
29
+ const textStyle = chartsTheme.echartsTheme.textStyle;
30
+ var ref;
31
+ const fontSize = (ref = Number(textStyle === null || textStyle === void 0 ? void 0 : textStyle.fontSize)) !== null && ref !== void 0 ? ref : 12;
32
+ var ref1;
33
+ const fontFamily = (ref1 = textStyle === null || textStyle === void 0 ? void 0 : textStyle.fontFamily) !== null && ref1 !== void 0 ? ref1 : 'Lato';
34
+ // set the font on the canvas context
35
+ const fontStyle = `${fontWeight} ${fontSize}px ${fontFamily}`;
36
+ ctx.font = fontStyle;
37
+ // measure the width of the text with the given font style
38
+ const textMetrics = ctx.measureText(text);
39
+ // check how much bigger we can make the font while staying within the width and height
40
+ const fontSizeBasedOnWidth = width / textMetrics.width * fontSize;
41
+ const fontSizeBasedOnHeight = height / lineHeight;
42
+ // return the smaller font size
43
+ const finalFontSize = Math.min(fontSizeBasedOnHeight, fontSizeBasedOnWidth);
44
+ return maxSize ? Math.min(finalFontSize, maxSize) : finalFontSize;
45
+ }
46
+
47
+ //# sourceMappingURL=calculateFontSize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/StatChart/calculateFontSize.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 { useChartsTheme } from '../context/ChartsThemeProvider';\n\ninterface CalculateFontSize {\n text: string;\n fontWeight: number;\n width: number;\n height: number;\n lineHeight: number;\n maxSize?: number;\n}\n\nlet canvasContext: CanvasRenderingContext2D | null;\n\nfunction getGlobalCanvasContext() {\n if (!canvasContext) {\n canvasContext = document.createElement('canvas').getContext('2d');\n if (canvasContext === null) {\n throw new Error('Canvas context is null.');\n }\n }\n return canvasContext;\n}\n\n/**\n * Find the optimal font size given available space\n */\nexport function useOptimalFontSize({ text, fontWeight, width, height, lineHeight, maxSize }: CalculateFontSize) {\n const ctx = getGlobalCanvasContext();\n const chartsTheme = useChartsTheme();\n\n const textStyle = chartsTheme.echartsTheme.textStyle;\n const fontSize = Number(textStyle?.fontSize) ?? 12;\n const fontFamily = textStyle?.fontFamily ?? 'Lato';\n\n // set the font on the canvas context\n const fontStyle = `${fontWeight} ${fontSize}px ${fontFamily}`;\n ctx.font = fontStyle;\n // measure the width of the text with the given font style\n const textMetrics: TextMetrics = ctx.measureText(text);\n\n // check how much bigger we can make the font while staying within the width and height\n const fontSizeBasedOnWidth = (width / textMetrics.width) * fontSize;\n const fontSizeBasedOnHeight = height / lineHeight;\n\n // return the smaller font size\n const finalFontSize = Math.min(fontSizeBasedOnHeight, fontSizeBasedOnWidth);\n return maxSize ? Math.min(finalFontSize, maxSize) : finalFontSize;\n}\n"],"names":["useChartsTheme","canvasContext","getGlobalCanvasContext","document","createElement","getContext","Error","useOptimalFontSize","text","fontWeight","width","height","lineHeight","maxSize","ctx","chartsTheme","textStyle","echartsTheme","Number","fontSize","fontFamily","fontStyle","font","textMetrics","measureText","fontSizeBasedOnWidth","fontSizeBasedOnHeight","finalFontSize","Math","min"],"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,SAASA,cAAc,QAAQ,gCAAgC,CAAC;AAWhE,IAAIC,aAAa,AAAiC,AAAC;AAEnD,SAASC,sBAAsB,GAAG;IAChC,IAAI,CAACD,aAAa,EAAE;QAClBA,aAAa,GAAGE,QAAQ,CAACC,aAAa,CAAC,QAAQ,CAAC,CAACC,UAAU,CAAC,IAAI,CAAC,CAAC;QAClE,IAAIJ,aAAa,KAAK,IAAI,EAAE;YAC1B,MAAM,IAAIK,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IACD,OAAOL,aAAa,CAAC;AACvB,CAAC;AAED;;CAEC,GACD,OAAO,SAASM,kBAAkB,CAAC,EAAEC,IAAI,CAAA,EAAEC,UAAU,CAAA,EAAEC,KAAK,CAAA,EAAEC,MAAM,CAAA,EAAEC,UAAU,CAAA,EAAEC,OAAO,CAAA,EAAqB,EAAE;IAC9G,MAAMC,GAAG,GAAGZ,sBAAsB,EAAE,AAAC;IACrC,MAAMa,WAAW,GAAGf,cAAc,EAAE,AAAC;IAErC,MAAMgB,SAAS,GAAGD,WAAW,CAACE,YAAY,CAACD,SAAS,AAAC;QACpCE,GAA2B;IAA5C,MAAMC,QAAQ,GAAGD,CAAAA,GAA2B,GAA3BA,MAAM,CAACF,SAAS,aAATA,SAAS,WAAU,GAAnBA,KAAAA,CAAmB,GAAnBA,SAAS,CAAEG,QAAQ,CAAC,cAA3BD,GAA2B,cAA3BA,GAA2B,GAAI,EAAE,AAAC;QAChCF,IAAqB;IAAxC,MAAMI,UAAU,GAAGJ,CAAAA,IAAqB,GAArBA,SAAS,aAATA,SAAS,WAAY,GAArBA,KAAAA,CAAqB,GAArBA,SAAS,CAAEI,UAAU,cAArBJ,IAAqB,cAArBA,IAAqB,GAAI,MAAM,AAAC;IAEnD,qCAAqC;IACrC,MAAMK,SAAS,GAAG,CAAC,EAAEZ,UAAU,CAAC,CAAC,EAAEU,QAAQ,CAAC,GAAG,EAAEC,UAAU,CAAC,CAAC,AAAC;IAC9DN,GAAG,CAACQ,IAAI,GAAGD,SAAS,CAAC;IACrB,0DAA0D;IAC1D,MAAME,WAAW,GAAgBT,GAAG,CAACU,WAAW,CAAChB,IAAI,CAAC,AAAC;IAEvD,uFAAuF;IACvF,MAAMiB,oBAAoB,GAAG,AAACf,KAAK,GAAGa,WAAW,CAACb,KAAK,GAAIS,QAAQ,AAAC;IACpE,MAAMO,qBAAqB,GAAGf,MAAM,GAAGC,UAAU,AAAC;IAElD,+BAA+B;IAC/B,MAAMe,aAAa,GAAGC,IAAI,CAACC,GAAG,CAACH,qBAAqB,EAAED,oBAAoB,CAAC,AAAC;IAC5E,OAAOZ,OAAO,GAAGe,IAAI,CAACC,GAAG,CAACF,aAAa,EAAEd,OAAO,CAAC,GAAGc,aAAa,CAAC;AACpE,CAAC"}
@@ -17,20 +17,20 @@ const StyledMuiTable = styled(MuiTable)(({ theme })=>({
17
17
  // This value is needed to have a consistent table layout when scrolling.
18
18
  tableLayout: 'fixed',
19
19
  borderCollapse: 'separate',
20
- backgroundColor: theme.palette.background.paper
20
+ backgroundColor: theme.palette.background.default
21
21
  }));
22
22
  const TABLE_DENSITY_CONFIG = {
23
23
  compact: 'small',
24
24
  standard: 'medium'
25
25
  };
26
- export const InnerTable = /*#__PURE__*/ forwardRef(function InnerTable({ density , width , ...otherProps }, ref) {
26
+ export const InnerTable = /*#__PURE__*/ forwardRef(function InnerTable({ density , ...otherProps }, ref) {
27
27
  return /*#__PURE__*/ _jsx(StyledMuiTable, {
28
28
  ...otherProps,
29
29
  tabIndex: -1,
30
30
  size: TABLE_DENSITY_CONFIG[density],
31
31
  ref: ref,
32
32
  sx: {
33
- width: width
33
+ width: '100%'
34
34
  }
35
35
  });
36
36
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Table/InnerTable.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 { Table as MuiTable, styled, TableProps as MuiTableProps } from '@mui/material';\nimport { forwardRef } from 'react';\nimport { TableDensity } from './model/table-model';\n\nconst StyledMuiTable = styled(MuiTable)(({ theme }) => ({\n // This value is needed to have a consistent table layout when scrolling.\n tableLayout: 'fixed',\n borderCollapse: 'separate',\n backgroundColor: theme.palette.background.paper,\n}));\n\ntype InnerTableProps = Omit<MuiTableProps, 'size'> & {\n density: TableDensity;\n};\n\nconst TABLE_DENSITY_CONFIG: Record<TableDensity, MuiTableProps['size']> = {\n compact: 'small',\n standard: 'medium',\n};\n\nexport const InnerTable = forwardRef<HTMLTableElement, InnerTableProps>(function InnerTable(\n { density, width, ...otherProps },\n ref\n) {\n return (\n <StyledMuiTable\n {...otherProps}\n tabIndex={-1}\n size={TABLE_DENSITY_CONFIG[density]}\n ref={ref}\n sx={{\n width: width,\n }}\n />\n );\n});\n"],"names":["Table","MuiTable","styled","forwardRef","StyledMuiTable","theme","tableLayout","borderCollapse","backgroundColor","palette","background","paper","TABLE_DENSITY_CONFIG","compact","standard","InnerTable","density","width","otherProps","ref","tabIndex","size","sx"],"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,SAASA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,QAAqC,eAAe,CAAC;AACvF,SAASC,UAAU,QAAQ,OAAO,CAAC;AAGnC,MAAMC,cAAc,GAAGF,MAAM,CAACD,QAAQ,CAAC,CAAC,CAAC,EAAEI,KAAK,CAAA,EAAE,GAAM,CAAA;QACtD,yEAAyE;QACzEC,WAAW,EAAE,OAAO;QACpBC,cAAc,EAAE,UAAU;QAC1BC,eAAe,EAAEH,KAAK,CAACI,OAAO,CAACC,UAAU,CAACC,KAAK;KAChD,CAAA,AAAC,CAAC,AAAC;AAMJ,MAAMC,oBAAoB,GAAgD;IACxEC,OAAO,EAAE,OAAO;IAChBC,QAAQ,EAAE,QAAQ;CACnB,AAAC;AAEF,OAAO,MAAMC,UAAU,iBAAGZ,UAAU,CAAoC,SAASY,UAAU,CACzF,EAAEC,OAAO,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGC,UAAU,EAAE,EACjCC,GAAG,EACH;IACA,qBACE,KAACf,cAAc;QACZ,GAAGc,UAAU;QACdE,QAAQ,EAAE,CAAC,CAAC;QACZC,IAAI,EAAET,oBAAoB,CAACI,OAAO,CAAC;QACnCG,GAAG,EAAEA,GAAG;QACRG,EAAE,EAAE;YACFL,KAAK,EAAEA,KAAK;SACb;MACD,CACF;AACJ,CAAC,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../src/Table/InnerTable.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 { Table as MuiTable, styled, TableProps as MuiTableProps } from '@mui/material';\nimport { forwardRef } from 'react';\nimport { TableDensity } from './model/table-model';\n\nconst StyledMuiTable = styled(MuiTable)(({ theme }) => ({\n // This value is needed to have a consistent table layout when scrolling.\n tableLayout: 'fixed',\n borderCollapse: 'separate',\n backgroundColor: theme.palette.background.default,\n}));\n\ntype InnerTableProps = Omit<MuiTableProps, 'size'> & {\n density: TableDensity;\n};\n\nconst TABLE_DENSITY_CONFIG: Record<TableDensity, MuiTableProps['size']> = {\n compact: 'small',\n standard: 'medium',\n};\n\nexport const InnerTable = forwardRef<HTMLTableElement, InnerTableProps>(function InnerTable(\n { density, ...otherProps },\n ref\n) {\n return (\n <StyledMuiTable\n {...otherProps}\n tabIndex={-1}\n size={TABLE_DENSITY_CONFIG[density]}\n ref={ref}\n sx={{\n width: '100%',\n }}\n />\n );\n});\n"],"names":["Table","MuiTable","styled","forwardRef","StyledMuiTable","theme","tableLayout","borderCollapse","backgroundColor","palette","background","default","TABLE_DENSITY_CONFIG","compact","standard","InnerTable","density","otherProps","ref","tabIndex","size","sx","width"],"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,SAASA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,QAAqC,eAAe,CAAC;AACvF,SAASC,UAAU,QAAQ,OAAO,CAAC;AAGnC,MAAMC,cAAc,GAAGF,MAAM,CAACD,QAAQ,CAAC,CAAC,CAAC,EAAEI,KAAK,CAAA,EAAE,GAAM,CAAA;QACtD,yEAAyE;QACzEC,WAAW,EAAE,OAAO;QACpBC,cAAc,EAAE,UAAU;QAC1BC,eAAe,EAAEH,KAAK,CAACI,OAAO,CAACC,UAAU,CAACC,OAAO;KAClD,CAAA,AAAC,CAAC,AAAC;AAMJ,MAAMC,oBAAoB,GAAgD;IACxEC,OAAO,EAAE,OAAO;IAChBC,QAAQ,EAAE,QAAQ;CACnB,AAAC;AAEF,OAAO,MAAMC,UAAU,iBAAGZ,UAAU,CAAoC,SAASY,UAAU,CACzF,EAAEC,OAAO,CAAA,EAAE,GAAGC,UAAU,EAAE,EAC1BC,GAAG,EACH;IACA,qBACE,KAACd,cAAc;QACZ,GAAGa,UAAU;QACdE,QAAQ,EAAE,CAAC,CAAC;QACZC,IAAI,EAAER,oBAAoB,CAACI,OAAO,CAAC;QACnCE,GAAG,EAAEA,GAAG;QACRG,EAAE,EAAE;YACFC,KAAK,EAAE,MAAM;SACd;MACD,CACF;AACJ,CAAC,CAAC,CAAC"}
@@ -6,5 +6,5 @@ import { TableProps } from './model/table-model';
6
6
  *
7
7
  * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**
8
8
  */
9
- export declare function Table<TableData>({ data, columns, density, checkboxSelection, onRowSelectionChange, getCheckboxColor, getRowId, rowSelection, ...otherProps }: TableProps<TableData>): JSX.Element;
9
+ export declare function Table<TableData>({ data, columns, density, checkboxSelection, onRowSelectionChange, onSortingChange, getCheckboxColor, getRowId, rowSelection, sorting, rowSelectionVariant, ...otherProps }: TableProps<TableData>): JSX.Element;
10
10
  //# sourceMappingURL=Table.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../src/Table/Table.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,UAAU,EAAkC,MAAM,qBAAqB,CAAC;AAMjF;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,SAAS,EAAE,EAC/B,IAAI,EACJ,OAAO,EACP,OAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,QAA6B,EAC7B,YAAiB,EACjB,GAAG,UAAU,EACd,EAAE,UAAU,CAAC,SAAS,CAAC,eA+EvB"}
1
+ {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../src/Table/Table.tsx"],"names":[],"mappings":";AA4BA,OAAO,EAAE,UAAU,EAAkC,MAAM,qBAAqB,CAAC;AAYjF;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,SAAS,EAAE,EAC/B,IAAI,EACJ,OAAO,EACP,OAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,QAA6B,EAC7B,YAAoC,EACpC,OAAyB,EACzB,mBAAgC,EAChC,GAAG,UAAU,EACd,EAAE,UAAU,CAAC,SAAS,CAAC,eA+HvB"}
@@ -11,7 +11,7 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- import { useReactTable, getCoreRowModel } from '@tanstack/react-table';
14
+ import { useReactTable, getCoreRowModel, getSortedRowModel } from '@tanstack/react-table';
15
15
  import { useTheme } from '@mui/material';
16
16
  import { useCallback, useMemo } from 'react';
17
17
  import { VirtualizedTable } from './VirtualizedTable';
@@ -20,21 +20,58 @@ import { persesColumnsToTanstackColumns } from './model/table-model';
20
20
  const DEFAULT_GET_ROW_ID = (data, index)=>{
21
21
  return `${index}`;
22
22
  };
23
+ // Setting these defaults one enables them to be consistent across renders instead
24
+ // of being recreated every time, which can be important for perf because react
25
+ // does not do deep equality checking for objects and arrays.
26
+ const DEFAULT_ROW_SELECTION = {};
27
+ const DEFAULT_SORTING = [];
23
28
  /**
24
29
  * Component used to render tabular data in Perses use cases. This component is
25
30
  * **not** intended to be a general use data table for use cases unrelated to Perses.
26
31
  *
27
32
  * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**
28
- */ export function Table({ data , columns , density ='standard' , checkboxSelection , onRowSelectionChange , getCheckboxColor , getRowId =DEFAULT_GET_ROW_ID , rowSelection ={} , ...otherProps }) {
33
+ */ export function Table({ data , columns , density ='standard' , checkboxSelection , onRowSelectionChange , onSortingChange , getCheckboxColor , getRowId =DEFAULT_GET_ROW_ID , rowSelection =DEFAULT_ROW_SELECTION , sorting =DEFAULT_SORTING , rowSelectionVariant ='standard' , ...otherProps }) {
29
34
  const theme = useTheme();
30
35
  const handleRowSelectionChange = (rowSelectionUpdater)=>{
31
36
  const newRowSelection = typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;
32
37
  onRowSelectionChange === null || onRowSelectionChange === void 0 ? void 0 : onRowSelectionChange(newRowSelection);
33
38
  };
39
+ const handleRowSelectionEvent = useCallback((table, row, isModified)=>{
40
+ if (rowSelectionVariant === 'standard' || isModified) {
41
+ row.toggleSelected();
42
+ } else {
43
+ // Legend variant (when action not modified with shift/meta key).
44
+ // Note that this behavior needs to be kept in sync with behavior in
45
+ // the Legend component for list-based legends.
46
+ if (row.getIsSelected() && !table.getIsAllRowsSelected()) {
47
+ // Row was already selected. Revert to select all.
48
+ table.toggleAllRowsSelected();
49
+ } else {
50
+ // Focus the selected row.
51
+ onRowSelectionChange === null || onRowSelectionChange === void 0 ? void 0 : onRowSelectionChange({
52
+ [row.id]: true
53
+ });
54
+ }
55
+ }
56
+ }, [
57
+ onRowSelectionChange,
58
+ rowSelectionVariant
59
+ ]);
60
+ const handleCheckboxChange = useCallback((e, table, row)=>{
61
+ const nativePointerEvent = e.nativeEvent && (e.nativeEvent instanceof MouseEvent || e.nativeEvent instanceof KeyboardEvent) ? e.nativeEvent : undefined;
62
+ const isModifed = !!(nativePointerEvent === null || nativePointerEvent === void 0 ? void 0 : nativePointerEvent.metaKey) || !!(nativePointerEvent === null || nativePointerEvent === void 0 ? void 0 : nativePointerEvent.shiftKey);
63
+ handleRowSelectionEvent(table, row, isModifed);
64
+ }, [
65
+ handleRowSelectionEvent
66
+ ]);
67
+ const handleSortingChange = (sortingUpdater)=>{
68
+ const newSorting = typeof sortingUpdater === 'function' ? sortingUpdater(sorting) : sortingUpdater;
69
+ onSortingChange === null || onSortingChange === void 0 ? void 0 : onSortingChange(newSorting);
70
+ };
34
71
  const checkboxColumn = useMemo(()=>{
35
72
  return {
36
73
  id: 'checkboxRowSelect',
37
- size: 32,
74
+ size: 28,
38
75
  header: ({ table })=>{
39
76
  return /*#__PURE__*/ _jsx(TableCheckbox, {
40
77
  checked: table.getIsAllRowsSelected(),
@@ -44,22 +81,24 @@ const DEFAULT_GET_ROW_ID = (data, index)=>{
44
81
  density: density
45
82
  });
46
83
  },
47
- cell: ({ row })=>{
84
+ cell: ({ row , table })=>{
48
85
  return /*#__PURE__*/ _jsx(TableCheckbox, {
49
86
  checked: row.getIsSelected(),
50
87
  indeterminate: row.getIsSomeSelected(),
51
88
  onChange: (e)=>{
52
- row.getToggleSelectedHandler()(e);
89
+ handleCheckboxChange(e, table, row);
53
90
  },
54
91
  color: getCheckboxColor === null || getCheckboxColor === void 0 ? void 0 : getCheckboxColor(row.original),
55
92
  density: density
56
93
  });
57
- }
94
+ },
95
+ enableSorting: false
58
96
  };
59
97
  }, [
98
+ theme.palette.text.primary,
60
99
  density,
61
100
  getCheckboxColor,
62
- theme.palette.text.primary
101
+ handleCheckboxChange
63
102
  ]);
64
103
  const tableColumns = useMemo(()=>{
65
104
  const initTableColumns = persesColumnsToTanstackColumns(columns);
@@ -77,15 +116,24 @@ const DEFAULT_GET_ROW_ID = (data, index)=>{
77
116
  columns: tableColumns,
78
117
  getRowId,
79
118
  getCoreRowModel: getCoreRowModel(),
119
+ getSortedRowModel: getSortedRowModel(),
80
120
  enableRowSelection: !!checkboxSelection,
81
121
  onRowSelectionChange: handleRowSelectionChange,
122
+ onSortingChange: handleSortingChange,
123
+ // For now, defaulting to sort by descending first. We can expose the ability
124
+ // to customize it if/when we have use cases for it.
125
+ sortDescFirst: true,
82
126
  state: {
83
- rowSelection
127
+ rowSelection,
128
+ sorting
84
129
  }
85
130
  });
86
- const handleRowClick = useCallback((rowId)=>{
87
- table.getRow(rowId).toggleSelected();
131
+ const handleRowClick = useCallback((e, rowId)=>{
132
+ const row = table.getRow(rowId);
133
+ const isModifiedClick = e.metaKey || e.shiftKey;
134
+ handleRowSelectionEvent(table, row, isModifiedClick);
88
135
  }, [
136
+ handleRowSelectionEvent,
89
137
  table
90
138
  ]);
91
139
  return /*#__PURE__*/ _jsx(VirtualizedTable, {