@perses-dev/components 0.26.0 → 0.27.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/InfoTooltip/InfoTooltip.d.ts.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.js +8 -5
- package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
- package/dist/Legend/CompactLegend.d.ts +3 -1
- package/dist/Legend/CompactLegend.d.ts.map +1 -1
- package/dist/Legend/CompactLegend.js +3 -1
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.d.ts +10 -1
- package/dist/Legend/Legend.d.ts.map +1 -1
- package/dist/Legend/Legend.js +24 -7
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/ListLegend.d.ts +14 -4
- package/dist/Legend/ListLegend.d.ts.map +1 -1
- package/dist/Legend/ListLegend.js +111 -15
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.d.ts +14 -2
- package/dist/Legend/ListLegendItem.d.ts.map +1 -1
- package/dist/Legend/ListLegendItem.js +31 -3
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/LineChart/LineChart.d.ts +0 -1
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +3 -4
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts +4 -2
- package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +34 -5
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
- package/dist/StatChart/StatChart.d.ts +1 -0
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +2 -2
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.d.ts +3 -1
- package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.js +9 -3
- package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js +57 -35
- package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +0 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js +3 -4
- package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +0 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -3
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts +0 -1
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +1 -2
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +1 -9
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +3 -7
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/utils.js +9 -6
- package/dist/TimeSeriesTooltip/utils.js.map +1 -1
- package/dist/cjs/InfoTooltip/InfoTooltip.js +8 -5
- package/dist/cjs/Legend/Legend.js +24 -7
- package/dist/cjs/Legend/ListLegend.js +106 -13
- package/dist/cjs/Legend/ListLegendItem.js +30 -2
- package/dist/cjs/LineChart/LineChart.js +3 -4
- package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +33 -4
- package/dist/cjs/StatChart/StatChart.js +2 -2
- package/dist/cjs/ThresholdsEditor/ThresholdInput.js +8 -2
- package/dist/cjs/ThresholdsEditor/ThresholdsEditor.js +56 -34
- package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +3 -4
- package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -3
- package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +1 -2
- package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +3 -7
- package/dist/cjs/TimeSeriesTooltip/utils.js +9 -6
- package/dist/cjs/model/units/bytes.js +33 -39
- package/dist/cjs/model/units/decimal.js +15 -26
- package/dist/cjs/model/units/time.js +2 -3
- package/dist/cjs/utils/theme-gen.js +1 -1
- package/dist/model/legend.d.ts +1 -1
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js.map +1 -1
- package/dist/model/units/bytes.d.ts +1 -5
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +28 -42
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/decimal.d.ts +1 -12
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +14 -30
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +2 -3
- package/dist/model/units/time.js.map +1 -1
- package/dist/utils/theme-gen.js +1 -1
- package/dist/utils/theme-gen.js.map +1 -1
- package/package.json +11 -5
|
@@ -16,7 +16,7 @@ import { SeriesMarker } from './SeriesMarker';
|
|
|
16
16
|
import { SeriesLabelsStack } from './SeriesLabelsStack';
|
|
17
17
|
import { TOOLTIP_LABELS_MAX_WIDTH } from './tooltip-model';
|
|
18
18
|
export function SeriesInfo(props) {
|
|
19
|
-
const { seriesName , formattedY , markerColor , totalSeries , wrapLabels =true
|
|
19
|
+
const { seriesName , formattedY , markerColor , totalSeries , wrapLabels =true } = props;
|
|
20
20
|
// metric __name__ comes before opening curly brace, ignore if not populated
|
|
21
21
|
// ex with metric name: node_load15{env="demo",job="node"}
|
|
22
22
|
// ex without metric name: {env="demo",job="node"}
|
|
@@ -36,9 +36,8 @@ export function SeriesInfo(props) {
|
|
|
36
36
|
markerColor: markerColor
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
//
|
|
40
|
-
const
|
|
41
|
-
const formattedSeriesInfo = seriesInfo.replace(/[,]/g, ', '); // add space after commas so wrapLabels works
|
|
39
|
+
// add space after commas so wrapLabels works
|
|
40
|
+
const formattedSeriesInfo = seriesName.replace(/[,]/g, ', ');
|
|
42
41
|
return /*#__PURE__*/ _jsxs(Box, {
|
|
43
42
|
sx: {
|
|
44
43
|
display: 'table-row',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/SeriesInfo.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 { Box } from '@mui/material';\nimport { SeriesMarker } from './SeriesMarker';\nimport { SeriesLabelsStack } from './SeriesLabelsStack';\nimport { TOOLTIP_LABELS_MAX_WIDTH } from './tooltip-model';\n\nexport interface SeriesInfoProps {\n seriesName: string;\n y: number;\n formattedY: string;\n markerColor: string;\n totalSeries: number;\n wrapLabels?: boolean;\n
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/SeriesInfo.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 { Box } from '@mui/material';\nimport { SeriesMarker } from './SeriesMarker';\nimport { SeriesLabelsStack } from './SeriesLabelsStack';\nimport { TOOLTIP_LABELS_MAX_WIDTH } from './tooltip-model';\n\nexport interface SeriesInfoProps {\n seriesName: string;\n y: number;\n formattedY: string;\n markerColor: string;\n totalSeries: number;\n wrapLabels?: boolean;\n}\n\nexport function SeriesInfo(props: SeriesInfoProps) {\n const { seriesName, formattedY, markerColor, totalSeries, wrapLabels = true } = props;\n\n // metric __name__ comes before opening curly brace, ignore if not populated\n // ex with metric name: node_load15{env=\"demo\",job=\"node\"}\n // ex without metric name: {env=\"demo\",job=\"node\"}\n const splitName = seriesName.split('{');\n const seriesLabels = splitName[1] ?? seriesName;\n\n // remove curly braces that wrap labels\n const formattedSeriesLabels = seriesLabels.replace(/[{}]/g, '');\n\n // determine whether to show labels on separate lines\n const splitLabels = formattedSeriesLabels.split(',');\n if (totalSeries === 1 && splitLabels.length > 1) {\n const metricName = splitName[0] ? `${splitName[0]}:` : 'value:';\n return (\n <SeriesLabelsStack\n formattedY={formattedY}\n metricName={metricName}\n metricLabels={splitLabels}\n markerColor={markerColor}\n />\n );\n }\n\n // add space after commas so wrapLabels works\n const formattedSeriesInfo = seriesName.replace(/[,]/g, ', ');\n\n return (\n <Box\n sx={{\n display: 'table-row',\n paddingTop: 0.5,\n }}\n >\n <Box\n sx={{\n display: 'table-cell',\n maxWidth: '520px',\n }}\n >\n <SeriesMarker markerColor={markerColor} sx={{ marginTop: 0.5 }} />\n <Box\n component=\"span\"\n sx={(theme) => ({\n display: 'inline-block',\n width: 'calc(100% - 20px)',\n minWidth: 150,\n maxWidth: TOOLTIP_LABELS_MAX_WIDTH,\n overflow: 'hidden',\n color: theme.palette.common.white,\n textOverflow: 'ellipsis',\n whiteSpace: wrapLabels ? 'normal' : 'nowrap',\n })}\n >\n {formattedSeriesInfo}\n </Box>\n </Box>\n <Box\n sx={{\n display: 'table-cell',\n paddingLeft: 1.5,\n textAlign: 'right',\n verticalAlign: 'top',\n fontWeight: '700',\n }}\n >\n {formattedY}\n </Box>\n </Box>\n );\n}\n"],"names":["Box","SeriesMarker","SeriesLabelsStack","TOOLTIP_LABELS_MAX_WIDTH","SeriesInfo","props","seriesName","formattedY","markerColor","totalSeries","wrapLabels","splitName","split","seriesLabels","formattedSeriesLabels","replace","splitLabels","length","metricName","metricLabels","formattedSeriesInfo","sx","display","paddingTop","maxWidth","marginTop","component","theme","width","minWidth","overflow","color","palette","common","white","textOverflow","whiteSpace","paddingLeft","textAlign","verticalAlign","fontWeight"],"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,GAAG,QAAQ,eAAe,CAAC;AACpC,SAASC,YAAY,QAAQ,gBAAgB,CAAC;AAC9C,SAASC,iBAAiB,QAAQ,qBAAqB,CAAC;AACxD,SAASC,wBAAwB,QAAQ,iBAAiB,CAAC;AAW3D,OAAO,SAASC,UAAU,CAACC,KAAsB,EAAE;IACjD,MAAM,EAAEC,UAAU,CAAA,EAAEC,UAAU,CAAA,EAAEC,WAAW,CAAA,EAAEC,WAAW,CAAA,EAAEC,UAAU,EAAG,IAAI,CAAA,EAAE,GAAGL,KAAK,AAAC;IAEtF,4EAA4E;IAC5E,0DAA0D;IAC1D,kDAAkD;IAClD,MAAMM,SAAS,GAAGL,UAAU,CAACM,KAAK,CAAC,GAAG,CAAC,AAAC;QACnBD,GAAY;IAAjC,MAAME,YAAY,GAAGF,CAAAA,GAAY,GAAZA,SAAS,CAAC,CAAC,CAAC,cAAZA,GAAY,cAAZA,GAAY,GAAIL,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AACC,KAAK;gCACjCC,YAAY,EAAE,UAAU;gCACxBC,UAAU,EAAE1B,UAAU,GAAG,QAAQ,GAAG,QAAQ;6BAC7C,CAAA,AAAC;kCAEDU,mBAAmB;sBAChB;;cACF;0BACN,KAACpB,GAAG;gBACFqB,EAAE,EAAE;oBACFC,OAAO,EAAE,YAAY;oBACrBe,WAAW,EAAE,GAAG;oBAChBC,SAAS,EAAE,OAAO;oBAClBC,aAAa,EAAE,KAAK;oBACpBC,UAAU,EAAE,KAAK;iBAClB;0BAEAjC,UAAU;cACP;;MACF,CACN;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeSeriesTooltip.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/TimeSeriesTooltip.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAM1D,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IAC9D,SAAS,EAAE,iBAAiB,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,
|
|
1
|
+
{"version":3,"file":"TimeSeriesTooltip.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/TimeSeriesTooltip.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAM1D,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IAC9D,SAAS,EAAE,iBAAiB,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,eAAO,MAAM,iBAAiB,oDA2D5B,CAAC"}
|
|
@@ -17,7 +17,7 @@ import { getFocusedSeriesData } from './focused-series';
|
|
|
17
17
|
import { TOOLTIP_MAX_HEIGHT, TOOLTIP_MAX_WIDTH, useMousePosition } from './tooltip-model';
|
|
18
18
|
import { TooltipContent } from './TooltipContent';
|
|
19
19
|
import { assembleTransform } from './utils';
|
|
20
|
-
export const TimeSeriesTooltip = /*#__PURE__*/ React.memo(function TimeSeriesTooltip({ chartRef , chartData , wrapLabels ,
|
|
20
|
+
export const TimeSeriesTooltip = /*#__PURE__*/ React.memo(function TimeSeriesTooltip({ chartRef , chartData , wrapLabels , pinTooltip , unit }) {
|
|
21
21
|
const [pinnedPos, setPinnedPos] = useState(null);
|
|
22
22
|
const mousePos = useMousePosition();
|
|
23
23
|
if (mousePos === null || mousePos.target === null) return null;
|
|
@@ -62,8 +62,7 @@ export const TimeSeriesTooltip = /*#__PURE__*/ React.memo(function TimeSeriesToo
|
|
|
62
62
|
},
|
|
63
63
|
children: /*#__PURE__*/ _jsx(TooltipContent, {
|
|
64
64
|
focusedSeries: focusedSeries,
|
|
65
|
-
wrapLabels: wrapLabels
|
|
66
|
-
showQuery: showQuery
|
|
65
|
+
wrapLabels: wrapLabels
|
|
67
66
|
})
|
|
68
67
|
})
|
|
69
68
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/TimeSeriesTooltip.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, { useState } from 'react';\nimport { Box, Portal } from '@mui/material';\nimport { ECharts as EChartsInstance } from 'echarts/core';\nimport { EChartsDataFormat, UnitOptions } from '../model';\nimport { getFocusedSeriesData } from './focused-series';\nimport { CursorCoordinates, TOOLTIP_MAX_HEIGHT, TOOLTIP_MAX_WIDTH, useMousePosition } from './tooltip-model';\nimport { TooltipContent } from './TooltipContent';\nimport { assembleTransform } from './utils';\n\ninterface TimeSeriesTooltipProps {\n chartRef: React.MutableRefObject<EChartsInstance | undefined>;\n chartData: EChartsDataFormat;\n pinTooltip: boolean;\n
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/TimeSeriesTooltip.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, { useState } from 'react';\nimport { Box, Portal } from '@mui/material';\nimport { ECharts as EChartsInstance } from 'echarts/core';\nimport { EChartsDataFormat, UnitOptions } from '../model';\nimport { getFocusedSeriesData } from './focused-series';\nimport { CursorCoordinates, TOOLTIP_MAX_HEIGHT, TOOLTIP_MAX_WIDTH, useMousePosition } from './tooltip-model';\nimport { TooltipContent } from './TooltipContent';\nimport { assembleTransform } from './utils';\n\ninterface TimeSeriesTooltipProps {\n chartRef: React.MutableRefObject<EChartsInstance | undefined>;\n chartData: EChartsDataFormat;\n pinTooltip: boolean;\n wrapLabels?: boolean;\n unit?: UnitOptions;\n}\n\nexport const TimeSeriesTooltip = React.memo(function TimeSeriesTooltip({\n chartRef,\n chartData,\n wrapLabels,\n pinTooltip,\n unit,\n}: TimeSeriesTooltipProps) {\n const [pinnedPos, setPinnedPos] = useState<CursorCoordinates | null>(null);\n const mousePos = useMousePosition();\n\n if (mousePos === null || mousePos.target === null) return null;\n\n // ensure user is hovering over a chart before checking for nearby series\n if (pinnedPos === null && (mousePos.target as HTMLElement).tagName !== 'CANVAS') return null;\n\n const chart = chartRef.current;\n const focusedSeries = getFocusedSeriesData(mousePos, chartData, pinnedPos, chart, unit);\n const chartWidth = chart?.getWidth() ?? 750;\n const chartHeight = chart?.getHeight() ?? 230;\n const cursorTransform = assembleTransform(mousePos, focusedSeries.length, chartWidth, chartHeight, pinnedPos);\n\n if (focusedSeries.length === 0) {\n return null;\n }\n\n if (pinTooltip === true && pinnedPos === null) {\n setPinnedPos(mousePos);\n }\n\n return (\n <Portal>\n <Box\n sx={(theme) => ({\n maxWidth: TOOLTIP_MAX_WIDTH,\n maxHeight: TOOLTIP_MAX_HEIGHT,\n position: 'absolute',\n top: 0,\n left: 0,\n backgroundColor: '#2E313E', // TODO: use colors from theme, separate styles for dark mode\n borderRadius: '6px',\n color: '#fff',\n fontSize: '11px',\n visibility: 'visible',\n opacity: 1,\n transition: 'all 0.1s ease-out',\n zIndex: theme.zIndex.tooltip,\n overflow: 'hidden',\n '&:hover': {\n overflowY: 'auto',\n },\n })}\n style={{\n transform: cursorTransform,\n }}\n >\n <TooltipContent focusedSeries={focusedSeries} wrapLabels={wrapLabels} />\n </Box>\n </Portal>\n );\n});\n"],"names":["React","useState","Box","Portal","getFocusedSeriesData","TOOLTIP_MAX_HEIGHT","TOOLTIP_MAX_WIDTH","useMousePosition","TooltipContent","assembleTransform","TimeSeriesTooltip","memo","chartRef","chartData","wrapLabels","pinTooltip","unit","pinnedPos","setPinnedPos","mousePos","target","tagName","chart","current","focusedSeries","chartWidth","getWidth","chartHeight","getHeight","cursorTransform","length","sx","theme","maxWidth","maxHeight","position","top","left","backgroundColor","borderRadius","color","fontSize","visib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Q;oBAClB,SAAS,EAAE;wBACTC,SAAS,EAAE,MAAM;qBAClB;iBACF,CAAA,AAAC;YACFC,KAAK,EAAE;gBACLC,SAAS,EAAErB,eAAe;aAC3B;sBAED,cAAA,KAACrB,cAAc;gBAACgB,aAAa,EAAEA,aAAa;gBAAEV,UAAU,EAAEA,UAAU;cAAI;UACpE;MACC,CACT;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { FocusedSeriesArray } from './focused-series';
|
|
3
3
|
export interface TooltipContentProps {
|
|
4
4
|
focusedSeries: FocusedSeriesArray | null;
|
|
5
|
-
showQuery?: boolean;
|
|
6
5
|
wrapLabels?: boolean;
|
|
7
6
|
}
|
|
8
7
|
export declare function TooltipContent(props: TooltipContentProps): JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TooltipContent.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/TooltipContent.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGtD,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACzC,
|
|
1
|
+
{"version":3,"file":"TooltipContent.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/TooltipContent.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGtD,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACzC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,eAqExD"}
|
|
@@ -16,7 +16,7 @@ import { Box, Divider, Stack, Typography } from '@mui/material';
|
|
|
16
16
|
import { useTimeZone } from '../context/TimeZoneProvider';
|
|
17
17
|
import { SeriesInfo } from './SeriesInfo';
|
|
18
18
|
export function TooltipContent(props) {
|
|
19
|
-
const { focusedSeries ,
|
|
19
|
+
const { focusedSeries , wrapLabels } = props;
|
|
20
20
|
const { formatWithUserTimeZone } = useTimeZone();
|
|
21
21
|
const seriesTime = focusedSeries && focusedSeries[0] && focusedSeries[0].date ? focusedSeries[0].date : null;
|
|
22
22
|
const formatTimeSeriesHeader = (timeString)=>{
|
|
@@ -75,7 +75,6 @@ export function TooltipContent(props) {
|
|
|
75
75
|
formattedY: formattedY,
|
|
76
76
|
markerColor: markerColor,
|
|
77
77
|
totalSeries: sortedFocusedSeries.length,
|
|
78
|
-
showQuery: showQuery,
|
|
79
78
|
wrapLabels: wrapLabels
|
|
80
79
|
}, key);
|
|
81
80
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/TooltipContent.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, Divider, Stack, Typography } from '@mui/material';\nimport { useTimeZone } from '../context/TimeZoneProvider';\nimport { FocusedSeriesArray } from './focused-series';\nimport { SeriesInfo } from './SeriesInfo';\n\nexport interface TooltipContentProps {\n focusedSeries: FocusedSeriesArray | null;\n
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/TooltipContent.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, Divider, Stack, Typography } from '@mui/material';\nimport { useTimeZone } from '../context/TimeZoneProvider';\nimport { FocusedSeriesArray } from './focused-series';\nimport { SeriesInfo } from './SeriesInfo';\n\nexport interface TooltipContentProps {\n focusedSeries: FocusedSeriesArray | null;\n wrapLabels?: boolean;\n}\n\nexport function TooltipContent(props: TooltipContentProps) {\n const { focusedSeries, wrapLabels } = props;\n const { formatWithUserTimeZone } = useTimeZone();\n\n const seriesTime = focusedSeries && focusedSeries[0] && focusedSeries[0].date ? focusedSeries[0].date : null;\n\n const formatTimeSeriesHeader = (timeString: string) => {\n const date = new Date(timeString);\n const formattedDate = formatWithUserTimeZone(date, 'MMM dd, yyyy - ');\n const formattedTime = formatWithUserTimeZone(date, 'HH:mm:ss');\n\n return (\n <>\n <Typography\n variant=\"caption\"\n sx={(theme) => ({\n color: theme.palette.common.white,\n })}\n >\n {formattedDate}\n </Typography>\n <Typography variant=\"caption\">\n <strong>{formattedTime}</strong>\n </Typography>\n </>\n );\n };\n\n const sortedFocusedSeries = useMemo(() => {\n if (focusedSeries === null) return null;\n return focusedSeries.sort((a, b) => (a.y > b.y ? -1 : 1));\n }, [focusedSeries]);\n\n if (sortedFocusedSeries !== null && seriesTime !== null) {\n return (\n <Stack py={1} px={1.5} spacing={0.5}>\n <Typography variant=\"caption\">{formatTimeSeriesHeader(seriesTime)}</Typography>\n <Divider\n sx={(theme) => ({\n borderColor: theme.palette.grey['500'],\n })}\n />\n <Box\n sx={{\n display: 'table',\n }}\n >\n {sortedFocusedSeries.map(({ datumIdx, seriesIdx, seriesName, y, formattedY, markerColor }) => {\n if (datumIdx === null || seriesIdx === null) return null;\n const key = seriesIdx.toString() + datumIdx.toString();\n\n return (\n <SeriesInfo\n key={key}\n seriesName={seriesName}\n y={y}\n formattedY={formattedY}\n markerColor={markerColor}\n totalSeries={sortedFocusedSeries.length}\n wrapLabels={wrapLabels}\n />\n );\n })}\n </Box>\n </Stack>\n );\n } else {\n return <></>;\n }\n}\n"],"names":["useMemo","Box","Divider","Stack","Typography","useTimeZone","SeriesInfo","TooltipContent","props","focusedSeries","wrapLabels","formatWithUserTimeZone","seriesTime","date","formatTimeSeriesHeader","timeString","Date","formattedDate","formattedTime","variant","sx","theme","color","palette","common","white","strong","sortedFocusedSeries","sort","a","b","y","py","px","spacing","borderColor","grey","display","map","datumIdx","seriesIdx","seriesName","formattedY","markerColor","key","toString","totalSeries","length"],"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,OAAO,EAAEC,KAAK,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAChE,SAASC,WAAW,QAAQ,6BAA6B,CAAC;AAE1D,SAASC,UAAU,QAAQ,cAAc,CAAC;AAO1C,OAAO,SAASC,cAAc,CAACC,KAA0B,EAAE;IACzD,MAAM,EAAEC,aAAa,CAAA,EAAEC,UAAU,CAAA,EAAE,GAAGF,KAAK,AAAC;IAC5C,MAAM,EAAEG,sBAAsB,CAAA,EAAE,GAAGN,WAAW,EAAE,AAAC;IAEjD,MAAMO,UAAU,GAAGH,aAAa,IAAIA,aAAa,CAAC,CAAC,CAAC,IAAIA,aAAa,CAAC,CAAC,CAAC,CAACI,IAAI,GAAGJ,aAAa,CAAC,CAAC,CAAC,CAACI,IAAI,GAAG,IAAI,AAAC;IAE7G,MAAMC,sBAAsB,GAAG,CAACC,UAAkB,GAAK;QACrD,MAAMF,IAAI,GAAG,IAAIG,IAAI,CAACD,UAAU,CAAC,AAAC;Q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B,EAAE,EAAE;wBACFiB,OAAO,EAAE,OAAO;qBACjB;8BAEAV,mBAAmB,CAACW,GAAG,CAAC,CAAC,EAAEC,QAAQ,CAAA,EAAEC,SAAS,CAAA,EAAEC,UAAU,CAAA,EAAEV,CAAC,CAAA,EAAEW,UAAU,CAAA,EAAEC,WAAW,CAAA,EAAE,GAAK;wBAC5F,IAAIJ,QAAQ,KAAK,IAAI,IAAIC,SAAS,KAAK,IAAI,EAAE,OAAO,IAAI,CAAC;wBACzD,MAAMI,GAAG,GAAGJ,SAAS,CAACK,QAAQ,EAAE,GAAGN,QAAQ,CAACM,QAAQ,EAAE,AAAC;wBAEvD,qBACE,KAACvC,UAAU;4BAETmC,UAAU,EAAEA,UAAU;4BACtBV,CAAC,EAAEA,CAAC;4BACJW,UAAU,EAAEA,UAAU;4BACtBC,WAAW,EAAEA,WAAW;4BACxBG,WAAW,EAAEnB,mBAAmB,CAACoB,MAAM;4BACvCrC,UAAU,EAAEA,UAAU;2BANjBkC,GAAG,CAOR,CACF;oBACJ,CAAC,CAAC;kBACE;;UACA,CACR;IACJ,OAAO;QACL,qBAAO,mBAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -6,10 +6,6 @@ export declare const TOOLTIP_MAX_ITEMS = 50;
|
|
|
6
6
|
export declare const TOOLTIP_DATE_FORMAT: Intl.DateTimeFormat;
|
|
7
7
|
export declare const defaultCursorData: {
|
|
8
8
|
coords: {
|
|
9
|
-
viewport: {
|
|
10
|
-
x: number;
|
|
11
|
-
y: number;
|
|
12
|
-
};
|
|
13
9
|
plotCanvas: {
|
|
14
10
|
x: number;
|
|
15
11
|
y: number;
|
|
@@ -25,10 +21,6 @@ export declare const defaultCursorData: {
|
|
|
25
21
|
export declare const emptyTooltipData: {
|
|
26
22
|
cursor: {
|
|
27
23
|
coords: {
|
|
28
|
-
viewport: {
|
|
29
|
-
x: number;
|
|
30
|
-
y: number;
|
|
31
|
-
};
|
|
32
24
|
plotCanvas: {
|
|
33
25
|
x: number;
|
|
34
26
|
y: number;
|
|
@@ -44,7 +36,7 @@ export declare const emptyTooltipData: {
|
|
|
44
36
|
focusedSeries: null;
|
|
45
37
|
};
|
|
46
38
|
export interface CursorCoordinates {
|
|
47
|
-
|
|
39
|
+
page: {
|
|
48
40
|
x: number;
|
|
49
41
|
y: number;
|
|
50
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip-model.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/tooltip-model.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,wBAAwB,QAA0B,CAAC;AAEhE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,eAAO,MAAM,mBAAmB,qBAQ9B,CAAC;AAEH,eAAO,MAAM,iBAAiB
|
|
1
|
+
{"version":3,"file":"tooltip-model.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/tooltip-model.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,wBAAwB,QAA0B,CAAC;AAEhE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,eAAO,MAAM,mBAAmB,qBAQ9B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAa7B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;CAG5B,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE;QACJ,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;IACF,UAAU,EAAE;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;IACF,OAAO,EAAE;QACP,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;KACZ,CAAC;IACF,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACzC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,aAAK,iBAAiB,GAAG;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,cAAc,GAAG,gBAAgB,CAAC;IACnD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,oBAAY,eAAe,GAAG,UAAU,GAAG,iBAAiB,CAAC;AAE7D,eAAO,MAAM,gBAAgB,QAAO,UAAU,CAAC,QAAQ,CAgCtD,CAAC"}
|
|
@@ -26,10 +26,6 @@ export const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
|
|
|
26
26
|
});
|
|
27
27
|
export const defaultCursorData = {
|
|
28
28
|
coords: {
|
|
29
|
-
viewport: {
|
|
30
|
-
x: 0,
|
|
31
|
-
y: 0
|
|
32
|
-
},
|
|
33
29
|
plotCanvas: {
|
|
34
30
|
x: 0,
|
|
35
31
|
y: 0
|
|
@@ -51,9 +47,9 @@ export const useMousePosition = ()=>{
|
|
|
51
47
|
useEffect(()=>{
|
|
52
48
|
const setFromEvent = (e)=>{
|
|
53
49
|
return setCoords({
|
|
54
|
-
|
|
55
|
-
x: e.
|
|
56
|
-
y: e.
|
|
50
|
+
page: {
|
|
51
|
+
x: e.pageX,
|
|
52
|
+
y: e.pageY
|
|
57
53
|
},
|
|
58
54
|
plotCanvas: {
|
|
59
55
|
x: e.offsetX,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/tooltip-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 { useEffect, useState } from 'react';\nimport { FocusedSeriesArray } from './focused-series';\n\nexport const TOOLTIP_MAX_WIDTH = 650;\nexport const TOOLTIP_MAX_HEIGHT = 230;\nexport const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;\n\nexport const TOOLTIP_MAX_ITEMS = 50;\n\nexport const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n hour12: true,\n});\n\nexport const defaultCursorData = {\n coords: {\n
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/tooltip-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 { useEffect, useState } from 'react';\nimport { FocusedSeriesArray } from './focused-series';\n\nexport const TOOLTIP_MAX_WIDTH = 650;\nexport const TOOLTIP_MAX_HEIGHT = 230;\nexport const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;\n\nexport const TOOLTIP_MAX_ITEMS = 50;\n\nexport const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n hour12: true,\n});\n\nexport const defaultCursorData = {\n coords: {\n plotCanvas: {\n x: 0,\n y: 0,\n },\n zrender: {\n x: 0,\n y: 0,\n },\n target: null,\n },\n chartWidth: 0,\n};\n\nexport const emptyTooltipData = {\n cursor: defaultCursorData,\n focusedSeries: null,\n};\n\nexport interface CursorCoordinates {\n page: {\n x: number;\n y: number;\n };\n plotCanvas: {\n x: number;\n y: number;\n };\n zrender: {\n x?: number;\n y?: number;\n };\n target: EventTarget | null;\n}\n\nexport interface CursorData {\n coords: CursorCoordinates | null;\n chartWidth?: number;\n}\n\nexport interface TooltipData {\n focusedSeries: FocusedSeriesArray | null;\n cursor: CursorData;\n}\n\ntype ZREventProperties = {\n zrX?: number;\n zrY?: number;\n zrDelta?: number;\n zrEventControl?: 'no_globalout' | 'only_globalout';\n zrByTouch?: boolean;\n};\n\nexport type ZRRawMouseEvent = MouseEvent & ZREventProperties;\n\nexport const useMousePosition = (): CursorData['coords'] => {\n const [coords, setCoords] = useState<CursorData['coords']>(null);\n\n useEffect(() => {\n const setFromEvent = (e: ZRRawMouseEvent) => {\n return setCoords({\n page: {\n x: e.pageX,\n y: e.pageY,\n },\n plotCanvas: {\n x: e.offsetX,\n y: e.offsetY,\n },\n zrender: {\n // echarts canvas coordinates added automatically by zrender\n // zrX and zrY are similar to offsetX and offsetY but they return undefined when not hovering over a chart canvas\n x: e.zrX,\n y: e.zrY,\n },\n // necessary to check whether cursor target matches correct chart canvas (since each chart has its own mousemove listener)\n target: e.target,\n });\n };\n window.addEventListener('mousemove', setFromEvent);\n\n return () => {\n window.removeEventListener('mousemove', setFromEvent);\n };\n }, []);\n\n return coords;\n};\n"],"names":["useEffect","useState","TOOLTIP_MAX_WIDTH","TOOLTIP_MAX_HEIGHT","TOOLTIP_LABELS_MAX_WIDTH","TOOLTIP_MAX_ITEMS","TOOLTIP_DATE_FORMAT","Intl","DateTimeFormat","undefined","year","month","day","hour","minute","second","hour12","defaultCursorData","coords","plotCanvas","x","y","zrender","target","chartWidth","emptyTooltipData","cursor","focusedSeries","useMousePosition","setCoords","setFromEvent","e","page","pageX","pageY","offsetX","offsetY","zrX","zrY","window","addEventListener","removeEventListener"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAG5C,OAAO,MAAMC,iBAAiB,GAAG,GAAG,CAAC;AACrC,OAAO,MAAMC,kBAAkB,GAAG,GAAG,CAAC;AACtC,OAAO,MAAMC,wBAAwB,GAAGF,iBAAiB,GAAG,GAAG,CAAC;AAEhE,OAAO,MAAMG,iBAAiB,GAAG,EAAE,CAAC;AAEpC,OAAO,MAAMC,mBAAmB,GAAG,IAAIC,IAAI,CAACC,cAAc,CAACC,SAAS,EAAE;IACpEC,IAAI,EAAE,SAAS;IACfC,KAAK,EAAE,OAAO;IACdC,GAAG,EAAE,SAAS;IACdC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE,SAAS;IACjBC,MAAM,EAAE,SAAS;IACjBC,MAAM,EAAE,IAAI;CACb,CAAC,CAAC;AAEH,OAAO,MAAMC,iBAAiB,GAAG;IAC/BC,MAAM,EAAE;QACNC,UAAU,EAAE;YACVC,CAAC,EAAE,CAAC;YACJC,CAAC,EAAE,CAAC;SACL;QACDC,OAAO,EAAE;YACPF,CAA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,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAqB,MAAM,iBAAiB,CAAC;AAEnF;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,iBAAiB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAqB,MAAM,iBAAiB,CAAC;AAEnF;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,iBAAiB,GAAG,IAAI,UAwCpC"}
|
|
@@ -22,19 +22,22 @@ import { TOOLTIP_MAX_WIDTH } from './tooltip-model';
|
|
|
22
22
|
}
|
|
23
23
|
const cursorPaddingX = 32;
|
|
24
24
|
const cursorPaddingY = 16;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
// Tooltip is located in a Portal attached to the body.
|
|
26
|
+
// Using page coordinates instead of viewport ensures the tooltip is
|
|
27
|
+
// absolutely positioned correctly as the user scrolls
|
|
28
|
+
const x = mousePos.page.x;
|
|
29
|
+
let y = mousePos.page.y + cursorPaddingY;
|
|
30
|
+
const isCloseToBottom = mousePos.page.y > window.innerHeight * 0.8;
|
|
28
31
|
const yPosAdjustThreshold = chartHeight * 0.75;
|
|
29
32
|
// adjust so tooltip does not get cut off at bottom of chart, reduce multiplier to move up
|
|
30
33
|
if (isCloseToBottom === true) {
|
|
31
34
|
if (seriesNum > 6) {
|
|
32
|
-
y = mousePos.
|
|
35
|
+
y = mousePos.page.y * 0.75;
|
|
33
36
|
} else {
|
|
34
|
-
y = mousePos.
|
|
37
|
+
y = mousePos.page.y * 0.9;
|
|
35
38
|
}
|
|
36
39
|
} else if (mousePos.plotCanvas.y > yPosAdjustThreshold) {
|
|
37
|
-
y = mousePos.
|
|
40
|
+
y = mousePos.page.y * 0.95;
|
|
38
41
|
}
|
|
39
42
|
// use tooltip width to determine when to repos from right to left (width is narrower when only 1 focused series since labels wrap)
|
|
40
43
|
const tooltipWidth = seriesNum > 1 ? TOOLTIP_MAX_WIDTH : TOOLTIP_MAX_WIDTH / 2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/utils.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 { CursorCoordinates, CursorData, TOOLTIP_MAX_WIDTH } from './tooltip-model';\n\n/**\n * Determine position of tooltip depending on chart dimensions and the number of focused series\n */\nexport function assembleTransform(\n mousePos: CursorData['coords'],\n seriesNum: number,\n chartWidth: number,\n chartHeight: number,\n pinnedPos: CursorCoordinates | null\n) {\n if (mousePos === null) {\n return 'translate3d(0, 0)';\n }\n\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n }\n\n const cursorPaddingX = 32;\n const cursorPaddingY = 16;\n const x = mousePos.
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/utils.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 { CursorCoordinates, CursorData, TOOLTIP_MAX_WIDTH } from './tooltip-model';\n\n/**\n * Determine position of tooltip depending on chart dimensions and the number of focused series\n */\nexport function assembleTransform(\n mousePos: CursorData['coords'],\n seriesNum: number,\n chartWidth: number,\n chartHeight: number,\n pinnedPos: CursorCoordinates | null\n) {\n if (mousePos === null) {\n return 'translate3d(0, 0)';\n }\n\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n }\n\n const cursorPaddingX = 32;\n const cursorPaddingY = 16;\n\n // Tooltip is located in a Portal attached to the body.\n // Using page coordinates instead of viewport ensures the tooltip is\n // absolutely positioned correctly as the user scrolls\n const x = mousePos.page.x;\n let y = mousePos.page.y + cursorPaddingY;\n\n const isCloseToBottom = mousePos.page.y > window.innerHeight * 0.8;\n const yPosAdjustThreshold = chartHeight * 0.75;\n // adjust so tooltip does not get cut off at bottom of chart, reduce multiplier to move up\n if (isCloseToBottom === true) {\n if (seriesNum > 6) {\n y = mousePos.page.y * 0.75;\n } else {\n y = mousePos.page.y * 0.9;\n }\n } else if (mousePos.plotCanvas.y > yPosAdjustThreshold) {\n y = mousePos.page.y * 0.95;\n }\n\n // use tooltip width to determine when to repos from right to left (width is narrower when only 1 focused series since labels wrap)\n const tooltipWidth = seriesNum > 1 ? TOOLTIP_MAX_WIDTH : TOOLTIP_MAX_WIDTH / 2;\n const xPosAdjustThreshold = chartWidth - tooltipWidth * 0.9;\n\n // reposition so tooltip is never too close to right side of chart or left side of browser window\n return mousePos.plotCanvas.x > xPosAdjustThreshold && x > TOOLTIP_MAX_WIDTH\n ? `translate3d(${x - cursorPaddingX}px, ${y}px, 0) translateX(-100%)`\n : `translate3d(${x + cursorPaddingX}px, ${y}px, 0)`;\n}\n"],"names":["TOOLTIP_MAX_WIDTH","assembleTransform","mousePos","seriesNum","chartWidth","chartHeight","pinnedPos","cursorPaddingX","cursorPaddingY","x","page","y","isCloseToBottom","window","innerHeight","yPosAdjustThreshold","plotCanvas","tooltipWidth","xPosAdjustThreshold"],"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,SAAwCA,iBAAiB,QAAQ,iBAAiB,CAAC;AAEnF;;CAEC,GACD,OAAO,SAASC,iBAAiB,CAC/BC,QAA8B,EAC9BC,SAAiB,EACjBC,UAAkB,EAClBC,WAAmB,EACnBC,SAAmC,EACnC;IACA,IAAIJ,QAAQ,KAAK,IAAI,EAAE;QACrB,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED,IAAII,SAAS,KAAK,IAAI,EAAE;QACtBJ,QAAQ,GAAGI,SAAS,CAAC;IACvB,CAAC;IAED,MAAMC,cAAc,GAAG,EAAE,AAAC;IAC1B,MAAMC,cAAc,GAAG,EAAE,AAAC;IAE1B,uDAAuD;IACvD,oEAAoE;IACpE,sDAAsD;IACtD,MAAMC,CAAC,GAAGP,QAAQ,CAACQ,IAAI,CAACD,CAAC,AAAC;IAC1B,IAAIE,CAAC,GAAGT,QAAQ,CAACQ,IAAI,CAACC,CAAC,GAAGH,cAAc,AAAC;IAEzC,MAAMI,eAAe,GAAGV,QAAQ,CAACQ,IAAI,CAACC,CAAC,GAAGE,MAAM,CAACC,WAAW,GAAG,GAAG,AAAC;IACnE,MAAMC,mBAAmB,GAAGV,WAAW,GAAG,IAAI,AAAC;IAC/C,0FAA0F;IAC1F,IAAIO,eAAe,KAAK,IAAI,EAAE;QAC5B,IAAIT,SAAS,GAAG,CAAC,EAAE;YACjBQ,CAAC,GAAGT,QAAQ,CAACQ,IAAI,CAACC,CAAC,GAAG,IAAI,CAAC;QAC7B,OAAO;YACLA,CAAC,GAAGT,QAAQ,CAACQ,IAAI,CAACC,CAAC,GAAG,GAAG,CAAC;QAC5B,CAAC;IACH,OAAO,IAAIT,QAAQ,CAACc,UAAU,CAACL,CAAC,GAAGI,mBAAmB,EAAE;QACtDJ,CAAC,GAAGT,QAAQ,CAACQ,IAAI,CAACC,CAAC,GAAG,IAAI,CAAC;IAC7B,CAAC;IAED,mIAAmI;IACnI,MAAMM,YAAY,GAAGd,SAAS,GAAG,CAAC,GAAGH,iBAAiB,GAAGA,iBAAiB,GAAG,CAAC,AAAC;IAC/E,MAAMkB,mBAAmB,GAAGd,UAAU,GAAGa,YAAY,GAAG,GAAG,AAAC;IAE5D,iGAAiG;IACjG,OAAOf,QAAQ,CAACc,UAAU,CAACP,CAAC,GAAGS,mBAAmB,IAAIT,CAAC,GAAGT,iBAAiB,GACvE,CAAC,YAAY,EAAES,CAAC,GAAGF,cAAc,CAAC,IAAI,EAAEI,CAAC,CAAC,wBAAwB,CAAC,GACnE,CAAC,YAAY,EAAEF,CAAC,GAAGF,cAAc,CAAC,IAAI,EAAEI,CAAC,CAAC,MAAM,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -27,10 +27,13 @@ function _interopRequireDefault(obj) {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
const InfoTooltip = ({ id , title , description , placement , children , enterDelay , enterNextDelay })=>{
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
// children
|
|
33
|
-
|
|
30
|
+
// Wrap children in a span to cover the following use cases:
|
|
31
|
+
// - Disabled buttons. MUI console.errors on putting these inside a tooltip.
|
|
32
|
+
// - Non-element tooltip children (e.g. text). The tooltip needs something that
|
|
33
|
+
// can have a ref as a child.
|
|
34
|
+
// We wrap in a `span` and not a `div` to minimize the impact on page layout
|
|
35
|
+
// and styles.
|
|
36
|
+
const wrappedChildren = /*#__PURE__*/ (0, _jsxRuntime.jsx)("span", {
|
|
34
37
|
children: children
|
|
35
38
|
});
|
|
36
39
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(StyledTooltip, {
|
|
@@ -43,7 +46,7 @@ const InfoTooltip = ({ id , title , description , placement , children , enterDe
|
|
|
43
46
|
}),
|
|
44
47
|
enterDelay: enterDelay !== null && enterDelay !== void 0 ? enterDelay : 500,
|
|
45
48
|
enterNextDelay: enterNextDelay !== null && enterNextDelay !== void 0 ? enterNextDelay : 500,
|
|
46
|
-
children:
|
|
49
|
+
children: wrappedChildren
|
|
47
50
|
});
|
|
48
51
|
};
|
|
49
52
|
const TooltipContent = ({ title , description })=>{
|
|
@@ -22,23 +22,35 @@ const _jsxRuntime = require("react/jsx-runtime");
|
|
|
22
22
|
const _material = require("@mui/material");
|
|
23
23
|
const _listLegend = require("./ListLegend");
|
|
24
24
|
const _compactLegend = require("./CompactLegend");
|
|
25
|
-
|
|
25
|
+
// When the number of items to display is above this number, it is likely to
|
|
26
|
+
// cause performance issues in the browser. The legend will be displayed in a
|
|
27
|
+
// format (list) that allows for virtualization to minimize the performance impact.
|
|
28
|
+
// Set this number based on testing, but it may need to be tuned a bit on the
|
|
29
|
+
// future as people test this out on different machines.
|
|
30
|
+
const NEED_VIRTUALIZATION_LIMIT = 500;
|
|
31
|
+
function Legend({ width , height , options , data , listProps }) {
|
|
26
32
|
if (options.position === 'Right') {
|
|
27
33
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
28
34
|
sx: {
|
|
29
35
|
width: width,
|
|
30
|
-
height:
|
|
36
|
+
height: height,
|
|
31
37
|
position: 'absolute',
|
|
32
38
|
top: 0,
|
|
33
|
-
right: 0
|
|
34
|
-
overflowX: 'hidden',
|
|
35
|
-
overflowY: 'scroll'
|
|
39
|
+
right: 0
|
|
36
40
|
},
|
|
37
41
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegend.ListLegend, {
|
|
38
|
-
items: data
|
|
42
|
+
items: data,
|
|
43
|
+
width: width,
|
|
44
|
+
height: height,
|
|
45
|
+
...listProps
|
|
39
46
|
})
|
|
40
47
|
});
|
|
41
48
|
}
|
|
49
|
+
// The bottom legend is displayed as a list when the number of items is too
|
|
50
|
+
// large and requires virtualization. Otherwise, it is rendered more compactly.
|
|
51
|
+
// We do not need this check for the right-side legend because it is always
|
|
52
|
+
// a virtualized list.
|
|
53
|
+
const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;
|
|
42
54
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
43
55
|
sx: {
|
|
44
56
|
width: width,
|
|
@@ -46,7 +58,12 @@ function Legend({ width , height , options , data }) {
|
|
|
46
58
|
position: 'absolute',
|
|
47
59
|
bottom: 0
|
|
48
60
|
},
|
|
49
|
-
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(
|
|
61
|
+
children: needsVirtualization ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegend.ListLegend, {
|
|
62
|
+
items: data,
|
|
63
|
+
width: width,
|
|
64
|
+
height: height,
|
|
65
|
+
...listProps
|
|
66
|
+
}) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_compactLegend.CompactLegend, {
|
|
50
67
|
items: data,
|
|
51
68
|
height: height
|
|
52
69
|
})
|
|
@@ -20,25 +20,118 @@ Object.defineProperty(exports, "ListLegend", {
|
|
|
20
20
|
});
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
22
|
const _material = require("@mui/material");
|
|
23
|
+
const _reactWindow = require("react-window");
|
|
24
|
+
const _react = require("react");
|
|
23
25
|
const _listLegendItem = require("./ListLegendItem");
|
|
24
|
-
|
|
26
|
+
const DEFAULT_INITIAL_ROW_HEIGHT = 26;
|
|
27
|
+
function ListLegend({ items , height , width , initialRowHeight =DEFAULT_INITIAL_ROW_HEIGHT }) {
|
|
28
|
+
// Storing a ref to the react-window `VariableSizeList`, so we can call
|
|
29
|
+
// `resetAfterIndex` to resize the list after mouseover/out events to account
|
|
30
|
+
// for the change in list items on hover.
|
|
31
|
+
const listRef = (0, _react.useRef)(null);
|
|
32
|
+
// Storing row heights, so we can use dynamic heights, which enables the
|
|
33
|
+
// user the hover to show the full label, while still having a virtualized
|
|
34
|
+
// list.
|
|
35
|
+
const rowHeights = (0, _react.useRef)({});
|
|
36
|
+
const theme = (0, _material.useTheme)();
|
|
37
|
+
// Padding value used throughout to adjust the react-window virtual layouts
|
|
38
|
+
// to simulate padding per the guidance from:
|
|
39
|
+
// https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list
|
|
40
|
+
const LIST_PADDING = parseInt(theme.spacing(1), 10);
|
|
25
41
|
// show full labels on hover when there are many total series
|
|
26
42
|
const truncateLabels = items.length > 5;
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
// Gets the row height for a given item to enable the virtualized list to
|
|
44
|
+
// render the row properly.
|
|
45
|
+
function getRowHeight(index) {
|
|
46
|
+
const currentHeight = rowHeights.current[index];
|
|
47
|
+
return currentHeight !== null && currentHeight !== void 0 ? currentHeight : initialRowHeight;
|
|
48
|
+
}
|
|
49
|
+
// Set the height for a given item to enable the virtualized list to
|
|
50
|
+
// adjust to size changes.
|
|
51
|
+
function setRowHeight(index, size) {
|
|
52
|
+
var // Tell the virtualized list that items changed size and need to be
|
|
53
|
+
// re-evaluated.
|
|
54
|
+
ref;
|
|
55
|
+
(ref = listRef.current) === null || ref === void 0 ? void 0 : ref.resetAfterIndex(0);
|
|
56
|
+
rowHeights.current = {
|
|
57
|
+
...rowHeights.current,
|
|
58
|
+
[index]: size
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// Renderer for virtualized rows in `VariableSizeList`.
|
|
62
|
+
function ListLegendRow({ index , style }) {
|
|
63
|
+
// Storing a ref to the row's `ListLegendItem`, so we can get the "real"
|
|
64
|
+
// height and adjust the height of the row based on it, enabling the dynamic
|
|
65
|
+
// heights on hover.
|
|
66
|
+
const rowRef = (0, _react.useRef)(null);
|
|
67
|
+
// useCallback is important here to avoid constantly running the useEffect
|
|
68
|
+
// that calls this in `ListLegendItem`.
|
|
69
|
+
const handleRowLayoutChange = (0, _react.useCallback)(()=>{
|
|
70
|
+
// Handle size changes from hovering on a list item.
|
|
71
|
+
if (rowRef.current) {
|
|
72
|
+
setRowHeight(index, rowRef.current.clientHeight);
|
|
73
|
+
}
|
|
74
|
+
}, [
|
|
75
|
+
index
|
|
76
|
+
]);
|
|
77
|
+
// Adjust row heights when the row being rendered changes.
|
|
78
|
+
(0, _react.useEffect)(()=>{
|
|
79
|
+
handleRowLayoutChange();
|
|
80
|
+
}, [
|
|
81
|
+
handleRowLayoutChange
|
|
82
|
+
]);
|
|
83
|
+
const item = items[index];
|
|
84
|
+
if (!item) {
|
|
85
|
+
// This shouldn't happen if configured correctly, but covering
|
|
86
|
+
// the case to appease the type checking and to cover any edge
|
|
87
|
+
// cases.
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const originalTop = parseFloat(`${style.top}`);
|
|
91
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
92
|
+
style: {
|
|
93
|
+
...style,
|
|
94
|
+
// Adjust the top position to simulate top padding on the list.
|
|
95
|
+
top: `${originalTop + LIST_PADDING}px`
|
|
96
|
+
},
|
|
97
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegendItem.ListLegendItem, {
|
|
98
|
+
ref: rowRef,
|
|
29
99
|
item: item,
|
|
100
|
+
truncateLabel: truncateLabels,
|
|
101
|
+
onLayoutChange: handleRowLayoutChange,
|
|
30
102
|
sx: {
|
|
31
|
-
width
|
|
32
|
-
|
|
103
|
+
// Having an explicit width is important for the ellipsizing to
|
|
104
|
+
// work correctly. Subtract padding to simulate padding.
|
|
105
|
+
width: width - LIST_PADDING,
|
|
33
106
|
wordBreak: 'break-word',
|
|
34
|
-
overflow:
|
|
35
|
-
whiteSpace: truncateLabels ? 'nowrap' : 'normal',
|
|
36
|
-
// TODO: add optional hover effect to show unformatted label
|
|
37
|
-
'&:hover': {
|
|
38
|
-
overflow: 'visible',
|
|
39
|
-
whiteSpace: 'normal'
|
|
40
|
-
}
|
|
107
|
+
overflow: 'hidden'
|
|
41
108
|
}
|
|
42
|
-
}, item.id)
|
|
109
|
+
}, item.id)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
// Renderer for the inner container element of the `VariableSizeList` used
|
|
113
|
+
// to adjust styles to simulate padding on the list per:
|
|
114
|
+
// https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list
|
|
115
|
+
const InnerElementType = /*#__PURE__*/ (0, _react.forwardRef)(function InnerElementType({ style , ...rest }, ref) {
|
|
116
|
+
const originalHeight = (style === null || style === void 0 ? void 0 : style.height) ? parseFloat(`${style === null || style === void 0 ? void 0 : style.height}`) : 0;
|
|
117
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
118
|
+
ref: ref,
|
|
119
|
+
role: "list",
|
|
120
|
+
style: {
|
|
121
|
+
...style,
|
|
122
|
+
// Adjust height to account for simulated padding.
|
|
123
|
+
height: `${originalHeight + LIST_PADDING * 2}px`
|
|
124
|
+
},
|
|
125
|
+
...rest
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactWindow.VariableSizeList, {
|
|
129
|
+
height: height,
|
|
130
|
+
width: width,
|
|
131
|
+
itemCount: items.length,
|
|
132
|
+
itemSize: getRowHeight,
|
|
133
|
+
innerElementType: InnerElementType,
|
|
134
|
+
ref: listRef,
|
|
135
|
+
children: ListLegendRow
|
|
43
136
|
});
|
|
44
137
|
}
|