@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.
- package/dist/ContentWithLegend/ContentWithLegend.d.ts +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.js +5 -3
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +10 -4
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.js +27 -8
- 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/EChart/EChart.d.ts +2 -1
- package/dist/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +15 -3
- package/dist/EChart/EChart.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 +4 -2
- package/dist/Legend/CompactLegend.d.ts.map +1 -1
- package/dist/Legend/CompactLegend.js +6 -3
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.d.ts +17 -3
- package/dist/Legend/Legend.d.ts.map +1 -1
- package/dist/Legend/Legend.js +7 -4
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/ListLegend.d.ts +4 -2
- package/dist/Legend/ListLegend.d.ts.map +1 -1
- package/dist/Legend/ListLegend.js +6 -5
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.d.ts +16 -3
- 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 +6 -3
- package/dist/Legend/TableLegend.d.ts.map +1 -1
- package/dist/Legend/TableLegend.js +17 -3
- package/dist/Legend/TableLegend.js.map +1 -1
- package/dist/Legend/index.d.ts +1 -0
- package/dist/Legend/index.d.ts.map +1 -1
- package/dist/Legend/index.js +1 -0
- package/dist/Legend/index.js.map +1 -1
- package/dist/Legend/legend-model.d.ts +24 -0
- package/dist/Legend/legend-model.d.ts.map +1 -0
- package/dist/Legend/legend-model.js +19 -0
- package/dist/Legend/legend-model.js.map +1 -0
- package/dist/LineChart/LineChart.d.ts +6 -11
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +36 -9
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/LineChart/index.d.ts +0 -1
- package/dist/LineChart/index.d.ts.map +1 -1
- package/dist/LineChart/index.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 +75 -22
- 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 +3 -3
- 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 +58 -10
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableCell.d.ts +16 -3
- package/dist/Table/TableCell.d.ts.map +1 -1
- package/dist/Table/TableCell.js +13 -5
- 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/TableRow.d.ts.map +1 -1
- package/dist/Table/TableRow.js +3 -3
- package/dist/Table/TableRow.js.map +1 -1
- package/dist/Table/VirtualizedTable.d.ts +3 -3
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +51 -10
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/model/table-model.d.ts +81 -3
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js +22 -7
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/TimeChart/TimeChart.d.ts +23 -0
- package/dist/TimeChart/TimeChart.d.ts.map +1 -0
- package/dist/TimeChart/TimeChart.js +314 -0
- package/dist/TimeChart/TimeChart.js.map +1 -0
- package/dist/TimeChart/index.d.ts +2 -0
- package/dist/TimeChart/index.d.ts.map +1 -0
- package/dist/{LegendOptionsEditor → TimeChart}/index.js +1 -1
- package/dist/TimeChart/index.js.map +1 -0
- package/dist/TimeSeriesTooltip/{TimeSeriesTooltip.d.ts → LineChartTooltip.d.ts} +5 -4
- package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts.map +1 -0
- package/dist/TimeSeriesTooltip/{TimeSeriesTooltip.js → LineChartTooltip.js} +7 -6
- package/dist/TimeSeriesTooltip/LineChartTooltip.js.map +1 -0
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts +16 -0
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -0
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js +76 -0
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -0
- package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +2 -2
- package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.js +10 -8
- package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts +2 -1
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +2 -1
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +23 -4
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.js +175 -17
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +4 -0
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts +25 -0
- package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/utils.js +29 -1
- package/dist/TimeSeriesTooltip/utils.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 +5 -3
- package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +28 -9
- package/dist/cjs/Drawer/Drawer.js +1 -1
- package/dist/cjs/EChart/EChart.js +22 -5
- package/dist/cjs/GaugeChart/GaugeChart.js +7 -5
- package/dist/cjs/Legend/CompactLegend.js +7 -4
- package/dist/cjs/Legend/Legend.js +8 -5
- package/dist/cjs/Legend/ListLegend.js +7 -6
- package/dist/cjs/Legend/ListLegendItem.js +17 -5
- package/dist/cjs/Legend/TableLegend.js +17 -3
- package/dist/cjs/Legend/index.js +1 -0
- package/dist/cjs/{model/units/types.js → Legend/legend-model.js} +7 -10
- package/dist/cjs/LineChart/LineChart.js +35 -47
- 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/SettingsAutocomplete/index.js +28 -0
- package/dist/cjs/StatChart/StatChart.js +82 -24
- package/dist/cjs/StatChart/calculateFontSize.js +51 -0
- package/dist/cjs/Table/InnerTable.js +3 -3
- package/dist/cjs/Table/Table.js +57 -9
- package/dist/cjs/Table/TableCell.js +13 -5
- package/dist/cjs/Table/TableCheckbox.js +1 -1
- package/dist/cjs/Table/TableHeaderCell.js +59 -0
- package/dist/cjs/Table/TableRow.js +2 -2
- package/dist/cjs/Table/VirtualizedTable.js +51 -10
- package/dist/cjs/Table/model/table-model.js +22 -7
- package/dist/cjs/TimeChart/TimeChart.js +320 -0
- package/dist/cjs/{LegendOptionsEditor → TimeChart}/index.js +1 -1
- package/dist/cjs/TimeSeriesTooltip/{TimeSeriesTooltip.js → LineChartTooltip.js} +7 -45
- package/dist/cjs/TimeSeriesTooltip/TimeChartTooltip.js +87 -0
- package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +10 -8
- package/dist/cjs/TimeSeriesTooltip/index.js +2 -1
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +171 -17
- package/dist/cjs/TimeSeriesTooltip/utils.js +35 -3
- package/dist/cjs/UnitSelector/UnitSelector.js +15 -28
- package/dist/cjs/YAxisLabel.js +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/model/index.js +1 -2
- package/dist/cjs/model/timeOption.js +16 -0
- package/dist/cjs/{model/units/constants.js → theme/component-overrides/paper.js} +9 -5
- package/dist/cjs/theme/palette/background.js +2 -2
- package/dist/cjs/theme/theme.js +2 -0
- package/dist/cjs/utils/axis.js +58 -0
- package/dist/cjs/{LineChart/utils.js → utils/chart-actions.js} +9 -47
- package/dist/cjs/utils/format.js +47 -1
- package/dist/cjs/utils/index.js +3 -1
- package/dist/cjs/utils/theme-gen.js +44 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +20 -3
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js.map +1 -1
- package/dist/model/index.d.ts +1 -2
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -2
- 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/dist/theme/component-overrides/paper.d.ts +3 -0
- package/dist/theme/component-overrides/paper.d.ts.map +1 -0
- package/dist/theme/component-overrides/paper.js +21 -0
- package/dist/theme/component-overrides/paper.js.map +1 -0
- package/dist/theme/palette/background.js +2 -2
- package/dist/theme/palette/background.js.map +1 -1
- package/dist/theme/theme.d.ts.map +1 -1
- package/dist/theme/theme.js +2 -0
- package/dist/theme/theme.js.map +1 -1
- package/dist/utils/axis.d.ts +14 -0
- package/dist/utils/axis.d.ts.map +1 -0
- package/dist/utils/axis.js +45 -0
- package/dist/utils/axis.js.map +1 -0
- package/dist/utils/chart-actions.d.ts +18 -0
- package/dist/utils/chart-actions.d.ts.map +1 -0
- package/dist/utils/chart-actions.js +52 -0
- package/dist/utils/chart-actions.js.map +1 -0
- package/dist/utils/format.d.ts +6 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +47 -0
- package/dist/utils/format.js.map +1 -1
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/theme-gen.d.ts.map +1 -1
- package/dist/utils/theme-gen.js +38 -1
- package/dist/utils/theme-gen.js.map +1 -1
- package/package.json +5 -9
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts +0 -8
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +0 -1
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js +0 -109
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +0 -1
- package/dist/LegendOptionsEditor/index.d.ts +0 -2
- package/dist/LegendOptionsEditor/index.d.ts.map +0 -1
- package/dist/LegendOptionsEditor/index.js.map +0 -1
- package/dist/LineChart/utils.d.ts +0 -30
- package/dist/LineChart/utils.d.ts.map +0 -1
- package/dist/LineChart/utils.js +0 -90
- package/dist/LineChart/utils.js.map +0 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +0 -1
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +0 -115
- package/dist/cjs/model/legend.js +0 -102
- 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/legend.d.ts +0 -36
- package/dist/model/legend.d.ts.map +0 -1
- package/dist/model/legend.js +0 -81
- package/dist/model/legend.js.map +0 -1
- 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
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Theme } from '@mui/material';
|
|
3
|
-
import { AccessorKeyColumnDef, ColumnDef, CoreOptions, RowSelectionState } from '@tanstack/react-table';
|
|
3
|
+
import { AccessorKeyColumnDef, CellContext, ColumnDef, CoreOptions, RowData, RowSelectionState, SortingState } from '@tanstack/react-table';
|
|
4
4
|
export declare type TableDensity = 'compact' | 'standard';
|
|
5
|
+
export declare type SortDirection = 'asc' | 'desc' | undefined;
|
|
6
|
+
export declare type TableRowEventOpts = {
|
|
7
|
+
/**
|
|
8
|
+
* Unique identifier for the row.
|
|
9
|
+
*/
|
|
10
|
+
id: string;
|
|
11
|
+
/**
|
|
12
|
+
* Index of the row in the original data.
|
|
13
|
+
*/
|
|
14
|
+
index: number;
|
|
15
|
+
};
|
|
5
16
|
export interface TableProps<TableData> {
|
|
6
17
|
/**
|
|
7
18
|
* Height of the table.
|
|
@@ -31,6 +42,18 @@ export interface TableProps<TableData> {
|
|
|
31
42
|
* When `true`, the first column of the table will include checkboxes.
|
|
32
43
|
*/
|
|
33
44
|
checkboxSelection?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Determines the behavior of row selection.
|
|
47
|
+
*
|
|
48
|
+
* - `standard`: clicking a checkbox will toggle that rows's selected/unselected
|
|
49
|
+
* state and will not impact other rows.
|
|
50
|
+
* - `legend`: clicking a checkbox will "focus" that row by selecting it and
|
|
51
|
+
* unselecting other rows. Clicking a checkbox with a modifier key pressed,
|
|
52
|
+
* will change this behavior to behave like `standard`.
|
|
53
|
+
*
|
|
54
|
+
* @default 'standard'
|
|
55
|
+
*/
|
|
56
|
+
rowSelectionVariant?: 'standard' | 'legend';
|
|
34
57
|
/**
|
|
35
58
|
* State of selected rows in the table when `checkboxSelection` is enabled.
|
|
36
59
|
*
|
|
@@ -38,10 +61,29 @@ export interface TableProps<TableData> {
|
|
|
38
61
|
* combination of this prop and `onRowSelectionChange`.
|
|
39
62
|
*/
|
|
40
63
|
rowSelection?: RowSelectionState;
|
|
64
|
+
/**
|
|
65
|
+
* Callback fired when the mouse is moved over a table row.
|
|
66
|
+
*/
|
|
67
|
+
onRowMouseOver?: (e: React.MouseEvent, opts: TableRowEventOpts) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Callback fired when the mouse is moved out of a table row.
|
|
70
|
+
*/
|
|
71
|
+
onRowMouseOut?: (e: React.MouseEvent, opts: TableRowEventOpts) => void;
|
|
72
|
+
/**
|
|
73
|
+
* State of the column sorting in the table.
|
|
74
|
+
*
|
|
75
|
+
* The column sorting is a controlled value that should be managed using a
|
|
76
|
+
* combination fo this prop and `onSortingChange`.
|
|
77
|
+
*/
|
|
78
|
+
sorting?: SortingState;
|
|
41
79
|
/**
|
|
42
80
|
* Callback fired when the selected rows in the table changes.
|
|
43
81
|
*/
|
|
44
82
|
onRowSelectionChange?: (rowSelection: RowSelectionState) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Callback fired when the table sorting changes.
|
|
85
|
+
*/
|
|
86
|
+
onSortingChange?: (sorting: SortingState) => void;
|
|
45
87
|
/**
|
|
46
88
|
* Function used to determine the unique identifier used for each row. This
|
|
47
89
|
* value is used to key `rowSelection`. If this value is not set, the index
|
|
@@ -57,16 +99,52 @@ export interface TableProps<TableData> {
|
|
|
57
99
|
declare type TableCellLayout = NonNullable<Pick<React.CSSProperties, 'padding' | 'fontSize' | 'lineHeight'>> & {
|
|
58
100
|
height: number;
|
|
59
101
|
};
|
|
102
|
+
declare type GetTableCellLayoutOpts = {
|
|
103
|
+
isLastColumn?: boolean;
|
|
104
|
+
isFirstColumn?: boolean;
|
|
105
|
+
};
|
|
60
106
|
/**
|
|
61
107
|
* Returns the properties to lay out the content of table cells based on the
|
|
62
108
|
* theme and density.
|
|
63
109
|
*/
|
|
64
|
-
export declare function getTableCellLayout(theme: Theme, density: TableDensity): TableCellLayout;
|
|
65
|
-
export
|
|
110
|
+
export declare function getTableCellLayout(theme: Theme, density: TableDensity, { isLastColumn, isFirstColumn }?: GetTableCellLayoutOpts): TableCellLayout;
|
|
111
|
+
export declare type TableCellAlignment = 'left' | 'right' | 'center';
|
|
112
|
+
declare module '@tanstack/table-core' {
|
|
113
|
+
interface ColumnMeta<TData extends RowData, TValue> {
|
|
114
|
+
align?: TableColumnConfig<TData>['align'];
|
|
115
|
+
headerDescription?: TableColumnConfig<TData>['headerDescription'];
|
|
116
|
+
cellDescription?: TableColumnConfig<TData>['cellDescription'];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export interface TableColumnConfig<TableData> extends Pick<AccessorKeyColumnDef<TableData, any>, 'accessorKey' | 'cell' | 'sortingFn'> {
|
|
66
120
|
/**
|
|
67
121
|
* Text to display in the header for the column.
|
|
68
122
|
*/
|
|
69
123
|
header: string;
|
|
124
|
+
/**
|
|
125
|
+
* Alignment of the content in the cell.
|
|
126
|
+
*/
|
|
127
|
+
align?: TableCellAlignment;
|
|
128
|
+
/**
|
|
129
|
+
* Text to display when hovering over a cell. This can be useful for
|
|
130
|
+
* providing additional information about the column when the content is
|
|
131
|
+
* ellipsized to fit in the space.
|
|
132
|
+
*
|
|
133
|
+
* If set to `true`, it will use the value generated by the `cell` prop if it
|
|
134
|
+
* can be treated as a string.
|
|
135
|
+
*/
|
|
136
|
+
cellDescription?: ((props: CellContext<TableData, any>) => string) | boolean | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* When `true`, the column will be sortable.
|
|
139
|
+
* @default false
|
|
140
|
+
*/
|
|
141
|
+
enableSorting?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Text to display when hovering over the header text. This can be useful for
|
|
144
|
+
* providing additional information about the column when you want to keep the
|
|
145
|
+
* header text relatively short to manage the column width.
|
|
146
|
+
*/
|
|
147
|
+
headerDescription?: string;
|
|
70
148
|
/**
|
|
71
149
|
* Width of the column when rendered in a table. It should be a number in pixels
|
|
72
150
|
* or "auto" to allow the table to automatically adjust the width to fill
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-model.d.ts","sourceRoot":"","sources":["../../../src/Table/model/table-model.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,
|
|
1
|
+
{"version":3,"file":"table-model.d.ts","sourceRoot":"","sources":["../../../src/Table/model/table-model.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,WAAW,EACX,OAAO,EACP,iBAAiB,EACjB,YAAY,EACb,MAAM,uBAAuB,CAAC;AAG/B,oBAAY,YAAY,GAAG,SAAS,GAAG,UAAU,CAAC;AAClD,oBAAY,aAAa,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;AAEvD,oBAAY,iBAAiB,GAAG;IAC9B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,UAAU,CAAC,SAAS;IACnC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,IAAI,EAAE,SAAS,EAAE,CAAC;IAElB;;;;OAIG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@@ function calculateTableCellHeight(lineHeight, paddingY) {
|
|
|
20
20
|
/**
|
|
21
21
|
* Returns the properties to lay out the content of table cells based on the
|
|
22
22
|
* theme and density.
|
|
23
|
-
*/ export function getTableCellLayout(theme, density) {
|
|
23
|
+
*/ export function getTableCellLayout(theme, density, { isLastColumn , isFirstColumn } = {}) {
|
|
24
24
|
if (density === 'compact') {
|
|
25
25
|
const paddingY = theme.spacing(0.5);
|
|
26
|
-
const
|
|
26
|
+
const basePaddingX = theme.spacing(0.5);
|
|
27
|
+
const edgePaddingX = theme.spacing(1);
|
|
28
|
+
const paddingLeft = isFirstColumn ? edgePaddingX : basePaddingX;
|
|
29
|
+
const paddingRight = isLastColumn ? edgePaddingX : basePaddingX;
|
|
27
30
|
const lineHeight = theme.typography.body2.lineHeight;
|
|
28
31
|
return {
|
|
29
|
-
padding: `${paddingY} ${
|
|
32
|
+
padding: `${paddingY} ${paddingRight} ${paddingY} ${paddingLeft}`,
|
|
30
33
|
height: calculateTableCellHeight(lineHeight, paddingY),
|
|
31
34
|
fontSize: theme.typography.body2.fontSize,
|
|
32
35
|
lineHeight: lineHeight
|
|
@@ -34,10 +37,13 @@ function calculateTableCellHeight(lineHeight, paddingY) {
|
|
|
34
37
|
}
|
|
35
38
|
// standard density
|
|
36
39
|
const paddingY1 = theme.spacing(1);
|
|
37
|
-
const
|
|
40
|
+
const basePaddingX1 = theme.spacing(1.25);
|
|
41
|
+
const edgePaddingX1 = theme.spacing(2);
|
|
42
|
+
const paddingLeft1 = isFirstColumn ? edgePaddingX1 : basePaddingX1;
|
|
43
|
+
const paddingRight1 = isLastColumn ? edgePaddingX1 : basePaddingX1;
|
|
38
44
|
const lineHeight1 = theme.typography.body1.lineHeight;
|
|
39
45
|
return {
|
|
40
|
-
padding: `${paddingY1} ${
|
|
46
|
+
padding: `${paddingY1} ${paddingRight1} ${paddingY1} ${paddingLeft1}`,
|
|
41
47
|
height: calculateTableCellHeight(lineHeight1, paddingY1),
|
|
42
48
|
fontSize: theme.typography.body1.fontSize,
|
|
43
49
|
lineHeight: lineHeight1
|
|
@@ -46,7 +52,7 @@ function calculateTableCellHeight(lineHeight, paddingY) {
|
|
|
46
52
|
/**
|
|
47
53
|
* Takes in a perses table column and transforms it into a tanstack column.
|
|
48
54
|
*/ export function persesColumnsToTanstackColumns(columns) {
|
|
49
|
-
const tableCols = columns.map(({ width , ...otherProps })=>{
|
|
55
|
+
const tableCols = columns.map(({ width , align , headerDescription , cellDescription , enableSorting , ...otherProps })=>{
|
|
50
56
|
// Tanstack Table does not support an "auto" value to naturally size to fit
|
|
51
57
|
// the space in a table. We translate our custom "auto" setting to 0 size
|
|
52
58
|
// for these columns, so it is easy to fall back to auto when rendering.
|
|
@@ -63,7 +69,16 @@ function calculateTableCellHeight(lineHeight, paddingY) {
|
|
|
63
69
|
};
|
|
64
70
|
const result = {
|
|
65
71
|
...otherProps,
|
|
66
|
-
...sizeProps
|
|
72
|
+
...sizeProps,
|
|
73
|
+
// Default sorting to false, so it is very explicitly set per column.
|
|
74
|
+
enableSorting: !!enableSorting,
|
|
75
|
+
// Open-ended store for extra metadata in TanStack Table, so you can bake
|
|
76
|
+
// in your own features.
|
|
77
|
+
meta: {
|
|
78
|
+
align,
|
|
79
|
+
headerDescription,
|
|
80
|
+
cellDescription
|
|
81
|
+
}
|
|
67
82
|
};
|
|
68
83
|
return result;
|
|
69
84
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Table/model/table-model.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 { Theme } from '@mui/material';\nimport { AccessorKeyColumnDef, ColumnDef, CoreOptions, RowSelectionState } from '@tanstack/react-table';\nimport { CSSProperties } from 'react';\n\nexport type TableDensity = 'compact' | 'standard';\n\nexport interface TableProps<TableData> {\n /**\n * Height of the table.\n */\n height: number;\n\n /**\n * Width of the table.\n */\n width: number;\n\n /**\n * Array of data to render in the table. Each entry in the array will be\n * rendered as a row in the table.\n */\n data: TableData[];\n\n /**\n * Array of column configuration for the table. Each entry in the array will\n * be rendered as a column header and impact the rendering of cells within\n * table rows.\n */\n columns: Array<TableColumnConfig<TableData>>;\n\n /**\n * The density of the table layout. This impacts the size and space taken up\n * by content in the table (e.g. font size, padding).\n */\n density?: TableDensity;\n\n /**\n * When `true`, the first column of the table will include checkboxes.\n */\n checkboxSelection?: boolean;\n\n /**\n * State of selected rows in the table when `checkboxSelection` is enabled.\n *\n * Selected row state is a controlled value that should be managed using a\n * combination of this prop and `onRowSelectionChange`.\n */\n rowSelection?: RowSelectionState;\n\n /**\n * Callback fired when the selected rows in the table changes.\n */\n onRowSelectionChange?: (rowSelection: RowSelectionState) => void;\n\n /**\n * Function used to determine the unique identifier used for each row. This\n * value is used to key `rowSelection`. If this value is not set, the index\n * is used as the unique identifier.\n */\n getRowId?: CoreOptions<TableData>['getRowId'];\n\n /**\n * Function used to determine the color of the checkbox when `checkboxSelection`\n * is enabled. If not set, a default color is used.\n */\n getCheckboxColor?: (rowData: TableData) => string;\n}\n\nfunction calculateTableCellHeight(lineHeight: CSSProperties['lineHeight'], paddingY: string): number {\n // Doing a bunch of math to enforce height to avoid weirdness with mismatched\n // heights based on customization of cell contents.\n const lineHeightNum = typeof lineHeight === 'string' ? parseInt(lineHeight, 10) : lineHeight ?? 0;\n const verticalPaddingNum = typeof paddingY === 'string' ? parseInt(paddingY, 10) : paddingY;\n\n return lineHeightNum + verticalPaddingNum * 2;\n}\n\ntype TableCellLayout = NonNullable<Pick<React.CSSProperties, 'padding' | 'fontSize' | 'lineHeight'>> & {\n height: number;\n};\n\n/**\n * Returns the properties to lay out the content of table cells based on the\n * theme and density.\n */\nexport function getTableCellLayout(theme: Theme, density: TableDensity): TableCellLayout {\n if (density === 'compact') {\n const paddingY = theme.spacing(0.5);\n const paddingX = theme.spacing(0.25);\n const lineHeight = theme.typography.body2.lineHeight;\n\n return {\n padding: `${paddingY} ${paddingX}`,\n height: calculateTableCellHeight(lineHeight, paddingY),\n fontSize: theme.typography.body2.fontSize,\n lineHeight: lineHeight,\n };\n }\n\n // standard density\n const paddingY = theme.spacing(1);\n const paddingX = theme.spacing(1.25);\n const lineHeight = theme.typography.body1.lineHeight;\n\n return {\n padding: `${paddingY} ${paddingX}`,\n height: calculateTableCellHeight(lineHeight, paddingY),\n fontSize: theme.typography.body1.fontSize,\n lineHeight: lineHeight,\n };\n}\n\n// Only exposing a very simplified version of the very extensive column definitions\n// possible with tanstack table to make it easier for us to control rendering\n// and functionality.\nexport interface TableColumnConfig<TableData>\n // Any needed to work around some typing issues with tanstack query.\n // https://github.com/TanStack/table/issues/4241\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n extends Pick<AccessorKeyColumnDef<TableData, any>, 'accessorKey' | 'cell'> {\n /**\n * Text to display in the header for the column.\n */\n header: string;\n\n // Tanstack Table does not support an \"auto\" value to naturally size to fit\n // the space in a table. Adding a custom setting to manage this ourselves.\n /**\n * Width of the column when rendered in a table. It should be a number in pixels\n * or \"auto\" to allow the table to automatically adjust the width to fill\n * space.\n * @default 'auto'\n */\n width?: number | 'auto';\n}\n\n/**\n * Takes in a perses table column and transforms it into a tanstack column.\n */\nexport function persesColumnsToTanstackColumns<TableData>(columns: Array<TableColumnConfig<TableData>>) {\n const tableCols: Array<ColumnDef<TableData>> = columns.map(({ width, ...otherProps }) => {\n // Tanstack Table does not support an \"auto\" value to naturally size to fit\n // the space in a table. We translate our custom \"auto\" setting to 0 size\n // for these columns, so it is easy to fall back to auto when rendering.\n // Taking from a recommendation in this github discussion:\n // https://github.com/TanStack/table/discussions/4179#discussioncomment-3631326\n const sizeProps =\n width === 'auto' || width === undefined\n ? {\n // All zero values are used as shorthand for \"auto\" when rendering\n // because it makes it easy to fall back. (e.g. `row.size || \"auto\"`)\n size: 0,\n minSize: 0,\n maxSize: 0,\n }\n : {\n size: width,\n };\n\n const result = {\n ...otherProps,\n ...sizeProps,\n };\n\n return result;\n });\n\n return tableCols;\n}\n"],"names":["calculateTableCellHeight","lineHeight","paddingY","lineHeightNum","parseInt","verticalPaddingNum","getTableCellLayout","theme","density","spacing","paddingX","typography","body2","padding","height","fontSize","body1","persesColumnsToTanstackColumns","columns","tableCols","map","width","otherProps","sizeProps","undefined","size","minSize","maxSize","result"],"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;AAsEjC,SAASA,wBAAwB,CAACC,UAAuC,EAAEC,QAAgB,EAAU;IACnG,6EAA6E;IAC7E,mDAAmD;IACnD,MAAMC,aAAa,GAAG,OAAOF,UAAU,KAAK,QAAQ,GAAGG,QAAQ,CAACH,UAAU,EAAE,EAAE,CAAC,GAAGA,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAI,CAAC,AAAC;IAClG,MAAMI,kBAAkB,GAAG,OAAOH,QAAQ,KAAK,QAAQ,GAAGE,QAAQ,CAACF,QAAQ,EAAE,EAAE,CAAC,GAAGA,QAAQ,AAAC;IAE5F,OAAOC,aAAa,GAAGE,kBAAkB,GAAG,CAAC,CAAC;AAChD,CAAC;AAMD;;;CAGC,GACD,OAAO,SAASC,kBAAkB,CAACC,KAAY,EAAEC,OAAqB,EAAmB;IACvF,IAAIA,OAAO,KAAK,SAAS,EAAE;QACzB,MAAMN,QAAQ,GAAGK,KAAK,CAACE,OAAO,CAAC,GAAG,CAAC,AAAC;QACpC,MAAMC,QAAQ,GAAGH,KAAK,CAACE,OAA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C;YACPC,OAAO,EAAE,CAAC;YACVC,OAAO,EAAE,CAAC;SACX,GACD;YACEF,IAAI,EAAEJ,KAAK;SACZ,AAAC;QAER,MAAMO,MAAM,GAAG;YACb,GAAGN,UAAU;YACb,GAAGC,SAAS;SACb,AAAC;QAEF,OAAOK,MAAM,CAAC;IAChB,CAAC,CAAC,AAAC;IAEH,OAAOT,SAAS,CAAC;AACnB,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/Table/model/table-model.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 { Theme } from '@mui/material';\nimport {\n AccessorKeyColumnDef,\n CellContext,\n ColumnDef,\n CoreOptions,\n RowData,\n RowSelectionState,\n SortingState,\n} from '@tanstack/react-table';\nimport { CSSProperties } from 'react';\n\nexport type TableDensity = 'compact' | 'standard';\nexport type SortDirection = 'asc' | 'desc' | undefined;\n\nexport type TableRowEventOpts = {\n /**\n * Unique identifier for the row.\n */\n id: string;\n\n /**\n * Index of the row in the original data.\n */\n index: number;\n};\n\nexport interface TableProps<TableData> {\n /**\n * Height of the table.\n */\n height: number;\n\n /**\n * Width of the table.\n */\n width: number;\n\n /**\n * Array of data to render in the table. Each entry in the array will be\n * rendered as a row in the table.\n */\n data: TableData[];\n\n /**\n * Array of column configuration for the table. Each entry in the array will\n * be rendered as a column header and impact the rendering of cells within\n * table rows.\n */\n columns: Array<TableColumnConfig<TableData>>;\n\n /**\n * The density of the table layout. This impacts the size and space taken up\n * by content in the table (e.g. font size, padding).\n */\n density?: TableDensity;\n\n /**\n * When `true`, the first column of the table will include checkboxes.\n */\n checkboxSelection?: boolean;\n\n /**\n * Determines the behavior of row selection.\n *\n * - `standard`: clicking a checkbox will toggle that rows's selected/unselected\n * state and will not impact other rows.\n * - `legend`: clicking a checkbox will \"focus\" that row by selecting it and\n * unselecting other rows. Clicking a checkbox with a modifier key pressed,\n * will change this behavior to behave like `standard`.\n *\n * @default 'standard'\n */\n rowSelectionVariant?: 'standard' | 'legend';\n\n /**\n * State of selected rows in the table when `checkboxSelection` is enabled.\n *\n * Selected row state is a controlled value that should be managed using a\n * combination of this prop and `onRowSelectionChange`.\n */\n rowSelection?: RowSelectionState;\n\n /**\n * Callback fired when the mouse is moved over a table row.\n */\n onRowMouseOver?: (e: React.MouseEvent, opts: TableRowEventOpts) => void;\n\n /**\n * Callback fired when the mouse is moved out of a table row.\n */\n onRowMouseOut?: (e: React.MouseEvent, opts: TableRowEventOpts) => void;\n\n /**\n * State of the column sorting in the table.\n *\n * The column sorting is a controlled value that should be managed using a\n * combination fo this prop and `onSortingChange`.\n */\n sorting?: SortingState;\n\n /**\n * Callback fired when the selected rows in the table changes.\n */\n onRowSelectionChange?: (rowSelection: RowSelectionState) => void;\n\n /**\n * Callback fired when the table sorting changes.\n */\n onSortingChange?: (sorting: SortingState) => void;\n\n /**\n * Function used to determine the unique identifier used for each row. This\n * value is used to key `rowSelection`. If this value is not set, the index\n * is used as the unique identifier.\n */\n getRowId?: CoreOptions<TableData>['getRowId'];\n\n /**\n * Function used to determine the color of the checkbox when `checkboxSelection`\n * is enabled. If not set, a default color is used.\n */\n getCheckboxColor?: (rowData: TableData) => string;\n}\n\nfunction calculateTableCellHeight(lineHeight: CSSProperties['lineHeight'], paddingY: string): number {\n // Doing a bunch of math to enforce height to avoid weirdness with mismatched\n // heights based on customization of cell contents.\n const lineHeightNum = typeof lineHeight === 'string' ? parseInt(lineHeight, 10) : lineHeight ?? 0;\n const verticalPaddingNum = typeof paddingY === 'string' ? parseInt(paddingY, 10) : paddingY;\n\n return lineHeightNum + verticalPaddingNum * 2;\n}\n\ntype TableCellLayout = NonNullable<Pick<React.CSSProperties, 'padding' | 'fontSize' | 'lineHeight'>> & {\n height: number;\n};\n\ntype GetTableCellLayoutOpts = {\n isLastColumn?: boolean;\n isFirstColumn?: boolean;\n};\n\n/**\n * Returns the properties to lay out the content of table cells based on the\n * theme and density.\n */\nexport function getTableCellLayout(\n theme: Theme,\n density: TableDensity,\n { isLastColumn, isFirstColumn }: GetTableCellLayoutOpts = {}\n): TableCellLayout {\n if (density === 'compact') {\n const paddingY = theme.spacing(0.5);\n\n const basePaddingX = theme.spacing(0.5);\n const edgePaddingX = theme.spacing(1);\n const paddingLeft = isFirstColumn ? edgePaddingX : basePaddingX;\n const paddingRight = isLastColumn ? edgePaddingX : basePaddingX;\n\n const lineHeight = theme.typography.body2.lineHeight;\n\n return {\n padding: `${paddingY} ${paddingRight} ${paddingY} ${paddingLeft}`,\n height: calculateTableCellHeight(lineHeight, paddingY),\n fontSize: theme.typography.body2.fontSize,\n lineHeight: lineHeight,\n };\n }\n\n // standard density\n const paddingY = theme.spacing(1);\n const basePaddingX = theme.spacing(1.25);\n const edgePaddingX = theme.spacing(2);\n const paddingLeft = isFirstColumn ? edgePaddingX : basePaddingX;\n const paddingRight = isLastColumn ? edgePaddingX : basePaddingX;\n const lineHeight = theme.typography.body1.lineHeight;\n\n return {\n padding: `${paddingY} ${paddingRight} ${paddingY} ${paddingLeft}`,\n height: calculateTableCellHeight(lineHeight, paddingY),\n fontSize: theme.typography.body1.fontSize,\n lineHeight: lineHeight,\n };\n}\n\nexport type TableCellAlignment = 'left' | 'right' | 'center';\n\n// Overrides of meta value, so it can have a meaningful type in our code instead\n// of `any`. Putting this in the model instead of a separate .d.ts file because\n// I couldn't get it to work properly that way and punted on figuring it out\n// after trying several things.\ndeclare module '@tanstack/table-core' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface ColumnMeta<TData extends RowData, TValue> {\n align?: TableColumnConfig<TData>['align'];\n headerDescription?: TableColumnConfig<TData>['headerDescription'];\n cellDescription?: TableColumnConfig<TData>['cellDescription'];\n }\n}\n\n// Only exposing a very simplified version of the very extensive column definitions\n// possible with tanstack table to make it easier for us to control rendering\n// and functionality.\nexport interface TableColumnConfig<TableData>\n // Any needed to work around some typing issues with tanstack query.\n // https://github.com/TanStack/table/issues/4241\n // TODO: revisit issue thread and see if there are any workarounds we can\n // use.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n extends Pick<AccessorKeyColumnDef<TableData, any>, 'accessorKey' | 'cell' | 'sortingFn'> {\n /**\n * Text to display in the header for the column.\n */\n header: string;\n\n /**\n * Alignment of the content in the cell.\n */\n align?: TableCellAlignment;\n\n /**\n * Text to display when hovering over a cell. This can be useful for\n * providing additional information about the column when the content is\n * ellipsized to fit in the space.\n *\n * If set to `true`, it will use the value generated by the `cell` prop if it\n * can be treated as a string.\n */\n // `any` needed for same reason as no-explicit-any higher up in this type.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n cellDescription?: ((props: CellContext<TableData, any>) => string) | boolean | undefined;\n\n /**\n * When `true`, the column will be sortable.\n * @default false\n */\n enableSorting?: boolean;\n\n /**\n * Text to display when hovering over the header text. This can be useful for\n * providing additional information about the column when you want to keep the\n * header text relatively short to manage the column width.\n */\n headerDescription?: string;\n\n // Tanstack Table does not support an \"auto\" value to naturally size to fit\n // the space in a table. Adding a custom setting to manage this ourselves.\n /**\n * Width of the column when rendered in a table. It should be a number in pixels\n * or \"auto\" to allow the table to automatically adjust the width to fill\n * space.\n * @default 'auto'\n */\n width?: number | 'auto';\n}\n\n/**\n * Takes in a perses table column and transforms it into a tanstack column.\n */\nexport function persesColumnsToTanstackColumns<TableData>(columns: Array<TableColumnConfig<TableData>>) {\n const tableCols: Array<ColumnDef<TableData>> = columns.map(\n ({ width, align, headerDescription, cellDescription, enableSorting, ...otherProps }) => {\n // Tanstack Table does not support an \"auto\" value to naturally size to fit\n // the space in a table. We translate our custom \"auto\" setting to 0 size\n // for these columns, so it is easy to fall back to auto when rendering.\n // Taking from a recommendation in this github discussion:\n // https://github.com/TanStack/table/discussions/4179#discussioncomment-3631326\n const sizeProps =\n width === 'auto' || width === undefined\n ? {\n // All zero values are used as shorthand for \"auto\" when rendering\n // because it makes it easy to fall back. (e.g. `row.size || \"auto\"`)\n size: 0,\n minSize: 0,\n maxSize: 0,\n }\n : {\n size: width,\n };\n\n const result = {\n ...otherProps,\n ...sizeProps,\n\n // Default sorting to false, so it is very explicitly set per column.\n enableSorting: !!enableSorting,\n\n // Open-ended store for extra metadata in TanStack Table, so you can bake\n // in your own features.\n meta: {\n align,\n headerDescription,\n cellDescription,\n },\n };\n\n return result;\n }\n );\n\n return tableCols;\n}\n"],"names":["calculateTableCellHeight","lineHeight","paddingY","lineHeightNum","parseInt","verticalPaddingNum","getTableCellLayout","theme","density","isLastColumn","isFirstColumn","spacing","basePaddingX","edgePaddingX","paddingLeft","paddingRight","typography","body2","padding","height","fontSize","body1","persesColumnsToTanstackColumns","columns","tableCols","map","width","align","headerDescription","cellDescription","enableSorting","otherProps","sizeProps","undefined","size","minSize","maxSize","result","meta"],"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;AA+HjC,SAASA,wBAAwB,CAACC,UAAuC,EAAEC,QAAgB,EAAU;IACnG,6EAA6E;IAC7E,mDAAmD;IACnD,MAAMC,aAAa,GAAG,OAAOF,UAAU,KAAK,QAAQ,GAAGG,QAAQ,CAACH,UAAU,EAAE,EAAE,CAAC,GAAGA,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAI,CAAC,AAAC;IAClG,MAAMI,kBAAkB,GAAG,OAAOH,QAAQ,KAAK,QAAQ,GAAGE,QAAQ,CAACF,QAAQ,EAAE,EAAE,CAAC,GAAGA,QAAQ,AAAC;IAE5F,OAAOC,aAAa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B;SACF,AAAC;QAEF,OAAOQ,MAAM,CAAC;IAChB,CAAC,CACF,AAAC;IAEF,OAAOb,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MouseEvent } from 'react';
|
|
2
|
+
import { TimeScale, UnitOptions, TimeSeries } from '@perses-dev/core';
|
|
3
|
+
import type { EChartsCoreOption, GridComponentOption, YAXisComponentOption } from 'echarts';
|
|
4
|
+
import { ChartHandle, TimeChartSeriesMapping } from '../model/graph';
|
|
5
|
+
import { ZoomEventData } from '../utils';
|
|
6
|
+
import { TooltipConfig } from '../TimeSeriesTooltip';
|
|
7
|
+
export interface TimeChartProps {
|
|
8
|
+
height: number;
|
|
9
|
+
data: TimeSeries[];
|
|
10
|
+
seriesMapping: TimeChartSeriesMapping;
|
|
11
|
+
timeScale?: TimeScale;
|
|
12
|
+
yAxis?: YAXisComponentOption;
|
|
13
|
+
unit?: UnitOptions;
|
|
14
|
+
grid?: GridComponentOption;
|
|
15
|
+
tooltipConfig?: TooltipConfig;
|
|
16
|
+
noDataVariant?: 'chart' | 'message';
|
|
17
|
+
syncGroup?: string;
|
|
18
|
+
onDataZoom?: (e: ZoomEventData) => void;
|
|
19
|
+
onDoubleClick?: (e: MouseEvent) => void;
|
|
20
|
+
__experimentalEChartsOptionsOverride?: (options: EChartsCoreOption) => EChartsCoreOption;
|
|
21
|
+
}
|
|
22
|
+
export declare const TimeChart: import("react").ForwardRefExoticComponent<TimeChartProps & import("react").RefAttributes<ChartHandle>>;
|
|
23
|
+
//# sourceMappingURL=TimeChart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeChart.d.ts","sourceRoot":"","sources":["../../src/TimeChart/TimeChart.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAc,UAAU,EAAkD,MAAM,OAAO,CAAC;AAG/F,OAAO,EAAsB,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EAEnB,oBAAoB,EAErB,MAAM,SAAS,CAAC;AAiBjB,OAAO,EAAwB,WAAW,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAE3F,OAAO,EAML,aAAa,EACd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAuC,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAkB1F,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,aAAa,EAAE,sBAAsB,CAAC;IACtC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,CAAC,EAAE,mBAAmB,CAAC;IAC3B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IACxC,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IACxC,oCAAoC,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,iBAAiB,CAAC;CAC1F;AAED,eAAO,MAAM,SAAS,wGAsRpB,CAAC"}
|
|
@@ -0,0 +1,314 @@
|
|
|
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 { forwardRef, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
15
|
+
import { Box } from '@mui/material';
|
|
16
|
+
import { utcToZonedTime } from 'date-fns-tz';
|
|
17
|
+
import { getCommonTimeScale } from '@perses-dev/core';
|
|
18
|
+
import { use } from 'echarts/core';
|
|
19
|
+
import { LineChart as EChartsLineChart } from 'echarts/charts';
|
|
20
|
+
import { GridComponent, DatasetComponent, DataZoomComponent, MarkAreaComponent, MarkLineComponent, MarkPointComponent, TitleComponent, ToolboxComponent, TooltipComponent, LegendComponent } from 'echarts/components';
|
|
21
|
+
import { CanvasRenderer } from 'echarts/renderers';
|
|
22
|
+
import { EChart } from '../EChart';
|
|
23
|
+
import { useChartsTheme } from '../context/ChartsThemeProvider';
|
|
24
|
+
import { clearHighlightedSeries, enableDataZoom, getFormattedAxisLabel, getYAxes, restoreChart } from '../utils';
|
|
25
|
+
import { TimeChartTooltip } from '../TimeSeriesTooltip';
|
|
26
|
+
import { useTimeZone } from '../context/TimeZoneProvider';
|
|
27
|
+
use([
|
|
28
|
+
EChartsLineChart,
|
|
29
|
+
GridComponent,
|
|
30
|
+
DatasetComponent,
|
|
31
|
+
DataZoomComponent,
|
|
32
|
+
MarkAreaComponent,
|
|
33
|
+
MarkLineComponent,
|
|
34
|
+
MarkPointComponent,
|
|
35
|
+
TitleComponent,
|
|
36
|
+
ToolboxComponent,
|
|
37
|
+
TooltipComponent,
|
|
38
|
+
LegendComponent,
|
|
39
|
+
CanvasRenderer
|
|
40
|
+
]);
|
|
41
|
+
export const TimeChart = /*#__PURE__*/ forwardRef(function TimeChart({ height , data , seriesMapping , timeScale: timeScaleProp , yAxis , unit , grid , tooltipConfig ={
|
|
42
|
+
wrapLabels: true
|
|
43
|
+
} , noDataVariant ='message' , syncGroup , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride , }, ref) {
|
|
44
|
+
var ref1;
|
|
45
|
+
const chartsTheme = useChartsTheme();
|
|
46
|
+
const chartRef = useRef();
|
|
47
|
+
const [showTooltip, setShowTooltip] = useState(true);
|
|
48
|
+
const [tooltipPinnedCoords, setTooltipPinnedCoords] = useState(null);
|
|
49
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
50
|
+
const [startX, setStartX] = useState(0);
|
|
51
|
+
const { timeZone } = useTimeZone();
|
|
52
|
+
var ref2;
|
|
53
|
+
const totalSeries = (ref2 = data === null || data === void 0 ? void 0 : data.length) !== null && ref2 !== void 0 ? ref2 : 0;
|
|
54
|
+
let timeScale;
|
|
55
|
+
if (timeScaleProp === undefined) {
|
|
56
|
+
const commonTimeScale = getCommonTimeScale(data);
|
|
57
|
+
if (commonTimeScale === undefined) {
|
|
58
|
+
// set default to past 5 years
|
|
59
|
+
const today = new Date();
|
|
60
|
+
const pastDate = new Date(today);
|
|
61
|
+
pastDate.setFullYear(today.getFullYear() - 5);
|
|
62
|
+
const todayMs = today.getTime();
|
|
63
|
+
const pastDateMs = pastDate.getTime();
|
|
64
|
+
timeScale = {
|
|
65
|
+
startMs: pastDateMs,
|
|
66
|
+
endMs: todayMs,
|
|
67
|
+
stepMs: 1,
|
|
68
|
+
rangeMs: todayMs - pastDateMs
|
|
69
|
+
};
|
|
70
|
+
} else {
|
|
71
|
+
timeScale = commonTimeScale;
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
timeScale = timeScaleProp;
|
|
75
|
+
}
|
|
76
|
+
useImperativeHandle(ref, ()=>{
|
|
77
|
+
return {
|
|
78
|
+
highlightSeries ({ name }) {
|
|
79
|
+
if (!chartRef.current) {
|
|
80
|
+
// No chart. Do nothing.
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
chartRef.current.dispatchAction({
|
|
84
|
+
type: 'highlight',
|
|
85
|
+
seriesId: name
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
clearHighlightedSeries: ()=>{
|
|
89
|
+
if (!chartRef.current) {
|
|
90
|
+
// No chart. Do nothing.
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
clearHighlightedSeries(chartRef.current, totalSeries);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}, [
|
|
97
|
+
totalSeries
|
|
98
|
+
]);
|
|
99
|
+
const handleEvents = useMemo(()=>{
|
|
100
|
+
return {
|
|
101
|
+
datazoom: (params)=>{
|
|
102
|
+
if (onDataZoom === undefined) {
|
|
103
|
+
setTimeout(()=>{
|
|
104
|
+
// workaround so unpin happens after click event
|
|
105
|
+
setTooltipPinnedCoords(null);
|
|
106
|
+
}, 10);
|
|
107
|
+
}
|
|
108
|
+
if (onDataZoom === undefined || params.batch[0] === undefined) return;
|
|
109
|
+
const xAxisStartValue = params.batch[0].startValue;
|
|
110
|
+
const xAxisEndValue = params.batch[0].endValue;
|
|
111
|
+
if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {
|
|
112
|
+
const zoomEvent = {
|
|
113
|
+
start: xAxisStartValue,
|
|
114
|
+
end: xAxisEndValue
|
|
115
|
+
};
|
|
116
|
+
onDataZoom(zoomEvent);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}, [
|
|
121
|
+
onDataZoom,
|
|
122
|
+
setTooltipPinnedCoords
|
|
123
|
+
]);
|
|
124
|
+
if (chartRef.current !== undefined) {
|
|
125
|
+
enableDataZoom(chartRef.current);
|
|
126
|
+
}
|
|
127
|
+
const { noDataOption } = chartsTheme;
|
|
128
|
+
const option = useMemo(()=>{
|
|
129
|
+
// TODO: fix loading state and noData variants
|
|
130
|
+
// if (data === undefined) return {};
|
|
131
|
+
// The "chart" `noDataVariant` is only used when the `timeSeries` is an
|
|
132
|
+
// empty array because a `null` value will throw an error.
|
|
133
|
+
if (data === null || data.length === 0 && noDataVariant === 'message') return noDataOption;
|
|
134
|
+
// Utilizes ECharts dataset so raw data is separate from series option style properties
|
|
135
|
+
// https://apache.github.io/echarts-handbook/en/concepts/dataset/
|
|
136
|
+
const dataset = [];
|
|
137
|
+
const isLocalTimeZone = timeZone === 'local';
|
|
138
|
+
data.map((d, index)=>{
|
|
139
|
+
const values = d.values.map(([timestamp, value])=>{
|
|
140
|
+
const val = value === null ? '-' : value; // echarts use '-' to represent null data
|
|
141
|
+
return [
|
|
142
|
+
isLocalTimeZone ? timestamp : utcToZonedTime(timestamp, timeZone),
|
|
143
|
+
val
|
|
144
|
+
];
|
|
145
|
+
});
|
|
146
|
+
dataset.push({
|
|
147
|
+
id: index,
|
|
148
|
+
source: [
|
|
149
|
+
...values
|
|
150
|
+
],
|
|
151
|
+
dimensions: [
|
|
152
|
+
'time',
|
|
153
|
+
'value'
|
|
154
|
+
]
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
var _rangeMs;
|
|
158
|
+
const option = {
|
|
159
|
+
dataset: dataset,
|
|
160
|
+
series: seriesMapping,
|
|
161
|
+
xAxis: {
|
|
162
|
+
type: 'time',
|
|
163
|
+
min: isLocalTimeZone ? timeScale.startMs : utcToZonedTime(timeScale.startMs, timeZone),
|
|
164
|
+
max: isLocalTimeZone ? timeScale.endMs : utcToZonedTime(timeScale.endMs, timeZone),
|
|
165
|
+
axisLabel: {
|
|
166
|
+
hideOverlap: true,
|
|
167
|
+
formatter: getFormattedAxisLabel((_rangeMs = timeScale.rangeMs) !== null && _rangeMs !== void 0 ? _rangeMs : 0)
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
yAxis: getYAxes(yAxis, unit),
|
|
171
|
+
animation: false,
|
|
172
|
+
tooltip: {
|
|
173
|
+
show: true,
|
|
174
|
+
trigger: 'axis',
|
|
175
|
+
showContent: false
|
|
176
|
+
},
|
|
177
|
+
// https://echarts.apache.org/en/option.html#axisPointer
|
|
178
|
+
axisPointer: {
|
|
179
|
+
type: 'line',
|
|
180
|
+
z: 0,
|
|
181
|
+
triggerEmphasis: false,
|
|
182
|
+
triggerTooltip: false,
|
|
183
|
+
snap: true
|
|
184
|
+
},
|
|
185
|
+
toolbox: {
|
|
186
|
+
feature: {
|
|
187
|
+
dataZoom: {
|
|
188
|
+
icon: null,
|
|
189
|
+
yAxisIndex: 'none'
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
grid
|
|
194
|
+
};
|
|
195
|
+
if (__experimentalEChartsOptionsOverride) {
|
|
196
|
+
return __experimentalEChartsOptionsOverride(option);
|
|
197
|
+
}
|
|
198
|
+
return option;
|
|
199
|
+
}, [
|
|
200
|
+
data,
|
|
201
|
+
seriesMapping,
|
|
202
|
+
timeScale,
|
|
203
|
+
yAxis,
|
|
204
|
+
unit,
|
|
205
|
+
grid,
|
|
206
|
+
noDataOption,
|
|
207
|
+
__experimentalEChartsOptionsOverride,
|
|
208
|
+
noDataVariant,
|
|
209
|
+
timeZone
|
|
210
|
+
]);
|
|
211
|
+
return /*#__PURE__*/ _jsxs(Box, {
|
|
212
|
+
sx: {
|
|
213
|
+
height
|
|
214
|
+
},
|
|
215
|
+
onClick: (e)=>{
|
|
216
|
+
// Pin and unpin when clicking on chart canvas but not tooltip text.
|
|
217
|
+
if (e.target instanceof HTMLCanvasElement) {
|
|
218
|
+
setTooltipPinnedCoords((current)=>{
|
|
219
|
+
if (current === null) {
|
|
220
|
+
return {
|
|
221
|
+
page: {
|
|
222
|
+
x: e.pageX,
|
|
223
|
+
y: e.pageY
|
|
224
|
+
},
|
|
225
|
+
client: {
|
|
226
|
+
x: e.clientX,
|
|
227
|
+
y: e.clientY
|
|
228
|
+
},
|
|
229
|
+
plotCanvas: {
|
|
230
|
+
x: e.nativeEvent.offsetX,
|
|
231
|
+
y: e.nativeEvent.offsetY
|
|
232
|
+
},
|
|
233
|
+
target: e.target
|
|
234
|
+
};
|
|
235
|
+
} else {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
onMouseDown: (e)=>{
|
|
242
|
+
const { clientX } = e;
|
|
243
|
+
setIsDragging(true);
|
|
244
|
+
setStartX(clientX);
|
|
245
|
+
},
|
|
246
|
+
onMouseMove: (e)=>{
|
|
247
|
+
// Allow clicking inside tooltip to copy labels.
|
|
248
|
+
if (!(e.target instanceof HTMLCanvasElement)) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const { clientX } = e;
|
|
252
|
+
if (isDragging) {
|
|
253
|
+
const deltaX = clientX - startX;
|
|
254
|
+
if (deltaX > 0) {
|
|
255
|
+
// Hide tooltip when user drags to zoom.
|
|
256
|
+
setShowTooltip(false);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
onMouseUp: ()=>{
|
|
261
|
+
setIsDragging(false);
|
|
262
|
+
setStartX(0);
|
|
263
|
+
setShowTooltip(true);
|
|
264
|
+
},
|
|
265
|
+
onMouseLeave: ()=>{
|
|
266
|
+
if (tooltipPinnedCoords === null) {
|
|
267
|
+
setShowTooltip(false);
|
|
268
|
+
}
|
|
269
|
+
if (chartRef.current !== undefined) {
|
|
270
|
+
clearHighlightedSeries(chartRef.current, totalSeries);
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
onMouseEnter: ()=>{
|
|
274
|
+
setShowTooltip(true);
|
|
275
|
+
if (chartRef.current !== undefined) {
|
|
276
|
+
enableDataZoom(chartRef.current);
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
onDoubleClick: (e)=>{
|
|
280
|
+
setTooltipPinnedCoords(null);
|
|
281
|
+
// either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
|
|
282
|
+
if (onDoubleClick === undefined) {
|
|
283
|
+
if (chartRef.current !== undefined) {
|
|
284
|
+
restoreChart(chartRef.current);
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
onDoubleClick(e);
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
children: [
|
|
291
|
+
showTooltip === true && ((ref1 = option.tooltip) === null || ref1 === void 0 ? void 0 : ref1.showContent) === false && tooltipConfig.hidden !== true && /*#__PURE__*/ _jsx(TimeChartTooltip, {
|
|
292
|
+
chartRef: chartRef,
|
|
293
|
+
data: data,
|
|
294
|
+
seriesMapping: seriesMapping,
|
|
295
|
+
wrapLabels: tooltipConfig.wrapLabels,
|
|
296
|
+
pinnedPos: tooltipPinnedCoords,
|
|
297
|
+
unit: unit
|
|
298
|
+
}),
|
|
299
|
+
/*#__PURE__*/ _jsx(EChart, {
|
|
300
|
+
sx: {
|
|
301
|
+
width: '100%',
|
|
302
|
+
height: '100%'
|
|
303
|
+
},
|
|
304
|
+
option: option,
|
|
305
|
+
theme: chartsTheme.echartsTheme,
|
|
306
|
+
onEvents: handleEvents,
|
|
307
|
+
_instance: chartRef,
|
|
308
|
+
syncGroup: syncGroup
|
|
309
|
+
})
|
|
310
|
+
]
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
//# sourceMappingURL=TimeChart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/TimeChart/TimeChart.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 { DatasetOption } from 'echarts/types/dist/shared';\nimport { forwardRef, MouseEvent, useImperativeHandle, useMemo, useRef, useState } from 'react';\nimport { Box } from '@mui/material';\nimport { utcToZonedTime } from 'date-fns-tz';\nimport { getCommonTimeScale, TimeScale, UnitOptions, TimeSeries } from '@perses-dev/core';\nimport type {\n EChartsCoreOption,\n GridComponentOption,\n LineSeriesOption,\n YAXisComponentOption,\n TooltipComponentOption,\n} from 'echarts';\nimport { ECharts as EChartsInstance, use } from 'echarts/core';\nimport { LineChart as EChartsLineChart } from 'echarts/charts';\nimport {\n GridComponent,\n DatasetComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, OnEventsType } from '../EChart';\nimport { ChartHandleFocusOpts, ChartHandle, TimeChartSeriesMapping } from '../model/graph';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport {\n clearHighlightedSeries,\n enableDataZoom,\n getFormattedAxisLabel,\n getYAxes,\n restoreChart,\n ZoomEventData,\n} from '../utils';\nimport { CursorCoordinates, TimeChartTooltip, TooltipConfig } from '../TimeSeriesTooltip';\nimport { useTimeZone } from '../context/TimeZoneProvider';\n\nuse([\n EChartsLineChart,\n GridComponent,\n DatasetComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n CanvasRenderer,\n]);\n\nexport interface TimeChartProps {\n height: number;\n data: TimeSeries[];\n seriesMapping: TimeChartSeriesMapping;\n timeScale?: TimeScale;\n yAxis?: YAXisComponentOption;\n unit?: UnitOptions;\n grid?: GridComponentOption;\n tooltipConfig?: TooltipConfig;\n noDataVariant?: 'chart' | 'message';\n syncGroup?: string;\n onDataZoom?: (e: ZoomEventData) => void;\n onDoubleClick?: (e: MouseEvent) => void;\n __experimentalEChartsOptionsOverride?: (options: EChartsCoreOption) => EChartsCoreOption;\n}\n\nexport const TimeChart = forwardRef<ChartHandle, TimeChartProps>(function TimeChart(\n {\n height,\n data,\n seriesMapping,\n timeScale: timeScaleProp,\n yAxis,\n unit,\n grid,\n tooltipConfig = { wrapLabels: true },\n noDataVariant = 'message',\n syncGroup,\n onDataZoom,\n onDoubleClick,\n __experimentalEChartsOptionsOverride,\n },\n ref\n) {\n const chartsTheme = useChartsTheme();\n const chartRef = useRef<EChartsInstance>();\n const [showTooltip, setShowTooltip] = useState<boolean>(true);\n const [tooltipPinnedCoords, setTooltipPinnedCoords] = useState<CursorCoordinates | null>(null);\n const [isDragging, setIsDragging] = useState(false);\n const [startX, setStartX] = useState(0);\n const { timeZone } = useTimeZone();\n const totalSeries = data?.length ?? 0;\n\n let timeScale: TimeScale;\n if (timeScaleProp === undefined) {\n const commonTimeScale = getCommonTimeScale(data);\n if (commonTimeScale === undefined) {\n // set default to past 5 years\n const today = new Date();\n const pastDate = new Date(today);\n pastDate.setFullYear(today.getFullYear() - 5);\n const todayMs = today.getTime();\n const pastDateMs = pastDate.getTime();\n timeScale = { startMs: pastDateMs, endMs: todayMs, stepMs: 1, rangeMs: todayMs - pastDateMs };\n } else {\n timeScale = commonTimeScale;\n }\n } else {\n timeScale = timeScaleProp;\n }\n\n useImperativeHandle(\n ref,\n () => {\n return {\n highlightSeries({ name }: ChartHandleFocusOpts) {\n if (!chartRef.current) {\n // No chart. Do nothing.\n return;\n }\n\n chartRef.current.dispatchAction({ type: 'highlight', seriesId: name });\n },\n clearHighlightedSeries: () => {\n if (!chartRef.current) {\n // No chart. Do nothing.\n return;\n }\n clearHighlightedSeries(chartRef.current, totalSeries);\n },\n };\n },\n [totalSeries]\n );\n\n const handleEvents: OnEventsType<LineSeriesOption['data'] | unknown> = useMemo(() => {\n return {\n datazoom: (params) => {\n if (onDataZoom === undefined) {\n setTimeout(() => {\n // workaround so unpin happens after click event\n setTooltipPinnedCoords(null);\n }, 10);\n }\n if (onDataZoom === undefined || params.batch[0] === undefined) return;\n const xAxisStartValue = params.batch[0].startValue;\n const xAxisEndValue = params.batch[0].endValue;\n if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {\n const zoomEvent: ZoomEventData = {\n start: xAxisStartValue,\n end: xAxisEndValue,\n };\n onDataZoom(zoomEvent);\n }\n },\n };\n }, [onDataZoom, setTooltipPinnedCoords]);\n\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n\n const { noDataOption } = chartsTheme;\n\n const option: EChartsCoreOption = useMemo(() => {\n // TODO: fix loading state and noData variants\n // if (data === undefined) return {};\n\n // The \"chart\" `noDataVariant` is only used when the `timeSeries` is an\n // empty array because a `null` value will throw an error.\n if (data === null || (data.length === 0 && noDataVariant === 'message')) return noDataOption;\n\n // Utilizes ECharts dataset so raw data is separate from series option style properties\n // https://apache.github.io/echarts-handbook/en/concepts/dataset/\n const dataset: DatasetOption[] = [];\n const isLocalTimeZone = timeZone === 'local';\n data.map((d, index) => {\n const values = d.values.map(([timestamp, value]) => {\n const val: string | number = value === null ? '-' : value; // echarts use '-' to represent null data\n return [isLocalTimeZone ? timestamp : utcToZonedTime(timestamp, timeZone), val];\n });\n dataset.push({ id: index, source: [...values], dimensions: ['time', 'value'] });\n });\n\n const option: EChartsCoreOption = {\n dataset: dataset,\n series: seriesMapping,\n xAxis: {\n type: 'time',\n min: isLocalTimeZone ? timeScale.startMs : utcToZonedTime(timeScale.startMs, timeZone),\n max: isLocalTimeZone ? timeScale.endMs : utcToZonedTime(timeScale.endMs, timeZone),\n axisLabel: {\n hideOverlap: true,\n formatter: getFormattedAxisLabel(timeScale.rangeMs ?? 0),\n },\n },\n yAxis: getYAxes(yAxis, unit),\n animation: false,\n tooltip: {\n show: true,\n trigger: 'axis',\n showContent: false, // echarts tooltip content hidden since we use custom tooltip instead\n },\n // https://echarts.apache.org/en/option.html#axisPointer\n axisPointer: {\n type: 'line',\n z: 0, // ensure point symbol shows on top of dashed line\n triggerEmphasis: false, // https://github.com/apache/echarts/issues/18495\n triggerTooltip: false,\n snap: true,\n },\n toolbox: {\n feature: {\n dataZoom: {\n icon: null, // https://stackoverflow.com/a/67684076/17575201\n yAxisIndex: 'none',\n },\n },\n },\n grid,\n };\n\n if (__experimentalEChartsOptionsOverride) {\n return __experimentalEChartsOptionsOverride(option);\n }\n return option;\n }, [\n data,\n seriesMapping,\n timeScale,\n yAxis,\n unit,\n grid,\n noDataOption,\n __experimentalEChartsOptionsOverride,\n noDataVariant,\n timeZone,\n ]);\n\n return (\n <Box\n sx={{ height }}\n onClick={(e) => {\n // Pin and unpin when clicking on chart canvas but not tooltip text.\n if (e.target instanceof HTMLCanvasElement) {\n setTooltipPinnedCoords((current) => {\n if (current === null) {\n return {\n page: {\n x: e.pageX,\n y: e.pageY,\n },\n client: {\n x: e.clientX,\n y: e.clientY,\n },\n plotCanvas: {\n x: e.nativeEvent.offsetX,\n y: e.nativeEvent.offsetY,\n },\n target: e.target,\n };\n } else {\n return null;\n }\n });\n }\n }}\n onMouseDown={(e) => {\n const { clientX } = e;\n setIsDragging(true);\n setStartX(clientX);\n }}\n onMouseMove={(e) => {\n // Allow clicking inside tooltip to copy labels.\n if (!(e.target instanceof HTMLCanvasElement)) {\n return;\n }\n const { clientX } = e;\n if (isDragging) {\n const deltaX = clientX - startX;\n if (deltaX > 0) {\n // Hide tooltip when user drags to zoom.\n setShowTooltip(false);\n }\n }\n }}\n onMouseUp={() => {\n setIsDragging(false);\n setStartX(0);\n setShowTooltip(true);\n }}\n onMouseLeave={() => {\n if (tooltipPinnedCoords === null) {\n setShowTooltip(false);\n }\n if (chartRef.current !== undefined) {\n clearHighlightedSeries(chartRef.current, totalSeries);\n }\n }}\n onMouseEnter={() => {\n setShowTooltip(true);\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n }}\n onDoubleClick={(e) => {\n setTooltipPinnedCoords(null);\n // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior\n if (onDoubleClick === undefined) {\n if (chartRef.current !== undefined) {\n restoreChart(chartRef.current);\n }\n } else {\n onDoubleClick(e);\n }\n }}\n >\n {/* Allows overrides prop to hide custom tooltip and use the ECharts option.tooltip instead */}\n {showTooltip === true &&\n (option.tooltip as TooltipComponentOption)?.showContent === false &&\n tooltipConfig.hidden !== true && (\n <TimeChartTooltip\n chartRef={chartRef}\n data={data}\n seriesMapping={seriesMapping}\n wrapLabels={tooltipConfig.wrapLabels}\n pinnedPos={tooltipPinnedCoords}\n unit={unit}\n />\n )}\n <EChart\n sx={{\n width: '100%',\n height: '100%',\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n onEvents={handleEvents}\n _instance={chartRef}\n syncGroup={syncGroup}\n />\n </Box>\n );\n});\n"],"names":["forwardRef","useImperativeHandle","useMemo","useRef","useState","Box","utcToZonedTime","getCommonTimeScale","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","DataZoomComponent","MarkAreaComponent","MarkLineComponent","MarkPointComponent","TitleComponent","ToolboxComponent","TooltipComponent","LegendComponent","CanvasRenderer","EChart","useChartsTheme","clearHighlightedSeries","enableDataZoom","getFormattedAxisLabel","getYAxes","restoreChart","TimeChartTooltip","useTimeZone","TimeChart","height","data","seriesMapping","timeScale","timeScaleProp","yAxis","unit","grid","tooltipConfig","wrapLabels","noDataVariant","syncGroup","onDataZoom","onDoubleClick","__experimentalEChartsOptionsOverride","ref","option","chartsTheme","chartRef","showTooltip","setShowTooltip","tooltipPinnedCoords","setTooltipPinnedCoords","isDragging","setIsDragging","startX","setStartX","timeZone","totalSeries","length","undefined","commonTimeScale","today","Date","pastDate","setFullYear","getFullYear","todayMs","getTime","pastDateMs","startMs","endMs","stepMs","rangeMs","highlightSeries","name","current","dispatchAction","type","seriesId","handleEvents","datazoom","params","setTimeout","batch","xAxisStartValue","startValue","xAxisEndValue","endValue","zoomEvent","start","end","noDataOption","dataset","isLocalTimeZone","map","d","index","values","timestamp","value","val","push","id","source","dimensions","series","xAxis","min","max","axisLabel","hideOverlap","formatter","animation","tooltip","show","trigger","showContent","axisPointer","z","triggerEmphasis","triggerTooltip","snap","toolbox","feature","dataZoom","icon","yAxisIndex","sx","onClick","e","target","HTMLCanvasElement","page","x","pageX","y","pageY","client","clientX","clientY","plotCanvas","nativeEvent","offsetX","offsetY","onMouseDown","onMouseMove","deltaX","onMouseUp","onMouseLeave","onMouseEnter","hidden","pinnedPos","width","theme","echartsTheme","onEvents","_instance"],"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;AACA,SAASA,UAAU,EAAcC,mBAAmB,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAC/F,SAASC,GAAG,QAAQ,eAAe,CAAC;AACpC,SAASC,cAAc,QAAQ,aAAa,CAAC;AAC7C,SAASC,kBAAkB,QAA4C,kBAAkB,CAAC;AAQ1F,SAAqCC,GAAG,QAAQ,cAAc,CAAC;AAC/D,SAASC,SAAS,IAAIC,gBAAgB,QAAQ,gBAAgB,CAAC;AAC/D,SACEC,aAAa,EACbC,gBAAgB,EAChBC,iBAAiB,EACjBC,iBAAiB,EACjBC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,EACdC,gBAAgB,EAChBC,gBAAgB,EAChBC,eAAe,QACV,oBAAoB,CAAC;AAC5B,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,MAAM,QAAsB,WAAW,CAAC;AAEjD,SAASC,cAAc,QAAQ,gCAAgC,CAAC;AAChE,SACEC,sBAAsB,EACtBC,cAAc,EACdC,qBAAqB,EACrBC,QAAQ,EACRC,YAAY,QAEP,UAAU,CAAC;AAClB,SAA4BC,gBAAgB,QAAuB,sBAAsB,CAAC;AAC1F,SAASC,WAAW,QAAQ,6BAA6B,CAAC;AAE1DtB,GAAG,CAAC;IACFE,gBAAgB;IAChBC,aAAa;IACbC,gBAAgB;IAChBC,iBAAiB;IACjBC,iBAAiB;IACjBC,iBAAiB;IACjBC,kBAAkB;IAClBC,cAAc;IACdC,gBAAgB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