@perses-dev/components 0.29.1 → 0.31.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/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js +7 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
- package/dist/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +1 -7
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/Legend/CompactLegend.d.ts +6 -4
- package/dist/Legend/CompactLegend.d.ts.map +1 -1
- package/dist/Legend/CompactLegend.js +4 -1
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.d.ts +11 -9
- package/dist/Legend/Legend.d.ts.map +1 -1
- package/dist/Legend/Legend.js +45 -11
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/ListLegend.d.ts +5 -8
- package/dist/Legend/ListLegend.d.ts.map +1 -1
- package/dist/Legend/ListLegend.js +34 -99
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.d.ts +8 -8
- package/dist/Legend/ListLegendItem.d.ts.map +1 -1
- package/dist/Legend/ListLegendItem.js +9 -12
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/LineChart/LineChart.d.ts +2 -1
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +35 -22
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +5 -1
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/Table/InnerTable.d.ts +9 -0
- package/dist/Table/InnerTable.d.ts.map +1 -0
- package/dist/Table/InnerTable.js +38 -0
- package/dist/Table/InnerTable.js.map +1 -0
- package/dist/Table/Table.d.ts +10 -0
- package/dist/Table/Table.d.ts.map +1 -0
- package/dist/Table/Table.js +101 -0
- package/dist/Table/Table.js.map +1 -0
- package/dist/Table/TableBody.d.ts +6 -0
- package/dist/Table/TableBody.d.ts.map +1 -0
- package/dist/Table/TableBody.js +23 -0
- package/dist/Table/TableBody.js.map +1 -0
- package/dist/Table/TableCell.d.ts +18 -0
- package/dist/Table/TableCell.d.ts.map +1 -0
- package/dist/Table/TableCell.js +91 -0
- package/dist/Table/TableCell.js.map +1 -0
- package/dist/Table/TableCheckbox.d.ts +9 -0
- package/dist/Table/TableCheckbox.d.ts.map +1 -0
- package/dist/Table/TableCheckbox.js +49 -0
- package/dist/Table/TableCheckbox.js.map +1 -0
- package/dist/Table/TableHead.d.ts +6 -0
- package/dist/Table/TableHead.d.ts.map +1 -0
- package/dist/Table/TableHead.js +23 -0
- package/dist/Table/TableHead.js.map +1 -0
- package/dist/Table/TableRow.d.ts +9 -0
- package/dist/Table/TableRow.d.ts.map +1 -0
- package/dist/Table/TableRow.js +29 -0
- package/dist/Table/TableRow.js.map +1 -0
- package/dist/Table/VirtualizedTable.d.ts +11 -0
- package/dist/Table/VirtualizedTable.d.ts.map +1 -0
- package/dist/Table/VirtualizedTable.js +152 -0
- package/dist/Table/VirtualizedTable.js.map +1 -0
- package/dist/Table/VirtualizedTableContainer.d.ts +6 -0
- package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -0
- package/dist/Table/VirtualizedTableContainer.js +24 -0
- package/dist/Table/VirtualizedTableContainer.js.map +1 -0
- package/dist/Table/hooks/useTableKeyboardNav.d.ts +32 -0
- package/dist/Table/hooks/useTableKeyboardNav.d.ts.map +1 -0
- package/dist/Table/hooks/useTableKeyboardNav.js +98 -0
- package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +29 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +89 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -0
- package/dist/Table/index.d.ts +4 -0
- package/dist/Table/index.d.ts.map +1 -0
- package/dist/Table/index.js +16 -0
- package/dist/Table/index.js.map +1 -0
- package/dist/Table/model/table-model.d.ts +83 -0
- package/dist/Table/model/table-model.d.ts.map +1 -0
- package/dist/Table/model/table-model.js +73 -0
- package/dist/Table/model/table-model.js.map +1 -0
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +1 -0
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js +11 -9
- package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +3 -2
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +63 -17
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts +5 -3
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +81 -44
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +1 -1
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +46 -0
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -0
- package/dist/TimeSeriesTooltip/nearby-series.js +200 -0
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -0
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +12 -4
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +10 -2
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/utils.js +7 -15
- package/dist/TimeSeriesTooltip/utils.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
- package/dist/UnitSelector/UnitSelector.js +40 -17
- package/dist/UnitSelector/UnitSelector.js.map +1 -1
- package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +7 -1
- package/dist/cjs/EChart/EChart.js +1 -7
- package/dist/cjs/Legend/CompactLegend.js +4 -1
- package/dist/cjs/Legend/Legend.js +45 -11
- package/dist/cjs/Legend/ListLegend.js +33 -98
- package/dist/cjs/Legend/ListLegendItem.js +8 -11
- package/dist/cjs/LineChart/LineChart.js +35 -22
- package/dist/cjs/StatChart/StatChart.js +5 -1
- package/dist/cjs/Table/InnerTable.js +44 -0
- package/dist/cjs/Table/Table.js +102 -0
- package/dist/cjs/Table/TableBody.js +29 -0
- package/dist/cjs/Table/TableCell.js +97 -0
- package/dist/cjs/Table/TableCheckbox.js +55 -0
- package/dist/cjs/Table/TableHead.js +29 -0
- package/dist/cjs/Table/TableRow.js +35 -0
- package/dist/cjs/Table/VirtualizedTable.js +155 -0
- package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
- package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
- package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
- package/dist/cjs/Table/index.js +33 -0
- package/dist/cjs/Table/model/table-model.js +80 -0
- package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
- package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +67 -16
- package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +85 -43
- package/dist/cjs/TimeSeriesTooltip/index.js +1 -1
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
- package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +15 -3
- package/dist/cjs/TimeSeriesTooltip/utils.js +6 -14
- package/dist/cjs/UnitSelector/UnitSelector.js +39 -16
- package/dist/cjs/context/SnackbarProvider.js +66 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/model/legend.js +7 -1
- package/dist/cjs/model/units/bytes.js +25 -21
- package/dist/cjs/model/units/constants.js +3 -3
- package/dist/cjs/model/units/decimal.js +22 -19
- package/dist/cjs/model/units/percent.js +15 -22
- package/dist/cjs/model/units/time.js +24 -20
- package/dist/cjs/model/units/units.js +2 -2
- package/dist/cjs/model/units/utils.js +42 -0
- package/dist/cjs/theme/palette/grey.js +6 -2
- package/dist/context/SnackbarProvider.d.ts +23 -0
- package/dist/context/SnackbarProvider.d.ts.map +1 -0
- package/dist/context/SnackbarProvider.js +59 -0
- package/dist/context/SnackbarProvider.js.map +1 -0
- 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/legend.d.ts +10 -2
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +5 -0
- package/dist/model/legend.js.map +1 -1
- package/dist/model/units/bytes.d.ts +1 -1
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +26 -22
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/constants.d.ts +1 -1
- package/dist/model/units/constants.js +1 -1
- package/dist/model/units/constants.js.map +1 -1
- package/dist/model/units/decimal.d.ts +2 -2
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +22 -19
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/percent.d.ts +1 -1
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js +14 -21
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/time.d.ts +1 -1
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +24 -20
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/units.js +2 -2
- package/dist/model/units/units.js.map +1 -1
- package/dist/model/units/utils.d.ts +4 -0
- package/dist/model/units/utils.d.ts.map +1 -0
- package/dist/model/units/utils.js +32 -0
- package/dist/model/units/utils.js.map +1 -0
- package/dist/theme/palette/grey.d.ts.map +1 -1
- package/dist/theme/palette/grey.js +6 -2
- package/dist/theme/palette/grey.js.map +1 -1
- package/package.json +6 -6
- package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -25
- package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/focused-series.js +0 -111
- package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
- package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -117
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Legend/ListLegend.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 { useTheme } from '@mui/material';\nimport { VariableSizeList, ListChildComponentProps } from 'react-window';\nimport { useRef, useEffect, forwardRef, useCallback } from 'react';\nimport { LegendItem } from '../model';\nimport { ListLegendItem } from './ListLegendItem';\n\nexport interface ListLegendProps {\n items: LegendItem[];\n height: number;\n width: number;\n\n /**\n * The height used when initially laying out items in the list. Once items\n * render, the height is determined based on the content. This is needed\n * because the list is virtualized.\n */\n initialRowHeight?: number;\n}\n\nconst DEFAULT_INITIAL_ROW_HEIGHT = 26;\n\n/**\n * ListLegend is used when legend.position is 'right' since legend items are\n * stacked. It is also used for `bottom` positioned legends when there are a\n * large number of items because it is virtualized and easier to visually scan\n * large numbers of items when there is a single item per row.\n */\nexport function ListLegend({ items, height, width, initialRowHeight = DEFAULT_INITIAL_ROW_HEIGHT }: ListLegendProps) {\n // Storing a ref to the react-window `VariableSizeList`, so we can call\n // `resetAfterIndex` to resize the list after mouseover/out events to account\n // for the change in list items on hover.\n const listRef = useRef<VariableSizeList>(null);\n // Storing row heights, so we can use dynamic heights, which enables the\n // user the hover to show the full label, while still having a virtualized\n // list.\n const rowHeights = useRef<Record<number, number>>({});\n\n const theme = useTheme();\n // Padding value used throughout to adjust the react-window virtual layouts\n // to simulate padding per the guidance from:\n // https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list\n const LIST_PADDING = parseInt(theme.spacing(1), 10);\n\n // show full labels on hover when there are many total series\n const truncateLabels = items.length > 5;\n\n // Gets the row height for a given item to enable the virtualized list to\n // render the row properly.\n function getRowHeight(index: number) {\n const currentHeight = rowHeights.current[index];\n return currentHeight ?? initialRowHeight;\n }\n\n // Set the height for a given item to enable the virtualized list to\n // adjust to size changes.\n function setRowHeight(index: number, size: number) {\n // Tell the virtualized list that items changed size and need to be\n // re-evaluated.\n listRef.current?.resetAfterIndex(0);\n rowHeights.current = { ...rowHeights.current, [index]: size };\n }\n\n // Renderer for virtualized rows in `VariableSizeList`.\n function ListLegendRow({ index, style }: ListChildComponentProps) {\n // Storing a ref to the row's `ListLegendItem`, so we can get the \"real\"\n // height and adjust the height of the row based on it, enabling the dynamic\n // heights on hover.\n const rowRef = useRef<HTMLDivElement | null>(null);\n\n // useCallback is important here to avoid constantly running the useEffect\n // that calls this in `ListLegendItem`.\n const handleRowLayoutChange = useCallback(() => {\n // Handle size changes from hovering on a list item.\n if (rowRef.current) {\n setRowHeight(index, rowRef.current.clientHeight);\n }\n }, [index]);\n\n // Adjust row heights when the row being rendered changes.\n useEffect(() => {\n handleRowLayoutChange();\n }, [handleRowLayoutChange]);\n\n const item = items[index];\n\n if (!item) {\n // This shouldn't happen if configured correctly, but covering\n // the case to appease the type checking and to cover any edge\n // cases.\n return null;\n }\n\n const originalTop = parseFloat(`${style.top}`);\n\n return (\n <div\n style={{\n ...style,\n // Adjust the top position to simulate top padding on the list.\n top: `${originalTop + LIST_PADDING}px`,\n }}\n >\n <ListLegendItem\n ref={rowRef}\n key={item.id}\n item={item}\n truncateLabel={truncateLabels}\n onLayoutChange={handleRowLayoutChange}\n sx={{\n // Having an explicit width is important for the ellipsizing to\n // work correctly. Subtract padding to simulate padding.\n width: width - LIST_PADDING,\n wordBreak: 'break-word',\n overflow: 'hidden',\n }}\n />\n </div>\n );\n }\n\n // Renderer for the inner container element of the `VariableSizeList` used\n // to adjust styles to simulate padding on the list per:\n // https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list\n const InnerElementType = forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<'div'>>(function InnerElementType(\n { style, ...rest },\n ref\n ) {\n const originalHeight = style?.height ? parseFloat(`${style?.height}`) : 0;\n\n return (\n <div\n ref={ref}\n role=\"list\"\n style={{\n ...style,\n // Adjust height to account for simulated padding.\n height: `${originalHeight + LIST_PADDING * 2}px`,\n }}\n {...rest}\n />\n );\n });\n\n return (\n <VariableSizeList\n height={height}\n width={width}\n itemCount={items.length}\n itemSize={getRowHeight}\n innerElementType={InnerElementType}\n ref={listRef}\n >\n {ListLegendRow}\n </VariableSizeList>\n );\n}\n"],"names":["useTheme","VariableSizeList","useRef","useEffect","forwardRef","useCallback","ListLegendItem","DEFAULT_INITIAL_ROW_HEIGHT","ListLegend","items","height","width","initialRowHeight","listRef","rowHeights","theme","LIST_PADDING","parseInt","spacing","truncateLabels","length","getRowHeight","index","currentHeight","current","setRowHeight","size","resetAfterIndex","ListLegendRow","style","rowRef","handleRowLayoutChange","clientHeight","item","originalTop","parseFloat","top","div","ref","truncateLabel","onLayoutChange","sx","wordBreak","overflow","id","InnerElementType","rest","originalHeight","role","itemCount","itemSize","innerElementType"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6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,KAAK;QACZsC,SAAS,EAAExC,KAAK,CAACW,MAAM;QACvB8B,QAAQ,EAAE7B,YAAY;QACtB8B,gBAAgB,EAAEN,gBAAgB;QAClCP,GAAG,EAAEzB,OAAO;kBAEXe,aAAa;MACG,CACnB;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/Legend/ListLegend.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 { useTheme, Box } from '@mui/material';\nimport { Virtuoso } from 'react-virtuoso';\nimport { LegendItem, SelectedLegendItemState, isLegendItemVisuallySelected } from '../model';\nimport { ListLegendItem, ListLegendItemProps } from './ListLegendItem';\n\nexport interface ListLegendProps {\n items: LegendItem[];\n height: number;\n width: number;\n selectedItems: SelectedLegendItemState;\n onLegendItemClick: ListLegendItemProps['onClick'];\n}\n\n/**\n * ListLegend is used when legend.position is 'right' since legend items are\n * stacked. It is also used for `bottom` positioned legends when there are a\n * large number of items because it is virtualized and easier to visually scan\n * large numbers of items when there is a single item per row.\n */\nexport function ListLegend({ items, height, width, selectedItems, onLegendItemClick }: ListLegendProps) {\n const theme = useTheme();\n // Padding value used in the react virtuoso header/footer components to\n // simulate top/bottom padding based on recommendation in this\n // issue.\n // https://github.com/petyosi/react-virtuoso/issues/238\n const LIST_PADDING = parseInt(theme.spacing(1), 10);\n const mockPadding = <Box sx={{ width: '100%', height: `${LIST_PADDING}px` }}></Box>;\n\n // show full labels on hover when there are many total series\n const truncateLabels = items.length > 5;\n\n return (\n <Virtuoso\n style={{ height, width }}\n data={items}\n itemContent={(index, item) => {\n return (\n <ListLegendItem\n key={item.id}\n item={item}\n truncateLabel={truncateLabels}\n isVisuallySelected={isLegendItemVisuallySelected(item, selectedItems)}\n onClick={onLegendItemClick}\n sx={{\n // Having an explicit width is important for the ellipsizing to\n // work correctly. Subtract padding to simulate padding.\n width: width - LIST_PADDING,\n wordBreak: 'break-word',\n overflow: 'hidden',\n }}\n />\n );\n }}\n role=\"list\"\n components={{\n Header: () => {\n return mockPadding;\n },\n Footer: () => {\n return mockPadding;\n },\n }}\n />\n );\n}\n"],"names":["useTheme","Box","Virtuoso","isLegendItemVisuallySelected","ListLegendItem","ListLegend","items","height","width","selectedItems","onLegendItemClick","theme","LIST_PADDING","parseInt","spacing","mockPadding","sx","truncateLabels","length","style","data","itemContent","index","item","truncateLabel","isVisuallySelected","onClick","wordBreak","overflow","id","role","components","Header","Footer"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,EAAEC,GAAG,QAAQ,eAAe,CAAC;AAC9C,SAASC,QAAQ,QAAQ,gBAAgB,CAAC;AAC1C,SAA8CC,4BAA4B,QAAQ,UAAU,CAAC;AAC7F,SAASC,cAAc,QAA6B,kBAAkB,CAAC;AAUvE;;;;;CAKC,GACD,OAAO,SAASC,UAAU,CAAC,EAAEC,KAAK,CAAA,EAAEC,MAAM,CAAA,EAAEC,KAAK,CAAA,EAAEC,aAAa,CAAA,EAAEC,iBAAiB,CAAA,EAAmB,EAAE;IACtG,MAAMC,KAAK,GAAGX,QAAQ,EAAE,AAAC;IACzB,uEAAuE;IACvE,8DAA8D;IAC9D,SAAS;IACT,uDAAuD;IACvD,MAAMY,YAAY,GAAGC,QAAQ,CAACF,KAAK,CAACG,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,AAAC;IACpD,MAAMC,WAAW,iBAAG,KAACd,GAAG;QAACe,EAAE,EAAE;YAAER,KAAK,EAAE,MAAM;YAAED,MAAM,EAAE,CAAC,EAAEK,YAAY,CAAC,EAAE,CAAC;SAAE;MAAQ,AAAC;IAEpF,6DAA6D;IAC7D,MAAMK,cAAc,GAAGX,KAAK,CAACY,MAAM,GAAG,CAAC,AAAC;IAExC,qBACE,KAAChB,QAAQ;QACPiB,KAAK,EAAE;YAAEZ,MAAM;YAAEC,KAAK;SAAE;QACxBY,IAAI,EAAEd,KAAK;QACXe,WAAW,EAAE,CAACC,KAAK,EAAEC,IAAI,GAAK;YAC5B,qBACE,KAACnB,cAAc;gBAEbmB,IAAI,EAAEA,IAAI;gBACVC,aAAa,EAAEP,cAAc;gBAC7BQ,kBAAkB,EAAEtB,4BAA4B,CAACoB,IAAI,EAAEd,aAAa,CAAC;gBACrEiB,OAAO,EAAEhB,iBAAiB;gBAC1BM,EAAE,EAAE;oBACF,+DAA+D;oBAC/D,wDAAwD;oBACxDR,KAAK,EAAEA,KAAK,GAAGI,YAAY;oBAC3Be,SAAS,EAAE,YAAY;oBACvBC,QAAQ,EAAE,QAAQ;iBACnB;eAXIL,IAAI,CAACM,EAAE,CAYZ,CACF;QACJ,CAAC;QACDC,IAAI,EAAC,MAAM;QACXC,UAAU,EAAE;YACVC,MAAM,EAAE,IAAM;gBACZ,OAAOjB,WAAW,CAAC;YACrB,CAAC;YACDkB,MAAM,EAAE,IAAM;gBACZ,OAAOlB,WAAW,CAAC;YACrB,CAAC;SACF;MACD,CACF;AACJ,CAAC"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ListItemProps } from '@mui/material';
|
|
3
3
|
import { LegendItem } from '../model';
|
|
4
|
-
interface ListLegendItemProps extends ListItemProps<'div'> {
|
|
4
|
+
export interface ListLegendItemProps extends Omit<ListItemProps<'div'>, 'onClick'> {
|
|
5
5
|
item: LegendItem;
|
|
6
|
+
/**
|
|
7
|
+
* When true, the item is rendered differently to visually communicate it is
|
|
8
|
+
* selected.
|
|
9
|
+
*/
|
|
10
|
+
isVisuallySelected?: boolean;
|
|
11
|
+
onClick: (e: React.MouseEvent<HTMLElement, MouseEvent>, seriesId: string) => void;
|
|
6
12
|
/**
|
|
7
13
|
* When `true`, will keep labels to a single line with overflow ellipsized. The
|
|
8
14
|
* full content will be shown on hover.
|
|
@@ -10,12 +16,6 @@ interface ListLegendItemProps extends ListItemProps<'div'> {
|
|
|
10
16
|
* When `false` or unset, will show the full label.
|
|
11
17
|
*/
|
|
12
18
|
truncateLabel?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Called when the layout of the legend item changes as a result of the hover
|
|
15
|
-
* behavior when `truncateLabel` is `true`.
|
|
16
|
-
*/
|
|
17
|
-
onLayoutChange?: () => void;
|
|
18
19
|
}
|
|
19
|
-
export declare const ListLegendItem: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<ListLegendItemProps, "classes" | "className" | "style" | "children" | "sx" | "slot" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "autoFocus" | "alignItems" | "disabled" | "selected" | "divider" | "components" | "componentsProps" | "slotProps" | "slots" | "dense" | "disableGutters" | "ContainerComponent" | "ContainerProps" | "disablePadding" | "secondaryAction" | "item" | "
|
|
20
|
-
export {};
|
|
20
|
+
export declare const ListLegendItem: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<ListLegendItemProps, "classes" | "className" | "style" | "children" | "sx" | "slot" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "autoFocus" | "alignItems" | "disabled" | "selected" | "divider" | "components" | "componentsProps" | "slotProps" | "slots" | "dense" | "disableGutters" | "ContainerComponent" | "ContainerProps" | "disablePadding" | "secondaryAction" | "item" | "isVisuallySelected" | "truncateLabel"> & React.RefAttributes<HTMLDivElement>>>;
|
|
21
21
|
//# sourceMappingURL=ListLegendItem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListLegendItem.d.ts","sourceRoot":"","sources":["../../src/Legend/ListLegendItem.tsx"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"ListLegendItem.d.ts","sourceRoot":"","sources":["../../src/Legend/ListLegendItem.tsx"],"names":[],"mappings":"AAaA,OAAO,KAA+B,MAAM,OAAO,CAAC;AACpD,OAAO,EAA+B,aAAa,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAItC,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAChF,IAAI,EAAE,UAAU,CAAC;IAEjB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,OAAO,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAElF;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAwDD,eAAO,MAAM,cAAc,o6JAAiC,CAAC"}
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { createElement as _createElement } from "react";
|
|
15
|
-
import React, { forwardRef, useState
|
|
15
|
+
import React, { forwardRef, useState } from 'react';
|
|
16
16
|
import { Box, ListItemText, ListItem } from '@mui/material';
|
|
17
17
|
import { combineSx } from '../utils';
|
|
18
18
|
import { LegendColorBadge } from './LegendColorBadge';
|
|
19
|
-
const ListLegendItemBase = /*#__PURE__*/ forwardRef(function ListLegendItem({ item , sx , truncateLabel ,
|
|
19
|
+
const ListLegendItemBase = /*#__PURE__*/ forwardRef(function ListLegendItem({ item , sx , truncateLabel , onClick , isVisuallySelected , ...others }, ref) {
|
|
20
20
|
const [noWrap, setNoWrap] = useState(truncateLabel);
|
|
21
21
|
function handleMouseOver() {
|
|
22
22
|
if (truncateLabel) {
|
|
@@ -28,14 +28,11 @@ const ListLegendItemBase = /*#__PURE__*/ forwardRef(function ListLegendItem({ it
|
|
|
28
28
|
setNoWrap(true);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
noWrap,
|
|
37
|
-
onLayoutChange
|
|
38
|
-
]);
|
|
31
|
+
const handleClick = (e)=>{
|
|
32
|
+
var ref;
|
|
33
|
+
onClick(e, item.id);
|
|
34
|
+
(ref = item.onClick) === null || ref === void 0 ? void 0 : ref.call(item, e);
|
|
35
|
+
};
|
|
39
36
|
return /*#__PURE__*/ _createElement(ListItem, {
|
|
40
37
|
...others,
|
|
41
38
|
component: "div",
|
|
@@ -46,8 +43,8 @@ const ListLegendItemBase = /*#__PURE__*/ forwardRef(function ListLegendItem({ it
|
|
|
46
43
|
}, sx),
|
|
47
44
|
dense: true,
|
|
48
45
|
key: item.id,
|
|
49
|
-
onClick:
|
|
50
|
-
selected:
|
|
46
|
+
onClick: handleClick,
|
|
47
|
+
selected: isVisuallySelected,
|
|
51
48
|
ref: ref,
|
|
52
49
|
children: [
|
|
53
50
|
/*#__PURE__*/ _jsx(Box, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Legend/ListLegendItem.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { forwardRef, useState
|
|
1
|
+
{"version":3,"sources":["../../src/Legend/ListLegendItem.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { forwardRef, useState } from 'react';\nimport { Box, ListItemText, ListItem, ListItemProps } from '@mui/material';\nimport { LegendItem } from '../model';\nimport { combineSx } from '../utils';\nimport { LegendColorBadge } from './LegendColorBadge';\n\nexport interface ListLegendItemProps extends Omit<ListItemProps<'div'>, 'onClick'> {\n item: LegendItem;\n\n /**\n * When true, the item is rendered differently to visually communicate it is\n * selected.\n */\n isVisuallySelected?: boolean;\n\n onClick: (e: React.MouseEvent<HTMLElement, MouseEvent>, seriesId: string) => void;\n\n /**\n * When `true`, will keep labels to a single line with overflow ellipsized. The\n * full content will be shown on hover.\n *\n * When `false` or unset, will show the full label.\n */\n truncateLabel?: boolean;\n}\n\nconst ListLegendItemBase = forwardRef<HTMLDivElement, ListLegendItemProps>(function ListLegendItem(\n { item, sx, truncateLabel, onClick, isVisuallySelected, ...others },\n ref\n) {\n const [noWrap, setNoWrap] = useState(truncateLabel);\n\n function handleMouseOver() {\n if (truncateLabel) {\n setNoWrap(false);\n }\n }\n\n function handleMouseOut() {\n if (truncateLabel) {\n setNoWrap(true);\n }\n }\n\n const handleClick: React.MouseEventHandler<HTMLDivElement> = (e) => {\n onClick(e, item.id);\n item.onClick?.(e);\n };\n\n return (\n <ListItem\n {...others}\n component=\"div\"\n role=\"listitem\"\n sx={combineSx(\n {\n padding: 0,\n cursor: 'pointer',\n },\n sx\n )}\n dense={true}\n key={item.id}\n onClick={handleClick}\n selected={isVisuallySelected}\n ref={ref}\n >\n <Box sx={{ display: 'flex', alignItems: 'center' }}>\n <LegendColorBadge color={item.color} />\n </Box>\n <ListItemText\n primary={item.label}\n primaryTypographyProps={{ noWrap: noWrap }}\n onMouseOver={handleMouseOver}\n onMouseOut={handleMouseOut}\n ></ListItemText>\n </ListItem>\n );\n});\n\nexport const ListLegendItem = React.memo(ListLegendItemBase);\n"],"names":["React","forwardRef","useState","Box","ListItemText","ListItem","combineSx","LegendColorBadge","ListLegendItemBase","ListLegendItem","item","sx","truncateLabel","onClick","isVisuallySelected","others","ref","noWrap","setNoWrap","handleMouseOver","handleMouseOut","handleClick","e","id","component","role","padding","cursor","dense","key","selected","display","alignItems","color","primary","label","primaryTypographyProps","onMouseOver","onMouseOut","memo"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,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AAE,CACH;QACDiB,KAAK,EAAE,IAAI;QACXC,GAAG,EAAEnB,IAAI,CAACa,EAAE;QACZV,OAAO,EAAEQ,WAAW;QACpBS,QAAQ,EAAEhB,kBAAkB;QAC5BE,GAAG,EAAEA,GAAG;;0BAER,KAACb,GAAG;gBAACQ,EAAE,EAAE;oBAAEoB,OAAO,EAAE,MAAM;oBAAEC,UAAU,EAAE,QAAQ;iBAAE;0BAChD,cAAA,KAACzB,gBAAgB;oBAAC0B,KAAK,EAAEvB,IAAI,CAACuB,KAAK;kBAAI;cACnC;0BACN,KAAC7B,YAAY;gBACX8B,OAAO,EAAExB,IAAI,CAACyB,KAAK;gBACnBC,sBAAsB,EAAE;oBAAEnB,MAAM,EAAEA,MAAM;iBAAE;gBAC1CoB,WAAW,EAAElB,eAAe;gBAC5BmB,UAAU,EAAElB,cAAc;cACZ;;MACP,CACX;AACJ,CAAC,CAAC,AAAC;AAEH,OAAO,MAAMX,cAAc,iBAAGT,KAAK,CAACuC,IAAI,CAAC/B,kBAAkB,CAAC,CAAC"}
|
|
@@ -18,9 +18,10 @@ export interface LineChartProps {
|
|
|
18
18
|
grid?: GridComponentOption;
|
|
19
19
|
legend?: LegendComponentOption;
|
|
20
20
|
tooltipConfig?: TooltipConfig;
|
|
21
|
+
noDataVariant?: 'chart' | 'message';
|
|
21
22
|
onDataZoom?: (e: ZoomEventData) => void;
|
|
22
23
|
onDoubleClick?: (e: MouseEvent) => void;
|
|
23
24
|
__experimentalEChartsOptionsOverride?: (options: EChartsCoreOption) => EChartsCoreOption;
|
|
24
25
|
}
|
|
25
|
-
export declare function LineChart({ height, data, yAxis, unit, grid, legend, tooltipConfig, onDataZoom, onDoubleClick, __experimentalEChartsOptionsOverride, }: LineChartProps): JSX.Element;
|
|
26
|
+
export declare function LineChart({ height, data, yAxis, unit, grid, legend, tooltipConfig, noDataVariant, onDataZoom, onDoubleClick, __experimentalEChartsOptionsOverride, }: LineChartProps): JSX.Element;
|
|
26
27
|
//# sourceMappingURL=LineChart.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/LineChart/LineChart.tsx"],"names":[],"mappings":"AAaA,OAAc,EAAE,UAAU,EAA6B,MAAM,OAAO,CAAC;AAErE,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EAEnB,qBAAqB,EACrB,oBAAoB,EAErB,MAAM,SAAS,CAAC;AAgBjB,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/LineChart/LineChart.tsx"],"names":[],"mappings":"AAaA,OAAc,EAAE,UAAU,EAA6B,MAAM,OAAO,CAAC;AAErE,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EAEnB,qBAAqB,EACrB,oBAAoB,EAErB,MAAM,SAAS,CAAC;AAgBjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,OAAO,EAA0E,aAAa,EAAE,MAAM,SAAS,CAAC;AAgBhH,oBAAY,aAAa,GAAG;IAC1B,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,CAAC,EAAE,mBAAmB,CAAC;IAC3B,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,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,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,aAAoC,EACpC,aAAyB,EACzB,UAAU,EACV,aAAa,EACb,oCAAoC,GACrC,EAAE,cAAc,eAoKhB"}
|
|
@@ -18,7 +18,6 @@ import { LineChart as EChartsLineChart } from 'echarts/charts';
|
|
|
18
18
|
import { GridComponent, DataZoomComponent, MarkAreaComponent, MarkLineComponent, MarkPointComponent, TitleComponent, ToolboxComponent, TooltipComponent, LegendComponent } from 'echarts/components';
|
|
19
19
|
import { CanvasRenderer } from 'echarts/renderers';
|
|
20
20
|
import { EChart } from '../EChart';
|
|
21
|
-
import { OPTIMIZED_MODE_SERIES_LIMIT } from '../model/graph';
|
|
22
21
|
import { useChartsTheme } from '../context/ChartsThemeProvider';
|
|
23
22
|
import { TimeSeriesTooltip } from '../TimeSeriesTooltip';
|
|
24
23
|
import { useTimeZone } from '../context/TimeZoneProvider';
|
|
@@ -38,12 +37,12 @@ use([
|
|
|
38
37
|
]);
|
|
39
38
|
export function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfig ={
|
|
40
39
|
wrapLabels: true
|
|
41
|
-
} , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
|
|
40
|
+
} , noDataVariant ='message' , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
|
|
42
41
|
var ref;
|
|
43
42
|
const chartsTheme = useChartsTheme();
|
|
44
43
|
const chartRef = useRef();
|
|
45
44
|
const [showTooltip, setShowTooltip] = useState(true);
|
|
46
|
-
const [
|
|
45
|
+
const [isTooltipPinned, setIsTooltipPinned] = useState(false);
|
|
47
46
|
const { timeZone } = useTimeZone();
|
|
48
47
|
const handleEvents = useMemo(()=>{
|
|
49
48
|
return {
|
|
@@ -51,7 +50,7 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , toolt
|
|
|
51
50
|
if (onDataZoom === undefined) {
|
|
52
51
|
setTimeout(()=>{
|
|
53
52
|
// workaround so unpin happens after click event
|
|
54
|
-
|
|
53
|
+
setIsTooltipPinned(false);
|
|
55
54
|
}, 10);
|
|
56
55
|
}
|
|
57
56
|
if (onDataZoom === undefined || params.batch[0] === undefined) return;
|
|
@@ -75,13 +74,13 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , toolt
|
|
|
75
74
|
}, [
|
|
76
75
|
data,
|
|
77
76
|
onDataZoom,
|
|
78
|
-
|
|
77
|
+
setIsTooltipPinned
|
|
79
78
|
]);
|
|
80
79
|
if (chartRef.current !== undefined) {
|
|
81
80
|
enableDataZoom(chartRef.current);
|
|
82
81
|
}
|
|
83
82
|
const handleOnDoubleClick = (e)=>{
|
|
84
|
-
|
|
83
|
+
setIsTooltipPinned(false);
|
|
85
84
|
// either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
|
|
86
85
|
if (onDoubleClick === undefined) {
|
|
87
86
|
if (chartRef.current !== undefined) {
|
|
@@ -94,9 +93,9 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , toolt
|
|
|
94
93
|
const { noDataOption } = chartsTheme;
|
|
95
94
|
const option = useMemo(()=>{
|
|
96
95
|
if (data.timeSeries === undefined) return {};
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
|
|
96
|
+
// The "chart" `noDataVariant` is only used when the `timeSeries` is an
|
|
97
|
+
// empty array because a `null` value will throw an error.
|
|
98
|
+
if (data.timeSeries === null || data.timeSeries.length === 0 && noDataVariant === 'message') return noDataOption;
|
|
100
99
|
var _rangeMs;
|
|
101
100
|
const rangeMs = (_rangeMs = data.rangeMs) !== null && _rangeMs !== void 0 ? _rangeMs : getDateRange(data.xAxis);
|
|
102
101
|
const option = {
|
|
@@ -114,13 +113,17 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , toolt
|
|
|
114
113
|
yAxis: getYAxes(yAxis, unit),
|
|
115
114
|
animation: false,
|
|
116
115
|
tooltip: {
|
|
117
|
-
show:
|
|
116
|
+
show: true,
|
|
118
117
|
trigger: 'axis',
|
|
119
|
-
showContent: false
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
showContent: false
|
|
119
|
+
},
|
|
120
|
+
// https://echarts.apache.org/en/option.html#axisPointer
|
|
121
|
+
axisPointer: {
|
|
122
|
+
type: 'line',
|
|
123
|
+
z: 0,
|
|
124
|
+
triggerEmphasis: false,
|
|
125
|
+
triggerTooltip: false,
|
|
126
|
+
snap: true
|
|
124
127
|
},
|
|
125
128
|
toolbox: {
|
|
126
129
|
feature: {
|
|
@@ -145,17 +148,21 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , toolt
|
|
|
145
148
|
legend,
|
|
146
149
|
noDataOption,
|
|
147
150
|
timeZone,
|
|
148
|
-
__experimentalEChartsOptionsOverride
|
|
151
|
+
__experimentalEChartsOptionsOverride,
|
|
152
|
+
noDataVariant
|
|
149
153
|
]);
|
|
150
154
|
return /*#__PURE__*/ _jsxs(Box, {
|
|
151
155
|
sx: {
|
|
152
156
|
height
|
|
153
157
|
},
|
|
154
|
-
onClick: ()=>{
|
|
155
|
-
|
|
158
|
+
onClick: (e)=>{
|
|
159
|
+
// Pin and unpin when clicking on chart canvas but not tooltip text.
|
|
160
|
+
if (e.target instanceof HTMLCanvasElement) {
|
|
161
|
+
setIsTooltipPinned((current)=>!current);
|
|
162
|
+
}
|
|
156
163
|
},
|
|
157
164
|
onMouseDown: (e)=>{
|
|
158
|
-
//
|
|
165
|
+
// Hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels.
|
|
159
166
|
if (e.target instanceof HTMLCanvasElement) {
|
|
160
167
|
setShowTooltip(false);
|
|
161
168
|
}
|
|
@@ -165,7 +172,6 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , toolt
|
|
|
165
172
|
},
|
|
166
173
|
onMouseLeave: ()=>{
|
|
167
174
|
setShowTooltip(false);
|
|
168
|
-
setPinTooltip(false);
|
|
169
175
|
},
|
|
170
176
|
onMouseEnter: ()=>{
|
|
171
177
|
setShowTooltip(true);
|
|
@@ -179,10 +185,17 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , toolt
|
|
|
179
185
|
chartRef: chartRef,
|
|
180
186
|
chartData: data,
|
|
181
187
|
wrapLabels: tooltipConfig.wrapLabels,
|
|
182
|
-
|
|
183
|
-
unit: unit
|
|
188
|
+
isTooltipPinned: isTooltipPinned,
|
|
189
|
+
unit: unit,
|
|
190
|
+
onUnpinClick: ()=>{
|
|
191
|
+
setIsTooltipPinned(false);
|
|
192
|
+
}
|
|
184
193
|
}),
|
|
185
194
|
/*#__PURE__*/ _jsx(EChart, {
|
|
195
|
+
sx: {
|
|
196
|
+
width: '100%',
|
|
197
|
+
height: '100%'
|
|
198
|
+
},
|
|
186
199
|
option: option,
|
|
187
200
|
theme: chartsTheme.echartsTheme,
|
|
188
201
|
onEvents: handleEvents,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/LineChart/LineChart.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { MouseEvent, useMemo, useRef, useState } from 'react';\nimport { Box } from '@mui/material';\nimport type {\n EChartsCoreOption,\n GridComponentOption,\n LineSeriesOption,\n LegendComponentOption,\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 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 { EChartsDataFormat, OPTIMIZED_MODE_SERIES_LIMIT } from '../model/graph';\nimport { UnitOptions } from '../model/units';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { TimeSeriesTooltip } from '../TimeSeriesTooltip';\nimport { useTimeZone } from '../context/TimeZoneProvider';\nimport { enableDataZoom, getDateRange, getFormattedDate, getYAxes, restoreChart, ZoomEventData } from './utils';\n\nuse([\n EChartsLineChart,\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n CanvasRenderer,\n]);\n\nexport type TooltipConfig = {\n wrapLabels: boolean;\n hidden?: boolean;\n};\n\nexport interface LineChartProps {\n /**\n * Height of the chart\n */\n height: number;\n data: EChartsDataFormat;\n yAxis?: YAXisComponentOption;\n unit?: UnitOptions;\n grid?: GridComponentOption;\n legend?: LegendComponentOption;\n tooltipConfig?: TooltipConfig;\n onDataZoom?: (e: ZoomEventData) => void;\n onDoubleClick?: (e: MouseEvent) => void;\n __experimentalEChartsOptionsOverride?: (options: EChartsCoreOption) => EChartsCoreOption;\n}\n\nexport function LineChart({\n height,\n data,\n yAxis,\n unit,\n grid,\n legend,\n tooltipConfig = { wrapLabels: true },\n onDataZoom,\n onDoubleClick,\n __experimentalEChartsOptionsOverride,\n}: LineChartProps) {\n const chartsTheme = useChartsTheme();\n const chartRef = useRef<EChartsInstance>();\n const [showTooltip, setShowTooltip] = useState<boolean>(true);\n const [pinTooltip, setPinTooltip] = useState<boolean>(false);\n const { timeZone } = useTimeZone();\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 setPinTooltip(false);\n }, 10);\n }\n if (onDataZoom === undefined || params.batch[0] === undefined) return;\n const startIndex = params.batch[0].startValue ?? 0;\n const endIndex = params.batch[0].endValue ?? data.xAxis.length - 1;\n const xAxisStartValue = data.xAxis[startIndex];\n const xAxisEndValue = data.xAxis[endIndex];\n\n if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {\n const zoomEvent: ZoomEventData = {\n start: xAxisStartValue,\n end: xAxisEndValue,\n startIndex,\n endIndex,\n };\n onDataZoom(zoomEvent);\n }\n },\n // TODO: use legendselectchanged event to fix tooltip when legend selected\n };\n }, [data, onDataZoom, setPinTooltip]);\n\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n\n const handleOnDoubleClick = (e: MouseEvent) => {\n setPinTooltip(false);\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 const { noDataOption } = chartsTheme;\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.timeSeries === undefined) return {};\n if (data.timeSeries === null || data.timeSeries.length === 0) return noDataOption;\n\n // show symbols and axisPointer dashed line on hover\n const isOptimizedMode = data.timeSeries.length > OPTIMIZED_MODE_SERIES_LIMIT;\n\n const rangeMs = data.rangeMs ?? getDateRange(data.xAxis);\n\n const option: EChartsCoreOption = {\n series: data.timeSeries,\n xAxis: {\n type: 'category',\n data: data.xAxis,\n max: data.xAxisMax,\n axisLabel: {\n formatter: (value: number) => {\n return getFormattedDate(value, rangeMs, timeZone);\n },\n },\n },\n yAxis: getYAxes(yAxis, unit),\n animation: false,\n tooltip: {\n show: !isOptimizedMode,\n trigger: 'axis',\n showContent: false, // echarts tooltip content hidden since we use custom tooltip instead\n axisPointer: {\n type: isOptimizedMode ? 'none' : 'line',\n z: 0, // ensure point symbol shows on top of dashed line\n },\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 legend,\n };\n\n if (__experimentalEChartsOptionsOverride) {\n return __experimentalEChartsOptionsOverride(option);\n }\n return option;\n }, [data, yAxis, unit, grid, legend, noDataOption, timeZone, __experimentalEChartsOptionsOverride]);\n\n return (\n <Box\n sx={{ height }}\n onClick={() => {\n setPinTooltip((current) => !current);\n }}\n onMouseDown={(e) => {\n // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels\n if (e.target instanceof HTMLCanvasElement) {\n setShowTooltip(false);\n }\n }}\n onMouseUp={() => {\n setShowTooltip(true);\n }}\n onMouseLeave={() => {\n setShowTooltip(false);\n setPinTooltip(false);\n }}\n onMouseEnter={() => {\n setShowTooltip(true);\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n }}\n onDoubleClick={handleOnDoubleClick}\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 <TimeSeriesTooltip\n chartRef={chartRef}\n chartData={data}\n wrapLabels={tooltipConfig.wrapLabels}\n pinTooltip={pinTooltip}\n unit={unit}\n />\n )}\n <EChart option={option} theme={chartsTheme.echartsTheme} onEvents={handleEvents} _instance={chartRef} />\n </Box>\n );\n}\n"],"names":["React","useMemo","useRef","useState","Box","use","LineChart","EChartsLineChart","GridComponent","DataZoomComponent","MarkAreaComponent","MarkLineComponent","MarkPointComponent","TitleComponent","ToolboxComponent","TooltipComponent","LegendComponent","CanvasRenderer","EChart","OPTIMIZED_MODE_SERIES_LIMIT","useChartsTheme","TimeSeriesTooltip","useTimeZone","enableDataZoom","getDateRange","getFormattedDate","getYAxes","restoreChart","height","data","yAxis","unit","grid","legend","tooltipConfig","wrapLabels","onDataZoom","onDoubleClick","__experimentalEChartsOptionsOverride","option","chartsTheme","chartRef","showTooltip","setShowTooltip","pinTooltip","setPinTooltip","timeZone","handleEvents","datazoom","params","undefined","setTimeout","batch","startIndex","startValue","endIndex","endValue","xAxis","length","xAxisStartValue","xAxisEndValue","zoomEvent","start","end","current","handleOnDoubleClick","e","noDataOption","timeSeries","isOptimizedMode","rangeMs","series","type","max","xAxisMax","axisLabel","formatter","value","animation","tooltip","show","trigger","showContent","axisPointer","z","toolbox","feature","dataZoom","icon","yAxisIndex","sx","onClick","onMouseDown","target","HTMLCanvasElement","onMouseUp","onMouseLeave","onMouseEnter","hidden","chartData","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;AAAA,OAAOA,KAAK,IAAgBC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACrE,SAASC,GAAG,QAAQ,eAAe,CAAC;AASpC,SAAqCC,GAAG,QAAQ,cAAc,CAAC;AAC/D,SAASC,SAAS,IAAIC,gBAAgB,QAAQ,gBAAgB,CAAC;AAC/D,SACEC,aAAa,EACbC,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;AACjD,SAA4BC,2BAA2B,QAAQ,gBAAgB,CAAC;AAEhF,SAASC,cAAc,QAAQ,gCAAgC,CAAC;AAChE,SAASC,iBAAiB,QAAQ,sBAAsB,CAAC;AACzD,SAASC,WAAW,QAAQ,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CAACuB,OAAO,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QACD3B,aAAa,EAAE4B,mBAAmB;;YAGjCvB,WAAW,KAAK,IAAI,IACnB,CAAA,CAACH,GAAc,GAAdA,MAAM,CAACwC,OAAO,cAAdxC,GAAc,WAAwC,GAAvD,KAAA,CAAuD,GAAtDA,GAAc,CAA6B2C,WAAW,CAAA,KAAK,KAAK,IACjEhD,aAAa,CAACgE,MAAM,KAAK,IAAI,kBAC3B,KAAC7E,iBAAiB;gBAChBoB,QAAQ,EAAEA,QAAQ;gBAClB0D,SAAS,EAAEtE,IAAI;gBACfM,UAAU,EAAED,aAAa,CAACC,UAAU;gBACpCS,UAAU,EAAEA,UAAU;gBACtBb,IAAI,EAAEA,IAAI;cACV,AACH;0BACH,KAACb,MAAM;gBAACqB,MAAM,EAAEA,MAAM;gBAAE6D,KAAK,EAAE5D,WAAW,CAAC6D,YAAY;gBAAEC,QAAQ,EAAEvD,YAAY;gBAAEwD,SAAS,EAAE9D,QAAQ;cAAI;;MACpG,CACN;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/LineChart/LineChart.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { MouseEvent, useMemo, useRef, useState } from 'react';\nimport { Box } from '@mui/material';\nimport type {\n EChartsCoreOption,\n GridComponentOption,\n LineSeriesOption,\n LegendComponentOption,\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 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 { EChartsDataFormat } from '../model/graph';\nimport { UnitOptions } from '../model/units';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { TimeSeriesTooltip } from '../TimeSeriesTooltip';\nimport { useTimeZone } from '../context/TimeZoneProvider';\nimport { enableDataZoom, getDateRange, getFormattedDate, getYAxes, restoreChart, ZoomEventData } from './utils';\n\nuse([\n EChartsLineChart,\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n CanvasRenderer,\n]);\n\nexport type TooltipConfig = {\n wrapLabels: boolean;\n hidden?: boolean;\n};\n\nexport interface LineChartProps {\n /**\n * Height of the chart\n */\n height: number;\n data: EChartsDataFormat;\n yAxis?: YAXisComponentOption;\n unit?: UnitOptions;\n grid?: GridComponentOption;\n legend?: LegendComponentOption;\n tooltipConfig?: TooltipConfig;\n noDataVariant?: 'chart' | 'message';\n onDataZoom?: (e: ZoomEventData) => void;\n onDoubleClick?: (e: MouseEvent) => void;\n __experimentalEChartsOptionsOverride?: (options: EChartsCoreOption) => EChartsCoreOption;\n}\n\nexport function LineChart({\n height,\n data,\n yAxis,\n unit,\n grid,\n legend,\n tooltipConfig = { wrapLabels: true },\n noDataVariant = 'message',\n onDataZoom,\n onDoubleClick,\n __experimentalEChartsOptionsOverride,\n}: LineChartProps) {\n const chartsTheme = useChartsTheme();\n const chartRef = useRef<EChartsInstance>();\n const [showTooltip, setShowTooltip] = useState<boolean>(true);\n const [isTooltipPinned, setIsTooltipPinned] = useState<boolean>(false);\n const { timeZone } = useTimeZone();\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 setIsTooltipPinned(false);\n }, 10);\n }\n if (onDataZoom === undefined || params.batch[0] === undefined) return;\n const startIndex = params.batch[0].startValue ?? 0;\n const endIndex = params.batch[0].endValue ?? data.xAxis.length - 1;\n const xAxisStartValue = data.xAxis[startIndex];\n const xAxisEndValue = data.xAxis[endIndex];\n\n if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {\n const zoomEvent: ZoomEventData = {\n start: xAxisStartValue,\n end: xAxisEndValue,\n startIndex,\n endIndex,\n };\n onDataZoom(zoomEvent);\n }\n },\n // TODO: use legendselectchanged event to fix tooltip when legend selected\n };\n }, [data, onDataZoom, setIsTooltipPinned]);\n\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n\n const handleOnDoubleClick = (e: MouseEvent) => {\n setIsTooltipPinned(false);\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 const { noDataOption } = chartsTheme;\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.timeSeries === 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.timeSeries === null || (data.timeSeries.length === 0 && noDataVariant === 'message')) return noDataOption;\n\n const rangeMs = data.rangeMs ?? getDateRange(data.xAxis);\n\n const option: EChartsCoreOption = {\n series: data.timeSeries,\n xAxis: {\n type: 'category',\n data: data.xAxis,\n max: data.xAxisMax,\n axisLabel: {\n formatter: (value: number) => {\n return getFormattedDate(value, rangeMs, timeZone);\n },\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 legend,\n };\n\n if (__experimentalEChartsOptionsOverride) {\n return __experimentalEChartsOptionsOverride(option);\n }\n return option;\n }, [data, yAxis, unit, grid, legend, noDataOption, timeZone, __experimentalEChartsOptionsOverride, noDataVariant]);\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 setIsTooltipPinned((current) => !current);\n }\n }}\n onMouseDown={(e) => {\n // Hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels.\n if (e.target instanceof HTMLCanvasElement) {\n setShowTooltip(false);\n }\n }}\n onMouseUp={() => {\n setShowTooltip(true);\n }}\n onMouseLeave={() => {\n setShowTooltip(false);\n }}\n onMouseEnter={() => {\n setShowTooltip(true);\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n }}\n onDoubleClick={handleOnDoubleClick}\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 <TimeSeriesTooltip\n chartRef={chartRef}\n chartData={data}\n wrapLabels={tooltipConfig.wrapLabels}\n isTooltipPinned={isTooltipPinned}\n unit={unit}\n onUnpinClick={() => {\n setIsTooltipPinned(false);\n }}\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 />\n </Box>\n );\n}\n"],"names":["React","useMemo","useRef","useState","Box","use","LineChart","EChartsLineChart","GridComponent","DataZoomComponent","MarkAreaComponent","MarkLineComponent","MarkPointComponent","TitleComponent","ToolboxComponent","TooltipComponent","LegendComponent","CanvasRenderer","EChart","useChartsTheme","TimeSeriesTooltip","useTimeZone","enableDataZoom","getDateRange","getFormattedDate","getYAxes","restoreChart","height","data","yAxis","unit","grid","legend","tooltipConfig","wrapLabels","noDataVariant","onDataZoom","onDoubleClick","__experimentalEChartsOptionsOverride","option","chartsTheme","chartRef","showTooltip","setShowTooltip","isTooltipPinned","setIsTooltipPinned","timeZone","handleEvents","datazoom","params","undefined","setTimeout","batch","startIndex","startValue","endIndex","endValue","xAxis","length","xAxisStartValue","xAxisEndValue","zoomEvent","start","end","current","handleOnDoubleClick","e","noDataOption","timeSeries","rangeMs","series","type","max","xAxisMax","axisLabel","formatter","value","animation","tooltip","show","trigger","showContent","axisPointer","z","triggerEmphasis","triggerTooltip","snap","toolbox","feature","dataZoom","icon","yAxisIndex","sx","onClick","target","HTMLCanvasElement","onMouseDown","onMouseUp","onMouseLeave","onMouseEnter","hidden","chartData","onUnpinClick","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;AAAA,OAAOA,KAAK,IAAgBC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACrE,SAASC,GAAG,QAAQ,eAAe,CAAC;AASpC,SAAqCC,GAAG,QAAQ,cAAc,CAAC;AAC/D,SAASC,SAAS,IAAIC,gBAAgB,QAAQ,gBAAgB,CAAC;AAC/D,SACEC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,EACdC,gBAAgB,EAChBC,gBAAgB,EAChBC,eAAe,QACV,oBAAoB,CAAC;AAC5B,SAASC,cAAc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[],"mappings":";AAiBA,OAAO,EAAiC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIjF,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"StatChart.d.ts","sourceRoot":"","sources":["../../src/StatChart/StatChart.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAiC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIjF,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAiG9C"}
|
|
@@ -109,11 +109,15 @@ export function StatChart(props) {
|
|
|
109
109
|
sx: (theme)=>({
|
|
110
110
|
color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
|
|
111
111
|
fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
|
|
112
|
-
padding: `${containerPadding} ${containerPadding} 0 ${containerPadding}`
|
|
112
|
+
padding: sparkline ? `${containerPadding} ${containerPadding} 0 ${containerPadding}` : ` 0 ${containerPadding}`
|
|
113
113
|
}),
|
|
114
114
|
children: formattedValue
|
|
115
115
|
}),
|
|
116
116
|
sparkline !== undefined && /*#__PURE__*/ _jsx(EChart, {
|
|
117
|
+
sx: {
|
|
118
|
+
width: '100%',
|
|
119
|
+
height: '100%'
|
|
120
|
+
},
|
|
117
121
|
option: option,
|
|
118
122
|
theme: chartsTheme.echartsTheme,
|
|
119
123
|
renderer: "svg"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/StatChart/StatChart.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useMemo } from 'react';\nimport { Box, Typography } from '@mui/material';\nimport { merge } from 'lodash-es';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { formatValue, UnitOptions } from '../model/units';\nimport { EChart } from '../EChart';\nimport { GraphSeries } from '../model/graph';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst MIN_VALUE_SIZE = 12;\nconst MAX_VALUE_SIZE = 36;\n\nexport interface StatChartData {\n calculatedValue?: number;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n unit: UnitOptions;\n color?: string;\n sparkline?: LineSeriesOption;\n}\n\nexport function StatChart(props: StatChartProps) {\n const { width, height, data, unit, color, sparkline } = props;\n const chartsTheme = useChartsTheme();\n\n const formattedValue = data.calculatedValue === undefined ? '' : formatValue(data.calculatedValue, unit);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.seriesData === undefined) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline !== undefined) {\n const lineSeries = {\n type: 'line',\n data: [...series.values],\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n const mergedSeries = merge(lineSeries, sparkline);\n statSeries.push(mergedSeries);\n }\n\n const option = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline]);\n\n const isLargePanel = width > 250 && height > 180;\n // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute\n const charactersAdjust = formattedValue.length;\n const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;\n\n const containerPadding = `${chartsTheme.container.padding.default}px`;\n\n const textAlignment = sparkline ? 'auto' : 'center';\n const textStyles = {\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n };\n\n return (\n <Box sx={{ height: '100%', width: '100%', ...textStyles }}>\n <Typography\n variant=\"h3\"\n sx={(theme) => ({\n color: color ?? theme.palette.text.primary,\n fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,\n padding: `${containerPadding} ${containerPadding} 0 ${containerPadding}`,\n })}\n >\n {formattedValue}\n </Typography>\n {sparkline !== undefined && <EChart option={option}
|
|
1
|
+
{"version":3,"sources":["../../src/StatChart/StatChart.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useMemo } from 'react';\nimport { Box, Typography } from '@mui/material';\nimport { merge } from 'lodash-es';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { formatValue, UnitOptions } from '../model/units';\nimport { EChart } from '../EChart';\nimport { GraphSeries } from '../model/graph';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst MIN_VALUE_SIZE = 12;\nconst MAX_VALUE_SIZE = 36;\n\nexport interface StatChartData {\n calculatedValue?: number;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n unit: UnitOptions;\n color?: string;\n sparkline?: LineSeriesOption;\n}\n\nexport function StatChart(props: StatChartProps) {\n const { width, height, data, unit, color, sparkline } = props;\n const chartsTheme = useChartsTheme();\n\n const formattedValue = data.calculatedValue === undefined ? '' : formatValue(data.calculatedValue, unit);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.seriesData === undefined) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline !== undefined) {\n const lineSeries = {\n type: 'line',\n data: [...series.values],\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n const mergedSeries = merge(lineSeries, sparkline);\n statSeries.push(mergedSeries);\n }\n\n const option = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline]);\n\n const isLargePanel = width > 250 && height > 180;\n // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute\n const charactersAdjust = formattedValue.length;\n const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;\n\n const containerPadding = `${chartsTheme.container.padding.default}px`;\n\n const textAlignment = sparkline ? 'auto' : 'center';\n const textStyles = {\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n };\n\n return (\n <Box sx={{ height: '100%', width: '100%', ...textStyles }}>\n <Typography\n variant=\"h3\"\n sx={(theme) => ({\n color: color ?? theme.palette.text.primary,\n fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,\n padding: sparkline\n ? `${containerPadding} ${containerPadding} 0 ${containerPadding}`\n : ` 0 ${containerPadding}`,\n })}\n >\n {formattedValue}\n </Typography>\n {sparkline !== undefined && (\n <EChart\n sx={{\n width: '100%',\n height: '100%',\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n renderer=\"svg\"\n />\n )}\n </Box>\n );\n}\n"],"names":["useMemo","Box","Typography","merge","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","formatValue","EChart","MIN_VALUE_SIZE","MAX_VALUE_SIZE","StatChart","props","width","height","data","unit","color","sparkline","chartsTheme","formattedValue","calculatedValue","undefined","option","seriesData","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","tooltip","isLargePanel","charactersAdjust","length","valueSize","Math","min","containerPadding","container","padding","default","textAlignment","textStyles","display","flexDirection","justifyContent","alignItems","sx","variant","theme","palette","text","primary","fontSize","echartsTheme","renderer"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAChD,SAASC,KAAK,QAAQ,WAAW,CAAC;AAClC,SAASC,GAAG,QAA2B,cAAc,CAAC;AACtD,SAASC,SAAS,IAAIC,gBAAgB,QAA0B,gBAAgB,CAAC;AACjF,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,oBAAoB,CAAC;AACvG,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,cAAc,QAAQ,gCAAgC,CAAC;AAChE,SAASC,WAAW,QAAqB,gBAAgB,CAAC;AAC1D,SAASC,MAAM,QAAQ,WAAW,CAAC;AAGnCV,GAAG,CAAC;IAACE,gBAAgB;IAAEC,aAAa;IAAEC,gBAAgB;IAAEC,cAAc;IAAEC,gBAAgB;IAAEC,cAAc;CAAC,CAAC,CAAC;AAE3G,MAAMI,cAAc,GAAG,EAAE,AAAC;AAC1B,MAAMC,cAAc,GAA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,KAAK,EAAEA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAIkD,KAAK,CAACC,OAAO,CAACC,IAAI,CAACC,OAAO;wBAC1CC,QAAQ,EAAE,CAAC,MAAM,EAAE9D,cAAc,CAAC,IAAI,EAAE2C,SAAS,CAAC,IAAI,EAAE1C,cAAc,CAAC,GAAG,CAAC;wBAC3E+C,OAAO,EAAEvC,SAAS,GACd,CAAC,EAAEqC,gBAAgB,CAAC,CAAC,EAAEA,gBAAgB,CAAC,GAAG,EAAEA,gBAAgB,CAAC,CAAC,GAC/D,CAAC,GAAG,EAAEA,gBAAgB,CAAC,CAAC;qBAC7B,CAAA,AAAC;0BAEDnC,cAAc;cACJ;YACZF,SAAS,KAAKI,SAAS,kBACtB,KAACd,MAAM;gBACLyD,EAAE,EAAE;oBACFpD,KAAK,EAAE,MAAM;oBACbC,MAAM,EAAE,MAAM;iBACf;gBACDS,MAAM,EAAEA,MAAM;gBACd4C,KAAK,EAAEhD,WAAW,CAACqD,YAAY;gBAC/BC,QAAQ,EAAC,KAAK;cACd,AACH;;MACG,CACN;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TableProps as MuiTableProps } from '@mui/material';
|
|
3
|
+
import { TableDensity } from './model/table-model';
|
|
4
|
+
declare type InnerTableProps = Omit<MuiTableProps, 'size'> & {
|
|
5
|
+
density: TableDensity;
|
|
6
|
+
};
|
|
7
|
+
export declare const InnerTable: import("react").ForwardRefExoticComponent<Pick<InnerTableProps, keyof import("@mui/material/OverridableComponent").CommonProps | "children" | "sx" | "slot" | "summary" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "width" | "border" | "bgcolor" | "padding" | "align" | "cellPadding" | "cellSpacing" | "frame" | "rules" | "density" | "stickyHeader"> & import("react").RefAttributes<HTMLTableElement>>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=InnerTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InnerTable.d.ts","sourceRoot":"","sources":["../../src/Table/InnerTable.tsx"],"names":[],"mappings":";AAaA,OAAO,EAA6B,UAAU,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AAEvF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AASnD,aAAK,eAAe,GAAG,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,GAAG;IACnD,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AAOF,eAAO,MAAM,UAAU,8yJAerB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 } from "react/jsx-runtime";
|
|
14
|
+
import { Table as MuiTable, styled } from '@mui/material';
|
|
15
|
+
import { forwardRef } from 'react';
|
|
16
|
+
const StyledMuiTable = styled(MuiTable)(({ theme })=>({
|
|
17
|
+
// This value is needed to have a consistent table layout when scrolling.
|
|
18
|
+
tableLayout: 'fixed',
|
|
19
|
+
borderCollapse: 'separate',
|
|
20
|
+
backgroundColor: theme.palette.background.paper
|
|
21
|
+
}));
|
|
22
|
+
const TABLE_DENSITY_CONFIG = {
|
|
23
|
+
compact: 'small',
|
|
24
|
+
standard: 'medium'
|
|
25
|
+
};
|
|
26
|
+
export const InnerTable = /*#__PURE__*/ forwardRef(function InnerTable({ density , width , ...otherProps }, ref) {
|
|
27
|
+
return /*#__PURE__*/ _jsx(StyledMuiTable, {
|
|
28
|
+
...otherProps,
|
|
29
|
+
tabIndex: -1,
|
|
30
|
+
size: TABLE_DENSITY_CONFIG[density],
|
|
31
|
+
ref: ref,
|
|
32
|
+
sx: {
|
|
33
|
+
width: width
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=InnerTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Table/InnerTable.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Table as MuiTable, styled, TableProps as MuiTableProps } from '@mui/material';\nimport { forwardRef } from 'react';\nimport { TableDensity } from './model/table-model';\n\nconst StyledMuiTable = styled(MuiTable)(({ theme }) => ({\n // This value is needed to have a consistent table layout when scrolling.\n tableLayout: 'fixed',\n borderCollapse: 'separate',\n backgroundColor: theme.palette.background.paper,\n}));\n\ntype InnerTableProps = Omit<MuiTableProps, 'size'> & {\n density: TableDensity;\n};\n\nconst TABLE_DENSITY_CONFIG: Record<TableDensity, MuiTableProps['size']> = {\n compact: 'small',\n standard: 'medium',\n};\n\nexport const InnerTable = forwardRef<HTMLTableElement, InnerTableProps>(function InnerTable(\n { density, width, ...otherProps },\n ref\n) {\n return (\n <StyledMuiTable\n {...otherProps}\n tabIndex={-1}\n size={TABLE_DENSITY_CONFIG[density]}\n ref={ref}\n sx={{\n width: width,\n }}\n />\n );\n});\n"],"names":["Table","MuiTable","styled","forwardRef","StyledMuiTable","theme","tableLayout","borderCollapse","backgroundColor","palette","background","paper","TABLE_DENSITY_CONFIG","compact","standard","InnerTable","density","width","otherProps","ref","tabIndex","size","sx"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,QAAqC,eAAe,CAAC;AACvF,SAASC,UAAU,QAAQ,OAAO,CAAC;AAGnC,MAAMC,cAAc,GAAGF,MAAM,CAACD,QAAQ,CAAC,CAAC,CAAC,EAAEI,KAAK,CAAA,EAAE,GAAM,CAAA;QACtD,yEAAyE;QACzEC,WAAW,EAAE,OAAO;QACpBC,cAAc,EAAE,UAAU;QAC1BC,eAAe,EAAEH,KAAK,CAACI,OAAO,CAACC,UAAU,CAACC,KAAK;KAChD,CAAA,AAAC,CAAC,AAAC;AAMJ,MAAMC,oBAAoB,GAAgD;IACxEC,OAAO,EAAE,OAAO;IAChBC,QAAQ,EAAE,QAAQ;CACnB,AAAC;AAEF,OAAO,MAAMC,UAAU,iBAAGZ,UAAU,CAAoC,SAASY,UAAU,CACzF,EAAEC,OAAO,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGC,UAAU,EAAE,EACjCC,GAAG,EACH;IACA,qBACE,KAACf,cAAc;QACZ,GAAGc,UAAU;QACdE,QAAQ,EAAE,CAAC,CAAC;QACZC,IAAI,EAAET,oBAAoB,CAACI,OAAO,CAAC;QACnCG,GAAG,EAAEA,GAAG;QACRG,EAAE,EAAE;YACFL,KAAK,EAAEA,KAAK;SACb;MACD,CACF;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TableProps } from './model/table-model';
|
|
3
|
+
/**
|
|
4
|
+
* Component used to render tabular data in Perses use cases. This component is
|
|
5
|
+
* **not** intended to be a general use data table for use cases unrelated to Perses.
|
|
6
|
+
*
|
|
7
|
+
* **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**
|
|
8
|
+
*/
|
|
9
|
+
export declare function Table<TableData>({ data, columns, density, checkboxSelection, onRowSelectionChange, getCheckboxColor, getRowId, rowSelection, ...otherProps }: TableProps<TableData>): JSX.Element;
|
|
10
|
+
//# sourceMappingURL=Table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../src/Table/Table.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,UAAU,EAAkC,MAAM,qBAAqB,CAAC;AAMjF;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,SAAS,EAAE,EAC/B,IAAI,EACJ,OAAO,EACP,OAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,QAA6B,EAC7B,YAAiB,EACjB,GAAG,UAAU,EACd,EAAE,UAAU,CAAC,SAAS,CAAC,eA+EvB"}
|