@moderneinc/react-charts 1.4.0 → 1.5.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.
@@ -118,4 +118,11 @@ export type D3StackedAreaChartProps = {
118
118
  * @default 1
119
119
  */
120
120
  tooltipScale?: number;
121
+ /**
122
+ * Render tooltip in a portal to escape container overflow constraints.
123
+ * When true, tooltip renders in document.body and positions relative to viewport.
124
+ * Use this when the chart is placed inside a container with overflow:hidden.
125
+ * @default false
126
+ */
127
+ usePortalTooltip?: boolean;
121
128
  };
@@ -86,6 +86,21 @@ export type D3StackedBarChartProps = {
86
86
  * @default 1
87
87
  */
88
88
  tooltipScale?: number;
89
+ /**
90
+ * Render tooltip in a portal to escape container overflow constraints.
91
+ * When true, tooltip renders in document.body and positions relative to viewport.
92
+ * Use this when the chart is placed inside a container with overflow:hidden.
93
+ * @default false
94
+ */
95
+ usePortalTooltip?: boolean;
96
+ /**
97
+ * Where to anchor the tooltip relative to the crosshair.
98
+ * - 'cursor': Position near the cursor/crosshair intersection (default)
99
+ * - 'top': Position at the top of the chart, centered on the crosshair X
100
+ * - 'bottom-corner': Position at lower-left or lower-right of crosshair intersection
101
+ * @default 'cursor'
102
+ */
103
+ tooltipAnchor?: 'cursor' | 'top' | 'bottom-corner';
89
104
  };
90
105
  export type TooltipData = {
91
106
  visible: boolean;
@@ -0,0 +1,15 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { ChartTooltipProps } from './chart-tooltip.types';
3
+ /**
4
+ * Chart tooltip component that supports both inline and portal rendering modes.
5
+ *
6
+ * Coordinates are provided in SVG viewBox space and transformed to pixel coordinates
7
+ * based on the actual rendered size of the container.
8
+ *
9
+ * When `usePortal` is false (default), the tooltip renders with `position: absolute`
10
+ * relative to the chart container - this can be clipped by parent overflow settings.
11
+ *
12
+ * When `usePortal` is true, the tooltip renders in a React Portal (document.body)
13
+ * with `position: fixed`, escaping any container overflow constraints.
14
+ */
15
+ export declare const ChartTooltip: FunctionComponent<ChartTooltipProps>;
@@ -0,0 +1,62 @@
1
+ import { RefObject } from 'react';
2
+ export type ChartTooltipProps = {
3
+ /**
4
+ * Whether the tooltip is visible
5
+ */
6
+ visible: boolean;
7
+ /**
8
+ * X position in SVG viewBox coordinates
9
+ */
10
+ x: number;
11
+ /**
12
+ * Y position in SVG viewBox coordinates
13
+ */
14
+ y: number;
15
+ /**
16
+ * Reference to the chart container element for dimension calculations
17
+ */
18
+ containerRef: RefObject<HTMLElement | null>;
19
+ /**
20
+ * SVG viewBox width - required to transform viewBox coordinates to pixel coordinates
21
+ */
22
+ viewBoxWidth: number;
23
+ /**
24
+ * SVG viewBox height - required to transform viewBox coordinates to pixel coordinates
25
+ */
26
+ viewBoxHeight: number;
27
+ /**
28
+ * Render tooltip in a portal to escape container overflow constraints.
29
+ * When true, tooltip renders in document.body and positions relative to viewport.
30
+ * @default false
31
+ */
32
+ usePortal?: boolean;
33
+ /**
34
+ * Scale factor for tooltip size. Affects padding and base styles.
35
+ * @default 1
36
+ */
37
+ scale?: number;
38
+ /**
39
+ * Width threshold in viewBox coordinates for horizontal flip.
40
+ * When x exceeds this value, tooltip flips to the left side of the cursor.
41
+ * Only applies when anchorPosition is 'cursor'.
42
+ */
43
+ flipThreshold?: number;
44
+ /**
45
+ * Where to anchor the tooltip relative to the crosshair.
46
+ * - 'cursor': Position near the cursor/crosshair intersection (default)
47
+ * - 'top': Position at the top of the chart, centered on the crosshair X
48
+ * - 'bottom-corner': Position at lower-left or lower-right of crosshair intersection
49
+ * @default 'cursor'
50
+ */
51
+ anchorPosition?: 'cursor' | 'top' | 'bottom-corner';
52
+ /**
53
+ * Top margin of the chart area in viewBox coordinates.
54
+ * Used when anchorPosition is 'top' to position tooltip correctly.
55
+ * @default 20
56
+ */
57
+ chartTopMargin?: number;
58
+ /**
59
+ * Tooltip content
60
+ */
61
+ children: React.ReactNode;
62
+ };