@perses-dev/components 0.34.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ContentWithLegend/ContentWithLegend.d.ts +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.js +4 -2
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +9 -3
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.js +17 -7
- package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +2 -5
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
- package/dist/Drawer/Drawer.js +1 -1
- package/dist/Drawer/Drawer.js.map +1 -1
- package/dist/GaugeChart/GaugeChart.d.ts +2 -2
- package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
- package/dist/GaugeChart/GaugeChart.js +7 -5
- package/dist/GaugeChart/GaugeChart.js.map +1 -1
- package/dist/Legend/CompactLegend.d.ts +3 -1
- package/dist/Legend/CompactLegend.d.ts.map +1 -1
- package/dist/Legend/CompactLegend.js +5 -2
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.d.ts +11 -2
- package/dist/Legend/Legend.d.ts.map +1 -1
- package/dist/Legend/Legend.js +4 -2
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/ListLegend.d.ts +3 -1
- package/dist/Legend/ListLegend.d.ts.map +1 -1
- package/dist/Legend/ListLegend.js +5 -4
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.d.ts +15 -2
- package/dist/Legend/ListLegendItem.d.ts.map +1 -1
- package/dist/Legend/ListLegendItem.js +17 -5
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/Legend/TableLegend.d.ts +4 -2
- package/dist/Legend/TableLegend.d.ts.map +1 -1
- package/dist/Legend/TableLegend.js +8 -2
- package/dist/Legend/TableLegend.js.map +1 -1
- package/dist/LineChart/LineChart.d.ts +17 -3
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +33 -7
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/LineChart/utils.d.ts +2 -1
- package/dist/LineChart/utils.d.ts.map +1 -1
- package/dist/LineChart/utils.js +14 -1
- package/dist/LineChart/utils.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts +12 -0
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts.map +1 -0
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +45 -0
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -0
- package/dist/RefreshIntervalPicker/index.d.ts +2 -0
- package/dist/RefreshIntervalPicker/index.d.ts.map +1 -0
- package/dist/{model/units → RefreshIntervalPicker}/index.js +1 -3
- package/dist/RefreshIntervalPicker/index.js.map +1 -0
- package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts +36 -0
- package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts.map +1 -0
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js +65 -0
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -0
- package/dist/SettingsAutocomplete/index.d.ts +2 -0
- package/dist/SettingsAutocomplete/index.d.ts.map +1 -0
- package/dist/{model/units/constants.js → SettingsAutocomplete/index.js} +2 -4
- package/dist/SettingsAutocomplete/index.js.map +1 -0
- package/dist/StatChart/StatChart.d.ts +3 -2
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +74 -21
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/StatChart/calculateFontSize.d.ts +14 -0
- package/dist/StatChart/calculateFontSize.d.ts.map +1 -0
- package/dist/StatChart/calculateFontSize.js +47 -0
- package/dist/StatChart/calculateFontSize.js.map +1 -0
- package/dist/Table/InnerTable.js +2 -2
- package/dist/Table/InnerTable.js.map +1 -1
- package/dist/Table/Table.d.ts +1 -1
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +57 -9
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableCell.d.ts +11 -1
- package/dist/Table/TableCell.d.ts.map +1 -1
- package/dist/Table/TableCell.js +8 -3
- package/dist/Table/TableCell.js.map +1 -1
- package/dist/Table/TableCheckbox.js +1 -1
- package/dist/Table/TableCheckbox.js.map +1 -1
- package/dist/Table/TableHeaderCell.d.ts +23 -0
- package/dist/Table/TableHeaderCell.d.ts.map +1 -0
- package/dist/Table/TableHeaderCell.js +53 -0
- package/dist/Table/TableHeaderCell.js.map +1 -0
- package/dist/Table/VirtualizedTable.d.ts +3 -3
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +43 -8
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/model/table-model.d.ts +71 -7
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js +6 -2
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +2 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.js +2 -11
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.d.ts +1 -1
- package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
- package/dist/UnitSelector/UnitSelector.js +11 -24
- package/dist/UnitSelector/UnitSelector.js.map +1 -1
- package/dist/YAxisLabel.js +1 -1
- package/dist/YAxisLabel.js.map +1 -1
- package/dist/cjs/ContentWithLegend/ContentWithLegend.js +4 -2
- package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +17 -7
- package/dist/cjs/Drawer/Drawer.js +1 -1
- package/dist/cjs/GaugeChart/GaugeChart.js +7 -5
- package/dist/cjs/Legend/CompactLegend.js +5 -2
- package/dist/cjs/Legend/Legend.js +4 -2
- package/dist/cjs/Legend/ListLegend.js +5 -4
- package/dist/cjs/Legend/ListLegendItem.js +17 -5
- package/dist/cjs/Legend/TableLegend.js +8 -2
- package/dist/cjs/LineChart/LineChart.js +31 -5
- package/dist/cjs/LineChart/utils.js +14 -3
- package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +1 -1
- package/dist/cjs/RefreshIntervalPicker/RefreshIntervalPicker.js +51 -0
- package/dist/cjs/{model/units → RefreshIntervalPicker}/index.js +1 -3
- package/dist/cjs/SettingsAutocomplete/SettingsAutocomplete.js +66 -0
- package/dist/cjs/{model/units/types.js → SettingsAutocomplete/index.js} +12 -12
- package/dist/cjs/StatChart/StatChart.js +75 -22
- package/dist/cjs/StatChart/calculateFontSize.js +51 -0
- package/dist/cjs/Table/InnerTable.js +2 -2
- package/dist/cjs/Table/Table.js +56 -8
- package/dist/cjs/Table/TableCell.js +8 -3
- package/dist/cjs/Table/TableCheckbox.js +1 -1
- package/dist/cjs/Table/TableHeaderCell.js +59 -0
- package/dist/cjs/Table/VirtualizedTable.js +43 -8
- package/dist/cjs/Table/model/table-model.js +6 -2
- package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -1
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -11
- package/dist/cjs/UnitSelector/UnitSelector.js +15 -28
- package/dist/cjs/YAxisLabel.js +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/model/index.js +1 -1
- package/dist/cjs/model/{units/constants.js → timeOption.js} +0 -7
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/index.d.ts +1 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/theme.d.ts +4 -6
- package/dist/model/theme.d.ts.map +1 -1
- package/dist/model/theme.js.map +1 -1
- package/dist/model/timeOption.d.ts +6 -0
- package/dist/model/timeOption.d.ts.map +1 -0
- package/dist/model/{units/types.js → timeOption.js} +2 -9
- package/dist/model/timeOption.js.map +1 -0
- package/package.json +3 -4
- package/dist/cjs/model/units/bytes.js +0 -84
- package/dist/cjs/model/units/decimal.js +0 -62
- package/dist/cjs/model/units/percent.js +0 -73
- package/dist/cjs/model/units/time.js +0 -105
- package/dist/cjs/model/units/units.js +0 -101
- package/dist/cjs/model/units/utils.js +0 -42
- package/dist/model/units/bytes.d.ts +0 -13
- package/dist/model/units/bytes.d.ts.map +0 -1
- package/dist/model/units/bytes.js +0 -66
- package/dist/model/units/bytes.js.map +0 -1
- package/dist/model/units/constants.d.ts +0 -2
- package/dist/model/units/constants.d.ts.map +0 -1
- package/dist/model/units/constants.js.map +0 -1
- package/dist/model/units/decimal.d.ts +0 -13
- package/dist/model/units/decimal.d.ts.map +0 -1
- package/dist/model/units/decimal.js +0 -49
- package/dist/model/units/decimal.js.map +0 -1
- package/dist/model/units/index.d.ts +0 -4
- package/dist/model/units/index.d.ts.map +0 -1
- package/dist/model/units/index.js.map +0 -1
- package/dist/model/units/percent.d.ts +0 -12
- package/dist/model/units/percent.d.ts.map +0 -1
- package/dist/model/units/percent.js +0 -60
- package/dist/model/units/percent.js.map +0 -1
- package/dist/model/units/time.d.ts +0 -22
- package/dist/model/units/time.d.ts.map +0 -1
- package/dist/model/units/time.js +0 -91
- package/dist/model/units/time.js.map +0 -1
- package/dist/model/units/types.d.ts +0 -47
- package/dist/model/units/types.d.ts.map +0 -1
- package/dist/model/units/types.js.map +0 -1
- package/dist/model/units/units.d.ts +0 -40
- package/dist/model/units/units.d.ts.map +0 -1
- package/dist/model/units/units.js +0 -80
- package/dist/model/units/units.js.map +0 -1
- package/dist/model/units/utils.d.ts +0 -4
- package/dist/model/units/utils.d.ts.map +0 -1
- package/dist/model/units/utils.js +0 -32
- package/dist/model/units/utils.js.map +0 -1
|
@@ -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 , tableProps }) {
|
|
34
|
+
function Legend({ width , height , options , data , selectedItems , onSelectedItemsChange , onItemMouseOver , onItemMouseOut , tableProps }) {
|
|
35
35
|
const onLegendItemClick = (e, seriesId)=>{
|
|
36
36
|
const isModifiedClick = e.metaKey || e.shiftKey;
|
|
37
37
|
const newSelected = (0, _immer.produce)(selectedItems, (draft)=>{
|
|
@@ -74,7 +74,9 @@ function Legend({ width , height , options , data , selectedItems , onSelectedIt
|
|
|
74
74
|
height,
|
|
75
75
|
items: data,
|
|
76
76
|
selectedItems,
|
|
77
|
-
onLegendItemClick
|
|
77
|
+
onLegendItemClick,
|
|
78
|
+
onItemMouseOver,
|
|
79
|
+
onItemMouseOut
|
|
78
80
|
};
|
|
79
81
|
let legendContent;
|
|
80
82
|
if (mode === 'Table') {
|
|
@@ -22,7 +22,7 @@ const _jsxRuntime = require("react/jsx-runtime");
|
|
|
22
22
|
const _reactVirtuoso = require("react-virtuoso");
|
|
23
23
|
const _listLegendItem = require("./ListLegendItem");
|
|
24
24
|
const _legendModel = require("./legend-model");
|
|
25
|
-
function ListLegend({ items , height , width , selectedItems , onLegendItemClick }) {
|
|
25
|
+
function ListLegend({ items , height , width , selectedItems , onLegendItemClick , onItemMouseOver , onItemMouseOut }) {
|
|
26
26
|
// show full labels on hover when there are many total series
|
|
27
27
|
const truncateLabels = items.length > 5;
|
|
28
28
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactVirtuoso.Virtuoso, {
|
|
@@ -34,13 +34,14 @@ function ListLegend({ items , height , width , selectedItems , onLegendItemClick
|
|
|
34
34
|
itemContent: (index, item)=>{
|
|
35
35
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegendItem.ListLegendItem, {
|
|
36
36
|
item: item,
|
|
37
|
+
index: index,
|
|
37
38
|
truncateLabel: truncateLabels,
|
|
38
39
|
isVisuallySelected: (0, _legendModel.isLegendItemVisuallySelected)(item, selectedItems),
|
|
39
40
|
onClick: onLegendItemClick,
|
|
41
|
+
onMouseOver: onItemMouseOver,
|
|
42
|
+
onMouseOut: onItemMouseOut,
|
|
40
43
|
sx: {
|
|
41
|
-
|
|
42
|
-
// work correctly. Subtract padding to simulate padding.
|
|
43
|
-
width: width,
|
|
44
|
+
width: '100%',
|
|
44
45
|
wordBreak: 'break-word',
|
|
45
46
|
overflow: 'hidden'
|
|
46
47
|
}
|
|
@@ -62,14 +62,14 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
62
62
|
}
|
|
63
63
|
return newObj;
|
|
64
64
|
}
|
|
65
|
-
const ListLegendItemBase = /*#__PURE__*/ (0, _react.forwardRef)(function ListLegendItem({ item , sx , truncateLabel , onClick , isVisuallySelected , ...others }, ref) {
|
|
65
|
+
const ListLegendItemBase = /*#__PURE__*/ (0, _react.forwardRef)(function ListLegendItem({ item , sx , truncateLabel , onClick , isVisuallySelected , onMouseOver , onMouseOut , index , ...others }, ref) {
|
|
66
66
|
const [noWrap, setNoWrap] = (0, _react.useState)(truncateLabel);
|
|
67
|
-
function
|
|
67
|
+
function handleTextMouseOver() {
|
|
68
68
|
if (truncateLabel) {
|
|
69
69
|
setNoWrap(false);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function handleTextMouseOut() {
|
|
73
73
|
if (truncateLabel) {
|
|
74
74
|
setNoWrap(true);
|
|
75
75
|
}
|
|
@@ -90,6 +90,18 @@ const ListLegendItemBase = /*#__PURE__*/ (0, _react.forwardRef)(function ListLeg
|
|
|
90
90
|
dense: true,
|
|
91
91
|
key: item.id,
|
|
92
92
|
onClick: handleClick,
|
|
93
|
+
onMouseOver: (e)=>{
|
|
94
|
+
return onMouseOver === null || onMouseOver === void 0 ? void 0 : onMouseOver(e, {
|
|
95
|
+
id: item.id,
|
|
96
|
+
index
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
onMouseOut: (e)=>{
|
|
100
|
+
return onMouseOut === null || onMouseOut === void 0 ? void 0 : onMouseOut(e, {
|
|
101
|
+
id: item.id,
|
|
102
|
+
index
|
|
103
|
+
});
|
|
104
|
+
},
|
|
93
105
|
selected: isVisuallySelected,
|
|
94
106
|
ref: ref,
|
|
95
107
|
children: [
|
|
@@ -107,8 +119,8 @@ const ListLegendItemBase = /*#__PURE__*/ (0, _react.forwardRef)(function ListLeg
|
|
|
107
119
|
primaryTypographyProps: {
|
|
108
120
|
noWrap: noWrap
|
|
109
121
|
},
|
|
110
|
-
onMouseOver:
|
|
111
|
-
onMouseOut:
|
|
122
|
+
onMouseOver: handleTextMouseOver,
|
|
123
|
+
onMouseOut: handleTextMouseOut
|
|
112
124
|
})
|
|
113
125
|
]
|
|
114
126
|
});
|
|
@@ -25,6 +25,7 @@ const COLUMNS = [
|
|
|
25
25
|
{
|
|
26
26
|
accessorKey: 'label',
|
|
27
27
|
header: 'Name',
|
|
28
|
+
enableSorting: true,
|
|
28
29
|
// Starting with `title` attr instead of a tooltip because it is easier to
|
|
29
30
|
// implement. We should try adding a tooltip in the future, but we'll need
|
|
30
31
|
// to be very careful about performance when doing so with large tables.
|
|
@@ -40,7 +41,7 @@ const getRowId = (data)=>{
|
|
|
40
41
|
const getCheckboxColor = (data)=>{
|
|
41
42
|
return data.color;
|
|
42
43
|
};
|
|
43
|
-
function TableLegend({ items , selectedItems: initRowSelection , onSelectedItemsChange , height , width , columns: additionalColumns = [] }) {
|
|
44
|
+
function TableLegend({ items , selectedItems: initRowSelection , onSelectedItemsChange , onItemMouseOver , onItemMouseOut , height , width , columns: additionalColumns = [] , sorting , onSortingChange }) {
|
|
44
45
|
const rowSelection = (0, _react.useMemo)(()=>{
|
|
45
46
|
return typeof initRowSelection !== 'string' ? initRowSelection : // items for checkboxes.
|
|
46
47
|
// TODO: clean this up if we switch to also using checkboxes in list legend.
|
|
@@ -65,11 +66,16 @@ function TableLegend({ items , selectedItems: initRowSelection , onSelectedItems
|
|
|
65
66
|
width: width,
|
|
66
67
|
rowSelection: rowSelection,
|
|
67
68
|
onRowSelectionChange: onSelectedItemsChange,
|
|
69
|
+
onRowMouseOver: onItemMouseOver,
|
|
70
|
+
onRowMouseOut: onItemMouseOut,
|
|
71
|
+
sorting: sorting,
|
|
72
|
+
onSortingChange: onSortingChange,
|
|
68
73
|
data: items,
|
|
69
74
|
columns: columns,
|
|
70
75
|
density: "compact",
|
|
71
76
|
getRowId: getRowId,
|
|
72
77
|
getCheckboxColor: getCheckboxColor,
|
|
73
|
-
checkboxSelection: true
|
|
78
|
+
checkboxSelection: true,
|
|
79
|
+
rowSelectionVariant: "legend"
|
|
74
80
|
});
|
|
75
81
|
}
|
|
@@ -82,10 +82,10 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
82
82
|
_components.LegendComponent,
|
|
83
83
|
_renderers.CanvasRenderer
|
|
84
84
|
]);
|
|
85
|
-
function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfig ={
|
|
85
|
+
const LineChart = /*#__PURE__*/ (0, _react.forwardRef)(function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfig ={
|
|
86
86
|
wrapLabels: true
|
|
87
|
-
} , noDataVariant ='message' , syncGroup , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
|
|
88
|
-
var
|
|
87
|
+
} , noDataVariant ='message' , syncGroup , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride , }, ref) {
|
|
88
|
+
var ref1;
|
|
89
89
|
const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
|
|
90
90
|
const chartRef = (0, _react.useRef)();
|
|
91
91
|
const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
|
|
@@ -93,6 +93,29 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
|
|
|
93
93
|
const { timeZone } = (0, _timeZoneProvider.useTimeZone)();
|
|
94
94
|
const [isDragging, setIsDragging] = (0, _react.useState)(false);
|
|
95
95
|
const [startX, setStartX] = (0, _react.useState)(0);
|
|
96
|
+
(0, _react.useImperativeHandle)(ref, ()=>{
|
|
97
|
+
return {
|
|
98
|
+
highlightSeries ({ id }) {
|
|
99
|
+
if (!chartRef.current) {
|
|
100
|
+
// No chart. Do nothing.
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
chartRef.current.dispatchAction({
|
|
104
|
+
type: 'highlight',
|
|
105
|
+
seriesId: id
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
clearHighlightedSeries: ()=>{
|
|
109
|
+
if (!chartRef.current) {
|
|
110
|
+
// No chart. Do nothing.
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
(0, _utils.clearHighlightedSeries)(chartRef.current, data.timeSeries.length);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}, [
|
|
117
|
+
data.timeSeries.length
|
|
118
|
+
]);
|
|
96
119
|
const handleEvents = (0, _react.useMemo)(()=>{
|
|
97
120
|
return {
|
|
98
121
|
datazoom: (params)=>{
|
|
@@ -247,6 +270,9 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
|
|
|
247
270
|
if (tooltipPinnedCoords === null) {
|
|
248
271
|
setShowTooltip(false);
|
|
249
272
|
}
|
|
273
|
+
if (chartRef.current !== undefined) {
|
|
274
|
+
(0, _utils.clearHighlightedSeries)(chartRef.current, data.timeSeries.length);
|
|
275
|
+
}
|
|
250
276
|
},
|
|
251
277
|
onMouseEnter: ()=>{
|
|
252
278
|
setShowTooltip(true);
|
|
@@ -266,7 +292,7 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
|
|
|
266
292
|
}
|
|
267
293
|
},
|
|
268
294
|
children: [
|
|
269
|
-
showTooltip === true && ((
|
|
295
|
+
showTooltip === true && ((ref1 = option.tooltip) === null || ref1 === void 0 ? void 0 : ref1.showContent) === false && tooltipConfig.hidden !== true && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeSeriesTooltip.TimeSeriesTooltip, {
|
|
270
296
|
chartRef: chartRef,
|
|
271
297
|
chartData: data,
|
|
272
298
|
wrapLabels: tooltipConfig.wrapLabels,
|
|
@@ -289,4 +315,4 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
|
|
|
289
315
|
})
|
|
290
316
|
]
|
|
291
317
|
});
|
|
292
|
-
}
|
|
318
|
+
});
|
|
@@ -25,10 +25,11 @@ _export(exports, {
|
|
|
25
25
|
restoreChart: ()=>restoreChart,
|
|
26
26
|
getDateRange: ()=>getDateRange,
|
|
27
27
|
getFormattedDate: ()=>getFormattedDate,
|
|
28
|
-
getYAxes: ()=>getYAxes
|
|
28
|
+
getYAxes: ()=>getYAxes,
|
|
29
|
+
clearHighlightedSeries: ()=>clearHighlightedSeries
|
|
29
30
|
});
|
|
31
|
+
const _core = require("@perses-dev/core");
|
|
30
32
|
const _merge = /*#__PURE__*/ _interopRequireDefault(require("lodash/merge"));
|
|
31
|
-
const _model = require("../model");
|
|
32
33
|
const _utils = require("../utils");
|
|
33
34
|
function _interopRequireDefault(obj) {
|
|
34
35
|
return obj && obj.__esModule ? obj : {
|
|
@@ -90,7 +91,7 @@ function getYAxes(yAxis, unit) {
|
|
|
90
91
|
],
|
|
91
92
|
axisLabel: {
|
|
92
93
|
formatter: (value)=>{
|
|
93
|
-
return (0,
|
|
94
|
+
return (0, _core.formatValue)(value, unit);
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
};
|
|
@@ -98,3 +99,13 @@ function getYAxes(yAxis, unit) {
|
|
|
98
99
|
(0, _merge.default)(Y_AXIS_DEFAULT, yAxis)
|
|
99
100
|
];
|
|
100
101
|
}
|
|
102
|
+
function clearHighlightedSeries(chart, totalSeries) {
|
|
103
|
+
if (chart.dispatchAction !== undefined) {
|
|
104
|
+
for(let i = 0; i < totalSeries; i++){
|
|
105
|
+
chart.dispatchAction({
|
|
106
|
+
type: 'downplay',
|
|
107
|
+
seriesIndex: i
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -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, "RefreshIntervalPicker", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>RefreshIntervalPicker
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
function RefreshIntervalPicker(props) {
|
|
24
|
+
const { value , onChange , timeOptions , height } = props;
|
|
25
|
+
const formattedValue = value;
|
|
26
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControl, {
|
|
27
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
28
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Select, {
|
|
29
|
+
id: "refreshInterval",
|
|
30
|
+
value: formattedValue,
|
|
31
|
+
onChange: (event)=>{
|
|
32
|
+
const duration = event.target.value;
|
|
33
|
+
onChange(duration);
|
|
34
|
+
},
|
|
35
|
+
inputProps: {
|
|
36
|
+
'aria-label': `Select refresh interval. Currently set to ${formattedValue}`
|
|
37
|
+
},
|
|
38
|
+
sx: {
|
|
39
|
+
'.MuiSelect-select': height ? {
|
|
40
|
+
lineHeight: height,
|
|
41
|
+
paddingY: 0
|
|
42
|
+
} : {}
|
|
43
|
+
},
|
|
44
|
+
children: timeOptions.map((item, idx)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
|
|
45
|
+
value: item.value.pastDuration,
|
|
46
|
+
children: item.display
|
|
47
|
+
}, idx))
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -14,9 +14,7 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
_exportStar(require("./
|
|
18
|
-
_exportStar(require("./constants"), exports);
|
|
19
|
-
_exportStar(require("./types"), exports);
|
|
17
|
+
_exportStar(require("./RefreshIntervalPicker"), exports);
|
|
20
18
|
function _exportStar(from, to) {
|
|
21
19
|
Object.keys(from).forEach(function(k) {
|
|
22
20
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -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
|
+
}
|
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
// Common types needed across individual unit groups and the overall combined
|
|
14
|
-
// units.
|
|
15
13
|
"use strict";
|
|
16
14
|
Object.defineProperty(exports, "__esModule", {
|
|
17
15
|
value: true
|
|
18
16
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
_exportStar(require("./SettingsAutocomplete"), exports);
|
|
18
|
+
function _exportStar(from, to) {
|
|
19
|
+
Object.keys(from).forEach(function(k) {
|
|
20
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return from[k];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return from;
|
|
28
|
+
}
|
|
@@ -20,21 +20,22 @@ Object.defineProperty(exports, "StatChart", {
|
|
|
20
20
|
});
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
22
|
const _react = require("react");
|
|
23
|
+
const _core = require("@perses-dev/core");
|
|
23
24
|
const _material = require("@mui/material");
|
|
24
25
|
const _merge = /*#__PURE__*/ _interopRequireDefault(require("lodash/merge"));
|
|
25
|
-
const
|
|
26
|
+
const _core1 = require("echarts/core");
|
|
26
27
|
const _charts = require("echarts/charts");
|
|
27
28
|
const _components = require("echarts/components");
|
|
28
29
|
const _renderers = require("echarts/renderers");
|
|
29
30
|
const _chartsThemeProvider = require("../context/ChartsThemeProvider");
|
|
30
|
-
const _units = require("../model/units");
|
|
31
31
|
const _echart = require("../EChart");
|
|
32
|
+
const _calculateFontSize = require("./calculateFontSize");
|
|
32
33
|
function _interopRequireDefault(obj) {
|
|
33
34
|
return obj && obj.__esModule ? obj : {
|
|
34
35
|
default: obj
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
|
-
(0,
|
|
38
|
+
(0, _core1.use)([
|
|
38
39
|
_charts.LineChart,
|
|
39
40
|
_components.GridComponent,
|
|
40
41
|
_components.DatasetComponent,
|
|
@@ -42,12 +43,48 @@ function _interopRequireDefault(obj) {
|
|
|
42
43
|
_components.TooltipComponent,
|
|
43
44
|
_renderers.CanvasRenderer
|
|
44
45
|
]);
|
|
45
|
-
const
|
|
46
|
-
const
|
|
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;
|
|
47
50
|
function StatChart(props) {
|
|
48
|
-
|
|
51
|
+
var ref, ref1;
|
|
52
|
+
const { width , height , data , unit , color , sparkline , showSeriesName } = props;
|
|
49
53
|
const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
|
|
50
|
-
|
|
54
|
+
let formattedValue = '';
|
|
55
|
+
if (data.calculatedValue === null) {
|
|
56
|
+
formattedValue = 'null';
|
|
57
|
+
} else if (typeof data.calculatedValue === 'number') {
|
|
58
|
+
formattedValue = (0, _core.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);
|
|
51
88
|
const option = (0, _react.useMemo)(()=>{
|
|
52
89
|
if (data.seriesData === undefined) return chartsTheme.noDataOption;
|
|
53
90
|
const series = data.seriesData;
|
|
@@ -55,9 +92,8 @@ function StatChart(props) {
|
|
|
55
92
|
if (sparkline !== undefined) {
|
|
56
93
|
const lineSeries = {
|
|
57
94
|
type: 'line',
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
],
|
|
95
|
+
name: series.name,
|
|
96
|
+
data: series.values,
|
|
61
97
|
zlevel: 1,
|
|
62
98
|
symbol: 'none',
|
|
63
99
|
animation: false,
|
|
@@ -105,11 +141,6 @@ function StatChart(props) {
|
|
|
105
141
|
chartsTheme,
|
|
106
142
|
sparkline
|
|
107
143
|
]);
|
|
108
|
-
const isLargePanel = width > 250 && height > 180;
|
|
109
|
-
// adjusts fontSize depending on number of characters, clamp also used in fontSize attribute
|
|
110
|
-
const charactersAdjust = formattedValue.length;
|
|
111
|
-
const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
|
|
112
|
-
const containerPadding = `${chartsTheme.container.padding.default}px`;
|
|
113
144
|
const textAlignment = sparkline ? 'auto' : 'center';
|
|
114
145
|
const textStyles = {
|
|
115
146
|
display: 'flex',
|
|
@@ -124,19 +155,22 @@ function StatChart(props) {
|
|
|
124
155
|
...textStyles
|
|
125
156
|
},
|
|
126
157
|
children: [
|
|
127
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(
|
|
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, {
|
|
128
164
|
variant: "h3",
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
padding: sparkline ? `${containerPadding} ${containerPadding} 0 ${containerPadding}` : ` 0 ${containerPadding}`
|
|
133
|
-
}),
|
|
165
|
+
color: color,
|
|
166
|
+
fontSize: valueFontSize,
|
|
167
|
+
padding: containerPadding,
|
|
134
168
|
children: formattedValue
|
|
135
169
|
}),
|
|
136
170
|
sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
|
|
137
171
|
sx: {
|
|
138
172
|
width: '100%',
|
|
139
|
-
height:
|
|
173
|
+
height: height - seriesNameHeight - valueFontHeight
|
|
140
174
|
},
|
|
141
175
|
option: option,
|
|
142
176
|
theme: chartsTheme.echartsTheme,
|
|
@@ -145,3 +179,22 @@ function StatChart(props) {
|
|
|
145
179
|
]
|
|
146
180
|
});
|
|
147
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
|
+
}
|
|
@@ -31,14 +31,14 @@ const TABLE_DENSITY_CONFIG = {
|
|
|
31
31
|
compact: 'small',
|
|
32
32
|
standard: 'medium'
|
|
33
33
|
};
|
|
34
|
-
const InnerTable = /*#__PURE__*/ (0, _react.forwardRef)(function InnerTable({ density ,
|
|
34
|
+
const InnerTable = /*#__PURE__*/ (0, _react.forwardRef)(function InnerTable({ density , ...otherProps }, ref) {
|
|
35
35
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(StyledMuiTable, {
|
|
36
36
|
...otherProps,
|
|
37
37
|
tabIndex: -1,
|
|
38
38
|
size: TABLE_DENSITY_CONFIG[density],
|
|
39
39
|
ref: ref,
|
|
40
40
|
sx: {
|
|
41
|
-
width:
|
|
41
|
+
width: '100%'
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
44
|
});
|