@perses-dev/components 0.54.0-beta.9 → 0.54.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EChart/index.d.ts +1 -0
- package/dist/EChart/index.d.ts.map +1 -1
- package/dist/EChart/index.js +1 -0
- package/dist/EChart/index.js.map +1 -1
- package/dist/EChart/timezone-formatter.d.ts +5 -0
- package/dist/EChart/timezone-formatter.d.ts.map +1 -0
- package/dist/EChart/timezone-formatter.js +43 -0
- package/dist/EChart/timezone-formatter.js.map +1 -0
- package/dist/LinksEditor/index.d.ts +0 -1
- package/dist/LinksEditor/index.d.ts.map +1 -1
- package/dist/LinksEditor/index.js +0 -1
- package/dist/LinksEditor/index.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js +25 -6
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts +1 -0
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +1 -0
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +5 -23
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.js +218 -153
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/types.d.ts +30 -0
- package/dist/TimeSeriesTooltip/types.d.ts.map +1 -0
- package/dist/TimeSeriesTooltip/types.js +15 -0
- package/dist/TimeSeriesTooltip/types.js.map +1 -0
- package/dist/TimeSeriesTooltip/utils.d.ts +26 -1
- package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/utils.js +105 -9
- package/dist/TimeSeriesTooltip/utils.js.map +1 -1
- package/dist/cjs/EChart/index.js +1 -0
- package/dist/cjs/EChart/timezone-formatter.js +49 -0
- package/dist/cjs/LinksEditor/index.js +0 -1
- package/dist/cjs/TimeSeriesTooltip/TimeChartTooltip.js +24 -5
- package/dist/cjs/TimeSeriesTooltip/index.js +1 -0
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +216 -151
- package/dist/cjs/TimeSeriesTooltip/types.js +16 -0
- package/dist/cjs/TimeSeriesTooltip/utils.js +109 -8
- package/dist/cjs/utils/chart-actions.js +12 -4
- package/dist/cjs/utils/request-interpolation.js +20 -2
- package/dist/cjs/utils/variable-interpolation.js +6 -0
- package/dist/utils/chart-actions.d.ts.map +1 -1
- package/dist/utils/chart-actions.js +12 -4
- package/dist/utils/chart-actions.js.map +1 -1
- package/dist/utils/request-interpolation.d.ts.map +1 -1
- package/dist/utils/request-interpolation.js +20 -2
- package/dist/utils/request-interpolation.js.map +1 -1
- package/dist/utils/variable-interpolation.d.ts +3 -1
- package/dist/utils/variable-interpolation.d.ts.map +1 -1
- package/dist/utils/variable-interpolation.js +6 -0
- package/dist/utils/variable-interpolation.js.map +1 -1
- package/package.json +3 -4
- package/dist/LinksEditor/LinksEditor.d.ts +0 -8
- package/dist/LinksEditor/LinksEditor.d.ts.map +0 -1
- package/dist/LinksEditor/LinksEditor.js +0 -149
- package/dist/LinksEditor/LinksEditor.js.map +0 -1
- package/dist/cjs/LinksEditor/LinksEditor.js +0 -162
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/tooltip-model.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 { useEffect, useState } from 'react';\nimport { NearbySeriesArray } from './
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/tooltip-model.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 { useEffect, useState } from 'react';\nimport { NearbySeriesArray } from './types';\n\nexport const TOOLTIP_MIN_WIDTH = 375;\nexport const TOOLTIP_MAX_WIDTH = 650;\nexport const TOOLTIP_MAX_HEIGHT = 650;\nexport const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;\nexport const TOOLTIP_ADJUST_Y_POS_MULTIPLIER = 0.75;\nexport const TOOLTIP_PADDING = 8;\n\nexport const FALLBACK_CHART_WIDTH = 750;\n\nexport const NEARBY_SERIES_DESCRIPTION = 'nearby series showing in tooltip';\nexport const EMPHASIZED_SERIES_DESCRIPTION = 'emphasized series showing as bold in tooltip';\n\nexport const TOOLTIP_BG_COLOR_FALLBACK = '#2E313E';\n\nexport const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n hour12: true,\n});\n\nexport const defaultCursorData = {\n coords: {\n plotCanvas: {\n x: 0,\n y: 0,\n },\n zrender: {\n x: 0,\n y: 0,\n },\n target: null,\n },\n chartWidth: 0,\n};\n\nexport const EMPTY_TOOLTIP_DATA: NearbySeriesArray = [];\n\n/**\n * ECharts is built with zrender, zrX and zrY are undefined when not hovering over a chart canvas\n */\nexport interface ZRCoordinate {\n x?: number;\n y?: number;\n}\n\nexport interface Coordinate {\n x: number;\n y: number;\n}\n\nexport interface CursorCoordinates {\n page: Coordinate;\n client: Coordinate;\n plotCanvas: ZRCoordinate;\n target: EventTarget | null;\n}\n\nexport interface CursorData {\n coords: CursorCoordinates | null;\n chartWidth?: number;\n}\n\nexport interface TooltipData {\n focusedSeries: NearbySeriesArray | null;\n cursor: CursorData;\n}\n\ntype ZREventProperties = {\n zrX?: number;\n zrY?: number;\n zrDelta?: number;\n zrEventControl?: 'no_globalout' | 'only_globalout';\n zrByTouch?: boolean;\n};\n\nexport type ZRRawMouseEvent = MouseEvent & ZREventProperties;\n\nexport const useMousePosition = (): CursorData['coords'] => {\n const [coords, setCoords] = useState<CursorData['coords']>(null);\n\n useEffect(() => {\n const setFromEvent = (e: ZRRawMouseEvent): void => {\n return setCoords({\n page: {\n x: e.pageX,\n y: e.pageY,\n },\n client: {\n x: e.clientX,\n y: e.clientY,\n },\n plotCanvas: {\n // Default to zrender mousemove coords since they handle browser inconsistencies for us\n // ex: Firefox and Chrome have slightly different implementations of offsetX and offsetY\n // more info: https://github.com/ecomfe/zrender/blob/5.5.0/src/core/event.ts#L46-L120\n // Fallback to offsetX and offsetY to ensure tooltip works correctly in Edge\n x: e.zrX ?? e.offsetX,\n y: e.zrY ?? e.offsetY,\n },\n // necessary to check whether cursor target matches correct chart canvas (since each chart has its own mousemove listener)\n target: e.target,\n });\n };\n window.addEventListener('mousemove', setFromEvent);\n\n return (): void => {\n window.removeEventListener('mousemove', setFromEvent);\n };\n }, []);\n\n return coords;\n};\n\nexport type TooltipConfig = {\n wrapLabels: boolean;\n hidden?: boolean;\n enablePinning?: boolean;\n};\n\nexport const DEFAULT_TOOLTIP_CONFIG: TooltipConfig = {\n wrapLabels: true,\n enablePinning: true,\n};\n\nexport const PIN_TOOLTIP_HELP_TEXT = 'Click chart to pin';\n\nexport const UNPIN_TOOLTIP_HELP_TEXT = 'Click chart to unpin';\n"],"names":["useEffect","useState","TOOLTIP_MIN_WIDTH","TOOLTIP_MAX_WIDTH","TOOLTIP_MAX_HEIGHT","TOOLTIP_LABELS_MAX_WIDTH","TOOLTIP_ADJUST_Y_POS_MULTIPLIER","TOOLTIP_PADDING","FALLBACK_CHART_WIDTH","NEARBY_SERIES_DESCRIPTION","EMPHASIZED_SERIES_DESCRIPTION","TOOLTIP_BG_COLOR_FALLBACK","TOOLTIP_DATE_FORMAT","Intl","DateTimeFormat","undefined","year","month","day","hour","minute","second","hour12","defaultCursorData","coords","plotCanvas","x","y","zrender","target","chartWidth","EMPTY_TOOLTIP_DATA","useMousePosition","setCoords","setFromEvent","e","page","pageX","pageY","client","clientX","clientY","zrX","offsetX","zrY","offsetY","window","addEventListener","removeEventListener","DEFAULT_TOOLTIP_CONFIG","wrapLabels","enablePinning","PIN_TOOLTIP_HELP_TEXT","UNPIN_TOOLTIP_HELP_TEXT"],"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,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAG5C,OAAO,MAAMC,oBAAoB,IAAI;AACrC,OAAO,MAAMC,oBAAoB,IAAI;AACrC,OAAO,MAAMC,qBAAqB,IAAI;AACtC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C1C;IACF,GAAG,EAAE;IAEL,OAAOV;AACT,EAAE;AAQF,OAAO,MAAMyB,yBAAwC;IACnDC,YAAY;IACZC,eAAe;AACjB,EAAE;AAEF,OAAO,MAAMC,wBAAwB,qBAAqB;AAE1D,OAAO,MAAMC,0BAA0B,uBAAuB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface NearbySeriesInfo {
|
|
2
|
+
seriesIdx: number | null;
|
|
3
|
+
datumIdx: number | null;
|
|
4
|
+
seriesName: string;
|
|
5
|
+
date: number;
|
|
6
|
+
markerColor: string;
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
formattedY: string;
|
|
10
|
+
isClosestToCursor: boolean;
|
|
11
|
+
}
|
|
12
|
+
export type NearbySeriesArray = NearbySeriesInfo[];
|
|
13
|
+
export type Candidate = Omit<NearbySeriesInfo, 'isClosestToCursor' | 'seriesIdx' | 'datumIdx' | 'formattedY'> & {
|
|
14
|
+
seriesIdx: number;
|
|
15
|
+
datumIdx: number;
|
|
16
|
+
seriesId: string;
|
|
17
|
+
visualY: number;
|
|
18
|
+
distance: number;
|
|
19
|
+
};
|
|
20
|
+
export type IsWithinPercentageRangeParams = {
|
|
21
|
+
valueToCheck: number;
|
|
22
|
+
baseValue: number;
|
|
23
|
+
percentage: number;
|
|
24
|
+
};
|
|
25
|
+
export type GetYBufferParams = {
|
|
26
|
+
yInterval: number;
|
|
27
|
+
totalSeries: number;
|
|
28
|
+
showAllSeries?: boolean;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/types.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,EAAE,CAAC;AAEnD,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,EAAE,mBAAmB,GAAG,WAAW,GAAG,UAAU,GAAG,YAAY,CAAC,GAAG;IAC9G,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
export { };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/types.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 interface NearbySeriesInfo {\n seriesIdx: number | null;\n datumIdx: number | null;\n seriesName: string;\n date: number;\n markerColor: string;\n x: number;\n y: number;\n formattedY: string;\n isClosestToCursor: boolean;\n}\n\nexport type NearbySeriesArray = NearbySeriesInfo[];\n\nexport type Candidate = Omit<NearbySeriesInfo, 'isClosestToCursor' | 'seriesIdx' | 'datumIdx' | 'formattedY'> & {\n seriesIdx: number;\n datumIdx: number;\n seriesId: string;\n visualY: number;\n distance: number;\n};\n\nexport type IsWithinPercentageRangeParams = {\n valueToCheck: number;\n baseValue: number;\n percentage: number;\n};\n\nexport type GetYBufferParams = {\n yInterval: number;\n totalSeries: number;\n showAllSeries?: boolean;\n};\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;AA8BjC,WAIE"}
|
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
import { Theme } from '@mui/material';
|
|
2
|
+
import { ECharts as EChartsInstance } from 'echarts/core';
|
|
3
|
+
import { TimeChartSeriesMapping } from '../model';
|
|
2
4
|
import { CursorCoordinates, CursorData } from './tooltip-model';
|
|
3
5
|
/**
|
|
4
|
-
* Determine position of tooltip depending on chart dimensions and the number of focused series
|
|
6
|
+
* Determine position of tooltip depending on chart dimensions and the number of focused series.
|
|
5
7
|
*/
|
|
6
8
|
export declare function assembleTransform(mousePos: CursorData['coords'], pinnedPos: CursorCoordinates | null, tooltipHeight: number, tooltipWidth: number, containerElement?: Element | null): string | undefined;
|
|
7
9
|
/**
|
|
8
10
|
* Helper for tooltip positioning styles
|
|
9
11
|
*/
|
|
10
12
|
export declare function getTooltipStyles(theme: Theme, pinnedPos: CursorCoordinates | null, maxHeight?: number): Record<string, unknown>;
|
|
13
|
+
export declare function getPixelXFromGrid(timestamp: number, chart: EChartsInstance): number | null;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the cumulative (visual) Y for a series, accumulating stack totals in-place.
|
|
16
|
+
* For non-stacked series, returns the raw yValue unchanged.
|
|
17
|
+
* Mutates `stackTotals` — pass a fresh Map for each cursor evaluation.
|
|
18
|
+
*/
|
|
19
|
+
export declare function calculateVisualYForSeries(seriesIdx: number, yValue: number, seriesMapping: TimeChartSeriesMapping, stackTotals: Map<string, number>): number;
|
|
20
|
+
export declare function calculateBarBandwidth(timestamp: number, sortedTimestamps: number[], chart: EChartsInstance): number;
|
|
21
|
+
/**
|
|
22
|
+
* Computes the pixel left/right bounds of one bar segment within a group.
|
|
23
|
+
* @param barRelativeIdx - zero-based index among bar-only series
|
|
24
|
+
* @param bandwidth - total pixel width for the bar group
|
|
25
|
+
* @param centerPixelX - pixel X of the bar group centre
|
|
26
|
+
* @param barCount - total bar series count (lines excluded)
|
|
27
|
+
*/
|
|
28
|
+
export declare function calculateBarSegmentBounds(barRelativeIdx: number, bandwidth: number, centerPixelX: number, barCount: number): {
|
|
29
|
+
left: number;
|
|
30
|
+
right: number;
|
|
31
|
+
};
|
|
32
|
+
export declare function calculateBarYBounds(visualYBottom: number, visualYTop: number, chart: EChartsInstance): {
|
|
33
|
+
top: number;
|
|
34
|
+
bottom: number;
|
|
35
|
+
} | null;
|
|
11
36
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,iBAAiB,EACjB,UAAU,EAMX,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,SAAS,EAAE,iBAAiB,GAAG,IAAI,EACnC,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,gBAAgB,CAAC,EAAE,OAAO,GAAG,IAAI,GAChC,MAAM,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EACL,iBAAiB,EACjB,UAAU,EAMX,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,SAAS,EAAE,iBAAiB,GAAG,IAAI,EACnC,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,gBAAgB,CAAC,EAAE,OAAO,GAAG,IAAI,GAChC,MAAM,GAAG,SAAS,CAuDpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,iBAAiB,GAAG,IAAI,EACnC,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyBzB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,CAO1F;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,sBAAsB,EACrC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,MAAM,CAcR;AAED,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,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"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { TOOLTIP_MAX_WIDTH, TOOLTIP_MAX_HEIGHT, TOOLTIP_MIN_WIDTH, TOOLTIP_BG_COLOR_FALLBACK, TOOLTIP_PADDING } from './tooltip-model';
|
|
14
14
|
/**
|
|
15
|
-
* Determine position of tooltip depending on chart dimensions and the number of focused series
|
|
15
|
+
* Determine position of tooltip depending on chart dimensions and the number of focused series.
|
|
16
16
|
*/ export function assembleTransform(mousePos, pinnedPos, tooltipHeight, tooltipWidth, containerElement) {
|
|
17
17
|
if (mousePos === null) {
|
|
18
18
|
return undefined;
|
|
@@ -23,6 +23,9 @@ import { TOOLTIP_MAX_WIDTH, TOOLTIP_MAX_HEIGHT, TOOLTIP_MIN_WIDTH, TOOLTIP_BG_CO
|
|
|
23
23
|
mousePos = pinnedPos;
|
|
24
24
|
}
|
|
25
25
|
if (mousePos.plotCanvas.x === undefined) return undefined;
|
|
26
|
+
// Fall back to max size before the resize observer reports a real measurement.
|
|
27
|
+
const effectiveHeight = tooltipHeight > 0 ? tooltipHeight : TOOLTIP_MAX_HEIGHT;
|
|
28
|
+
const effectiveWidth = tooltipWidth > 0 ? tooltipWidth : TOOLTIP_MAX_WIDTH;
|
|
26
29
|
let x = mousePos.page.x + cursorPaddingX; // Default to right side of the cursor
|
|
27
30
|
let y = mousePos.page.y + cursorPaddingY;
|
|
28
31
|
// If containerElement is defined, adjust coordinates relative to the container
|
|
@@ -32,18 +35,18 @@ import { TOOLTIP_MAX_WIDTH, TOOLTIP_MAX_HEIGHT, TOOLTIP_MIN_WIDTH, TOOLTIP_BG_CO
|
|
|
32
35
|
y = y - containerRect.top + containerElement.scrollTop;
|
|
33
36
|
// Ensure tooltip does not go out of the container's bottom
|
|
34
37
|
const containerBottom = containerRect.top + containerElement.scrollHeight;
|
|
35
|
-
if (y +
|
|
36
|
-
y = Math.max(containerBottom -
|
|
38
|
+
if (y + effectiveHeight > containerBottom) {
|
|
39
|
+
y = Math.max(containerBottom - effectiveHeight - cursorPaddingY, TOOLTIP_PADDING / 2);
|
|
37
40
|
}
|
|
38
41
|
} else {
|
|
39
42
|
// Ensure tooltip does not go out of the screen on the bottom
|
|
40
|
-
if (y +
|
|
41
|
-
y = Math.max(window.innerHeight + window.scrollY -
|
|
43
|
+
if (y + effectiveHeight > window.innerHeight + window.scrollY) {
|
|
44
|
+
y = Math.max(window.innerHeight + window.scrollY - effectiveHeight - cursorPaddingY, TOOLTIP_PADDING / 2);
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
// Ensure tooltip does not go out of the screen on the right
|
|
45
|
-
if (x +
|
|
46
|
-
x = mousePos.page.x -
|
|
48
|
+
if (x + effectiveWidth > window.innerWidth) {
|
|
49
|
+
x = mousePos.page.x - effectiveWidth - cursorPaddingX; // Move to the left of the cursor
|
|
47
50
|
}
|
|
48
51
|
// Ensure tooltip does not go out of the screen on the left
|
|
49
52
|
if (x < cursorPaddingX) {
|
|
@@ -73,8 +76,9 @@ import { TOOLTIP_MAX_WIDTH, TOOLTIP_MAX_HEIGHT, TOOLTIP_MIN_WIDTH, TOOLTIP_BG_CO
|
|
|
73
76
|
fontSize: '11px',
|
|
74
77
|
visibility: 'visible',
|
|
75
78
|
opacity: 1,
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
// Animating transform causes intermediate positions outside the viewport; animate opacity/visibility instead.
|
|
80
|
+
transition: 'opacity 0.1s ease-out, visibility 0.1s ease-out',
|
|
81
|
+
// Pinned tooltip should not float above the drawer/sticky header.
|
|
78
82
|
zIndex: pinnedPos !== null ? 'auto' : theme.zIndex.tooltip,
|
|
79
83
|
overflow: 'hidden',
|
|
80
84
|
'&:hover': {
|
|
@@ -82,5 +86,97 @@ import { TOOLTIP_MAX_WIDTH, TOOLTIP_MAX_HEIGHT, TOOLTIP_MIN_WIDTH, TOOLTIP_BG_CO
|
|
|
82
86
|
}
|
|
83
87
|
};
|
|
84
88
|
}
|
|
89
|
+
export function getPixelXFromGrid(timestamp, chart) {
|
|
90
|
+
try {
|
|
91
|
+
const pixelCoords = chart.convertToPixel('grid', [
|
|
92
|
+
timestamp,
|
|
93
|
+
0
|
|
94
|
+
]);
|
|
95
|
+
return pixelCoords?.[0] ?? null;
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns the cumulative (visual) Y for a series, accumulating stack totals in-place.
|
|
102
|
+
* For non-stacked series, returns the raw yValue unchanged.
|
|
103
|
+
* Mutates `stackTotals` — pass a fresh Map for each cursor evaluation.
|
|
104
|
+
*/ export function calculateVisualYForSeries(seriesIdx, yValue, seriesMapping, stackTotals) {
|
|
105
|
+
const currentSeries = seriesMapping[seriesIdx];
|
|
106
|
+
if (!currentSeries) return yValue;
|
|
107
|
+
const stackId = currentSeries.stack;
|
|
108
|
+
if (!stackId) {
|
|
109
|
+
return yValue;
|
|
110
|
+
}
|
|
111
|
+
const stackIdStr = stackId.toString();
|
|
112
|
+
const currentTotal = stackTotals.get(stackIdStr) ?? 0;
|
|
113
|
+
const newTotal = currentTotal + yValue;
|
|
114
|
+
stackTotals.set(stackIdStr, newTotal);
|
|
115
|
+
return newTotal;
|
|
116
|
+
}
|
|
117
|
+
export function calculateBarBandwidth(timestamp, sortedTimestamps, chart) {
|
|
118
|
+
const currentIdx = sortedTimestamps.indexOf(timestamp);
|
|
119
|
+
if (currentIdx === -1) {
|
|
120
|
+
return 20;
|
|
121
|
+
}
|
|
122
|
+
const prevTimestamp = currentIdx > 0 ? sortedTimestamps[currentIdx - 1] ?? null : null;
|
|
123
|
+
const nextTimestamp = currentIdx < sortedTimestamps.length - 1 ? sortedTimestamps[currentIdx + 1] ?? null : null;
|
|
124
|
+
const currentPixelX = getPixelXFromGrid(timestamp, chart);
|
|
125
|
+
if (currentPixelX === null) return 20;
|
|
126
|
+
let leftBound;
|
|
127
|
+
let rightBound;
|
|
128
|
+
if (prevTimestamp !== null && nextTimestamp !== null) {
|
|
129
|
+
const prevPixelX = getPixelXFromGrid(prevTimestamp, chart) ?? currentPixelX;
|
|
130
|
+
const nextPixelX = getPixelXFromGrid(nextTimestamp, chart) ?? currentPixelX;
|
|
131
|
+
leftBound = (currentPixelX + prevPixelX) / 2;
|
|
132
|
+
rightBound = (currentPixelX + nextPixelX) / 2;
|
|
133
|
+
} else if (prevTimestamp !== null) {
|
|
134
|
+
const prevPixelX = getPixelXFromGrid(prevTimestamp, chart) ?? currentPixelX;
|
|
135
|
+
leftBound = (currentPixelX + prevPixelX) / 2;
|
|
136
|
+
rightBound = currentPixelX + (currentPixelX - leftBound);
|
|
137
|
+
} else if (nextTimestamp !== null) {
|
|
138
|
+
const nextPixelX = getPixelXFromGrid(nextTimestamp, chart) ?? currentPixelX;
|
|
139
|
+
rightBound = (currentPixelX + nextPixelX) / 2;
|
|
140
|
+
leftBound = currentPixelX - (rightBound - currentPixelX);
|
|
141
|
+
} else {
|
|
142
|
+
return 20;
|
|
143
|
+
}
|
|
144
|
+
return Math.max(1, rightBound - leftBound);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Computes the pixel left/right bounds of one bar segment within a group.
|
|
148
|
+
* @param barRelativeIdx - zero-based index among bar-only series
|
|
149
|
+
* @param bandwidth - total pixel width for the bar group
|
|
150
|
+
* @param centerPixelX - pixel X of the bar group centre
|
|
151
|
+
* @param barCount - total bar series count (lines excluded)
|
|
152
|
+
*/ export function calculateBarSegmentBounds(barRelativeIdx, bandwidth, centerPixelX, barCount) {
|
|
153
|
+
const count = Math.max(1, barCount);
|
|
154
|
+
const segmentWidth = bandwidth / count;
|
|
155
|
+
const segmentLeft = centerPixelX - bandwidth / 2 + barRelativeIdx * segmentWidth;
|
|
156
|
+
return {
|
|
157
|
+
left: segmentLeft,
|
|
158
|
+
right: segmentLeft + segmentWidth
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export function calculateBarYBounds(visualYBottom, visualYTop, chart) {
|
|
162
|
+
try {
|
|
163
|
+
const bottomPixel = chart.convertToPixel('grid', [
|
|
164
|
+
0,
|
|
165
|
+
visualYBottom
|
|
166
|
+
]);
|
|
167
|
+
const topPixel = chart.convertToPixel('grid', [
|
|
168
|
+
0,
|
|
169
|
+
visualYTop
|
|
170
|
+
]);
|
|
171
|
+
if (!bottomPixel || !topPixel || bottomPixel[1] === undefined || topPixel[1] === undefined) return null;
|
|
172
|
+
// Y increases downward in pixels; min/max normalizes the mapping for negative bar values.
|
|
173
|
+
return {
|
|
174
|
+
top: Math.min(topPixel[1], bottomPixel[1]),
|
|
175
|
+
bottom: Math.max(topPixel[1], bottomPixel[1])
|
|
176
|
+
};
|
|
177
|
+
} catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
85
181
|
|
|
86
182
|
//# sourceMappingURL=utils.js.map
|
|
@@ -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 { Theme } from '@mui/material';\nimport {\n CursorCoordinates,\n CursorData,\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 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 + tooltipHeight > containerBottom) {\n y = Math.max(containerBottom - tooltipHeight - cursorPaddingY, TOOLTIP_PADDING / 2);\n }\n } else {\n // Ensure tooltip does not go out of the screen on the bottom\n if (y + tooltipHeight > window.innerHeight + window.scrollY) {\n y = Math.max(window.innerHeight + window.scrollY - tooltipHeight - cursorPaddingY, TOOLTIP_PADDING / 2);\n }\n }\n\n // Ensure tooltip does not go out of the screen on the right\n if (x + tooltipWidth > window.innerWidth) {\n x = mousePos.page.x - tooltipWidth - 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 transition: 'all 0.1s ease-out',\n // Ensure pinned tooltip shows behind edit panel drawer and sticky header\n zIndex: pinnedPos !== null ? 'auto' : theme.zIndex.tooltip,\n overflow: 'hidden',\n '&:hover': {\n overflowY: 'auto',\n },\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","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"],"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,SAGEA,iBAAiB,EACjBC,kBAAkB,EAClBC,iBAAiB,EACjBC,yBAAyB,EACzBC,eAAe,QACV,kBAAkB;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,IAAII,IAAIT,SAASU,IAAI,CAACD,CAAC,GAAGH,gBAAgB,sCAAsC;IAChF,IAAIK,IAAIX,SAASU,IAAI,CAACC,CAAC,GAAGJ;IAE1B,+EAA+E;IAC/E,IAAIH,kBAAkB;QACpB,MAAMQ,gBAAgBR,iBAAiBS,qBAAqB;QAC5DJ,IAAIA,IAAIG,cAAcE,IAAI,GAAGV,iBAAiBW,UAAU;QACxDJ,IAAIA,IAAIC,cAAcI,GAAG,GAAGZ,iBAAiBa,SAAS;QAEtD,2DAA2D;QAC3D,MAAMC,kBAAkB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,WAAW;QACb;IACF;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 { Theme } from '@mui/material';\nimport { ECharts as EChartsInstance } from 'echarts/core';\nimport { BarSeriesOption, LineSeriesOption } from 'echarts/charts';\nimport { TimeChartSeriesMapping } from '../model';\nimport {\n CursorCoordinates,\n CursorData,\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;AAMjC,SAGEA,iBAAiB,EACjBC,kBAAkB,EAClBC,iBAAiB,EACjBC,yBAAyB,EACzBC,eAAe,QACV,kBAAkB;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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BC,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"}
|
package/dist/cjs/EChart/index.js
CHANGED
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
17
|
_export_star(require("./EChart"), exports);
|
|
18
|
+
_export_star(require("./timezone-formatter"), exports);
|
|
18
19
|
function _export_star(from, to) {
|
|
19
20
|
Object.keys(from).forEach(function(k) {
|
|
20
21
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "createTimezoneAwareAxisFormatter", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return createTimezoneAwareAxisFormatter;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _components = require("@perses-dev/components");
|
|
24
|
+
const DAY_MS = 1000 * 60 * 60 * 24;
|
|
25
|
+
const MONTH_MS = DAY_MS * 30;
|
|
26
|
+
const YEAR_MS = DAY_MS * 365;
|
|
27
|
+
function createTimezoneAwareAxisFormatter(rangeMs, timeZone) {
|
|
28
|
+
return function(value) {
|
|
29
|
+
const timeStamp = new Date(Number(value));
|
|
30
|
+
// more than 5 years
|
|
31
|
+
if (rangeMs > YEAR_MS * 5) {
|
|
32
|
+
return (0, _components.formatWithTimeZone)(timeStamp, 'yyyy', timeZone);
|
|
33
|
+
}
|
|
34
|
+
// more than 6 months
|
|
35
|
+
if (rangeMs > MONTH_MS * 6) {
|
|
36
|
+
return (0, _components.formatWithTimeZone)(timeStamp, 'MMM yyyy', timeZone);
|
|
37
|
+
}
|
|
38
|
+
// more than 10 days
|
|
39
|
+
if (rangeMs > DAY_MS * 10) {
|
|
40
|
+
return (0, _components.formatWithTimeZone)(timeStamp, 'dd.MM', timeZone);
|
|
41
|
+
}
|
|
42
|
+
// more than 2 days
|
|
43
|
+
if (rangeMs > DAY_MS * 2) {
|
|
44
|
+
return (0, _components.formatWithTimeZone)(timeStamp, 'dd.MM HH:mm', timeZone);
|
|
45
|
+
}
|
|
46
|
+
// less or equal 2 days
|
|
47
|
+
return (0, _components.formatWithTimeZone)(timeStamp, 'HH:mm', timeZone);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -37,18 +37,37 @@ function _interop_require_default(obj) {
|
|
|
37
37
|
const TimeChartTooltip = /*#__PURE__*/ (0, _react.memo)(function TimeChartTooltip({ containerId, chartRef, data, seriesMapping, enablePinning = true, wrapLabels, format, seriesFormatMap, onUnpinClick, pinnedPos }) {
|
|
38
38
|
const [showAllSeries, setShowAllSeries] = (0, _react.useState)(false);
|
|
39
39
|
const transform = (0, _react.useRef)();
|
|
40
|
+
const tooltipElementRef = (0, _react.useRef)(null);
|
|
40
41
|
const mousePos = (0, _tooltipmodel.useMousePosition)();
|
|
41
42
|
const { height, width, ref: tooltipRef } = (0, _useresizeobserver.default)();
|
|
42
43
|
const isTooltipPinned = pinnedPos !== null && enablePinning;
|
|
44
|
+
// Stable callback — prevents the ResizeObserver from disconnecting/reconnecting on every render.
|
|
45
|
+
const setTooltipRef = (0, _react.useCallback)((node)=>{
|
|
46
|
+
tooltipElementRef.current = node;
|
|
47
|
+
tooltipRef(node);
|
|
48
|
+
}, [
|
|
49
|
+
tooltipRef
|
|
50
|
+
]);
|
|
51
|
+
const containerElement = containerId ? document.querySelector(containerId) : undefined;
|
|
52
|
+
// Synchronously reposition after every render to prevent one-frame viewport overflow.
|
|
53
|
+
(0, _react.useLayoutEffect)(()=>{
|
|
54
|
+
if (mousePos === null) return;
|
|
55
|
+
const node = tooltipElementRef.current;
|
|
56
|
+
if (!node) return;
|
|
57
|
+
const rect = node.getBoundingClientRect();
|
|
58
|
+
if (rect.height === 0 || rect.width === 0) return;
|
|
59
|
+
const nextTransform = (0, _utils.assembleTransform)(mousePos, pinnedPos, rect.height, rect.width, containerElement);
|
|
60
|
+
if (nextTransform && nextTransform !== transform.current) {
|
|
61
|
+
transform.current = nextTransform;
|
|
62
|
+
node.style.transform = nextTransform;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
43
65
|
if (mousePos === null || mousePos.target === null || data === null) return null;
|
|
44
|
-
// Ensure user is hovering over a chart before checking for nearby series.
|
|
45
66
|
if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS') return null;
|
|
46
67
|
const chart = chartRef.current;
|
|
47
|
-
|
|
48
|
-
// if tooltip is attached to a container, set max height to the height of the container so tooltip does not get cut off
|
|
68
|
+
// Cap height to container so the tooltip is not cut off.
|
|
49
69
|
const maxHeight = containerElement ? containerElement.getBoundingClientRect().height : undefined;
|
|
50
70
|
transform.current = (0, _utils.assembleTransform)(mousePos, pinnedPos, height ?? 0, width ?? 0, containerElement);
|
|
51
|
-
// Get series nearby the cursor and pass into tooltip content children.
|
|
52
71
|
const nearbySeries = (0, _nearbyseries.getNearbySeriesData)({
|
|
53
72
|
mousePos,
|
|
54
73
|
data,
|
|
@@ -66,7 +85,7 @@ const TimeChartTooltip = /*#__PURE__*/ (0, _react.memo)(function TimeChartToolti
|
|
|
66
85
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Portal, {
|
|
67
86
|
container: containerElement,
|
|
68
87
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
69
|
-
ref:
|
|
88
|
+
ref: setTooltipRef,
|
|
70
89
|
sx: (theme)=>(0, _utils.getTooltipStyles)(theme, pinnedPos, maxHeight),
|
|
71
90
|
style: {
|
|
72
91
|
transform: transform.current
|
|
@@ -22,6 +22,7 @@ _export_star(require("./TooltipContent"), exports);
|
|
|
22
22
|
_export_star(require("./TooltipHeader"), exports);
|
|
23
23
|
_export_star(require("./nearby-series"), exports);
|
|
24
24
|
_export_star(require("./tooltip-model"), exports);
|
|
25
|
+
_export_star(require("./types"), exports);
|
|
25
26
|
_export_star(require("./utils"), exports);
|
|
26
27
|
function _export_star(from, to) {
|
|
27
28
|
Object.keys(from).forEach(function(k) {
|