@moderneinc/react-charts 1.1.0-next.dcefa6 → 1.2.0-next.0d3f64

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.
Files changed (53) hide show
  1. package/dist/components/chrono-chart/chrono-chart.component.d.ts +10 -0
  2. package/dist/components/chrono-chart/chrono-chart.types.d.ts +129 -0
  3. package/dist/components/chrono-chart/components/category-table.component.d.ts +13 -0
  4. package/dist/components/chrono-chart/components/category-table.types.d.ts +42 -0
  5. package/dist/components/chrono-chart/utils/data-transformer.d.ts +41 -0
  6. package/dist/components/d3-stacked-area-chart/d3-stacked-area-chart.component.d.ts +7 -0
  7. package/dist/components/d3-stacked-area-chart/d3-stacked-area-chart.types.d.ts +95 -0
  8. package/dist/components/d3-stacked-area-chart/hooks/use-d3-stacked-area.hook.d.ts +35 -0
  9. package/dist/components/morph-chart/hooks/shared/computations.d.ts +29 -0
  10. package/dist/components/morph-chart/hooks/shared/types.d.ts +24 -0
  11. package/dist/components/morph-chart/hooks/use-morph-chart.hook.d.ts +90 -0
  12. package/dist/components/morph-chart/index.d.ts +2 -0
  13. package/dist/components/morph-chart/morph-chart.component.d.ts +14 -0
  14. package/dist/components/morph-chart/morph-chart.types.d.ts +175 -0
  15. package/dist/components/morph-chart/utils/accordion-generator.d.ts +102 -0
  16. package/dist/components/morph-chart/utils/animation-constants.d.ts +23 -0
  17. package/dist/components/morph-chart/utils/animation-utils.d.ts +44 -0
  18. package/dist/components/morph-chart/utils/arc-path-calculator.d.ts +53 -0
  19. package/dist/components/morph-chart/utils/area-renderer.d.ts +24 -0
  20. package/dist/components/morph-chart/utils/bar-renderer.d.ts +19 -0
  21. package/dist/components/morph-chart/utils/gsap-orchestrator.d.ts +291 -0
  22. package/dist/components/morph-chart/utils/morph-interpolator.d.ts +96 -0
  23. package/dist/components/morph-chart/utils/parliament-renderer.d.ts +23 -0
  24. package/dist/components/morph-chart/utils/parliament-seat-extractor.d.ts +33 -0
  25. package/dist/components/morph-chart/utils/position-mapper.d.ts +48 -0
  26. package/dist/components/morph-chart/utils/segment-transformer.d.ts +70 -0
  27. package/dist/components/morph-chart/utils/slinky-3d-generator.d.ts +35 -0
  28. package/dist/components/morph-chart/utils/svg-patterns.d.ts +19 -0
  29. package/dist/components/morph-chart/utils/svg-slinky-generator.d.ts +25 -0
  30. package/dist/components/parliament-chart/hooks/{use-parliament-chart.d.ts → use-parliament-chart.hook.d.ts} +5 -1
  31. package/dist/components/parliament-chart/parliament-chart.types.d.ts +5 -0
  32. package/dist/components/parliament-chart/utils/parliament-animation.d.ts +13 -0
  33. package/dist/components/stacked-area-chart/hooks/use-stacked-area-chart.hook.d.ts +6 -0
  34. package/dist/components/stacked-area-chart/stacked-area-chart.component.d.ts +10 -0
  35. package/dist/components/stacked-area-chart/stacked-area-chart.constants.d.ts +115 -0
  36. package/dist/components/stacked-area-chart/stacked-area-chart.types.d.ts +186 -0
  37. package/dist/components/stacked-area-chart/utils/color.utils.d.ts +4 -0
  38. package/dist/components/stacked-area-with-timeline/hooks/use-stacked-area-with-timeline.hook.d.ts +52 -0
  39. package/dist/components/stacked-area-with-timeline/index.d.ts +4 -0
  40. package/dist/components/stacked-area-with-timeline/stacked-area-with-timeline.component.d.ts +3 -0
  41. package/dist/components/stacked-area-with-timeline/stacked-area-with-timeline.types.d.ts +97 -0
  42. package/dist/components/stacked-area-with-timeline/utils/render-timeline-track.d.ts +54 -0
  43. package/dist/components/timeline-chart/hooks/use-timeline-chart.hook.d.ts +2 -0
  44. package/dist/components/timeline-chart/timeline-chart.component.d.ts +9 -0
  45. package/dist/components/timeline-chart/timeline-chart.types.d.ts +156 -0
  46. package/dist/components/timeline-chart/timeline-selected-events.component.d.ts +9 -0
  47. package/dist/index.cjs +144 -11
  48. package/dist/index.d.ts +21 -6
  49. package/dist/index.js +31597 -4839
  50. package/dist/theme/default-colors.d.ts +8 -4
  51. package/dist/theme/timeline-defaults.d.ts +82 -0
  52. package/package.json +35 -12
  53. /package/dist/components/parliament-chart/{parliament-chart.d.ts → parliament-chart.component.d.ts} +0 -0
@@ -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,102 @@
1
+ /**
2
+ * Utility functions for generating accordion-style zig-zag lines
3
+ * Used in the seats-to-lines animation stage
4
+ */
5
+ export interface AccordionLinePoint {
6
+ x: number;
7
+ y: number;
8
+ category: string;
9
+ categoryIndex: number;
10
+ }
11
+ export interface AccordionLineConfig {
12
+ centerX: number;
13
+ centerY: number;
14
+ radius: number;
15
+ startAngle: number;
16
+ endAngle: number;
17
+ amplitude: number;
18
+ segments: number;
19
+ }
20
+ /**
21
+ * Generate zig-zag line points for a category's accordion section
22
+ *
23
+ * @param config - Configuration for the accordion line
24
+ * @returns Array of points forming the zig-zag pattern
25
+ */
26
+ export declare function generateAccordionLine(config: AccordionLineConfig): AccordionLinePoint[];
27
+ /**
28
+ * Generate accordion lines for all categories
29
+ *
30
+ * @param categories - Array of categories with their seat counts
31
+ * @param parliamentCenter - Center point of the parliament
32
+ * @param radius - Base radius of the parliament arc
33
+ * @param arcAngle - Total angle of the parliament arc (in radians)
34
+ * @returns Map of category to accordion line points
35
+ */
36
+ export declare function generateCategoryAccordionLines(categories: Array<{
37
+ name: string;
38
+ seatCount: number;
39
+ color: string;
40
+ }>, parliamentCenter: {
41
+ x: number;
42
+ y: number;
43
+ }, radius: number, arcAngle?: number): Map<string, AccordionLinePoint[]>;
44
+ /**
45
+ * Generate a single continuous accordion line for all categories
46
+ * Creates one connected slinky that spans the entire parliament arc
47
+ *
48
+ * @param categories - Array of categories with their seat counts
49
+ * @param parliamentCenter - Center point of the parliament
50
+ * @param radius - Base radius of the parliament arc
51
+ * @param arcAngle - Total angle of the parliament arc (in radians)
52
+ * @returns Single array of accordion line points with category info
53
+ */
54
+ export declare function generateContinuousAccordionLine(categories: Array<{
55
+ name: string;
56
+ seatCount: number;
57
+ color: string;
58
+ }>, parliamentCenter: {
59
+ x: number;
60
+ y: number;
61
+ }, radius: number, arcAngle?: number): AccordionLinePoint[];
62
+ /**
63
+ * Create SVG path string from accordion line points
64
+ *
65
+ * @param points - Array of accordion line points
66
+ * @param curved - Whether to use curved lines (true) or sharp zig-zags (false)
67
+ * @returns SVG path string
68
+ */
69
+ export declare function createAccordionPath(points: AccordionLinePoint[], curved?: boolean): string;
70
+ /**
71
+ * Calculate intermediate positions for accordion collapse animation with slinky physics
72
+ *
73
+ * @param linePoints - Original accordion line points
74
+ * @param targetX - Target X position (vertical bar location)
75
+ * @param targetY - Target Y position (vertical bar location)
76
+ * @param progress - Animation progress (0-1)
77
+ * @returns Interpolated points for current progress with wave motion
78
+ */
79
+ export declare function interpolateAccordionCollapse(linePoints: AccordionLinePoint[], targetX: number, targetY: number, progress: number): AccordionLinePoint[];
80
+ /**
81
+ * Generate multiple depth layers for slinky 3D effect
82
+ *
83
+ * @param config - Base configuration for accordion line
84
+ * @param numLayers - Number of layers to create (default 3)
85
+ * @returns Array of accordion line configurations with depth properties
86
+ */
87
+ export declare function generateLayeredAccordionLines(config: AccordionLineConfig, numLayers?: number): Array<{
88
+ points: AccordionLinePoint[];
89
+ depth: number;
90
+ opacity: number;
91
+ strokeWidth: number;
92
+ blur: number;
93
+ }>;
94
+ /**
95
+ * Generate a single vertical line path for collapsed state
96
+ *
97
+ * @param x - X position of the vertical line
98
+ * @param topY - Top Y position
99
+ * @param bottomY - Bottom Y position
100
+ * @returns SVG path string for vertical line
101
+ */
102
+ export declare function createVerticalLinePath(x: number, topY: number, bottomY: number): string;
@@ -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,44 @@
1
+ /**
2
+ * Utility functions for animation path manipulation
3
+ * Shared helpers for creating SVG paths from bar geometries
4
+ */
5
+ /**
6
+ * Create a rectangular SVG path from bar dimensions
7
+ * Used as the initial state for path morphing animations
8
+ *
9
+ * @param x - Left edge x-coordinate of the rectangle
10
+ * @param y - Top edge y-coordinate of the rectangle
11
+ * @param width - Width of the rectangle
12
+ * @param height - Height of the rectangle
13
+ * @returns SVG path string representing a closed rectangle
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const path = createRectPath(100, 50, 20, 80);
18
+ * // Returns: "M 100 130 L 100 50 L 120 50 L 120 130 Z"
19
+ * ```
20
+ */
21
+ export declare function createRectPath(x: number, y: number, width: number, height: number): string;
22
+ /**
23
+ * Create a combined SVG path from multiple bar segments for a single category
24
+ * Connects all bars into a single continuous path suitable for morphing
25
+ *
26
+ * The path traces along the top edges of all bars (left to right),
27
+ * then closes along the bottom baseline, creating a unified shape.
28
+ *
29
+ * @param bars - Array of SVG rect elements to combine
30
+ * @returns SVG path string representing the combined shape
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const bars = svg.selectAll('.category-java rect').nodes();
35
+ * const combinedPath = createCombinedBarPath(bars);
36
+ * // Returns path that traces outline of all bars
37
+ * ```
38
+ *
39
+ * @remarks
40
+ * - Bars are automatically sorted by x-position (left to right)
41
+ * - Empty array returns empty string
42
+ * - Path draws: bottom-left → tops (left-to-right) → bottom-right → close
43
+ */
44
+ export declare function createCombinedBarPath(bars: SVGRectElement[]): string;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Arc path calculator for slinky-style seat → bar animations
3
+ * Generates pronounced bezier arc paths for smooth cascading motion
4
+ */
5
+ export interface Point {
6
+ x: number;
7
+ y: number;
8
+ }
9
+ export interface ArcPathData {
10
+ startX: number;
11
+ startY: number;
12
+ controlX: number;
13
+ controlY: number;
14
+ endX: number;
15
+ endY: number;
16
+ distance: number;
17
+ }
18
+ /**
19
+ * Calculate the control point for a quadratic bezier curve
20
+ * Creates a pronounced arc by offsetting perpendicular to the direct path
21
+ *
22
+ * @param start - Starting point (seat position)
23
+ * @param end - Ending point (bar segment position)
24
+ * @param arcIntensity - How pronounced the arc should be (0-1, default 0.35 for 35% offset)
25
+ * @returns Control point for the bezier curve
26
+ */
27
+ export declare function calculateArcControlPoint(start: Point, end: Point, arcIntensity?: number): Point;
28
+ /**
29
+ * Generate complete arc path data for animating a seat to a bar position
30
+ *
31
+ * @param seatPosition - Current seat position in parliament
32
+ * @param barPosition - Target bar segment position
33
+ * @param arcIntensity - How pronounced the arc should be (default 0.35)
34
+ * @returns Complete path data for GSAP animation
35
+ */
36
+ export declare function generateArcPath(seatPosition: Point, barPosition: Point, arcIntensity?: number): ArcPathData;
37
+ /**
38
+ * Generate SVG path string for a quadratic bezier arc
39
+ * Useful for debugging or visual representation
40
+ *
41
+ * @param pathData - Arc path data
42
+ * @returns SVG path string
43
+ */
44
+ export declare function generateSVGPath(pathData: ArcPathData): string;
45
+ /**
46
+ * Calculate points along a quadratic bezier curve
47
+ * Useful for visualizing or debugging the arc path
48
+ *
49
+ * @param pathData - Arc path data
50
+ * @param numPoints - Number of points to generate along the curve (default 20)
51
+ * @returns Array of points along the curve
52
+ */
53
+ export declare function getPointsAlongArc(pathData: ArcPathData, numPoints?: number): Point[];
@@ -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[];