principles-disciple 1.71.0 → 1.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/openclaw.plugin.json +10 -5
  2. package/package.json +17 -19
  3. package/scripts/acceptance-test.mjs +16 -73
  4. package/scripts/sync-plugin.mjs +382 -77
  5. package/src/commands/archive-impl.ts +2 -1
  6. package/src/commands/capabilities.ts +2 -2
  7. package/src/commands/context.ts +2 -2
  8. package/src/commands/disable-impl.ts +2 -1
  9. package/src/commands/evolution-status.ts +16 -16
  10. package/src/commands/export.ts +12 -67
  11. package/src/commands/pain.ts +91 -1
  12. package/src/commands/principle-rollback.ts +2 -1
  13. package/src/commands/promote-impl.ts +7 -43
  14. package/src/commands/rollback-impl.ts +2 -1
  15. package/src/commands/rollback.ts +2 -1
  16. package/src/commands/samples.ts +2 -1
  17. package/src/commands/thinking-os.ts +2 -1
  18. package/src/config/errors.ts +18 -2
  19. package/src/constants/diagnostician.ts +2 -2
  20. package/src/constants/tools.ts +2 -1
  21. package/src/core/__tests__/focus-history.test.ts +210 -0
  22. package/src/core/config.ts +1 -1
  23. package/src/core/confirm-first-gate.ts +255 -0
  24. package/src/core/correction-cue-learner.ts +2 -136
  25. package/src/core/correction-types.ts +16 -88
  26. package/src/core/dictionary.ts +19 -20
  27. package/src/core/empathy-keyword-matcher.ts +17 -289
  28. package/src/core/empathy-types.ts +18 -229
  29. package/src/core/event-log.ts +38 -132
  30. package/src/core/evolution-reducer.ts +21 -2
  31. package/src/core/evolution-types.ts +76 -464
  32. package/src/core/file-store.ts +80 -0
  33. package/src/core/focus-history.ts +228 -955
  34. package/src/core/local-worker-routing.ts +34 -314
  35. package/src/core/merge-gate-audit.ts +0 -195
  36. package/src/core/pain-diagnostic-gate.ts +154 -0
  37. package/src/core/pain-signal.ts +21 -138
  38. package/src/core/pain.ts +15 -88
  39. package/src/core/pd-task-reconciler.ts +26 -115
  40. package/src/core/pd-task-service.ts +9 -9
  41. package/src/core/pd-task-types.ts +23 -127
  42. package/src/core/principle-compiler/__tests__/compiler-replay-gate.test.ts +174 -0
  43. package/src/core/principle-compiler/code-validator.ts +15 -42
  44. package/src/core/principle-compiler/compiler.ts +100 -15
  45. package/src/core/principle-compiler/index.ts +5 -2
  46. package/src/core/principle-compiler/template-generator.ts +4 -104
  47. package/src/core/principle-injection.ts +10 -202
  48. package/src/core/principle-internalization/filesystem-lifecycle-datasource.ts +42 -0
  49. package/src/core/principle-internalization/lifecycle-read-model.ts +39 -242
  50. package/src/core/principle-internalization/principle-lifecycle-service.ts +12 -10
  51. package/src/core/principle-tree-ledger-adapter.ts +145 -0
  52. package/src/core/principle-tree-ledger.ts +8 -6
  53. package/src/core/reflection/reflection-context.ts +14 -109
  54. package/src/core/replay-engine.ts +8 -500
  55. package/src/core/rule-host-helpers.ts +5 -35
  56. package/src/core/rule-host-types.ts +10 -82
  57. package/src/core/rule-host.ts +6 -63
  58. package/src/core/runtime-v2-prompt-activation-reader.ts +231 -0
  59. package/src/core/session-tracker.ts +87 -101
  60. package/src/core/shadow-observation-registry.ts +19 -48
  61. package/src/core/trajectory.ts +3 -1
  62. package/src/core/workflow-funnel-loader.ts +62 -68
  63. package/src/core/workspace-context.ts +46 -0
  64. package/src/core/workspace-dir-service.ts +1 -1
  65. package/src/core/workspace-dir-validation.ts +18 -9
  66. package/src/hooks/AGENTS.md +1 -1
  67. package/src/hooks/gate-block-helper.ts +46 -44
  68. package/src/hooks/gate.ts +207 -7
  69. package/src/hooks/lifecycle.ts +30 -32
  70. package/src/hooks/llm.ts +60 -32
  71. package/src/hooks/pain.ts +297 -103
  72. package/src/hooks/prompt.ts +469 -339
  73. package/src/hooks/subagent.ts +2 -29
  74. package/src/i18n/commands.ts +2 -10
  75. package/src/index.ts +95 -85
  76. package/src/openclaw-sdk.ts +311 -0
  77. package/src/service/central-database.ts +8 -4
  78. package/src/service/evolution-queue-migration.ts +2 -1
  79. package/src/service/evolution-worker.ts +163 -1786
  80. package/src/service/internalization-trigger-adapter.ts +302 -0
  81. package/src/service/keyword-optimization-service.ts +4 -4
  82. package/src/service/monitoring-query-service.ts +1 -215
  83. package/src/service/queue-io.ts +60 -331
  84. package/src/service/runtime-summary-service.ts +115 -18
  85. package/src/service/subagent-workflow/index.ts +0 -41
  86. package/src/service/subagent-workflow/types.ts +9 -120
  87. package/src/service/subagent-workflow/workflow-store.ts +2 -119
  88. package/src/service/workflow-watchdog.ts +0 -43
  89. package/src/types/event-payload.ts +16 -74
  90. package/src/types/event-types.ts +39 -547
  91. package/src/types/hygiene-types.ts +7 -30
  92. package/src/types/principle-tree-schema.ts +20 -222
  93. package/src/types/queue.ts +15 -70
  94. package/src/types/runtime-summary.ts +5 -49
  95. package/src/utils/io.ts +10 -0
  96. package/src/utils/retry.ts +1 -1
  97. package/src/utils/shadow-fingerprint.ts +2 -2
  98. package/src/utils/workspace-resolver.ts +50 -0
  99. package/templates/langs/en/core/AGENTS.md +2 -2
  100. package/templates/langs/en/core/BOOT.md +1 -1
  101. package/templates/langs/en/core/HEARTBEAT.md +2 -2
  102. package/templates/langs/en/skills/ai-sprint-orchestration/references/agent-registry.json +1 -72
  103. package/templates/langs/en/skills/ai-sprint-orchestration/references/specs/bugfix-complex-template.json +6 -6
  104. package/templates/langs/en/skills/ai-sprint-orchestration/references/specs/feature-complex-template.json +6 -6
  105. package/templates/langs/en/skills/ai-sprint-orchestration/references/specs/workflow-validation-minimal-verify.json +2 -12
  106. package/templates/langs/en/skills/ai-sprint-orchestration/references/specs/workflow-validation-minimal.json +2 -12
  107. package/templates/langs/en/skills/ai-sprint-orchestration/runtime/.gitignore +2 -2
  108. package/templates/langs/en/skills/ai-sprint-orchestration/scripts/run.mjs +51 -15
  109. package/templates/langs/en/skills/evolve-task/SKILL.md +1 -1
  110. package/templates/langs/en/skills/pd-cli-operator/SKILL.md +67 -0
  111. package/templates/langs/en/skills/pd-diagnostician/SKILL.md +1 -1
  112. package/templates/langs/en/skills/pd-mentor/SKILL.md +1 -1
  113. package/templates/langs/en/skills/pd-pain-signal/SKILL.md +17 -39
  114. package/templates/langs/en/skills/pd-runtime-v2/SKILL.md +61 -0
  115. package/templates/langs/zh/core/AGENTS.md +2 -2
  116. package/templates/langs/zh/core/BOOT.md +1 -1
  117. package/templates/langs/zh/core/HEARTBEAT.md +2 -2
  118. package/templates/langs/zh/skills/ai-sprint-orchestration/references/agent-registry.json +1 -72
  119. package/templates/langs/zh/skills/ai-sprint-orchestration/references/specs/bugfix-complex-template.json +6 -6
  120. package/templates/langs/zh/skills/ai-sprint-orchestration/references/specs/feature-complex-template.json +6 -6
  121. package/templates/langs/zh/skills/ai-sprint-orchestration/references/specs/nocturnal-trinity-quality-enhancement.json +8 -8
  122. package/templates/langs/zh/skills/ai-sprint-orchestration/references/specs/workflow-validation-minimal-verify.json +2 -12
  123. package/templates/langs/zh/skills/ai-sprint-orchestration/references/specs/workflow-validation-minimal.json +2 -12
  124. package/templates/langs/zh/skills/ai-sprint-orchestration/runtime/.gitignore +2 -2
  125. package/templates/langs/zh/skills/ai-sprint-orchestration/scripts/run.mjs +51 -15
  126. package/templates/langs/zh/skills/ai-sprint-orchestration/test/run.test.mjs +21 -5
  127. package/templates/langs/zh/skills/evolve-task/SKILL.md +2 -2
  128. package/templates/langs/zh/skills/pd-cli-operator/SKILL.md +67 -0
  129. package/templates/langs/zh/skills/pd-diagnostician/SKILL.md +1 -1
  130. package/templates/langs/zh/skills/pd-mentor/SKILL.md +1 -1
  131. package/templates/langs/zh/skills/pd-pain-signal/SKILL.md +17 -38
  132. package/templates/langs/zh/skills/pd-runtime-v2/SKILL.md +61 -0
  133. package/tests/build-artifacts.test.ts +1 -3
  134. package/tests/commands/evolution-status.test.ts +0 -118
  135. package/tests/core/bootstrap-rules.test.ts +1 -1
  136. package/tests/core/config.test.ts +1 -1
  137. package/tests/core/event-log.test.ts +35 -0
  138. package/tests/core/evolution-engine.test.ts +610 -0
  139. package/tests/core/file-store.test.ts +102 -0
  140. package/tests/core/focus-history.test.ts +203 -11
  141. package/tests/core/merge-gate-audit.test.ts +2 -169
  142. package/tests/core/model-deployment-registry.test.ts +7 -1
  143. package/tests/core/model-training-registry.test.ts +19 -0
  144. package/tests/core/observability.test.ts +0 -1
  145. package/tests/core/pain-diagnostic-gate.test.ts +498 -0
  146. package/tests/core/pain.test.ts +0 -1
  147. package/tests/core/principle-internalization/deprecated-readiness.test.ts +2 -2
  148. package/tests/core/principle-internalization/lifecycle-metrics.test.ts +2 -2
  149. package/tests/core/principle-internalization/{internalization-routing-policy.test.ts → lifecycle-routing-policy.test.ts} +6 -6
  150. package/tests/core/principle-internalization/lineage-source-retired.test.ts +56 -0
  151. package/tests/core/principle-internalization/principle-lifecycle-service.test.ts +1 -23
  152. package/tests/core/principle-tree-ledger-adapter.test.ts +253 -0
  153. package/tests/core/reflection-context.test.ts +0 -14
  154. package/tests/core/replay-engine.test.ts +127 -215
  155. package/tests/core/rule-host-helpers.test.ts +2 -2
  156. package/tests/core/rule-implementation-runtime.test.ts +0 -27
  157. package/tests/core/workflow-funnel-loader.test.ts +162 -0
  158. package/tests/core/workspace-dir-validation.test.ts +8 -1
  159. package/tests/core-anti-growth.test.ts +192 -0
  160. package/tests/hook-workspace-nextaction-contract.test.ts +42 -0
  161. package/tests/hooks/confirm-first-gate.test.ts +333 -0
  162. package/tests/hooks/gate-auto-correct-shadow.test.ts +310 -0
  163. package/tests/hooks/gate-auto-correct.test.ts +665 -0
  164. package/tests/hooks/gate-rule-host-pipeline.test.ts +2 -1
  165. package/tests/hooks/pain.test.ts +269 -12
  166. package/tests/hooks/prompt-characterization.test.ts +500 -0
  167. package/tests/hooks/prompt-size-guard.test.ts +329 -0
  168. package/tests/hooks/runtime-v2-prompt-activation.test.ts +869 -0
  169. package/tests/index.test.ts +94 -1
  170. package/tests/integration/auto-entry-gate.test.ts +248 -0
  171. package/tests/integration/internalization-trigger-guard.test.ts +69 -0
  172. package/tests/integration/m8-legacy-paths.test.ts +63 -0
  173. package/tests/integration/runtime-v2-pain-guard.test.ts +125 -0
  174. package/tests/plugin-config-resolution-cutover.test.ts +359 -0
  175. package/tests/runtime-v2-discovery-guard.test.ts +154 -0
  176. package/tests/service/central-database.test.ts +457 -0
  177. package/tests/service/evolution-worker.correction-observer.test.ts +173 -0
  178. package/tests/service/evolution-worker.timeout.test.ts +11 -129
  179. package/tests/service/internalization-trigger-adapter.test.ts +251 -0
  180. package/tests/service/monitoring-query-service.test.ts +1 -47
  181. package/tests/service/queue-io.test.ts +1 -62
  182. package/tests/service/runtime-summary-service.test.ts +184 -3
  183. package/tests/service/workflow-watchdog.test.ts +0 -91
  184. package/tests/utils/file-lock.test.ts +5 -3
  185. package/tests/utils/session-key.test.ts +52 -0
  186. package/tests/utils/subagent-probe.test.ts +48 -1
  187. package/vitest.config.ts +4 -11
  188. package/.planning/codebase/ARCHITECTURE.md +0 -157
  189. package/.planning/codebase/CONCERNS.md +0 -145
  190. package/.planning/codebase/CONVENTIONS.md +0 -148
  191. package/.planning/codebase/INTEGRATIONS.md +0 -81
  192. package/.planning/codebase/STACK.md +0 -87
  193. package/.planning/codebase/STRUCTURE.md +0 -193
  194. package/.planning/codebase/TESTING.md +0 -243
  195. package/.planning/phases/01-basic-visualization/01-GAP-CLOSURE-VERIFICATION.md +0 -113
  196. package/docs/COMMAND_REFERENCE.md +0 -76
  197. package/docs/COMMAND_REFERENCE_EN.md +0 -79
  198. package/scripts/build-web.mjs +0 -46
  199. package/scripts/diagnose-nocturnal.mjs +0 -537
  200. package/scripts/seed-nocturnal-scenarios.mjs +0 -384
  201. package/src/commands/nocturnal-review.ts +0 -322
  202. package/src/commands/nocturnal-rollout.ts +0 -790
  203. package/src/commands/nocturnal-train.ts +0 -986
  204. package/src/commands/pd-reflect.ts +0 -88
  205. package/src/core/adaptive-thresholds.ts +0 -478
  206. package/src/core/diagnostician-task-store.ts +0 -192
  207. package/src/core/nocturnal-arbiter.ts +0 -715
  208. package/src/core/nocturnal-artifact-lineage.ts +0 -116
  209. package/src/core/nocturnal-artificer.ts +0 -257
  210. package/src/core/nocturnal-candidate-scoring.ts +0 -530
  211. package/src/core/nocturnal-compliance.ts +0 -1146
  212. package/src/core/nocturnal-dataset.ts +0 -763
  213. package/src/core/nocturnal-executability.ts +0 -428
  214. package/src/core/nocturnal-export.ts +0 -499
  215. package/src/core/nocturnal-paths.ts +0 -240
  216. package/src/core/nocturnal-reasoning-deriver.ts +0 -343
  217. package/src/core/nocturnal-rule-implementation-validator.ts +0 -246
  218. package/src/core/nocturnal-snapshot-contract.ts +0 -99
  219. package/src/core/nocturnal-trajectory-extractor.ts +0 -512
  220. package/src/core/nocturnal-trinity-types.ts +0 -218
  221. package/src/core/nocturnal-trinity.ts +0 -2680
  222. package/src/core/principle-internalization/deprecated-readiness.ts +0 -93
  223. package/src/core/principle-internalization/internalization-routing-policy.ts +0 -208
  224. package/src/core/principle-internalization/lifecycle-metrics.ts +0 -152
  225. package/src/http/principles-console-route.ts +0 -709
  226. package/src/service/central-health-service.ts +0 -49
  227. package/src/service/central-overview-service.ts +0 -138
  228. package/src/service/control-ui-query-service.ts +0 -900
  229. package/src/service/cooldown-strategy.ts +0 -97
  230. package/src/service/evolution-pain-context.ts +0 -79
  231. package/src/service/evolution-query-service.ts +0 -407
  232. package/src/service/health-query-service.ts +0 -1038
  233. package/src/service/nocturnal-config.ts +0 -214
  234. package/src/service/nocturnal-runtime.ts +0 -734
  235. package/src/service/nocturnal-service.ts +0 -1605
  236. package/src/service/nocturnal-target-selector.ts +0 -545
  237. package/src/service/sleep-cycle.ts +0 -157
  238. package/src/service/startup-reconciler.ts +0 -112
  239. package/src/service/subagent-workflow/correction-observer-types.ts +0 -82
  240. package/src/service/subagent-workflow/correction-observer-workflow-manager.ts +0 -250
  241. package/src/service/subagent-workflow/deep-reflect-workflow-manager.ts +0 -1
  242. package/src/service/subagent-workflow/dynamic-timeout.ts +0 -30
  243. package/src/service/subagent-workflow/empathy-observer-workflow-manager.ts +0 -268
  244. package/src/service/subagent-workflow/nocturnal-workflow-manager.ts +0 -795
  245. package/src/service/subagent-workflow/runtime-direct-driver.ts +0 -268
  246. package/src/service/subagent-workflow/workflow-manager-base.ts +0 -580
  247. package/src/tools/write-pain-flag.ts +0 -215
  248. package/tests/commands/nocturnal-review.test.ts +0 -448
  249. package/tests/commands/nocturnal-train.test.ts +0 -97
  250. package/tests/commands/pd-reflect.test.ts +0 -49
  251. package/tests/core/adaptive-thresholds.test.ts +0 -261
  252. package/tests/core/nocturnal-arbiter.test.ts +0 -559
  253. package/tests/core/nocturnal-artifact-lineage.test.ts +0 -53
  254. package/tests/core/nocturnal-artificer.test.ts +0 -241
  255. package/tests/core/nocturnal-candidate-scoring.test.ts +0 -532
  256. package/tests/core/nocturnal-compliance-p-principles.test.ts +0 -133
  257. package/tests/core/nocturnal-compliance.test.ts +0 -646
  258. package/tests/core/nocturnal-dataset.test.ts +0 -892
  259. package/tests/core/nocturnal-e2e.test.ts +0 -234
  260. package/tests/core/nocturnal-executability.test.ts +0 -357
  261. package/tests/core/nocturnal-export.test.ts +0 -517
  262. package/tests/core/nocturnal-reasoning-deriver.test.ts +0 -372
  263. package/tests/core/nocturnal-reviewed-subset-comparison.test.ts +0 -428
  264. package/tests/core/nocturnal-rule-implementation-validator.test.ts +0 -127
  265. package/tests/core/nocturnal-snapshot-contract.test.ts +0 -121
  266. package/tests/core/nocturnal-trajectory-extractor.test.ts +0 -634
  267. package/tests/core/nocturnal-trinity.test.ts +0 -2053
  268. package/tests/core/pain-auto-repair.test.ts +0 -96
  269. package/tests/core/pain-integration.test.ts +0 -510
  270. package/tests/fixtures/nocturnal-reviewed-subset.json +0 -183
  271. package/tests/http/principles-console-route.test.ts +0 -162
  272. package/tests/integration/chaos-resilience.test.ts +0 -348
  273. package/tests/integration/empathy-workflow-integration.test.ts +0 -626
  274. package/tests/integration/pain-diagnostician-loop.e2e.test.ts +0 -380
  275. package/tests/service/control-ui-query-service.test.ts +0 -121
  276. package/tests/service/cooldown-strategy.test.ts +0 -164
  277. package/tests/service/data-endpoints-regression.test.ts +0 -834
  278. package/tests/service/empathy-observer-workflow-manager.test.ts +0 -175
  279. package/tests/service/evolution-worker.nocturnal.test.ts +0 -601
  280. package/tests/service/nocturnal-runtime-hardening.test.ts +0 -118
  281. package/tests/service/nocturnal-runtime.test.ts +0 -473
  282. package/tests/service/nocturnal-service-code-candidate.test.ts +0 -330
  283. package/tests/service/nocturnal-target-selector.test.ts +0 -615
  284. package/tests/service/startup-reconciler.test.ts +0 -148
  285. package/tests/tools/write-pain-flag.test.ts +0 -358
  286. package/ui/src/App.tsx +0 -45
  287. package/ui/src/api.ts +0 -220
  288. package/ui/src/charts.tsx +0 -955
  289. package/ui/src/components/ErrorState.tsx +0 -6
  290. package/ui/src/components/Loading.tsx +0 -13
  291. package/ui/src/components/ProtectedRoute.tsx +0 -12
  292. package/ui/src/components/Shell.tsx +0 -91
  293. package/ui/src/components/WorkspaceConfig.tsx +0 -178
  294. package/ui/src/components/index.ts +0 -5
  295. package/ui/src/context/auth.tsx +0 -80
  296. package/ui/src/context/theme.tsx +0 -66
  297. package/ui/src/hooks/useAutoRefresh.ts +0 -39
  298. package/ui/src/i18n/ui.ts +0 -473
  299. package/ui/src/main.tsx +0 -16
  300. package/ui/src/pages/EvolutionPage.tsx +0 -333
  301. package/ui/src/pages/FeedbackPage.tsx +0 -138
  302. package/ui/src/pages/GateMonitorPage.tsx +0 -136
  303. package/ui/src/pages/LoginPage.tsx +0 -89
  304. package/ui/src/pages/OverviewPage.tsx +0 -599
  305. package/ui/src/pages/SamplesPage.tsx +0 -174
  306. package/ui/src/pages/ThinkingModelsPage.tsx +0 -702
  307. package/ui/src/styles.css +0 -2020
  308. package/ui/src/types.ts +0 -384
  309. package/ui/src/utils/format.ts +0 -15
package/ui/src/charts.tsx DELETED
@@ -1,955 +0,0 @@
1
- import React from 'react';
2
-
3
- /**
4
- * StatusBadge - 统一颜色的状态徽章
5
- */
6
-
7
- type BadgeVariant = 'success' | 'warning' | 'error' | 'info' | 'neutral';
8
-
9
- interface StatusBadgeProps {
10
- variant: BadgeVariant;
11
- children: React.ReactNode;
12
- className?: string;
13
- }
14
-
15
- const BADGE_COLORS: Record<BadgeVariant, { bg: string; text: string }> = {
16
- success: { bg: 'rgba(74, 124, 111, 0.12)', text: 'var(--success)' },
17
- warning: { bg: 'rgba(184, 134, 11, 0.12)', text: 'var(--warning)' },
18
- error: { bg: 'rgba(196, 92, 74, 0.12)', text: 'var(--error)' },
19
- info: { bg: 'rgba(91, 139, 160, 0.12)', text: 'var(--info)' },
20
- neutral: { bg: 'var(--bg-sunken)', text: 'var(--text-secondary)' },
21
- };
22
-
23
- export function StatusBadge({ variant, children, className = '' }: StatusBadgeProps) {
24
- const { bg, text } = BADGE_COLORS[variant];
25
- return (
26
- <span
27
- className={`badge ${variant !== 'neutral' ? variant : ''} ${className}`}
28
- style={variant !== 'neutral' ? undefined : { background: bg, color: text }}
29
- >
30
- {children}
31
- </span>
32
- );
33
- }
34
-
35
- /**
36
- * EmptyState - 空状态插图组件
37
- */
38
-
39
- interface EmptyStateProps {
40
- title: string;
41
- description?: string;
42
- action?: React.ReactNode;
43
- }
44
-
45
- export function EmptyState({ title, description, action }: EmptyStateProps) {
46
- return (
47
- <div className="empty-state">
48
- <div className="empty-state-icon">
49
- <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
50
- <rect x="8" y="12" width="32" height="24" rx="3" stroke="currentColor" strokeWidth="1.5" strokeDasharray="3 2"/>
51
- <path d="M16 20h16M16 26h10" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/>
52
- <circle cx="38" cy="10" r="6" fill="var(--bg-sunken)" stroke="currentColor" strokeWidth="1.5"/>
53
- <path d="M36 10h4M38 8v4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/>
54
- </svg>
55
- </div>
56
- <p className="empty-state-title">{title}</p>
57
- {description && <p className="empty-state-desc">{description}</p>}
58
- {action && <div className="empty-state-action">{action}</div>}
59
- </div>
60
- );
61
- }
62
-
63
- /**
64
- * Sparkline - 轻量级迷你趋势图
65
- * 用于 KPI 卡片展示趋势
66
- */
67
-
68
- interface SparklineProps {
69
- data: number[];
70
- width?: number;
71
- height?: number;
72
- color?: string;
73
- fillOpacity?: number;
74
- showDots?: boolean;
75
- animated?: boolean;
76
- }
77
-
78
- export function Sparkline({
79
- data,
80
- width = 60,
81
- height = 24,
82
- color = 'var(--accent)',
83
- fillOpacity = 0.15,
84
- showDots = false,
85
- animated = true,
86
- }: SparklineProps) {
87
- if (!data || data.length < 2) {
88
- return <span className="sparkline-empty">-</span>;
89
- }
90
-
91
- const max = Math.max(...data);
92
- const min = Math.min(...data);
93
- const range = max - min;
94
- // If all values are the same, draw a flat line in the middle
95
- const isFlat = range === 0;
96
-
97
- const points = data.map((value, index) => {
98
- const x = (index / (data.length - 1)) * width;
99
- const y = isFlat ? height / 2 : height - ((value - min) / range) * height;
100
- return `${x},${y}`;
101
- });
102
-
103
- const linePoints = points.join(' ');
104
- const areaPoints = `0,${height} ${linePoints} ${width},${height}`;
105
-
106
- return (
107
- <svg
108
- className={`sparkline ${animated ? 'sparkline-animated' : ''}`}
109
- width={width}
110
- height={height}
111
- viewBox={`0 0 ${width} ${height}`}
112
- preserveAspectRatio="none"
113
- >
114
- {/* 填充区域 */}
115
- <polygon
116
- points={areaPoints}
117
- fill={color}
118
- fillOpacity={fillOpacity}
119
- className="sparkline-area"
120
- />
121
- {/* 线条 */}
122
- <polyline
123
- points={linePoints}
124
- fill="none"
125
- stroke={color}
126
- strokeWidth={1.5}
127
- strokeLinecap="round"
128
- strokeLinejoin="round"
129
- className="sparkline-line"
130
- />
131
- {/* 数据点 */}
132
- {showDots && data.map((value, index) => {
133
- const x = (index / (data.length - 1)) * width;
134
- const y = isFlat ? height / 2 : height - ((value - min) / range!) * height;
135
- return (
136
- <circle
137
- key={index}
138
- cx={x}
139
- cy={y}
140
- r={2}
141
- fill={color}
142
- className="sparkline-dot"
143
- />
144
- );
145
- })}
146
- </svg>
147
- );
148
- }
149
-
150
- /**
151
- * MiniBarChart - 迷你柱状图
152
- * 用于展示对比数据
153
- */
154
-
155
- interface MiniBarChartProps {
156
- data: number[];
157
- labels?: string[];
158
- width?: number;
159
- height?: number;
160
- color?: string;
161
- barWidth?: number;
162
- gap?: number;
163
- }
164
-
165
- export function MiniBarChart({
166
- data,
167
- labels,
168
- width = 100,
169
- height = 40,
170
- color = 'var(--accent)',
171
- barWidth = 6,
172
- gap = 4,
173
- }: MiniBarChartProps) {
174
- if (!data || data.length === 0) {
175
- return <span className="chart-empty">-</span>;
176
- }
177
-
178
- const max = Math.max(...data, 1);
179
- const totalWidth = data.length * (barWidth + gap) - gap;
180
- const startX = (width - totalWidth) / 2;
181
-
182
- return (
183
- <svg
184
- className="mini-bar-chart"
185
- width={width}
186
- height={height}
187
- viewBox={`0 0 ${width} ${height}`}
188
- >
189
- {data.map((value, index) => {
190
- const barHeight = (value / max) * (height - 4);
191
- const x = startX + index * (barWidth + gap);
192
- const y = height - barHeight - 2;
193
- return (
194
- <rect
195
- key={index}
196
- x={x}
197
- y={y}
198
- width={barWidth}
199
- height={barHeight}
200
- fill={color}
201
- rx={2}
202
- className="bar"
203
- >
204
- {labels && (
205
- <title>{labels[index]}: {value}</title>
206
- )}
207
- </rect>
208
- );
209
- })}
210
- </svg>
211
- );
212
- }
213
-
214
- /**
215
- * DonutChart - 环形图
216
- * 用于展示比例数据
217
- */
218
-
219
- interface DonutSegment {
220
- label: string;
221
- value: number;
222
- color: string;
223
- }
224
-
225
- interface DonutChartProps {
226
- segments: DonutSegment[];
227
- size?: number;
228
- strokeWidth?: number;
229
- showLabels?: boolean;
230
- }
231
-
232
- export function DonutChart({
233
- segments,
234
- size = 80,
235
- strokeWidth = 8,
236
- showLabels = true,
237
- }: DonutChartProps) {
238
- if (!segments || segments.length === 0) {
239
- return <span className="chart-empty">-</span>;
240
- }
241
-
242
- const total = Math.abs(segments.reduce((sum, s) => sum + s.value, 0));
243
-
244
- // Handle zero total case
245
- if (total === 0) {
246
- return <span className="chart-empty">No data</span>;
247
- }
248
-
249
- const radius = (size - strokeWidth) / 2;
250
- const center = size / 2;
251
-
252
- let currentAngle = -90; // 从顶部开始
253
-
254
- const paths = segments.map((segment, index) => {
255
- const percentage = Math.abs(segment.value) / Math.abs(total);
256
- const angle = percentage * 360;
257
- const startAngle = currentAngle;
258
- const endAngle = currentAngle + angle;
259
-
260
- // 转换为弧度
261
- const startRad = (startAngle * Math.PI) / 180;
262
- const endRad = (endAngle * Math.PI) / 180;
263
-
264
- // 计算弧线端点
265
- const x1 = center + radius * Math.cos(startRad);
266
- const y1 = center + radius * Math.sin(startRad);
267
- const x2 = center + radius * Math.cos(endRad);
268
- const y2 = center + radius * Math.sin(endRad);
269
-
270
- // 大弧标志
271
- const largeArc = angle > 180 ? 1 : 0;
272
-
273
- const path = `M ${x1} ${y1} A ${radius} ${radius} 0 ${largeArc} 1 ${x2} ${y2}`;
274
-
275
- currentAngle = endAngle;
276
-
277
- return {
278
- ...segment,
279
- path,
280
- percentage,
281
- key: index,
282
- };
283
- });
284
-
285
- return (
286
- <div className="donut-chart-wrapper">
287
- <svg
288
- className="donut-chart"
289
- width={size}
290
- height={size}
291
- viewBox={`0 0 ${size} ${size}`}
292
- >
293
- {/* 背景圆环 */}
294
- <circle
295
- cx={center}
296
- cy={center}
297
- r={radius}
298
- fill="none"
299
- stroke="var(--border)"
300
- strokeWidth={strokeWidth}
301
- />
302
- {/* 数据弧线 */}
303
- {paths.map((segment) => (
304
- <path
305
- key={segment.key}
306
- d={segment.path}
307
- fill="none"
308
- stroke={segment.color}
309
- strokeWidth={strokeWidth}
310
- strokeLinecap="round"
311
- className="donut-segment"
312
- >
313
- <title>{segment.label}: {segment.value} ({(segment.percentage * 100).toFixed(1)}%)</title>
314
- </path>
315
- ))}
316
- {/* 中心数值 */}
317
- <text
318
- x={center}
319
- y={center - 4}
320
- textAnchor="middle"
321
- className="donut-total"
322
- >
323
- {total}
324
- </text>
325
- <text
326
- x={center}
327
- y={center + 12}
328
- textAnchor="middle"
329
- className="donut-label"
330
- >
331
- total
332
- </text>
333
- </svg>
334
- {showLabels && (
335
- <div className="donut-legend">
336
- {paths.map((segment) => (
337
- <div key={segment.key} className="legend-item">
338
- <span
339
- className="legend-color"
340
- style={{ background: segment.color }}
341
- />
342
- <span className="legend-label">{segment.label}</span>
343
- <span className="legend-value">{segment.value}</span>
344
- </div>
345
- ))}
346
- </div>
347
- )}
348
- </div>
349
- );
350
- }
351
-
352
- /**
353
- * TrendIndicator - 趋势指示器
354
- * 展示数值变化方向
355
- */
356
-
357
- interface TrendIndicatorProps {
358
- value: number;
359
- previousValue: number;
360
- showPercent?: boolean;
361
- }
362
-
363
- export function TrendIndicator({
364
- value,
365
- previousValue,
366
- showPercent = true,
367
- }: TrendIndicatorProps) {
368
- if (previousValue === 0) {
369
- return <span className="trend-neutral">-</span>;
370
- }
371
-
372
- const change = value - previousValue;
373
- const percentChange = (change / previousValue) * 100;
374
-
375
- const isPositive = change > 0;
376
- const isNegative = change < 0;
377
-
378
- const direction = isPositive ? '↑' : isNegative ? '↓' : '→';
379
- const percentText = showPercent ? `${Math.abs(percentChange).toFixed(1)}%` : '';
380
-
381
- return (
382
- <span
383
- className={`trend-indicator ${
384
- isPositive ? 'trend-up' : isNegative ? 'trend-down' : 'trend-neutral'
385
- }`}
386
- aria-label={`${isPositive ? 'Increase' : isNegative ? 'Decrease' : 'No change'} of ${percentText}`}
387
- >
388
- <span className="trend-direction">{direction}</span>
389
- {percentText && <span className="trend-percent">{percentText}</span>}
390
- </span>
391
- );
392
- }
393
-
394
- /**
395
- * StatCard - 统计卡片(带趋势图)
396
- */
397
-
398
- interface StatCardProps {
399
- label: string;
400
- value: string | number;
401
- trend?: number[];
402
- trendLabel?: string;
403
- status?: 'success' | 'warning' | 'error' | 'info';
404
- }
405
-
406
- export function StatCard({
407
- label,
408
- value,
409
- trend,
410
- trendLabel,
411
- status = 'info',
412
- }: StatCardProps) {
413
- const statusColors: Record<string, string> = {
414
- success: 'var(--success)',
415
- warning: 'var(--warning)',
416
- error: 'var(--error)',
417
- info: 'var(--accent)',
418
- };
419
-
420
- return (
421
- <div className={`stat-card stat-card--${status}`}>
422
- <div className="stat-content">
423
- <span className="stat-label">{label}</span>
424
- <span className="stat-value">{value}</span>
425
- {trendLabel && <span className="stat-trend-label">{trendLabel}</span>}
426
- </div>
427
- {trend && trend.length >= 2 && (
428
- <div className="stat-sparkline">
429
- <Sparkline
430
- data={trend}
431
- width={50}
432
- height={20}
433
- color={statusColors[status]}
434
- />
435
- </div>
436
- )}
437
- </div>
438
- );
439
- }
440
-
441
- /**
442
- * TimeRangeSelector - 时间范围选择器
443
- * 用于控制图表数据的时间范围
444
- */
445
-
446
- interface TimeRangeSelectorProps {
447
- value: number;
448
- onChange: (days: number) => void;
449
- options?: number[];
450
- }
451
-
452
- export function TimeRangeSelector({
453
- value,
454
- onChange,
455
- options = [7, 14, 30],
456
- }: TimeRangeSelectorProps) {
457
- return (
458
- <div className="time-range-selector">
459
- {options.map((days) => (
460
- <button
461
- key={days}
462
- className={`time-range-option ${value === days ? 'active' : ''}`}
463
- onClick={() => onChange(days)}
464
- >
465
- {days}天
466
- </button>
467
- ))}
468
- </div>
469
- );
470
- }
471
-
472
- /**
473
- * GroupedBarChart - 分组柱状图
474
- * 用于展示多组对比数据(如 created vs completed)
475
- */
476
-
477
- interface GroupedBarChartProps {
478
- data: Array<{
479
- label: string;
480
- values: number[];
481
- }>;
482
- colors?: string[];
483
- width?: number;
484
- height?: number;
485
- barWidth?: number;
486
- groupGap?: number;
487
- }
488
-
489
- export function GroupedBarChart({
490
- data,
491
- colors = ['var(--accent)', 'var(--earth-tan)'],
492
- width = 280,
493
- height = 60,
494
- barWidth = 4,
495
- groupGap = 8,
496
- }: GroupedBarChartProps) {
497
- if (!data || data.length === 0) {
498
- return <span className="chart-empty">-</span>;
499
- }
500
-
501
- // 找出最大值
502
- const maxValue = Math.max(...data.flatMap((d) => d.values), 1);
503
- const numBars = data[0]?.values.length || 1;
504
- const groupWidth = numBars * barWidth + (numBars - 1) * 2;
505
- const totalWidth = data.length * groupWidth + (data.length - 1) * groupGap;
506
- const startX = (width - totalWidth) / 2;
507
-
508
- return (
509
- <svg
510
- className="grouped-bar-chart"
511
- width="100%"
512
- height={height}
513
- viewBox={`0 0 ${width} ${height}`}
514
- preserveAspectRatio="xMidYMid meet"
515
- >
516
- {data.map((group, groupIndex) => {
517
- const groupX = startX + groupIndex * (groupWidth + groupGap);
518
- return group.values.map((value, barIndex) => {
519
- const barHeight = (value / maxValue) * (height - 8);
520
- const x = groupX + (barIndex + 1) * (barWidth + 2);
521
- const y = height - barHeight - 4;
522
- return (
523
- <rect
524
- key={`${groupIndex}-${barIndex}`}
525
- x={x}
526
- y={y}
527
- width={barWidth}
528
- height={barHeight}
529
- fill={colors[barIndex] || colors[0]}
530
- rx={2}
531
- className="bar"
532
- >
533
- <title>{group.label}: {value}</title>
534
- </rect>
535
- );
536
- });
537
- })}
538
- </svg>
539
- );
540
- }
541
-
542
- /**
543
- * CollapsiblePanel - 可折叠面板
544
- */
545
-
546
- import { ChevronDown, ChevronUp } from 'lucide-react';
547
-
548
- interface CollapsiblePanelProps {
549
- title: string;
550
- badge?: React.ReactNode;
551
- defaultCollapsed?: boolean;
552
- children: React.ReactNode;
553
- className?: string;
554
- }
555
-
556
- export function CollapsiblePanel({
557
- title,
558
- badge,
559
- defaultCollapsed = false,
560
- children,
561
- className = '',
562
- }: CollapsiblePanelProps) {
563
- const [collapsed, setCollapsed] = React.useState(defaultCollapsed);
564
-
565
- return (
566
- <section className={`panel collapsible-panel ${collapsed ? 'collapsed' : ''} ${className}`}>
567
- <div
568
- className="panel-header"
569
- onClick={() => setCollapsed(!collapsed)}
570
- >
571
- <div className="panel-header-left">
572
- <h3>{title}</h3>
573
- {badge}
574
- </div>
575
- <button className="collapse-toggle" onClick={(e) => { e.stopPropagation(); }}>
576
- {collapsed ? (
577
- <ChevronDown strokeWidth={1.75} size={18} />
578
- ) : (
579
- <ChevronUp strokeWidth={1.75} size={18} />
580
- )}
581
- </button>
582
- </div>
583
- {!collapsed && <div className="panel-content">{children}</div>}
584
- </section>
585
- );
586
- }
587
-
588
- /**
589
- * BulletChart - 子弹图(Performance vs Target)
590
- * 用于展示 GFI vs 阈值,带安全/警告/危险分区
591
- */
592
-
593
- interface BulletChartProps {
594
- value: number;
595
- target: number;
596
- peak?: number;
597
- max?: number;
598
- width?: number;
599
- height?: number;
600
- unit?: string;
601
- }
602
-
603
- export function BulletChart({
604
- value,
605
- target,
606
- peak,
607
- max = 150,
608
- width = 200,
609
- height = 28,
610
- unit = '',
611
- }: BulletChartProps) {
612
- const pct = Math.min(value / max, 1);
613
- const targetPct = Math.min(target / max, 1);
614
- const peakPct = peak ? Math.min(peak / max, 1) : 0;
615
-
616
- // Zones
617
- const safeEnd = 0.47; // 70/150
618
- const warnEnd = 0.73; // 110/150
619
-
620
- const barH = height * 0.5;
621
- const barY = (height - barH) / 2;
622
-
623
- return (
624
- <div className="bullet-chart">
625
- <svg width={width} height={height} viewBox={`0 0 ${width} ${height}`}>
626
- {/* Background zones */}
627
- <rect x={0} y={barY} width={width * safeEnd} height={barH} fill="var(--success)" opacity={0.15} rx={3} />
628
- <rect x={width * safeEnd} y={barY} width={width * (warnEnd - safeEnd)} height={barH} fill="var(--warning)" opacity={0.15} />
629
- <rect x={width * warnEnd} y={barY} width={width * (1 - warnEnd)} height={barH} fill="var(--error)" opacity={0.15} rx={3} />
630
-
631
- {/* Value bar */}
632
- <rect
633
- x={0} y={barY}
634
- width={Math.max(width * pct, 2)}
635
- height={barH}
636
- fill={value >= target ? 'var(--error)' : value >= target * 0.7 ? 'var(--warning)' : 'var(--success)'}
637
- rx={3}
638
- >
639
- <title>{`GFI: ${value}${unit} | 阈值: ${target}${unit}`}{peak ? ` | 今日峰值: ${peak}${unit}` : ''}</title>
640
- </rect>
641
-
642
- {/* Target marker */}
643
- <line
644
- x1={width * targetPct} y1={barY - 2}
645
- x2={width * targetPct} y2={barY + barH + 2}
646
- stroke="var(--text-primary)" strokeWidth={2} opacity={0.7}
647
- />
648
-
649
- {/* Peak marker */}
650
- {peakPct > pct && (
651
- <circle cx={width * peakPct} cy={height / 2} r={3} fill="var(--warning)" opacity={0.8} />
652
- )}
653
- </svg>
654
- <div className="bullet-labels" style={{ display: 'flex', justifyContent: 'space-between', marginTop: 2, fontSize: '0.7rem', color: 'var(--text-secondary)' }}>
655
- <span>0</span>
656
- <span style={{ position: 'relative', left: `-${width * targetPct * 0.3}px` }}>阈值 {target}</span>
657
- <span>{max}</span>
658
- </div>
659
- </div>
660
- );
661
- }
662
-
663
- /**
664
- * GaugeChart - 半圆仪表盘
665
- * 用于展示 Trust Score (0-100)
666
- */
667
-
668
- interface GaugeChartProps {
669
- value: number;
670
- max?: number;
671
- label: string;
672
- sublabel?: string;
673
- size?: number;
674
- segments?: Array<{ label: string; color: string; max: number }>;
675
- }
676
-
677
- export function GaugeChart({
678
- value,
679
- max = 100,
680
- label,
681
- sublabel,
682
- size = 100,
683
- segments = [
684
- { label: 'Observer', color: 'var(--text-secondary)', max: 30 },
685
- { label: 'Editor', color: 'var(--info)', max: 60 },
686
- { label: 'Developer', color: 'var(--accent)', max: 80 },
687
- { label: 'Architect', color: 'var(--success)', max: 100 },
688
- ],
689
- }: GaugeChartProps) {
690
- const pct = Math.min(value / max, 1);
691
- const radius = (size - 16) / 2;
692
- const center = size / 2;
693
- const circumference = Math.PI * radius;
694
- const arcLength = circumference * pct;
695
-
696
- // Find current segment
697
- const currentSeg = segments.find(s => value <= s.max) ?? segments[segments.length - 1];
698
-
699
- return (
700
- <div className="gauge-chart" style={{ textAlign: 'center' }}>
701
- <svg width={size} height={size / 2 + 20} viewBox={`0 0 ${size} ${size / 2 + 20}`}>
702
- {/* Background arc */}
703
- <path
704
- d={`M ${center - radius} ${center} A ${radius} ${radius} 0 0 1 ${center + radius} ${center}`}
705
- fill="none"
706
- stroke="var(--bg-sunken)"
707
- strokeWidth={8}
708
- strokeLinecap="round"
709
- />
710
- {/* Value arc */}
711
- <path
712
- d={`M ${center - radius} ${center} A ${radius} ${radius} 0 0 1 ${center + radius} ${center}`}
713
- fill="none"
714
- stroke={currentSeg.color}
715
- strokeWidth={8}
716
- strokeLinecap="round"
717
- strokeDasharray={`${arcLength} ${circumference}`}
718
- style={{ transition: 'stroke-dasharray 0.5s ease' }}
719
- />
720
- {/* Value text */}
721
- <text
722
- x={center} y={center - 4}
723
- textAnchor="middle"
724
- fontSize="18"
725
- fontWeight="600"
726
- fill="var(--text-primary)"
727
- >
728
- {value}
729
- </text>
730
- </svg>
731
- <div style={{ fontSize: '0.75rem', color: currentSeg.color, fontWeight: 500 }}>{label}</div>
732
- {sublabel && <div style={{ fontSize: '0.65rem', color: 'var(--text-secondary)' }}>{sublabel}</div>}
733
- </div>
734
- );
735
- }
736
-
737
- /**
738
- * PrincipleStack - 原则状态堆叠
739
- * 展示原则分布
740
- */
741
-
742
- interface PrincipleStackProps {
743
- candidate: number;
744
- probation: number;
745
- active: number;
746
- deprecated: number;
747
- }
748
-
749
- export function PrincipleStack({ candidate, probation, active, deprecated }: PrincipleStackProps) {
750
- const total = candidate + probation + active + deprecated;
751
- const segs = [
752
- { label: 'Active', value: active, color: 'var(--success)' },
753
- { label: 'Probation', value: probation, color: 'var(--warning)' },
754
- { label: 'Candidate', value: candidate, color: 'var(--info)' },
755
- { label: 'Deprecated', value: deprecated, color: 'var(--text-secondary)' },
756
- ].filter(s => s.value > 0);
757
-
758
- if (total === 0) {
759
- return (
760
- <div className="principle-stack" style={{ textAlign: 'center', padding: 'var(--space-3)', color: 'var(--text-secondary)', fontSize: '0.85rem' }}>
761
- No principles yet
762
- </div>
763
- );
764
- }
765
-
766
- return (
767
- <div className="principle-stack">
768
- {/* Stacked bar */}
769
- <div style={{ display: 'flex', height: 8, borderRadius: 4, overflow: 'hidden', marginBottom: 8 }}>
770
- {segs.map(seg => (
771
- <div
772
- key={seg.label}
773
- style={{
774
- width: `${(seg.value / total) * 100}%`,
775
- backgroundColor: seg.color,
776
- transition: 'width 0.3s ease',
777
- }}
778
- title={`${seg.label}: ${seg.value}`}
779
- />
780
- ))}
781
- </div>
782
- {/* Legend */}
783
- <div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, fontSize: '0.7rem' }}>
784
- {segs.map(seg => (
785
- <span key={seg.label} style={{ display: 'flex', alignItems: 'center', gap: 3 }}>
786
- <span style={{ width: 6, height: 6, borderRadius: '50%', backgroundColor: seg.color, display: 'inline-block' }} />
787
- <span style={{ color: 'var(--text-secondary)' }}>{seg.label}</span>
788
- <span style={{ fontWeight: 600, color: 'var(--text-primary)' }}>{seg.value}</span>
789
- </span>
790
- ))}
791
- </div>
792
- </div>
793
- );
794
- }
795
-
796
- /**
797
- * QueueBar - 队列状态条
798
- * 展示 pending/in-progress/completed
799
- */
800
-
801
- interface QueueBarProps {
802
- pending: number;
803
- inProgress: number;
804
- completed: number;
805
- }
806
-
807
- export function QueueBar({ pending, inProgress, completed }: QueueBarProps) {
808
- const total = pending + inProgress + completed;
809
- const items = [
810
- { label: 'Pending', value: pending, color: 'var(--warning)' },
811
- { label: 'In Progress', value: inProgress, color: 'var(--info)' },
812
- { label: 'Completed', value: completed, color: 'var(--success)' },
813
- ];
814
-
815
- if (total === 0) {
816
- return (
817
- <div className="queue-bar" style={{ textAlign: 'center', padding: 'var(--space-3)', color: 'var(--text-secondary)', fontSize: '0.85rem' }}>
818
- Queue empty
819
- </div>
820
- );
821
- }
822
-
823
- return (
824
- <div className="queue-bar">
825
- <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
826
- {items.map(item => (
827
- <div key={item.label} style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
828
- <div style={{ width: 6, height: 6, borderRadius: '50%', backgroundColor: item.color, flexShrink: 0 }} />
829
- <span style={{ fontSize: '0.7rem', color: 'var(--text-secondary)', minWidth: 55 }}>{item.label}</span>
830
- <div style={{ flex: 1, height: 6, backgroundColor: 'var(--bg-sunken)', borderRadius: 3, overflow: 'hidden' }}>
831
- <div
832
- style={{
833
- width: `${(item.value / total) * 100}%`,
834
- height: '100%',
835
- backgroundColor: item.color,
836
- borderRadius: 3,
837
- minWidth: item.value > 0 ? 4 : 0,
838
- transition: 'width 0.3s ease',
839
- }}
840
- />
841
- </div>
842
- <span style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-primary)', minWidth: 20, textAlign: 'right' }}>{item.value}</span>
843
- </div>
844
- ))}
845
- </div>
846
- </div>
847
- );
848
- }
849
-
850
- /**
851
- * LineChart - 全尺寸折线图
852
- * 用于展示 GFI 等时间序列数据的完整趋势
853
- */
854
-
855
- interface LineChartProps {
856
- data: Array<{ label: string; value: number }>;
857
- width?: number;
858
- height?: number;
859
- color?: string;
860
- showGrid?: boolean;
861
- showDots?: boolean;
862
- showArea?: boolean;
863
- unit?: string;
864
- emptyText?: string;
865
- }
866
-
867
- export function LineChart({
868
- data,
869
- width = 560,
870
- height = 180,
871
- color = 'var(--accent)',
872
- showGrid = true,
873
- showDots = true,
874
- showArea = true,
875
- unit = '',
876
- emptyText = '',
877
- }: LineChartProps) {
878
- if (!data || data.length === 0) {
879
- if (!emptyText) return null;
880
- return (
881
- <div style={{ height, display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--text-secondary)', fontSize: '0.85rem' }}>
882
- {emptyText}
883
- </div>
884
- );
885
- }
886
-
887
- const padding = { top: 16, right: 16, bottom: 28, left: 44 };
888
- const chartW = width - padding.left - padding.right;
889
- const chartH = height - padding.top - padding.bottom;
890
-
891
- const values = data.map(d => d.value);
892
- const maxVal = Math.max(...values, 1);
893
- const minVal = Math.min(...values, 0);
894
- const range = maxVal - minVal || 1;
895
-
896
- // Y-axis ticks (5 ticks)
897
- const yTicks = Array.from({ length: 5 }, (_, i) => minVal + (range * i) / 4);
898
-
899
- const xStep = data.length > 1 ? chartW / (data.length - 1) : 0;
900
-
901
- const points = data.map((d, i) => ({
902
- x: padding.left + (data.length > 1 ? i * xStep : chartW / 2),
903
- y: padding.top + chartH - ((d.value - minVal) / range) * chartH,
904
- label: d.label,
905
- value: d.value,
906
- }));
907
-
908
- const linePath = points.map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x} ${p.y}`).join(' ');
909
- const areaPath = linePath + ` L ${points[points.length - 1].x} ${padding.top + chartH} L ${points[0].x} ${padding.top + chartH} Z`;
910
-
911
- return (
912
- <svg width={width} height={height} viewBox={`0 0 ${width} ${height}`} style={{ display: 'block' }}>
913
- {/* Grid lines */}
914
- {showGrid && yTicks.map((tick, i) => {
915
- const y = padding.top + chartH - ((tick - minVal) / range) * chartH;
916
- return (
917
- <g key={i}>
918
- <line x1={padding.left} y1={y} x2={padding.left + chartW} y2={y} stroke="var(--border)" strokeWidth={0.5} strokeDasharray="3 3" />
919
- <text x={padding.left - 6} y={y + 4} textAnchor="end" fontSize="10" fill="var(--text-secondary)">
920
- {Math.round(tick)}
921
- </text>
922
- </g>
923
- );
924
- })}
925
-
926
- {/* Area fill */}
927
- {showArea && points.length > 1 && (
928
- <path d={areaPath} fill={color} fillOpacity={0.08} />
929
- )}
930
-
931
- {/* Line */}
932
- <path d={linePath} fill="none" stroke={color} strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" />
933
-
934
- {/* Dots */}
935
- {showDots && points.map((p, i) => (
936
- <g key={i}>
937
- <circle cx={p.x} cy={p.y} r={3} fill={color} stroke="var(--bg-raised)" strokeWidth={1.5} />
938
- <title>{p.label}: {p.value}{unit}</title>
939
- </g>
940
- ))}
941
-
942
- {/* X-axis labels */}
943
- {points.map((p, i) => {
944
- // Skip some labels if too many
945
- const skipCount = data.length > 12 ? 2 : data.length > 8 ? 1 : 0;
946
- if (i % (skipCount + 1) !== 0 && i !== points.length - 1) return null;
947
- return (
948
- <text key={i} x={p.x} y={height - 4} textAnchor="middle" fontSize="9" fill="var(--text-secondary)">
949
- {p.label}
950
- </text>
951
- );
952
- })}
953
- </svg>
954
- );
955
- }