react-native-metrify 0.1.0-alpha.1 → 0.1.0-alpha.3

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 (101) hide show
  1. package/README.md +111 -51
  2. package/package.json +1 -2
  3. package/src/core/animation/index.ts +0 -113
  4. package/src/core/animation/index.web.ts +0 -112
  5. package/src/core/hooks/index.ts +0 -66
  6. package/src/core/index.ts +0 -26
  7. package/src/core/layout/index.ts +0 -101
  8. package/src/core/math/index.ts +0 -72
  9. package/src/core/package.json +0 -13
  10. package/src/core/theme/ThemeProvider.tsx +0 -36
  11. package/src/core/theme/index.ts +0 -5
  12. package/src/core/theme/themes.ts +0 -132
  13. package/src/core/types/index.ts +0 -164
  14. package/src/core/utils/responsive.ts +0 -203
  15. package/src/core/utils/time.ts +0 -100
  16. package/src/index.ts +0 -13
  17. package/src/renderer-svg/adapters/index.ts +0 -84
  18. package/src/renderer-svg/index.ts +0 -8
  19. package/src/renderer-svg/package.json +0 -17
  20. package/src/renderer-svg/paths/arc.ts +0 -93
  21. package/src/renderer-svg/paths/index.ts +0 -6
  22. package/src/renderer-svg/paths/line.ts +0 -83
  23. package/src/renderer-svg/paths/rect.ts +0 -80
  24. package/src/renderer-svg/primitives/AnimatedCircle.tsx +0 -48
  25. package/src/renderer-svg/primitives/AnimatedPath.tsx +0 -48
  26. package/src/renderer-svg/primitives/Text.tsx +0 -73
  27. package/src/renderer-svg/primitives/index.ts +0 -6
  28. package/src/widgets/AreaChart/AreaChart.tsx +0 -213
  29. package/src/widgets/AreaChart/index.ts +0 -2
  30. package/src/widgets/AreaChart/types.ts +0 -34
  31. package/src/widgets/BarChart/BarChart.tsx +0 -249
  32. package/src/widgets/BarChart/index.ts +0 -10
  33. package/src/widgets/BarChart/types.ts +0 -27
  34. package/src/widgets/BoxPlot/BoxPlot.tsx +0 -252
  35. package/src/widgets/BoxPlot/index.ts +0 -2
  36. package/src/widgets/BoxPlot/types.ts +0 -27
  37. package/src/widgets/BubbleChart/BubbleChart.tsx +0 -175
  38. package/src/widgets/BubbleChart/index.ts +0 -2
  39. package/src/widgets/BubbleChart/types.ts +0 -33
  40. package/src/widgets/CandlestickChart/CandlestickChart.tsx +0 -204
  41. package/src/widgets/CandlestickChart/index.ts +0 -2
  42. package/src/widgets/CandlestickChart/types.ts +0 -29
  43. package/src/widgets/FunnelChart/FunnelChart.tsx +0 -172
  44. package/src/widgets/FunnelChart/index.ts +0 -2
  45. package/src/widgets/FunnelChart/types.ts +0 -22
  46. package/src/widgets/Gauge/Gauge.tsx +0 -235
  47. package/src/widgets/Gauge/index.ts +0 -5
  48. package/src/widgets/Gauge/types.ts +0 -19
  49. package/src/widgets/GroupedBarChart/GroupedBarChart.tsx +0 -190
  50. package/src/widgets/GroupedBarChart/index.ts +0 -2
  51. package/src/widgets/GroupedBarChart/types.ts +0 -30
  52. package/src/widgets/Heatmap/Heatmap.tsx +0 -216
  53. package/src/widgets/Heatmap/index.ts +0 -2
  54. package/src/widgets/Heatmap/types.ts +0 -27
  55. package/src/widgets/Histogram/Histogram.tsx +0 -173
  56. package/src/widgets/Histogram/index.ts +0 -2
  57. package/src/widgets/Histogram/types.ts +0 -18
  58. package/src/widgets/HorizontalBarChart/HorizontalBarChart.tsx +0 -125
  59. package/src/widgets/HorizontalBarChart/index.ts +0 -2
  60. package/src/widgets/HorizontalBarChart/types.ts +0 -23
  61. package/src/widgets/KPI/KPI.tsx +0 -222
  62. package/src/widgets/KPI/index.ts +0 -5
  63. package/src/widgets/KPI/types.ts +0 -19
  64. package/src/widgets/LineChart/LineChart.tsx +0 -364
  65. package/src/widgets/LineChart/index.ts +0 -10
  66. package/src/widgets/LineChart/types.ts +0 -34
  67. package/src/widgets/MultiLineSparkline/MultiLineSparkline.tsx +0 -234
  68. package/src/widgets/MultiLineSparkline/index.ts +0 -10
  69. package/src/widgets/MultiLineSparkline/types.ts +0 -25
  70. package/src/widgets/PieChart/PieChart.tsx +0 -275
  71. package/src/widgets/PieChart/index.ts +0 -10
  72. package/src/widgets/PieChart/types.ts +0 -26
  73. package/src/widgets/Progress/Progress.tsx +0 -201
  74. package/src/widgets/Progress/index.ts +0 -5
  75. package/src/widgets/Progress/types.ts +0 -19
  76. package/src/widgets/RadarChart/RadarChart.tsx +0 -213
  77. package/src/widgets/RadarChart/index.ts +0 -2
  78. package/src/widgets/RadarChart/types.ts +0 -29
  79. package/src/widgets/SankeyDiagram/SankeyDiagram.tsx +0 -272
  80. package/src/widgets/SankeyDiagram/index.ts +0 -2
  81. package/src/widgets/SankeyDiagram/types.ts +0 -29
  82. package/src/widgets/ScatterPlot/ScatterPlot.tsx +0 -167
  83. package/src/widgets/ScatterPlot/index.ts +0 -2
  84. package/src/widgets/ScatterPlot/types.ts +0 -32
  85. package/src/widgets/Sparkline/Sparkline.tsx +0 -203
  86. package/src/widgets/Sparkline/index.ts +0 -5
  87. package/src/widgets/Sparkline/types.ts +0 -18
  88. package/src/widgets/StackedBarChart/StackedBarChart.tsx +0 -181
  89. package/src/widgets/StackedBarChart/index.ts +0 -2
  90. package/src/widgets/StackedBarChart/types.ts +0 -29
  91. package/src/widgets/SunburstChart/SunburstChart.tsx +0 -176
  92. package/src/widgets/SunburstChart/index.ts +0 -2
  93. package/src/widgets/SunburstChart/types.ts +0 -22
  94. package/src/widgets/Treemap/Treemap.tsx +0 -191
  95. package/src/widgets/Treemap/index.ts +0 -2
  96. package/src/widgets/Treemap/types.ts +0 -23
  97. package/src/widgets/WaterfallChart/WaterfallChart.tsx +0 -226
  98. package/src/widgets/WaterfallChart/index.ts +0 -2
  99. package/src/widgets/WaterfallChart/types.ts +0 -26
  100. package/src/widgets/index.ts +0 -40
  101. package/src/widgets/package.json +0 -18
package/README.md CHANGED
@@ -88,24 +88,48 @@ export default function Dashboard() {
88
88
  return (
89
89
  <View>
90
90
  <KPI
91
- value={1234}
92
- label="Total Sales"
93
- trend={12.5}
94
- format="currency"
91
+ data={{
92
+ value: 1234,
93
+ label: 'Total Sales',
94
+ delta: 12.5,
95
+ trend: 'up',
96
+ format: 'currency',
97
+ currency: 'USD',
98
+ }}
99
+ width={300}
100
+ height={120}
95
101
  />
96
102
 
97
103
  <LineChart
98
- data={[10, 25, 15, 40, 30, 55, 45]}
104
+ data={{
105
+ series: [{
106
+ data: [
107
+ { x: 0, y: 10 },
108
+ { x: 1, y: 25 },
109
+ { x: 2, y: 15 },
110
+ { x: 3, y: 40 },
111
+ { x: 4, y: 30 },
112
+ { x: 5, y: 55 },
113
+ { x: 6, y: 45 },
114
+ ],
115
+ color: '#007AFF',
116
+ }],
117
+ }}
99
118
  width={300}
100
119
  height={200}
101
120
  />
102
121
 
103
122
  <Gauge
104
- value={75}
105
- min={0}
106
- max={100}
123
+ data={{
124
+ value: 75,
125
+ max: 100,
126
+ label: 'Progress',
127
+ unit: '%',
128
+ }}
107
129
  width={200}
108
130
  height={200}
131
+ startAngle={-120}
132
+ endAngle={120}
109
133
  />
110
134
  </View>
111
135
  );
@@ -114,41 +138,77 @@ export default function Dashboard() {
114
138
 
115
139
  ## 📊 Available Charts
116
140
 
117
- ### Core Widgets
118
- - **KPI** - Display key metrics with trends and formatting
119
- - **Gauge** - Circular or semi-circular gauge charts
120
- - **Progress** - Linear progress bars with variants
121
- - **Sparkline** - Minimal inline charts
122
-
123
- ### Line & Area Charts
124
- - **LineChart** - Single or multi-line charts
125
- - **AreaChart** - Filled area charts
126
- - **MultiLineSparkline** - Compact multi-line visualization
127
-
128
- ### Bar Charts
129
- - **BarChart** - Vertical bar charts
130
- - **HorizontalBarChart** - Horizontal bar charts
131
- - **StackedBarChart** - Stacked bar visualization
132
- - **GroupedBarChart** - Side-by-side bars
133
- - **WaterfallChart** - Cumulative change visualization
134
-
135
- ### Distribution & Comparison
136
- - **PieChart** - Pie and donut charts
137
- - **FunnelChart** - Conversion funnel visualization
138
- - **Histogram** - Distribution frequency charts
139
- - **BoxPlot** - Statistical box and whisker plots
140
-
141
- ### Scientific & Advanced
142
- - **ScatterPlot** - X-Y scatter charts with optional bubbles
143
- - **BubbleChart** - Multi-dimensional bubble visualization
144
- - **Heatmap** - Grid-based heat intensity maps
145
- - **RadarChart** - Multi-axis spider charts
146
- - **CandlestickChart** - Financial OHLC charts
147
-
148
- ### Hierarchical & Flow
149
- - **Treemap** - Hierarchical rectangle visualization
150
- - **SunburstChart** - Radial hierarchical charts
151
- - **SankeyDiagram** - Flow and relationship visualization
141
+ ### Widget Showcase
142
+
143
+ <table>
144
+ <tr>
145
+ <td align="center" width="50%">
146
+ <img src="https://raw.githubusercontent.com/chvvkrishnakumar/react-native-metrify/main/docs/images/widgets/core-widgets.png" width="400" alt="Core Widgets"/><br/>
147
+ <b>Core Widgets</b><br/>
148
+ <sub>KPI Gauge Progress Sparkline</sub>
149
+ </td>
150
+ <td align="center" width="50%">
151
+ <img src="https://raw.githubusercontent.com/chvvkrishnakumar/react-native-metrify/main/docs/images/widgets/line-area-charts.png" width="400" alt="Line & Area Charts"/><br/>
152
+ <b>Line & Area Charts</b><br/>
153
+ <sub>LineChart AreaChart MultiLineSparkline</sub>
154
+ </td>
155
+ </tr>
156
+ <tr>
157
+ <td align="center" width="50%">
158
+ <img src="https://raw.githubusercontent.com/chvvkrishnakumar/react-native-metrify/main/docs/images/widgets/bar-charts.png" width="400" alt="Bar Charts"/><br/>
159
+ <b>Bar Charts</b><br/>
160
+ <sub>BarChart HorizontalBarChart StackedBarChart</sub>
161
+ </td>
162
+ <td align="center" width="50%">
163
+ <img src="https://raw.githubusercontent.com/chvvkrishnakumar/react-native-metrify/main/docs/images/widgets/bar-charts-2.png" width="400" alt="More Bar Charts"/><br/>
164
+ <b>More Bar Charts</b><br/>
165
+ <sub>GroupedBarChart Histogram • WaterfallChart</sub>
166
+ </td>
167
+ </tr>
168
+ <tr>
169
+ <td align="center" width="50%">
170
+ <img src="https://raw.githubusercontent.com/chvvkrishnakumar/react-native-metrify/main/docs/images/widgets/distribution-charts.png" width="400" alt="Distribution Charts"/><br/>
171
+ <b>Distribution Charts</b><br/>
172
+ <sub>PieChart FunnelChart</sub>
173
+ </td>
174
+ <td align="center" width="50%">
175
+ <img src="https://raw.githubusercontent.com/chvvkrishnakumar/react-native-metrify/main/docs/images/widgets/scientific-charts.png" width="400" alt="Scientific Charts"/><br/>
176
+ <b>Scientific Charts</b><br/>
177
+ <sub>ScatterPlot • BubbleChart • Heatmap</sub>
178
+ </td>
179
+ </tr>
180
+ <tr>
181
+ <td align="center" width="50%">
182
+ <img src="https://raw.githubusercontent.com/chvvkrishnakumar/react-native-metrify/main/docs/images/widgets/advanced-charts.png" width="400" alt="Advanced Charts"/><br/>
183
+ <b>Advanced Charts</b><br/>
184
+ <sub>RadarChart • CandlestickChart</sub>
185
+ </td>
186
+ <td align="center" width="50%">
187
+ <img src="https://raw.githubusercontent.com/chvvkrishnakumar/react-native-metrify/main/docs/images/widgets/treemap-sunburst-chart.png" width="400" alt="Hierarchical Charts"/><br/>
188
+ <b>Hierarchical Charts</b><br/>
189
+ <sub>Treemap • SunburstChart</sub>
190
+ </td>
191
+ </tr>
192
+ <tr>
193
+ <td align="center" colspan="2">
194
+ <img src="https://raw.githubusercontent.com/chvvkrishnakumar/react-native-metrify/main/docs/images/widgets/sankey-diagram.png" width="400" alt="Flow Diagram"/><br/>
195
+ <b>Flow Diagram</b><br/>
196
+ <sub>SankeyDiagram</sub>
197
+ </td>
198
+ </tr>
199
+ </table>
200
+
201
+ ### All Chart Types
202
+
203
+ **Bar Charts:** BarChart, HorizontalBarChart, StackedBarChart, GroupedBarChart, WaterfallChart, Histogram
204
+
205
+ **Line & Area:** LineChart, AreaChart, MultiLineSparkline
206
+
207
+ **Distribution:** PieChart, FunnelChart, BoxPlot
208
+
209
+ **Scientific:** ScatterPlot, BubbleChart, Heatmap, RadarChart, CandlestickChart
210
+
211
+ **Hierarchical:** Treemap, SunburstChart, SankeyDiagram
152
212
 
153
213
  ## 🎨 Theming
154
214
 
@@ -311,21 +371,21 @@ MIT © [Krishna Kumar](https://github.com/chvvkrishnakumar)
311
371
  ## 🔗 Links
312
372
 
313
373
  - [Documentation](https://github.com/chvvkrishnakumar/react-native-metrify#readme)
314
- - [Examples](./examples/)
374
+ - [Examples](https://github.com/chvvkrishnakumar/react-native-metrify/tree/main/examples/basic-demo)
315
375
  - [Changelog](./CHANGELOG.md)
316
376
  - [Issues](https://github.com/chvvkrishnakumar/react-native-metrify/issues)
317
377
 
318
378
  ## 💡 Examples
319
379
 
320
- Check out the [examples directory](./examples/expo-template/) for a full-featured demo app showcasing all chart types.
380
+ Check out the [examples directory](https://github.com/chvvkrishnakumar/react-native-metrify/tree/main/examples/basic-demo) for complete working examples:
321
381
 
322
- To run the example:
382
+ - **AllWidgetsDashboard.tsx** - All 24 widgets in one scrollable file
383
+ - **KPIExample.tsx** - 7 KPI variations
384
+ - **GaugeExample.tsx** - 6 Gauge variations
385
+ - **DashboardExample.tsx** - Real-world dashboard
386
+ - **API_REFERENCE.md** - Complete type reference
323
387
 
324
- ```bash
325
- cd examples/expo-template
326
- npm install
327
- npm start
328
- ```
388
+ Copy any example directly into your app and start using it!
329
389
 
330
390
  ---
331
391
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-metrify",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "Mobile-first SVG chart library for React Native, Expo, and React Native Web",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -14,7 +14,6 @@
14
14
  },
15
15
  "files": [
16
16
  "dist",
17
- "src",
18
17
  "README.md",
19
18
  "LICENSE",
20
19
  "CHANGELOG.md"
@@ -1,113 +0,0 @@
1
- /**
2
- * Animation helpers - Simple version without reanimated
3
- * For full animation support, use react-native-reanimated separately
4
- */
5
- import { useEffect } from 'react';
6
- import { AnimationConfig } from '../types';
7
-
8
- // Type for shared value (compatible with reanimated)
9
- export type SharedValue<T = number> = { value: T };
10
-
11
- // Simple implementations (no animations, just values)
12
- export const useSharedValue = <T = number>(initialValue: T): SharedValue<T> => {
13
- return { value: initialValue };
14
- };
15
-
16
- export const withTiming = (value: any, config?: any) => value;
17
- export const withSpring = (value: any, config?: any) => value;
18
-
19
- export const Easing = {
20
- linear: (t: number) => t,
21
- ease: (t: number) => t,
22
- quad: (t: number) => t * t,
23
- cubic: (t: number) => t * t * t,
24
- bezier: (x1: number, y1: number, x2: number, y2: number) => (t: number) => t,
25
- in: (easing: (t: number) => number) => easing,
26
- out: (easing: (t: number) => number) => (t: number) => 1 - easing(1 - t),
27
- inOut: (easing: (t: number) => number) => (t: number) =>
28
- t < 0.5 ? easing(t * 2) / 2 : 1 - easing((1 - t) * 2) / 2,
29
- };
30
-
31
- /**
32
- * Default timing configuration
33
- */
34
- export const DEFAULT_TIMING_CONFIG = {
35
- duration: 300,
36
- easing: Easing.out(Easing.cubic),
37
- };
38
-
39
- /**
40
- * Default spring configuration
41
- */
42
- export const DEFAULT_SPRING_CONFIG = {
43
- damping: 15,
44
- stiffness: 150,
45
- mass: 1,
46
- };
47
-
48
- /**
49
- * Hook that creates an animated value that transitions to a target
50
- * @param target - Target value to animate to
51
- * @param config - Animation configuration
52
- */
53
- export function useAnimatedValue(
54
- target: number,
55
- config: AnimationConfig = {}
56
- ): SharedValue<number> {
57
- const animatedValue = useSharedValue(target);
58
-
59
- useEffect(() => {
60
- animatedValue.value = withTiming(target, {
61
- duration: config.duration ?? DEFAULT_TIMING_CONFIG.duration,
62
- easing: DEFAULT_TIMING_CONFIG.easing,
63
- });
64
- }, [target, config.duration, animatedValue]);
65
-
66
- return animatedValue;
67
- }
68
-
69
- /**
70
- * Hook that creates an animated progress value (0 to normalized)
71
- * @param value - Current value
72
- * @param max - Maximum value
73
- * @param config - Animation configuration
74
- */
75
- export function useAnimatedProgress(
76
- value: number,
77
- max: number,
78
- config: AnimationConfig = {}
79
- ): SharedValue<number> {
80
- const normalized = max > 0 ? Math.min(value / max, 1) : 0;
81
- return useAnimatedValue(normalized, config);
82
- }
83
-
84
- /**
85
- * Hook that creates a spring-animated value
86
- * @param target - Target value to animate to
87
- */
88
- export function useSpringValue(target: number): SharedValue<number> {
89
- const animatedValue = useSharedValue(target);
90
-
91
- useEffect(() => {
92
- animatedValue.value = withSpring(target, DEFAULT_SPRING_CONFIG);
93
- }, [target, animatedValue]);
94
-
95
- return animatedValue;
96
- }
97
-
98
- /**
99
- * Creates timing config for manual animations
100
- */
101
- export function useTimingConfig(config: AnimationConfig = {}) {
102
- return {
103
- duration: config.duration ?? DEFAULT_TIMING_CONFIG.duration,
104
- easing: DEFAULT_TIMING_CONFIG.easing,
105
- };
106
- }
107
-
108
- /**
109
- * Creates spring config for manual animations
110
- */
111
- export function useSpringConfig() {
112
- return DEFAULT_SPRING_CONFIG;
113
- }
@@ -1,112 +0,0 @@
1
- /**
2
- * Animation helpers for widgets (Web version - no reanimated)
3
- * Uses basic React state for web compatibility
4
- */
5
- import { useEffect } from 'react';
6
- import { AnimationConfig } from '../types';
7
-
8
- // Type for shared value (web compatible)
9
- export type SharedValue<T> = { value: T };
10
-
11
- // Web-compatible stubs for reanimated functions
12
- export const useSharedValue = <T,>(initialValue: T): SharedValue<T> => {
13
- return { value: initialValue };
14
- };
15
-
16
- export const withTiming = (value: number, config?: any) => {
17
- return value;
18
- };
19
-
20
- export const withSpring = (value: number, config?: any) => {
21
- return value;
22
- };
23
-
24
- export const withDelay = (delay: number, animation: any) => {
25
- return animation;
26
- };
27
-
28
- export const withSequence = (...animations: any[]) => {
29
- return animations[animations.length - 1];
30
- };
31
-
32
- export const withRepeat = (animation: any, numberOfReps?: number, reverse?: boolean) => {
33
- return animation;
34
- };
35
-
36
- export const Easing = {
37
- linear: (t: number) => t,
38
- ease: (t: number) => t,
39
- quad: (t: number) => t * t,
40
- cubic: (t: number) => t * t * t,
41
- bezier: (x1: number, y1: number, x2: number, y2: number) => (t: number) => t,
42
- in: (easing: (t: number) => number) => easing,
43
- out: (easing: (t: number) => number) => (t: number) => 1 - easing(1 - t),
44
- inOut: (easing: (t: number) => number) => (t: number) =>
45
- t < 0.5 ? easing(t * 2) / 2 : 1 - easing((1 - t) * 2) / 2,
46
- };
47
-
48
- /**
49
- * Default timing configuration
50
- */
51
- export const DEFAULT_TIMING_CONFIG = {
52
- duration: 300,
53
- easing: Easing.linear,
54
- };
55
-
56
- /**
57
- * Default spring configuration
58
- */
59
- export const DEFAULT_SPRING_CONFIG = {
60
- damping: 15,
61
- stiffness: 150,
62
- mass: 1,
63
- };
64
-
65
- /**
66
- * Hook to animate value changes (web version)
67
- */
68
- export function useAnimatedValue(
69
- target: number,
70
- config: AnimationConfig = {}
71
- ): SharedValue<number> {
72
- // On web, just return the value directly
73
- // Full animation support requires additional setup
74
- return useSharedValue(target);
75
- }
76
-
77
- /**
78
- * Hook that creates an animated progress value (0 to normalized)
79
- */
80
- export function useAnimatedProgress(
81
- value: number,
82
- max: number,
83
- config: AnimationConfig = {}
84
- ): SharedValue<number> {
85
- const normalized = max > 0 ? Math.min(value / max, 1) : 0;
86
- return useAnimatedValue(normalized, config);
87
- }
88
-
89
- /**
90
- * Hook that creates a spring-animated value
91
- */
92
- export function useSpringValue(target: number): SharedValue<number> {
93
- return useSharedValue(target);
94
- }
95
-
96
- /**
97
- * Creates timing config for manual animations
98
- */
99
- export function useTimingConfig(config: AnimationConfig = {}) {
100
- return {
101
- duration: config.duration ?? DEFAULT_TIMING_CONFIG.duration,
102
- easing: DEFAULT_TIMING_CONFIG.easing,
103
- };
104
- }
105
-
106
- /**
107
- * Creates spring config for manual animations
108
- */
109
- export function useSpringConfig() {
110
- return DEFAULT_SPRING_CONFIG;
111
- }
112
-
@@ -1,66 +0,0 @@
1
- /**
2
- * Reusable hooks for widgets
3
- */
4
- import { useMemo } from 'react';
5
- import { Theme } from '../types';
6
- import { useTheme } from '../theme';
7
-
8
- /**
9
- * Hook to get widget dimensions with defaults
10
- */
11
- export function useWidgetDimensions(
12
- width?: number,
13
- height?: number,
14
- defaultWidth: number = 300,
15
- defaultHeight: number = 200
16
- ) {
17
- return useMemo(
18
- () => ({
19
- width: width ?? defaultWidth,
20
- height: height ?? defaultHeight,
21
- }),
22
- [width, height, defaultWidth, defaultHeight]
23
- );
24
- }
25
-
26
- /**
27
- * Hook to merge theme overrides
28
- */
29
- export function useWidgetTheme(themeOverride?: Theme): Theme {
30
- const contextTheme = useTheme();
31
- return themeOverride ?? contextTheme;
32
- }
33
-
34
- /**
35
- * Hook for widget padding calculations
36
- */
37
- export function useWidgetPadding(theme: Theme) {
38
- return useMemo(
39
- () => ({
40
- top: theme.spacing.md,
41
- right: theme.spacing.md,
42
- bottom: theme.spacing.md,
43
- left: theme.spacing.md,
44
- horizontal: theme.spacing.md * 2,
45
- vertical: theme.spacing.md * 2,
46
- }),
47
- [theme.spacing.md]
48
- );
49
- }
50
-
51
- /**
52
- * Hook to calculate inner dimensions after padding
53
- */
54
- export function useInnerDimensions(
55
- width: number,
56
- height: number,
57
- padding: { horizontal: number; vertical: number }
58
- ) {
59
- return useMemo(
60
- () => ({
61
- width: Math.max(0, width - padding.horizontal),
62
- height: Math.max(0, height - padding.vertical),
63
- }),
64
- [width, height, padding.horizontal, padding.vertical]
65
- );
66
- }
package/src/core/index.ts DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * Core package - Foundation for all widgets
3
- * NO SVG dependencies allowed here
4
- */
5
-
6
- // Math utilities
7
- export * from './math';
8
-
9
- // Layout utilities
10
- export * from './layout';
11
-
12
- // Theme system
13
- export * from './theme';
14
-
15
- // Animation helpers
16
- export * from './animation';
17
-
18
- // Hooks
19
- export * from './hooks';
20
-
21
- // Types
22
- export * from './types';
23
-
24
- // Utils
25
- export * from './utils/time';
26
- export * from './utils/responsive';
@@ -1,101 +0,0 @@
1
- /**
2
- * Layout utilities for widget positioning and sizing
3
- */
4
-
5
- export interface Box {
6
- x: number;
7
- y: number;
8
- width: number;
9
- height: number;
10
- }
11
-
12
- export interface Point {
13
- x: number;
14
- y: number;
15
- }
16
-
17
- /**
18
- * Calculate center point of a box
19
- */
20
- export function getCenter(box: Box): Point {
21
- return {
22
- x: box.x + box.width / 2,
23
- y: box.y + box.height / 2,
24
- };
25
- }
26
-
27
- /**
28
- * Calculate bounding box for a set of points
29
- */
30
- export function getBoundingBox(points: Point[]): Box {
31
- if (points.length === 0) {
32
- return { x: 0, y: 0, width: 0, height: 0 };
33
- }
34
-
35
- const xs = points.map(p => p.x);
36
- const ys = points.map(p => p.y);
37
-
38
- const minX = Math.min(...xs);
39
- const maxX = Math.max(...xs);
40
- const minY = Math.min(...ys);
41
- const maxY = Math.max(...ys);
42
-
43
- return {
44
- x: minX,
45
- y: minY,
46
- width: maxX - minX,
47
- height: maxY - minY,
48
- };
49
- }
50
-
51
- /**
52
- * Apply padding to a box
53
- */
54
- export function applyPadding(
55
- box: Box,
56
- padding: { top: number; right: number; bottom: number; left: number }
57
- ): Box {
58
- return {
59
- x: box.x + padding.left,
60
- y: box.y + padding.top,
61
- width: Math.max(0, box.width - padding.left - padding.right),
62
- height: Math.max(0, box.height - padding.top - padding.bottom),
63
- };
64
- }
65
-
66
- /**
67
- * Calculate aspect ratio
68
- */
69
- export function getAspectRatio(width: number, height: number): number {
70
- return height > 0 ? width / height : 1;
71
- }
72
-
73
- /**
74
- * Scale box to fit within constraints while maintaining aspect ratio
75
- */
76
- export function fitBox(
77
- box: Box,
78
- maxWidth: number,
79
- maxHeight: number
80
- ): Box {
81
- const aspectRatio = getAspectRatio(box.width, box.height);
82
- const maxAspectRatio = getAspectRatio(maxWidth, maxHeight);
83
-
84
- let width = maxWidth;
85
- let height = maxHeight;
86
-
87
- if (aspectRatio > maxAspectRatio) {
88
- // Box is wider than container
89
- height = width / aspectRatio;
90
- } else {
91
- // Box is taller than container
92
- width = height * aspectRatio;
93
- }
94
-
95
- return {
96
- x: box.x,
97
- y: box.y,
98
- width,
99
- height,
100
- };
101
- }