@perses-dev/components 0.55.0-beta.9 → 0.55.0-rc.1
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/FormatControls/FormatControls.d.ts.map +1 -1
- package/dist/FormatControls/FormatControls.js +42 -4
- package/dist/FormatControls/FormatControls.js.map +1 -1
- package/dist/FormatControls/UnitSelector.js +4 -4
- package/dist/FormatControls/UnitSelector.js.map +1 -1
- package/dist/Legend/TableLegend.d.ts.map +1 -1
- package/dist/Legend/TableLegend.js +2 -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/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +2 -3
- package/dist/OptionsEditorLayout/OptionsEditorControl.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/TransformsEditor/TransformEditor.d.ts.map +1 -1
- package/dist/TransformsEditor/TransformEditor.js +89 -0
- package/dist/TransformsEditor/TransformEditor.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/model/custom.d.ts +22 -0
- package/dist/model/custom.d.ts.map +1 -0
- package/dist/model/custom.js +243 -0
- package/dist/model/custom.js.map +1 -0
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/transforms.d.ts +22 -1
- package/dist/model/transforms.d.ts.map +1 -1
- package/dist/model/transforms.js +2 -1
- package/dist/model/transforms.js.map +1 -1
- package/dist/model/units.d.ts +12 -10
- package/dist/model/units.d.ts.map +1 -1
- package/dist/model/units.js +33 -28
- package/dist/model/units.js.map +1 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -2
- 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/dist/utils/transform-data.d.ts +5 -0
- package/dist/utils/transform-data.d.ts.map +1 -1
- package/dist/utils/transform-data.js +96 -0
- package/dist/utils/transform-data.js.map +1 -1
- package/dist/utils/variable-interpolation.d.ts +11 -0
- package/dist/utils/variable-interpolation.d.ts.map +1 -1
- package/dist/utils/variable-interpolation.js +64 -0
- package/dist/utils/variable-interpolation.js.map +1 -1
- package/package.json +3 -3
- package/dist/utils/component-ids.d.ts +0 -8
- package/dist/utils/component-ids.d.ts.map +0 -1
- package/dist/utils/component-ids.js +0 -27
- package/dist/utils/component-ids.js.map +0 -1
- 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
|
@@ -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","segmentL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ACT;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,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,QAAQjE,KAAKC,GAAG,CAAC,GAAG+D;IAC1B,MAAME,eAAeJ,YAAYG;IACjC,MAAME,cAAcJ,eAAeD,YAAY,IAAID,iBAAiBK;IACpE,OAAO;QACLxE,MAAMyE;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,KAAKzF,aAAa0F,QAAQ,CAAC,EAAE,KAAK1F,WAAW,OAAO;QAEnG,0FAA0F;QAC1F,OAAO;YACLa,KAAKI,KAAK0E,GAAG,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":"TransformEditor.d.ts","sourceRoot":"","sources":["../../src/TransformsEditor/TransformEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAUhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAG1C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"TransformEditor.d.ts","sourceRoot":"","sources":["../../src/TransformsEditor/TransformEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAUhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAG1C,OAAO,KAAK,EAMV,SAAS,EACV,MAAM,UAAU,CAAC;AAiLlB,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;IAC/F,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;CAC1C;AAED,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,oBAAoB,GAAG,YAAY,CA+CjG"}
|
|
@@ -263,6 +263,20 @@ export function TransformEditor({ value, onChange, ...props }) {
|
|
|
263
263
|
})
|
|
264
264
|
]
|
|
265
265
|
})
|
|
266
|
+
}),
|
|
267
|
+
/*#__PURE__*/ _jsx(MenuItem, {
|
|
268
|
+
value: "PivotByLabel",
|
|
269
|
+
children: /*#__PURE__*/ _jsxs(Stack, {
|
|
270
|
+
children: [
|
|
271
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
272
|
+
children: "Pivot by label"
|
|
273
|
+
}),
|
|
274
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
275
|
+
variant: "caption",
|
|
276
|
+
children: "Time × label matrix (rows = time, columns = label values)"
|
|
277
|
+
})
|
|
278
|
+
]
|
|
279
|
+
})
|
|
266
280
|
})
|
|
267
281
|
]
|
|
268
282
|
}),
|
|
@@ -281,6 +295,81 @@ export function TransformEditor({ value, onChange, ...props }) {
|
|
|
281
295
|
value.kind === 'MergeSeries' && /*#__PURE__*/ _jsx(MergeSeriesTransformEditor, {
|
|
282
296
|
value: value,
|
|
283
297
|
onChange: onChange
|
|
298
|
+
}),
|
|
299
|
+
value.kind === 'PivotByLabel' && /*#__PURE__*/ _jsx(PivotByLabelTransformEditor, {
|
|
300
|
+
value: value,
|
|
301
|
+
onChange: onChange
|
|
302
|
+
})
|
|
303
|
+
]
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
function PivotByLabelTransformEditor({ value, onChange }) {
|
|
307
|
+
return /*#__PURE__*/ _jsxs(Stack, {
|
|
308
|
+
gap: 2,
|
|
309
|
+
children: [
|
|
310
|
+
/*#__PURE__*/ _jsx(MuiTextField, {
|
|
311
|
+
label: "Column label",
|
|
312
|
+
fullWidth: true,
|
|
313
|
+
value: value.spec.columnLabel ?? '',
|
|
314
|
+
onChange: (e)=>onChange({
|
|
315
|
+
...value,
|
|
316
|
+
spec: {
|
|
317
|
+
...value.spec,
|
|
318
|
+
columnLabel: e.target.value
|
|
319
|
+
}
|
|
320
|
+
}),
|
|
321
|
+
helperText: "Label that becomes dynamic column headers (e.g. farm_short)"
|
|
322
|
+
}),
|
|
323
|
+
/*#__PURE__*/ _jsx(MuiTextField, {
|
|
324
|
+
label: "Row field",
|
|
325
|
+
fullWidth: true,
|
|
326
|
+
value: value.spec.rowField ?? 'timestamp',
|
|
327
|
+
onChange: (e)=>onChange({
|
|
328
|
+
...value,
|
|
329
|
+
spec: {
|
|
330
|
+
...value.spec,
|
|
331
|
+
rowField: e.target.value
|
|
332
|
+
}
|
|
333
|
+
}),
|
|
334
|
+
helperText: "Field used for row identity (default: timestamp)"
|
|
335
|
+
}),
|
|
336
|
+
/*#__PURE__*/ _jsx(MuiTextField, {
|
|
337
|
+
label: "Value field",
|
|
338
|
+
fullWidth: true,
|
|
339
|
+
value: value.spec.valueField ?? 'value',
|
|
340
|
+
onChange: (e)=>onChange({
|
|
341
|
+
...value,
|
|
342
|
+
spec: {
|
|
343
|
+
...value.spec,
|
|
344
|
+
valueField: e.target.value
|
|
345
|
+
}
|
|
346
|
+
})
|
|
347
|
+
}),
|
|
348
|
+
/*#__PURE__*/ _jsx(MuiTextField, {
|
|
349
|
+
label: "Row column name",
|
|
350
|
+
fullWidth: true,
|
|
351
|
+
value: value.spec.rowColumnName ?? '',
|
|
352
|
+
onChange: (e)=>onChange({
|
|
353
|
+
...value,
|
|
354
|
+
spec: {
|
|
355
|
+
...value.spec,
|
|
356
|
+
rowColumnName: e.target.value || undefined
|
|
357
|
+
}
|
|
358
|
+
}),
|
|
359
|
+
helperText: "Optional display name for the row column (default: row field)"
|
|
360
|
+
}),
|
|
361
|
+
/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
362
|
+
control: /*#__PURE__*/ _jsx(Switch, {
|
|
363
|
+
checked: !!value.spec.disabled,
|
|
364
|
+
onChange: (_, checked)=>onChange({
|
|
365
|
+
...value,
|
|
366
|
+
spec: {
|
|
367
|
+
...value.spec,
|
|
368
|
+
disabled: checked
|
|
369
|
+
}
|
|
370
|
+
})
|
|
371
|
+
}),
|
|
372
|
+
label: "Disabled"
|
|
284
373
|
})
|
|
285
374
|
]
|
|
286
375
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TransformsEditor/TransformEditor.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 { StackProps } from '@mui/material';\nimport {\n Autocomplete,\n FormControlLabel,\n MenuItem,\n Stack,\n Switch,\n Typography,\n TextField as MuiTextField,\n} from '@mui/material';\nimport type { ReactElement } from 'react';\n\nimport { TextField } from '../controls';\nimport type {\n JoinByColumnValueTransform,\n MergeColumnsTransform,\n MergeIndexedColumnsTransform,\n MergeSeriesTransform,\n Transform,\n} from '../model';\n\ninterface TransformSpecEditorProps<Spec> {\n value: Spec;\n onChange: (transform: Spec) => void;\n}\n\nfunction JoinByColumnValueTransformEditor({\n value,\n onChange,\n}: TransformSpecEditorProps<JoinByColumnValueTransform>): ReactElement {\n return (\n <Stack direction=\"row\">\n <Autocomplete\n freeSolo\n multiple\n id=\"join-columns\"\n sx={{ width: '100%' }}\n options={[]} // TODO: autofill columns name when query results is available to panel editors\n value={value.spec.columns ?? []}\n renderInput={(params) => <MuiTextField {...params} variant=\"outlined\" label=\"Columns\" required />}\n onChange={(_, columns) => {\n onChange({\n ...value,\n spec: {\n ...value.spec,\n columns: columns,\n },\n });\n }}\n />\n <FormControlLabel\n label=\"Enabled\"\n labelPlacement=\"start\"\n control={\n <Switch\n value={!value.spec.disabled}\n checked={!value.spec.disabled}\n onChange={(e) =>\n onChange({\n ...value,\n spec: { ...value.spec, disabled: !e.target.checked },\n })\n }\n />\n }\n />\n </Stack>\n );\n}\n\nfunction MergeColumnsTransformEditor({\n value,\n onChange,\n}: TransformSpecEditorProps<MergeColumnsTransform>): ReactElement {\n return (\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n <Autocomplete\n freeSolo\n multiple\n id=\"merge-columns-columns\"\n sx={{ width: '100%' }}\n options={[]}\n value={value.spec.columns ?? []}\n renderInput={(params) => <MuiTextField {...params} variant=\"outlined\" label=\"Columns\" required />}\n onChange={(_, columns) => {\n onChange({\n ...value,\n spec: {\n ...value.spec,\n columns: columns,\n },\n });\n }}\n />\n\n <TextField\n id=\"merge-columns-name\"\n variant=\"outlined\"\n label=\"Output Name\"\n value={value.spec.name ?? ''}\n sx={{ width: '100%' }}\n onChange={(name) => {\n onChange({\n ...value,\n spec: {\n ...value.spec,\n name: name,\n },\n });\n }}\n required\n />\n <FormControlLabel\n label=\"Enabled\"\n labelPlacement=\"start\"\n control={\n <Switch\n value={!value.spec.disabled}\n checked={!value.spec.disabled}\n onChange={(e) =>\n onChange({\n ...value,\n spec: { ...value.spec, disabled: !e.target.checked },\n })\n }\n />\n }\n />\n </Stack>\n );\n}\n\nfunction MergeIndexedColumnsTransformEditor({\n value,\n onChange,\n}: TransformSpecEditorProps<MergeIndexedColumnsTransform>): ReactElement {\n return (\n <Stack direction=\"row\">\n <TextField\n id=\"merge-indexed-columns\"\n variant=\"outlined\"\n label=\"Column\"\n placeholder=\"Example: 'value' for merging 'value #1', 'value #2' and 'value #...'\"\n value={value.spec.column ?? ''}\n sx={{ width: '100%' }}\n onChange={(column) => {\n onChange({\n ...value,\n spec: { ...value.spec, column: column },\n });\n }}\n required\n />\n <FormControlLabel\n label=\"Enabled\"\n labelPlacement=\"start\"\n control={\n <Switch\n value={!value.spec.disabled}\n checked={!value.spec.disabled}\n onChange={(e) =>\n onChange({\n ...value,\n spec: { ...value.spec, disabled: !e.target.checked },\n })\n }\n />\n }\n />\n </Stack>\n );\n}\n\nfunction MergeSeriesTransformEditor({ value, onChange }: TransformSpecEditorProps<MergeSeriesTransform>): ReactElement {\n return (\n <Stack direction=\"row\">\n <FormControlLabel\n label=\"Enabled\"\n labelPlacement=\"start\"\n control={\n <Switch\n value={!value.spec.disabled}\n checked={!value.spec.disabled}\n onChange={(e) =>\n onChange({\n ...value,\n spec: { ...value.spec, disabled: !e.target.checked },\n })\n }\n />\n }\n />\n </Stack>\n );\n}\n\nexport interface TransformEditorProps extends Omit<StackProps, 'children' | 'value' | 'onChange'> {\n value: Transform;\n onChange: (transform: Transform) => void;\n}\n\nexport function TransformEditor({ value, onChange, ...props }: TransformEditorProps): ReactElement {\n return (\n <Stack gap={2} sx={{ width: '100%' }} mt={1} {...props}>\n <TextField\n select\n label=\"Kind\"\n value={value.kind}\n onChange={(kind) => onChange({ ...value, kind: kind as unknown as Transform['kind'] } as Transform)}\n >\n <MenuItem value=\"JoinByColumnValue\">\n <Stack>\n <Typography>Join by column value</Typography>\n <Typography variant=\"caption\">Regroup rows with equal cell value in a column</Typography>\n </Stack>\n </MenuItem>\n <MenuItem value=\"MergeColumns\">\n <Stack>\n <Typography>Merge columns</Typography>\n <Typography variant=\"caption\">Multiple columns are merged to one column</Typography>\n </Stack>\n </MenuItem>\n <MenuItem value=\"MergeIndexedColumns\">\n <Stack>\n <Typography>Merge indexed columns</Typography>\n <Typography variant=\"caption\">Indexed columns are merged to one column</Typography>\n </Stack>\n </MenuItem>\n <MenuItem value=\"MergeSeries\">\n <Stack>\n <Typography>Merge series</Typography>\n <Typography variant=\"caption\">Series will be merged by their labels</Typography>\n </Stack>\n </MenuItem>\n </TextField>\n {value.kind === 'JoinByColumnValue' && <JoinByColumnValueTransformEditor value={value} onChange={onChange} />}\n {value.kind === 'MergeColumns' && <MergeColumnsTransformEditor value={value} onChange={onChange} />}\n {value.kind === 'MergeIndexedColumns' && <MergeIndexedColumnsTransformEditor value={value} onChange={onChange} />}\n {value.kind === 'MergeSeries' && <MergeSeriesTransformEditor value={value} onChange={onChange} />}\n </Stack>\n );\n}\n"],"names":["Autocomplete","FormControlLabel","MenuItem","Stack","Switch","Typography","TextField","MuiTextField","JoinByColumnValueTransformEditor","value","onChange","direction","freeSolo","multiple","id","sx","width","options","spec","columns","renderInput","params","variant","label","required","_","labelPlacement","control","disabled","checked","e","target","MergeColumnsTransformEditor","gap","alignItems","name","MergeIndexedColumnsTransformEditor","placeholder","column","MergeSeriesTransformEditor","TransformEditor","props","mt","select","kind"],"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,SACEA,YAAY,EACZC,gBAAgB,EAChBC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,aAAaC,YAAY,QACpB,gBAAgB;AAGvB,SAASD,SAAS,QAAQ,uBAAc;AAcxC,SAASE,iCAAiC,EACxCC,KAAK,EACLC,QAAQ,EAC6C;IACrD,qBACE,MAACP;QAAMQ,WAAU;;0BACf,KAACX;gBACCY,QAAQ;gBACRC,QAAQ;gBACRC,IAAG;gBACHC,IAAI;oBAAEC,OAAO;gBAAO;gBACpBC,SAAS,EAAE;gBACXR,OAAOA,MAAMS,IAAI,CAACC,OAAO,IAAI,EAAE;gBAC/BC,aAAa,CAACC,uBAAW,KAACd;wBAAc,GAAGc,MAAM;w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OA;gBAAOC,UAAUA;;YACtFD,MAAMmC,IAAI,KAAK,uCAAyB,KAACR;gBAAmC3B,OAAOA;gBAAOC,UAAUA;;YACpGD,MAAMmC,IAAI,KAAK,+BAAiB,KAACL;gBAA2B9B,OAAOA;gBAAOC,UAAUA;;;;AAG3F"}
|
|
1
|
+
{"version":3,"sources":["../../src/TransformsEditor/TransformEditor.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 { StackProps } from '@mui/material';\nimport {\n Autocomplete,\n FormControlLabel,\n MenuItem,\n Stack,\n Switch,\n Typography,\n TextField as MuiTextField,\n} from '@mui/material';\nimport type { ReactElement } from 'react';\n\nimport { TextField } from '../controls';\nimport type {\n JoinByColumnValueTransform,\n MergeColumnsTransform,\n MergeIndexedColumnsTransform,\n MergeSeriesTransform,\n PivotByLabelTransform,\n Transform,\n} from '../model';\n\ninterface TransformSpecEditorProps<Spec> {\n value: Spec;\n onChange: (transform: Spec) => void;\n}\n\nfunction JoinByColumnValueTransformEditor({\n value,\n onChange,\n}: TransformSpecEditorProps<JoinByColumnValueTransform>): ReactElement {\n return (\n <Stack direction=\"row\">\n <Autocomplete\n freeSolo\n multiple\n id=\"join-columns\"\n sx={{ width: '100%' }}\n options={[]} // TODO: autofill columns name when query results is available to panel editors\n value={value.spec.columns ?? []}\n renderInput={(params) => <MuiTextField {...params} variant=\"outlined\" label=\"Columns\" required />}\n onChange={(_, columns) => {\n onChange({\n ...value,\n spec: {\n ...value.spec,\n columns: columns,\n },\n });\n }}\n />\n <FormControlLabel\n label=\"Enabled\"\n labelPlacement=\"start\"\n control={\n <Switch\n value={!value.spec.disabled}\n checked={!value.spec.disabled}\n onChange={(e) =>\n onChange({\n ...value,\n spec: { ...value.spec, disabled: !e.target.checked },\n })\n }\n />\n }\n />\n </Stack>\n );\n}\n\nfunction MergeColumnsTransformEditor({\n value,\n onChange,\n}: TransformSpecEditorProps<MergeColumnsTransform>): ReactElement {\n return (\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n <Autocomplete\n freeSolo\n multiple\n id=\"merge-columns-columns\"\n sx={{ width: '100%' }}\n options={[]}\n value={value.spec.columns ?? []}\n renderInput={(params) => <MuiTextField {...params} variant=\"outlined\" label=\"Columns\" required />}\n onChange={(_, columns) => {\n onChange({\n ...value,\n spec: {\n ...value.spec,\n columns: columns,\n },\n });\n }}\n />\n\n <TextField\n id=\"merge-columns-name\"\n variant=\"outlined\"\n label=\"Output Name\"\n value={value.spec.name ?? ''}\n sx={{ width: '100%' }}\n onChange={(name) => {\n onChange({\n ...value,\n spec: {\n ...value.spec,\n name: name,\n },\n });\n }}\n required\n />\n <FormControlLabel\n label=\"Enabled\"\n labelPlacement=\"start\"\n control={\n <Switch\n value={!value.spec.disabled}\n checked={!value.spec.disabled}\n onChange={(e) =>\n onChange({\n ...value,\n spec: { ...value.spec, disabled: !e.target.checked },\n })\n }\n />\n }\n />\n </Stack>\n );\n}\n\nfunction MergeIndexedColumnsTransformEditor({\n value,\n onChange,\n}: TransformSpecEditorProps<MergeIndexedColumnsTransform>): ReactElement {\n return (\n <Stack direction=\"row\">\n <TextField\n id=\"merge-indexed-columns\"\n variant=\"outlined\"\n label=\"Column\"\n placeholder=\"Example: 'value' for merging 'value #1', 'value #2' and 'value #...'\"\n value={value.spec.column ?? ''}\n sx={{ width: '100%' }}\n onChange={(column) => {\n onChange({\n ...value,\n spec: { ...value.spec, column: column },\n });\n }}\n required\n />\n <FormControlLabel\n label=\"Enabled\"\n labelPlacement=\"start\"\n control={\n <Switch\n value={!value.spec.disabled}\n checked={!value.spec.disabled}\n onChange={(e) =>\n onChange({\n ...value,\n spec: { ...value.spec, disabled: !e.target.checked },\n })\n }\n />\n }\n />\n </Stack>\n );\n}\n\nfunction MergeSeriesTransformEditor({ value, onChange }: TransformSpecEditorProps<MergeSeriesTransform>): ReactElement {\n return (\n <Stack direction=\"row\">\n <FormControlLabel\n label=\"Enabled\"\n labelPlacement=\"start\"\n control={\n <Switch\n value={!value.spec.disabled}\n checked={!value.spec.disabled}\n onChange={(e) =>\n onChange({\n ...value,\n spec: { ...value.spec, disabled: !e.target.checked },\n })\n }\n />\n }\n />\n </Stack>\n );\n}\n\nexport interface TransformEditorProps extends Omit<StackProps, 'children' | 'value' | 'onChange'> {\n value: Transform;\n onChange: (transform: Transform) => void;\n}\n\nexport function TransformEditor({ value, onChange, ...props }: TransformEditorProps): ReactElement {\n return (\n <Stack gap={2} sx={{ width: '100%' }} mt={1} {...props}>\n <TextField\n select\n label=\"Kind\"\n value={value.kind}\n onChange={(kind) => onChange({ ...value, kind: kind as unknown as Transform['kind'] } as Transform)}\n >\n <MenuItem value=\"JoinByColumnValue\">\n <Stack>\n <Typography>Join by column value</Typography>\n <Typography variant=\"caption\">Regroup rows with equal cell value in a column</Typography>\n </Stack>\n </MenuItem>\n <MenuItem value=\"MergeColumns\">\n <Stack>\n <Typography>Merge columns</Typography>\n <Typography variant=\"caption\">Multiple columns are merged to one column</Typography>\n </Stack>\n </MenuItem>\n <MenuItem value=\"MergeIndexedColumns\">\n <Stack>\n <Typography>Merge indexed columns</Typography>\n <Typography variant=\"caption\">Indexed columns are merged to one column</Typography>\n </Stack>\n </MenuItem>\n <MenuItem value=\"MergeSeries\">\n <Stack>\n <Typography>Merge series</Typography>\n <Typography variant=\"caption\">Series will be merged by their labels</Typography>\n </Stack>\n </MenuItem>\n <MenuItem value=\"PivotByLabel\">\n <Stack>\n <Typography>Pivot by label</Typography>\n <Typography variant=\"caption\">Time × label matrix (rows = time, columns = label values)</Typography>\n </Stack>\n </MenuItem>\n </TextField>\n {value.kind === 'JoinByColumnValue' && <JoinByColumnValueTransformEditor value={value} onChange={onChange} />}\n {value.kind === 'MergeColumns' && <MergeColumnsTransformEditor value={value} onChange={onChange} />}\n {value.kind === 'MergeIndexedColumns' && <MergeIndexedColumnsTransformEditor value={value} onChange={onChange} />}\n {value.kind === 'MergeSeries' && <MergeSeriesTransformEditor value={value} onChange={onChange} />}\n {value.kind === 'PivotByLabel' && <PivotByLabelTransformEditor value={value} onChange={onChange} />}\n </Stack>\n );\n}\n\nfunction PivotByLabelTransformEditor({\n value,\n onChange,\n}: TransformSpecEditorProps<PivotByLabelTransform>): ReactElement {\n return (\n <Stack gap={2}>\n <MuiTextField\n label=\"Column label\"\n fullWidth\n value={value.spec.columnLabel ?? ''}\n onChange={(e) => onChange({ ...value, spec: { ...value.spec, columnLabel: e.target.value } })}\n helperText=\"Label that becomes dynamic column headers (e.g. farm_short)\"\n />\n <MuiTextField\n label=\"Row field\"\n fullWidth\n value={value.spec.rowField ?? 'timestamp'}\n onChange={(e) => onChange({ ...value, spec: { ...value.spec, rowField: e.target.value } })}\n helperText=\"Field used for row identity (default: timestamp)\"\n />\n <MuiTextField\n label=\"Value field\"\n fullWidth\n value={value.spec.valueField ?? 'value'}\n onChange={(e) => onChange({ ...value, spec: { ...value.spec, valueField: e.target.value } })}\n />\n <MuiTextField\n label=\"Row column name\"\n fullWidth\n value={value.spec.rowColumnName ?? ''}\n onChange={(e) =>\n onChange({\n ...value,\n spec: { ...value.spec, rowColumnName: e.target.value || undefined },\n })\n }\n helperText=\"Optional display name for the row column (default: row field)\"\n />\n <FormControlLabel\n control={\n <Switch\n checked={!!value.spec.disabled}\n onChange={(_, checked) => onChange({ ...value, spec: { ...value.spec, disabled: checked } })}\n />\n }\n label=\"Disabled\"\n />\n </Stack>\n );\n}\n"],"names":["Autocomplete","FormControlLabel","MenuItem","Stack","Switch","Typography","TextField","MuiTextField","JoinByColumnValueTransformEditor","value","onChange","direction","freeSolo","multiple","id","sx","width","options","spec","columns","renderInput","params","variant","label","required","_","labelPlacement","control","disabled","checked","e","target","MergeColumnsTransformEditor","gap","alignItems","name","MergeIndexedColumnsTransformEditor","placeholder","column","MergeSeriesTransformEditor","TransformEditor","props","mt","select","kind","PivotByLabelTransformEditor","fullWidth","columnLabel","helperText","rowField","valueField","rowColumnName","undefined"],"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,SACEA,YAAY,EACZC,gBAAgB,EAChBC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,aAAaC,YAAY,QACpB,gBAAgB;AAGvB,SAASD,SAAS,QAAQ,uBAAc;AAexC,SAASE,iCAAiC,EACxCC,KAAK,EACLC,QAAQ,EAC6C;IACrD,qBACE,MAACP;QAAMQ,WAAU;;0BACf,KAACX;gBACCY,QAAQ;gBACRC,QAAQ;gBACRC,IAAG;gBACHC,IAAI;oBAAEC,OAAO;gBAAO;gBACpBC,SAAS,EAAE;gBACXR,OAAOA,MAAMS,IAAI,CAACC,OAAO,IAAI,EAAE;gBAC/BC,aAAa,CAACC,uBAAW,KAACd;wBAAc,GAAGc,MAAM;wBAAEC,SAAQ;wBAAWC,OAAM;wBAAUC,QAAQ;;gBAC9Fd,UAAU,CAACe,GAAGN;oBACZT,SAAS;wBACP,GAAGD,KAAK;wBACRS,MAAM;4BACJ,GAAGT,MAAMS,IAAI;4BACbC,SAASA;wBACX;oBACF;gBACF;;0BAEF,KAAClB;gBACCsB,OAAM;gBACNG,gBAAe;gBACfC,uBACE,KAACvB;oBACCK,OAAO,CAACA,MAAMS,IAAI,CAACU,QAAQ;oBAC3BC,SAAS,CAACpB,MAAMS,IAAI,CAACU,QAAQ;oBAC7BlB,UAAU,CAACoB,IACTpB,SAAS;4BACP,GAAGD,KAAK;4BACRS,MA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,UAAYnB,SAAS;4BAAE,GAAGD,KAAK;4BAAES,MAAM;gCAAE,GAAGT,MAAMS,IAAI;gCAAEU,UAAUC;4BAAQ;wBAAE;;gBAG9FN,OAAM;;;;AAId"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional display override on standard formats.
|
|
3
|
+
* `unit` remains the stable key (multi-axis, maps, UI config);
|
|
4
|
+
* `customLabel` only changes the text shown after the scaled quantity.
|
|
5
|
+
*
|
|
6
|
+
* Data sizes (bytes/bits): keep SI/IEC scale (Ki, Mi, K, M, …) and replace the
|
|
7
|
+
* base unit — e.g. "1.46 KiB" + "prout" → "1.46 Ki prout" (not "gigaprout").
|
|
8
|
+
* Dates stay untouched (structured timestamps).
|
|
9
|
+
*/
|
|
10
|
+
export type WithCustomLabel = {
|
|
11
|
+
customLabel?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Whether FormatControls / formatValue should honor customLabel for this unit key.
|
|
15
|
+
*/
|
|
16
|
+
export declare function supportsCustomLabel(unit?: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* If customLabel is set and the unit is supported, replace the standard unit text
|
|
19
|
+
* with the display label. Dates leave `formatted` unchanged.
|
|
20
|
+
*/
|
|
21
|
+
export declare function applyCustomLabel(formatted: string, customLabel?: string, unit?: string): string;
|
|
22
|
+
//# sourceMappingURL=custom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/model/custom.ts"],"names":[],"mappings":"AAaA;;;;;;;;GAQG;AAEH,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAgEF;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAK1D;AAKD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAwD/F"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
/**
|
|
14
|
+
* Optional display override on standard formats.
|
|
15
|
+
* `unit` remains the stable key (multi-axis, maps, UI config);
|
|
16
|
+
* `customLabel` only changes the text shown after the scaled quantity.
|
|
17
|
+
*
|
|
18
|
+
* Data sizes (bytes/bits): keep SI/IEC scale (Ki, Mi, K, M, …) and replace the
|
|
19
|
+
* base unit — e.g. "1.46 KiB" + "prout" → "1.46 Ki prout" (not "gigaprout").
|
|
20
|
+
* Dates stay untouched (structured timestamps).
|
|
21
|
+
*/ /** Units where customLabel is not applied (unstructured / identity formats). */ const CUSTOM_LABEL_EXCLUDED_UNITS = new Set([
|
|
22
|
+
'datetime-iso',
|
|
23
|
+
'datetime-us',
|
|
24
|
+
'datetime-local',
|
|
25
|
+
'date-iso',
|
|
26
|
+
'date-us',
|
|
27
|
+
'date-local',
|
|
28
|
+
'time-local',
|
|
29
|
+
'time-iso',
|
|
30
|
+
'time-us',
|
|
31
|
+
'relative-time',
|
|
32
|
+
'unix-timestamp',
|
|
33
|
+
'unix-timestamp-ms'
|
|
34
|
+
]);
|
|
35
|
+
const DATA_SIZE_UNITS = new Set([
|
|
36
|
+
'bytes',
|
|
37
|
+
'decbytes',
|
|
38
|
+
'bits',
|
|
39
|
+
'decbits',
|
|
40
|
+
'bytes/sec',
|
|
41
|
+
'decbytes/sec',
|
|
42
|
+
'bits/sec',
|
|
43
|
+
'decbits/sec'
|
|
44
|
+
]);
|
|
45
|
+
const CURRENCY_UNITS = new Set([
|
|
46
|
+
'usd',
|
|
47
|
+
'eur',
|
|
48
|
+
'gbp',
|
|
49
|
+
'jpy',
|
|
50
|
+
'cny',
|
|
51
|
+
'cad',
|
|
52
|
+
'aud',
|
|
53
|
+
'chf',
|
|
54
|
+
'hkd',
|
|
55
|
+
'sgd',
|
|
56
|
+
'sek',
|
|
57
|
+
'krw',
|
|
58
|
+
'nok',
|
|
59
|
+
'nzd',
|
|
60
|
+
'inr',
|
|
61
|
+
'mxn',
|
|
62
|
+
'twd',
|
|
63
|
+
'zar',
|
|
64
|
+
'brl',
|
|
65
|
+
'dkk',
|
|
66
|
+
'pln',
|
|
67
|
+
'thb',
|
|
68
|
+
'ils',
|
|
69
|
+
'czk',
|
|
70
|
+
'clp',
|
|
71
|
+
'php',
|
|
72
|
+
'aed',
|
|
73
|
+
'cop',
|
|
74
|
+
'sar',
|
|
75
|
+
'myr',
|
|
76
|
+
'ron',
|
|
77
|
+
'afn'
|
|
78
|
+
]);
|
|
79
|
+
/**
|
|
80
|
+
* Whether FormatControls / formatValue should honor customLabel for this unit key.
|
|
81
|
+
*/ export function supportsCustomLabel(unit) {
|
|
82
|
+
if (!unit) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return !CUSTOM_LABEL_EXCLUDED_UNITS.has(unit);
|
|
86
|
+
}
|
|
87
|
+
/** Sign + number (grouped / scientific). */ const LEADING_NUMBER = /^[+-]?(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?(?:[eE][+-]?\d+)?/;
|
|
88
|
+
/**
|
|
89
|
+
* If customLabel is set and the unit is supported, replace the standard unit text
|
|
90
|
+
* with the display label. Dates leave `formatted` unchanged.
|
|
91
|
+
*/ export function applyCustomLabel(formatted, customLabel, unit) {
|
|
92
|
+
const label = customLabel?.trim();
|
|
93
|
+
if (!label) {
|
|
94
|
+
return formatted;
|
|
95
|
+
}
|
|
96
|
+
if (!supportsCustomLabel(unit)) {
|
|
97
|
+
return formatted;
|
|
98
|
+
}
|
|
99
|
+
if (unit && DATA_SIZE_UNITS.has(unit)) {
|
|
100
|
+
return applyDataSizeCustomLabel(formatted, label);
|
|
101
|
+
}
|
|
102
|
+
if (unit && CURRENCY_UNITS.has(unit)) {
|
|
103
|
+
return applyCurrencyCustomLabel(formatted, label);
|
|
104
|
+
}
|
|
105
|
+
// formatTime zero sentinel
|
|
106
|
+
if (formatted === '0s') {
|
|
107
|
+
return `0 ${label}`;
|
|
108
|
+
}
|
|
109
|
+
// Percent: "12.3%" → "12.3 load"
|
|
110
|
+
if (unit === 'percent' || unit === 'percent-decimal') {
|
|
111
|
+
if (formatted.endsWith('%')) {
|
|
112
|
+
return `${formatted.slice(0, -1).trimEnd()} ${label}`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Temperature: "11°C" / "52°F"
|
|
116
|
+
if (unit === 'celsius' && formatted.endsWith('°C')) {
|
|
117
|
+
return `${formatted.slice(0, -2).trimEnd()} ${label}`;
|
|
118
|
+
}
|
|
119
|
+
if (unit === 'fahrenheit' && formatted.endsWith('°F')) {
|
|
120
|
+
return `${formatted.slice(0, -2).trimEnd()} ${label}`;
|
|
121
|
+
}
|
|
122
|
+
// Exact unit-key suffix: "10 ops/sec", "1.5K ops/sec"
|
|
123
|
+
if (unit && formatted.endsWith(` ${unit}`)) {
|
|
124
|
+
return `${formatted.slice(0, -(unit.length + 1))} ${label}`;
|
|
125
|
+
}
|
|
126
|
+
// Time units: Intl narrow often glues the suffix ("1ms", "1μs") with no space — the
|
|
127
|
+
// generic leadingQuantity path can leave "ms" if a consumer re-appends a label, and
|
|
128
|
+
// the bare append fallback would yield "1ms prout". Strip known time tokens first.
|
|
129
|
+
if (unit && TIME_FORMAT_UNITS.has(unit)) {
|
|
130
|
+
return applyTimeCustomLabel(formatted, label);
|
|
131
|
+
}
|
|
132
|
+
// Decimal / throughput fallback: keep leading quantity only
|
|
133
|
+
const qty = leadingQuantity(formatted);
|
|
134
|
+
if (qty !== null) {
|
|
135
|
+
return `${qty} ${label}`;
|
|
136
|
+
}
|
|
137
|
+
return `${formatted} ${label}`;
|
|
138
|
+
}
|
|
139
|
+
/** Time format unit keys (formatTime / Intl unit style). */ const TIME_FORMAT_UNITS = new Set([
|
|
140
|
+
'nanoseconds',
|
|
141
|
+
'microseconds',
|
|
142
|
+
'milliseconds',
|
|
143
|
+
'seconds',
|
|
144
|
+
'minutes',
|
|
145
|
+
'hours',
|
|
146
|
+
'days',
|
|
147
|
+
'weeks',
|
|
148
|
+
'months',
|
|
149
|
+
'years'
|
|
150
|
+
]);
|
|
151
|
+
/**
|
|
152
|
+
* Replace formatTime output with custom label.
|
|
153
|
+
* Handles glued narrow units (1ms, 500µs), spaced long forms (1 month), and
|
|
154
|
+
* multi-part strings (1d255ms) by keeping only the leading quantity (+ compact K/M/B/T).
|
|
155
|
+
*/ function applyTimeCustomLabel(formatted, label) {
|
|
156
|
+
const body = formatted.trim();
|
|
157
|
+
if (body === '0s' || body === '0') {
|
|
158
|
+
return `0 ${label}`;
|
|
159
|
+
}
|
|
160
|
+
// Strip trailing time tokens (repeat for compound "1d 2h", "1d255ms").
|
|
161
|
+
// Long names → multi-letter narrow (ms before m|s) → single-letter. One µ only (not µs|μs).
|
|
162
|
+
let stripped = body.replace(/\u03bc/g, '\u00b5'); // Greek μ → micro sign µ (Intl variants)
|
|
163
|
+
const timeToken = /(?:\s*)(?:milliseconds?|microseconds?|nanoseconds?|seconds?|minutes?|hours?|days?|weeks?|months?|years?|ms|us|ns|µs|[ywdhms])$/i;
|
|
164
|
+
let guard = 0;
|
|
165
|
+
while(timeToken.test(stripped) && guard++ < 8){
|
|
166
|
+
stripped = stripped.replace(timeToken, '').trimEnd();
|
|
167
|
+
}
|
|
168
|
+
if (stripped !== '' && stripped !== body) {
|
|
169
|
+
// Prefer full numeric head (incl. decimals / compact) from stripped body
|
|
170
|
+
const qty = leadingQuantity(stripped) ?? stripped;
|
|
171
|
+
return `${qty} ${label}`;
|
|
172
|
+
}
|
|
173
|
+
const qty = leadingQuantity(body);
|
|
174
|
+
if (qty !== null) {
|
|
175
|
+
return `${qty} ${label}`;
|
|
176
|
+
}
|
|
177
|
+
return `${body} ${label}`;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Bytes/bits (+ optional /s|/sec): keep scale (Ki, Mi, K, M, …), replace base unit.
|
|
181
|
+
* "1.46 KiB" + prout → "1.46 Ki prout"
|
|
182
|
+
* "1.5 KB/s" + wire → "1.5 K wire/s"
|
|
183
|
+
* "500 bytes" + prout → "500 prout"
|
|
184
|
+
*/ function applyDataSizeCustomLabel(formatted, label) {
|
|
185
|
+
let rate = '';
|
|
186
|
+
let body = formatted.trim();
|
|
187
|
+
const rateM = body.match(/(\/s(?:ec)?)$/i);
|
|
188
|
+
if (rateM?.[1]) {
|
|
189
|
+
rate = rateM[1];
|
|
190
|
+
body = body.slice(0, -rate.length).trimEnd();
|
|
191
|
+
}
|
|
192
|
+
// Long form: "500 bytes", "1,500 bits"
|
|
193
|
+
const long = body.match(/^(.+?)\s+(bytes?|bits?)$/i);
|
|
194
|
+
if (long?.[1]) {
|
|
195
|
+
return `${long[1].trim()} ${label}${rate}`;
|
|
196
|
+
}
|
|
197
|
+
// Short form: "1.46 KiB", "1.5 KB", "1.46 Kib", "1.5 Kb" (optional space before scale)
|
|
198
|
+
const short = body.match(/^(.+?)\s*([KMGTPE]i?)\s*([Bb])$/);
|
|
199
|
+
if (short?.[1] && short[2]) {
|
|
200
|
+
return `${short[1].trim()} ${short[2]} ${label}${rate}`;
|
|
201
|
+
}
|
|
202
|
+
const qty = leadingQuantity(body);
|
|
203
|
+
if (qty !== null) {
|
|
204
|
+
return `${qty} ${label}${rate}`;
|
|
205
|
+
}
|
|
206
|
+
return `${formatted} ${label}`;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Currency: drop symbol/code, keep amount + custom label.
|
|
210
|
+
* "$1,500" + credits → "1,500 credits"
|
|
211
|
+
*/ function applyCurrencyCustomLabel(formatted, label) {
|
|
212
|
+
// Strip common leading/trailing currency symbols and ISO codes.
|
|
213
|
+
// Keep optional leading sign so "-$1.23" → "-1.23 credits" (not "-$1.23 credits").
|
|
214
|
+
let body = formatted.trim();
|
|
215
|
+
body = body.replace(/^([+-]?)\s*[^\d\s+-]+/, '$1'); // -$1.23 / $1.23 / €12.3
|
|
216
|
+
body = body.replace(/\s*[A-Z]{3}$/, ''); // trailing USD
|
|
217
|
+
body = body.trim();
|
|
218
|
+
const qty = leadingQuantity(body);
|
|
219
|
+
if (qty !== null) {
|
|
220
|
+
return `${body} ${label}`;
|
|
221
|
+
}
|
|
222
|
+
return `${body} ${label}`;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Numeric prefix of a formatted value, keeping SI compact (1.5K)
|
|
226
|
+
* but not unit letters glued to the number (500ms → 500, not 500m).
|
|
227
|
+
*/ function leadingQuantity(formatted) {
|
|
228
|
+
const s = formatted.trimStart();
|
|
229
|
+
const num = s.match(LEADING_NUMBER);
|
|
230
|
+
if (!num?.[0]) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
const head = num[0];
|
|
234
|
+
const rest = s.slice(head.length);
|
|
235
|
+
// Compact decimal suffix K/M/B/T only when not starting a longer unit word (ms, min, …).
|
|
236
|
+
const compact = rest.match(/^([KMBT])(?=\s|$)/i);
|
|
237
|
+
if (compact) {
|
|
238
|
+
return head + compact[1];
|
|
239
|
+
}
|
|
240
|
+
return head;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
//# sourceMappingURL=custom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/custom.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\n/**\n * Optional display override on standard formats.\n * `unit` remains the stable key (multi-axis, maps, UI config);\n * `customLabel` only changes the text shown after the scaled quantity.\n *\n * Data sizes (bytes/bits): keep SI/IEC scale (Ki, Mi, K, M, …) and replace the\n * base unit — e.g. \"1.46 KiB\" + \"prout\" → \"1.46 Ki prout\" (not \"gigaprout\").\n * Dates stay untouched (structured timestamps).\n */\n\nexport type WithCustomLabel = {\n customLabel?: string;\n};\n\n/** Units where customLabel is not applied (unstructured / identity formats). */\nconst CUSTOM_LABEL_EXCLUDED_UNITS = new Set([\n 'datetime-iso',\n 'datetime-us',\n 'datetime-local',\n 'date-iso',\n 'date-us',\n 'date-local',\n 'time-local',\n 'time-iso',\n 'time-us',\n 'relative-time',\n 'unix-timestamp',\n 'unix-timestamp-ms',\n]);\n\nconst DATA_SIZE_UNITS = new Set([\n 'bytes',\n 'decbytes',\n 'bits',\n 'decbits',\n 'bytes/sec',\n 'decbytes/sec',\n 'bits/sec',\n 'decbits/sec',\n]);\n\nconst CURRENCY_UNITS = new Set([\n 'usd',\n 'eur',\n 'gbp',\n 'jpy',\n 'cny',\n 'cad',\n 'aud',\n 'chf',\n 'hkd',\n 'sgd',\n 'sek',\n 'krw',\n 'nok',\n 'nzd',\n 'inr',\n 'mxn',\n 'twd',\n 'zar',\n 'brl',\n 'dkk',\n 'pln',\n 'thb',\n 'ils',\n 'czk',\n 'clp',\n 'php',\n 'aed',\n 'cop',\n 'sar',\n 'myr',\n 'ron',\n 'afn',\n]);\n\n/**\n * Whether FormatControls / formatValue should honor customLabel for this unit key.\n */\nexport function supportsCustomLabel(unit?: string): boolean {\n if (!unit) {\n return true;\n }\n return !CUSTOM_LABEL_EXCLUDED_UNITS.has(unit);\n}\n\n/** Sign + number (grouped / scientific). */\nconst LEADING_NUMBER = /^[+-]?(?:\\d{1,3}(?:,\\d{3})*|\\d+)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?/;\n\n/**\n * If customLabel is set and the unit is supported, replace the standard unit text\n * with the display label. Dates leave `formatted` unchanged.\n */\nexport function applyCustomLabel(formatted: string, customLabel?: string, unit?: string): string {\n const label = customLabel?.trim();\n if (!label) {\n return formatted;\n }\n if (!supportsCustomLabel(unit)) {\n return formatted;\n }\n\n if (unit && DATA_SIZE_UNITS.has(unit)) {\n return applyDataSizeCustomLabel(formatted, label);\n }\n\n if (unit && CURRENCY_UNITS.has(unit)) {\n return applyCurrencyCustomLabel(formatted, label);\n }\n\n // formatTime zero sentinel\n if (formatted === '0s') {\n return `0 ${label}`;\n }\n\n // Percent: \"12.3%\" → \"12.3 load\"\n if (unit === 'percent' || unit === 'percent-decimal') {\n if (formatted.endsWith('%')) {\n return `${formatted.slice(0, -1).trimEnd()} ${label}`;\n }\n }\n\n // Temperature: \"11°C\" / \"52°F\"\n if (unit === 'celsius' && formatted.endsWith('°C')) {\n return `${formatted.slice(0, -2).trimEnd()} ${label}`;\n }\n if (unit === 'fahrenheit' && formatted.endsWith('°F')) {\n return `${formatted.slice(0, -2).trimEnd()} ${label}`;\n }\n\n // Exact unit-key suffix: \"10 ops/sec\", \"1.5K ops/sec\"\n if (unit && formatted.endsWith(` ${unit}`)) {\n return `${formatted.slice(0, -(unit.length + 1))} ${label}`;\n }\n\n // Time units: Intl narrow often glues the suffix (\"1ms\", \"1μs\") with no space — the\n // generic leadingQuantity path can leave \"ms\" if a consumer re-appends a label, and\n // the bare append fallback would yield \"1ms prout\". Strip known time tokens first.\n if (unit && TIME_FORMAT_UNITS.has(unit)) {\n return applyTimeCustomLabel(formatted, label);\n }\n\n // Decimal / throughput fallback: keep leading quantity only\n const qty = leadingQuantity(formatted);\n if (qty !== null) {\n return `${qty} ${label}`;\n }\n\n return `${formatted} ${label}`;\n}\n\n/** Time format unit keys (formatTime / Intl unit style). */\nconst TIME_FORMAT_UNITS = new Set([\n 'nanoseconds',\n 'microseconds',\n 'milliseconds',\n 'seconds',\n 'minutes',\n 'hours',\n 'days',\n 'weeks',\n 'months',\n 'years',\n]);\n\n/**\n * Replace formatTime output with custom label.\n * Handles glued narrow units (1ms, 500µs), spaced long forms (1 month), and\n * multi-part strings (1d255ms) by keeping only the leading quantity (+ compact K/M/B/T).\n */\nfunction applyTimeCustomLabel(formatted: string, label: string): string {\n const body = formatted.trim();\n if (body === '0s' || body === '0') {\n return `0 ${label}`;\n }\n\n // Strip trailing time tokens (repeat for compound \"1d 2h\", \"1d255ms\").\n // Long names → multi-letter narrow (ms before m|s) → single-letter. One µ only (not µs|μs).\n let stripped = body.replace(/\\u03bc/g, '\\u00b5'); // Greek μ → micro sign µ (Intl variants)\n const timeToken =\n /(?:\\s*)(?:milliseconds?|microseconds?|nanoseconds?|seconds?|minutes?|hours?|days?|weeks?|months?|years?|ms|us|ns|µs|[ywdhms])$/i;\n let guard = 0;\n while (timeToken.test(stripped) && guard++ < 8) {\n stripped = stripped.replace(timeToken, '').trimEnd();\n }\n if (stripped !== '' && stripped !== body) {\n // Prefer full numeric head (incl. decimals / compact) from stripped body\n const qty = leadingQuantity(stripped) ?? stripped;\n return `${qty} ${label}`;\n }\n\n const qty = leadingQuantity(body);\n if (qty !== null) {\n return `${qty} ${label}`;\n }\n return `${body} ${label}`;\n}\n\n/**\n * Bytes/bits (+ optional /s|/sec): keep scale (Ki, Mi, K, M, …), replace base unit.\n * \"1.46 KiB\" + prout → \"1.46 Ki prout\"\n * \"1.5 KB/s\" + wire → \"1.5 K wire/s\"\n * \"500 bytes\" + prout → \"500 prout\"\n */\nfunction applyDataSizeCustomLabel(formatted: string, label: string): string {\n let rate = '';\n let body = formatted.trim();\n const rateM = body.match(/(\\/s(?:ec)?)$/i);\n if (rateM?.[1]) {\n rate = rateM[1];\n body = body.slice(0, -rate.length).trimEnd();\n }\n\n // Long form: \"500 bytes\", \"1,500 bits\"\n const long = body.match(/^(.+?)\\s+(bytes?|bits?)$/i);\n if (long?.[1]) {\n return `${long[1].trim()} ${label}${rate}`;\n }\n\n // Short form: \"1.46 KiB\", \"1.5 KB\", \"1.46 Kib\", \"1.5 Kb\" (optional space before scale)\n const short = body.match(/^(.+?)\\s*([KMGTPE]i?)\\s*([Bb])$/);\n if (short?.[1] && short[2]) {\n return `${short[1].trim()} ${short[2]} ${label}${rate}`;\n }\n\n const qty = leadingQuantity(body);\n if (qty !== null) {\n return `${qty} ${label}${rate}`;\n }\n return `${formatted} ${label}`;\n}\n\n/**\n * Currency: drop symbol/code, keep amount + custom label.\n * \"$1,500\" + credits → \"1,500 credits\"\n */\nfunction applyCurrencyCustomLabel(formatted: string, label: string): string {\n // Strip common leading/trailing currency symbols and ISO codes.\n // Keep optional leading sign so \"-$1.23\" → \"-1.23 credits\" (not \"-$1.23 credits\").\n let body = formatted.trim();\n body = body.replace(/^([+-]?)\\s*[^\\d\\s+-]+/, '$1'); // -$1.23 / $1.23 / €12.3\n body = body.replace(/\\s*[A-Z]{3}$/, ''); // trailing USD\n body = body.trim();\n const qty = leadingQuantity(body);\n if (qty !== null) {\n return `${body} ${label}`;\n }\n return `${body} ${label}`;\n}\n\n/**\n * Numeric prefix of a formatted value, keeping SI compact (1.5K)\n * but not unit letters glued to the number (500ms → 500, not 500m).\n */\nfunction leadingQuantity(formatted: string): string | null {\n const s = formatted.trimStart();\n const num = s.match(LEADING_NUMBER);\n if (!num?.[0]) {\n return null;\n }\n const head = num[0];\n const rest = s.slice(head.length);\n\n // Compact decimal suffix K/M/B/T only when not starting a longer unit word (ms, min, …).\n const compact = rest.match(/^([KMBT])(?=\\s|$)/i);\n if (compact) {\n return head + compact[1];\n }\n\n return head;\n}\n"],"names":["CUSTOM_LABEL_EXCLUDED_UNITS","Set","DATA_SIZE_UNITS","CURRENCY_UNITS","supportsCustomLabel","unit","has","LEADING_NUMBER","applyCustomLabel","formatted","customLabel","label","trim","applyDataSizeCustomLabel","applyCurrencyCustomLabel","endsWith","slice","trimEnd","length","TIME_FORMAT_UNITS","applyTimeCustomLabel","qty","leadingQuantity","body","stripped","replace","timeToken","guard","test","rate","rateM","match","long","short","s","trimStart","num","head","rest","compact"],"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;;;;;;;;CAQC,GAMD,8EAA8E,GAC9E,MAAMA,8BA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