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.
- package/README.md +111 -51
- 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/math/index.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core math utilities for dashboard widgets
|
|
3
|
-
* Pure functions only - no side effects, no dependencies
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Clamps a value between min and max
|
|
8
|
-
*/
|
|
9
|
-
export function clamp(value: number, min: number, max: number): number {
|
|
10
|
-
return Math.min(Math.max(value, min), max);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Normalizes a value from [min, max] to [0, 1]
|
|
15
|
-
*/
|
|
16
|
-
export function normalize(value: number, min: number, max: number): number {
|
|
17
|
-
if (max === min) return 0;
|
|
18
|
-
return clamp((value - min) / (max - min), 0, 1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Interpolates a value from one range to another
|
|
23
|
-
* @example interpolate(5, [0, 10], [0, 100]) // 50
|
|
24
|
-
*/
|
|
25
|
-
export function interpolate(
|
|
26
|
-
value: number,
|
|
27
|
-
inRange: [number, number],
|
|
28
|
-
outRange: [number, number]
|
|
29
|
-
): number {
|
|
30
|
-
const normalized = normalize(value, inRange[0], inRange[1]);
|
|
31
|
-
return outRange[0] + normalized * (outRange[1] - outRange[0]);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Converts polar coordinates to cartesian
|
|
36
|
-
* @param cx - Center X
|
|
37
|
-
* @param cy - Center Y
|
|
38
|
-
* @param r - Radius
|
|
39
|
-
* @param angle - Angle in degrees
|
|
40
|
-
*/
|
|
41
|
-
export function polarToCartesian(
|
|
42
|
-
cx: number,
|
|
43
|
-
cy: number,
|
|
44
|
-
r: number,
|
|
45
|
-
angle: number
|
|
46
|
-
): { x: number; y: number } {
|
|
47
|
-
const angleInRadians = ((angle - 90) * Math.PI) / 180;
|
|
48
|
-
return {
|
|
49
|
-
x: cx + r * Math.cos(angleInRadians),
|
|
50
|
-
y: cy + r * Math.sin(angleInRadians),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Rounds a number to a specified number of decimal places
|
|
56
|
-
*/
|
|
57
|
-
export function roundTo(value: number, decimals: number = 2): number {
|
|
58
|
-
const multiplier = Math.pow(10, decimals);
|
|
59
|
-
return Math.round(value * multiplier) / multiplier;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Calculates the distance between two points
|
|
64
|
-
*/
|
|
65
|
-
export function distance(
|
|
66
|
-
x1: number,
|
|
67
|
-
y1: number,
|
|
68
|
-
x2: number,
|
|
69
|
-
y2: number
|
|
70
|
-
): number {
|
|
71
|
-
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
|
|
72
|
-
}
|
package/src/core/package.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@dashboard-widgets/core",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "Core utilities for dashboard widgets - math, theme, animation, layout",
|
|
5
|
-
"main": "index.ts",
|
|
6
|
-
"types": "index.ts",
|
|
7
|
-
"private": true,
|
|
8
|
-
"peerDependencies": {
|
|
9
|
-
"react": ">=18.0.0",
|
|
10
|
-
"react-native": ">=0.70.0",
|
|
11
|
-
"react-native-reanimated": ">=3.0.0"
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Theme provider and context
|
|
3
|
-
*/
|
|
4
|
-
import React, { createContext, useContext, ReactNode } from 'react';
|
|
5
|
-
import { Theme } from '../types';
|
|
6
|
-
import { DefaultTheme } from './themes';
|
|
7
|
-
|
|
8
|
-
const ThemeContext = createContext<Theme>(DefaultTheme);
|
|
9
|
-
|
|
10
|
-
export interface ThemeProviderProps {
|
|
11
|
-
theme?: Theme;
|
|
12
|
-
children: ReactNode;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Theme provider component
|
|
17
|
-
* Wraps the app and provides theme to all widgets
|
|
18
|
-
*/
|
|
19
|
-
export function ThemeProvider({ theme = DefaultTheme, children }: ThemeProviderProps) {
|
|
20
|
-
return (
|
|
21
|
-
<ThemeContext.Provider value={theme}>
|
|
22
|
-
{children}
|
|
23
|
-
</ThemeContext.Provider>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Hook to access the current theme
|
|
29
|
-
*/
|
|
30
|
-
export function useTheme(): Theme {
|
|
31
|
-
const theme = useContext(ThemeContext);
|
|
32
|
-
if (!theme) {
|
|
33
|
-
throw new Error('useTheme must be used within a ThemeProvider');
|
|
34
|
-
}
|
|
35
|
-
return theme;
|
|
36
|
-
}
|
package/src/core/theme/index.ts
DELETED
package/src/core/theme/themes.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default theme definitions
|
|
3
|
-
*/
|
|
4
|
-
import { Theme } from '../types';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Default light theme
|
|
8
|
-
*/
|
|
9
|
-
export const DefaultTheme: Theme = {
|
|
10
|
-
colors: {
|
|
11
|
-
// Primary colors
|
|
12
|
-
primary: '#3B82F6',
|
|
13
|
-
secondary: '#8B5CF6',
|
|
14
|
-
accent: '#EC4899',
|
|
15
|
-
|
|
16
|
-
// Semantic colors
|
|
17
|
-
success: '#10B981',
|
|
18
|
-
warning: '#F59E0B',
|
|
19
|
-
error: '#EF4444',
|
|
20
|
-
info: '#3B82F6',
|
|
21
|
-
|
|
22
|
-
// Background colors
|
|
23
|
-
background: '#FFFFFF',
|
|
24
|
-
surface: '#F9FAFB',
|
|
25
|
-
overlay: 'rgba(0, 0, 0, 0.5)',
|
|
26
|
-
|
|
27
|
-
// Text colors
|
|
28
|
-
text: '#111827',
|
|
29
|
-
textSecondary: '#6B7280',
|
|
30
|
-
textDisabled: '#D1D5DB',
|
|
31
|
-
|
|
32
|
-
// Border colors
|
|
33
|
-
border: '#E5E7EB',
|
|
34
|
-
borderLight: '#F3F4F6',
|
|
35
|
-
|
|
36
|
-
// Chart colors
|
|
37
|
-
chartPrimary: '#3B82F6',
|
|
38
|
-
chartSecondary: '#8B5CF6',
|
|
39
|
-
chartTertiary: '#EC4899',
|
|
40
|
-
chartQuaternary: '#F59E0B',
|
|
41
|
-
chartPositive: '#10B981',
|
|
42
|
-
chartNegative: '#EF4444',
|
|
43
|
-
chartNeutral: '#6B7280',
|
|
44
|
-
},
|
|
45
|
-
spacing: {
|
|
46
|
-
xs: 4,
|
|
47
|
-
sm: 8,
|
|
48
|
-
md: 16,
|
|
49
|
-
lg: 24,
|
|
50
|
-
xl: 32,
|
|
51
|
-
xxl: 48,
|
|
52
|
-
},
|
|
53
|
-
radius: {
|
|
54
|
-
none: 0,
|
|
55
|
-
sm: 4,
|
|
56
|
-
md: 8,
|
|
57
|
-
lg: 12,
|
|
58
|
-
full: 9999,
|
|
59
|
-
},
|
|
60
|
-
fontScale: {
|
|
61
|
-
xs: 10,
|
|
62
|
-
sm: 12,
|
|
63
|
-
md: 14,
|
|
64
|
-
lg: 18,
|
|
65
|
-
xl: 24,
|
|
66
|
-
xxl: 32,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Dark theme
|
|
72
|
-
*/
|
|
73
|
-
export const DarkTheme: Theme = {
|
|
74
|
-
colors: {
|
|
75
|
-
// Primary colors
|
|
76
|
-
primary: '#60A5FA',
|
|
77
|
-
secondary: '#A78BFA',
|
|
78
|
-
accent: '#F472B6',
|
|
79
|
-
|
|
80
|
-
// Semantic colors
|
|
81
|
-
success: '#34D399',
|
|
82
|
-
warning: '#FBBF24',
|
|
83
|
-
error: '#F87171',
|
|
84
|
-
info: '#60A5FA',
|
|
85
|
-
|
|
86
|
-
// Background colors
|
|
87
|
-
background: '#111827',
|
|
88
|
-
surface: '#1F2937',
|
|
89
|
-
overlay: 'rgba(0, 0, 0, 0.7)',
|
|
90
|
-
|
|
91
|
-
// Text colors
|
|
92
|
-
text: '#F9FAFB',
|
|
93
|
-
textSecondary: '#D1D5DB',
|
|
94
|
-
textDisabled: '#6B7280',
|
|
95
|
-
|
|
96
|
-
// Border colors
|
|
97
|
-
border: '#374151',
|
|
98
|
-
borderLight: '#4B5563',
|
|
99
|
-
|
|
100
|
-
// Chart colors
|
|
101
|
-
chartPrimary: '#60A5FA',
|
|
102
|
-
chartSecondary: '#A78BFA',
|
|
103
|
-
chartTertiary: '#F472B6',
|
|
104
|
-
chartQuaternary: '#FBBF24',
|
|
105
|
-
chartPositive: '#34D399',
|
|
106
|
-
chartNegative: '#F87171',
|
|
107
|
-
chartNeutral: '#9CA3AF',
|
|
108
|
-
},
|
|
109
|
-
spacing: {
|
|
110
|
-
xs: 4,
|
|
111
|
-
sm: 8,
|
|
112
|
-
md: 16,
|
|
113
|
-
lg: 24,
|
|
114
|
-
xl: 32,
|
|
115
|
-
xxl: 48,
|
|
116
|
-
},
|
|
117
|
-
radius: {
|
|
118
|
-
none: 0,
|
|
119
|
-
sm: 4,
|
|
120
|
-
md: 8,
|
|
121
|
-
lg: 12,
|
|
122
|
-
full: 9999,
|
|
123
|
-
},
|
|
124
|
-
fontScale: {
|
|
125
|
-
xs: 10,
|
|
126
|
-
sm: 12,
|
|
127
|
-
md: 14,
|
|
128
|
-
lg: 18,
|
|
129
|
-
xl: 24,
|
|
130
|
-
xxl: 32,
|
|
131
|
-
},
|
|
132
|
-
};
|
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
|
-
}
|