@perses-dev/components 0.33.0 → 0.35.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 (146) hide show
  1. package/dist/ContentWithLegend/ContentWithLegend.js +1 -1
  2. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
  3. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +3 -3
  4. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
  5. package/dist/ContentWithLegend/model/content-with-legend-model.js +12 -3
  6. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
  7. package/dist/Drawer/Drawer.js +1 -1
  8. package/dist/Drawer/Drawer.js.map +1 -1
  9. package/dist/EChart/EChart.d.ts +2 -1
  10. package/dist/EChart/EChart.d.ts.map +1 -1
  11. package/dist/EChart/EChart.js +15 -3
  12. package/dist/EChart/EChart.js.map +1 -1
  13. package/dist/GaugeChart/GaugeChart.d.ts +1 -1
  14. package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
  15. package/dist/GaugeChart/GaugeChart.js +6 -3
  16. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  17. package/dist/Legend/CompactLegend.d.ts +1 -1
  18. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  19. package/dist/Legend/CompactLegend.js +1 -1
  20. package/dist/Legend/CompactLegend.js.map +1 -1
  21. package/dist/Legend/Legend.d.ts +8 -3
  22. package/dist/Legend/Legend.d.ts.map +1 -1
  23. package/dist/Legend/Legend.js +4 -3
  24. package/dist/Legend/Legend.js.map +1 -1
  25. package/dist/Legend/ListLegend.d.ts +1 -1
  26. package/dist/Legend/ListLegend.d.ts.map +1 -1
  27. package/dist/Legend/ListLegend.js +1 -1
  28. package/dist/Legend/ListLegend.js.map +1 -1
  29. package/dist/Legend/ListLegendItem.d.ts +1 -1
  30. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  31. package/dist/Legend/ListLegendItem.js.map +1 -1
  32. package/dist/Legend/TableLegend.d.ts +3 -2
  33. package/dist/Legend/TableLegend.d.ts.map +1 -1
  34. package/dist/Legend/TableLegend.js +10 -2
  35. package/dist/Legend/TableLegend.js.map +1 -1
  36. package/dist/Legend/index.d.ts +1 -0
  37. package/dist/Legend/index.d.ts.map +1 -1
  38. package/dist/Legend/index.js +1 -0
  39. package/dist/Legend/index.js.map +1 -1
  40. package/dist/Legend/legend-model.d.ts +24 -0
  41. package/dist/Legend/legend-model.d.ts.map +1 -0
  42. package/dist/Legend/legend-model.js +19 -0
  43. package/dist/Legend/legend-model.js.map +1 -0
  44. package/dist/LineChart/LineChart.d.ts +2 -1
  45. package/dist/LineChart/LineChart.d.ts.map +1 -1
  46. package/dist/LineChart/LineChart.js +3 -2
  47. package/dist/LineChart/LineChart.js.map +1 -1
  48. package/dist/LineChart/utils.js +1 -1
  49. package/dist/LineChart/utils.js.map +1 -1
  50. package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  51. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  52. package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts +36 -0
  53. package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts.map +1 -0
  54. package/dist/SettingsAutocomplete/SettingsAutocomplete.js +65 -0
  55. package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -0
  56. package/dist/SettingsAutocomplete/index.d.ts +2 -0
  57. package/dist/SettingsAutocomplete/index.d.ts.map +1 -0
  58. package/dist/{LegendOptionsEditor → SettingsAutocomplete}/index.js +1 -1
  59. package/dist/SettingsAutocomplete/index.js.map +1 -0
  60. package/dist/StatChart/StatChart.d.ts +2 -1
  61. package/dist/StatChart/StatChart.d.ts.map +1 -1
  62. package/dist/StatChart/StatChart.js +74 -21
  63. package/dist/StatChart/StatChart.js.map +1 -1
  64. package/dist/StatChart/calculateFontSize.d.ts +14 -0
  65. package/dist/StatChart/calculateFontSize.d.ts.map +1 -0
  66. package/dist/StatChart/calculateFontSize.js +47 -0
  67. package/dist/StatChart/calculateFontSize.js.map +1 -0
  68. package/dist/Table/Table.js +1 -1
  69. package/dist/Table/Table.js.map +1 -1
  70. package/dist/Table/TableCell.d.ts +6 -3
  71. package/dist/Table/TableCell.d.ts.map +1 -1
  72. package/dist/Table/TableCell.js +5 -2
  73. package/dist/Table/TableCell.js.map +1 -1
  74. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  75. package/dist/Table/VirtualizedTable.js +11 -5
  76. package/dist/Table/VirtualizedTable.js.map +1 -1
  77. package/dist/Table/model/table-model.d.ts +16 -2
  78. package/dist/Table/model/table-model.d.ts.map +1 -1
  79. package/dist/Table/model/table-model.js +18 -7
  80. package/dist/Table/model/table-model.js.map +1 -1
  81. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  82. package/dist/TimeSeriesTooltip/nearby-series.js +4 -2
  83. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  84. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  85. package/dist/UnitSelector/UnitSelector.js +10 -22
  86. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  87. package/dist/YAxisLabel.js +1 -1
  88. package/dist/YAxisLabel.js.map +1 -1
  89. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +1 -1
  90. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +13 -4
  91. package/dist/cjs/Drawer/Drawer.js +1 -1
  92. package/dist/cjs/EChart/EChart.js +22 -5
  93. package/dist/cjs/GaugeChart/GaugeChart.js +6 -3
  94. package/dist/cjs/Legend/CompactLegend.js +2 -2
  95. package/dist/cjs/Legend/Legend.js +5 -4
  96. package/dist/cjs/Legend/ListLegend.js +2 -2
  97. package/dist/cjs/Legend/TableLegend.js +10 -2
  98. package/dist/cjs/Legend/index.js +1 -0
  99. package/dist/cjs/Legend/legend-model.js +25 -0
  100. package/dist/cjs/LineChart/LineChart.js +3 -2
  101. package/dist/cjs/LineChart/utils.js +7 -2
  102. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  103. package/dist/cjs/SettingsAutocomplete/SettingsAutocomplete.js +66 -0
  104. package/dist/cjs/{LegendOptionsEditor → SettingsAutocomplete}/index.js +1 -1
  105. package/dist/cjs/StatChart/StatChart.js +79 -21
  106. package/dist/cjs/StatChart/calculateFontSize.js +51 -0
  107. package/dist/cjs/Table/Table.js +1 -1
  108. package/dist/cjs/Table/TableCell.js +5 -2
  109. package/dist/cjs/Table/VirtualizedTable.js +11 -5
  110. package/dist/cjs/Table/model/table-model.js +18 -7
  111. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +4 -2
  112. package/dist/cjs/UnitSelector/UnitSelector.js +9 -21
  113. package/dist/cjs/YAxisLabel.js +1 -1
  114. package/dist/cjs/index.js +1 -1
  115. package/dist/cjs/model/index.js +0 -1
  116. package/dist/cjs/utils/theme-gen.js +7 -2
  117. package/dist/index.d.ts +1 -1
  118. package/dist/index.d.ts.map +1 -1
  119. package/dist/index.js +1 -1
  120. package/dist/index.js.map +1 -1
  121. package/dist/model/graph.d.ts +1 -1
  122. package/dist/model/graph.d.ts.map +1 -1
  123. package/dist/model/graph.js.map +1 -1
  124. package/dist/model/index.d.ts +0 -1
  125. package/dist/model/index.d.ts.map +1 -1
  126. package/dist/model/index.js +0 -1
  127. package/dist/model/index.js.map +1 -1
  128. package/dist/model/theme.d.ts +3 -2
  129. package/dist/model/theme.d.ts.map +1 -1
  130. package/dist/model/theme.js.map +1 -1
  131. package/dist/utils/theme-gen.js +1 -1
  132. package/dist/utils/theme-gen.js.map +1 -1
  133. package/package.json +4 -4
  134. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts +0 -8
  135. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +0 -1
  136. package/dist/LegendOptionsEditor/LegendOptionsEditor.js +0 -109
  137. package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +0 -1
  138. package/dist/LegendOptionsEditor/index.d.ts +0 -2
  139. package/dist/LegendOptionsEditor/index.d.ts.map +0 -1
  140. package/dist/LegendOptionsEditor/index.js.map +0 -1
  141. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +0 -115
  142. package/dist/cjs/model/legend.js +0 -102
  143. package/dist/model/legend.d.ts +0 -36
  144. package/dist/model/legend.d.ts.map +0 -1
  145. package/dist/model/legend.js +0 -81
  146. package/dist/model/legend.js.map +0 -1
@@ -22,7 +22,13 @@ const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
23
23
  const _core = require("echarts/core");
24
24
  const _material = require("@mui/material");
25
- const _lodashEs = require("lodash-es");
25
+ const _isEqual = /*#__PURE__*/ _interopRequireDefault(require("lodash/isEqual"));
26
+ const _debounce = /*#__PURE__*/ _interopRequireDefault(require("lodash/debounce"));
27
+ function _interopRequireDefault(obj) {
28
+ return obj && obj.__esModule ? obj : {
29
+ default: obj
30
+ };
31
+ }
26
32
  function _getRequireWildcardCache(nodeInterop) {
27
33
  if (typeof WeakMap !== "function") return null;
28
34
  var cacheBabelInterop = new WeakMap();
@@ -78,7 +84,7 @@ const batchEvents = [
78
84
  'downplay',
79
85
  'highlight'
80
86
  ];
81
- const EChart = /*#__PURE__*/ _react.default.memo(function EChart({ option , theme , renderer , sx , onEvents , _instance , onChartInitialized }) {
87
+ const EChart = /*#__PURE__*/ _react.default.memo(function EChart({ option , theme , renderer , sx , onEvents , _instance , syncGroup , onChartInitialized }) {
82
88
  const initialOption = (0, _react.useRef)(option);
83
89
  const prevOption = (0, _react.useRef)(option);
84
90
  const containerRef = (0, _react.useRef)(null);
@@ -106,9 +112,20 @@ const EChart = /*#__PURE__*/ _react.default.memo(function EChart({ option , them
106
112
  theme,
107
113
  renderer
108
114
  ]);
115
+ // When syncGroup is explicitly set, charts within same group share interactions such as crosshair
116
+ (0, _react.useEffect)(()=>{
117
+ if (!chartElement.current || !syncGroup) return;
118
+ chartElement.current.group = syncGroup;
119
+ (0, _core.connect)([
120
+ chartElement.current
121
+ ]); // more info: https://echarts.apache.org/en/api.html#echarts.connect
122
+ }, [
123
+ syncGroup,
124
+ chartElement
125
+ ]);
109
126
  // Update chart data when option changes
110
127
  (0, _react.useEffect)(()=>{
111
- if (prevOption.current === undefined || (0, _lodashEs.isEqual)(prevOption.current, option)) return;
128
+ if (prevOption.current === undefined || (0, _isEqual.default)(prevOption.current, option)) return;
112
129
  if (!chartElement.current) return;
113
130
  chartElement.current.setOption(option, true);
114
131
  prevOption.current = option;
@@ -117,7 +134,7 @@ const EChart = /*#__PURE__*/ _react.default.memo(function EChart({ option , them
117
134
  ]);
118
135
  // Resize chart, cleanup listener on unmount
119
136
  (0, _react.useLayoutEffect)(()=>{
120
- const updateSize = (0, _lodashEs.debounce)(()=>{
137
+ const updateSize = (0, _debounce.default)(()=>{
121
138
  if (!chartElement.current) return;
122
139
  chartElement.current.resize();
123
140
  }, 200);
@@ -149,7 +166,7 @@ const EChart = /*#__PURE__*/ _react.default.memo(function EChart({ option , them
149
166
  (0, _react.useEffect)(()=>{
150
167
  // TODO: fix this debouncing. This likely isn't working as intended because
151
168
  // the debounced function is re-created every time this useEffect is called.
152
- const updateSize = (0, _lodashEs.debounce)(()=>{
169
+ const updateSize = (0, _debounce.default)(()=>{
153
170
  if (!chartElement.current) return;
154
171
  chartElement.current.resize();
155
172
  }, 200, {
@@ -49,7 +49,7 @@ function GaugeChart(props) {
49
49
  // useDeepMemo ensures value size util does not rerun everytime you hover on the chart
50
50
  const option = (0, _core.useDeepMemo)(()=>{
51
51
  var ref;
52
- if (data.value === undefined || data.value === null) return chartsTheme.noDataOption;
52
+ if (data.value === undefined) return chartsTheme.noDataOption;
53
53
  // adjusts fontSize depending on number of characters
54
54
  const valueSizeClamp = getResponsiveValueSize(data.value, unit, width, height);
55
55
  var ref1;
@@ -167,7 +167,10 @@ function GaugeChart(props) {
167
167
  ],
168
168
  color: 'inherit',
169
169
  fontSize: valueSizeClamp,
170
- formatter: (value)=>{
170
+ formatter: data.value === null ? // at this level because the `formatter` function argument is `NaN`
171
+ // when the value is `null`, making it difficult to differentiate
172
+ // `null` from a true `NaN` case.
173
+ ()=>'null' : (value)=>{
171
174
  return (0, _units.formatValue)(value, unit);
172
175
  }
173
176
  },
@@ -216,7 +219,7 @@ function getResponsiveValueSize(value, unit, width, height) {
216
219
  const MIN_SIZE = 3;
217
220
  const MAX_SIZE = 24;
218
221
  const SIZE_MULTIPLIER = 0.7;
219
- const formattedValue = (0, _units.formatValue)(value, unit);
222
+ const formattedValue = typeof value === 'number' ? (0, _units.formatValue)(value, unit) : `${value}`;
220
223
  var _length;
221
224
  const valueCharacters = (_length = formattedValue.length) !== null && _length !== void 0 ? _length : 2;
222
225
  const valueSize = Math.min(width, height) / valueCharacters * SIZE_MULTIPLIER;
@@ -20,8 +20,8 @@ Object.defineProperty(exports, "CompactLegend", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
- const _model = require("../model");
24
23
  const _listLegendItem = require("./ListLegendItem");
24
+ const _legendModel = require("./legend-model");
25
25
  function CompactLegend({ height , items , selectedItems , onLegendItemClick }) {
26
26
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
27
27
  component: "ul",
@@ -39,7 +39,7 @@ function CompactLegend({ height , items , selectedItems , onLegendItemClick })
39
39
  },
40
40
  children: items.map((item)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegendItem.ListLegendItem, {
41
41
  item: item,
42
- isVisuallySelected: (0, _model.isLegendItemVisuallySelected)(item, selectedItems),
42
+ isVisuallySelected: (0, _legendModel.isLegendItemVisuallySelected)(item, selectedItems),
43
43
  onClick: onLegendItemClick,
44
44
  sx: {
45
45
  width: 'auto',
@@ -21,7 +21,7 @@ Object.defineProperty(exports, "Legend", {
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
23
  const _immer = require("immer");
24
- const _model = require("../model");
24
+ const _core = require("@perses-dev/core");
25
25
  const _listLegend = require("./ListLegend");
26
26
  const _compactLegend = require("./CompactLegend");
27
27
  const _tableLegend = require("./TableLegend");
@@ -31,7 +31,7 @@ const _tableLegend = require("./TableLegend");
31
31
  // Set this number based on testing, but it may need to be tuned a bit on the
32
32
  // future as people test this out on different machines.
33
33
  const NEED_VIRTUALIZATION_LIMIT = 500;
34
- function Legend({ width , height , options , data , selectedItems , onSelectedItemsChange }) {
34
+ function Legend({ width , height , options , data , selectedItems , onSelectedItemsChange , tableProps }) {
35
35
  const onLegendItemClick = (e, seriesId)=>{
36
36
  const isModifiedClick = e.metaKey || e.shiftKey;
37
37
  const newSelected = (0, _immer.produce)(selectedItems, (draft)=>{
@@ -64,7 +64,7 @@ function Legend({ width , height , options , data , selectedItems , onSelectedIt
64
64
  });
65
65
  onSelectedItemsChange(newSelected);
66
66
  };
67
- const mode = (0, _model.getLegendMode)(options.mode);
67
+ const mode = (0, _core.getLegendMode)(options.mode);
68
68
  // The bottom legend is displayed as a list when the number of items is too
69
69
  // large and requires virtualization. Otherwise, it is rendered more compactly.
70
70
  // We do not need this check for the right-side legend because it is always
@@ -81,7 +81,8 @@ function Legend({ width , height , options , data , selectedItems , onSelectedIt
81
81
  legendContent = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableLegend.TableLegend, {
82
82
  ...commonLegendProps,
83
83
  onSelectedItemsChange: onSelectedItemsChange,
84
- width: width
84
+ width: width,
85
+ ...tableProps
85
86
  });
86
87
  } else if (options.position === 'Right' || needsVirtualization) {
87
88
  legendContent = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegend.ListLegend, {
@@ -20,8 +20,8 @@ Object.defineProperty(exports, "ListLegend", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _reactVirtuoso = require("react-virtuoso");
23
- const _model = require("../model");
24
23
  const _listLegendItem = require("./ListLegendItem");
24
+ const _legendModel = require("./legend-model");
25
25
  function ListLegend({ items , height , width , selectedItems , onLegendItemClick }) {
26
26
  // show full labels on hover when there are many total series
27
27
  const truncateLabels = items.length > 5;
@@ -35,7 +35,7 @@ function ListLegend({ items , height , width , selectedItems , onLegendItemClick
35
35
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegendItem.ListLegendItem, {
36
36
  item: item,
37
37
  truncateLabel: truncateLabels,
38
- isVisuallySelected: (0, _model.isLegendItemVisuallySelected)(item, selectedItems),
38
+ isVisuallySelected: (0, _legendModel.isLegendItemVisuallySelected)(item, selectedItems),
39
39
  onClick: onLegendItemClick,
40
40
  sx: {
41
41
  // Having an explicit width is important for the ellipsizing to
@@ -40,7 +40,7 @@ const getRowId = (data)=>{
40
40
  const getCheckboxColor = (data)=>{
41
41
  return data.color;
42
42
  };
43
- function TableLegend({ items , selectedItems: initRowSelection , onSelectedItemsChange , height , width }) {
43
+ function TableLegend({ items , selectedItems: initRowSelection , onSelectedItemsChange , height , width , columns: additionalColumns = [] }) {
44
44
  const rowSelection = (0, _react.useMemo)(()=>{
45
45
  return typeof initRowSelection !== 'string' ? initRowSelection : // items for checkboxes.
46
46
  // TODO: clean this up if we switch to also using checkboxes in list legend.
@@ -52,13 +52,21 @@ function TableLegend({ items , selectedItems: initRowSelection , onSelectedItems
52
52
  initRowSelection,
53
53
  items
54
54
  ]);
55
+ const columns = (0, _react.useMemo)(()=>{
56
+ return [
57
+ ...COLUMNS,
58
+ ...additionalColumns
59
+ ];
60
+ }, [
61
+ additionalColumns
62
+ ]);
55
63
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_table.Table, {
56
64
  height: height,
57
65
  width: width,
58
66
  rowSelection: rowSelection,
59
67
  onRowSelectionChange: onSelectedItemsChange,
60
68
  data: items,
61
- columns: COLUMNS,
69
+ columns: columns,
62
70
  density: "compact",
63
71
  getRowId: getRowId,
64
72
  getCheckboxColor: getCheckboxColor,
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _exportStar(require("./Legend"), exports);
18
+ _exportStar(require("./legend-model"), exports);
18
19
  function _exportStar(from, to) {
19
20
  Object.keys(from).forEach(function(k) {
20
21
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -0,0 +1,25 @@
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, "isLegendItemVisuallySelected", {
18
+ enumerable: true,
19
+ get: ()=>isLegendItemVisuallySelected
20
+ });
21
+ function isLegendItemVisuallySelected(item, selectedItems) {
22
+ // In the "ALL" case, technically all legend items are selected, but we do
23
+ // not render them differently.
24
+ return selectedItems !== 'ALL' && !!selectedItems[item.id];
25
+ }
@@ -84,7 +84,7 @@ function _interopRequireWildcard(obj, nodeInterop) {
84
84
  ]);
85
85
  function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfig ={
86
86
  wrapLabels: true
87
- } , noDataVariant ='message' , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
87
+ } , noDataVariant ='message' , syncGroup , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
88
88
  var ref;
89
89
  const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
90
90
  const chartRef = (0, _react.useRef)();
@@ -284,7 +284,8 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
284
284
  option: option,
285
285
  theme: chartsTheme.echartsTheme,
286
286
  onEvents: handleEvents,
287
- _instance: chartRef
287
+ _instance: chartRef,
288
+ syncGroup: syncGroup
288
289
  })
289
290
  ]
290
291
  });
@@ -27,9 +27,14 @@ _export(exports, {
27
27
  getFormattedDate: ()=>getFormattedDate,
28
28
  getYAxes: ()=>getYAxes
29
29
  });
30
- const _lodashEs = require("lodash-es");
30
+ const _merge = /*#__PURE__*/ _interopRequireDefault(require("lodash/merge"));
31
31
  const _model = require("../model");
32
32
  const _utils = require("../utils");
33
+ function _interopRequireDefault(obj) {
34
+ return obj && obj.__esModule ? obj : {
35
+ default: obj
36
+ };
37
+ }
33
38
  function enableDataZoom(chart) {
34
39
  const chartModel = chart['_model'];
35
40
  if (chartModel === undefined) return;
@@ -90,6 +95,6 @@ function getYAxes(yAxis, unit) {
90
95
  }
91
96
  };
92
97
  return [
93
- (0, _lodashEs.merge)(Y_AXIS_DEFAULT, yAxis)
98
+ (0, _merge.default)(Y_AXIS_DEFAULT, yAxis)
94
99
  ];
95
100
  }
@@ -76,7 +76,7 @@ const OptionsEditorControl = ({ label , control , description })=>{
76
76
  }),
77
77
  /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
78
78
  sx: {
79
- width: '150px',
79
+ width: '180px',
80
80
  textAlign: 'right'
81
81
  },
82
82
  children: [
@@ -0,0 +1,66 @@
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, "SettingsAutocomplete", {
18
+ enumerable: true,
19
+ get: ()=>SettingsAutocomplete
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ function SettingsAutocomplete({ options , renderInput =(params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
24
+ ...params
25
+ }) , ...otherProps }) {
26
+ const getOptionLabel = (option)=>{
27
+ var _label;
28
+ return (_label = option.label) !== null && _label !== void 0 ? _label : option.id;
29
+ };
30
+ // Note: this component currently is not virtualized because it is specific
31
+ // to being used for settings, which generally have a pretty small list of
32
+ // options. If this changes to include values with many options, virtualization
33
+ // should be added using react-virtuoso.
34
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
35
+ isOptionEqualToValue: (option, value)=>option.id === value.id,
36
+ getOptionDisabled: (option)=>!!option.disabled,
37
+ getOptionLabel: getOptionLabel,
38
+ options: options,
39
+ renderInput: renderInput,
40
+ renderOption: (props, option)=>{
41
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)("li", {
42
+ ...props,
43
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
44
+ children: [
45
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
46
+ variant: "body1",
47
+ component: "div",
48
+ children: getOptionLabel(option)
49
+ }),
50
+ option.description && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
51
+ variant: "body2",
52
+ component: "div",
53
+ color: (theme)=>theme.palette.text.secondary,
54
+ children: option.description
55
+ })
56
+ ]
57
+ })
58
+ });
59
+ },
60
+ filterOptions: (0, _material.createFilterOptions)({
61
+ // Include the label and the description in search.
62
+ stringify: (option)=>`${getOptionLabel(option)} ${option.description || ''}`
63
+ }),
64
+ ...otherProps
65
+ });
66
+ }
@@ -14,7 +14,7 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- _exportStar(require("./LegendOptionsEditor"), exports);
17
+ _exportStar(require("./SettingsAutocomplete"), exports);
18
18
  function _exportStar(from, to) {
19
19
  Object.keys(from).forEach(function(k) {
20
20
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -21,7 +21,7 @@ Object.defineProperty(exports, "StatChart", {
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _react = require("react");
23
23
  const _material = require("@mui/material");
24
- const _lodashEs = require("lodash-es");
24
+ const _merge = /*#__PURE__*/ _interopRequireDefault(require("lodash/merge"));
25
25
  const _core = require("echarts/core");
26
26
  const _charts = require("echarts/charts");
27
27
  const _components = require("echarts/components");
@@ -29,6 +29,12 @@ const _renderers = require("echarts/renderers");
29
29
  const _chartsThemeProvider = require("../context/ChartsThemeProvider");
30
30
  const _units = require("../model/units");
31
31
  const _echart = require("../EChart");
32
+ const _calculateFontSize = require("./calculateFontSize");
33
+ function _interopRequireDefault(obj) {
34
+ return obj && obj.__esModule ? obj : {
35
+ default: obj
36
+ };
37
+ }
32
38
  (0, _core.use)([
33
39
  _charts.LineChart,
34
40
  _components.GridComponent,
@@ -37,12 +43,48 @@ const _echart = require("../EChart");
37
43
  _components.TooltipComponent,
38
44
  _renderers.CanvasRenderer
39
45
  ]);
40
- const MIN_VALUE_SIZE = 12;
41
- const MAX_VALUE_SIZE = 36;
46
+ const LINE_HEIGHT = 1.2;
47
+ const SERIES_NAME_MAX_FONT_SIZE = 30;
48
+ const SERIES_NAME_FONT_WEIGHT = 400;
49
+ const VALUE_FONT_WEIGHT = 700;
42
50
  function StatChart(props) {
43
- const { width , height , data , unit , color , sparkline } = props;
51
+ var ref, ref1;
52
+ const { width , height , data , unit , color , sparkline , showSeriesName } = props;
44
53
  const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
45
- const formattedValue = data.calculatedValue === undefined ? '' : (0, _units.formatValue)(data.calculatedValue, unit);
54
+ let formattedValue = '';
55
+ if (data.calculatedValue === null) {
56
+ formattedValue = 'null';
57
+ } else if (typeof data.calculatedValue === 'number') {
58
+ formattedValue = (0, _units.formatValue)(data.calculatedValue, unit);
59
+ }
60
+ const containerPadding = chartsTheme.container.padding.default;
61
+ var ref2;
62
+ // calculate series name font size and height
63
+ let seriesNameFontSize = (0, _calculateFontSize.useOptimalFontSize)({
64
+ 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 : '',
65
+ fontWeight: SERIES_NAME_FONT_WEIGHT,
66
+ width,
67
+ height: height * 0.125,
68
+ lineHeight: LINE_HEIGHT,
69
+ maxSize: SERIES_NAME_MAX_FONT_SIZE
70
+ });
71
+ const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;
72
+ // calculate value font size and height
73
+ const availableWidth = width - containerPadding * 2;
74
+ const availableHeight = height - seriesNameHeight;
75
+ const valueFontSize = (0, _calculateFontSize.useOptimalFontSize)({
76
+ text: formattedValue,
77
+ fontWeight: VALUE_FONT_WEIGHT,
78
+ // without sparkline, use only 50% of the available width so it looks better for multiseries
79
+ width: sparkline ? availableWidth : availableWidth * 0.5,
80
+ // with sparkline, use only 25% of available height to leave room for chart
81
+ // without sparkline, value should take up 90% of available space
82
+ height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,
83
+ lineHeight: LINE_HEIGHT
84
+ });
85
+ const valueFontHeight = valueFontSize * LINE_HEIGHT;
86
+ // make sure the series name font size is slightly smaller than value font size
87
+ seriesNameFontSize = Math.min(valueFontSize * 0.7, seriesNameFontSize);
46
88
  const option = (0, _react.useMemo)(()=>{
47
89
  if (data.seriesData === undefined) return chartsTheme.noDataOption;
48
90
  const series = data.seriesData;
@@ -50,15 +92,14 @@ function StatChart(props) {
50
92
  if (sparkline !== undefined) {
51
93
  const lineSeries = {
52
94
  type: 'line',
53
- data: [
54
- ...series.values
55
- ],
95
+ name: series.name,
96
+ data: series.values,
56
97
  zlevel: 1,
57
98
  symbol: 'none',
58
99
  animation: false,
59
100
  silent: true
60
101
  };
61
- const mergedSeries = (0, _lodashEs.merge)(lineSeries, sparkline);
102
+ const mergedSeries = (0, _merge.default)(lineSeries, sparkline);
62
103
  statSeries.push(mergedSeries);
63
104
  }
64
105
  const option = {
@@ -100,11 +141,6 @@ function StatChart(props) {
100
141
  chartsTheme,
101
142
  sparkline
102
143
  ]);
103
- const isLargePanel = width > 250 && height > 180;
104
- // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute
105
- const charactersAdjust = formattedValue.length;
106
- const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
107
- const containerPadding = `${chartsTheme.container.padding.default}px`;
108
144
  const textAlignment = sparkline ? 'auto' : 'center';
109
145
  const textStyles = {
110
146
  display: 'flex',
@@ -119,19 +155,22 @@ function StatChart(props) {
119
155
  ...textStyles
120
156
  },
121
157
  children: [
122
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
158
+ showSeriesName && /*#__PURE__*/ (0, _jsxRuntime.jsx)(SeriesName, {
159
+ padding: containerPadding,
160
+ fontSize: seriesNameFontSize,
161
+ children: (ref1 = data.seriesData) === null || ref1 === void 0 ? void 0 : ref1.name
162
+ }),
163
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(Value, {
123
164
  variant: "h3",
124
- sx: (theme)=>({
125
- color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
126
- fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
127
- padding: sparkline ? `${containerPadding} ${containerPadding} 0 ${containerPadding}` : ` 0 ${containerPadding}`
128
- }),
165
+ color: color,
166
+ fontSize: valueFontSize,
167
+ padding: containerPadding,
129
168
  children: formattedValue
130
169
  }),
131
170
  sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
132
171
  sx: {
133
172
  width: '100%',
134
- height: '100%'
173
+ height: height - seriesNameHeight - valueFontHeight
135
174
  },
136
175
  option: option,
137
176
  theme: chartsTheme.echartsTheme,
@@ -140,3 +179,22 @@ function StatChart(props) {
140
179
  ]
141
180
  });
142
181
  }
182
+ const SeriesName = (0, _material.styled)(_material.Typography, {
183
+ shouldForwardProp: (prop)=>prop !== 'padding' && prop !== 'fontSize'
184
+ })(({ theme , padding , fontSize })=>({
185
+ color: theme.palette.text.secondary,
186
+ padding: `${padding}px`,
187
+ fontSize: `${fontSize}px`,
188
+ overflow: 'hidden',
189
+ textOverflow: 'ellipsis',
190
+ whiteSpace: 'nowrap'
191
+ }));
192
+ const Value = (0, _material.styled)(_material.Typography, {
193
+ shouldForwardProp: (prop)=>prop !== 'color' && prop !== 'padding' && prop !== 'fontSize' && prop !== 'sparkline'
194
+ })(({ theme , color , padding , fontSize , sparkline })=>({
195
+ color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
196
+ fontSize: `${fontSize}px`,
197
+ padding: sparkline ? `${padding}px ${padding}px 0 ${padding}px` : ` 0 ${padding}px`,
198
+ whiteSpace: 'nowrap',
199
+ lineHeight: LINE_HEIGHT
200
+ }));
@@ -0,0 +1,51 @@
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, "useOptimalFontSize", {
18
+ enumerable: true,
19
+ get: ()=>useOptimalFontSize
20
+ });
21
+ const _chartsThemeProvider = require("../context/ChartsThemeProvider");
22
+ let canvasContext;
23
+ function getGlobalCanvasContext() {
24
+ if (!canvasContext) {
25
+ canvasContext = document.createElement('canvas').getContext('2d');
26
+ if (canvasContext === null) {
27
+ throw new Error('Canvas context is null.');
28
+ }
29
+ }
30
+ return canvasContext;
31
+ }
32
+ function useOptimalFontSize({ text , fontWeight , width , height , lineHeight , maxSize }) {
33
+ const ctx = getGlobalCanvasContext();
34
+ const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
35
+ const textStyle = chartsTheme.echartsTheme.textStyle;
36
+ var ref;
37
+ const fontSize = (ref = Number(textStyle === null || textStyle === void 0 ? void 0 : textStyle.fontSize)) !== null && ref !== void 0 ? ref : 12;
38
+ var ref1;
39
+ const fontFamily = (ref1 = textStyle === null || textStyle === void 0 ? void 0 : textStyle.fontFamily) !== null && ref1 !== void 0 ? ref1 : 'Lato';
40
+ // set the font on the canvas context
41
+ const fontStyle = `${fontWeight} ${fontSize}px ${fontFamily}`;
42
+ ctx.font = fontStyle;
43
+ // measure the width of the text with the given font style
44
+ const textMetrics = ctx.measureText(text);
45
+ // check how much bigger we can make the font while staying within the width and height
46
+ const fontSizeBasedOnWidth = width / textMetrics.width * fontSize;
47
+ const fontSizeBasedOnHeight = height / lineHeight;
48
+ // return the smaller font size
49
+ const finalFontSize = Math.min(fontSizeBasedOnHeight, fontSizeBasedOnWidth);
50
+ return maxSize ? Math.min(finalFontSize, maxSize) : finalFontSize;
51
+ }
@@ -37,7 +37,7 @@ function Table({ data , columns , density ='standard' , checkboxSelection , onRo
37
37
  const checkboxColumn = (0, _react.useMemo)(()=>{
38
38
  return {
39
39
  id: 'checkboxRowSelect',
40
- size: 32,
40
+ size: 28,
41
41
  header: ({ table })=>{
42
42
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableCheckbox.TableCheckbox, {
43
43
  checked: table.getIsAllRowsSelected(),
@@ -37,7 +37,7 @@ const StyledMuiTableCell = (0, _material.styled)(_material.TableCell)(({ theme
37
37
  borderRadius: 0
38
38
  }
39
39
  }));
40
- function TableCell({ children , density , variant , width , focusState ='none' , onFocusTrigger , ...otherProps }) {
40
+ function TableCell({ children , density , variant , width , focusState ='none' , onFocusTrigger , isFirstColumn , isLastColumn , ...otherProps }) {
41
41
  const theme = (0, _material.useTheme)();
42
42
  const elRef = (0, _react.useRef)();
43
43
  const isHeader = variant === 'head';
@@ -83,7 +83,10 @@ function TableCell({ children , density , variant , width , focusState ='none' ,
83
83
  ref: elRef,
84
84
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
85
85
  sx: {
86
- ...(0, _tableModel.getTableCellLayout)(theme, density),
86
+ ...(0, _tableModel.getTableCellLayout)(theme, density, {
87
+ isLastColumn,
88
+ isFirstColumn
89
+ }),
87
90
  position: 'relative',
88
91
  // Text truncation. Currently enforced on all cells. We may control
89
92
  // this with a prop on column config in the future.