@moderneinc/react-charts 1.2.0 → 1.3.0-next.bc5134
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/components/chrono-chart/chrono-chart.component.d.ts +10 -0
- package/dist/components/chrono-chart/chrono-chart.types.d.ts +129 -0
- package/dist/components/chrono-chart/components/category-table.component.d.ts +13 -0
- package/dist/components/chrono-chart/components/category-table.types.d.ts +42 -0
- package/dist/components/chrono-chart/utils/data-transformer.d.ts +41 -0
- package/dist/components/d3-stacked-area-chart/d3-stacked-area-chart.component.d.ts +7 -0
- package/dist/components/d3-stacked-area-chart/d3-stacked-area-chart.types.d.ts +115 -0
- package/dist/components/d3-stacked-area-chart/hooks/use-d3-stacked-area.hook.d.ts +43 -0
- package/dist/components/d3-stacked-bar-chart/d3-stacked-bar-chart.component.d.ts +7 -0
- package/dist/components/d3-stacked-bar-chart/d3-stacked-bar-chart.types.d.ts +89 -0
- package/dist/components/d3-stacked-bar-chart/hooks/use-d3-stacked-bar.hook.d.ts +31 -0
- package/dist/components/morph-chart/hooks/shared/computations.d.ts +29 -0
- package/dist/components/morph-chart/hooks/shared/types.d.ts +24 -0
- package/dist/components/morph-chart/hooks/use-morph-chart.hook.d.ts +90 -0
- package/dist/components/morph-chart/morph-chart.component.d.ts +14 -0
- package/dist/components/morph-chart/morph-chart.types.d.ts +175 -0
- package/dist/components/morph-chart/utils/animation-constants.d.ts +23 -0
- package/dist/components/morph-chart/utils/area-renderer.d.ts +24 -0
- package/dist/components/morph-chart/utils/bar-renderer.d.ts +19 -0
- package/dist/components/morph-chart/utils/gsap-orchestrator.d.ts +291 -0
- package/dist/components/morph-chart/utils/parliament-renderer.d.ts +23 -0
- package/dist/components/morph-chart/utils/parliament-seat-extractor.d.ts +33 -0
- package/dist/components/morph-chart/utils/position-mapper.d.ts +48 -0
- package/dist/components/morph-chart/utils/svg-patterns.d.ts +19 -0
- package/dist/components/parliament-chart/hooks/use-parliament-chart.hook.d.ts +5 -1
- package/dist/components/parliament-chart/parliament-chart.types.d.ts +5 -0
- package/dist/components/parliament-chart/utils/parliament-animation.d.ts +13 -0
- package/dist/components/stacked-area-with-timeline/hooks/use-stacked-area-with-timeline.hook.d.ts +53 -0
- package/dist/components/stacked-area-with-timeline/stacked-area-with-timeline.component.d.ts +3 -0
- package/dist/components/stacked-area-with-timeline/stacked-area-with-timeline.types.d.ts +97 -0
- package/dist/components/stacked-area-with-timeline/utils/render-timeline-track.d.ts +46 -0
- package/dist/components/timeline-chart/timeline-chart.types.d.ts +44 -0
- package/dist/index.cjs +49 -11
- package/dist/index.d.ts +13 -1
- package/dist/index.js +14165 -3520
- package/dist/theme/chart-palettes.d.ts +59 -0
- package/dist/theme/default-colors.d.ts +8 -4
- package/dist/theme/timeline-defaults.d.ts +25 -1
- package/package.json +28 -16
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
import { MorphChartProps } from './morph-chart.types';
|
|
3
|
+
/**
|
|
4
|
+
* MorphChart - Seamlessly morphs between parliament and stacked area visualizations
|
|
5
|
+
*
|
|
6
|
+
* This component uses D3 to create smooth transitions between a parliament chart
|
|
7
|
+
* (point-in-time view) and a stacked area chart (historical view).
|
|
8
|
+
*
|
|
9
|
+
* Key insight: The parliament chart represents the rightmost edge (latest timestamp)
|
|
10
|
+
* of the stacked area chart. During morphing:
|
|
11
|
+
* - Parliament → Stacked Area: Seats slide to the right edge, then areas expand leftward
|
|
12
|
+
* - Stacked Area → Parliament: Areas collapse to the right edge, then seats expand to parliament layout
|
|
13
|
+
*/
|
|
14
|
+
export declare const MorphChart: FunctionComponent<MorphChartProps>;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { D3StackedAreaCategory } from '../d3-stacked-area-chart/d3-stacked-area-chart.types';
|
|
2
|
+
export type MorphMode = 'area' | 'parliament' | 'morphing';
|
|
3
|
+
export type MorphChartDataPoint = {
|
|
4
|
+
timestamp: number;
|
|
5
|
+
values: Record<string, number>;
|
|
6
|
+
};
|
|
7
|
+
export type MorphChartCategory = D3StackedAreaCategory & {
|
|
8
|
+
/** Parliament chart mapping (for special categories) */
|
|
9
|
+
parliamentMapping?: {
|
|
10
|
+
isSpecialCategory?: boolean;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Hovered data state for tooltips and interactions
|
|
15
|
+
*/
|
|
16
|
+
export type HoveredData = {
|
|
17
|
+
label: string;
|
|
18
|
+
value: number;
|
|
19
|
+
color: string;
|
|
20
|
+
} | null;
|
|
21
|
+
export type MorphChartProps = {
|
|
22
|
+
/** Time series data for area chart */
|
|
23
|
+
data: MorphChartDataPoint[];
|
|
24
|
+
/** Category definitions */
|
|
25
|
+
categories: MorphChartCategory[];
|
|
26
|
+
/** Current visualization mode */
|
|
27
|
+
mode: 'parliament' | 'stacked-area';
|
|
28
|
+
/** Morph progress: 0 = fully area, 1 = fully parliament */
|
|
29
|
+
morphProgress?: number;
|
|
30
|
+
/** Chart dimensions */
|
|
31
|
+
width?: number;
|
|
32
|
+
height?: number;
|
|
33
|
+
/** Margins */
|
|
34
|
+
margin?: {
|
|
35
|
+
top: number;
|
|
36
|
+
right: number;
|
|
37
|
+
bottom: number;
|
|
38
|
+
left: number;
|
|
39
|
+
};
|
|
40
|
+
/** Time range for area chart */
|
|
41
|
+
timeRange?: [number, number];
|
|
42
|
+
/** Show grid lines */
|
|
43
|
+
showGrid?: boolean;
|
|
44
|
+
/** Show axes */
|
|
45
|
+
showAxes?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Color for axis labels (dates on x-axis, values on y-axis).
|
|
48
|
+
* @default undefined (inherits from SVG default, typically black)
|
|
49
|
+
*/
|
|
50
|
+
axisLabelColor?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Font size for axis labels in pixels.
|
|
53
|
+
* Increase this value when displaying charts at smaller sizes (e.g., in dashboards).
|
|
54
|
+
* @default 14
|
|
55
|
+
*/
|
|
56
|
+
axisLabelSize?: number;
|
|
57
|
+
/** Enable brush selection */
|
|
58
|
+
enableBrush?: boolean;
|
|
59
|
+
/** Callback when time range changes */
|
|
60
|
+
onTimeRangeChange?: (range: [number, number]) => void;
|
|
61
|
+
/** Minimum allowed timestamp for time range selection (constrains brush selection) */
|
|
62
|
+
minAllowedTime?: number;
|
|
63
|
+
/** Maximum allowed timestamp for time range selection (constrains brush selection) */
|
|
64
|
+
maxAllowedTime?: number;
|
|
65
|
+
/** Format date for axis */
|
|
66
|
+
formatDate?: (timestamp: number) => string;
|
|
67
|
+
/** Format value for axis */
|
|
68
|
+
formatValue?: (value: number) => string;
|
|
69
|
+
/** Event markers */
|
|
70
|
+
markers?: Array<{
|
|
71
|
+
timestamp: number;
|
|
72
|
+
label?: string;
|
|
73
|
+
color?: string;
|
|
74
|
+
}>;
|
|
75
|
+
/** Animation duration in milliseconds */
|
|
76
|
+
animationDuration?: number;
|
|
77
|
+
/** Callback when morphing animation completes */
|
|
78
|
+
onMorphComplete?: () => void;
|
|
79
|
+
/** Callback when animation state changes */
|
|
80
|
+
onAnimationStateChange?: (isAnimating: boolean) => void;
|
|
81
|
+
/** Callback when GSAP timeline is ready for control */
|
|
82
|
+
onTimelineReady?: (timeline: unknown) => void;
|
|
83
|
+
/** Callback for animation progress updates */
|
|
84
|
+
onAnimationProgress?: (progress: number, stage: string) => void;
|
|
85
|
+
/** Parliament arc angle (degrees) */
|
|
86
|
+
arcAngle?: number;
|
|
87
|
+
/** Parliament radius */
|
|
88
|
+
parliamentRadius?: number;
|
|
89
|
+
/** Parliament seat size */
|
|
90
|
+
seatSize?: number;
|
|
91
|
+
/** Use enhanced parliament rendering */
|
|
92
|
+
useEnhancedParliament?: boolean;
|
|
93
|
+
/** Callback when hover state changes */
|
|
94
|
+
onHoveredDataChange?: (data: HoveredData) => void;
|
|
95
|
+
/** Currently hovered category (for external control of highlighting) */
|
|
96
|
+
hoveredCategory?: string | null;
|
|
97
|
+
/** Max seats before scaling (default: 500) */
|
|
98
|
+
maxSeats?: number;
|
|
99
|
+
/** Show tooltip overlay (default: true) */
|
|
100
|
+
showTooltip?: boolean;
|
|
101
|
+
/** Show category summary table (default: false for MorphChart) */
|
|
102
|
+
showTable?: boolean;
|
|
103
|
+
/** Show scaled indicator when seats > maxSeats (default: true) */
|
|
104
|
+
showScaledIndicator?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Explicit timestamp that the parliament represents.
|
|
107
|
+
* If provided, this overrides automatic timestamp detection and ensures
|
|
108
|
+
* the bar slides to the correct position on the timeline during animation.
|
|
109
|
+
* If not provided, defaults to the rightmost (most recent) timestamp.
|
|
110
|
+
*/
|
|
111
|
+
parliamentTimestamp?: number;
|
|
112
|
+
/** Timeline events to display below the x-axis (area mode only) */
|
|
113
|
+
timelineEvents?: Array<{
|
|
114
|
+
timestamp: number;
|
|
115
|
+
eventName: string;
|
|
116
|
+
color?: string;
|
|
117
|
+
}>;
|
|
118
|
+
/** Show timeline track (default: false) */
|
|
119
|
+
showTimeline?: boolean;
|
|
120
|
+
/** Timeline track height in pixels (default: 40) */
|
|
121
|
+
timelineHeight?: number;
|
|
122
|
+
/** Space between x-axis and timeline in pixels (default: 35) */
|
|
123
|
+
timelineOffset?: number;
|
|
124
|
+
/**
|
|
125
|
+
* Color for brush selection overlay.
|
|
126
|
+
* Used for both the selection area and drag handles.
|
|
127
|
+
* @default '#69b3a2'
|
|
128
|
+
*/
|
|
129
|
+
brushColor?: string;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Seat position in parliament layout
|
|
133
|
+
*/
|
|
134
|
+
export type SeatPosition = {
|
|
135
|
+
x: number;
|
|
136
|
+
y: number;
|
|
137
|
+
category: string;
|
|
138
|
+
categoryIndex: number;
|
|
139
|
+
seatIndex: number;
|
|
140
|
+
ring: number;
|
|
141
|
+
angle: number;
|
|
142
|
+
radius: number;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Area chart point in cartesian space
|
|
146
|
+
*/
|
|
147
|
+
export type AreaPoint = {
|
|
148
|
+
x: number;
|
|
149
|
+
y: number;
|
|
150
|
+
y0: number;
|
|
151
|
+
y1: number;
|
|
152
|
+
category: string;
|
|
153
|
+
timestamp: number;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Parliament layout metadata
|
|
157
|
+
*/
|
|
158
|
+
export type ParliamentLayout = {
|
|
159
|
+
arcAngle: number;
|
|
160
|
+
radius: number;
|
|
161
|
+
innerRadius: number;
|
|
162
|
+
centerX: number;
|
|
163
|
+
centerY: number;
|
|
164
|
+
seatSize: number;
|
|
165
|
+
seats: SeatPosition[];
|
|
166
|
+
totalSeats: number;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Area chart layout metadata
|
|
170
|
+
*/
|
|
171
|
+
export type AreaLayout = {
|
|
172
|
+
chartWidth: number;
|
|
173
|
+
chartHeight: number;
|
|
174
|
+
points: AreaPoint[];
|
|
175
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animation constants for parliament to stacked area morphing
|
|
3
|
+
* Centralized configuration for timing, easing, and stage proportions
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* GSAP easing functions for smooth transitions
|
|
7
|
+
* Uses GSAP's power easing for professional motion
|
|
8
|
+
*/
|
|
9
|
+
export declare const EASING: {
|
|
10
|
+
/** Smooth acceleration and deceleration - used for transformations */
|
|
11
|
+
readonly IN_OUT: "power2.inOut";
|
|
12
|
+
/** Smooth deceleration only - used for sliding and growing */
|
|
13
|
+
readonly OUT: "power2.out";
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Timing constants for staggered animations
|
|
17
|
+
*/
|
|
18
|
+
export declare const TIMING: {
|
|
19
|
+
/** No stagger - all elements animate simultaneously */
|
|
20
|
+
readonly NO_STAGGER: 0;
|
|
21
|
+
/** Ripple effect delay - each bar delayed by distance × this value (50ms per unit) */
|
|
22
|
+
readonly RIPPLE_STAGGER_DELAY: 0.05;
|
|
23
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Selection } from 'd3-selection';
|
|
2
|
+
import { MorphChartCategory } from '../morph-chart.types';
|
|
3
|
+
interface AreaRenderOptions {
|
|
4
|
+
xScale: (value: Date) => number;
|
|
5
|
+
yScale: (value: number) => number;
|
|
6
|
+
addClasses?: boolean;
|
|
7
|
+
instanceId?: string;
|
|
8
|
+
}
|
|
9
|
+
interface StackedDataPoint {
|
|
10
|
+
data: {
|
|
11
|
+
timestamp: number;
|
|
12
|
+
};
|
|
13
|
+
0: number;
|
|
14
|
+
1: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Render stacked areas into an SVG container
|
|
18
|
+
* @param container - D3 selection of the container (typically a <g> element)
|
|
19
|
+
* @param stackedData - D3 stacked data (output of d3.stack())
|
|
20
|
+
* @param categories - Category definitions with colors and opacity
|
|
21
|
+
* @param options - Rendering options (scales, styling)
|
|
22
|
+
*/
|
|
23
|
+
export declare function renderStackedAreas(container: Selection<SVGGElement, unknown, null, undefined>, stackedData: StackedDataPoint[][], categories: MorphChartCategory[], options: AreaRenderOptions): void;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MorphChartCategory } from '../morph-chart.types';
|
|
2
|
+
export type StackedBarSegment = {
|
|
3
|
+
timestamp: number;
|
|
4
|
+
category: string;
|
|
5
|
+
dataKey: string;
|
|
6
|
+
y0: number;
|
|
7
|
+
y1: number;
|
|
8
|
+
value: number;
|
|
9
|
+
color: string;
|
|
10
|
+
isSpecialCategory: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Generate stacked bar data from time series
|
|
14
|
+
* Converts raw data into stacked segments for bar rendering
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateStackedBarData(data: Array<{
|
|
17
|
+
timestamp: number;
|
|
18
|
+
[key: string]: number;
|
|
19
|
+
}>, categories: MorphChartCategory[]): StackedBarSegment[];
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { Selection } from 'd3-selection';
|
|
2
|
+
import { MorphChartCategory } from '../morph-chart.types';
|
|
3
|
+
interface AnimationDurations {
|
|
4
|
+
seatsToRings: number;
|
|
5
|
+
ringsToBar: number;
|
|
6
|
+
axesReveal: number;
|
|
7
|
+
barSlide: number;
|
|
8
|
+
barsGrow: number;
|
|
9
|
+
barsToArea: number;
|
|
10
|
+
ringsHold?: number;
|
|
11
|
+
}
|
|
12
|
+
interface AnimationCallbacks {
|
|
13
|
+
onStageComplete?: (stage: string) => void;
|
|
14
|
+
onProgress?: (progress: number) => void;
|
|
15
|
+
onComplete?: () => void;
|
|
16
|
+
}
|
|
17
|
+
interface AnimationControls {
|
|
18
|
+
play: () => void;
|
|
19
|
+
pause: () => void;
|
|
20
|
+
reverse: () => void;
|
|
21
|
+
restart: () => void;
|
|
22
|
+
seek: (progress: number) => void;
|
|
23
|
+
seekToStage: (stageName: string) => void;
|
|
24
|
+
kill: () => void;
|
|
25
|
+
getProgress: () => number;
|
|
26
|
+
getCurrentStage: () => string;
|
|
27
|
+
getTimeline: () => gsap.core.Timeline;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* GSAP Orchestrator class that manages the entire animation sequence
|
|
31
|
+
*/
|
|
32
|
+
export declare class GSAPOrchestrator {
|
|
33
|
+
private timeline;
|
|
34
|
+
private currentStage;
|
|
35
|
+
private callbacks;
|
|
36
|
+
private durations;
|
|
37
|
+
constructor(durations: AnimationDurations, callbacks?: AnimationCallbacks);
|
|
38
|
+
/**
|
|
39
|
+
* Stage 1a: Animate parliament seats transforming into slinky rings
|
|
40
|
+
*
|
|
41
|
+
* Transforms the circular parliament layout into a slinky (spring coil) formation.
|
|
42
|
+
* This creates a whimsical intermediate state between the circular parliament
|
|
43
|
+
* and the stacked bar, making the transition more visually engaging.
|
|
44
|
+
*
|
|
45
|
+
* @param seats - D3 selection of parliament seat elements to animate
|
|
46
|
+
* @param baselineY - Y-coordinate of the chart baseline (reference for positioning)
|
|
47
|
+
* @returns this - Returns the orchestrator instance for method chaining
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* **Visual transformation:**
|
|
51
|
+
* - Parliament seats (circular arc) → Slinky rings (elliptical coils)
|
|
52
|
+
* - Seats morph and fade into overlapping rings
|
|
53
|
+
* - Rings positioned along the parliament arc initially
|
|
54
|
+
* - Uses perspective effects for 3D slinky appearance
|
|
55
|
+
*
|
|
56
|
+
* **Data preservation:**
|
|
57
|
+
* - Original seat positions stored in data-orig-* attributes for potential reversal
|
|
58
|
+
* - Current dimensions preserved before transformation
|
|
59
|
+
*
|
|
60
|
+
* **Timeline integration:**
|
|
61
|
+
* - Added at 'seatsToRings' label (first stage)
|
|
62
|
+
* - Duration: Set by durations.seatsToRings
|
|
63
|
+
* - Triggers onStageComplete callback when starting
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const seats = svg.selectAll('.parliament-seat');
|
|
68
|
+
* const baselineY = height - margin.bottom;
|
|
69
|
+
* orchestrator.animateSeatsToRings(seats, baselineY);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
animateSeatsToRings(seats: Selection<SVGRectElement, unknown, null, undefined>, baselineY: number): GSAPOrchestrator;
|
|
73
|
+
/**
|
|
74
|
+
* Stage 1b: Animate slinky rings collapsing into stacked bar
|
|
75
|
+
*
|
|
76
|
+
* Transforms the slinky rings created in Stage 1a into a stacked
|
|
77
|
+
* vertical bar. Rings compress and stack vertically to form rectangular
|
|
78
|
+
* segments of the final bar, maintaining visual continuity.
|
|
79
|
+
*
|
|
80
|
+
* @param seats - D3 selection of ring elements (formerly seats) to animate
|
|
81
|
+
* @param targetPositions - Array of target positions for each segment, where each position defines the final rectangle geometry (x, y, width, height)
|
|
82
|
+
* @returns this - Returns the orchestrator instance for method chaining
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* **Visual transformation:**
|
|
86
|
+
* - Slinky rings → Stacked bar segments (rectangles)
|
|
87
|
+
* - Rings compress and flatten into bar segments
|
|
88
|
+
* - Reposition to stack vertically in correct order
|
|
89
|
+
* - All segments animate simultaneously (no stagger)
|
|
90
|
+
* - Uses power2.inOut easing for smooth acceleration/deceleration
|
|
91
|
+
*
|
|
92
|
+
* **Data requirements:**
|
|
93
|
+
* - Target positions must match ring count (indexed by array position)
|
|
94
|
+
* - Each position defines final x, y, width, height for the bar segment
|
|
95
|
+
*
|
|
96
|
+
* **Timeline integration:**
|
|
97
|
+
* - Added at 'ringsToBar' label (after seatsToRings)
|
|
98
|
+
* - Duration: Set by durations.ringsToBar
|
|
99
|
+
* - Triggers onStageComplete callback when starting
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const rings = svg.selectAll('.slinky-ring');
|
|
104
|
+
* const targets = calculateBarPositions(rings);
|
|
105
|
+
* orchestrator.animateRingsToBar(rings, targets);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
animateRingsToBar(seats: Selection<SVGRectElement, unknown, null, undefined>, targetPositions: Array<{
|
|
109
|
+
x: number;
|
|
110
|
+
y: number;
|
|
111
|
+
width: number;
|
|
112
|
+
height: number;
|
|
113
|
+
}>): GSAPOrchestrator;
|
|
114
|
+
/**
|
|
115
|
+
* Stage 2a: Reveal X and Y axes to establish timeline context
|
|
116
|
+
*
|
|
117
|
+
* Fades in the chart axes (x-axis with dates, y-axis with values) to provide
|
|
118
|
+
* spatial context before the bar slides to its position. This stage establishes
|
|
119
|
+
* the timeline framework that gives meaning to the bar's position.
|
|
120
|
+
*
|
|
121
|
+
* @param xAxisGroup - D3 selection of the x-axis group element (must have opacity: 0)
|
|
122
|
+
* @param yAxisGroup - D3 selection of the y-axis group element (must have opacity: 0)
|
|
123
|
+
* @returns this - Returns the orchestrator instance for method chaining
|
|
124
|
+
*
|
|
125
|
+
* @remarks
|
|
126
|
+
* **Visual transformation:**
|
|
127
|
+
* - Axes fade in from opacity 0 → 1
|
|
128
|
+
* - Uses full stage duration for smooth, gradual reveal
|
|
129
|
+
* - Both axes animate simultaneously
|
|
130
|
+
* - Uses power2.inOut easing for professional motion
|
|
131
|
+
*
|
|
132
|
+
* **Data requirements:**
|
|
133
|
+
* - Axes must already exist in the DOM with opacity: 0
|
|
134
|
+
* - xAxisGroup should contain tick marks and labels for dates
|
|
135
|
+
* - yAxisGroup should contain tick marks and labels for values
|
|
136
|
+
*
|
|
137
|
+
* **Timeline integration:**
|
|
138
|
+
* - Added at 'axesReveal' label (after seats→bar transformation)
|
|
139
|
+
* - Duration: 12.5% of total animation (STAGE_DURATION_RATIOS.AXES_REVEAL)
|
|
140
|
+
* - Happens **before** bar slide to establish context first
|
|
141
|
+
* - Triggers onStageComplete callback when starting
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const xAxis = svg.select('.x-axis').style('opacity', 0);
|
|
146
|
+
* const yAxis = svg.select('.y-axis').style('opacity', 0);
|
|
147
|
+
* orchestrator.animateAxesReveal(xAxis, yAxis);
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
animateAxesReveal(xAxisGroup: Selection<SVGGElement, unknown, null, undefined>, yAxisGroup: Selection<SVGGElement, unknown, null, undefined>): GSAPOrchestrator;
|
|
151
|
+
/**
|
|
152
|
+
* Stage 2b: Slide the collapsed bar horizontally to its timeline position
|
|
153
|
+
*
|
|
154
|
+
* Moves the vertical bar created in Stage 1 to its correct x-position on the timeline.
|
|
155
|
+
* This stage establishes spatial context by positioning the bar relative to the time axis.
|
|
156
|
+
*
|
|
157
|
+
* @param barSegments - D3 selection of bar segment rectangles to slide
|
|
158
|
+
* @param targetX - Final x-coordinate where the bar should be positioned on the timeline
|
|
159
|
+
* @returns this - Returns the orchestrator instance for method chaining
|
|
160
|
+
*
|
|
161
|
+
* @remarks
|
|
162
|
+
* **Visual transformation:**
|
|
163
|
+
* - Horizontal slide only (y-position and height remain constant)
|
|
164
|
+
* - All bar segments move together as a unified column
|
|
165
|
+
* - Uses power2.out easing for smooth deceleration (settling into place)
|
|
166
|
+
*
|
|
167
|
+
* **Timeline integration:**
|
|
168
|
+
* - Added at 'barSlide' label (after seats→bar transformation)
|
|
169
|
+
* - Duration: 25% of total animation (STAGE_DURATION_RATIOS.BAR_SLIDE)
|
|
170
|
+
* - Triggers onStageComplete callback when starting
|
|
171
|
+
*
|
|
172
|
+
* **Positioning:**
|
|
173
|
+
* - targetX typically corresponds to a specific timestamp on the x-axis
|
|
174
|
+
* - For "rightmost edge" positioning: targetX = width - margin.right
|
|
175
|
+
* - For "middle date" positioning: targetX = xScale(middleTimestamp)
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const barSegments = svg.selectAll('.bar-segment');
|
|
180
|
+
* const rightEdgeX = width - margin.right;
|
|
181
|
+
* orchestrator.animateBarSlide(barSegments, rightEdgeX);
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
animateBarSlide(barSegments: Selection<SVGRectElement, unknown, null, undefined>, targetX: number): GSAPOrchestrator;
|
|
185
|
+
/**
|
|
186
|
+
* Stage 3: Grow other bars with ripple effect from parliament position
|
|
187
|
+
*
|
|
188
|
+
* Animates the historical bars growing from the baseline, creating a wave-like
|
|
189
|
+
* ripple effect radiating outward from the parliament bar's position. Bars closer
|
|
190
|
+
* to the parliament position appear first, with increasing delay for distant bars.
|
|
191
|
+
*
|
|
192
|
+
* @param otherBars - D3 selection of bars at other timestamps (excluding parliament bar)
|
|
193
|
+
* @param parliamentIndex - Timeline index of the parliament bar (center of ripple)
|
|
194
|
+
* @param staggerDelay - Delay multiplier per distance unit (default: TIMING.RIPPLE_STAGGER_DELAY = 0.05)
|
|
195
|
+
* @returns this - Returns the orchestrator instance for method chaining
|
|
196
|
+
*
|
|
197
|
+
* @remarks
|
|
198
|
+
* **Visual transformation:**
|
|
199
|
+
* - Bars grow vertically from height=0 (baseline) to final stacked height
|
|
200
|
+
* - Ripple effect: delay = |barIndex - parliamentIndex| × staggerDelay
|
|
201
|
+
* - Bars furthest from parliament bar appear last (e.g., delay of 0.50s for 10 bars away)
|
|
202
|
+
* - Uses power2.out easing for smooth upward growth
|
|
203
|
+
*
|
|
204
|
+
* **Data requirements:**
|
|
205
|
+
* Each bar element must have these data attributes:
|
|
206
|
+
* - `data-final-y`: Target y-coordinate (top of bar)
|
|
207
|
+
* - `data-final-height`: Target height
|
|
208
|
+
* - `data-timestamp-index`: Position in timeline array
|
|
209
|
+
* - `data-baseline-y`: Y-coordinate of chart baseline (for fromTo animation)
|
|
210
|
+
*
|
|
211
|
+
* **Timeline integration:**
|
|
212
|
+
* - Added at 'barsGrow' label (after bar slide)
|
|
213
|
+
* - Duration: 25% of total animation (STAGE_DURATION_RATIOS.BARS_GROW)
|
|
214
|
+
* - Individual bars have additional stagger delays
|
|
215
|
+
* - Triggers onStageComplete callback when starting
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* const otherBars = svg.selectAll('.bar:not(.parliament-bar)');
|
|
220
|
+
* const parliamentIndex = 15; // Parliament bar is at index 15
|
|
221
|
+
* orchestrator.animateBarsGrow(otherBars, parliamentIndex, 0.05);
|
|
222
|
+
* // Bars will appear with 50ms delay per timeline distance
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
animateBarsGrow(otherBars: Selection<SVGRectElement, unknown, null, undefined>, parliamentIndex: number, staggerDelay?: number): GSAPOrchestrator;
|
|
226
|
+
/**
|
|
227
|
+
* Stage 4: Morph bars into curved areas using path interpolation
|
|
228
|
+
*
|
|
229
|
+
* Transforms rectangular stacked bars into smooth, curved area paths. This is
|
|
230
|
+
* the final stage that creates the traditional stacked area chart appearance.
|
|
231
|
+
* Uses GSAP's path morphing to interpolate from bar rectangles to bezier curves.
|
|
232
|
+
*
|
|
233
|
+
* @param allBars - D3 selection of all bar rectangles (will be hidden during morph)
|
|
234
|
+
* @param morphPaths - D3 selection of SVG paths used for morphing (one per category)
|
|
235
|
+
* @param targetAreaPaths - Map of category IDs to target SVG path strings (curved areas)
|
|
236
|
+
* @param categories - Array of category definitions (used for grouping)
|
|
237
|
+
* @returns this - Returns the orchestrator instance for method chaining
|
|
238
|
+
*
|
|
239
|
+
* @remarks
|
|
240
|
+
* **Visual transformation:**
|
|
241
|
+
* - Rectangular bars (straight edges) → Curved area paths (smooth curves)
|
|
242
|
+
* - Bars fade out (opacity: 0), morphing paths fade in (opacity: 1)
|
|
243
|
+
* - GSAP interpolates path data attribute from bar shape to curve shape
|
|
244
|
+
* - Uses power2.inOut easing for smooth shape morphing
|
|
245
|
+
*
|
|
246
|
+
* **Path morphing technique:**
|
|
247
|
+
* 1. Each category has a morphPath element that starts as combined bar outline
|
|
248
|
+
* 2. morphPath's `d` attribute animates from bar path → area path
|
|
249
|
+
* 3. GSAP handles point interpolation automatically
|
|
250
|
+
* 4. Original bars hidden to avoid visual duplication
|
|
251
|
+
*
|
|
252
|
+
* **Data requirements:**
|
|
253
|
+
* - morphPaths must have `data-category` attribute matching category ID
|
|
254
|
+
* - allBars must have CSS class `category-{categoryKey}` for grouping
|
|
255
|
+
* - targetAreaPaths keys must match category IDs
|
|
256
|
+
*
|
|
257
|
+
* **Timeline integration:**
|
|
258
|
+
* - Added at 'barsToArea' label (after bars grow)
|
|
259
|
+
* - Duration: 20% of total animation (STAGE_DURATION_RATIOS.BARS_TO_AREA)
|
|
260
|
+
* - Triggers onStageComplete callback when starting
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* const allBars = svg.selectAll('.stacked-bar rect');
|
|
265
|
+
* const morphPaths = svg.selectAll('.morph-path');
|
|
266
|
+
* const targetPaths = new Map([
|
|
267
|
+
* ['java', 'M 100 300 C 150 280, 200 270, 250 260 L 250 300 Z'],
|
|
268
|
+
* ['python', 'M 100 260 C 150 240, 200 230, 250 220 L 250 260 Z']
|
|
269
|
+
* ]);
|
|
270
|
+
* orchestrator.animateBarsToArea(allBars, morphPaths, targetPaths, categories);
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
animateBarsToArea(allBars: Selection<SVGRectElement, unknown, null, undefined>, morphPaths: Selection<SVGPathElement, unknown, null, undefined>, targetAreaPaths: Map<string, string>, _categories: MorphChartCategory[]): GSAPOrchestrator;
|
|
274
|
+
/**
|
|
275
|
+
* Handle timeline progress updates
|
|
276
|
+
*/
|
|
277
|
+
private handleProgress;
|
|
278
|
+
/**
|
|
279
|
+
* Get animation control interface
|
|
280
|
+
*/
|
|
281
|
+
getControls(): AnimationControls;
|
|
282
|
+
/**
|
|
283
|
+
* Start the animation
|
|
284
|
+
*/
|
|
285
|
+
play(): void;
|
|
286
|
+
/**
|
|
287
|
+
* Clean up and destroy the timeline
|
|
288
|
+
*/
|
|
289
|
+
destroy(): void;
|
|
290
|
+
}
|
|
291
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Selection } from 'd3-selection';
|
|
2
|
+
import { MorphChartCategory, ParliamentLayout } from '../morph-chart.types';
|
|
3
|
+
/**
|
|
4
|
+
* Sanitize category name for use in CSS class names
|
|
5
|
+
* Replaces spaces, slashes, and other special characters with hyphens
|
|
6
|
+
*/
|
|
7
|
+
export declare function sanitizeCategoryForClass(category: string): string;
|
|
8
|
+
interface ParliamentRenderOptions {
|
|
9
|
+
centerX: number;
|
|
10
|
+
centerY: number;
|
|
11
|
+
addClasses?: boolean;
|
|
12
|
+
instanceId?: string;
|
|
13
|
+
parliamentRadius?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Render parliament seats into an SVG container
|
|
17
|
+
* @param container - D3 selection of the container (typically a <g> element)
|
|
18
|
+
* @param layout - Parliament layout with seat positions
|
|
19
|
+
* @param categories - Category definitions with colors
|
|
20
|
+
* @param options - Rendering options (positioning, styling)
|
|
21
|
+
*/
|
|
22
|
+
export declare function renderParliamentSeats(container: Selection<SVGGElement, unknown, null, undefined>, layout: ParliamentLayout, categories: MorphChartCategory[], options: ParliamentRenderOptions): void;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ParliamentLayout } from '../morph-chart.types';
|
|
2
|
+
type Party = {
|
|
3
|
+
id: string | number;
|
|
4
|
+
name: string;
|
|
5
|
+
seats: number;
|
|
6
|
+
colour: string;
|
|
7
|
+
};
|
|
8
|
+
type ParliamentOptions = {
|
|
9
|
+
arcAngle: number;
|
|
10
|
+
arcAngleFlexibility?: number;
|
|
11
|
+
radius: number;
|
|
12
|
+
seatSize: number;
|
|
13
|
+
minSeatSize: number;
|
|
14
|
+
maxSeatSize: number;
|
|
15
|
+
spacing: number;
|
|
16
|
+
innerRadiusRatio: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Generate parliament layout with seat positions
|
|
20
|
+
* Based on the logic from parliament-svg-enhanced.ts but returns position data
|
|
21
|
+
* instead of SVG elements
|
|
22
|
+
*/
|
|
23
|
+
export declare function generateParliamentLayout(parties: Party[], options: ParliamentOptions): ParliamentLayout;
|
|
24
|
+
/**
|
|
25
|
+
* Convert category data to parliament party format
|
|
26
|
+
*/
|
|
27
|
+
export declare function categoriesToParties(categories: Array<{
|
|
28
|
+
dataKey: string;
|
|
29
|
+
label: string;
|
|
30
|
+
color: string;
|
|
31
|
+
value: number;
|
|
32
|
+
}>, totalRepositories: number, maxSeats: number): Party[];
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ScaleLinear, ScaleTime } from 'd3-scale';
|
|
2
|
+
import { ParliamentLayout, SeatPosition } from '../morph-chart.types';
|
|
3
|
+
/**
|
|
4
|
+
* Map parliament seats to their target positions at the right edge of the stacked area chart
|
|
5
|
+
* Seats can be positioned at the top (y1) or distributed vertically within their category's segment
|
|
6
|
+
*
|
|
7
|
+
* NOTE: stackData uses dataKey, but parliamentLayout.seats use category labels.
|
|
8
|
+
* We need to match by label, so stackData must contain label information.
|
|
9
|
+
*
|
|
10
|
+
* @param distributeVertically - If true, seats are spread between y0 and y1; if false, all seats at y1
|
|
11
|
+
*/
|
|
12
|
+
export declare function mapSeatsToStackEdge(parliamentLayout: ParliamentLayout, stackData: Array<{
|
|
13
|
+
dataKey: string;
|
|
14
|
+
label?: string;
|
|
15
|
+
y0: number;
|
|
16
|
+
y1: number;
|
|
17
|
+
timestamp?: number;
|
|
18
|
+
isSpecialCategory?: boolean;
|
|
19
|
+
}>, xScale: ScaleTime<number, number>, yScale: ScaleLinear<number, number>, chartWidth: number, chartHeight: number, distributeVertically?: boolean): Map<SeatPosition, {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Extract the rightmost slice of stacked area data
|
|
25
|
+
* This represents the same point-in-time as the parliament chart
|
|
26
|
+
*
|
|
27
|
+
* IMPORTANT: The stack is generated using original category order.
|
|
28
|
+
* We build the slice in original order to match the stack generation.
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractRightmostStackSlice(data: Array<{
|
|
31
|
+
timestamp: number;
|
|
32
|
+
[key: string]: number;
|
|
33
|
+
}>, categories: Array<{
|
|
34
|
+
dataKey: string;
|
|
35
|
+
label: string;
|
|
36
|
+
color: string;
|
|
37
|
+
parliamentMapping?: {
|
|
38
|
+
isSpecialCategory?: boolean;
|
|
39
|
+
};
|
|
40
|
+
}>, _yScale: ScaleLinear<number, number>): Array<{
|
|
41
|
+
dataKey: string;
|
|
42
|
+
label: string;
|
|
43
|
+
y0: number;
|
|
44
|
+
y1: number;
|
|
45
|
+
value: number;
|
|
46
|
+
timestamp: number;
|
|
47
|
+
isSpecialCategory?: boolean;
|
|
48
|
+
}>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Selection } from 'd3-selection';
|
|
2
|
+
/**
|
|
3
|
+
* Add all hatch pattern definitions to an SVG's <defs> element
|
|
4
|
+
* Call this once when setting up the SVG
|
|
5
|
+
* @param svg - The SVG selection to add patterns to
|
|
6
|
+
* @param instancePrefix - Unique prefix for this instance to avoid ID conflicts
|
|
7
|
+
*/
|
|
8
|
+
export declare function addHatchPatternDefs(svg: Selection<SVGSVGElement, unknown, null, undefined>, instancePrefix: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Transform a color to use instance-specific pattern IDs
|
|
11
|
+
* Converts 'url(#patternName)' to 'url(#prefix-patternName)'
|
|
12
|
+
*/
|
|
13
|
+
export declare function transformColorForInstance(color: string, instancePrefix: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Get the display color for a category, handling pattern URLs
|
|
16
|
+
* Returns the line color for patterns (better visibility in hover states)
|
|
17
|
+
* Works with both instance-specific and generic pattern URLs
|
|
18
|
+
*/
|
|
19
|
+
export declare function getDisplayColor(color: string): string;
|