@moderneinc/react-charts 1.3.0 → 1.4.0-next.3ca97d

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.
@@ -126,4 +126,20 @@ export type ChronoChartProps = {
126
126
  * @default '#69b3a2'
127
127
  */
128
128
  brushColor?: string;
129
+ /**
130
+ * Show crosshair cursor on hover (historical mode only).
131
+ * Crosshairs are hidden during morphing transitions.
132
+ * @default true
133
+ */
134
+ showCrosshair?: boolean;
135
+ /**
136
+ * Color for crosshair lines.
137
+ * @default '#666'
138
+ */
139
+ crosshairColor?: string;
140
+ /**
141
+ * Dash array pattern for crosshair lines.
142
+ * @default '4,4'
143
+ */
144
+ crosshairDashArray?: string;
129
145
  };
@@ -2,6 +2,14 @@
2
2
  * D3-based stacked area chart types
3
3
  * Built for seamless morphing with parliament chart
4
4
  */
5
+ export type HoveredAreaData = {
6
+ timestamp: number;
7
+ category: {
8
+ label: string;
9
+ color: string;
10
+ };
11
+ value: number;
12
+ };
5
13
  export type D3StackedAreaDataPoint = {
6
14
  timestamp: number;
7
15
  [category: string]: number;
@@ -78,6 +86,18 @@ export type D3StackedAreaChartProps = {
78
86
  * @default '#69b3a2'
79
87
  */
80
88
  brushColor?: string;
89
+ /** Show crosshair cursor on hover */
90
+ showCrosshair?: boolean;
91
+ /**
92
+ * Color for crosshair lines
93
+ * @default '#666'
94
+ */
95
+ crosshairColor?: string;
96
+ /**
97
+ * Dash array pattern for crosshair lines
98
+ * @default '4,4'
99
+ */
100
+ crosshairDashArray?: string;
81
101
  /** Mode for morphing animation */
82
102
  morphMode?: 'area' | 'parliament' | 'morphing';
83
103
  /** Parliament layout data (for morphing) */
@@ -92,4 +112,17 @@ export type D3StackedAreaChartProps = {
92
112
  };
93
113
  /** Morph progress (0 = area, 1 = parliament) */
94
114
  morphProgress?: number;
115
+ /**
116
+ * Scale factor for tooltip size. Use values like 0.8 for 80% size, 1.2 for 120% size.
117
+ * Affects font sizes, padding, spacing, and color bar width proportionally.
118
+ * @default 1
119
+ */
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;
95
128
  };
@@ -1,5 +1,5 @@
1
1
  import { RefObject } from 'react';
2
- import { D3StackedAreaCategory, D3StackedAreaDataPoint } from '../d3-stacked-area-chart.types';
2
+ import { D3StackedAreaCategory, D3StackedAreaDataPoint, HoveredAreaData } from '../d3-stacked-area-chart.types';
3
3
  type UseD3StackedAreaProps = {
4
4
  containerRef: RefObject<SVGSVGElement>;
5
5
  data: D3StackedAreaDataPoint[];
@@ -30,6 +30,14 @@ type UseD3StackedAreaProps = {
30
30
  markerVisibilityMode?: 'always' | 'hover';
31
31
  onMarkerHoverChange?: (isHovering: boolean) => void;
32
32
  brushColor?: string;
33
+ showCrosshair?: boolean;
34
+ crosshairColor?: string;
35
+ crosshairDashArray?: string;
36
+ onHoveredAreaChange?: (data: HoveredAreaData | null) => void;
37
+ onCrosshairMove?: (position: {
38
+ x: number;
39
+ y: number;
40
+ } | null) => void;
33
41
  };
34
- export declare const useD3StackedArea: ({ containerRef, data, categories, width, height, margin, timeRange, showGrid, showXAxis, showYAxis, enableBrush, zoomToSelection, onTimeRangeChange, formatDate, formatValue, markers, markerVisibilityMode, onMarkerHoverChange, brushColor }: UseD3StackedAreaProps) => void;
42
+ export declare const useD3StackedArea: ({ containerRef, data, categories, width, height, margin, timeRange, showGrid, showXAxis, showYAxis, enableBrush, zoomToSelection, onTimeRangeChange, formatDate, formatValue, markers, markerVisibilityMode, onMarkerHoverChange, brushColor, showCrosshair, onHoveredAreaChange, onCrosshairMove }: UseD3StackedAreaProps) => void;
35
43
  export {};
@@ -0,0 +1,7 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { D3StackedBarChartProps } from './d3-stacked-bar-chart.types';
3
+ /**
4
+ * D3-based stacked bar chart component
5
+ * Timeline-based bar chart with crosshair cursor and brush selection
6
+ */
7
+ export declare const D3StackedBarChart: FunctionComponent<D3StackedBarChartProps>;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * D3-based stacked bar chart types
3
+ * Timeline-based bar chart with crosshair cursor and brush selection
4
+ */
5
+ export type D3StackedBarDataPoint = {
6
+ timestamp: number;
7
+ [category: string]: number;
8
+ };
9
+ export type D3StackedBarCategory = {
10
+ dataKey: string;
11
+ label: string;
12
+ color: string;
13
+ fillOpacity?: number;
14
+ };
15
+ export type D3StackedBarChartProps = {
16
+ /** Array of data points sorted by timestamp */
17
+ data: D3StackedBarDataPoint[];
18
+ /** Array of category definitions */
19
+ categories: D3StackedBarCategory[];
20
+ /** Chart title */
21
+ title?: string;
22
+ /** Chart subtitle */
23
+ subtitle?: string;
24
+ /** Show header (title and subtitle) */
25
+ showHeader?: boolean;
26
+ /** Show legend */
27
+ showLegend?: boolean;
28
+ /** Show tooltips on hover */
29
+ showTooltip?: boolean;
30
+ /** Chart dimensions */
31
+ width?: number;
32
+ height?: number;
33
+ /** Margins for axes */
34
+ margin?: {
35
+ top: number;
36
+ right: number;
37
+ bottom: number;
38
+ left: number;
39
+ };
40
+ /** Time range for x-axis */
41
+ timeRange?: [number, number];
42
+ /** Show grid lines */
43
+ showGrid?: boolean;
44
+ /** Show axes (deprecated: use showXAxis and showYAxis instead) */
45
+ showAxes?: boolean;
46
+ /** Show X-axis */
47
+ showXAxis?: boolean;
48
+ /** Show Y-axis */
49
+ showYAxis?: boolean;
50
+ /** Format date for axis and tooltip */
51
+ formatDate?: (timestamp: number) => string;
52
+ /** Format value for axis and tooltip */
53
+ formatValue?: (value: number) => string;
54
+ /** Callback when time range changes */
55
+ onTimeRangeChange?: (range: [number, number]) => void;
56
+ /** Enable brush selection */
57
+ enableBrush?: boolean;
58
+ /** Zoom to selection - when true, brush clears after selection */
59
+ zoomToSelection?: boolean;
60
+ /**
61
+ * Color for brush selection overlay.
62
+ * @default '#69b3a2'
63
+ */
64
+ brushColor?: string;
65
+ /** Show crosshair cursor on hover */
66
+ showCrosshair?: boolean;
67
+ /**
68
+ * Color for crosshair lines
69
+ * @default '#666'
70
+ */
71
+ crosshairColor?: string;
72
+ /**
73
+ * Dash array pattern for crosshair lines
74
+ * @default '4,4'
75
+ */
76
+ crosshairDashArray?: string;
77
+ /**
78
+ * Minimum bar width in pixels. Overrides the automatic minimum width behavior.
79
+ * When not specified, the chart auto-applies a 2px minimum for time ranges > 3 months.
80
+ * Set to 0 to disable minimum width entirely.
81
+ */
82
+ minBarWidth?: number;
83
+ /**
84
+ * Scale factor for tooltip size. Use values like 0.8 for 80% size, 1.2 for 120% size.
85
+ * Affects font sizes, padding, spacing, and color bar width proportionally.
86
+ * @default 1
87
+ */
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';
104
+ };
105
+ export type TooltipData = {
106
+ visible: boolean;
107
+ x: number;
108
+ y: number;
109
+ category: {
110
+ label: string;
111
+ color: string;
112
+ };
113
+ value: number;
114
+ startTime: number;
115
+ endTime: number;
116
+ };
@@ -0,0 +1,36 @@
1
+ import { RefObject } from 'react';
2
+ import { D3StackedBarCategory, D3StackedBarDataPoint, TooltipData } from '../d3-stacked-bar-chart.types';
3
+ type UseD3StackedBarProps = {
4
+ containerRef: RefObject<SVGSVGElement | null>;
5
+ data: D3StackedBarDataPoint[];
6
+ categories: D3StackedBarCategory[];
7
+ width: number;
8
+ height: number;
9
+ margin: {
10
+ top: number;
11
+ right: number;
12
+ bottom: number;
13
+ left: number;
14
+ };
15
+ timeRange?: [number, number];
16
+ showGrid?: boolean;
17
+ showXAxis?: boolean;
18
+ showYAxis?: boolean;
19
+ enableBrush?: boolean;
20
+ zoomToSelection?: boolean;
21
+ onTimeRangeChange?: (range: [number, number]) => void;
22
+ formatDate?: (timestamp: number) => string;
23
+ formatValue?: (value: number) => string;
24
+ showCrosshair?: boolean;
25
+ crosshairColor?: string;
26
+ crosshairDashArray?: string;
27
+ brushColor?: string;
28
+ onTooltipChange?: (tooltip: TooltipData | null) => void;
29
+ minBarWidth?: number;
30
+ onCrosshairPositionChange?: (position: {
31
+ x: number;
32
+ y: number;
33
+ } | null) => void;
34
+ };
35
+ export declare const useD3StackedBar: ({ containerRef, data, categories, width, height, margin, timeRange, showGrid, showXAxis, showYAxis, enableBrush, zoomToSelection, onTimeRangeChange, formatDate, formatValue, showCrosshair, brushColor, onTooltipChange, minBarWidth, onCrosshairPositionChange }: UseD3StackedBarProps) => void;
36
+ export {};
@@ -52,8 +52,13 @@ type UseMorphChartProps = {
52
52
  timelineHeight?: number;
53
53
  timelineOffset?: number;
54
54
  brushColor?: string;
55
+ showCrosshair?: boolean;
56
+ onCrosshairMove?: (position: {
57
+ x: number;
58
+ y: number;
59
+ } | null) => void;
55
60
  };
56
- export declare const useMorphChart: ({ containerRef, data, categories, mode, width, height, margin, timeRange, showGrid, showAxes, axisLabelColor, axisLabelSize, formatDate, formatValue, markers, arcAngle, parliamentRadius, seatSize, animationDuration, onMorphComplete, onAnimationStateChange, onTimelineReady, onAnimationProgress, onHoveredDataChange, hoveredCategory: externalHoveredCategory, maxSeats, parliamentTimestamp, enableBrush, onTimeRangeChange, minAllowedTime: minAllowedTimeConstraint, maxAllowedTime: maxAllowedTimeConstraint, showScaleIndicator, reposPerSeat, timelineEvents, showTimeline, timelineHeight, timelineOffset, brushColor }: UseMorphChartProps) => {
61
+ export declare const useMorphChart: ({ containerRef, data, categories, mode, width, height, margin, timeRange, showGrid, showAxes, axisLabelColor, axisLabelSize, formatDate, formatValue, markers, arcAngle, parliamentRadius, seatSize, animationDuration, onMorphComplete, onAnimationStateChange, onTimelineReady, onAnimationProgress, onHoveredDataChange, hoveredCategory: externalHoveredCategory, maxSeats, parliamentTimestamp, enableBrush, onTimeRangeChange, minAllowedTime: minAllowedTimeConstraint, maxAllowedTime: maxAllowedTimeConstraint, showScaleIndicator, reposPerSeat, timelineEvents, showTimeline, timelineHeight, timelineOffset, brushColor, showCrosshair, onCrosshairMove }: UseMorphChartProps) => {
57
62
  isMorphing: boolean;
58
63
  currentMode: MorphMode;
59
64
  hoveredCategory: string | null;
@@ -127,6 +127,22 @@ export type MorphChartProps = {
127
127
  * @default '#69b3a2'
128
128
  */
129
129
  brushColor?: string;
130
+ /**
131
+ * Show crosshair cursor on hover (area mode only).
132
+ * Crosshairs are hidden during morphing transitions.
133
+ * @default false
134
+ */
135
+ showCrosshair?: boolean;
136
+ /**
137
+ * Color for crosshair lines.
138
+ * @default '#666'
139
+ */
140
+ crosshairColor?: string;
141
+ /**
142
+ * Dash array pattern for crosshair lines.
143
+ * @default '4,4'
144
+ */
145
+ crosshairDashArray?: string;
130
146
  };
131
147
  /**
132
148
  * Seat position in parliament layout
@@ -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
+ };