glacia-native 0.3.2 → 0.3.4
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 +1 -7
- package/README.md +178 -0
- package/lib/module/Dialog.js +128 -0
- package/lib/module/Form.js +125 -0
- package/lib/module/Input.js +64 -0
- package/lib/module/Table.js +81 -0
- package/lib/module/ai.js +246 -0
- package/lib/module/charts/AreaChart.js +32 -0
- package/lib/module/charts/BarChart.js +65 -0
- package/lib/module/charts/FunnelChart.js +48 -0
- package/lib/module/charts/HeatmapChart.js +69 -0
- package/lib/module/charts/LineChart.js +79 -0
- package/lib/module/charts/PlotChart.js +44 -0
- package/lib/module/charts/RadarChart.js +76 -0
- package/lib/module/charts/RingChart.js +50 -0
- package/lib/module/charts/ScatterChart.js +78 -0
- package/lib/module/charts/WaterfallChart.js +76 -0
- package/lib/module/charts/advanced.js +307 -0
- package/lib/module/charts/extra.js +105 -0
- package/lib/module/charts/index.js +50 -0
- package/lib/module/charts/primitives.js +212 -0
- package/lib/module/charts/scales.js +140 -0
- package/lib/module/index.js +48 -1
- package/lib/module/internal/tokens.js +3 -0
- package/lib/typescript/Dialog.d.ts +71 -0
- package/lib/typescript/Form.d.ts +81 -0
- package/lib/typescript/Input.d.ts +47 -0
- package/lib/typescript/Table.d.ts +55 -0
- package/lib/typescript/ai.d.ts +163 -0
- package/lib/typescript/charts/AreaChart.d.ts +44 -0
- package/lib/typescript/charts/BarChart.d.ts +19 -0
- package/lib/typescript/charts/FunnelChart.d.ts +25 -0
- package/lib/typescript/charts/HeatmapChart.d.ts +23 -0
- package/lib/typescript/charts/LineChart.d.ts +30 -0
- package/lib/typescript/charts/PlotChart.d.ts +31 -0
- package/lib/typescript/charts/RadarChart.d.ts +27 -0
- package/lib/typescript/charts/RingChart.d.ts +28 -0
- package/lib/typescript/charts/ScatterChart.d.ts +34 -0
- package/lib/typescript/charts/WaterfallChart.d.ts +22 -0
- package/lib/typescript/charts/advanced.d.ts +107 -0
- package/lib/typescript/charts/extra.d.ts +63 -0
- package/lib/typescript/charts/index.d.ts +13 -0
- package/lib/typescript/charts/primitives.d.ts +23 -0
- package/lib/typescript/charts/scales.d.ts +35 -0
- package/lib/typescript/index.d.ts +6 -0
- package/lib/typescript/internal/tokens.d.ts +2 -0
- package/package.json +10 -3
- package/src/Dialog.tsx +345 -0
- package/src/Form.tsx +360 -0
- package/src/Input.tsx +172 -0
- package/src/Table.tsx +207 -0
- package/src/ai.tsx +655 -0
- package/src/charts/AreaChart.tsx +73 -0
- package/src/charts/BarChart.tsx +181 -0
- package/src/charts/FunnelChart.tsx +123 -0
- package/src/charts/HeatmapChart.tsx +153 -0
- package/src/charts/LineChart.tsx +245 -0
- package/src/charts/PlotChart.tsx +148 -0
- package/src/charts/RadarChart.tsx +206 -0
- package/src/charts/RingChart.tsx +131 -0
- package/src/charts/ScatterChart.tsx +202 -0
- package/src/charts/WaterfallChart.tsx +183 -0
- package/src/charts/advanced.tsx +670 -0
- package/src/charts/extra.tsx +239 -0
- package/src/charts/index.ts +86 -0
- package/src/charts/primitives.ts +262 -0
- package/src/charts/scales.ts +163 -0
- package/src/index.ts +68 -0
- package/src/internal/tokens.ts +3 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// Native chart scales.
|
|
2
|
+
//
|
|
3
|
+
// This mirrors the web package's chart maths so a series drawn on a phone and
|
|
4
|
+
// the same series drawn in a browser land on the same axis values. It is
|
|
5
|
+
// deliberately duplicated rather than imported from `glacia`: glacia-native is
|
|
6
|
+
// a standalone package with no dependency on the web build.
|
|
7
|
+
|
|
8
|
+
/** Maps a value into pixel space along one axis. */
|
|
9
|
+
export interface Scale {
|
|
10
|
+
(value: number): number;
|
|
11
|
+
invert(pixel: number): number;
|
|
12
|
+
domain: [number, number];
|
|
13
|
+
range: [number, number];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function linearScale(
|
|
17
|
+
domain: [number, number],
|
|
18
|
+
range: [number, number],
|
|
19
|
+
options: { nice?: boolean; ticks?: number } = {},
|
|
20
|
+
): Scale {
|
|
21
|
+
let [d0, d1] = domain;
|
|
22
|
+
if (d0 === d1) {
|
|
23
|
+
d0 = d0 === 0 ? 0 : d0 * 0.9;
|
|
24
|
+
d1 = d1 === 0 ? 1 : d1 * 1.1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const base: [number, number] =
|
|
28
|
+
options.nice === false ? [d0, d1] : niceDomain(d0, d1, options.ticks ?? 5);
|
|
29
|
+
const [a, b] = base;
|
|
30
|
+
const [r0, r1] = range;
|
|
31
|
+
const span = b - a || 1;
|
|
32
|
+
|
|
33
|
+
const scale = ((value: number) => r0 + ((value - a) / span) * (r1 - r0)) as Scale;
|
|
34
|
+
scale.invert = (pixel: number) => a + ((pixel - r0) / (r1 - r0)) * span;
|
|
35
|
+
scale.domain = [a, b];
|
|
36
|
+
scale.range = range;
|
|
37
|
+
return scale;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Rounds a domain outward to values that read cleanly on an axis. */
|
|
41
|
+
export function niceDomain(min: number, max: number, tickCount = 5): [number, number] {
|
|
42
|
+
if (min === max) return [min === 0 ? 0 : min * 0.9, max === 0 ? 1 : max * 1.1];
|
|
43
|
+
const span = max - min;
|
|
44
|
+
const step = Math.pow(10, Math.floor(Math.log10(span / tickCount)));
|
|
45
|
+
const error = span / tickCount / step;
|
|
46
|
+
const factor = error >= 7.5 ? 10 : error >= 3.5 ? 5 : error >= 1.5 ? 2 : 1;
|
|
47
|
+
const niceStep = step * factor;
|
|
48
|
+
return [Math.floor(min / niceStep) * niceStep, Math.ceil(max / niceStep) * niceStep];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function ticks(domain: [number, number], count = 4): number[] {
|
|
52
|
+
const [d0, d1] = domain;
|
|
53
|
+
if (d0 === d1) return [d0];
|
|
54
|
+
return Array.from({ length: count + 1 }, (_, i) => d0 + ((d1 - d0) * i) / count);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Evenly divided bands; returns the centre and width of each. */
|
|
58
|
+
export function bandScale(count: number, range: [number, number], padding = 0.2) {
|
|
59
|
+
const [r0, r1] = range;
|
|
60
|
+
const step = (r1 - r0) / Math.max(1, count);
|
|
61
|
+
const width = step * (1 - padding);
|
|
62
|
+
return {
|
|
63
|
+
bandWidth: step,
|
|
64
|
+
width,
|
|
65
|
+
start: (i: number) => r0 + i * step + (step - width) / 2,
|
|
66
|
+
center: (i: number) => r0 + i * step + step / 2,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Compact number formatting, matching the web charts. */
|
|
71
|
+
export function formatValue(
|
|
72
|
+
value: number,
|
|
73
|
+
options: { compact?: boolean; decimals?: number } = {},
|
|
74
|
+
): string {
|
|
75
|
+
if (Number.isNaN(value)) return "—";
|
|
76
|
+
if (options.compact) {
|
|
77
|
+
const abs = Math.abs(value);
|
|
78
|
+
if (abs >= 1_000_000_000) return trim(value / 1_000_000_000) + "B";
|
|
79
|
+
if (abs >= 1_000_000) return trim(value / 1_000_000) + "M";
|
|
80
|
+
if (abs >= 1_000) return trim(value / 1_000) + "k";
|
|
81
|
+
}
|
|
82
|
+
const fixed = options.decimals ?? (Number.isInteger(value) ? 0 : 2);
|
|
83
|
+
return value
|
|
84
|
+
.toFixed(fixed)
|
|
85
|
+
.replace(/(\.\d*?)0+$/, "$1")
|
|
86
|
+
.replace(/\.$/, "");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function trim(value: number): string {
|
|
90
|
+
return (Math.round(value * 10) / 10).toString();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Points along a smooth (monotone) path, as SVG path segments. */
|
|
94
|
+
export function smoothPath(points: { x: number; y: number }[]): string {
|
|
95
|
+
if (points.length === 0) return "";
|
|
96
|
+
if (points.length === 1) return `M ${points[0]!.x} ${points[0]!.y}`;
|
|
97
|
+
if (points.length === 2) return `M ${points[0]!.x} ${points[0]!.y} L ${points[1]!.x} ${points[1]!.y}`;
|
|
98
|
+
|
|
99
|
+
let d = `M ${points[0]!.x} ${points[0]!.y}`;
|
|
100
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
101
|
+
const p0 = points[i - 1] ?? points[i]!;
|
|
102
|
+
const p1 = points[i]!;
|
|
103
|
+
const p2 = points[i + 1]!;
|
|
104
|
+
const p3 = points[i + 2] ?? p2;
|
|
105
|
+
|
|
106
|
+
const t = 0.2;
|
|
107
|
+
const c1x = p1.x + (p2.x - p0.x) * t;
|
|
108
|
+
const c1y = p1.y + (p2.y - p0.y) * t;
|
|
109
|
+
const c2x = p2.x - (p3.x - p1.x) * t;
|
|
110
|
+
const c2y = p2.y - (p3.y - p1.y) * t;
|
|
111
|
+
|
|
112
|
+
// Clamp so the curve cannot overshoot the segment's own y-range.
|
|
113
|
+
const lo = Math.min(p1.y, p2.y);
|
|
114
|
+
const hi = Math.max(p1.y, p2.y);
|
|
115
|
+
d += ` C ${c1x} ${Math.min(hi, Math.max(lo, c1y))} ${c2x} ${Math.min(hi, Math.max(lo, c2y))} ${p2.x} ${p2.y}`;
|
|
116
|
+
}
|
|
117
|
+
return d;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** A pie/donut arc, with an optional inner radius. */
|
|
121
|
+
export function arcPath(
|
|
122
|
+
cx: number,
|
|
123
|
+
cy: number,
|
|
124
|
+
outer: number,
|
|
125
|
+
inner: number,
|
|
126
|
+
startAngle: number,
|
|
127
|
+
endAngle: number,
|
|
128
|
+
): string {
|
|
129
|
+
const sweep = endAngle - startAngle;
|
|
130
|
+
if (sweep >= Math.PI * 2 - 1e-6) {
|
|
131
|
+
const mid = startAngle + Math.PI;
|
|
132
|
+
return (
|
|
133
|
+
arcPath(cx, cy, outer, inner, startAngle, mid) +
|
|
134
|
+
" " +
|
|
135
|
+
arcPath(cx, cy, outer, inner, mid, endAngle - 1e-6)
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const p = (r: number, a: number) => [cx + r * Math.cos(a), cy + r * Math.sin(a)] as const;
|
|
140
|
+
const large = sweep > Math.PI ? 1 : 0;
|
|
141
|
+
const [x1, y1] = p(outer, startAngle);
|
|
142
|
+
const [x2, y2] = p(outer, endAngle);
|
|
143
|
+
|
|
144
|
+
if (inner <= 0) {
|
|
145
|
+
return `M ${cx} ${cy} L ${x1} ${y1} A ${outer} ${outer} 0 ${large} 1 ${x2} ${y2} Z`;
|
|
146
|
+
}
|
|
147
|
+
const [x3, y3] = p(inner, endAngle);
|
|
148
|
+
const [x4, y4] = p(inner, startAngle);
|
|
149
|
+
return `M ${x1} ${y1} A ${outer} ${outer} 0 ${large} 1 ${x2} ${y2} L ${x3} ${y3} A ${inner} ${inner} 0 ${large} 0 ${x4} ${y4} Z`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const SERIES_COLORS = [
|
|
153
|
+
"#0088ff",
|
|
154
|
+
"#34c759",
|
|
155
|
+
"#ff9f0a",
|
|
156
|
+
"#ff375f",
|
|
157
|
+
"#bf5af2",
|
|
158
|
+
"#64d2ff",
|
|
159
|
+
"#ffd60a",
|
|
160
|
+
] as const;
|
|
161
|
+
|
|
162
|
+
export const seriesColor = (index: number, palette?: readonly string[]): string =>
|
|
163
|
+
(palette ?? SERIES_COLORS)[index % (palette ?? SERIES_COLORS).length]!;
|
package/src/index.ts
CHANGED
|
@@ -18,5 +18,73 @@ export {
|
|
|
18
18
|
CardFooter,
|
|
19
19
|
type CardProps,
|
|
20
20
|
} from "./Card";
|
|
21
|
+
// Forms.
|
|
22
|
+
export {
|
|
23
|
+
Input,
|
|
24
|
+
Textarea,
|
|
25
|
+
type InputProps,
|
|
26
|
+
type TextareaProps,
|
|
27
|
+
} from "./Input";
|
|
28
|
+
export {
|
|
29
|
+
Label,
|
|
30
|
+
Field,
|
|
31
|
+
Checkbox,
|
|
32
|
+
RadioGroup,
|
|
33
|
+
Select,
|
|
34
|
+
type LabelProps,
|
|
35
|
+
type FieldProps,
|
|
36
|
+
type CheckboxProps,
|
|
37
|
+
type RadioOption,
|
|
38
|
+
type RadioGroupProps,
|
|
39
|
+
type SelectOption,
|
|
40
|
+
type SelectProps,
|
|
41
|
+
} from "./Form";
|
|
42
|
+
// Overlays.
|
|
43
|
+
export {
|
|
44
|
+
Dialog,
|
|
45
|
+
DialogTrigger,
|
|
46
|
+
AlertDialog,
|
|
47
|
+
ActionSheet,
|
|
48
|
+
type DialogProps,
|
|
49
|
+
type AlertDialogProps,
|
|
50
|
+
type ActionSheetProps,
|
|
51
|
+
type ActionSheetOption,
|
|
52
|
+
} from "./Dialog";
|
|
53
|
+
// AI conversation primitives.
|
|
54
|
+
export {
|
|
55
|
+
NativePlan,
|
|
56
|
+
NativeSources,
|
|
57
|
+
NativeResponse,
|
|
58
|
+
NativeTask,
|
|
59
|
+
NativeSoundwave,
|
|
60
|
+
NativeThinkingOrb,
|
|
61
|
+
NativePanelside,
|
|
62
|
+
NativeAIInput,
|
|
63
|
+
NativeImageGeneration,
|
|
64
|
+
type NativePlanProps,
|
|
65
|
+
type NativePlanStep,
|
|
66
|
+
type NativeSourcesProps,
|
|
67
|
+
type NativeSource,
|
|
68
|
+
type NativeResponseProps,
|
|
69
|
+
type NativeTaskProps,
|
|
70
|
+
type NativeSoundwaveProps,
|
|
71
|
+
type NativeThinkingOrbProps,
|
|
72
|
+
type NativePanelsideProps,
|
|
73
|
+
type NativePanelNavItem,
|
|
74
|
+
type NativeAIInputProps,
|
|
75
|
+
type NativeImageGenerationProps,
|
|
76
|
+
type NativeGeneratedImage,
|
|
77
|
+
} from "./ai";
|
|
78
|
+
// Data display.
|
|
79
|
+
export {
|
|
80
|
+
NativeTable,
|
|
81
|
+
NativeScrollArea,
|
|
82
|
+
type NativeTableProps,
|
|
83
|
+
type NativeTableColumn,
|
|
84
|
+
type NativeTableRow,
|
|
85
|
+
type NativeScrollAreaProps,
|
|
86
|
+
} from "./Table";
|
|
87
|
+
// Charts, drawn with react-native-svg using the same maths as the web package.
|
|
88
|
+
export * from "./charts";
|
|
21
89
|
export { isGlassSupported } from "./internal/GlassView";
|
|
22
90
|
export { colors, radii, springs } from "./internal/tokens";
|
package/src/internal/tokens.ts
CHANGED
|
@@ -23,6 +23,8 @@ export const colors = {
|
|
|
23
23
|
edge: "rgba(0, 0, 0, 0.08)",
|
|
24
24
|
fill: "#0088FF",
|
|
25
25
|
destructive: "#FF3B30",
|
|
26
|
+
// Chart axis and grid lines: low-contrast, so they never compete with data.
|
|
27
|
+
axis: "#3C3C43",
|
|
26
28
|
},
|
|
27
29
|
dark: {
|
|
28
30
|
foreground: "#FFFFFF",
|
|
@@ -32,5 +34,6 @@ export const colors = {
|
|
|
32
34
|
edge: "rgba(255, 255, 255, 0.08)",
|
|
33
35
|
fill: "#0091FF",
|
|
34
36
|
destructive: "#FF4245",
|
|
37
|
+
axis: "#EBEBF5",
|
|
35
38
|
},
|
|
36
39
|
};
|