react-native-metrify 0.1.0-alpha.1 → 0.1.0-alpha.2
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/package.json +1 -2
- package/src/core/animation/index.ts +0 -113
- package/src/core/animation/index.web.ts +0 -112
- package/src/core/hooks/index.ts +0 -66
- package/src/core/index.ts +0 -26
- package/src/core/layout/index.ts +0 -101
- package/src/core/math/index.ts +0 -72
- package/src/core/package.json +0 -13
- package/src/core/theme/ThemeProvider.tsx +0 -36
- package/src/core/theme/index.ts +0 -5
- package/src/core/theme/themes.ts +0 -132
- package/src/core/types/index.ts +0 -164
- package/src/core/utils/responsive.ts +0 -203
- package/src/core/utils/time.ts +0 -100
- package/src/index.ts +0 -13
- package/src/renderer-svg/adapters/index.ts +0 -84
- package/src/renderer-svg/index.ts +0 -8
- package/src/renderer-svg/package.json +0 -17
- package/src/renderer-svg/paths/arc.ts +0 -93
- package/src/renderer-svg/paths/index.ts +0 -6
- package/src/renderer-svg/paths/line.ts +0 -83
- package/src/renderer-svg/paths/rect.ts +0 -80
- package/src/renderer-svg/primitives/AnimatedCircle.tsx +0 -48
- package/src/renderer-svg/primitives/AnimatedPath.tsx +0 -48
- package/src/renderer-svg/primitives/Text.tsx +0 -73
- package/src/renderer-svg/primitives/index.ts +0 -6
- package/src/widgets/AreaChart/AreaChart.tsx +0 -213
- package/src/widgets/AreaChart/index.ts +0 -2
- package/src/widgets/AreaChart/types.ts +0 -34
- package/src/widgets/BarChart/BarChart.tsx +0 -249
- package/src/widgets/BarChart/index.ts +0 -10
- package/src/widgets/BarChart/types.ts +0 -27
- package/src/widgets/BoxPlot/BoxPlot.tsx +0 -252
- package/src/widgets/BoxPlot/index.ts +0 -2
- package/src/widgets/BoxPlot/types.ts +0 -27
- package/src/widgets/BubbleChart/BubbleChart.tsx +0 -175
- package/src/widgets/BubbleChart/index.ts +0 -2
- package/src/widgets/BubbleChart/types.ts +0 -33
- package/src/widgets/CandlestickChart/CandlestickChart.tsx +0 -204
- package/src/widgets/CandlestickChart/index.ts +0 -2
- package/src/widgets/CandlestickChart/types.ts +0 -29
- package/src/widgets/FunnelChart/FunnelChart.tsx +0 -172
- package/src/widgets/FunnelChart/index.ts +0 -2
- package/src/widgets/FunnelChart/types.ts +0 -22
- package/src/widgets/Gauge/Gauge.tsx +0 -235
- package/src/widgets/Gauge/index.ts +0 -5
- package/src/widgets/Gauge/types.ts +0 -19
- package/src/widgets/GroupedBarChart/GroupedBarChart.tsx +0 -190
- package/src/widgets/GroupedBarChart/index.ts +0 -2
- package/src/widgets/GroupedBarChart/types.ts +0 -30
- package/src/widgets/Heatmap/Heatmap.tsx +0 -216
- package/src/widgets/Heatmap/index.ts +0 -2
- package/src/widgets/Heatmap/types.ts +0 -27
- package/src/widgets/Histogram/Histogram.tsx +0 -173
- package/src/widgets/Histogram/index.ts +0 -2
- package/src/widgets/Histogram/types.ts +0 -18
- package/src/widgets/HorizontalBarChart/HorizontalBarChart.tsx +0 -125
- package/src/widgets/HorizontalBarChart/index.ts +0 -2
- package/src/widgets/HorizontalBarChart/types.ts +0 -23
- package/src/widgets/KPI/KPI.tsx +0 -222
- package/src/widgets/KPI/index.ts +0 -5
- package/src/widgets/KPI/types.ts +0 -19
- package/src/widgets/LineChart/LineChart.tsx +0 -364
- package/src/widgets/LineChart/index.ts +0 -10
- package/src/widgets/LineChart/types.ts +0 -34
- package/src/widgets/MultiLineSparkline/MultiLineSparkline.tsx +0 -234
- package/src/widgets/MultiLineSparkline/index.ts +0 -10
- package/src/widgets/MultiLineSparkline/types.ts +0 -25
- package/src/widgets/PieChart/PieChart.tsx +0 -275
- package/src/widgets/PieChart/index.ts +0 -10
- package/src/widgets/PieChart/types.ts +0 -26
- package/src/widgets/Progress/Progress.tsx +0 -201
- package/src/widgets/Progress/index.ts +0 -5
- package/src/widgets/Progress/types.ts +0 -19
- package/src/widgets/RadarChart/RadarChart.tsx +0 -213
- package/src/widgets/RadarChart/index.ts +0 -2
- package/src/widgets/RadarChart/types.ts +0 -29
- package/src/widgets/SankeyDiagram/SankeyDiagram.tsx +0 -272
- package/src/widgets/SankeyDiagram/index.ts +0 -2
- package/src/widgets/SankeyDiagram/types.ts +0 -29
- package/src/widgets/ScatterPlot/ScatterPlot.tsx +0 -167
- package/src/widgets/ScatterPlot/index.ts +0 -2
- package/src/widgets/ScatterPlot/types.ts +0 -32
- package/src/widgets/Sparkline/Sparkline.tsx +0 -203
- package/src/widgets/Sparkline/index.ts +0 -5
- package/src/widgets/Sparkline/types.ts +0 -18
- package/src/widgets/StackedBarChart/StackedBarChart.tsx +0 -181
- package/src/widgets/StackedBarChart/index.ts +0 -2
- package/src/widgets/StackedBarChart/types.ts +0 -29
- package/src/widgets/SunburstChart/SunburstChart.tsx +0 -176
- package/src/widgets/SunburstChart/index.ts +0 -2
- package/src/widgets/SunburstChart/types.ts +0 -22
- package/src/widgets/Treemap/Treemap.tsx +0 -191
- package/src/widgets/Treemap/index.ts +0 -2
- package/src/widgets/Treemap/types.ts +0 -23
- package/src/widgets/WaterfallChart/WaterfallChart.tsx +0 -226
- package/src/widgets/WaterfallChart/index.ts +0 -2
- package/src/widgets/WaterfallChart/types.ts +0 -26
- package/src/widgets/index.ts +0 -40
- package/src/widgets/package.json +0 -18
package/src/core/types/index.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core type definitions for dashboard widgets
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Theme color palette
|
|
7
|
-
*/
|
|
8
|
-
export interface ThemeColors {
|
|
9
|
-
// Primary colors
|
|
10
|
-
primary: string;
|
|
11
|
-
secondary: string;
|
|
12
|
-
accent: string;
|
|
13
|
-
|
|
14
|
-
// Semantic colors
|
|
15
|
-
success: string;
|
|
16
|
-
warning: string;
|
|
17
|
-
error: string;
|
|
18
|
-
info: string;
|
|
19
|
-
|
|
20
|
-
// Background colors
|
|
21
|
-
background: string;
|
|
22
|
-
surface: string;
|
|
23
|
-
overlay: string;
|
|
24
|
-
|
|
25
|
-
// Text colors
|
|
26
|
-
text: string;
|
|
27
|
-
textSecondary: string;
|
|
28
|
-
textDisabled: string;
|
|
29
|
-
|
|
30
|
-
// Border colors
|
|
31
|
-
border: string;
|
|
32
|
-
borderLight: string;
|
|
33
|
-
|
|
34
|
-
// Chart colors
|
|
35
|
-
chartPrimary: string;
|
|
36
|
-
chartSecondary: string;
|
|
37
|
-
chartTertiary: string;
|
|
38
|
-
chartQuaternary: string;
|
|
39
|
-
chartPositive: string;
|
|
40
|
-
chartNegative: string;
|
|
41
|
-
chartNeutral: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Theme spacing scale
|
|
46
|
-
*/
|
|
47
|
-
export interface ThemeSpacing {
|
|
48
|
-
xs: number;
|
|
49
|
-
sm: number;
|
|
50
|
-
md: number;
|
|
51
|
-
lg: number;
|
|
52
|
-
xl: number;
|
|
53
|
-
xxl: number;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Theme border radius scale
|
|
58
|
-
*/
|
|
59
|
-
export interface ThemeRadius {
|
|
60
|
-
none: number;
|
|
61
|
-
sm: number;
|
|
62
|
-
md: number;
|
|
63
|
-
lg: number;
|
|
64
|
-
full: number;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Theme font scale
|
|
69
|
-
*/
|
|
70
|
-
export interface ThemeFontScale {
|
|
71
|
-
xs: number;
|
|
72
|
-
sm: number;
|
|
73
|
-
md: number;
|
|
74
|
-
lg: number;
|
|
75
|
-
xl: number;
|
|
76
|
-
xxl: number;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Complete theme definition
|
|
81
|
-
*/
|
|
82
|
-
export interface Theme {
|
|
83
|
-
colors: ThemeColors;
|
|
84
|
-
spacing: ThemeSpacing;
|
|
85
|
-
radius: ThemeRadius;
|
|
86
|
-
fontScale: ThemeFontScale;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Widget loading states
|
|
91
|
-
*/
|
|
92
|
-
export type WidgetState = 'idle' | 'loading' | 'error' | 'empty';
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Trend direction
|
|
96
|
-
*/
|
|
97
|
-
export type TrendDirection = 'up' | 'down' | 'neutral';
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Font size configuration for widgets
|
|
101
|
-
*/
|
|
102
|
-
export interface FontSizeConfig {
|
|
103
|
-
/**
|
|
104
|
-
* Custom font size for labels
|
|
105
|
-
*/
|
|
106
|
-
labelSize?: number;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Custom font size for values
|
|
110
|
-
*/
|
|
111
|
-
valueSize?: number;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Custom font size for secondary text
|
|
115
|
-
*/
|
|
116
|
-
secondarySize?: number;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Enable/disable responsive font scaling (default: true)
|
|
120
|
-
*/
|
|
121
|
-
responsive?: boolean;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Minimum font size when responsive scaling is enabled
|
|
125
|
-
*/
|
|
126
|
-
minSize?: number;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Maximum font size when responsive scaling is enabled
|
|
130
|
-
*/
|
|
131
|
-
maxSize?: number;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Base props shared by all widgets
|
|
136
|
-
*/
|
|
137
|
-
export interface BaseWidgetProps<T = unknown> {
|
|
138
|
-
data: T;
|
|
139
|
-
width?: number;
|
|
140
|
-
height?: number;
|
|
141
|
-
loading?: boolean;
|
|
142
|
-
theme?: Theme;
|
|
143
|
-
animated?: boolean;
|
|
144
|
-
testID?: string;
|
|
145
|
-
/**
|
|
146
|
-
* Font size configuration
|
|
147
|
-
*/
|
|
148
|
-
fontSize?: FontSizeConfig;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Animation configuration
|
|
153
|
-
*/
|
|
154
|
-
export interface AnimationConfig {
|
|
155
|
-
duration?: number;
|
|
156
|
-
easing?: 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
|
|
157
|
-
delay?: number;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Time interval types
|
|
162
|
-
* Note: Also exported from utils/time.ts - using that as the main export
|
|
163
|
-
*/
|
|
164
|
-
// export type TimeInterval = 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Responsive sizing utilities for widgets
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { FontSizeConfig } from '../types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Scale factor type for responsive sizing
|
|
9
|
-
*/
|
|
10
|
-
export type ScaleFactor = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Base font sizes - used as reference for scaling
|
|
14
|
-
*/
|
|
15
|
-
const BASE_FONT_SIZES = {
|
|
16
|
-
xs: 10,
|
|
17
|
-
sm: 12,
|
|
18
|
-
md: 14,
|
|
19
|
-
lg: 18,
|
|
20
|
-
xl: 24,
|
|
21
|
-
xxl: 32,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Calculate responsive font size based on widget dimensions
|
|
26
|
-
*
|
|
27
|
-
* @param baseFontSize - Base font size (from theme or custom)
|
|
28
|
-
* @param width - Widget width
|
|
29
|
-
* @param height - Widget height
|
|
30
|
-
* @param referenceSize - Reference dimension (default: 300 for width-based scaling)
|
|
31
|
-
* @returns Scaled font size
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* // For a widget that's 150px wide (half of reference 300px)
|
|
35
|
-
* getResponsiveFontSize(16, 150, 100, 300) // Returns 8 (50% of 16)
|
|
36
|
-
*
|
|
37
|
-
* // For a widget that's 600px wide (2x reference)
|
|
38
|
-
* getResponsiveFontSize(16, 600, 200, 300) // Returns 32 (200% of 16)
|
|
39
|
-
*/
|
|
40
|
-
export function getResponsiveFontSize(
|
|
41
|
-
baseFontSize: number,
|
|
42
|
-
width: number,
|
|
43
|
-
height: number,
|
|
44
|
-
referenceSize: number = 300
|
|
45
|
-
): number {
|
|
46
|
-
// Use the smaller dimension to ensure text fits in both directions
|
|
47
|
-
const dimension = Math.min(width, height);
|
|
48
|
-
const scaleFactor = dimension / referenceSize;
|
|
49
|
-
|
|
50
|
-
// Clamp the scale factor to prevent text from becoming too small or too large
|
|
51
|
-
const clampedScale = Math.max(0.5, Math.min(scaleFactor, 2.5));
|
|
52
|
-
|
|
53
|
-
return Math.round(baseFontSize * clampedScale);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Get scaled font sizes for all scale factors
|
|
58
|
-
*
|
|
59
|
-
* @param width - Widget width
|
|
60
|
-
* @param height - Widget height
|
|
61
|
-
* @param referenceSize - Reference dimension for scaling
|
|
62
|
-
* @returns Object with scaled font sizes for each scale factor
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* const fontSizes = getScaledFontSizes(150, 100, 300);
|
|
66
|
-
* // Returns: { xs: 5, sm: 6, md: 7, lg: 9, xl: 12, xxl: 16 }
|
|
67
|
-
*/
|
|
68
|
-
export function getScaledFontSizes(
|
|
69
|
-
width: number,
|
|
70
|
-
height: number,
|
|
71
|
-
referenceSize: number = 300
|
|
72
|
-
): Record<ScaleFactor, number> {
|
|
73
|
-
return {
|
|
74
|
-
xs: getResponsiveFontSize(BASE_FONT_SIZES.xs, width, height, referenceSize),
|
|
75
|
-
sm: getResponsiveFontSize(BASE_FONT_SIZES.sm, width, height, referenceSize),
|
|
76
|
-
md: getResponsiveFontSize(BASE_FONT_SIZES.md, width, height, referenceSize),
|
|
77
|
-
lg: getResponsiveFontSize(BASE_FONT_SIZES.lg, width, height, referenceSize),
|
|
78
|
-
xl: getResponsiveFontSize(BASE_FONT_SIZES.xl, width, height, referenceSize),
|
|
79
|
-
xxl: getResponsiveFontSize(BASE_FONT_SIZES.xxl, width, height, referenceSize),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Options for responsive font scaling
|
|
85
|
-
*/
|
|
86
|
-
export interface ResponsiveFontOptions {
|
|
87
|
-
/**
|
|
88
|
-
* Enable/disable responsive scaling (default: true)
|
|
89
|
-
*/
|
|
90
|
-
enabled?: boolean;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Minimum font size to prevent text from becoming unreadable
|
|
94
|
-
*/
|
|
95
|
-
minSize?: number;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Maximum font size to prevent text from becoming too large
|
|
99
|
-
*/
|
|
100
|
-
maxSize?: number;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Reference size for scaling calculations (default: 300)
|
|
104
|
-
*/
|
|
105
|
-
referenceSize?: number;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Calculate font size with options
|
|
110
|
-
*
|
|
111
|
-
* @param baseFontSize - Base font size
|
|
112
|
-
* @param width - Widget width
|
|
113
|
-
* @param height - Widget height
|
|
114
|
-
* @param options - Responsive font options
|
|
115
|
-
* @returns Calculated font size
|
|
116
|
-
*/
|
|
117
|
-
export function calculateFontSize(
|
|
118
|
-
baseFontSize: number,
|
|
119
|
-
width: number,
|
|
120
|
-
height: number,
|
|
121
|
-
options: ResponsiveFontOptions = {}
|
|
122
|
-
): number {
|
|
123
|
-
const {
|
|
124
|
-
enabled = true,
|
|
125
|
-
minSize = 8,
|
|
126
|
-
maxSize = 48,
|
|
127
|
-
referenceSize = 300,
|
|
128
|
-
} = options;
|
|
129
|
-
|
|
130
|
-
// If responsive scaling is disabled, return base size
|
|
131
|
-
if (!enabled) {
|
|
132
|
-
return baseFontSize;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Calculate responsive size
|
|
136
|
-
const responsiveSize = getResponsiveFontSize(
|
|
137
|
-
baseFontSize,
|
|
138
|
-
width,
|
|
139
|
-
height,
|
|
140
|
-
referenceSize
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
// Apply min/max constraints
|
|
144
|
-
return Math.max(minSize, Math.min(responsiveSize, maxSize));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Create font size calculator for a widget
|
|
149
|
-
*
|
|
150
|
-
* @param width - Widget width
|
|
151
|
-
* @param height - Widget height
|
|
152
|
-
* @param fontConfig - Font size configuration from props
|
|
153
|
-
* @returns Function to calculate responsive font sizes
|
|
154
|
-
*/
|
|
155
|
-
export function createFontSizeCalculator(
|
|
156
|
-
width: number,
|
|
157
|
-
height: number,
|
|
158
|
-
fontConfig: FontSizeConfig = {}
|
|
159
|
-
) {
|
|
160
|
-
const {
|
|
161
|
-
responsive = true,
|
|
162
|
-
minSize = 8,
|
|
163
|
-
maxSize = 48,
|
|
164
|
-
} = fontConfig;
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
/**
|
|
168
|
-
* Get font size for labels
|
|
169
|
-
*/
|
|
170
|
-
label: (baseFontSize: number): number => {
|
|
171
|
-
return fontConfig.labelSize ?? calculateFontSize(
|
|
172
|
-
baseFontSize,
|
|
173
|
-
width,
|
|
174
|
-
height,
|
|
175
|
-
{ enabled: responsive, minSize, maxSize }
|
|
176
|
-
);
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Get font size for values
|
|
181
|
-
*/
|
|
182
|
-
value: (baseFontSize: number): number => {
|
|
183
|
-
return fontConfig.valueSize ?? calculateFontSize(
|
|
184
|
-
baseFontSize,
|
|
185
|
-
width,
|
|
186
|
-
height,
|
|
187
|
-
{ enabled: responsive, minSize, maxSize }
|
|
188
|
-
);
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Get font size for secondary text
|
|
193
|
-
*/
|
|
194
|
-
secondary: (baseFontSize: number): number => {
|
|
195
|
-
return fontConfig.secondarySize ?? calculateFontSize(
|
|
196
|
-
baseFontSize,
|
|
197
|
-
width,
|
|
198
|
-
height,
|
|
199
|
-
{ enabled: responsive, minSize, maxSize }
|
|
200
|
-
);
|
|
201
|
-
},
|
|
202
|
-
};
|
|
203
|
-
}
|
package/src/core/utils/time.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Time formatting utilities for chart labels
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export type TimeInterval = 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Format date based on interval
|
|
9
|
-
*/
|
|
10
|
-
export function formatTimeLabel(date: Date, interval: TimeInterval): string {
|
|
11
|
-
switch (interval) {
|
|
12
|
-
case 'minute':
|
|
13
|
-
return date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
|
|
14
|
-
|
|
15
|
-
case 'hour':
|
|
16
|
-
return date.toLocaleTimeString('en-US', { hour: '2-digit' });
|
|
17
|
-
|
|
18
|
-
case 'day':
|
|
19
|
-
return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
|
|
20
|
-
|
|
21
|
-
case 'week':
|
|
22
|
-
return `Week ${getWeekNumber(date)}`;
|
|
23
|
-
|
|
24
|
-
case 'month':
|
|
25
|
-
return date.toLocaleDateString('en-US', { month: 'short', year: 'numeric' });
|
|
26
|
-
|
|
27
|
-
case 'year':
|
|
28
|
-
return date.getFullYear().toString();
|
|
29
|
-
|
|
30
|
-
default:
|
|
31
|
-
return date.toLocaleDateString();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Get week number of year
|
|
37
|
-
*/
|
|
38
|
-
function getWeekNumber(date: Date): number {
|
|
39
|
-
const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
|
|
40
|
-
const pastDaysOfYear = (date.getTime() - firstDayOfYear.getTime()) / 86400000;
|
|
41
|
-
return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Generate array of dates for a time range
|
|
46
|
-
*/
|
|
47
|
-
export function generateTimeLabels(
|
|
48
|
-
start: Date,
|
|
49
|
-
count: number,
|
|
50
|
-
interval: TimeInterval
|
|
51
|
-
): string[] {
|
|
52
|
-
const labels: string[] = [];
|
|
53
|
-
const current = new Date(start);
|
|
54
|
-
|
|
55
|
-
for (let i = 0; i < count; i++) {
|
|
56
|
-
labels.push(formatTimeLabel(current, interval));
|
|
57
|
-
|
|
58
|
-
// Increment based on interval
|
|
59
|
-
switch (interval) {
|
|
60
|
-
case 'minute':
|
|
61
|
-
current.setMinutes(current.getMinutes() + 1);
|
|
62
|
-
break;
|
|
63
|
-
case 'hour':
|
|
64
|
-
current.setHours(current.getHours() + 1);
|
|
65
|
-
break;
|
|
66
|
-
case 'day':
|
|
67
|
-
current.setDate(current.getDate() + 1);
|
|
68
|
-
break;
|
|
69
|
-
case 'week':
|
|
70
|
-
current.setDate(current.getDate() + 7);
|
|
71
|
-
break;
|
|
72
|
-
case 'month':
|
|
73
|
-
current.setMonth(current.getMonth() + 1);
|
|
74
|
-
break;
|
|
75
|
-
case 'year':
|
|
76
|
-
current.setFullYear(current.getFullYear() + 1);
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return labels;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Reduce labels to fit width (show every Nth label)
|
|
86
|
-
*/
|
|
87
|
-
export function reduceLabels(labels: string[], maxLabels: number): { label: string; index: number }[] {
|
|
88
|
-
if (labels.length <= maxLabels) {
|
|
89
|
-
return labels.map((label, index) => ({ label, index }));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const step = Math.ceil(labels.length / maxLabels);
|
|
93
|
-
const reduced: { label: string; index: number }[] = [];
|
|
94
|
-
|
|
95
|
-
for (let i = 0; i < labels.length; i += step) {
|
|
96
|
-
reduced.push({ label: labels[i], index: i });
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return reduced;
|
|
100
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dashboard Widgets - Main entry point
|
|
3
|
-
* Mobile-first dashboard widget library for React Native
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Core exports
|
|
7
|
-
export * from './core';
|
|
8
|
-
|
|
9
|
-
// Widget exports
|
|
10
|
-
export * from './widgets';
|
|
11
|
-
|
|
12
|
-
// Version
|
|
13
|
-
export const VERSION = '0.1.0';
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapters for bridging core utilities with SVG rendering
|
|
3
|
-
*/
|
|
4
|
-
import { Point } from '../../core/layout';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Converts data array to SVG points
|
|
8
|
-
*/
|
|
9
|
-
export function dataToPoints(
|
|
10
|
-
data: number[],
|
|
11
|
-
width: number,
|
|
12
|
-
height: number,
|
|
13
|
-
padding: number = 0
|
|
14
|
-
): Point[] {
|
|
15
|
-
if (data.length === 0) return [];
|
|
16
|
-
|
|
17
|
-
const min = Math.min(...data);
|
|
18
|
-
const max = Math.max(...data);
|
|
19
|
-
const range = max - min || 1;
|
|
20
|
-
|
|
21
|
-
const innerWidth = width - padding * 2;
|
|
22
|
-
const innerHeight = height - padding * 2;
|
|
23
|
-
const stepX = data.length > 1 ? innerWidth / (data.length - 1) : 0;
|
|
24
|
-
|
|
25
|
-
return data.map((value, index) => {
|
|
26
|
-
const normalizedY = (value - min) / range;
|
|
27
|
-
return {
|
|
28
|
-
x: padding + index * stepX,
|
|
29
|
-
y: padding + innerHeight - normalizedY * innerHeight,
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Formats numbers for display
|
|
36
|
-
*/
|
|
37
|
-
export function formatNumber(
|
|
38
|
-
value: number,
|
|
39
|
-
format?: 'number' | 'currency' | 'percent' | 'compact'
|
|
40
|
-
): string {
|
|
41
|
-
switch (format) {
|
|
42
|
-
case 'currency':
|
|
43
|
-
return new Intl.NumberFormat('en-US', {
|
|
44
|
-
style: 'currency',
|
|
45
|
-
currency: 'USD',
|
|
46
|
-
minimumFractionDigits: 0,
|
|
47
|
-
maximumFractionDigits: 0,
|
|
48
|
-
}).format(value);
|
|
49
|
-
|
|
50
|
-
case 'percent':
|
|
51
|
-
return `${value.toFixed(1)}%`;
|
|
52
|
-
|
|
53
|
-
case 'compact':
|
|
54
|
-
if (value >= 1_000_000) {
|
|
55
|
-
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
56
|
-
}
|
|
57
|
-
if (value >= 1_000) {
|
|
58
|
-
return `${(value / 1_000).toFixed(1)}K`;
|
|
59
|
-
}
|
|
60
|
-
return value.toString();
|
|
61
|
-
|
|
62
|
-
case 'number':
|
|
63
|
-
default:
|
|
64
|
-
return new Intl.NumberFormat('en-US').format(value);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Gets color for trend direction
|
|
70
|
-
*/
|
|
71
|
-
export function getTrendColor(
|
|
72
|
-
trend: 'up' | 'down' | 'neutral',
|
|
73
|
-
colors: { positive: string; negative: string; neutral: string }
|
|
74
|
-
): string {
|
|
75
|
-
switch (trend) {
|
|
76
|
-
case 'up':
|
|
77
|
-
return colors.positive;
|
|
78
|
-
case 'down':
|
|
79
|
-
return colors.negative;
|
|
80
|
-
case 'neutral':
|
|
81
|
-
default:
|
|
82
|
-
return colors.neutral;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@dashboard-widgets/renderer-svg",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "SVG renderer for dashboard widgets - primitives, paths, adapters",
|
|
5
|
-
"main": "index.ts",
|
|
6
|
-
"types": "index.ts",
|
|
7
|
-
"private": true,
|
|
8
|
-
"dependencies": {
|
|
9
|
-
"@dashboard-widgets/core": "*"
|
|
10
|
-
},
|
|
11
|
-
"peerDependencies": {
|
|
12
|
-
"react": ">=18.0.0",
|
|
13
|
-
"react-native": ">=0.70.0",
|
|
14
|
-
"react-native-svg": ">=13.0.0",
|
|
15
|
-
"react-native-reanimated": ">=3.0.0"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SVG arc path generator
|
|
3
|
-
* Translates geometry to SVG path strings
|
|
4
|
-
*/
|
|
5
|
-
import { polarToCartesian } from '../../core/math';
|
|
6
|
-
|
|
7
|
-
export interface ArcPathConfig {
|
|
8
|
-
cx: number;
|
|
9
|
-
cy: number;
|
|
10
|
-
radius: number;
|
|
11
|
-
startAngle: number;
|
|
12
|
-
endAngle: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an SVG arc path
|
|
17
|
-
* @param config - Arc configuration
|
|
18
|
-
* @returns SVG path string
|
|
19
|
-
*/
|
|
20
|
-
export function createArcPath(config: ArcPathConfig): string {
|
|
21
|
-
const { cx, cy, radius, startAngle, endAngle } = config;
|
|
22
|
-
|
|
23
|
-
const start = polarToCartesian(cx, cy, radius, endAngle);
|
|
24
|
-
const end = polarToCartesian(cx, cy, radius, startAngle);
|
|
25
|
-
|
|
26
|
-
const largeArcFlag = endAngle - startAngle <= 180 ? '0' : '1';
|
|
27
|
-
|
|
28
|
-
return [
|
|
29
|
-
'M',
|
|
30
|
-
start.x,
|
|
31
|
-
start.y,
|
|
32
|
-
'A',
|
|
33
|
-
radius,
|
|
34
|
-
radius,
|
|
35
|
-
0,
|
|
36
|
-
largeArcFlag,
|
|
37
|
-
0,
|
|
38
|
-
end.x,
|
|
39
|
-
end.y,
|
|
40
|
-
].join(' ');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Creates a filled arc (pie slice) path
|
|
45
|
-
*/
|
|
46
|
-
export function createFilledArcPath(config: ArcPathConfig): string {
|
|
47
|
-
const { cx, cy } = config;
|
|
48
|
-
const arcPath = createArcPath(config);
|
|
49
|
-
|
|
50
|
-
return `${arcPath} L ${cx} ${cy} Z`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Creates a donut arc path with inner and outer radius
|
|
55
|
-
*/
|
|
56
|
-
export function createDonutArcPath(
|
|
57
|
-
config: ArcPathConfig & { innerRadius: number }
|
|
58
|
-
): string {
|
|
59
|
-
const { cx, cy, radius, innerRadius, startAngle, endAngle } = config;
|
|
60
|
-
|
|
61
|
-
const outerStart = polarToCartesian(cx, cy, radius, endAngle);
|
|
62
|
-
const outerEnd = polarToCartesian(cx, cy, radius, startAngle);
|
|
63
|
-
const innerStart = polarToCartesian(cx, cy, innerRadius, endAngle);
|
|
64
|
-
const innerEnd = polarToCartesian(cx, cy, innerRadius, startAngle);
|
|
65
|
-
|
|
66
|
-
const largeArcFlag = endAngle - startAngle <= 180 ? '0' : '1';
|
|
67
|
-
|
|
68
|
-
return [
|
|
69
|
-
'M',
|
|
70
|
-
outerStart.x,
|
|
71
|
-
outerStart.y,
|
|
72
|
-
'A',
|
|
73
|
-
radius,
|
|
74
|
-
radius,
|
|
75
|
-
0,
|
|
76
|
-
largeArcFlag,
|
|
77
|
-
0,
|
|
78
|
-
outerEnd.x,
|
|
79
|
-
outerEnd.y,
|
|
80
|
-
'L',
|
|
81
|
-
innerEnd.x,
|
|
82
|
-
innerEnd.y,
|
|
83
|
-
'A',
|
|
84
|
-
innerRadius,
|
|
85
|
-
innerRadius,
|
|
86
|
-
0,
|
|
87
|
-
largeArcFlag,
|
|
88
|
-
1,
|
|
89
|
-
innerStart.x,
|
|
90
|
-
innerStart.y,
|
|
91
|
-
'Z',
|
|
92
|
-
].join(' ');
|
|
93
|
-
}
|