vibefast-cli 0.1.1
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/FINAL-STATUS.md +144 -0
- package/HOW-IT-WORKS.md +559 -0
- package/PLAN.md +453 -0
- package/README.md +129 -0
- package/RECIPES-READY.md +172 -0
- package/STATUS.md +199 -0
- package/SUCCESS.md +259 -0
- package/TESTING-CHECKLIST.md +450 -0
- package/cloudflare-worker/.wrangler/state/v3/kv/64907821e2634080acce34618d2f3d4c/blobs/11f2769953c717e188062bc644da97c1fd1e4d6d0813a226ce7567dba759afab0000019a736fb8d4 +1 -0
- package/cloudflare-worker/.wrangler/state/v3/kv/miniflare-KVNamespaceObject/0b03767237c0408301af51ca35d4b09470cbc479c7e5f23cc9de774749d23c59.sqlite +0 -0
- package/cloudflare-worker/.wrangler/state/v3/kv/miniflare-KVNamespaceObject/0b03767237c0408301af51ca35d4b09470cbc479c7e5f23cc9de774749d23c59.sqlite-shm +0 -0
- package/cloudflare-worker/.wrangler/state/v3/kv/miniflare-KVNamespaceObject/0b03767237c0408301af51ca35d4b09470cbc479c7e5f23cc9de774749d23c59.sqlite-wal +0 -0
- package/cloudflare-worker/.wrangler/state/v3/r2/miniflare-R2BucketObject/d1cc388a1a0ef44dd5669fd1a165d168b61362136c8b5fa50aefd96c72688e54.sqlite +0 -0
- package/cloudflare-worker/.wrangler/state/v3/r2/miniflare-R2BucketObject/d1cc388a1a0ef44dd5669fd1a165d168b61362136c8b5fa50aefd96c72688e54.sqlite-shm +0 -0
- package/cloudflare-worker/.wrangler/state/v3/r2/miniflare-R2BucketObject/d1cc388a1a0ef44dd5669fd1a165d168b61362136c8b5fa50aefd96c72688e54.sqlite-wal +0 -0
- package/cloudflare-worker/.wrangler/state/v3/r2/vibefast-recipes/blobs/620e8cf7c35d9806da25dee237e1d7e8b2432bd98f755b60e2c7f08a48d2c7b90000019a73736484 +0 -0
- package/cloudflare-worker/MIGRATION.md +160 -0
- package/cloudflare-worker/QUICKSTART.md +200 -0
- package/cloudflare-worker/README.md +242 -0
- package/cloudflare-worker/generate-token.js +32 -0
- package/cloudflare-worker/mini-native@latest.zip +0 -0
- package/cloudflare-worker/setup.sh +143 -0
- package/cloudflare-worker/test-recipe/apps/native/src/app/mini/index.tsx +15 -0
- package/cloudflare-worker/test-recipe/recipe.json +16 -0
- package/cloudflare-worker/worker.js +308 -0
- package/cloudflare-worker/wrangler.toml +13 -0
- package/dist/commands/add.d.ts +3 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/add.js +149 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/devices.d.ts +3 -0
- package/dist/commands/devices.d.ts.map +1 -0
- package/dist/commands/devices.js +35 -0
- package/dist/commands/devices.js.map +1 -0
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +67 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/list.d.ts +3 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +40 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +23 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +3 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +16 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/remove.d.ts +3 -0
- package/dist/commands/remove.d.ts.map +1 -0
- package/dist/commands/remove.js +67 -0
- package/dist/commands/remove.js.map +1 -0
- package/dist/core/__tests__/journal.test.d.ts +2 -0
- package/dist/core/__tests__/journal.test.d.ts.map +1 -0
- package/dist/core/__tests__/journal.test.js +101 -0
- package/dist/core/__tests__/journal.test.js.map +1 -0
- package/dist/core/__tests__/validate.test.d.ts +2 -0
- package/dist/core/__tests__/validate.test.d.ts.map +1 -0
- package/dist/core/__tests__/validate.test.js +53 -0
- package/dist/core/__tests__/validate.test.js.map +1 -0
- package/dist/core/archive.d.ts +2 -0
- package/dist/core/archive.d.ts.map +1 -0
- package/dist/core/archive.js +59 -0
- package/dist/core/archive.js.map +1 -0
- package/dist/core/auth.d.ts +15 -0
- package/dist/core/auth.d.ts.map +1 -0
- package/dist/core/auth.js +76 -0
- package/dist/core/auth.js.map +1 -0
- package/dist/core/codemod.d.ts +20 -0
- package/dist/core/codemod.d.ts.map +1 -0
- package/dist/core/codemod.js +150 -0
- package/dist/core/codemod.js.map +1 -0
- package/dist/core/fsx.d.ts +12 -0
- package/dist/core/fsx.d.ts.map +1 -0
- package/dist/core/fsx.js +70 -0
- package/dist/core/fsx.js.map +1 -0
- package/dist/core/http.d.ts +30 -0
- package/dist/core/http.d.ts.map +1 -0
- package/dist/core/http.js +95 -0
- package/dist/core/http.js.map +1 -0
- package/dist/core/journal.d.ts +18 -0
- package/dist/core/journal.d.ts.map +1 -0
- package/dist/core/journal.js +34 -0
- package/dist/core/journal.js.map +1 -0
- package/dist/core/log.d.ts +8 -0
- package/dist/core/log.d.ts.map +1 -0
- package/dist/core/log.js +9 -0
- package/dist/core/log.js.map +1 -0
- package/dist/core/pathGuard.d.ts +3 -0
- package/dist/core/pathGuard.d.ts.map +1 -0
- package/dist/core/pathGuard.js +18 -0
- package/dist/core/pathGuard.js.map +1 -0
- package/dist/core/paths.d.ts +11 -0
- package/dist/core/paths.d.ts.map +1 -0
- package/dist/core/paths.js +22 -0
- package/dist/core/paths.js.map +1 -0
- package/dist/core/validate.d.ts +8 -0
- package/dist/core/validate.d.ts.map +1 -0
- package/dist/core/validate.js +27 -0
- package/dist/core/validate.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/docs/decisions.md +55 -0
- package/package.json +39 -0
- package/recipes/audio-recorder/apps/native/src/app/audio-recorder/index.tsx +5 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/components/audio-player.tsx +301 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/components/audio-recorder.tsx +373 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/components/audio-waveform.tsx +270 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/components/index.ts +4 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/components/recording-list.tsx +89 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/audio-player-demo.tsx +66 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/audio-recorder-cloud.tsx +68 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/audio-recorder-interview.tsx +102 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/basic.tsx +27 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/index.ts +5 -0
- package/recipes/audio-recorder/apps/native/src/features/audio-recorder/demo/with-recording-list-demo.tsx +82 -0
- package/recipes/audio-recorder/recipe.json +22 -0
- package/recipes/audio-recorder@latest.zip +0 -0
- package/recipes/charts/apps/native/src/app/charts/index.tsx +3 -0
- package/recipes/charts/apps/native/src/features/charts/README.md +185 -0
- package/recipes/charts/apps/native/src/features/charts/app/preview.tsx +223 -0
- package/recipes/charts/apps/native/src/features/charts/components/area-chart.tsx +40 -0
- package/recipes/charts/apps/native/src/features/charts/components/bar-chart.tsx +143 -0
- package/recipes/charts/apps/native/src/features/charts/components/candlestick-chart.tsx +196 -0
- package/recipes/charts/apps/native/src/features/charts/components/chart-card.tsx +65 -0
- package/recipes/charts/apps/native/src/features/charts/components/column-chart.tsx +143 -0
- package/recipes/charts/apps/native/src/features/charts/components/doughnut-chart.tsx +246 -0
- package/recipes/charts/apps/native/src/features/charts/components/index.ts +10 -0
- package/recipes/charts/apps/native/src/features/charts/components/line-chart.tsx +308 -0
- package/recipes/charts/apps/native/src/features/charts/components/radar-chart.tsx +180 -0
- package/recipes/charts/apps/native/src/features/charts/components/radial-bar-chart.tsx +188 -0
- package/recipes/charts/apps/native/src/features/charts/components/stacked-area-chart.tsx +265 -0
- package/recipes/charts/apps/native/src/features/charts/components/stacked-bar-chart.tsx +322 -0
- package/recipes/charts/apps/native/src/features/charts/data/mock-data.ts +183 -0
- package/recipes/charts/apps/native/src/features/charts/types/index.ts +66 -0
- package/recipes/charts/recipe.json +22 -0
- package/recipes/charts@latest.zip +0 -0
- package/recipes/chatbot/apps/native/src/app/chatbot/index.tsx +1 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/app/index.tsx +302 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/chat-header-buttons.tsx +59 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/chat-input-bar.tsx +469 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/chat-markdown.tsx +575 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/chat-message-bubble.tsx +246 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/chat-settings-modal.tsx +161 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/image-preview-list.tsx +115 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/markdown/code-block.tsx +165 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/markdown/index.ts +10 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/markdown/table-renderer.tsx +129 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/message-error-boundary.tsx +78 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/message-list.tsx +173 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/model-selector.tsx +283 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/report-content-modal.tsx +188 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/components/suggested-messages.tsx +67 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/constants/models.ts +20 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/constants/report-reasons.ts +9 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-attachment-cache.ts +143 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-chat-config.ts +664 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-chat-handlers.ts +359 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-chatbot-settings.ts +89 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-conversation.ts +79 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-image-picker.ts +122 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-keyboard-coordinator.ts +161 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/hooks/use-smart-scroll-manager.ts +207 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/models/index.ts +86 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/models/models.ts +162 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/models/providers.ts +62 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/models/types.ts +40 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/services/file-uploader.ts +238 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/services/message-handler-service.ts +180 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/types/index.ts +60 -0
- package/recipes/chatbot/apps/native/src/features/chatbot/utils/chat-telemetry.ts +91 -0
- package/recipes/chatbot/recipe.json +22 -0
- package/recipes/chatbot@latest.zip +0 -0
- package/recipes/image-generator/apps/native/src/app/image-generator/gallery.tsx +3 -0
- package/recipes/image-generator/apps/native/src/app/image-generator/index.tsx +3 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/app/_layout.tsx +25 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/app/gallery.tsx +217 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/app/index.tsx +237 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/components/gallery-image.tsx +26 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/components/image-detail-modal.tsx +215 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/components/image-model-selector.tsx +210 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/components/image-placeholder.tsx +26 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/hooks/use-image-gallery.ts +71 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/hooks/use-image-generator-settings.ts +152 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/hooks/use-image-generator.ts +93 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/models/models.ts +66 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/services/image-gallery-service.ts +98 -0
- package/recipes/image-generator/apps/native/src/features/image-generator/services/image-save-service.ts +121 -0
- package/recipes/image-generator/recipe.json +22 -0
- package/recipes/image-generator@latest.zip +0 -0
- package/recipes/quiz/apps/native/src/app/quiz/index.tsx +47 -0
- package/recipes/quiz/apps/native/src/features/quiz/components/question.tsx +67 -0
- package/recipes/quiz/apps/native/src/features/quiz/config.ts +11 -0
- package/recipes/quiz/apps/native/src/features/quiz/index.tsx +133 -0
- package/recipes/quiz/recipe.json +22 -0
- package/recipes/quiz@latest.zip +0 -0
- package/recipes/tracker-app/apps/native/src/app/tracker-app/index.tsx +1 -0
- package/recipes/tracker-app/apps/native/src/features/tracker-app/app/index.tsx +108 -0
- package/recipes/tracker-app/apps/native/src/features/tracker-app/components/animated-number.tsx +102 -0
- package/recipes/tracker-app/apps/native/src/features/tracker-app/components/calorie-card.tsx +66 -0
- package/recipes/tracker-app/apps/native/src/features/tracker-app/components/circular-progress.tsx +97 -0
- package/recipes/tracker-app/apps/native/src/features/tracker-app/components/floating-add-button.tsx +27 -0
- package/recipes/tracker-app/apps/native/src/features/tracker-app/components/macro-card.tsx +80 -0
- package/recipes/tracker-app/apps/native/src/features/tracker-app/components/promo-banner.tsx +98 -0
- package/recipes/tracker-app/apps/native/src/features/tracker-app/components/recently-logged.tsx +64 -0
- package/recipes/tracker-app/apps/native/src/features/tracker-app/components/week-calendar.tsx +68 -0
- package/recipes/tracker-app/recipe.json +22 -0
- package/recipes/tracker-app@latest.zip +0 -0
- package/recipes/upload-all.sh +32 -0
- package/recipes/voice-bot/apps/native/src/app/voice-bot/index.tsx +27 -0
- package/recipes/voice-bot/apps/native/src/features/voice-bot/README.md +185 -0
- package/recipes/voice-bot/apps/native/src/features/voice-bot/components/conversation-status.tsx +76 -0
- package/recipes/voice-bot/apps/native/src/features/voice-bot/components/index.ts +4 -0
- package/recipes/voice-bot/apps/native/src/features/voice-bot/components/message-input.tsx +98 -0
- package/recipes/voice-bot/apps/native/src/features/voice-bot/components/voice-bot-screen.tsx +173 -0
- package/recipes/voice-bot/apps/native/src/features/voice-bot/components/voice-controls.tsx +73 -0
- package/recipes/voice-bot/apps/native/src/features/voice-bot/index.ts +3 -0
- package/recipes/voice-bot/apps/native/src/features/voice-bot/services/index.ts +1 -0
- package/recipes/voice-bot/apps/native/src/features/voice-bot/services/use-voice-bot.ts +161 -0
- package/recipes/voice-bot/apps/native/src/features/voice-bot/types.ts +29 -0
- package/recipes/voice-bot/recipe.json +22 -0
- package/recipes/voice-bot@latest.zip +0 -0
- package/scripts/create-recipes.mjs +189 -0
- package/src/commands/add.ts +183 -0
- package/src/commands/devices.ts +38 -0
- package/src/commands/doctor.ts +67 -0
- package/src/commands/list.ts +45 -0
- package/src/commands/login.ts +24 -0
- package/src/commands/logout.ts +15 -0
- package/src/commands/remove.ts +78 -0
- package/src/core/__tests__/journal.test.ts +119 -0
- package/src/core/__tests__/validate.test.ts +64 -0
- package/src/core/archive.ts +69 -0
- package/src/core/auth.ts +103 -0
- package/src/core/codemod.ts +211 -0
- package/src/core/fsx.ts +80 -0
- package/src/core/http.ts +136 -0
- package/src/core/journal.ts +64 -0
- package/src/core/log.ts +9 -0
- package/src/core/pathGuard.ts +22 -0
- package/src/core/paths.ts +33 -0
- package/src/core/validate.ts +44 -0
- package/src/index.ts +27 -0
- package/test-critical-cases.mjs +258 -0
- package/tsconfig.json +21 -0
- package/vitest.config.mts +12 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Canvas, Group, RoundedRect } from '@shopify/react-native-skia';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
import { type LayoutChangeEvent, View, type ViewStyle } from 'react-native';
|
|
4
|
+
import Svg, { Text as SvgText } from 'react-native-svg';
|
|
5
|
+
|
|
6
|
+
import { useThemeConfig } from '@/lib/use-theme-config';
|
|
7
|
+
|
|
8
|
+
interface ChartConfig {
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
padding?: number;
|
|
12
|
+
showLabels?: boolean;
|
|
13
|
+
animated?: boolean;
|
|
14
|
+
duration?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface ChartDataPoint {
|
|
18
|
+
label: string;
|
|
19
|
+
value: number;
|
|
20
|
+
color?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Props = {
|
|
24
|
+
data: ChartDataPoint[];
|
|
25
|
+
config?: ChartConfig;
|
|
26
|
+
style?: ViewStyle;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const ColumnChart = ({ data, config = {}, style }: Props) => {
|
|
30
|
+
const [containerWidth, setContainerWidth] = useState(300);
|
|
31
|
+
const {
|
|
32
|
+
height = 200,
|
|
33
|
+
padding = 20,
|
|
34
|
+
showLabels = true,
|
|
35
|
+
animated = true,
|
|
36
|
+
duration = 800,
|
|
37
|
+
} = config;
|
|
38
|
+
const chartWidth = containerWidth || config.width || 300;
|
|
39
|
+
|
|
40
|
+
const theme = useThemeConfig();
|
|
41
|
+
const primaryColor = theme.colors.primary as string;
|
|
42
|
+
const mutedColor = theme.colors.mutedForeground as string;
|
|
43
|
+
|
|
44
|
+
const [progress, setProgress] = useState(1);
|
|
45
|
+
|
|
46
|
+
const onLayout = (e: LayoutChangeEvent) => {
|
|
47
|
+
const { width } = e.nativeEvent.layout;
|
|
48
|
+
if (width > 0) setContainerWidth(width);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!animated) {
|
|
53
|
+
setProgress(1);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let raf: number;
|
|
57
|
+
const start = Date.now();
|
|
58
|
+
const easeInOutCubic = (t: number) =>
|
|
59
|
+
t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2;
|
|
60
|
+
const tick = () => {
|
|
61
|
+
const elapsed = Date.now() - start;
|
|
62
|
+
const t = Math.min(1, elapsed / (duration || 800));
|
|
63
|
+
setProgress(easeInOutCubic(t));
|
|
64
|
+
if (t < 1) raf = requestAnimationFrame(tick);
|
|
65
|
+
};
|
|
66
|
+
setProgress(0);
|
|
67
|
+
raf = requestAnimationFrame(tick);
|
|
68
|
+
return () => cancelAnimationFrame(raf);
|
|
69
|
+
}, [animated, duration, data]);
|
|
70
|
+
|
|
71
|
+
if (!data.length) return null;
|
|
72
|
+
|
|
73
|
+
const maxValue = Math.max(...data.map((d) => d.value));
|
|
74
|
+
const innerChartWidth = chartWidth - padding * 2;
|
|
75
|
+
const chartHeight = height - padding * 2;
|
|
76
|
+
const barHeight = (chartHeight / data.length) * 0.8;
|
|
77
|
+
const barSpacing = (chartHeight / data.length) * 0.2;
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<View style={[{ width: '100%', height }, style]} onLayout={onLayout}>
|
|
81
|
+
<Canvas style={{ width: chartWidth, height }}>
|
|
82
|
+
<Group>
|
|
83
|
+
{data.map((item, index) => {
|
|
84
|
+
const w = (item.value / maxValue) * innerChartWidth * progress;
|
|
85
|
+
const x = padding;
|
|
86
|
+
const y =
|
|
87
|
+
padding + index * (barHeight + barSpacing) + barSpacing / 2;
|
|
88
|
+
return (
|
|
89
|
+
<RoundedRect
|
|
90
|
+
key={`bar-${index}`}
|
|
91
|
+
x={x}
|
|
92
|
+
y={y}
|
|
93
|
+
width={w}
|
|
94
|
+
height={barHeight}
|
|
95
|
+
color={(item.color || primaryColor) as string}
|
|
96
|
+
r={4}
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
})}
|
|
100
|
+
</Group>
|
|
101
|
+
</Canvas>
|
|
102
|
+
{showLabels && (
|
|
103
|
+
<Svg
|
|
104
|
+
width={chartWidth}
|
|
105
|
+
height={height}
|
|
106
|
+
style={{ position: 'absolute', left: 0, top: 0 }}
|
|
107
|
+
>
|
|
108
|
+
{data.map((item, index) => {
|
|
109
|
+
const w = (item.value / maxValue) * innerChartWidth;
|
|
110
|
+
const x = padding;
|
|
111
|
+
const y =
|
|
112
|
+
padding + index * (barHeight + barSpacing) + barSpacing / 2;
|
|
113
|
+
return (
|
|
114
|
+
<React.Fragment key={`label-${index}`}>
|
|
115
|
+
<SvgText
|
|
116
|
+
x={padding - 10}
|
|
117
|
+
y={y + barHeight / 2}
|
|
118
|
+
textAnchor="end"
|
|
119
|
+
fontSize={12}
|
|
120
|
+
fill={mutedColor}
|
|
121
|
+
alignmentBaseline="middle"
|
|
122
|
+
>
|
|
123
|
+
{item.label}
|
|
124
|
+
</SvgText>
|
|
125
|
+
<SvgText
|
|
126
|
+
x={x + w + 10}
|
|
127
|
+
y={y + barHeight / 2}
|
|
128
|
+
textAnchor="start"
|
|
129
|
+
fontSize={11}
|
|
130
|
+
fill={mutedColor}
|
|
131
|
+
fontWeight="600"
|
|
132
|
+
alignmentBaseline="middle"
|
|
133
|
+
>
|
|
134
|
+
{item.value}
|
|
135
|
+
</SvgText>
|
|
136
|
+
</React.Fragment>
|
|
137
|
+
);
|
|
138
|
+
})}
|
|
139
|
+
</Svg>
|
|
140
|
+
)}
|
|
141
|
+
</View>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Canvas,
|
|
3
|
+
Group,
|
|
4
|
+
Path as SkPath,
|
|
5
|
+
Skia,
|
|
6
|
+
} from '@shopify/react-native-skia';
|
|
7
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
8
|
+
import { type LayoutChangeEvent, View, type ViewStyle } from 'react-native';
|
|
9
|
+
import Svg, { Text as SvgText } from 'react-native-svg';
|
|
10
|
+
|
|
11
|
+
import { Text } from '@/components/ui';
|
|
12
|
+
import { useThemeConfig } from '@/lib/use-theme-config';
|
|
13
|
+
|
|
14
|
+
interface ChartConfig {
|
|
15
|
+
width?: number;
|
|
16
|
+
height?: number;
|
|
17
|
+
showLabels?: boolean; // not rendered in Skia v1 (no font binding yet)
|
|
18
|
+
animated?: boolean;
|
|
19
|
+
duration?: number;
|
|
20
|
+
innerRadius?: number; // ratio 0..1
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface ChartDataPoint {
|
|
24
|
+
label: string;
|
|
25
|
+
value: number;
|
|
26
|
+
color?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type Props = {
|
|
30
|
+
data: ChartDataPoint[];
|
|
31
|
+
config?: ChartConfig;
|
|
32
|
+
style?: ViewStyle;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const makeDonutSlicePath = (
|
|
36
|
+
cx: number,
|
|
37
|
+
cy: number,
|
|
38
|
+
outerR: number,
|
|
39
|
+
innerR: number,
|
|
40
|
+
startAngle: number,
|
|
41
|
+
endAngle: number,
|
|
42
|
+
) => {
|
|
43
|
+
const largeArcFlag = endAngle - startAngle > Math.PI ? 1 : 0;
|
|
44
|
+
|
|
45
|
+
const x1 = cx + outerR * Math.cos(startAngle);
|
|
46
|
+
const y1 = cy + outerR * Math.sin(startAngle);
|
|
47
|
+
const x2 = cx + outerR * Math.cos(endAngle);
|
|
48
|
+
const y2 = cy + outerR * Math.sin(endAngle);
|
|
49
|
+
|
|
50
|
+
const x3 = cx + innerR * Math.cos(endAngle);
|
|
51
|
+
const y3 = cy + innerR * Math.sin(endAngle);
|
|
52
|
+
const x4 = cx + innerR * Math.cos(startAngle);
|
|
53
|
+
const y4 = cy + innerR * Math.sin(startAngle);
|
|
54
|
+
|
|
55
|
+
const pathData = [
|
|
56
|
+
`M ${x1} ${y1}`,
|
|
57
|
+
`A ${outerR} ${outerR} 0 ${largeArcFlag} 1 ${x2} ${y2}`,
|
|
58
|
+
`L ${x3} ${y3}`,
|
|
59
|
+
`A ${innerR} ${innerR} 0 ${largeArcFlag} 0 ${x4} ${y4}`,
|
|
60
|
+
'Z',
|
|
61
|
+
].join(' ');
|
|
62
|
+
|
|
63
|
+
return Skia.Path.MakeFromSVGString(pathData) || Skia.Path.Make();
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const DoughnutChart = ({ data, config = {}, style }: Props) => {
|
|
67
|
+
const [containerWidth, setContainerWidth] = useState(300);
|
|
68
|
+
const {
|
|
69
|
+
height = 200,
|
|
70
|
+
animated = true,
|
|
71
|
+
duration = 1000,
|
|
72
|
+
innerRadius = 0.5,
|
|
73
|
+
showLabels = true,
|
|
74
|
+
} = config;
|
|
75
|
+
|
|
76
|
+
const theme = useThemeConfig();
|
|
77
|
+
const primaryColor = theme.colors.primary as string;
|
|
78
|
+
const chartWidth = containerWidth || config.width || 300;
|
|
79
|
+
const centerX = chartWidth / 2;
|
|
80
|
+
const centerY = height / 2;
|
|
81
|
+
|
|
82
|
+
const total = Math.max(
|
|
83
|
+
1,
|
|
84
|
+
data.reduce((s, d) => s + d.value, 0),
|
|
85
|
+
);
|
|
86
|
+
const outerR = Math.min(chartWidth, height) / 2 - 20;
|
|
87
|
+
const innerR = outerR * innerRadius;
|
|
88
|
+
|
|
89
|
+
const [progress, setProgress] = useState(1);
|
|
90
|
+
|
|
91
|
+
const onLayout = (e: LayoutChangeEvent) => {
|
|
92
|
+
const { width } = e.nativeEvent.layout;
|
|
93
|
+
if (width > 0) setContainerWidth(width);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (!animated) {
|
|
98
|
+
setProgress(1);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
let raf: number;
|
|
102
|
+
const start = Date.now();
|
|
103
|
+
const easeInOutCubic = (t: number) =>
|
|
104
|
+
t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2;
|
|
105
|
+
const tick = () => {
|
|
106
|
+
const elapsed = Date.now() - start;
|
|
107
|
+
const t = Math.min(1, elapsed / (duration || 1000));
|
|
108
|
+
setProgress(easeInOutCubic(t));
|
|
109
|
+
if (t < 1) raf = requestAnimationFrame(tick);
|
|
110
|
+
};
|
|
111
|
+
setProgress(0);
|
|
112
|
+
raf = requestAnimationFrame(tick);
|
|
113
|
+
return () => cancelAnimationFrame(raf);
|
|
114
|
+
}, [animated, duration, data]);
|
|
115
|
+
|
|
116
|
+
// fallback palette based on theme
|
|
117
|
+
const colors = useMemo(
|
|
118
|
+
() =>
|
|
119
|
+
[
|
|
120
|
+
primaryColor,
|
|
121
|
+
theme.colors.success[500],
|
|
122
|
+
theme.colors.warning[500],
|
|
123
|
+
theme.colors.danger[500],
|
|
124
|
+
theme.colors.neutral[500],
|
|
125
|
+
theme.colors.primary[600],
|
|
126
|
+
theme.colors.success[600],
|
|
127
|
+
theme.colors.warning[600],
|
|
128
|
+
theme.colors.danger[600],
|
|
129
|
+
theme.colors.neutral[600],
|
|
130
|
+
] as string[],
|
|
131
|
+
[
|
|
132
|
+
primaryColor,
|
|
133
|
+
theme.colors.success[500],
|
|
134
|
+
theme.colors.warning[500],
|
|
135
|
+
theme.colors.danger[500],
|
|
136
|
+
theme.colors.neutral[500],
|
|
137
|
+
theme.colors.primary[600],
|
|
138
|
+
theme.colors.success[600],
|
|
139
|
+
theme.colors.warning[600],
|
|
140
|
+
theme.colors.danger[600],
|
|
141
|
+
theme.colors.neutral[600],
|
|
142
|
+
],
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// Calculate cumulative data properly to avoid mutation
|
|
146
|
+
const cumulativeData = useMemo(() => {
|
|
147
|
+
if (!data.length) return [];
|
|
148
|
+
let accumulatedStart = -Math.PI / 2;
|
|
149
|
+
return data.map((item, idx) => {
|
|
150
|
+
const delta = (item.value / total) * Math.PI * 2 * progress;
|
|
151
|
+
const start = accumulatedStart;
|
|
152
|
+
const end = start + delta;
|
|
153
|
+
accumulatedStart = end;
|
|
154
|
+
const color = (item.color || colors[idx % colors.length]) as string;
|
|
155
|
+
const path = makeDonutSlicePath(
|
|
156
|
+
centerX,
|
|
157
|
+
centerY,
|
|
158
|
+
outerR,
|
|
159
|
+
innerR,
|
|
160
|
+
start,
|
|
161
|
+
end,
|
|
162
|
+
);
|
|
163
|
+
return { path, color, key: `slice-${idx}` };
|
|
164
|
+
});
|
|
165
|
+
}, [data, total, progress, centerX, centerY, outerR, innerR, colors]);
|
|
166
|
+
|
|
167
|
+
if (!data.length) return null;
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<View style={[{ width: '100%' }, style]} onLayout={onLayout}>
|
|
171
|
+
<Canvas style={{ width: chartWidth, height }}>
|
|
172
|
+
<Group>
|
|
173
|
+
{cumulativeData.map(({ path, color, key }) => (
|
|
174
|
+
<SkPath key={key} path={path} color={color} style="fill" />
|
|
175
|
+
))}
|
|
176
|
+
</Group>
|
|
177
|
+
</Canvas>
|
|
178
|
+
{showLabels && (
|
|
179
|
+
<Svg
|
|
180
|
+
width={chartWidth}
|
|
181
|
+
height={height}
|
|
182
|
+
style={{ position: 'absolute', left: 0, top: 0 }}
|
|
183
|
+
>
|
|
184
|
+
{(() => {
|
|
185
|
+
return data.map((item, idx) => {
|
|
186
|
+
const startAngle = data
|
|
187
|
+
.slice(0, idx)
|
|
188
|
+
.reduce(
|
|
189
|
+
(sum, d) => sum + (d.value / total) * Math.PI * 2,
|
|
190
|
+
-Math.PI / 2,
|
|
191
|
+
);
|
|
192
|
+
const slice = (item.value / total) * Math.PI * 2;
|
|
193
|
+
const mid = startAngle + slice / 2;
|
|
194
|
+
const r = (outerR + innerR) / 2;
|
|
195
|
+
const lx = centerX + r * Math.cos(mid);
|
|
196
|
+
const ly = centerY + r * Math.sin(mid);
|
|
197
|
+
return (
|
|
198
|
+
<SvgText
|
|
199
|
+
key={`label-${idx}`}
|
|
200
|
+
x={lx}
|
|
201
|
+
y={ly}
|
|
202
|
+
textAnchor="middle"
|
|
203
|
+
fontSize={12}
|
|
204
|
+
fill={theme.colors.foreground as string}
|
|
205
|
+
fontWeight="600"
|
|
206
|
+
>
|
|
207
|
+
{Math.round((item.value / total) * 100)}%
|
|
208
|
+
</SvgText>
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
})()}
|
|
212
|
+
</Svg>
|
|
213
|
+
)}
|
|
214
|
+
{/* Legend */}
|
|
215
|
+
<View style={{ marginTop: 10 }}>
|
|
216
|
+
{data.map((item, index) => (
|
|
217
|
+
<View
|
|
218
|
+
key={`legend-${index}`}
|
|
219
|
+
style={{
|
|
220
|
+
flexDirection: 'row',
|
|
221
|
+
alignItems: 'center',
|
|
222
|
+
marginBottom: 5,
|
|
223
|
+
}}
|
|
224
|
+
>
|
|
225
|
+
<View
|
|
226
|
+
style={{
|
|
227
|
+
width: 12,
|
|
228
|
+
height: 12,
|
|
229
|
+
borderRadius: 6,
|
|
230
|
+
backgroundColor:
|
|
231
|
+
item.color || (colors[index % colors.length] as string),
|
|
232
|
+
marginRight: 8,
|
|
233
|
+
}}
|
|
234
|
+
/>
|
|
235
|
+
<Text
|
|
236
|
+
className="text-xs"
|
|
237
|
+
style={{ color: theme.colors.mutedForeground }}
|
|
238
|
+
>
|
|
239
|
+
{item.label}: {item.value}
|
|
240
|
+
</Text>
|
|
241
|
+
</View>
|
|
242
|
+
))}
|
|
243
|
+
</View>
|
|
244
|
+
</View>
|
|
245
|
+
);
|
|
246
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { AreaChart } from './area-chart';
|
|
2
|
+
export { BarChart } from './bar-chart';
|
|
3
|
+
export { CandlestickChart } from './candlestick-chart';
|
|
4
|
+
export { ColumnChart } from './column-chart';
|
|
5
|
+
export { DoughnutChart } from './doughnut-chart';
|
|
6
|
+
export { LineChart } from './line-chart';
|
|
7
|
+
export { RadarChart } from './radar-chart';
|
|
8
|
+
export { RadialBarChart } from './radial-bar-chart';
|
|
9
|
+
export { StackedAreaChart } from './stacked-area-chart';
|
|
10
|
+
export { StackedBarChart } from './stacked-bar-chart';
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Canvas,
|
|
3
|
+
Circle,
|
|
4
|
+
Group,
|
|
5
|
+
LinearGradient,
|
|
6
|
+
Path as SkPath,
|
|
7
|
+
Skia,
|
|
8
|
+
vec,
|
|
9
|
+
} from '@shopify/react-native-skia';
|
|
10
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
11
|
+
import { type LayoutChangeEvent, View, type ViewStyle } from 'react-native';
|
|
12
|
+
import Svg, { G, Text as SvgText } from 'react-native-svg';
|
|
13
|
+
|
|
14
|
+
import { useThemeConfig } from '@/lib/use-theme-config';
|
|
15
|
+
|
|
16
|
+
interface ChartConfig {
|
|
17
|
+
width?: number;
|
|
18
|
+
height?: number;
|
|
19
|
+
padding?: number;
|
|
20
|
+
showGrid?: boolean;
|
|
21
|
+
showLabels?: boolean; // not rendered in Skia v1 (no font binding yet)
|
|
22
|
+
animated?: boolean;
|
|
23
|
+
duration?: number;
|
|
24
|
+
gradient?: boolean;
|
|
25
|
+
interactive?: boolean; // not implemented in Skia v1
|
|
26
|
+
showYLabels?: boolean; // not rendered in Skia v1
|
|
27
|
+
yLabelCount?: number;
|
|
28
|
+
yAxisWidth?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type ChartDataPoint = {
|
|
32
|
+
x: string | number;
|
|
33
|
+
y: number;
|
|
34
|
+
label?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type Props = {
|
|
38
|
+
data: ChartDataPoint[];
|
|
39
|
+
config?: ChartConfig;
|
|
40
|
+
style?: ViewStyle;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const makeSmoothPath = (points: { x: number; y: number }[]) => {
|
|
44
|
+
const p = Skia.Path.Make();
|
|
45
|
+
if (!points.length) return p;
|
|
46
|
+
p.moveTo(points[0].x, points[0].y);
|
|
47
|
+
for (let i = 1; i < points.length; i++) {
|
|
48
|
+
const prev = points[i - 1];
|
|
49
|
+
const curr = points[i];
|
|
50
|
+
const cpx = (prev.x + curr.x) / 2;
|
|
51
|
+
const cpy = prev.y;
|
|
52
|
+
p.quadTo(cpx, cpy, curr.x, curr.y);
|
|
53
|
+
}
|
|
54
|
+
return p;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const makeAreaPath = (
|
|
58
|
+
points: { x: number; y: number }[],
|
|
59
|
+
height: number,
|
|
60
|
+
padding: number,
|
|
61
|
+
) => {
|
|
62
|
+
const p = makeSmoothPath(points).copy();
|
|
63
|
+
if (!points.length) return p;
|
|
64
|
+
const last = points[points.length - 1];
|
|
65
|
+
const first = points[0];
|
|
66
|
+
p.lineTo(last.x, height - padding);
|
|
67
|
+
p.lineTo(first.x, height - padding);
|
|
68
|
+
p.close();
|
|
69
|
+
return p;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const withAlpha = (hex: string, alpha: number) => {
|
|
73
|
+
// alpha 0..1 -> 00..FF
|
|
74
|
+
const a = Math.round(Math.min(1, Math.max(0, alpha)) * 255)
|
|
75
|
+
.toString(16)
|
|
76
|
+
.padStart(2, '0');
|
|
77
|
+
if (hex.startsWith('#') && (hex.length === 7 || hex.length === 9)) {
|
|
78
|
+
// #RRGGBB or #RRGGBBAA
|
|
79
|
+
return hex.length === 7 ? `${hex}${a}` : `${hex.slice(0, 7)}${a}`;
|
|
80
|
+
}
|
|
81
|
+
return hex; // fallback
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const formatNumber = (num: number): string => {
|
|
85
|
+
if (num >= 1000000) return (num / 1000000).toFixed(1) + 'M';
|
|
86
|
+
if (num >= 1000) return (num / 1000).toFixed(1) + 'K';
|
|
87
|
+
return num.toFixed(0);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const LineChart = ({ data, config = {}, style }: Props) => {
|
|
91
|
+
const hasData = data.length > 0;
|
|
92
|
+
const [containerWidth, setContainerWidth] = useState(300);
|
|
93
|
+
const [progress, setProgress] = useState(1);
|
|
94
|
+
const {
|
|
95
|
+
height = 200,
|
|
96
|
+
padding = 20,
|
|
97
|
+
showGrid = true,
|
|
98
|
+
animated = true,
|
|
99
|
+
duration = 1000,
|
|
100
|
+
gradient = false,
|
|
101
|
+
showYLabels = true,
|
|
102
|
+
yLabelCount = 5,
|
|
103
|
+
yAxisWidth = 20,
|
|
104
|
+
} = config;
|
|
105
|
+
|
|
106
|
+
const chartWidth = containerWidth || config.width || 300;
|
|
107
|
+
const theme = useThemeConfig();
|
|
108
|
+
const primaryColor = theme.colors.primary as string;
|
|
109
|
+
const mutedColor = theme.colors.mutedForeground as string;
|
|
110
|
+
|
|
111
|
+
const onLayout = (e: LayoutChangeEvent) => {
|
|
112
|
+
const { width } = e.nativeEvent.layout;
|
|
113
|
+
if (width > 0) setContainerWidth(width);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (!animated) {
|
|
118
|
+
setProgress(1);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
let raf: number;
|
|
122
|
+
const start = Date.now();
|
|
123
|
+
const easeInOutCubic = (t: number) =>
|
|
124
|
+
t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2;
|
|
125
|
+
const tick = () => {
|
|
126
|
+
const elapsed = Date.now() - start;
|
|
127
|
+
const t = Math.min(1, elapsed / (duration || 1000));
|
|
128
|
+
setProgress(easeInOutCubic(t));
|
|
129
|
+
if (t < 1) raf = requestAnimationFrame(tick);
|
|
130
|
+
};
|
|
131
|
+
setProgress(0);
|
|
132
|
+
raf = requestAnimationFrame(tick);
|
|
133
|
+
return () => cancelAnimationFrame(raf);
|
|
134
|
+
}, [animated, duration, data]);
|
|
135
|
+
|
|
136
|
+
const maxValue = hasData ? Math.max(...data.map((d) => d.y)) : 0;
|
|
137
|
+
const minValue = hasData ? Math.min(...data.map((d) => d.y)) : 0;
|
|
138
|
+
const valueRange = hasData ? maxValue - minValue || 1 : 1;
|
|
139
|
+
|
|
140
|
+
const leftPadding = showYLabels ? padding + yAxisWidth : padding;
|
|
141
|
+
const innerChartWidth = chartWidth - leftPadding - padding;
|
|
142
|
+
const chartHeight = height - padding * 2;
|
|
143
|
+
|
|
144
|
+
const points = useMemo(
|
|
145
|
+
() =>
|
|
146
|
+
(hasData ? data : []).map((point, index) => ({
|
|
147
|
+
x:
|
|
148
|
+
leftPadding +
|
|
149
|
+
(index / Math.max(1, data.length - 1)) * innerChartWidth,
|
|
150
|
+
y: padding + ((maxValue - point.y) / valueRange) * chartHeight,
|
|
151
|
+
})),
|
|
152
|
+
[
|
|
153
|
+
data,
|
|
154
|
+
hasData,
|
|
155
|
+
leftPadding,
|
|
156
|
+
innerChartWidth,
|
|
157
|
+
padding,
|
|
158
|
+
maxValue,
|
|
159
|
+
valueRange,
|
|
160
|
+
chartHeight,
|
|
161
|
+
],
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const path = makeSmoothPath(points);
|
|
165
|
+
const areaPath = gradient ? makeAreaPath(points, height, padding) : undefined;
|
|
166
|
+
|
|
167
|
+
// Simple horizontal grid lines
|
|
168
|
+
const yAxisLabels = useMemo(() => {
|
|
169
|
+
const labels: { value: number; y: number }[] = [];
|
|
170
|
+
const count = yLabelCount;
|
|
171
|
+
for (let i = 0; i < count; i++) {
|
|
172
|
+
const ratio = i / (count - 1);
|
|
173
|
+
const value = maxValue - ratio * valueRange;
|
|
174
|
+
const y = padding + ratio * chartHeight;
|
|
175
|
+
labels.push({ value, y });
|
|
176
|
+
}
|
|
177
|
+
return labels;
|
|
178
|
+
}, [yLabelCount, padding, chartHeight, maxValue, valueRange]);
|
|
179
|
+
|
|
180
|
+
const gridYs: number[] = useMemo(
|
|
181
|
+
() => (showGrid ? yAxisLabels.map((l) => l.y) : []),
|
|
182
|
+
[showGrid, yAxisLabels],
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
// Batch grid lines into a single path each to reduce draw calls
|
|
186
|
+
const gridHPath = useMemo(() => {
|
|
187
|
+
const p = Skia.Path.Make();
|
|
188
|
+
if (!showGrid) return p;
|
|
189
|
+
for (const y of gridYs) {
|
|
190
|
+
p.moveTo(leftPadding, y);
|
|
191
|
+
p.lineTo(chartWidth - padding, y);
|
|
192
|
+
}
|
|
193
|
+
return p;
|
|
194
|
+
}, [showGrid, gridYs, leftPadding, chartWidth, padding]);
|
|
195
|
+
|
|
196
|
+
const gridVPath = useMemo(() => {
|
|
197
|
+
const p = Skia.Path.Make();
|
|
198
|
+
if (!showGrid) return p;
|
|
199
|
+
for (const pt of points) {
|
|
200
|
+
p.moveTo(pt.x, padding);
|
|
201
|
+
p.lineTo(pt.x, height - padding);
|
|
202
|
+
}
|
|
203
|
+
return p;
|
|
204
|
+
}, [showGrid, points, padding, height]);
|
|
205
|
+
|
|
206
|
+
if (!hasData) return null;
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<View style={[{ width: '100%', height }, style]} onLayout={onLayout}>
|
|
210
|
+
<Canvas style={{ width: chartWidth, height }}>
|
|
211
|
+
{showGrid && (
|
|
212
|
+
<Group>
|
|
213
|
+
<SkPath
|
|
214
|
+
path={gridHPath}
|
|
215
|
+
color={mutedColor}
|
|
216
|
+
style="stroke"
|
|
217
|
+
strokeWidth={0.5}
|
|
218
|
+
opacity={0.3}
|
|
219
|
+
/>
|
|
220
|
+
<SkPath
|
|
221
|
+
path={gridVPath}
|
|
222
|
+
color={mutedColor}
|
|
223
|
+
style="stroke"
|
|
224
|
+
strokeWidth={0.5}
|
|
225
|
+
opacity={0.2}
|
|
226
|
+
/>
|
|
227
|
+
</Group>
|
|
228
|
+
)}
|
|
229
|
+
|
|
230
|
+
{gradient && areaPath && (
|
|
231
|
+
<SkPath path={areaPath} style="fill">
|
|
232
|
+
<LinearGradient
|
|
233
|
+
start={vec(0, padding)}
|
|
234
|
+
end={vec(0, height - padding)}
|
|
235
|
+
colors={[
|
|
236
|
+
withAlpha(primaryColor, 0.3),
|
|
237
|
+
withAlpha(primaryColor, 0.05),
|
|
238
|
+
]}
|
|
239
|
+
/>
|
|
240
|
+
</SkPath>
|
|
241
|
+
)}
|
|
242
|
+
|
|
243
|
+
<SkPath
|
|
244
|
+
path={path}
|
|
245
|
+
color={primaryColor}
|
|
246
|
+
style="stroke"
|
|
247
|
+
strokeWidth={2}
|
|
248
|
+
strokeJoin="round"
|
|
249
|
+
strokeCap="round"
|
|
250
|
+
start={0}
|
|
251
|
+
end={progress}
|
|
252
|
+
/>
|
|
253
|
+
|
|
254
|
+
{points.map((pt, idx) => (
|
|
255
|
+
<Circle
|
|
256
|
+
key={`pt-${idx}`}
|
|
257
|
+
cx={pt.x}
|
|
258
|
+
cy={pt.y}
|
|
259
|
+
r={3}
|
|
260
|
+
color={primaryColor}
|
|
261
|
+
opacity={progress}
|
|
262
|
+
/>
|
|
263
|
+
))}
|
|
264
|
+
</Canvas>
|
|
265
|
+
{/* Labels overlays for parity with SVG */}
|
|
266
|
+
{(config.showYLabels || config.showLabels) && (
|
|
267
|
+
<Svg
|
|
268
|
+
width={chartWidth}
|
|
269
|
+
height={height}
|
|
270
|
+
style={{ position: 'absolute', left: 0, top: 0 }}
|
|
271
|
+
>
|
|
272
|
+
{config.showYLabels && (
|
|
273
|
+
<G>
|
|
274
|
+
{yAxisLabels.map((label, index) => (
|
|
275
|
+
<SvgText
|
|
276
|
+
key={`y-label-${index}`}
|
|
277
|
+
x={leftPadding - 10}
|
|
278
|
+
y={label.y + 4}
|
|
279
|
+
textAnchor="end"
|
|
280
|
+
fontSize={10}
|
|
281
|
+
fill={mutedColor}
|
|
282
|
+
>
|
|
283
|
+
{formatNumber(label.value)}
|
|
284
|
+
</SvgText>
|
|
285
|
+
))}
|
|
286
|
+
</G>
|
|
287
|
+
)}
|
|
288
|
+
{config.showLabels && (
|
|
289
|
+
<G>
|
|
290
|
+
{data.map((point, index) => (
|
|
291
|
+
<SvgText
|
|
292
|
+
key={`x-label-${index}`}
|
|
293
|
+
x={points[index].x}
|
|
294
|
+
y={height - 5}
|
|
295
|
+
textAnchor="middle"
|
|
296
|
+
fontSize={10}
|
|
297
|
+
fill={mutedColor}
|
|
298
|
+
>
|
|
299
|
+
{point.label || String(point.x)}
|
|
300
|
+
</SvgText>
|
|
301
|
+
))}
|
|
302
|
+
</G>
|
|
303
|
+
)}
|
|
304
|
+
</Svg>
|
|
305
|
+
)}
|
|
306
|
+
</View>
|
|
307
|
+
);
|
|
308
|
+
};
|