@perses-dev/components 0.55.0-beta.13 → 0.55.0-beta.15
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/DragAndDrop/DragAndDropList.d.ts +10 -2
- package/dist/DragAndDrop/DragAndDropList.d.ts.map +1 -1
- package/dist/DragAndDrop/DragAndDropList.js +6 -4
- package/dist/DragAndDrop/DragAndDropList.js.map +1 -1
- package/dist/EChart/EChart.d.ts +1 -1
- package/dist/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +12 -25
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/Legend/TableLegend.js.map +1 -1
- package/dist/LinksEditor/LinkEditorForm.d.ts +1 -0
- package/dist/LinksEditor/LinkEditorForm.d.ts.map +1 -1
- package/dist/LinksEditor/LinkEditorForm.js +1 -0
- package/dist/LinksEditor/LinkEditorForm.js.map +1 -1
- package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts.map +1 -1
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js +6 -3
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +3 -0
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableToolbar.d.ts.map +1 -1
- package/dist/Table/TableToolbar.js +1 -0
- package/dist/Table/TableToolbar.js.map +1 -1
- package/dist/Table/VirtualizedTable.d.ts +1 -1
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +10 -19
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/model/table-model.d.ts +6 -2
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js +1 -3
- package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js +4 -4
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js +27 -16
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/utils.js +6 -2
- package/dist/TimeSeriesTooltip/utils.js.map +1 -1
- package/dist/controls/TextField.d.ts.map +1 -1
- package/dist/controls/TextField.js +15 -10
- package/dist/controls/TextField.js.map +1 -1
- package/dist/utils/component-ids.d.ts +1 -6
- package/dist/utils/component-ids.d.ts.map +1 -1
- package/dist/utils/component-ids.js +5 -12
- package/dist/utils/component-ids.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +14 -18
- package/dist/utils/text.js.map +1 -1
- package/package.json +3 -3
- package/dist/utils/memo.d.ts +0 -13
- package/dist/utils/memo.d.ts.map +0 -1
- package/dist/utils/memo.js +0 -50
- package/dist/utils/memo.js.map +0 -1
|
@@ -15,7 +15,7 @@ import { Box, MenuItem, Popover, Select, IconButton, TextField, Stack } from "@m
|
|
|
15
15
|
import { isRelativeTimeRange, toAbsoluteTimeRange } from "@perses-dev/spec";
|
|
16
16
|
import Calendar from "mdi-material-ui/Calendar";
|
|
17
17
|
import EarthIcon from "mdi-material-ui/Earth";
|
|
18
|
-
import { useMemo,
|
|
18
|
+
import { useMemo, useState } from "react";
|
|
19
19
|
import { useTimeZone } from "../context/index.js";
|
|
20
20
|
import { getTimeZoneOptions } from "../model/timeZoneOption.js";
|
|
21
21
|
import { SettingsAutocomplete } from "../SettingsAutocomplete/index.js";
|
|
@@ -30,7 +30,7 @@ import { buildCustomTimeOption, formatTimeRange } from "./utils.js";
|
|
|
30
30
|
*/ export function TimeRangeSelector({ value, timeOptions, onChange, height, showCustomTimeRange = true, timeZone: timeZoneProp, timeZoneOptions, onTimeZoneChange }) {
|
|
31
31
|
const { timeZone: ctxTimeZone } = useTimeZone();
|
|
32
32
|
const timeZone = timeZoneProp ?? ctxTimeZone;
|
|
33
|
-
const anchorEl =
|
|
33
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
34
34
|
const [showCustomDateSelector, setShowCustomDateSelector] = useState(false);
|
|
35
35
|
const convertedTimeRange = useMemo(()=>{
|
|
36
36
|
return isRelativeTimeRange(value) ? toAbsoluteTimeRange(value) : value;
|
|
@@ -98,7 +98,7 @@ import { buildCustomTimeOption, formatTimeRange } from "./utils.js";
|
|
|
98
98
|
})
|
|
99
99
|
}),
|
|
100
100
|
/*#__PURE__*/ _jsx(Popover, {
|
|
101
|
-
anchorEl: anchorEl
|
|
101
|
+
anchorEl: anchorEl,
|
|
102
102
|
anchorOrigin: {
|
|
103
103
|
vertical: 'bottom',
|
|
104
104
|
horizontal: 'center'
|
|
@@ -120,7 +120,7 @@ import { buildCustomTimeOption, formatTimeRange } from "./utils.js";
|
|
|
120
120
|
})
|
|
121
121
|
}),
|
|
122
122
|
/*#__PURE__*/ _jsx(Box, {
|
|
123
|
-
ref:
|
|
123
|
+
ref: setAnchorEl,
|
|
124
124
|
children: /*#__PURE__*/ _jsxs(Select, {
|
|
125
125
|
open: open,
|
|
126
126
|
value: formatTimeRange(value, timeZone),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeRangeSelector/TimeRangeSelector.tsx"],"sourcesContent":["// Copyright 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, MenuItem, Popover, Select, IconButton, TextField, Stack } from '@mui/material';\nimport type { TimeRangeValue, AbsoluteTimeRange } from '@perses-dev/spec';\nimport { isRelativeTimeRange, toAbsoluteTimeRange } from '@perses-dev/spec';\nimport Calendar from 'mdi-material-ui/Calendar';\nimport EarthIcon from 'mdi-material-ui/Earth';\nimport type { ReactElement } from 'react';\nimport { useMemo, useRef, useState } from 'react';\n\nimport { useTimeZone } from '../context';\nimport type { TimeOption } from '../model';\nimport type { TimeZoneOption } from '../model/timeZoneOption';\nimport { getTimeZoneOptions } from '../model/timeZoneOption';\nimport { SettingsAutocomplete } from '../SettingsAutocomplete';\nimport { getGMTOffset } from '../utils/format';\nimport { DateTimeRangePicker } from './DateTimeRangePicker';\nimport { buildCustomTimeOption, formatTimeRange } from './utils';\n\ninterface TimeRangeSelectorProps {\n /**\n * The current value of the time range.\n */\n value: TimeRangeValue;\n /**\n * The list of time options to display in the dropdown.\n * The component will automatically add the last two options as a zoom out x2 and a custom absolute time range.\n */\n timeOptions: TimeOption[];\n /**\n * The callback to call when the time range changes.\n */\n onChange: (value: TimeRangeValue) => void;\n /**\n * Custom line height for the select component.\n */\n height?: string;\n /**\n * Whether to show the custom time range option.\n * Defaults to true.\n */\n showCustomTimeRange?: boolean;\n /** Optional explicit timezone and change handler to enable changing tz from the selector */\n timeZone?: string;\n timeZoneOptions?: TimeZoneOption[];\n onTimeZoneChange?: (timeZone: TimeZoneOption) => void;\n}\n\n/**\n * Date & time selection component to customize what data renders on dashboard.\n * This includes relative shortcuts and the ability to pick absolute start and end times.\n * @param props\n * @constructor\n */\nexport function TimeRangeSelector({\n value,\n timeOptions,\n onChange,\n height,\n showCustomTimeRange = true,\n timeZone: timeZoneProp,\n timeZoneOptions,\n onTimeZoneChange,\n}: TimeRangeSelectorProps): ReactElement {\n const { timeZone: ctxTimeZone } = useTimeZone();\n const timeZone = timeZoneProp ?? ctxTimeZone;\n\n const anchorEl = useRef();\n const [showCustomDateSelector, setShowCustomDateSelector] = useState(false);\n\n const convertedTimeRange = useMemo(() => {\n return isRelativeTimeRange(value) ? toAbsoluteTimeRange(value) : value;\n }, [value]);\n\n const lastOption = useMemo(\n () => buildCustomTimeOption(isRelativeTimeRange(value) ? undefined : value, timeZone),\n [value, timeZone],\n );\n\n const [open, setOpen] = useState(false);\n const tzOptions = timeZoneOptions ?? getTimeZoneOptions();\n const [tzAnchorEl, setTzAnchorEl] = useState<HTMLElement | null>(null);\n const tzOpen = Boolean(tzAnchorEl);\n const tzLabel = tzOptions.find((o) => o.value === timeZone)?.display ?? timeZone;\n const tzOffset = getGMTOffset(timeZone);\n const localOffset = getGMTOffset('local');\n const tzAutocompleteOptions = tzOptions.map((o) => ({ id: o.value, label: o.display }));\n const tzAutocompleteValue = tzAutocompleteOptions.find((option) => option.id === timeZone);\n\n return (\n <>\n <Popover\n anchorEl={tzAnchorEl}\n anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}\n transformOrigin={{ vertical: 'top', horizontal: 'right' }}\n open={tzOpen}\n onClose={() => setTzAnchorEl(null)}\n sx={(theme) => ({ padding: theme.spacing(1) })}\n >\n <Box\n sx={{ p: 1, minWidth: 260 }}\n onClick={(e) => {\n e.stopPropagation();\n }}\n >\n <SettingsAutocomplete\n options={tzAutocompleteOptions}\n value={tzAutocompleteValue}\n onChange={(_e, option) => {\n if (option) {\n const selected = tzOptions.find((o) => o.value === option.id);\n if (selected) onTimeZoneChange?.(selected);\n }\n setTzAnchorEl(null);\n }}\n disableClearable\n renderInput={(params) => <TextField {...params} placeholder=\"Search timezones\" size=\"small\" />}\n />\n </Box>\n </Popover>\n <Popover\n anchorEl={anchorEl.current}\n anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}\n open={showCustomDateSelector}\n onClose={() => setShowCustomDateSelector(false)}\n sx={(theme) => ({ padding: theme.spacing(2) })}\n >\n <DateTimeRangePicker\n initialTimeRange={convertedTimeRange}\n onChange={(value: AbsoluteTimeRange) => {\n onChange(value);\n setShowCustomDateSelector(false);\n setOpen(false);\n }}\n onCancel={() => setShowCustomDateSelector(false)}\n timeZone={timeZone}\n />\n </Popover>\n <Box ref={anchorEl}>\n <Select\n open={open}\n value={formatTimeRange(value, timeZone)}\n onClick={() => setOpen(!open)}\n IconComponent={Calendar}\n renderValue={() => (\n <Stack direction=\"row\" alignItems=\"center\" spacing={1}>\n <span>\n {timeOptions.find((opt) => formatTimeRange(opt.value, timeZone) === formatTimeRange(value, timeZone))\n ?.display ?? formatTimeRange(value, timeZone)}\n </span>\n {tzOffset !== localOffset && (\n <Box sx={{ typography: 'caption', color: 'text.secondary' }}>· {tzOffset}</Box>\n )}\n </Stack>\n )}\n inputProps={{ 'aria-label': `Select time range. Currently set to ${value}` }}\n sx={{\n '.MuiSelect-icon': { marginTop: '1px', transform: 'none' },\n '.MuiSelect-select.MuiSelect-outlined.MuiInputBase-input': { paddingRight: '36px' },\n '.MuiSelect-select': height ? { lineHeight: height, paddingY: 0 } : {},\n }}\n >\n <MenuItem\n disableRipple\n onClick={(e: React.MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n sx={{ cursor: 'default', '&:hover': { backgroundColor: 'transparent' }, py: 0.5, px: 1 }}\n >\n <Box sx={{ display: 'flex', alignItems: 'center', width: '100%', justifyContent: 'space-between' }}>\n <Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>\n <Box sx={{ typography: 'subtitle1' }}>Time Range</Box>\n <Box sx={{ color: 'text.secondary', typography: 'caption', mt: 0.25 }}>Timezone: {tzLabel}</Box>\n </Box>\n <Box sx={{ display: 'flex', alignItems: 'center', pr: 1, ml: 1.5 }}>\n <IconButton\n size=\"small\"\n aria-label=\"Select timezone\"\n onClick={(e) => {\n e.preventDefault();\n e.stopPropagation();\n setTzAnchorEl(e.currentTarget);\n }}\n >\n <EarthIcon fontSize=\"small\" />\n </IconButton>\n </Box>\n </Box>\n </MenuItem>\n {timeOptions.map((item, idx) => (\n <MenuItem\n key={idx}\n value={formatTimeRange(item.value, timeZone)}\n onClick={() => {\n onChange(item.value);\n }}\n >\n {item.display}\n </MenuItem>\n ))}\n {showCustomTimeRange && (\n <MenuItem\n value={formatTimeRange(lastOption.value, timeZone)}\n onClick={() => setShowCustomDateSelector(true)}\n >\n {lastOption.display}\n </MenuItem>\n )}\n </Select>\n </Box>\n </>\n );\n}\n"],"names":["Box","MenuItem","Popover","Select","IconButton","TextField","Stack","isRelativeTimeRange","toAbsoluteTimeRange","Calendar","EarthIcon","useMemo","useRef","useState","useTimeZone","getTimeZoneOptions","SettingsAutocomplete","getGMTOffset","DateTimeRangePicker","buildCustomTimeOption","formatTimeRange","TimeRangeSelector","value","timeOptions","onChange","height","showCustomTimeRange","timeZone","timeZoneProp","timeZoneOptions","onTimeZoneChange","ctxTimeZone","anchorEl","showCustomDateSelector","setShowCustomDateSelector","convertedTimeRange","lastOption","undefined","open","setOpen","tzOptions","tzAnchorEl","setTzAnchorEl","tzOpen","Boolean","tzLabel","find","o","display","tzOffset","localOffset","tzAutocompleteOptions","map","id","label","tzAutocompleteValue","option","anchorOrigin","vertical","horizontal","transformOrigin","onClose","sx","theme","padding","spacing","p","minWidth","onClick","e","stopPropagation","options","_e","selected","disableClearable","renderInput","params","placeholder","size","current","initialTimeRange","onCancel","ref","IconComponent","renderValue","direction","alignItems","span","opt","typography","color","inputProps","marginTop","transform","paddingRight","lineHeight","paddingY","disableRipple","preventDefault","cursor","backgroundColor","py","px","width","justifyContent","flexDirection","mt","pr","ml","aria-label","currentTarget","fontSize","item","idx"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AA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8D,IAAI;oCAAEd,SAAS;oCAAQsC,YAAY;oCAAUiB,OAAO;oCAAQC,gBAAgB;gCAAgB;;kDAC/F,MAACxG;wCAAI8D,IAAI;4CAAEd,SAAS;4CAAQyD,eAAe;4CAAUnB,YAAY;wCAAa;;0DAC5E,KAACtF;gDAAI8D,IAAI;oDAAE2B,YAAY;gDAAY;0DAAG;;0DACtC,MAACzF;gDAAI8D,IAAI;oDAAE4B,OAAO;oDAAkBD,YAAY;oDAAWiB,IAAI;gDAAK;;oDAAG;oDAAW7D;;;;;kDAEpF,KAAC7C;wCAAI8D,IAAI;4CAAEd,SAAS;4CAAQsC,YAAY;4CAAUqB,IAAI;4CAAGC,IAAI;wCAAI;kDAC/D,cAAA,KAACxG;4CACC0E,MAAK;4CACL+B,cAAW;4CACXzC,SAAS,CAACC;gDACRA,EAAE6B,cAAc;gDAChB7B,EAAEC,eAAe;gDACjB5B,cAAc2B,EAAEyC,aAAa;4CAC/B;sDAEA,cAAA,KAACpG;gDAAUqG,UAAS;;;;;;;wBAK3BxF,YAAY6B,GAAG,CAAC,CAAC4D,MAAMC,oBACtB,KAAChH;gCAECqB,OAAOF,gBAAgB4F,KAAK1F,KAAK,EAAEK;gCACnCyC,SAAS;oCACP5C,SAASwF,KAAK1F,KAAK;gCACrB;0CAEC0F,KAAKhE,OAAO;+BANRiE;wBASRvF,qCACC,KAACzB;4BACCqB,OAAOF,gBAAgBgB,WAAWd,KAAK,EAAEK;4BACzCyC,SAAS,IAAMlC,0BAA0B;sCAExCE,WAAWY,OAAO;;;;;;;AAOjC"}
|
|
1
|
+
{"version":3,"sources":["../../src/TimeRangeSelector/TimeRangeSelector.tsx"],"sourcesContent":["// Copyright 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, MenuItem, Popover, Select, IconButton, TextField, Stack } from '@mui/material';\nimport type { TimeRangeValue, AbsoluteTimeRange } from '@perses-dev/spec';\nimport { isRelativeTimeRange, toAbsoluteTimeRange } from '@perses-dev/spec';\nimport Calendar from 'mdi-material-ui/Calendar';\nimport EarthIcon from 'mdi-material-ui/Earth';\nimport type { ReactElement } from 'react';\nimport { useMemo, useState } from 'react';\n\nimport { useTimeZone } from '../context';\nimport type { TimeOption } from '../model';\nimport type { TimeZoneOption } from '../model/timeZoneOption';\nimport { getTimeZoneOptions } from '../model/timeZoneOption';\nimport { SettingsAutocomplete } from '../SettingsAutocomplete';\nimport { getGMTOffset } from '../utils/format';\nimport { DateTimeRangePicker } from './DateTimeRangePicker';\nimport { buildCustomTimeOption, formatTimeRange } from './utils';\n\ninterface TimeRangeSelectorProps {\n /**\n * The current value of the time range.\n */\n value: TimeRangeValue;\n /**\n * The list of time options to display in the dropdown.\n * The component will automatically add the last two options as a zoom out x2 and a custom absolute time range.\n */\n timeOptions: TimeOption[];\n /**\n * The callback to call when the time range changes.\n */\n onChange: (value: TimeRangeValue) => void;\n /**\n * Custom line height for the select component.\n */\n height?: string;\n /**\n * Whether to show the custom time range option.\n * Defaults to true.\n */\n showCustomTimeRange?: boolean;\n /** Optional explicit timezone and change handler to enable changing tz from the selector */\n timeZone?: string;\n timeZoneOptions?: TimeZoneOption[];\n onTimeZoneChange?: (timeZone: TimeZoneOption) => void;\n}\n\n/**\n * Date & time selection component to customize what data renders on dashboard.\n * This includes relative shortcuts and the ability to pick absolute start and end times.\n * @param props\n * @constructor\n */\nexport function TimeRangeSelector({\n value,\n timeOptions,\n onChange,\n height,\n showCustomTimeRange = true,\n timeZone: timeZoneProp,\n timeZoneOptions,\n onTimeZoneChange,\n}: TimeRangeSelectorProps): ReactElement {\n const { timeZone: ctxTimeZone } = useTimeZone();\n const timeZone = timeZoneProp ?? ctxTimeZone;\n\n const [anchorEl, setAnchorEl] = useState<HTMLDivElement | null>(null);\n const [showCustomDateSelector, setShowCustomDateSelector] = useState(false);\n\n const convertedTimeRange = useMemo(() => {\n return isRelativeTimeRange(value) ? toAbsoluteTimeRange(value) : value;\n }, [value]);\n\n const lastOption = useMemo(\n () => buildCustomTimeOption(isRelativeTimeRange(value) ? undefined : value, timeZone),\n [value, timeZone],\n );\n\n const [open, setOpen] = useState(false);\n const tzOptions = timeZoneOptions ?? getTimeZoneOptions();\n const [tzAnchorEl, setTzAnchorEl] = useState<HTMLElement | null>(null);\n const tzOpen = Boolean(tzAnchorEl);\n const tzLabel = tzOptions.find((o) => o.value === timeZone)?.display ?? timeZone;\n const tzOffset = getGMTOffset(timeZone);\n const localOffset = getGMTOffset('local');\n const tzAutocompleteOptions = tzOptions.map((o) => ({ id: o.value, label: o.display }));\n const tzAutocompleteValue = tzAutocompleteOptions.find((option) => option.id === timeZone);\n\n return (\n <>\n <Popover\n anchorEl={tzAnchorEl}\n anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}\n transformOrigin={{ vertical: 'top', horizontal: 'right' }}\n open={tzOpen}\n onClose={() => setTzAnchorEl(null)}\n sx={(theme) => ({ padding: theme.spacing(1) })}\n >\n <Box\n sx={{ p: 1, minWidth: 260 }}\n onClick={(e) => {\n e.stopPropagation();\n }}\n >\n <SettingsAutocomplete\n options={tzAutocompleteOptions}\n value={tzAutocompleteValue}\n onChange={(_e, option) => {\n if (option) {\n const selected = tzOptions.find((o) => o.value === option.id);\n if (selected) onTimeZoneChange?.(selected);\n }\n setTzAnchorEl(null);\n }}\n disableClearable\n renderInput={(params) => <TextField {...params} placeholder=\"Search timezones\" size=\"small\" />}\n />\n </Box>\n </Popover>\n <Popover\n anchorEl={anchorEl}\n anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}\n open={showCustomDateSelector}\n onClose={() => setShowCustomDateSelector(false)}\n sx={(theme) => ({ padding: theme.spacing(2) })}\n >\n <DateTimeRangePicker\n initialTimeRange={convertedTimeRange}\n onChange={(value: AbsoluteTimeRange) => {\n onChange(value);\n setShowCustomDateSelector(false);\n setOpen(false);\n }}\n onCancel={() => setShowCustomDateSelector(false)}\n timeZone={timeZone}\n />\n </Popover>\n <Box ref={setAnchorEl}>\n <Select\n open={open}\n value={formatTimeRange(value, timeZone)}\n onClick={() => setOpen(!open)}\n IconComponent={Calendar}\n renderValue={() => (\n <Stack direction=\"row\" alignItems=\"center\" spacing={1}>\n <span>\n {timeOptions.find((opt) => formatTimeRange(opt.value, timeZone) === formatTimeRange(value, timeZone))\n ?.display ?? formatTimeRange(value, timeZone)}\n </span>\n {tzOffset !== localOffset && (\n <Box sx={{ typography: 'caption', color: 'text.secondary' }}>· {tzOffset}</Box>\n )}\n </Stack>\n )}\n inputProps={{ 'aria-label': `Select time range. Currently set to ${value}` }}\n sx={{\n '.MuiSelect-icon': { marginTop: '1px', transform: 'none' },\n '.MuiSelect-select.MuiSelect-outlined.MuiInputBase-input': { paddingRight: '36px' },\n '.MuiSelect-select': height ? { lineHeight: height, paddingY: 0 } : {},\n }}\n >\n <MenuItem\n disableRipple\n onClick={(e: React.MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n sx={{ cursor: 'default', '&:hover': { backgroundColor: 'transparent' }, py: 0.5, px: 1 }}\n >\n <Box sx={{ display: 'flex', alignItems: 'center', width: '100%', justifyContent: 'space-between' }}>\n <Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>\n <Box sx={{ typography: 'subtitle1' }}>Time Range</Box>\n <Box sx={{ color: 'text.secondary', typography: 'caption', mt: 0.25 }}>Timezone: {tzLabel}</Box>\n </Box>\n <Box sx={{ display: 'flex', alignItems: 'center', pr: 1, ml: 1.5 }}>\n <IconButton\n size=\"small\"\n aria-label=\"Select timezone\"\n onClick={(e) => {\n e.preventDefault();\n e.stopPropagation();\n setTzAnchorEl(e.currentTarget);\n }}\n >\n <EarthIcon fontSize=\"small\" />\n </IconButton>\n </Box>\n </Box>\n </MenuItem>\n {timeOptions.map((item, idx) => (\n <MenuItem\n key={idx}\n value={formatTimeRange(item.value, timeZone)}\n onClick={() => {\n onChange(item.value);\n }}\n >\n {item.display}\n </MenuItem>\n ))}\n {showCustomTimeRange && (\n <MenuItem\n value={formatTimeRange(lastOption.value, timeZone)}\n onClick={() => setShowCustomDateSelector(true)}\n >\n {lastOption.display}\n </MenuItem>\n )}\n </Select>\n </Box>\n </>\n );\n}\n"],"names":["Box","MenuItem","Popover","Select","IconButton","TextField","Stack","isRelativeTimeRange","toAbsoluteTimeRange","Calendar","EarthIcon","useMemo","useState","useTimeZone","getTimeZoneOptions","SettingsAutocomplete","getGMTOffset","DateTimeRangePicker","buildCustomTimeOption","formatTimeRange","TimeRangeSelector","value","timeOptions","onChange","height","showCustomTimeRange","timeZone","timeZoneProp","timeZoneOptions","onTimeZoneChange","ctxTimeZone","anchorEl","setAnchorEl","showCustomDateSelector","setShowCustomDateSelector","convertedTimeRange","lastOption","undefined","open","setOpen","tzOptions","tzAnchorEl","setTzAnchorEl","tzOpen","Boolean","tzLabel","find","o","display","tzOffset","localOffset","tzAutocompleteOptions","map","id","label","tzAutocompleteValue","option","anchorOrigin","vertical","horizontal","transformOrigin","onClose","sx","theme","padding","spacing","p","minWidth","onClick","e","stopPropagation","options","_e","selected","disableClearable","renderInput","params","placeholder","size","initialTimeRange","onCancel","ref","IconComponent","renderValue","direction","alignItems","span","opt","typography","color","inputProps","marginTop","transform","paddingRight","lineHeight","paddingY","disableRipple","preventDefault","cursor","backgroundColor","py","px","width","justifyContent","flexDirection","mt","pr","ml","aria-label","currentTarget","fontSize","item","idx"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AA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KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAI9C,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"TimeChartTooltip.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/TimeChartTooltip.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAI9C,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAGtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAMzD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,gBAAgB,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IACxD,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,aAAa,EAAE,sBAAsB,CAAC;IACtC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACpC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB;;OAEG;IACH,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,gBAAgB,qKAW1B,qBAAqB,oDA0FtB,CAAC"}
|
|
@@ -21,7 +21,7 @@ import { TooltipHeader } from "./TooltipHeader.js";
|
|
|
21
21
|
import { assembleTransform, getTooltipStyles } from "./utils.js";
|
|
22
22
|
export const TimeChartTooltip = /*#__PURE__*/ memo(function TimeChartTooltip({ containerId, chartRef, data, seriesMapping, enablePinning = true, wrapLabels, format, seriesFormatMap, onUnpinClick, pinnedPos }) {
|
|
23
23
|
const [showAllSeries, setShowAllSeries] = useState(false);
|
|
24
|
-
const
|
|
24
|
+
const [nearbySeries, setNearbySeries] = useState([]);
|
|
25
25
|
const tooltipElementRef = useRef(null);
|
|
26
26
|
const mousePos = useMousePosition();
|
|
27
27
|
const { height, width, ref: tooltipRef } = useResizeObserver();
|
|
@@ -34,6 +34,29 @@ export const TimeChartTooltip = /*#__PURE__*/ memo(function TimeChartTooltip({ c
|
|
|
34
34
|
tooltipRef
|
|
35
35
|
]);
|
|
36
36
|
const containerElement = containerId ? document.querySelector(containerId) : undefined;
|
|
37
|
+
// Chart reads and highlight actions synchronize with ECharts after commit.
|
|
38
|
+
useLayoutEffect(()=>{
|
|
39
|
+
const chart = chartRef.current;
|
|
40
|
+
setNearbySeries(getNearbySeriesData({
|
|
41
|
+
mousePos,
|
|
42
|
+
data,
|
|
43
|
+
seriesMapping,
|
|
44
|
+
pinnedPos,
|
|
45
|
+
chart,
|
|
46
|
+
format,
|
|
47
|
+
seriesFormatMap,
|
|
48
|
+
showAllSeries
|
|
49
|
+
}));
|
|
50
|
+
}, [
|
|
51
|
+
chartRef,
|
|
52
|
+
mousePos,
|
|
53
|
+
data,
|
|
54
|
+
seriesMapping,
|
|
55
|
+
pinnedPos,
|
|
56
|
+
format,
|
|
57
|
+
seriesFormatMap,
|
|
58
|
+
showAllSeries
|
|
59
|
+
]);
|
|
37
60
|
// Synchronously reposition after every render to prevent one-frame viewport overflow.
|
|
38
61
|
useLayoutEffect(()=>{
|
|
39
62
|
if (mousePos === null) return;
|
|
@@ -42,27 +65,15 @@ export const TimeChartTooltip = /*#__PURE__*/ memo(function TimeChartTooltip({ c
|
|
|
42
65
|
const rect = node.getBoundingClientRect();
|
|
43
66
|
if (rect.height === 0 || rect.width === 0) return;
|
|
44
67
|
const nextTransform = assembleTransform(mousePos, pinnedPos, rect.height, rect.width, containerElement);
|
|
45
|
-
if (nextTransform && nextTransform !== transform
|
|
46
|
-
transform.current = nextTransform;
|
|
68
|
+
if (nextTransform && nextTransform !== node.style.transform) {
|
|
47
69
|
node.style.transform = nextTransform;
|
|
48
70
|
}
|
|
49
71
|
});
|
|
50
72
|
if (mousePos === null || mousePos.target === null || data === null) return null;
|
|
51
73
|
if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS') return null;
|
|
52
|
-
const chart = chartRef.current;
|
|
53
74
|
// Cap height to container so the tooltip is not cut off.
|
|
54
75
|
const maxHeight = containerElement ? containerElement.getBoundingClientRect().height : undefined;
|
|
55
|
-
transform
|
|
56
|
-
const nearbySeries = getNearbySeriesData({
|
|
57
|
-
mousePos,
|
|
58
|
-
data,
|
|
59
|
-
seriesMapping,
|
|
60
|
-
pinnedPos,
|
|
61
|
-
chart,
|
|
62
|
-
format,
|
|
63
|
-
seriesFormatMap,
|
|
64
|
-
showAllSeries
|
|
65
|
-
});
|
|
76
|
+
const transform = assembleTransform(mousePos, pinnedPos, height ?? 0, width ?? 0, containerElement);
|
|
66
77
|
if (nearbySeries.length === 0) {
|
|
67
78
|
return null;
|
|
68
79
|
}
|
|
@@ -73,7 +84,7 @@ export const TimeChartTooltip = /*#__PURE__*/ memo(function TimeChartTooltip({ c
|
|
|
73
84
|
ref: setTooltipRef,
|
|
74
85
|
sx: (theme)=>getTooltipStyles(theme, pinnedPos, maxHeight),
|
|
75
86
|
style: {
|
|
76
|
-
transform
|
|
87
|
+
transform
|
|
77
88
|
},
|
|
78
89
|
children: /*#__PURE__*/ _jsxs(Stack, {
|
|
79
90
|
spacing: 0.5,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/TimeChartTooltip.tsx"],"sourcesContent":["// Copyright 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, Portal, Stack } from '@mui/material';\nimport type { TimeSeries } from '@perses-dev/spec';\nimport type { ECharts as EChartsInstance } from 'echarts/core';\nimport type { MutableRefObject } from 'react';\nimport { memo, useCallback, useLayoutEffect, useRef, useState } from 'react';\nimport useResizeObserver from 'use-resize-observer';\n\nimport type { FormatOptions, TimeChartSeriesMapping } from '../model';\nimport { getNearbySeriesData } from './nearby-series';\nimport type { CursorCoordinates } from './tooltip-model';\nimport { useMousePosition } from './tooltip-model';\nimport { TooltipContent } from './TooltipContent';\nimport { TooltipHeader } from './TooltipHeader';\nimport { assembleTransform, getTooltipStyles } from './utils';\n\nexport interface TimeChartTooltipProps {\n chartRef: MutableRefObject<EChartsInstance | undefined>;\n data: TimeSeries[];\n seriesMapping: TimeChartSeriesMapping;\n enablePinning?: boolean;\n pinnedPos: CursorCoordinates | null;\n /**\n * The id of the container that will have the chart tooltip appended to it.\n * By default, the chart tooltip is attached to document.body.\n */\n containerId?: string;\n onUnpinClick?: () => void;\n format?: FormatOptions;\n /**\n * Map of series ID to format options for per-series formatting (used with multiple Y axes)\n */\n seriesFormatMap?: Map<string, FormatOptions>;\n wrapLabels?: boolean;\n}\n\nexport const TimeChartTooltip = memo(function TimeChartTooltip({\n containerId,\n chartRef,\n data,\n seriesMapping,\n enablePinning = true,\n wrapLabels,\n format,\n seriesFormatMap,\n onUnpinClick,\n pinnedPos,\n}: TimeChartTooltipProps) {\n const [showAllSeries, setShowAllSeries] = useState(false);\n const
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/TimeChartTooltip.tsx"],"sourcesContent":["// Copyright 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, Portal, Stack } from '@mui/material';\nimport type { TimeSeries } from '@perses-dev/spec';\nimport type { ECharts as EChartsInstance } from 'echarts/core';\nimport type { MutableRefObject } from 'react';\nimport { memo, useCallback, useLayoutEffect, useRef, useState } from 'react';\nimport useResizeObserver from 'use-resize-observer';\n\nimport type { FormatOptions, TimeChartSeriesMapping } from '../model';\nimport type { NearbySeriesArray } from './nearby-series';\nimport { getNearbySeriesData } from './nearby-series';\nimport type { CursorCoordinates } from './tooltip-model';\nimport { useMousePosition } from './tooltip-model';\nimport { TooltipContent } from './TooltipContent';\nimport { TooltipHeader } from './TooltipHeader';\nimport { assembleTransform, getTooltipStyles } from './utils';\n\nexport interface TimeChartTooltipProps {\n chartRef: MutableRefObject<EChartsInstance | undefined>;\n data: TimeSeries[];\n seriesMapping: TimeChartSeriesMapping;\n enablePinning?: boolean;\n pinnedPos: CursorCoordinates | null;\n /**\n * The id of the container that will have the chart tooltip appended to it.\n * By default, the chart tooltip is attached to document.body.\n */\n containerId?: string;\n onUnpinClick?: () => void;\n format?: FormatOptions;\n /**\n * Map of series ID to format options for per-series formatting (used with multiple Y axes)\n */\n seriesFormatMap?: Map<string, FormatOptions>;\n wrapLabels?: boolean;\n}\n\nexport const TimeChartTooltip = memo(function TimeChartTooltip({\n containerId,\n chartRef,\n data,\n seriesMapping,\n enablePinning = true,\n wrapLabels,\n format,\n seriesFormatMap,\n onUnpinClick,\n pinnedPos,\n}: TimeChartTooltipProps) {\n const [showAllSeries, setShowAllSeries] = useState(false);\n const [nearbySeries, setNearbySeries] = useState<NearbySeriesArray>([]);\n const tooltipElementRef = useRef<HTMLDivElement | null>(null);\n\n const mousePos = useMousePosition();\n const { height, width, ref: tooltipRef } = useResizeObserver();\n\n const isTooltipPinned = pinnedPos !== null && enablePinning;\n\n // Stable callback — prevents the ResizeObserver from disconnecting/reconnecting on every render.\n const setTooltipRef = useCallback(\n (node: HTMLDivElement | null): void => {\n tooltipElementRef.current = node;\n tooltipRef(node);\n },\n [tooltipRef],\n );\n\n const containerElement = containerId ? document.querySelector(containerId) : undefined;\n\n // Chart reads and highlight actions synchronize with ECharts after commit.\n useLayoutEffect(() => {\n const chart = chartRef.current;\n setNearbySeries(\n getNearbySeriesData({\n mousePos,\n data,\n seriesMapping,\n pinnedPos,\n chart,\n format,\n seriesFormatMap,\n showAllSeries,\n }),\n );\n }, [chartRef, mousePos, data, seriesMapping, pinnedPos, format, seriesFormatMap, showAllSeries]);\n\n // Synchronously reposition after every render to prevent one-frame viewport overflow.\n useLayoutEffect(() => {\n if (mousePos === null) return;\n const node = tooltipElementRef.current;\n if (!node) return;\n const rect = node.getBoundingClientRect();\n if (rect.height === 0 || rect.width === 0) return;\n const nextTransform = assembleTransform(mousePos, pinnedPos, rect.height, rect.width, containerElement);\n if (nextTransform && nextTransform !== node.style.transform) {\n node.style.transform = nextTransform;\n }\n });\n\n if (mousePos === null || mousePos.target === null || data === null) return null;\n\n if (pinnedPos === null && (mousePos.target as HTMLElement).tagName !== 'CANVAS') return null;\n\n // Cap height to container so the tooltip is not cut off.\n const maxHeight = containerElement ? containerElement.getBoundingClientRect().height : undefined;\n\n const transform = assembleTransform(mousePos, pinnedPos, height ?? 0, width ?? 0, containerElement);\n\n if (nearbySeries.length === 0) {\n return null;\n }\n\n const totalSeries = data.length;\n\n return (\n <Portal container={containerElement}>\n <Box\n ref={setTooltipRef}\n sx={(theme) => getTooltipStyles(theme, pinnedPos, maxHeight)}\n style={{\n transform,\n }}\n >\n <Stack spacing={0.5}>\n <TooltipHeader\n nearbySeries={nearbySeries}\n totalSeries={totalSeries}\n enablePinning={enablePinning}\n isTooltipPinned={isTooltipPinned}\n showAllSeries={showAllSeries}\n onShowAllClick={(checked) => setShowAllSeries(checked)}\n onUnpinClick={onUnpinClick}\n />\n <TooltipContent series={nearbySeries} wrapLabels={wrapLabels} />\n </Stack>\n </Box>\n </Portal>\n );\n});\n"],"names":["Box","Portal","Stack","memo","useCallback","useLayoutEffect","useRef","useState","useResizeObserver","getNearbySeriesData","useMousePosition","TooltipContent","TooltipHeader","assembleTransform","getTooltipStyles","TimeChartTooltip","containerId","chartRef","data","seriesMapping","enablePinning","wrapLabels","format","seriesFormatMap","onUnpinClick","pinnedPos","showAllSeries","setShowAllSeries","nearbySeries","setNearbySeries","tooltipElementRef","mousePos","height","width","ref","tooltipRef","isTooltipPinned","setTooltipRef","node","current","containerElement","document","querySelector","undefined","chart","rect","getBoundingClientRect","nextTransform","style","transform","target","tagName","maxHeight","length","totalSeries","container","sx","theme","spacing","onShowAllClick","checked","series"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,GAAG,EAAEC,MAAM,EAAEC,KAAK,QAAQ,gBAAgB;AAInD,SAASC,IAAI,EAAEC,WAAW,EAAEC,eAAe,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAC7E,OAAOC,uBAAuB,sBAAsB;AAIpD,SAASC,mBAAmB,QAAQ,qBAAkB;AAEtD,SAASC,gBAAgB,QAAQ,qBAAkB;AACnD,SAASC,cAAc,QAAQ,sBAAmB;AAClD,SAASC,aAAa,QAAQ,qBAAkB;AAChD,SAASC,iBAAiB,EAAEC,gBAAgB,QAAQ,aAAU;AAsB9D,OAAO,MAAMC,iCAAmBZ,KAAK,SAASY,iBAAiB,EAC7DC,WAAW,EACXC,QAAQ,EACRC,IAAI,EACJC,aAAa,EACbC,gBAAgB,IAAI,EACpBC,UAAU,EACVC,MAAM,EACNC,eAAe,E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EAAE,KAAK,EAAE,eAAe,GAAG,MAAM,CAiCnH;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,GACf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAQjC;AAED,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,eAAe,GACrB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAexC"}
|
|
@@ -58,6 +58,11 @@ import { TOOLTIP_MAX_WIDTH, TOOLTIP_MAX_HEIGHT, TOOLTIP_MIN_WIDTH, TOOLTIP_BG_CO
|
|
|
58
58
|
}
|
|
59
59
|
return `translate3d(${x}px, ${y}px, 0)`;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Stacking level of a pinned tooltip. It must cover the table legend's sticky header, which
|
|
63
|
+
* react-virtuoso renders at z-index 2, and stay below PanelHeader (5, in @perses-dev/dashboards),
|
|
64
|
+
* the drawer and the sticky dashboard header.
|
|
65
|
+
*/ const PINNED_TOOLTIP_Z_INDEX = 3;
|
|
61
66
|
/**
|
|
62
67
|
* Helper for tooltip positioning styles
|
|
63
68
|
*/ export function getTooltipStyles(theme, pinnedPos, maxHeight) {
|
|
@@ -78,8 +83,7 @@ import { TOOLTIP_MAX_WIDTH, TOOLTIP_MAX_HEIGHT, TOOLTIP_MIN_WIDTH, TOOLTIP_BG_CO
|
|
|
78
83
|
opacity: 1,
|
|
79
84
|
// Animating transform causes intermediate positions outside the viewport; animate opacity/visibility instead.
|
|
80
85
|
transition: 'opacity 0.1s ease-out, visibility 0.1s ease-out',
|
|
81
|
-
|
|
82
|
-
zIndex: pinnedPos !== null ? 'auto' : theme.zIndex.tooltip,
|
|
86
|
+
zIndex: pinnedPos !== null ? PINNED_TOOLTIP_Z_INDEX : theme.zIndex.tooltip,
|
|
83
87
|
overflow: 'hidden',
|
|
84
88
|
'&:hover': {
|
|
85
89
|
overflowY: 'auto'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/utils.ts"],"sourcesContent":["// Copyright 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 type { Theme } from '@mui/material';\nimport type { BarSeriesOption, LineSeriesOption } from 'echarts/charts';\nimport type { ECharts as EChartsInstance } from 'echarts/core';\n\nimport type { TimeChartSeriesMapping } from '../model';\nimport type { CursorCoordinates, CursorData } from './tooltip-model';\nimport {\n TOOLTIP_MAX_WIDTH,\n TOOLTIP_MAX_HEIGHT,\n TOOLTIP_MIN_WIDTH,\n TOOLTIP_BG_COLOR_FALLBACK,\n TOOLTIP_PADDING,\n} 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 pinnedPos: CursorCoordinates | null,\n tooltipHeight: number,\n tooltipWidth: number,\n containerElement?: Element | null,\n): string | undefined {\n if (mousePos === null) {\n return undefined;\n }\n\n const cursorPaddingX = 32;\n const cursorPaddingY = 16;\n\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n }\n\n if (mousePos.plotCanvas.x === undefined) return undefined;\n\n // Fall back to max size before the resize observer reports a real measurement.\n const effectiveHeight = tooltipHeight > 0 ? tooltipHeight : TOOLTIP_MAX_HEIGHT;\n const effectiveWidth = tooltipWidth > 0 ? tooltipWidth : TOOLTIP_MAX_WIDTH;\n\n let x = mousePos.page.x + cursorPaddingX; // Default to right side of the cursor\n let y = mousePos.page.y + cursorPaddingY;\n\n // If containerElement is defined, adjust coordinates relative to the container\n if (containerElement) {\n const containerRect = containerElement.getBoundingClientRect();\n x = x - containerRect.left + containerElement.scrollLeft;\n y = y - containerRect.top + containerElement.scrollTop;\n\n // Ensure tooltip does not go out of the container's bottom\n const containerBottom = containerRect.top + containerElement.scrollHeight;\n if (y + effectiveHeight > containerBottom) {\n y = Math.max(containerBottom - effectiveHeight - cursorPaddingY, TOOLTIP_PADDING / 2);\n }\n } else {\n // Ensure tooltip does not go out of the screen on the bottom\n if (y + effectiveHeight > window.innerHeight + window.scrollY) {\n y = Math.max(window.innerHeight + window.scrollY - effectiveHeight - cursorPaddingY, TOOLTIP_PADDING / 2);\n }\n }\n\n // Ensure tooltip does not go out of the screen on the right\n if (x + effectiveWidth > window.innerWidth) {\n x = mousePos.page.x - effectiveWidth - cursorPaddingX; // Move to the left of the cursor\n }\n\n // Ensure tooltip does not go out of the screen on the left\n if (x < cursorPaddingX) {\n x = cursorPaddingX;\n }\n\n // Ensure tooltip does not go out of the screen on the top\n if (y < TOOLTIP_PADDING / 2) {\n y = TOOLTIP_PADDING / 2;\n }\n\n return `translate3d(${x}px, ${y}px, 0)`;\n}\n\n/**\n * Helper for tooltip positioning styles\n */\nexport function getTooltipStyles(\n theme: Theme,\n pinnedPos: CursorCoordinates | null,\n maxHeight?: number,\n): Record<string, unknown> {\n const adjustedMaxHeight = maxHeight ? maxHeight - TOOLTIP_PADDING : undefined;\n return {\n minWidth: TOOLTIP_MIN_WIDTH,\n maxWidth: TOOLTIP_MAX_WIDTH,\n maxHeight: adjustedMaxHeight ?? TOOLTIP_MAX_HEIGHT,\n padding: 0,\n position: 'absolute',\n top: 0,\n left: 0,\n backgroundColor: theme.palette.designSystem?.grey[800] ?? TOOLTIP_BG_COLOR_FALLBACK,\n borderRadius: '6px',\n color: '#fff',\n fontSize: '11px',\n visibility: 'visible',\n opacity: 1,\n // Animating transform causes intermediate positions outside the viewport; animate opacity/visibility instead.\n transition: 'opacity 0.1s ease-out, visibility 0.1s ease-out',\n // Pinned tooltip should not float above the drawer/sticky header.\n zIndex: pinnedPos !== null ? 'auto' : theme.zIndex.tooltip,\n overflow: 'hidden',\n '&:hover': {\n overflowY: 'auto',\n },\n };\n}\n\nexport function getPixelXFromGrid(timestamp: number, chart: EChartsInstance): number | null {\n try {\n const pixelCoords = chart.convertToPixel('grid', [timestamp, 0]);\n return pixelCoords?.[0] ?? null;\n } catch {\n return null;\n }\n}\n\n/**\n * Returns the cumulative (visual) Y for a series, accumulating stack totals in-place.\n * For non-stacked series, returns the raw yValue unchanged.\n * Mutates `stackTotals` — pass a fresh Map for each cursor evaluation.\n */\nexport function calculateVisualYForSeries(\n seriesIdx: number,\n yValue: number,\n seriesMapping: TimeChartSeriesMapping,\n stackTotals: Map<string, number>,\n): number {\n const currentSeries = seriesMapping[seriesIdx];\n if (!currentSeries) return yValue;\n\n const stackId = (currentSeries as LineSeriesOption | BarSeriesOption).stack;\n if (!stackId) {\n return yValue;\n }\n\n const stackIdStr = stackId.toString();\n const currentTotal = stackTotals.get(stackIdStr) ?? 0;\n const newTotal = currentTotal + yValue;\n stackTotals.set(stackIdStr, newTotal);\n return newTotal;\n}\n\nexport function calculateBarBandwidth(timestamp: number, sortedTimestamps: number[], chart: EChartsInstance): number {\n const currentIdx = sortedTimestamps.indexOf(timestamp);\n if (currentIdx === -1) {\n return 20;\n }\n\n const prevTimestamp = currentIdx > 0 ? (sortedTimestamps[currentIdx - 1] ?? null) : null;\n const nextTimestamp = currentIdx < sortedTimestamps.length - 1 ? (sortedTimestamps[currentIdx + 1] ?? null) : null;\n\n const currentPixelX = getPixelXFromGrid(timestamp, chart);\n if (currentPixelX === null) return 20;\n\n let leftBound: number;\n let rightBound: number;\n\n if (prevTimestamp !== null && nextTimestamp !== null) {\n const prevPixelX = getPixelXFromGrid(prevTimestamp, chart) ?? currentPixelX;\n const nextPixelX = getPixelXFromGrid(nextTimestamp, chart) ?? currentPixelX;\n leftBound = (currentPixelX + prevPixelX) / 2;\n rightBound = (currentPixelX + nextPixelX) / 2;\n } else if (prevTimestamp !== null) {\n const prevPixelX = getPixelXFromGrid(prevTimestamp, chart) ?? currentPixelX;\n leftBound = (currentPixelX + prevPixelX) / 2;\n rightBound = currentPixelX + (currentPixelX - leftBound);\n } else if (nextTimestamp !== null) {\n const nextPixelX = getPixelXFromGrid(nextTimestamp, chart) ?? currentPixelX;\n rightBound = (currentPixelX + nextPixelX) / 2;\n leftBound = currentPixelX - (rightBound - currentPixelX);\n } else {\n return 20;\n }\n\n return Math.max(1, rightBound - leftBound);\n}\n\n/**\n * Computes the pixel left/right bounds of one bar segment within a group.\n * @param barRelativeIdx - zero-based index among bar-only series\n * @param bandwidth - total pixel width for the bar group\n * @param centerPixelX - pixel X of the bar group centre\n * @param barCount - total bar series count (lines excluded)\n */\nexport function calculateBarSegmentBounds(\n barRelativeIdx: number,\n bandwidth: number,\n centerPixelX: number,\n barCount: number,\n): { left: number; right: number } {\n const count = Math.max(1, barCount);\n const segmentWidth = bandwidth / count;\n const segmentLeft = centerPixelX - bandwidth / 2 + barRelativeIdx * segmentWidth;\n return {\n left: segmentLeft,\n right: segmentLeft + segmentWidth,\n };\n}\n\nexport function calculateBarYBounds(\n visualYBottom: number,\n visualYTop: number,\n chart: EChartsInstance,\n): { top: number; bottom: number } | null {\n try {\n const bottomPixel = chart.convertToPixel('grid', [0, visualYBottom]);\n const topPixel = chart.convertToPixel('grid', [0, visualYTop]);\n\n if (!bottomPixel || !topPixel || bottomPixel[1] === undefined || topPixel[1] === undefined) return null;\n\n // Y increases downward in pixels; min/max normalizes the mapping for negative bar values.\n return {\n top: Math.min(topPixel[1], bottomPixel[1]),\n bottom: Math.max(topPixel[1], bottomPixel[1]),\n };\n } catch {\n return null;\n }\n}\n"],"names":["TOOLTIP_MAX_WIDTH","TOOLTIP_MAX_HEIGHT","TOOLTIP_MIN_WIDTH","TOOLTIP_BG_COLOR_FALLBACK","TOOLTIP_PADDING","assembleTransform","mousePos","pinnedPos","tooltipHeight","tooltipWidth","containerElement","undefined","cursorPaddingX","cursorPaddingY","plotCanvas","x","effectiveHeight","effectiveWidth","page","y","containerRect","getBoundingClientRect","left","scrollLeft","top","scrollTop","containerBottom","scrollHeight","Math","max","window","innerHeight","scrollY","innerWidth","getTooltipStyles","theme","maxHeight","adjustedMaxHeight","minWidth","maxWidth","padding","position","backgroundColor","palette","designSystem","grey","borderRadius","color","fontSize","visibility","opacity","transition","zIndex","tooltip","overflow","overflowY","getPixelXFromGrid","timestamp","chart","pixelCoords","convertToPixel","calculateVisualYForSeries","seriesIdx","yValue","seriesMapping","stackTotals","currentSeries","stackId","stack","stackIdStr","toString","currentTotal","get","newTotal","set","calculateBarBandwidth","sortedTimestamps","currentIdx","indexOf","prevTimestamp","nextTimestamp","length","currentPixelX","leftBound","rightBound","prevPixelX","nextPixelX","calculateBarSegmentBounds","barRelativeIdx","bandwidth","centerPixelX","barCount","count","segmentWidth","segmentLeft","right","calculateBarYBounds","visualYBottom","visualYTop","bottomPixel","topPixel","min","bottom"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAQjC,SACEA,iBAAiB,EACjBC,kBAAkB,EAClBC,iBAAiB,EACjBC,yBAAyB,EACzBC,eAAe,QACV,qBAAkB;AAEzB;;CAEC,GACD,OAAO,SAASC,kBACdC,QAA8B,EAC9BC,SAAmC,EACnCC,aAAqB,EACrBC,YAAoB,EACpBC,gBAAiC;IAEjC,IAAIJ,aAAa,MAAM;QACrB,OAAOK;IACT;IAEA,MAAMC,iBAAiB;IACvB,MAAMC,iBAAiB;IAEvB,IAAIN,cAAc,MAAM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;IAC1B,MAAME,eAAeJ,YAAYG;IACjC,MAAME,cAAcJ,eAAeD,YAAY,IAAID,iBAAiBK;IACpE,OAAO;QACLvE,MAAMwE;QACNC,OAAOD,cAAcD;IACvB;AACF;AAEA,OAAO,SAASG,oBACdC,aAAqB,EACrBC,UAAkB,EAClBxC,KAAsB;IAEtB,IAAI;QACF,MAAMyC,cAAczC,MAAME,cAAc,CAAC,QAAQ;YAAC;YAAGqC;SAAc;QACnE,MAAMG,WAAW1C,MAAME,cAAc,CAAC,QAAQ;YAAC;YAAGsC;SAAW;QAE7D,IAAI,CAACC,eAAe,CAACC,YAAYD,WAAW,CAAC,EAAE,KAAKxF,aAAayF,QAAQ,CAAC,EAAE,KAAKzF,WAAW,OAAO;QAEnG,0FAA0F;QAC1F,OAAO;YACLa,KAAKI,KAAKyE,GAAG,CAACD,QAAQ,CAAC,EAAE,EAAED,WAAW,CAAC,EAAE;YACzCG,QAAQ1E,KAAKC,GAAG,CAACuE,QAAQ,CAAC,EAAE,EAAED,WAAW,CAAC,EAAE;QAC9C;IACF,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/utils.ts"],"sourcesContent":["// Copyright 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 type { Theme } from '@mui/material';\nimport type { BarSeriesOption, LineSeriesOption } from 'echarts/charts';\nimport type { ECharts as EChartsInstance } from 'echarts/core';\n\nimport type { TimeChartSeriesMapping } from '../model';\nimport type { CursorCoordinates, CursorData } from './tooltip-model';\nimport {\n TOOLTIP_MAX_WIDTH,\n TOOLTIP_MAX_HEIGHT,\n TOOLTIP_MIN_WIDTH,\n TOOLTIP_BG_COLOR_FALLBACK,\n TOOLTIP_PADDING,\n} 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 pinnedPos: CursorCoordinates | null,\n tooltipHeight: number,\n tooltipWidth: number,\n containerElement?: Element | null,\n): string | undefined {\n if (mousePos === null) {\n return undefined;\n }\n\n const cursorPaddingX = 32;\n const cursorPaddingY = 16;\n\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n }\n\n if (mousePos.plotCanvas.x === undefined) return undefined;\n\n // Fall back to max size before the resize observer reports a real measurement.\n const effectiveHeight = tooltipHeight > 0 ? tooltipHeight : TOOLTIP_MAX_HEIGHT;\n const effectiveWidth = tooltipWidth > 0 ? tooltipWidth : TOOLTIP_MAX_WIDTH;\n\n let x = mousePos.page.x + cursorPaddingX; // Default to right side of the cursor\n let y = mousePos.page.y + cursorPaddingY;\n\n // If containerElement is defined, adjust coordinates relative to the container\n if (containerElement) {\n const containerRect = containerElement.getBoundingClientRect();\n x = x - containerRect.left + containerElement.scrollLeft;\n y = y - containerRect.top + containerElement.scrollTop;\n\n // Ensure tooltip does not go out of the container's bottom\n const containerBottom = containerRect.top + containerElement.scrollHeight;\n if (y + effectiveHeight > containerBottom) {\n y = Math.max(containerBottom - effectiveHeight - cursorPaddingY, TOOLTIP_PADDING / 2);\n }\n } else {\n // Ensure tooltip does not go out of the screen on the bottom\n if (y + effectiveHeight > window.innerHeight + window.scrollY) {\n y = Math.max(window.innerHeight + window.scrollY - effectiveHeight - cursorPaddingY, TOOLTIP_PADDING / 2);\n }\n }\n\n // Ensure tooltip does not go out of the screen on the right\n if (x + effectiveWidth > window.innerWidth) {\n x = mousePos.page.x - effectiveWidth - cursorPaddingX; // Move to the left of the cursor\n }\n\n // Ensure tooltip does not go out of the screen on the left\n if (x < cursorPaddingX) {\n x = cursorPaddingX;\n }\n\n // Ensure tooltip does not go out of the screen on the top\n if (y < TOOLTIP_PADDING / 2) {\n y = TOOLTIP_PADDING / 2;\n }\n\n return `translate3d(${x}px, ${y}px, 0)`;\n}\n\n/**\n * Stacking level of a pinned tooltip. It must cover the table legend's sticky header, which\n * react-virtuoso renders at z-index 2, and stay below PanelHeader (5, in @perses-dev/dashboards),\n * the drawer and the sticky dashboard header.\n */\nconst PINNED_TOOLTIP_Z_INDEX = 3;\n\n/**\n * Helper for tooltip positioning styles\n */\nexport function getTooltipStyles(\n theme: Theme,\n pinnedPos: CursorCoordinates | null,\n maxHeight?: number,\n): Record<string, unknown> {\n const adjustedMaxHeight = maxHeight ? maxHeight - TOOLTIP_PADDING : undefined;\n return {\n minWidth: TOOLTIP_MIN_WIDTH,\n maxWidth: TOOLTIP_MAX_WIDTH,\n maxHeight: adjustedMaxHeight ?? TOOLTIP_MAX_HEIGHT,\n padding: 0,\n position: 'absolute',\n top: 0,\n left: 0,\n backgroundColor: theme.palette.designSystem?.grey[800] ?? TOOLTIP_BG_COLOR_FALLBACK,\n borderRadius: '6px',\n color: '#fff',\n fontSize: '11px',\n visibility: 'visible',\n opacity: 1,\n // Animating transform causes intermediate positions outside the viewport; animate opacity/visibility instead.\n transition: 'opacity 0.1s ease-out, visibility 0.1s ease-out',\n zIndex: pinnedPos !== null ? PINNED_TOOLTIP_Z_INDEX : theme.zIndex.tooltip,\n overflow: 'hidden',\n '&:hover': {\n overflowY: 'auto',\n },\n };\n}\n\nexport function getPixelXFromGrid(timestamp: number, chart: EChartsInstance): number | null {\n try {\n const pixelCoords = chart.convertToPixel('grid', [timestamp, 0]);\n return pixelCoords?.[0] ?? null;\n } catch {\n return null;\n }\n}\n\n/**\n * Returns the cumulative (visual) Y for a series, accumulating stack totals in-place.\n * For non-stacked series, returns the raw yValue unchanged.\n * Mutates `stackTotals` — pass a fresh Map for each cursor evaluation.\n */\nexport function calculateVisualYForSeries(\n seriesIdx: number,\n yValue: number,\n seriesMapping: TimeChartSeriesMapping,\n stackTotals: Map<string, number>,\n): number {\n const currentSeries = seriesMapping[seriesIdx];\n if (!currentSeries) return yValue;\n\n const stackId = (currentSeries as LineSeriesOption | BarSeriesOption).stack;\n if (!stackId) {\n return yValue;\n }\n\n const stackIdStr = stackId.toString();\n const currentTotal = stackTotals.get(stackIdStr) ?? 0;\n const newTotal = currentTotal + yValue;\n stackTotals.set(stackIdStr, newTotal);\n return newTotal;\n}\n\nexport function calculateBarBandwidth(timestamp: number, sortedTimestamps: number[], chart: EChartsInstance): number {\n const currentIdx = sortedTimestamps.indexOf(timestamp);\n if (currentIdx === -1) {\n return 20;\n }\n\n const prevTimestamp = currentIdx > 0 ? (sortedTimestamps[currentIdx - 1] ?? null) : null;\n const nextTimestamp = currentIdx < sortedTimestamps.length - 1 ? (sortedTimestamps[currentIdx + 1] ?? null) : null;\n\n const currentPixelX = getPixelXFromGrid(timestamp, chart);\n if (currentPixelX === null) return 20;\n\n let leftBound: number;\n let rightBound: number;\n\n if (prevTimestamp !== null && nextTimestamp !== null) {\n const prevPixelX = getPixelXFromGrid(prevTimestamp, chart) ?? currentPixelX;\n const nextPixelX = getPixelXFromGrid(nextTimestamp, chart) ?? currentPixelX;\n leftBound = (currentPixelX + prevPixelX) / 2;\n rightBound = (currentPixelX + nextPixelX) / 2;\n } else if (prevTimestamp !== null) {\n const prevPixelX = getPixelXFromGrid(prevTimestamp, chart) ?? currentPixelX;\n leftBound = (currentPixelX + prevPixelX) / 2;\n rightBound = currentPixelX + (currentPixelX - leftBound);\n } else if (nextTimestamp !== null) {\n const nextPixelX = getPixelXFromGrid(nextTimestamp, chart) ?? currentPixelX;\n rightBound = (currentPixelX + nextPixelX) / 2;\n leftBound = currentPixelX - (rightBound - currentPixelX);\n } else {\n return 20;\n }\n\n return Math.max(1, rightBound - leftBound);\n}\n\n/**\n * Computes the pixel left/right bounds of one bar segment within a group.\n * @param barRelativeIdx - zero-based index among bar-only series\n * @param bandwidth - total pixel width for the bar group\n * @param centerPixelX - pixel X of the bar group centre\n * @param barCount - total bar series count (lines excluded)\n */\nexport function calculateBarSegmentBounds(\n barRelativeIdx: number,\n bandwidth: number,\n centerPixelX: number,\n barCount: number,\n): { left: number; right: number } {\n const count = Math.max(1, barCount);\n const segmentWidth = bandwidth / count;\n const segmentLeft = centerPixelX - bandwidth / 2 + barRelativeIdx * segmentWidth;\n return {\n left: segmentLeft,\n right: segmentLeft + segmentWidth,\n };\n}\n\nexport function calculateBarYBounds(\n visualYBottom: number,\n visualYTop: number,\n chart: EChartsInstance,\n): { top: number; bottom: number } | null {\n try {\n const bottomPixel = chart.convertToPixel('grid', [0, visualYBottom]);\n const topPixel = chart.convertToPixel('grid', [0, visualYTop]);\n\n if (!bottomPixel || !topPixel || bottomPixel[1] === undefined || topPixel[1] === undefined) return null;\n\n // Y increases downward in pixels; min/max normalizes the mapping for negative bar values.\n return {\n top: Math.min(topPixel[1], bottomPixel[1]),\n bottom: Math.max(topPixel[1], bottomPixel[1]),\n };\n } catch {\n return null;\n }\n}\n"],"names":["TOOLTIP_MAX_WIDTH","TOOLTIP_MAX_HEIGHT","TOOLTIP_MIN_WIDTH","TOOLTIP_BG_COLOR_FALLBACK","TOOLTIP_PADDING","assembleTransform","mousePos","pinnedPos","tooltipHeight","tooltipWidth","containerElement","undefined","cursorPaddingX","cursorPaddingY","plotCanvas","x","effectiveHeight","effectiveWidth","page","y","containerRect","getBoundingClientRect","left","scrollLeft","top","scrollTop","containerBottom","scrollHeight","Math","max","window","innerHeight","scrollY","innerWidth","PINNED_TOOLTIP_Z_INDEX","getTooltipStyles","theme","maxHeight","adjustedMaxHeight","minWidth","maxWidth","padding","position","backgroundColor","palette","designSystem","grey","borderRadius","color","fontSize","visibility","opacity","transition","zIndex","tooltip","overflow","overflowY","getPixelXFromGrid","timestamp","chart","pixelCoords","convertToPixel","calculateVisualYForSeries","seriesIdx","yValue","seriesMapping","stackTotals","currentSeries","stackId","stack","stackIdStr","toString","currentTotal","get","newTotal","set","calculateBarBandwidth","sortedTimestamps","currentIdx","indexOf","prevTimestamp","nextTimestamp","length","currentPixelX","leftBound","rightBound","prevPixelX","nextPixelX","calculateBarSegmentBounds","barRelativeIdx","bandwidth","centerPixelX","barCount","count","segmentWidth","segmentLeft","right","calculateBarYBounds","visualYBottom","visualYTop","bottomPixel","topPixel","min","bottom"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAQjC,SACEA,iBAAiB,EACjBC,kBAAkB,EAClBC,iBAAiB,EACjBC,yBAAyB,EACzBC,eAAe,QACV,qBAAkB;AAEzB;;CAEC,GACD,OAAO,SAASC,kBACdC,QAA8B,EAC9BC,SAAmC,EACnCC,aAAqB,EACrBC,YAAoB,EACpBC,gBAAiC;IAEjC,IAAIJ,aAAa,MAAM;QACrB,OAAOK;IACT;IAEA,MAAMC,iBAAiB;IACvB,MAAMC,iBAAiB;IAEvB,IAAIN,cAAc,MAAM;QACtBD,WAAWC;IACb;IAEA,IAAID,SAASQ,UAAU,CAACC,CAAC,KAAKJ,WAAW,OAAOA;IAEhD,+EAA+E;IAC/E,MAAMK,kBAAkBR,gBAAgB,IAAIA,gBAAgBP;IAC5D,MAAMgB,iBAAiBR,eAAe,IAAIA,eAAeT;IAEzD,IAAIe,IAAIT,SAASY,IAAI,CAACH,CAAC,GAAGH,gBAAgB,sCAAsC;IAChF,IAAIO,IAAIb,SAASY,IAAI,CAACC,CAAC,GAAGN;IAE1B,+EAA+E;IAC/E,IAAIH,kBAAkB;QACpB,MAAMU,gBAAgBV,iBAAiBW,qBAAqB;QAC5DN,IAAIA,IAAIK,cAAcE,IAAI,GAAGZ,iBAAiBa,UAAU;QACxDJ,IAAIA,IAAIC,cAAcI,GAAG,GAAGd,iBAAiBe,SAAS;QAEtD,2DAA2D;QAC3D,MAAMC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AG,CAACD,QAAQ,CAAC,EAAE,EAAED,WAAW,CAAC,EAAE;YACzCG,QAAQ3E,KAAKC,GAAG,CAACwE,QAAQ,CAAC,EAAE,EAAED,WAAW,CAAC,EAAE;QAC9C;IACF,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../src/controls/TextField.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../src/controls/TextField.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAOzE,KAAK,cAAc,GAAG,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAAC;AAExH,eAAO,MAAM,SAAS,wHAwBpB,CAAC"}
|
|
@@ -13,22 +13,27 @@
|
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { TextField as MuiTextField } from "@mui/material";
|
|
15
15
|
import debounce from "lodash/debounce";
|
|
16
|
-
import { forwardRef, useCallback,
|
|
16
|
+
import { forwardRef, useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
17
17
|
export const TextField = /*#__PURE__*/ forwardRef(function({ debounceMs = 250, value, onChange, ...props }, ref) {
|
|
18
18
|
const [currentValue, setCurrentValue] = useState(value);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
const handleDebounceFn = useCallback((inputValue)=>{
|
|
24
|
-
onChange?.(inputValue);
|
|
19
|
+
const onChangeRef = useRef(onChange);
|
|
20
|
+
useLayoutEffect(()=>{
|
|
21
|
+
onChangeRef.current = onChange;
|
|
25
22
|
}, [
|
|
26
23
|
onChange
|
|
27
24
|
]);
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
const debounceRef = useRef(null);
|
|
26
|
+
useLayoutEffect(()=>{
|
|
27
|
+
const debounceFn = debounce((inputValue)=>onChangeRef.current?.(inputValue), debounceMs);
|
|
28
|
+
debounceRef.current = debounceFn;
|
|
29
|
+
return ()=>debounceFn.cancel();
|
|
30
|
+
}, [
|
|
31
|
+
debounceMs
|
|
31
32
|
]);
|
|
33
|
+
const handleChange = useCallback((event)=>{
|
|
34
|
+
setCurrentValue(event.target.value);
|
|
35
|
+
debounceRef.current?.(event.target.value);
|
|
36
|
+
}, []);
|
|
32
37
|
return /*#__PURE__*/ _jsx(MuiTextField, {
|
|
33
38
|
ref: ref,
|
|
34
39
|
value: currentValue,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/controls/TextField.tsx"],"sourcesContent":["// Copyright 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 type { TextFieldProps as MuiTextFieldProps } from '@mui/material';\nimport { TextField as MuiTextField } from '@mui/material';\nimport debounce from 'lodash/debounce';\nimport type { ChangeEvent, ForwardedRef } from 'react';\nimport { forwardRef, useCallback,
|
|
1
|
+
{"version":3,"sources":["../../src/controls/TextField.tsx"],"sourcesContent":["// Copyright 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 type { TextFieldProps as MuiTextFieldProps } from '@mui/material';\nimport { TextField as MuiTextField } from '@mui/material';\nimport type { DebouncedFunc } from 'lodash';\nimport debounce from 'lodash/debounce';\nimport type { ChangeEvent, ForwardedRef } from 'react';\nimport { forwardRef, useCallback, useLayoutEffect, useRef, useState } from 'react';\n\ntype TextFieldProps = Omit<MuiTextFieldProps, 'onChange'> & { debounceMs?: number; onChange?: (value: string) => void };\n\nexport const TextField = forwardRef(function (\n { debounceMs = 250, value, onChange, ...props }: TextFieldProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const [currentValue, setCurrentValue] = useState(value);\n\n const onChangeRef = useRef(onChange);\n useLayoutEffect(() => {\n onChangeRef.current = onChange;\n }, [onChange]);\n\n const debounceRef = useRef<DebouncedFunc<(inputValue: string) => void> | null>(null);\n useLayoutEffect(() => {\n const debounceFn = debounce((inputValue: string) => onChangeRef.current?.(inputValue), debounceMs);\n debounceRef.current = debounceFn;\n return (): void => debounceFn.cancel();\n }, [debounceMs]);\n\n const handleChange = useCallback((event: ChangeEvent<HTMLInputElement>): void => {\n setCurrentValue(event.target.value);\n debounceRef.current?.(event.target.value);\n }, []);\n\n return <MuiTextField ref={ref} value={currentValue} onChange={handleChange} {...props} />;\n});\nTextField.displayName = 'TextField';\n"],"names":["TextField","MuiTextField","debounce","forwardRef","useCallback","useLayoutEffect","useRef","useState","debounceMs","value","onChange","props","ref","currentValue","setCurrentValue","onChangeRef","current","debounceRef","debounceFn","inputValue","cancel","handleChange","event","target","displayName"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,aAAaC,YAAY,QAAQ,gBAAgB;AAE1D,OAAOC,cAAc,kBAAkB;AAEvC,SAASC,UAAU,EAAEC,WAAW,EAAEC,eAAe,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAInF,OAAO,MAAMP,0BAAYG,WAAW,SAClC,EAAEK,aAAa,GAAG,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGC,OAAuB,EAC/DC,GAAiC;IAEjC,MAAM,CAACC,cAAcC,gBAAgB,GAAGP,SAASE;IAEjD,MAAMM,cAAcT,OAAOI;IAC3BL,gBAAgB;QACdU,YAAYC,OAAO,GAAGN;IACxB,GAAG;QAACA;KAAS;IAEb,MAAMO,cAAcX,OAA2D;IAC/ED,gBAAgB;QACd,MAAMa,aAAahB,SAAS,CAACiB,aAAuBJ,YAAYC,OAAO,GAAGG,aAAaX;QACvFS,YAAYD,OAAO,GAAGE;QACtB,OAAO,IAAYA,WAAWE,MAAM;IACtC,GAAG;QAACZ;KAAW;IAEf,MAAMa,eAAejB,YAAY,CAACkB;QAChCR,gBAAgBQ,MAAMC,MAAM,CAACd,KAAK;QAClCQ,YAAYD,OAAO,GAAGM,MAAMC,MAAM,CAACd,KAAK;IAC1C,GAAG,EAAE;IAEL,qBAAO,KAACR;QAAaW,KAAKA;QAAKH,OAAOI;QAAcH,UAAUW;QAAe,GAAGV,KAAK;;AACvF,GAAG;AACHX,UAAUwB,WAAW,GAAG"}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
var useIdValue: number;
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Generates a unique (stable) ID for a component. Should be replaced with React.useId once we support only React 18.
|
|
6
|
-
*/
|
|
1
|
+
/** Generates a unique, stable React ID with the given prefix. */
|
|
7
2
|
export declare function useId(prefix: string): string;
|
|
8
3
|
//# sourceMappingURL=component-ids.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-ids.d.ts","sourceRoot":"","sources":["../../src/utils/component-ids.ts"],"names":[],"mappings":"AAeA,
|
|
1
|
+
{"version":3,"file":"component-ids.d.ts","sourceRoot":"","sources":["../../src/utils/component-ids.ts"],"names":[],"mappings":"AAeA,iEAAiE;AACjE,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAI5C"}
|
|
@@ -10,18 +10,11 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import {
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
globalThis.useIdValue = 0;
|
|
19
|
-
}
|
|
20
|
-
const id = useRef(undefined);
|
|
21
|
-
if (id.current === undefined) {
|
|
22
|
-
id.current = `${prefix}-${globalThis.useIdValue++}`;
|
|
23
|
-
}
|
|
24
|
-
return id.current;
|
|
13
|
+
import { useId as useReactId, useState } from "react";
|
|
14
|
+
/** Generates a unique, stable React ID with the given prefix. */ export function useId(prefix) {
|
|
15
|
+
const id = useReactId();
|
|
16
|
+
const [initialPrefix] = useState(prefix);
|
|
17
|
+
return `${initialPrefix}-${id}`;
|
|
25
18
|
}
|
|
26
19
|
|
|
27
20
|
//# sourceMappingURL=component-ids.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/component-ids.ts"],"sourcesContent":["// Copyright 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 {
|
|
1
|
+
{"version":3,"sources":["../../src/utils/component-ids.ts"],"sourcesContent":["// Copyright 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 { useId as useReactId, useState } from 'react';\n\n/** Generates a unique, stable React ID with the given prefix. */\nexport function useId(prefix: string): string {\n const id = useReactId();\n const [initialPrefix] = useState(prefix);\n return `${initialPrefix}-${id}`;\n}\n"],"names":["useId","useReactId","useState","prefix","id","initialPrefix"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,SAASC,UAAU,EAAEC,QAAQ,QAAQ,QAAQ;AAEtD,+DAA+D,GAC/D,OAAO,SAASF,MAAMG,MAAc;IAClC,MAAMC,KAAKH;IACX,MAAM,CAACI,cAAc,GAAGH,SAASC;IACjC,OAAO,GAAGE,cAAc,CAAC,EAAED,IAAI;AACjC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export * from './combine-sx';
|
|
|
5
5
|
export * from './component-ids';
|
|
6
6
|
export * from './data-field-interpolation';
|
|
7
7
|
export * from './format';
|
|
8
|
-
export * from './memo';
|
|
9
8
|
export * from './request-interpolation';
|
|
10
9
|
export * from './selection-interpolation';
|
|
11
10
|
export * from './theme-gen';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,UAAU,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -17,7 +17,6 @@ export * from "./combine-sx.js";
|
|
|
17
17
|
export * from "./component-ids.js";
|
|
18
18
|
export * from "./data-field-interpolation.js";
|
|
19
19
|
export * from "./format.js";
|
|
20
|
-
export * from "./memo.js";
|
|
21
20
|
export * from "./request-interpolation.js";
|
|
22
21
|
export * from "./selection-interpolation.js";
|
|
23
22
|
export * from "./theme-gen.js";
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 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\nexport * from './axis';\nexport * from './browser-storage';\nexport * from './chart-actions';\nexport * from './combine-sx';\nexport * from './component-ids';\nexport * from './data-field-interpolation';\nexport * from './format';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 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\nexport * from './axis';\nexport * from './browser-storage';\nexport * from './chart-actions';\nexport * from './combine-sx';\nexport * from './component-ids';\nexport * from './data-field-interpolation';\nexport * from './format';\nexport * from './request-interpolation';\nexport * from './selection-interpolation';\nexport * from './theme-gen';\nexport * from './variable-interpolation';\nexport * from './value-mapping';\nexport * from './regexp';\nexport * from './transform-data';\nexport * from './time-series-data';\nexport * from './trace-data';\nexport * from './types';\nexport * from './text';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,YAAS;AACvB,cAAc,uBAAoB;AAClC,cAAc,qBAAkB;AAChC,cAAc,kBAAe;AAC7B,cAAc,qBAAkB;AAChC,cAAc,gCAA6B;AAC3C,cAAc,cAAW;AACzB,cAAc,6BAA0B;AACxC,cAAc,+BAA4B;AAC1C,cAAc,iBAAc;AAC5B,cAAc,8BAA2B;AACzC,cAAc,qBAAkB;AAChC,cAAc,cAAW;AACzB,cAAc,sBAAmB;AACjC,cAAc,wBAAqB;AACnC,cAAc,kBAAe;AAC7B,cAAc,aAAU;AACxB,cAAc,YAAS"}
|
package/dist/utils/text.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAenD,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,QAAQ,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,CAE9E;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,SAAS,QAAQ,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,CAGtF"}
|
package/dist/utils/text.js
CHANGED
|
@@ -10,30 +10,26 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
+
function getDisplayName(spec) {
|
|
14
|
+
if (typeof spec !== 'object' || spec === null || !('display' in spec)) return undefined;
|
|
15
|
+
const { display } = spec;
|
|
16
|
+
if (typeof display !== 'object' || display === null || !('name' in display)) return undefined;
|
|
17
|
+
return typeof display.name === 'string' && display.name ? display.name : undefined;
|
|
18
|
+
}
|
|
19
|
+
function getSpecDisplayName(spec) {
|
|
20
|
+
// Variables wrap their display settings in a nested spec.
|
|
21
|
+
const nestedSpec = typeof spec === 'object' && spec !== null && 'spec' in spec ? spec.spec : undefined;
|
|
22
|
+
return getDisplayName(nestedSpec) ?? getDisplayName(spec);
|
|
23
|
+
}
|
|
13
24
|
export function getResourceDisplayName(resource) {
|
|
14
|
-
|
|
15
|
-
if (resource.spec?.spec?.display?.name) {
|
|
16
|
-
return resource.spec.spec.display.name;
|
|
17
|
-
}
|
|
18
|
-
// Other resources with display
|
|
19
|
-
if (resource.spec?.display?.name) {
|
|
20
|
-
return resource.spec.display.name;
|
|
21
|
-
}
|
|
22
|
-
return resource.metadata.name;
|
|
25
|
+
return getSpecDisplayName(resource.spec) ?? resource.metadata.name;
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
25
28
|
* If the resource has a display name, return the resource display name with the resource name too
|
|
26
29
|
* Else, only return the resource name
|
|
27
30
|
*/ export function getResourceExtendedDisplayName(resource) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return `${resource.spec.spec.display.name} (ID: ${resource.metadata.name})`;
|
|
31
|
-
}
|
|
32
|
-
// Other resources with display
|
|
33
|
-
if (resource.spec?.display?.name) {
|
|
34
|
-
return `${resource.spec.display.name} (ID: ${resource.metadata.name})`;
|
|
35
|
-
}
|
|
36
|
-
return resource.metadata.name;
|
|
31
|
+
const displayName = getSpecDisplayName(resource.spec);
|
|
32
|
+
return displayName ? `${displayName} (ID: ${resource.metadata.name})` : resource.metadata.name;
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
//# sourceMappingURL=text.js.map
|
package/dist/utils/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/text.ts"],"sourcesContent":["// Copyright 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 type { Resource } from '@perses-dev/client';\n\
|
|
1
|
+
{"version":3,"sources":["../../src/utils/text.ts"],"sourcesContent":["// Copyright 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 type { Resource } from '@perses-dev/client';\n\nfunction getDisplayName(spec: unknown): string | undefined {\n if (typeof spec !== 'object' || spec === null || !('display' in spec)) return undefined;\n const { display } = spec;\n if (typeof display !== 'object' || display === null || !('name' in display)) return undefined;\n return typeof display.name === 'string' && display.name ? display.name : undefined;\n}\n\nfunction getSpecDisplayName(spec: unknown): string | undefined {\n // Variables wrap their display settings in a nested spec.\n const nestedSpec = typeof spec === 'object' && spec !== null && 'spec' in spec ? spec.spec : undefined;\n return getDisplayName(nestedSpec) ?? getDisplayName(spec);\n}\n\nexport function getResourceDisplayName<T extends Resource>(resource: T): string {\n return getSpecDisplayName(resource.spec) ?? resource.metadata.name;\n}\n\n/**\n * If the resource has a display name, return the resource display name with the resource name too\n * Else, only return the resource name\n */\nexport function getResourceExtendedDisplayName<T extends Resource>(resource: T): string {\n const displayName = getSpecDisplayName(resource.spec);\n return displayName ? `${displayName} (ID: ${resource.metadata.name})` : resource.metadata.name;\n}\n"],"names":["getDisplayName","spec","undefined","display","name","getSpecDisplayName","nestedSpec","getResourceDisplayName","resource","metadata","getResourceExtendedDisplayName","displayName"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,eAAeC,IAAa;IACnC,IAAI,OAAOA,SAAS,YAAYA,SAAS,QAAQ,CAAE,CAAA,aAAaA,IAAG,GAAI,OAAOC;IAC9E,MAAM,EAAEC,OAAO,EAAE,GAAGF;IACpB,IAAI,OAAOE,YAAY,YAAYA,YAAY,QAAQ,CAAE,CAAA,UAAUA,OAAM,GAAI,OAAOD;IACpF,OAAO,OAAOC,QAAQC,IAAI,KAAK,YAAYD,QAAQC,IAAI,GAAGD,QAAQC,IAAI,GAAGF;AAC3E;AAEA,SAASG,mBAAmBJ,IAAa;IACvC,0DAA0D;IAC1D,MAAMK,aAAa,OAAOL,SAAS,YAAYA,SAAS,QAAQ,UAAUA,OAAOA,KAAKA,IAAI,GAAGC;IAC7F,OAAOF,eAAeM,eAAeN,eAAeC;AACtD;AAEA,OAAO,SAASM,uBAA2CC,QAAW;IACpE,OAAOH,mBAAmBG,SAASP,IAAI,KAAKO,SAASC,QAAQ,CAACL,IAAI;AACpE;AAEA;;;CAGC,GACD,OAAO,SAASM,+BAAmDF,QAAW;IAC5E,MAAMG,cAAcN,mBAAmBG,SAASP,IAAI;IACpD,OAAOU,cAAc,GAAGA,YAAY,MAAM,EAAEH,SAASC,QAAQ,CAACL,IAAI,CAAC,CAAC,CAAC,GAAGI,SAASC,QAAQ,CAACL,IAAI;AAChG"}
|