@impulse-ui-native/charts 2.0.1 → 2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ImpulseUI Native contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.mts CHANGED
@@ -1,3 +1,321 @@
1
- declare const packageName = "charts";
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as _shopify_react_native_skia from '@shopify/react-native-skia';
3
+ import { FontWeight, SkTypefaceFontProvider, SkTextFontFeatures, SkPath, TextAlign, SkParagraphStyle } from '@shopify/react-native-skia';
4
+ import * as _impulse_ui_native_theme from '@impulse-ui-native/theme';
5
+ import { AppTheme } from '@impulse-ui-native/theme';
6
+ import * as react from 'react';
2
7
 
3
- export { packageName };
8
+ type ChartStrokeCap = "butt" | "round" | "square";
9
+ type ChartStrokeJoin = "bevel" | "miter" | "round";
10
+ interface ChartStrokeStyle {
11
+ color?: string;
12
+ width?: number;
13
+ opacity?: number;
14
+ dash?: readonly number[];
15
+ }
16
+ interface ChartLabelStyle {
17
+ color?: string;
18
+ fontSize?: number;
19
+ fontFamily?: string;
20
+ fontWeight?: FontWeight;
21
+ maxLines?: number;
22
+ }
23
+
24
+ type ChartScaleType = "linear" | "point" | "time";
25
+ type ChartNumericDomain = readonly [minimum: number, maximum: number];
26
+ interface ChartInsets {
27
+ top: number;
28
+ right: number;
29
+ bottom: number;
30
+ left: number;
31
+ }
32
+ interface ChartSize {
33
+ width: number;
34
+ height: number;
35
+ }
36
+ interface ChartPoint {
37
+ x: number;
38
+ y: number;
39
+ }
40
+ interface ChartRect extends ChartSize {
41
+ x: number;
42
+ y: number;
43
+ }
44
+ interface ChartLayout {
45
+ size: ChartSize;
46
+ insets: ChartInsets;
47
+ plot: ChartRect;
48
+ xAxis: ChartRect;
49
+ yAxis: ChartRect;
50
+ }
51
+ interface ChartAxisOptions<Value> {
52
+ visible?: boolean;
53
+ tickCount?: number;
54
+ format?: (value: Value) => string;
55
+ line?: ChartAxisLineOptions;
56
+ tick?: ChartAxisTickOptions;
57
+ label?: ChartAxisLabelOptions;
58
+ }
59
+ interface ChartAxisLineOptions extends ChartStrokeStyle {
60
+ visible?: boolean;
61
+ }
62
+ interface ChartAxisTickOptions extends ChartStrokeStyle {
63
+ visible?: boolean;
64
+ length?: number;
65
+ }
66
+ interface ChartAxisLabelOptions extends ChartLabelStyle {
67
+ visible?: boolean;
68
+ gap?: number;
69
+ rotation?: number;
70
+ }
71
+ interface ChartXAxisOptions<X> extends ChartAxisOptions<X> {
72
+ }
73
+ interface ChartYAxisOptions extends ChartAxisOptions<number> {
74
+ domain?: ChartNumericDomain;
75
+ }
76
+
77
+ interface ChartGridLineOptions extends ChartStrokeStyle {
78
+ visible?: boolean;
79
+ }
80
+ interface ChartGridOptions {
81
+ x?: boolean | ChartGridLineOptions;
82
+ y?: boolean | ChartGridLineOptions;
83
+ }
84
+ interface ResolvedGridLineOptions {
85
+ visible: boolean;
86
+ color: string;
87
+ width: number;
88
+ opacity: number;
89
+ dash?: readonly number[];
90
+ }
91
+ interface GridProps<X extends ChartXValue = number> {
92
+ options?: ChartGridOptions;
93
+ plot: ChartRect;
94
+ theme: AppTheme;
95
+ xTicks: readonly X[];
96
+ xScale: LineChartScale<X>;
97
+ yTicks: readonly number[];
98
+ yScale: LineChartScale<number>;
99
+ }
100
+
101
+ type ChartXValue = number | string | Date;
102
+ type LineChartCurve = "linear" | "monotone";
103
+ type LineChartScale<Value> = (value: Value) => number | undefined;
104
+ interface LineChartPoint<X extends ChartXValue = number> {
105
+ x: X;
106
+ y: number | null;
107
+ }
108
+ interface LineChartCoordinate<X extends ChartXValue = number> {
109
+ datum: LineChartPoint<X>;
110
+ index: number;
111
+ x: number | null;
112
+ y: number | null;
113
+ }
114
+ interface LineChartLineOptions extends ChartStrokeStyle {
115
+ visible?: boolean;
116
+ curve?: LineChartCurve;
117
+ cap?: ChartStrokeCap;
118
+ join?: ChartStrokeJoin;
119
+ }
120
+ interface LineChartCommonProps<X extends ChartXValue = number> {
121
+ fontManager?: SkTypefaceFontProvider;
122
+ grid?: ChartGridOptions;
123
+ xScaleType?: ChartScaleType;
124
+ xAxis?: ChartXAxisOptions<X>;
125
+ yAxis?: ChartYAxisOptions;
126
+ insets?: Partial<ChartInsets>;
127
+ }
128
+ interface LineChartProps<X extends ChartXValue = number> extends LineChartCommonProps<X> {
129
+ data: readonly LineChartPoint<X>[];
130
+ line?: LineChartLineOptions;
131
+ }
132
+
133
+ interface AxisTick<Value> {
134
+ value: Value;
135
+ position: number;
136
+ }
137
+ interface AxisLineLayout {
138
+ start: ChartPoint;
139
+ end: ChartPoint;
140
+ }
141
+ interface AxisTickLayout<Value> extends AxisTick<Value>, AxisLineLayout {
142
+ labelRect: ChartRect;
143
+ }
144
+ interface AxisLayout<Value> {
145
+ line: AxisLineLayout;
146
+ ticks: readonly AxisTickLayout<Value>[];
147
+ }
148
+ interface CreateAxisLayoutProps<Value> {
149
+ values: readonly Value[];
150
+ scale: LineChartScale<Value>;
151
+ plot: ChartRect;
152
+ region: ChartRect;
153
+ tickLength: number;
154
+ labelGap: number;
155
+ }
156
+ interface CreateYAxisLayoutProps extends CreateAxisLayoutProps<number> {
157
+ fontSize: number;
158
+ }
159
+ interface AxisProps<Value> {
160
+ ticks: readonly Value[];
161
+ scale: LineChartScale<Value>;
162
+ plot: ChartRect;
163
+ region: ChartRect;
164
+ theme: AppTheme;
165
+ options?: ChartAxisOptions<Value>;
166
+ fontManager?: SkTypefaceFontProvider;
167
+ lineVisible?: boolean;
168
+ tickVisible?: boolean;
169
+ }
170
+ interface XAxisProps<X extends ChartXValue = number> extends AxisProps<X> {
171
+ }
172
+ interface YAxisProps extends AxisProps<number> {
173
+ }
174
+
175
+ type LabelHorizontalAlignment = "left" | "center" | "right";
176
+ type LabelVerticalAlignment = "top" | "center" | "bottom";
177
+ interface LabelProps {
178
+ text: string;
179
+ rect: ChartRect;
180
+ theme: AppTheme;
181
+ horizontalAlign?: LabelHorizontalAlignment;
182
+ verticalAlign?: LabelVerticalAlignment;
183
+ color?: string;
184
+ fontSize?: number;
185
+ fontFamily?: string;
186
+ fontWeight?: FontWeight;
187
+ fontManager?: SkTypefaceFontProvider;
188
+ maxLines?: number;
189
+ rotation?: number;
190
+ tnum?: boolean;
191
+ }
192
+
193
+ interface LineProps<X extends ChartXValue = number> extends LineChartLineOptions {
194
+ coordinates: readonly LineChartCoordinate<X>[];
195
+ }
196
+
197
+ interface MultiLineChartSeries<X extends ChartXValue = number> {
198
+ id: string;
199
+ data: readonly LineChartPoint<X>[];
200
+ line?: LineChartLineOptions;
201
+ }
202
+ interface MultiLineChartSeriesModel<X extends ChartXValue = number> extends MultiLineChartSeries<X> {
203
+ coordinates: readonly LineChartCoordinate<X>[];
204
+ }
205
+ interface MultiLineChartProps<X extends ChartXValue = number> extends LineChartCommonProps<X> {
206
+ series: readonly MultiLineChartSeries<X>[];
207
+ }
208
+ interface MultiLineChartBodyProps<X extends ChartXValue = number> extends MultiLineChartProps<X> {
209
+ size: ChartSize;
210
+ theme: AppTheme;
211
+ }
212
+
213
+ interface UseLineChartProps<X extends ChartXValue = number> {
214
+ data: readonly LineChartPoint<X>[];
215
+ plot: ChartRect;
216
+ xScaleType?: ChartScaleType;
217
+ xAxis?: ChartXAxisOptions<X>;
218
+ yAxis?: ChartYAxisOptions;
219
+ }
220
+ interface UseLineChartResult<X extends ChartXValue = number> {
221
+ xDomain: readonly X[];
222
+ yDomain: ChartNumericDomain;
223
+ xTicks: readonly X[];
224
+ yTicks: readonly number[];
225
+ coordinates: readonly LineChartCoordinate<X>[];
226
+ xScale: LineChartScale<X>;
227
+ yScale: LineChartScale<number>;
228
+ }
229
+ interface LineChartXScaleModel<X extends ChartXValue> {
230
+ domain: readonly X[];
231
+ ticks: readonly X[];
232
+ scale: LineChartScale<X>;
233
+ }
234
+
235
+ interface UseMultiLineChartProps<X extends ChartXValue = number> extends Pick<MultiLineChartProps<X>, "series" | "xAxis" | "xScaleType" | "yAxis"> {
236
+ plot: ChartRect;
237
+ }
238
+ interface UseMultiLineChartResult<X extends ChartXValue = number> extends Omit<UseLineChartResult<X>, "coordinates"> {
239
+ series: readonly MultiLineChartSeriesModel<X>[];
240
+ }
241
+
242
+ declare const Grid: <X extends ChartXValue = number>(props: GridProps<X>) => react_jsx_runtime.JSX.Element;
243
+
244
+ declare const Label: (props: LabelProps) => react_jsx_runtime.JSX.Element | null;
245
+
246
+ declare const Line: <X extends ChartXValue = number>(props: LineProps<X>) => react_jsx_runtime.JSX.Element | null;
247
+
248
+ declare const XAxis: <X extends ChartXValue = number>(props: XAxisProps<X>) => react_jsx_runtime.JSX.Element;
249
+
250
+ declare const YAxis: (props: YAxisProps) => react_jsx_runtime.JSX.Element;
251
+
252
+ declare const LineChart: <X extends ChartXValue = number>(props: LineChartProps<X>) => react_jsx_runtime.JSX.Element;
253
+
254
+ declare const MultiLineChart: <X extends ChartXValue = number>(props: MultiLineChartProps<X>) => react_jsx_runtime.JSX.Element;
255
+
256
+ declare const AxisDefaultWidth = 1;
257
+ declare const AxisDefaultOpacity = 1;
258
+ declare const AxisDefaultTickLength = 4;
259
+ declare const AxisDefaultLabelGap = 4;
260
+
261
+ declare const GridDefaultWidth = 1;
262
+ declare const GridDefaultOpacity = 1;
263
+ declare const GridDefaultXVisible = true;
264
+ declare const GridDefaultYVisible = true;
265
+
266
+ declare const TabularNumsFeature: SkTextFontFeatures;
267
+ declare const LabelDefaultHorizontalAlignment: LabelHorizontalAlignment;
268
+ declare const LabelDefaultVerticalAlignment: LabelVerticalAlignment;
269
+
270
+ declare const LineDefaultColor: string;
271
+ declare const LineDefaultColors: _impulse_ui_native_theme.ChartColorPalette;
272
+ declare const LineDefaultWidth = 2;
273
+ declare const LineDefaultOpacity = 1;
274
+ declare const LineDefaultCurve: LineChartCurve;
275
+ declare const LineDefaultCap: ChartStrokeCap;
276
+ declare const LineDefaultJoin: ChartStrokeJoin;
277
+
278
+ declare const LineChartDefaultTickCount = 5;
279
+ declare const LineChartDefaultNumericDomain: ChartNumericDomain;
280
+
281
+ declare function useChartCanvas(): {
282
+ ref: react.RefObject<_shopify_react_native_skia.CanvasRef | null>;
283
+ size: _shopify_react_native_skia.SkSize;
284
+ };
285
+
286
+ declare function useLineChart<X extends ChartXValue = number>(props: UseLineChartProps<X>): UseLineChartResult<X>;
287
+
288
+ declare function useMultiLineChart<X extends ChartXValue = number>(props: UseMultiLineChartProps<X>): UseMultiLineChartResult<X>;
289
+
290
+ declare function createAxisTicks<Value>(values: readonly Value[], scale: LineChartScale<Value>): AxisTick<Value>[];
291
+ declare function createXAxisLayout<Value>(props: CreateAxisLayoutProps<Value>): AxisLayout<Value>;
292
+ declare function createYAxisLayout(props: CreateYAxisLayoutProps): AxisLayout<number>;
293
+ declare function createXAxisLabelRect(ticks: readonly AxisTick<unknown>[], index: number, region: ChartRect, offset: number): ChartRect;
294
+ declare function createYAxisLabelRect(position: number, region: ChartRect, width: number, fontSize: number): ChartRect;
295
+ declare function formatAxisTick<Value>(value: Value, format?: (value: Value) => string): string;
296
+
297
+ declare function createChartLayout(size: ChartSize, insets?: Partial<ChartInsets>): ChartLayout;
298
+ declare function createInsetRect(rect: ChartRect, amount: number): ChartRect;
299
+
300
+ declare function createVerticalGridPath<Value>(values: readonly Value[], scale: LineChartScale<Value>, plot: ChartRect): SkPath | null;
301
+ declare function createHorizontalGridPath<Value>(values: readonly Value[], scale: LineChartScale<Value>, plot: ChartRect): SkPath | null;
302
+ declare function resolveGridLineOptions(options: boolean | ChartGridLineOptions | undefined, defaultVisible: boolean, defaultColor: string): ResolvedGridLineOptions;
303
+
304
+ declare function getLabelTextAlign(alignment: LabelHorizontalAlignment): TextAlign;
305
+ declare function getLabelY(rect: ChartRect, paragraphHeight: number, alignment: LabelVerticalAlignment): number;
306
+
307
+ declare function createLinePath<X extends ChartXValue>(coordinates: readonly LineChartCoordinate<X>[], curve: LineChartCurve): SkPath | null;
308
+ declare function fitLineCoordinatesToRect<X extends ChartXValue>(coordinates: readonly LineChartCoordinate<X>[], source: ChartRect, target: ChartRect): LineChartCoordinate<X>[];
309
+
310
+ declare function createLineChartModel<X extends ChartXValue>(props: UseLineChartProps<X>): UseLineChartResult<X>;
311
+ declare function createLineChartCoordinates<X extends ChartXValue>(data: readonly LineChartPoint<X>[], xScale: LineChartScale<X>, yScale: LineChartScale<number>): LineChartCoordinate<X>[];
312
+
313
+ declare function createDrawableMultiLineChartSeries<X extends ChartXValue>(series: MultiLineChartSeriesModel<X>, index: number, plot: ChartRect): MultiLineChartSeriesModel<X>;
314
+
315
+ interface CreateParagraphBuilderProps {
316
+ paragraphStyle?: SkParagraphStyle;
317
+ typefaceProvider?: SkTypefaceFontProvider;
318
+ }
319
+ declare function createParagraphBuilder(props: CreateParagraphBuilderProps): _shopify_react_native_skia.SkParagraphBuilder;
320
+
321
+ export { AxisDefaultLabelGap, AxisDefaultOpacity, AxisDefaultTickLength, AxisDefaultWidth, type AxisLayout, type AxisLineLayout, type AxisProps, type AxisTick, type AxisTickLayout, type ChartAxisLabelOptions, type ChartAxisLineOptions, type ChartAxisOptions, type ChartAxisTickOptions, type ChartGridLineOptions, type ChartGridOptions, type ChartInsets, type ChartLabelStyle, type ChartLayout, type ChartNumericDomain, type ChartPoint, type ChartRect, type ChartScaleType, type ChartSize, type ChartStrokeCap, type ChartStrokeJoin, type ChartStrokeStyle, type ChartXAxisOptions, type ChartXValue, type ChartYAxisOptions, type CreateAxisLayoutProps, type CreateYAxisLayoutProps, Grid, GridDefaultOpacity, GridDefaultWidth, GridDefaultXVisible, GridDefaultYVisible, type GridProps, Label, LabelDefaultHorizontalAlignment, LabelDefaultVerticalAlignment, type LabelHorizontalAlignment, type LabelProps, type LabelVerticalAlignment, Line, LineChart, type LineChartCommonProps, type LineChartCoordinate, type LineChartCurve, LineChartDefaultNumericDomain, LineChartDefaultTickCount, type LineChartLineOptions, type LineChartPoint, type LineChartProps, type LineChartScale, type LineChartXScaleModel, LineDefaultCap, LineDefaultColor, LineDefaultColors, LineDefaultCurve, LineDefaultJoin, LineDefaultOpacity, LineDefaultWidth, type LineProps, MultiLineChart, type MultiLineChartBodyProps, type MultiLineChartProps, type MultiLineChartSeries, type MultiLineChartSeriesModel, type ResolvedGridLineOptions, TabularNumsFeature, type UseLineChartProps, type UseLineChartResult, type UseMultiLineChartProps, type UseMultiLineChartResult, XAxis, type XAxisProps, YAxis, type YAxisProps, createAxisTicks, createChartLayout, createDrawableMultiLineChartSeries, createHorizontalGridPath, createInsetRect, createLineChartCoordinates, createLineChartModel, createLinePath, createParagraphBuilder, createVerticalGridPath, createXAxisLabelRect, createXAxisLayout, createYAxisLabelRect, createYAxisLayout, fitLineCoordinatesToRect, formatAxisTick, getLabelTextAlign, getLabelY, resolveGridLineOptions, useChartCanvas, useLineChart, useMultiLineChart };