rn-native-ios-charts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts ADDED
@@ -0,0 +1,213 @@
1
+ import type { ColorValue, ViewStyle } from "react-native";
2
+
3
+ /* ────────────────────────── Data ────────────────────────── */
4
+
5
+ export type DataPoint = {
6
+ /** Categorical or stringified-numeric x value. */
7
+ x: string;
8
+ /** Primary numeric value. */
9
+ y: number;
10
+ /** Second value, used by range bars and rectangle marks. */
11
+ yEnd?: number;
12
+ /**
13
+ * Optional series/group key. When set, SwiftUI Charts auto-colors
14
+ * by this value (so the legend stays consistent across marks).
15
+ */
16
+ category?: string;
17
+ /** Per-point color override. Beats mark-level color when both set. */
18
+ color?: ColorValue;
19
+ };
20
+
21
+ /* ────────────────────────── Mark types ────────────────────────── */
22
+
23
+ export type Interpolation =
24
+ | "linear"
25
+ | "catmullRom"
26
+ | "monotone"
27
+ | "stepStart"
28
+ | "stepEnd"
29
+ | "stepCenter";
30
+
31
+ export type Symbol =
32
+ | "circle"
33
+ | "square"
34
+ | "triangle"
35
+ | "diamond"
36
+ | "pentagon"
37
+ | "plus"
38
+ | "cross"
39
+ | "asterisk";
40
+
41
+ export type LineCap = "butt" | "round" | "square";
42
+
43
+ export type GradientStop = {
44
+ /** Position along the gradient, 0–1. */
45
+ offset: number;
46
+ /** Stop color. Defaults to the mark's `color` when omitted. */
47
+ color?: ColorValue;
48
+ /** Multiplied with the stop's color alpha. 0 = transparent. */
49
+ opacity?: number;
50
+ };
51
+
52
+ export type Gradient = {
53
+ kind?: "linear";
54
+ /** Linear gradient start point in unit coords. Default top: { x: 0.5, y: 0 }. */
55
+ startX?: number;
56
+ startY?: number;
57
+ /** Linear gradient end point in unit coords. Default bottom: { x: 0.5, y: 1 }. */
58
+ endX?: number;
59
+ endY?: number;
60
+ /** Two-stop shorthand — used when `stops` is empty. Default 0.35. */
61
+ startOpacity?: number;
62
+ /** Two-stop shorthand — used when `stops` is empty. Default 0.02. */
63
+ endOpacity?: number;
64
+ /** Explicit stops. Overrides the two-stop shorthand. */
65
+ stops?: GradientStop[];
66
+ };
67
+
68
+ export type MarkType =
69
+ | "bar"
70
+ | "line"
71
+ | "area"
72
+ | "point"
73
+ | "rectangle"
74
+ | "rule"
75
+ | "sector";
76
+
77
+ export type Mark = {
78
+ type: MarkType;
79
+ data: DataPoint[];
80
+
81
+ /** Solid fill color. Falls back to system accent if neither this nor `gradient` is set. */
82
+ color?: ColorValue;
83
+ /** Multiplier on the resolved fill alpha. 0–1. Default 1. */
84
+ opacity?: number;
85
+ /**
86
+ * Gradient fill. Wins over solid `color`. Most useful on `area`
87
+ * marks for the standard "shaded under the curve" look.
88
+ */
89
+ gradient?: Gradient;
90
+
91
+ // ─── Stroke (line / rule) ───
92
+ lineWidth?: number;
93
+ /** Dash pattern in pt. Empty = solid line. */
94
+ dashArray?: number[];
95
+ lineCap?: LineCap;
96
+
97
+ // ─── Line / area interpolation ───
98
+ interpolation?: Interpolation;
99
+
100
+ // ─── Symbol marks ───
101
+ symbol?: Symbol;
102
+ symbolSize?: number;
103
+ /** When set on a `line` mark, also draws point symbols at each datum. */
104
+ showPoints?: boolean;
105
+
106
+ // ─── Bar / rectangle ───
107
+ cornerRadius?: number;
108
+ /** Fixed bar width in pt. 0 = auto. */
109
+ barWidth?: number;
110
+
111
+ // ─── Sector (pie / donut) ───
112
+ /** Donut hole ratio, 0–1. 0 = full pie, 0.62 = thin donut. */
113
+ innerRadius?: number;
114
+ /** Outer radius ratio, 0–1. 0 = auto-fill. */
115
+ outerRadius?: number;
116
+ /** Gap between adjacent sectors in pt. */
117
+ angularInset?: number;
118
+
119
+ // ─── Rule mark ───
120
+ orientation?: "horizontal" | "vertical";
121
+ /** Constant value the rule draws at. With this set, `data` can be empty. */
122
+ ruleValue?: number;
123
+ };
124
+
125
+ /* ────────────────────────── Chart-level config ────────────────────────── */
126
+
127
+ export type AxisConfig = {
128
+ hidden?: boolean;
129
+ gridLines?: boolean;
130
+ tickLabels?: boolean;
131
+ labelColor?: ColorValue;
132
+ gridColor?: ColorValue;
133
+ labelFontSize?: number;
134
+ /** Numeric domain. Both must be set to take effect. */
135
+ domainMin?: number;
136
+ domainMax?: number;
137
+ };
138
+
139
+ export type LegendConfig = {
140
+ hidden?: boolean;
141
+ placement?:
142
+ | "automatic"
143
+ | "top"
144
+ | "bottom"
145
+ | "leading"
146
+ | "trailing"
147
+ | "overlay";
148
+ };
149
+
150
+ export type CenterLabel = {
151
+ value?: string;
152
+ label?: string;
153
+ valueColor?: ColorValue;
154
+ labelColor?: ColorValue;
155
+ valueFontSize?: number;
156
+ labelFontSize?: number;
157
+ };
158
+
159
+ /**
160
+ * Interactive tooltip config. Drives SwiftUI Charts' native
161
+ * `chartXSelection` — the scrubber snaps to the nearest data point
162
+ * automatically and the callout is drawn inside the plot frame.
163
+ *
164
+ * For pie / sector marks, only the `onSelect` event fires (no
165
+ * built-in visual callout) — use the event to drive a `centerLabel`.
166
+ */
167
+ export type TooltipConfig = {
168
+ enabled?: boolean;
169
+ /** Vertical dashed rule at the selected X. Default true. */
170
+ showRule?: boolean;
171
+ /** Filled dot at the selected point. Default true. */
172
+ showDot?: boolean;
173
+ /** Show the x label above the y value in the callout. Default true. */
174
+ showTitle?: boolean;
175
+ backgroundColor?: ColorValue;
176
+ textColor?: ColorValue;
177
+ borderColor?: ColorValue;
178
+ /** Decimal places for the y value. Default 0. */
179
+ valueDecimals?: number;
180
+ /** Prepended to the y value, e.g. "$". */
181
+ valuePrefix?: string;
182
+ /** Appended to the y value, e.g. "%". */
183
+ valueSuffix?: string;
184
+ };
185
+
186
+ /** Payload emitted by `onSelect`. `null` when the selection is cleared. */
187
+ export type SelectedPoint = { x: string; y: number } | null;
188
+
189
+ export type ChartProps = {
190
+ /** One or more marks to render. Mix freely (e.g. area + line + points). */
191
+ marks: Mark[];
192
+ xAxis?: AxisConfig;
193
+ yAxis?: AxisConfig;
194
+ legend?: LegendConfig;
195
+ /**
196
+ * Center label rendered inside the chart's plot frame (via
197
+ * SwiftUI's `chartBackground`). Tracks the plot center natively —
198
+ * works especially well with `sector` marks for donut center text.
199
+ */
200
+ centerLabel?: CenterLabel;
201
+ /**
202
+ * Interactive tooltip overlay. Defaults to disabled so charts stay
203
+ * static unless you opt in. Enable by passing `{ enabled: true }`.
204
+ */
205
+ tooltip?: TooltipConfig;
206
+ /**
207
+ * Fires when the user picks a point via the scrubber, or taps a
208
+ * pie sector. Receives `null` when selection clears.
209
+ */
210
+ onSelect?: (point: SelectedPoint) => void;
211
+ animate?: boolean;
212
+ style?: ViewStyle;
213
+ };