@recharts/devtools 0.0.8 → 0.0.9

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 (43) hide show
  1. package/dist/annotations/AnnotationsController.d.ts +40 -0
  2. package/dist/annotations/AnnotationsController.js +241 -0
  3. package/dist/annotations/Blanket.d.ts +31 -0
  4. package/dist/annotations/Blanket.js +19 -0
  5. package/dist/annotations/CircleAnnotation.d.ts +15 -0
  6. package/dist/annotations/CircleAnnotation.js +32 -0
  7. package/dist/annotations/Crosshair.d.ts +23 -0
  8. package/dist/annotations/Crosshair.js +42 -0
  9. package/dist/annotations/FreeformLine.d.ts +15 -0
  10. package/dist/annotations/FreeformLine.js +35 -0
  11. package/dist/annotations/HorizontalLine.d.ts +15 -0
  12. package/dist/annotations/HorizontalLine.js +23 -0
  13. package/dist/annotations/LabelAnnotation.d.ts +23 -0
  14. package/dist/annotations/LabelAnnotation.js +41 -0
  15. package/dist/annotations/RectangleAnnotation.d.ts +15 -0
  16. package/dist/annotations/RectangleAnnotation.js +36 -0
  17. package/dist/annotations/RenderAnnotations.d.ts +31 -0
  18. package/dist/annotations/RenderAnnotations.js +114 -0
  19. package/dist/annotations/VerticalLine.d.ts +15 -0
  20. package/dist/annotations/VerticalLine.js +23 -0
  21. package/dist/annotations/annotationColors.d.ts +20 -0
  22. package/dist/annotations/annotationColors.js +34 -0
  23. package/dist/annotations/getDistance.d.ts +2 -0
  24. package/dist/annotations/getDistance.js +4 -0
  25. package/dist/annotations/index.d.ts +17 -0
  26. package/dist/annotations/index.js +17 -0
  27. package/dist/annotations/types.d.ts +38 -0
  28. package/dist/annotations/types.js +1 -0
  29. package/dist/annotations/useAnnotationsManager.d.ts +35 -0
  30. package/dist/annotations/useAnnotationsManager.js +136 -0
  31. package/dist/annotations/useSnap.d.ts +44 -0
  32. package/dist/annotations/useSnap.js +127 -0
  33. package/dist/components/RechartsAnnotations.d.ts +19 -0
  34. package/dist/components/RechartsAnnotations.js +38 -0
  35. package/dist/components/RechartsDevtools.d.ts +1 -1
  36. package/dist/components/RechartsDevtools.js +21 -15
  37. package/dist/constants.d.ts +1 -0
  38. package/dist/constants.js +1 -0
  39. package/dist/context/RechartsDevtoolsContext.d.ts +5 -0
  40. package/dist/context/RechartsDevtoolsContext.js +10 -1
  41. package/dist/index.d.ts +5 -2
  42. package/dist/index.js +4 -2
  43. package/package.json +3 -3
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @fileoverview renders UI form for managing annotations in a chart.
3
+ *
4
+ * This is basic UI for demonstration purposes.
5
+ * In your own application, this UI is probably going to look completely different.
6
+ * Feel free to reuse what you see here but chances are you'll want to build your own anyway.
7
+ *
8
+ * Allows:
9
+ *
10
+ * - Adding, editing, and deleting annotations.
11
+ * - Supported annotations: Crosshairs, Labels, Shapes (lines, rectangles, circles).
12
+ * - Configuring annotation styles: color, strokeWidth, strokeDasharray, fill, opacity.
13
+ * - Positioning annotations using coordinates. Allows both absolute pixel values and data values.
14
+ * - Adding labels to annotations with customizable text and styles and position.
15
+ *
16
+ * This controller is meant to be rendered outside the chart area, typically in a sidebar or modal,
17
+ * in an HTML context (not SVG).
18
+ */
19
+ import React from 'react';
20
+ import type { Annotation, AnnotationType, SnapMode } from './types.js';
21
+ interface AnnotationsControllerProps {
22
+ annotations: Annotation[];
23
+ isAdding: AnnotationType | null;
24
+ selectedAnnotationId: number | null;
25
+ snapMode: SnapMode;
26
+ onStartAdding: (type: AnnotationType) => void;
27
+ onCancelAdding: () => void;
28
+ onDeleteAnnotation: (id: number) => void;
29
+ onUpdateAnnotation: (annotation: Annotation) => void;
30
+ onSelectAnnotation: (id: number | null) => void;
31
+ onSnapModeChange: (newSnapMode: SnapMode) => void;
32
+ }
33
+ /**
34
+ * Renders controls for adding, editing, and removing annotations.
35
+ *
36
+ * This component renders HTML elements and is meant to be rendered via portal
37
+ * outside the SVG chart context.
38
+ */
39
+ export declare function AnnotationsController({ annotations, isAdding, selectedAnnotationId, snapMode, onStartAdding, onCancelAdding, onDeleteAnnotation, onUpdateAnnotation, onSelectAnnotation, onSnapModeChange, }: AnnotationsControllerProps): React.JSX.Element;
40
+ export {};
@@ -0,0 +1,241 @@
1
+ /**
2
+ * @fileoverview renders UI form for managing annotations in a chart.
3
+ *
4
+ * This is basic UI for demonstration purposes.
5
+ * In your own application, this UI is probably going to look completely different.
6
+ * Feel free to reuse what you see here but chances are you'll want to build your own anyway.
7
+ *
8
+ * Allows:
9
+ *
10
+ * - Adding, editing, and deleting annotations.
11
+ * - Supported annotations: Crosshairs, Labels, Shapes (lines, rectangles, circles).
12
+ * - Configuring annotation styles: color, strokeWidth, strokeDasharray, fill, opacity.
13
+ * - Positioning annotations using coordinates. Allows both absolute pixel values and data values.
14
+ * - Adding labels to annotations with customizable text and styles and position.
15
+ *
16
+ * This controller is meant to be rendered outside the chart area, typically in a sidebar or modal,
17
+ * in an HTML context (not SVG).
18
+ */
19
+ import React, { useId, useState } from 'react';
20
+ const ANNOTATION_TYPES = [
21
+ { type: 'horizontalLine', label: 'Horizontal Line' },
22
+ { type: 'verticalLine', label: 'Vertical Line' },
23
+ { type: 'circle', label: 'Circle' },
24
+ { type: 'rectangle', label: 'Rectangle' },
25
+ { type: 'label', label: 'Label' },
26
+ { type: 'freeformLine', label: 'Freeform Line' },
27
+ { type: 'crosshair', label: 'Crosshair' },
28
+ ];
29
+ const buttonStyle = {
30
+ padding: '4px 8px',
31
+ fontSize: '11px',
32
+ cursor: 'pointer',
33
+ border: '1px solid #ccc',
34
+ borderRadius: '3px',
35
+ background: '#fff',
36
+ };
37
+ const activeButtonStyle = {
38
+ ...buttonStyle,
39
+ background: '#e0e0e0',
40
+ borderColor: '#999',
41
+ };
42
+ const inputStyle = {
43
+ width: '50px',
44
+ fontSize: '11px',
45
+ padding: '2px 4px',
46
+ border: '1px solid #ccc',
47
+ borderRadius: '2px',
48
+ };
49
+ const labelStyle = {
50
+ fontSize: '11px',
51
+ minWidth: '40px',
52
+ display: 'inline-flex',
53
+ flexDirection: 'row',
54
+ alignItems: 'center',
55
+ gap: '1ex',
56
+ marginRight: '2ex',
57
+ };
58
+ function SnapModeRadioGroup({ snapMode, onSnapModeChange, }) {
59
+ const name = useId();
60
+ return (React.createElement("div", { style: { marginBottom: '12px' } },
61
+ React.createElement("div", { style: { marginBottom: '6px', fontWeight: 'bold' } }, "Snap to Data:"),
62
+ React.createElement("label", { style: labelStyle },
63
+ React.createElement("input", { type: "radio", name: name, value: "none", checked: snapMode === 'none', onChange: () => onSnapModeChange('none') }),
64
+ "No snapping"),
65
+ React.createElement("label", { style: labelStyle },
66
+ React.createElement("input", { type: "radio", name: name, value: "data", checked: snapMode === 'data', onChange: () => onSnapModeChange('data') }),
67
+ "Snap to data points"),
68
+ React.createElement("label", { style: labelStyle },
69
+ React.createElement("input", { type: "radio", name: name, value: "tick", checked: snapMode === 'tick', onChange: () => onSnapModeChange('tick') }),
70
+ "Snap to axis ticks")));
71
+ }
72
+ function AnnotationEditForm({ annotation, handleStyleChange, onUpdateAnnotation, }) {
73
+ return (React.createElement("div", { style: { marginTop: '8px', paddingTop: '8px', borderTop: '1px solid #ddd' } },
74
+ React.createElement("div", { style: { display: 'flex', flexWrap: 'wrap', gap: '8px', marginBottom: '8px' } },
75
+ (annotation.type === 'verticalLine' ||
76
+ annotation.type === 'circle' ||
77
+ annotation.type === 'label' ||
78
+ annotation.type === 'crosshair') && (React.createElement("label", { style: labelStyle },
79
+ "X:",
80
+ React.createElement("input", { type: "number", value: annotation.pointA.interactionCoordinate.x, onChange: (e) => onUpdateAnnotation({
81
+ ...annotation,
82
+ pointA: {
83
+ ...annotation.pointA,
84
+ interactionCoordinate: {
85
+ ...annotation.pointA.interactionCoordinate,
86
+ x: parseFloat(e.target.value),
87
+ },
88
+ },
89
+ }), style: inputStyle }))),
90
+ (annotation.type === 'horizontalLine' ||
91
+ annotation.type === 'circle' ||
92
+ annotation.type === 'label' ||
93
+ annotation.type === 'crosshair') && (React.createElement("label", { style: labelStyle },
94
+ "Y:",
95
+ React.createElement("input", { type: "number", value: annotation.pointA.interactionCoordinate.y, onChange: (e) => onUpdateAnnotation({
96
+ ...annotation,
97
+ pointA: {
98
+ ...annotation.pointA,
99
+ interactionCoordinate: {
100
+ ...annotation.pointA.interactionCoordinate,
101
+ y: parseFloat(e.target.value),
102
+ },
103
+ },
104
+ }), style: inputStyle }))),
105
+ (annotation.type === 'rectangle' || annotation.type === 'freeformLine') && (React.createElement(React.Fragment, null,
106
+ React.createElement("label", { style: labelStyle },
107
+ "X1:",
108
+ React.createElement("input", { type: "number", value: annotation.pointA.interactionCoordinate.x, onChange: (e) => onUpdateAnnotation({
109
+ ...annotation,
110
+ pointA: {
111
+ ...annotation.pointA,
112
+ interactionCoordinate: {
113
+ x: parseFloat(e.target.value),
114
+ y: annotation.pointA.interactionCoordinate.y,
115
+ },
116
+ },
117
+ }), style: inputStyle })),
118
+ React.createElement("label", { style: labelStyle },
119
+ "Y1:",
120
+ React.createElement("input", { type: "number", value: annotation.pointA.interactionCoordinate.y, onChange: (e) => onUpdateAnnotation({
121
+ ...annotation,
122
+ pointA: {
123
+ ...annotation.pointA,
124
+ interactionCoordinate: {
125
+ x: annotation.pointA.interactionCoordinate.x,
126
+ y: parseFloat(e.target.value),
127
+ },
128
+ },
129
+ }), style: inputStyle })),
130
+ React.createElement("label", { style: labelStyle },
131
+ "X2:",
132
+ React.createElement("input", { type: "number", value: annotation.pointB?.interactionCoordinate.x ?? '', onChange: (e) => onUpdateAnnotation({
133
+ ...annotation,
134
+ pointB: {
135
+ snappedCoordinate: undefined,
136
+ dataPoint: undefined,
137
+ interactionCoordinate: {
138
+ x: parseFloat(e.target.value),
139
+ y: annotation.pointB?.interactionCoordinate.y ?? 0,
140
+ },
141
+ },
142
+ }), style: inputStyle })),
143
+ React.createElement("label", { style: labelStyle },
144
+ "Y2:",
145
+ React.createElement("input", { type: "number", value: annotation.pointB?.interactionCoordinate.y ?? '', onChange: (e) => onUpdateAnnotation({
146
+ ...annotation,
147
+ pointB: {
148
+ snappedCoordinate: undefined,
149
+ dataPoint: undefined,
150
+ interactionCoordinate: {
151
+ x: annotation.pointB?.interactionCoordinate.x ?? 0,
152
+ y: parseFloat(e.target.value),
153
+ },
154
+ },
155
+ }), style: inputStyle }))))),
156
+ React.createElement("div", { style: { display: 'flex', flexWrap: 'wrap', gap: '8px' } },
157
+ React.createElement("label", { style: labelStyle },
158
+ "Stroke:",
159
+ React.createElement("input", { type: "number", value: annotation.style.strokeWidth ?? 2, onChange: (e) => handleStyleChange(annotation, 'strokeWidth', parseFloat(e.target.value)), style: inputStyle, min: 0, step: 0.5 })),
160
+ React.createElement("label", { style: labelStyle },
161
+ "Opacity:",
162
+ React.createElement("input", { type: "number", value: annotation.style.opacity ?? 1, onChange: (e) => handleStyleChange(annotation, 'opacity', parseFloat(e.target.value)), style: inputStyle, min: 0, max: 1, step: 0.1 })),
163
+ React.createElement("label", { style: labelStyle },
164
+ "Dash:",
165
+ React.createElement("input", { type: "text", value: annotation.style.strokeDasharray ?? '', onChange: (e) => handleStyleChange(annotation, 'strokeDasharray', e.target.value), style: { ...inputStyle, width: '60px' }, placeholder: "e.g. 4 2" })),
166
+ (annotation.type === 'rectangle' || annotation.type === 'circle') && (React.createElement(React.Fragment, null,
167
+ React.createElement("label", { style: labelStyle },
168
+ "Fill:",
169
+ React.createElement("input", { type: "color", value: annotation.style.fill ?? '#cccccc', onChange: (e) => handleStyleChange(annotation, 'fill', e.target.value), style: {
170
+ width: '20px',
171
+ height: '20px',
172
+ padding: 0,
173
+ border: 'none',
174
+ cursor: 'pointer',
175
+ } })),
176
+ React.createElement("label", { style: labelStyle },
177
+ "Fill Opacity:",
178
+ React.createElement("input", { type: "number", value: annotation.style.fillOpacity ?? 0.1, onChange: (e) => handleStyleChange(annotation, 'fillOpacity', parseFloat(e.target.value)), style: inputStyle, min: 0, max: 1, step: 0.1 }))))),
179
+ annotation.type === 'label' && (React.createElement("div", { style: { marginTop: '8px' } },
180
+ React.createElement("label", { style: labelStyle },
181
+ "Text:",
182
+ React.createElement("input", { type: "text", value: String(annotation.label?.value ?? ''), onChange: (e) => onUpdateAnnotation({
183
+ ...annotation,
184
+ label: { ...annotation.label, value: e.target.value },
185
+ }), style: { ...inputStyle, width: '150px' } }))))));
186
+ }
187
+ /**
188
+ * Renders controls for adding, editing, and removing annotations.
189
+ *
190
+ * This component renders HTML elements and is meant to be rendered via portal
191
+ * outside the SVG chart context.
192
+ */
193
+ export function AnnotationsController({ annotations, isAdding, selectedAnnotationId, snapMode, onStartAdding, onCancelAdding, onDeleteAnnotation, onUpdateAnnotation, onSelectAnnotation, onSnapModeChange, }) {
194
+ const [expandedAnnotationId, setExpandedAnnotationId] = useState(null);
195
+ const handleStyleChange = (annotation, styleKey, value) => {
196
+ onUpdateAnnotation({
197
+ ...annotation,
198
+ style: {
199
+ ...annotation.style,
200
+ [styleKey]: value,
201
+ },
202
+ });
203
+ };
204
+ const toggleExpanded = (id) => {
205
+ setExpandedAnnotationId((prev) => (prev === id ? null : id));
206
+ };
207
+ return (React.createElement("div", { style: { fontFamily: 'monospace', fontSize: '12px' } },
208
+ React.createElement("div", { style: { marginBottom: '12px' } },
209
+ React.createElement("div", { style: { marginBottom: '6px', fontWeight: 'bold' } }, "Add Annotation:"),
210
+ React.createElement("div", { style: { display: 'flex', flexWrap: 'wrap', gap: '4px' } }, ANNOTATION_TYPES.map(({ type, label }) => (React.createElement("button", { key: type, type: "button", onClick: () => (isAdding === type ? onCancelAdding() : onStartAdding(type)), style: isAdding === type ? activeButtonStyle : buttonStyle }, isAdding === type ? `Cancel ${label}` : label)))),
211
+ isAdding && (React.createElement("div", { style: { marginTop: '6px', fontSize: '11px', color: '#666' } },
212
+ "Click on the chart to place the annotation",
213
+ (isAdding === 'rectangle' || isAdding === 'freeformLine' || isAdding === 'circle') &&
214
+ ' (click twice or drag to define dimensions)'))),
215
+ React.createElement(SnapModeRadioGroup, { snapMode: snapMode, onSnapModeChange: onSnapModeChange }),
216
+ React.createElement("div", null,
217
+ React.createElement("div", { style: { marginBottom: '6px', fontWeight: 'bold' } },
218
+ "Annotations (",
219
+ annotations.length,
220
+ "):"),
221
+ annotations.length === 0 ? (React.createElement("div", { style: { fontSize: '11px', color: '#666' } }, "No annotations yet")) : (React.createElement("div", { style: { display: 'flex', flexDirection: 'column', gap: '8px' } }, annotations.map((annotation) => (React.createElement("div", { key: annotation.id, style: {
222
+ padding: '8px',
223
+ border: selectedAnnotationId === annotation.id ? '2px solid #007bff' : '1px solid #ddd',
224
+ borderRadius: '4px',
225
+ background: '#fafafa',
226
+ } },
227
+ React.createElement("div", { style: { display: 'flex', alignItems: 'center', gap: '8px', marginBottom: '4px' } },
228
+ React.createElement("input", { type: "color", value: annotation.style.color ?? '#ff0000', onChange: (e) => handleStyleChange(annotation, 'color', e.target.value), style: {
229
+ width: '20px',
230
+ height: '20px',
231
+ padding: 0,
232
+ border: 'none',
233
+ cursor: 'pointer',
234
+ }, title: "Change color" }),
235
+ React.createElement("span", { style: { fontWeight: 'bold', fontSize: '11px', flex: 1 } }, ANNOTATION_TYPES.find((t) => t.type === annotation.type)?.label ??
236
+ annotation.type),
237
+ React.createElement("button", { type: "button", onClick: () => toggleExpanded(annotation.id), style: buttonStyle }, expandedAnnotationId === annotation.id ? '▼' : '▶'),
238
+ React.createElement("button", { type: "button", onClick: () => onSelectAnnotation(selectedAnnotationId === annotation.id ? null : annotation.id), style: selectedAnnotationId === annotation.id ? activeButtonStyle : buttonStyle }, selectedAnnotationId === annotation.id ? 'Deselect' : 'Select'),
239
+ React.createElement("button", { type: "button", onClick: () => onDeleteAnnotation(annotation.id), style: { ...buttonStyle, color: '#d00' } }, "Delete")),
240
+ expandedAnnotationId === annotation.id && (React.createElement(AnnotationEditForm, { annotation: annotation, handleStyleChange: handleStyleChange, onUpdateAnnotation: onUpdateAnnotation }))))))))));
241
+ }
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ export interface BlanketProps {
3
+ onClick?: (e: React.MouseEvent<SVGGraphicsElement>) => void;
4
+ onMouseMove?: (e: React.MouseEvent<SVGGraphicsElement>) => void;
5
+ onMouseLeave?: (e: React.MouseEvent<SVGGraphicsElement>) => void;
6
+ onMouseDown?: (e: React.MouseEvent<SVGGraphicsElement>) => void;
7
+ onMouseUp?: (e: React.MouseEvent<SVGGraphicsElement>) => void;
8
+ onMouseEnter?: (e: React.MouseEvent<SVGGraphicsElement>) => void;
9
+ pointerEvents?: 'none' | 'auto';
10
+ /**
11
+ * Optional fill color. Defaults to transparent.
12
+ * Can be set to a semi-transparent color to darken the background
13
+ * when in annotation editing mode.
14
+ */
15
+ fill?: string;
16
+ }
17
+ /**
18
+ * This component is used to create an invisible layer over the chart
19
+ * that can capture mouse events like clicks and movements.
20
+ *
21
+ * It renders a transparent rectangle that spans the entire chart area.
22
+ *
23
+ * Its purpose is to keep the API simple; we could achieve the same effect
24
+ * by attaching event listeners directly to the chart container, but this
25
+ * would complicate the API and usage and pollute the examples with multiple event handlers
26
+ * that are not relevant to the core concepts being demonstrated.
27
+ *
28
+ * Instead, we render a transparent SVG rectangle that has pointerEvents disabled by default,
29
+ * and only enable them when the user is in the state where they are either adding, editing, or removing annotations.
30
+ */
31
+ export declare const Blanket: React.NamedExoticComponent<BlanketProps>;
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ /**
3
+ * This component is used to create an invisible layer over the chart
4
+ * that can capture mouse events like clicks and movements.
5
+ *
6
+ * It renders a transparent rectangle that spans the entire chart area.
7
+ *
8
+ * Its purpose is to keep the API simple; we could achieve the same effect
9
+ * by attaching event listeners directly to the chart container, but this
10
+ * would complicate the API and usage and pollute the examples with multiple event handlers
11
+ * that are not relevant to the core concepts being demonstrated.
12
+ *
13
+ * Instead, we render a transparent SVG rectangle that has pointerEvents disabled by default,
14
+ * and only enable them when the user is in the state where they are either adding, editing, or removing annotations.
15
+ */
16
+ export const Blanket = React.memo(function Blanket({ onClick, onMouseMove, onMouseLeave, onMouseDown, onMouseUp, onMouseEnter, pointerEvents = 'none', fill = 'transparent', }) {
17
+ return (React.createElement(React.Fragment, null,
18
+ React.createElement("rect", { x: 0, y: 0, width: "100%", height: "100%", fill: fill, style: { pointerEvents }, onClick: onClick, onMouseMove: onMouseMove, onMouseLeave: onMouseLeave, onMouseDown: onMouseDown, onMouseUp: onMouseUp, onMouseEnter: onMouseEnter })));
19
+ });
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This annotation allows drawing a circle on a chart.
3
+ *
4
+ * It accepts either pixel coordinates or data values for positioning.
5
+ *
6
+ * In case it receives pixel coordinates, it uses a Dot component.
7
+ * If data values are provided, it uses a ReferenceDot component.
8
+ */
9
+ import React from 'react';
10
+ import { Annotation } from './types.js';
11
+ interface CircleAnnotationProps {
12
+ annotation: Annotation;
13
+ }
14
+ export declare function CircleAnnotation({ annotation }: CircleAnnotationProps): React.JSX.Element | null;
15
+ export {};
@@ -0,0 +1,32 @@
1
+ /**
2
+ * This annotation allows drawing a circle on a chart.
3
+ *
4
+ * It accepts either pixel coordinates or data values for positioning.
5
+ *
6
+ * In case it receives pixel coordinates, it uses a Dot component.
7
+ * If data values are provided, it uses a ReferenceDot component.
8
+ */
9
+ import React from 'react';
10
+ import { Dot, ReferenceDot } from 'recharts';
11
+ import { getDistance } from './getDistance.js';
12
+ export function CircleAnnotation({ annotation }) {
13
+ const { pointA, pointB, positionType, label, style } = annotation;
14
+ const { color = '#ccc', strokeWidth = 1, fill = '#fff', opacity = 1, fillOpacity = 0.1, pointerEvents, } = style;
15
+ if (!pointB) {
16
+ return null;
17
+ }
18
+ const r = getDistance(pointA, pointB);
19
+ if (positionType === 'data') {
20
+ // Use ReferenceDot for data-based positioning
21
+ if (!pointA.dataPoint) {
22
+ return null;
23
+ }
24
+ return (React.createElement(ReferenceDot, { x: String(pointA.dataPoint.x), y: String(pointA.dataPoint.y), r: r, stroke: color, strokeWidth: strokeWidth, strokeOpacity: opacity, fill: fill, fillOpacity: fillOpacity, style: { pointerEvents }, label: label }));
25
+ }
26
+ // For pixel-based positioning, use Dot component
27
+ const xPixel = pointA.interactionCoordinate.x;
28
+ const yPixel = pointA.interactionCoordinate.y;
29
+ return (React.createElement("g", { style: { pointerEvents } },
30
+ React.createElement(Dot, { cx: xPixel, cy: yPixel, r: r, stroke: color, strokeWidth: strokeWidth, fill: fill, fillOpacity: fillOpacity }),
31
+ label && (React.createElement("text", { x: xPixel + r + 5, y: yPixel + 4, fill: label.style?.fill ?? color, fontSize: label.style?.fontSize ?? 10, fontWeight: label.style?.fontWeight ?? 'normal', pointerEvents: "none" }, label.value))));
32
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * This annotation allows drawing a crosshair on a chart.
3
+ *
4
+ * A crosshair is a combination of horizontal and vertical lines intersecting at a point,
5
+ * with optional coordinate labels.
6
+ *
7
+ * It accepts either pixel coordinates or data values for positioning.
8
+ *
9
+ * In case it receives pixel coordinates, it uses a Cross component (raw SVG).
10
+ * If data values are provided, it uses a combination of two ReferenceLine components.
11
+ *
12
+ * TODO: For data-based positioning, we need two ReferenceLine components (one with x, one with y).
13
+ * However, ReferenceLine with just x or just y will draw a full line across the chart.
14
+ * This works well for crosshairs but doesn't support truncated crosshairs.
15
+ */
16
+ import React from 'react';
17
+ import { Annotation } from './types.js';
18
+ interface CrosshairProps {
19
+ annotation: Annotation;
20
+ showLabels?: boolean;
21
+ }
22
+ export declare function Crosshair({ annotation, showLabels }: CrosshairProps): React.JSX.Element | null;
23
+ export {};
@@ -0,0 +1,42 @@
1
+ /**
2
+ * This annotation allows drawing a crosshair on a chart.
3
+ *
4
+ * A crosshair is a combination of horizontal and vertical lines intersecting at a point,
5
+ * with optional coordinate labels.
6
+ *
7
+ * It accepts either pixel coordinates or data values for positioning.
8
+ *
9
+ * In case it receives pixel coordinates, it uses a Cross component (raw SVG).
10
+ * If data values are provided, it uses a combination of two ReferenceLine components.
11
+ *
12
+ * TODO: For data-based positioning, we need two ReferenceLine components (one with x, one with y).
13
+ * However, ReferenceLine with just x or just y will draw a full line across the chart.
14
+ * This works well for crosshairs but doesn't support truncated crosshairs.
15
+ */
16
+ import React from 'react';
17
+ import { ReferenceLine } from 'recharts';
18
+ export function Crosshair({ annotation, showLabels = false }) {
19
+ const { pointA, positionType, style } = annotation;
20
+ const { color = 'red', strokeWidth = 2, strokeDasharray = '4', opacity = 1 } = style;
21
+ if (positionType === 'data') {
22
+ // Use two ReferenceLines for data-based positioning
23
+ if (!pointA.dataPoint) {
24
+ return null;
25
+ }
26
+ return (React.createElement(React.Fragment, null,
27
+ React.createElement(ReferenceLine, { x: String(pointA.dataPoint.x), stroke: color, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray, strokeOpacity: opacity }),
28
+ React.createElement(ReferenceLine, { y: String(pointA.dataPoint.y), stroke: color, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray, strokeOpacity: opacity })));
29
+ }
30
+ // For pixel-based positioning, use raw SVG
31
+ const xPixel = pointA.interactionCoordinate.x;
32
+ const yPixel = pointA.interactionCoordinate.y;
33
+ const coordinateText = `${xPixel.toFixed(1)}, ${yPixel.toFixed(1)}`;
34
+ // Approximate text width calculation (roughly 6.5 pixels per character for 10px bold monospace)
35
+ const textWidth = coordinateText.length * 6.5;
36
+ return (React.createElement("g", null,
37
+ React.createElement("line", { x1: xPixel, y1: 0, x2: xPixel, y2: "100%", stroke: color, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray, opacity: opacity, pointerEvents: "none" }),
38
+ React.createElement("line", { x1: 0, y1: yPixel, x2: "100%", y2: yPixel, stroke: color, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray, opacity: opacity, pointerEvents: "none" }),
39
+ showLabels && (React.createElement(React.Fragment, null,
40
+ React.createElement("rect", { x: xPixel + 5, y: yPixel - 25, width: textWidth + 6, height: 16, fill: "rgba(255, 255, 255, 0.9)", stroke: color, strokeWidth: 1, rx: 2, pointerEvents: "none" }),
41
+ React.createElement("text", { x: xPixel + 8, y: yPixel - 12, fill: color, fontSize: 10, fontWeight: "bold", fontFamily: "'Courier New', Courier, monospace", pointerEvents: "none" }, coordinateText)))));
42
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This annotation allows drawing a freeform line on a chart.
3
+ *
4
+ * It accepts either pixel coordinates or data values for positioning.
5
+ *
6
+ * In case it receives pixel coordinates, it uses a line SVG element.
7
+ * If data values are provided, it uses a ReferenceLine component with the segment prop.
8
+ */
9
+ import React from 'react';
10
+ import { Annotation } from './types.js';
11
+ interface FreeformLineProps {
12
+ annotation: Annotation;
13
+ }
14
+ export declare function FreeformLine({ annotation }: FreeformLineProps): React.JSX.Element | null;
15
+ export {};
@@ -0,0 +1,35 @@
1
+ /**
2
+ * This annotation allows drawing a freeform line on a chart.
3
+ *
4
+ * It accepts either pixel coordinates or data values for positioning.
5
+ *
6
+ * In case it receives pixel coordinates, it uses a line SVG element.
7
+ * If data values are provided, it uses a ReferenceLine component with the segment prop.
8
+ */
9
+ import React from 'react';
10
+ import { ReferenceLine } from 'recharts';
11
+ export function FreeformLine({ annotation }) {
12
+ const { pointA, pointB, positionType, style, label } = annotation;
13
+ const { color = '#ccc', strokeWidth = 1, strokeDasharray, opacity = 1 } = style;
14
+ if (!pointB) {
15
+ return null;
16
+ }
17
+ if (positionType === 'data') {
18
+ // Use ReferenceLine with segment prop for data-based positioning
19
+ if (!pointA.dataPoint || !pointB.dataPoint) {
20
+ return null;
21
+ }
22
+ return (React.createElement(ReferenceLine, { segment: [
23
+ { x: String(pointA.dataPoint.x), y: String(pointA.dataPoint.y) },
24
+ { x: String(pointB.dataPoint.x), y: String(pointB.dataPoint.y) },
25
+ ], stroke: color, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray, strokeOpacity: opacity, label: label }));
26
+ }
27
+ // For pixel-based positioning, use raw SVG line
28
+ const x1Pixel = pointA.interactionCoordinate.x;
29
+ const y1Pixel = pointA.interactionCoordinate.y;
30
+ const x2Pixel = pointB.interactionCoordinate.x;
31
+ const y2Pixel = pointB.interactionCoordinate.y;
32
+ return (React.createElement("g", null,
33
+ React.createElement("line", { x1: x1Pixel, y1: y1Pixel, x2: x2Pixel, y2: y2Pixel, stroke: color, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray, opacity: opacity, pointerEvents: "none" }),
34
+ label && (React.createElement("text", { x: (x1Pixel + x2Pixel) / 2, y: (y1Pixel + y2Pixel) / 2 - 5, fill: label.style?.fill ?? color, fontSize: label.style?.fontSize ?? 10, fontWeight: label.style?.fontWeight ?? 'normal', textAnchor: "middle", pointerEvents: "none" }, label.value))));
35
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This annotation allows drawing a horizontal line on a chart.
3
+ *
4
+ * It accepts either pixel coordinates or data values for positioning.
5
+ *
6
+ * In case it receives pixel coordinates, it uses a line SVG element.
7
+ * If data values are provided, it uses a ReferenceLine component.
8
+ */
9
+ import React from 'react';
10
+ import { Annotation } from './types.js';
11
+ interface HorizontalLineProps {
12
+ annotation: Annotation;
13
+ }
14
+ export declare function HorizontalLine({ annotation }: HorizontalLineProps): React.JSX.Element;
15
+ export {};
@@ -0,0 +1,23 @@
1
+ /**
2
+ * This annotation allows drawing a horizontal line on a chart.
3
+ *
4
+ * It accepts either pixel coordinates or data values for positioning.
5
+ *
6
+ * In case it receives pixel coordinates, it uses a line SVG element.
7
+ * If data values are provided, it uses a ReferenceLine component.
8
+ */
9
+ import React from 'react';
10
+ import { ReferenceLine } from 'recharts';
11
+ export function HorizontalLine({ annotation }) {
12
+ const { pointA, positionType, label, style } = annotation;
13
+ const { color = '#ccc', strokeWidth = 1, strokeDasharray, opacity = 1 } = style;
14
+ if (positionType === 'data') {
15
+ // Use ReferenceLine for data-based positioning
16
+ return (React.createElement(ReferenceLine, { y: String(pointA.dataPoint?.y), stroke: color, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray, strokeOpacity: opacity, label: label, tabIndex: -1, focusable: false }));
17
+ }
18
+ // For pixel-based positioning, use raw SVG line
19
+ const yPixel = pointA.interactionCoordinate.y;
20
+ return (React.createElement("g", null,
21
+ React.createElement("line", { x1: 0, y1: yPixel, x2: "100%", y2: yPixel, stroke: color, strokeWidth: strokeWidth, strokeDasharray: strokeDasharray, opacity: opacity, pointerEvents: "none", tabIndex: -1, focusable: false }),
22
+ label && (React.createElement("text", { x: 5, y: yPixel - 5, fill: label.style?.fill ?? color, fontSize: label.style?.fontSize ?? 10, fontWeight: label.style?.fontWeight ?? 'normal', pointerEvents: "none" }, label.value))));
23
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * This annotation allows drawing a text label on a chart.
3
+ *
4
+ * It accepts either pixel coordinates or data values for positioning.
5
+ *
6
+ * Position can be provided either as a keyword (see Label.position prop),
7
+ * or pixel coordinates, or data coordinates.
8
+ *
9
+ * In case it receives pixel coordinates, it passes them directly as position={{x, y}} to the Label component.
10
+ * If data values are provided, it resolves them to pixel coordinates and then passes them as position={{x, y}} to the Label component again.
11
+ *
12
+ * TODO: Recharts Label component doesn't have direct support for data-based coordinates.
13
+ * When positionType='data', we would need access to axis scales to convert data values to pixels.
14
+ * This requires being inside a chart context with access to selectAxisScale.
15
+ * For now, data-based positioning falls back to pixel positioning with a warning.
16
+ */
17
+ import React from 'react';
18
+ import { Annotation } from './types.js';
19
+ interface LabelAnnotationProps {
20
+ annotation: Annotation;
21
+ }
22
+ export declare function LabelAnnotation({ annotation }: LabelAnnotationProps): React.JSX.Element | null;
23
+ export {};
@@ -0,0 +1,41 @@
1
+ /**
2
+ * This annotation allows drawing a text label on a chart.
3
+ *
4
+ * It accepts either pixel coordinates or data values for positioning.
5
+ *
6
+ * Position can be provided either as a keyword (see Label.position prop),
7
+ * or pixel coordinates, or data coordinates.
8
+ *
9
+ * In case it receives pixel coordinates, it passes them directly as position={{x, y}} to the Label component.
10
+ * If data values are provided, it resolves them to pixel coordinates and then passes them as position={{x, y}} to the Label component again.
11
+ *
12
+ * TODO: Recharts Label component doesn't have direct support for data-based coordinates.
13
+ * When positionType='data', we would need access to axis scales to convert data values to pixels.
14
+ * This requires being inside a chart context with access to selectAxisScale.
15
+ * For now, data-based positioning falls back to pixel positioning with a warning.
16
+ */
17
+ import React from 'react';
18
+ import { Label } from 'recharts';
19
+ export function LabelAnnotation({ annotation }) {
20
+ const { pointA, positionType, style, label } = annotation;
21
+ const { color = '#333', opacity = 1, pointerEvents } = style;
22
+ const fontSize = label?.style?.fontSize ?? 12;
23
+ const fontWeight = label?.style?.fontWeight ?? 'normal';
24
+ if (!label) {
25
+ return null;
26
+ }
27
+ let x, y;
28
+ if (positionType === 'data') {
29
+ if (pointA.snappedCoordinate == null) {
30
+ return null;
31
+ }
32
+ // Recharts Label doesn't support data coordinates directly so we use snappedCoordinate which we computed earlier from the inverse scale.
33
+ x = pointA.snappedCoordinate.x;
34
+ y = pointA.snappedCoordinate.y;
35
+ }
36
+ else {
37
+ x = pointA.interactionCoordinate.x;
38
+ y = pointA.interactionCoordinate.y;
39
+ }
40
+ return (React.createElement(Label, { value: label.value, position: { x, y }, fill: label.style?.fill ?? color, fontSize: fontSize, fontWeight: fontWeight, opacity: opacity, style: { pointerEvents } }));
41
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This annotation allows drawing a rectangle on a chart.
3
+ *
4
+ * It accepts either pixel coordinates or data values for positioning.
5
+ *
6
+ * In case it receives pixel coordinates, it uses a Rectangle component.
7
+ * If data values are provided, it uses a ReferenceArea component.
8
+ */
9
+ import React from 'react';
10
+ import { Annotation } from './types.js';
11
+ interface RectangleAnnotationProps {
12
+ annotation: Annotation;
13
+ }
14
+ export declare function RectangleAnnotation({ annotation }: RectangleAnnotationProps): React.JSX.Element | null;
15
+ export {};