soma-kit 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +8 -5
- package/packs/ai/model-card.ts +3 -3
- package/packs/finance/reconcile-desk/compile.ts +1 -1
- package/packs/finance/reconcile-desk/shell.ts +1 -1
- package/packs/ops/error-budget-card.ts +3 -3
- package/packs/ops/release-readiness-card.ts +3 -3
- package/packs/security/control-evidence-card.ts +3 -3
- package/packs/security/finding-card.ts +3 -2
- package/packs/shared/card-util.ts +17 -0
- package/spec/generated/kit-app.schema.json +2148 -338
- package/spec/generated/kit-page.schema.json +1152 -87
- package/spec/kit-grammar.json +1084 -136
- package/spec/kit-grammar.schema.json +167 -26
- package/src/app/app-config.ts +220 -187
- package/src/app/component-gate.ts +2 -2
- package/src/app/compose-apps.ts +5 -2
- package/src/app/define-kit-actions.ts +200 -22
- package/src/app/define-kit-app.ts +54 -8
- package/src/app/define-kit-view.ts +1 -1
- package/src/app/index.ts +12 -7
- package/src/app/kit-view-context.ts +50 -3
- package/src/app/list-page-defaults.ts +14 -0
- package/src/app/server-pages.ts +239 -7
- package/src/app/server.ts +466 -25
- package/src/app/theme-endpoint.ts +68 -24
- package/src/app/theme-runtime.ts +421 -87
- package/src/app/theme-shards.ts +69 -0
- package/src/app/tier-compat.ts +107 -0
- package/src/base/action-busy.ts +215 -38
- package/src/base/affix.ts +137 -0
- package/src/base/alert.ts +107 -59
- package/src/base/anchored-layer.ts +8 -7
- package/src/base/avatar.ts +147 -61
- package/src/base/badge.ts +186 -0
- package/src/base/button-group.ts +227 -0
- package/src/base/button.ts +365 -53
- package/src/base/card.ts +233 -0
- package/src/base/cascader.ts +147 -32
- package/src/base/check-core.ts +196 -33
- package/src/base/checkbox.ts +67 -2
- package/src/base/choice.ts +132 -31
- package/src/base/collapse.ts +249 -0
- package/src/base/color-picker.ts +404 -28
- package/src/base/combobox.ts +6 -2
- package/src/base/command-palette.ts +155 -37
- package/src/base/context-menu.ts +26 -6
- package/src/base/countdown.ts +37 -15
- package/src/base/date-range.ts +115 -94
- package/src/base/date.ts +487 -76
- package/src/base/delta.ts +20 -11
- package/src/base/divider.ts +64 -97
- package/src/base/end-edge.ts +10 -4
- package/src/base/fab.ts +64 -23
- package/src/base/gap-value.ts +35 -16
- package/src/base/hint-tips.ts +100 -30
- package/src/base/identity-cells.ts +839 -0
- package/src/base/illustrations.ts +6 -4
- package/src/base/image.ts +40 -19
- package/src/base/index.ts +92 -24
- package/src/base/inline-error.ts +90 -0
- package/src/base/input.ts +174 -38
- package/src/base/kbd.ts +31 -17
- package/src/base/kit-contract.ts +400 -0
- package/src/base/link.ts +41 -20
- package/src/base/listbox-core.ts +324 -95
- package/src/base/loading-gate.ts +3 -0
- package/src/base/look.ts +197 -0
- package/src/base/mentions.ts +58 -22
- package/src/base/menu-button.ts +129 -42
- package/src/base/menu-core.ts +210 -26
- package/src/base/month-grid.ts +60 -3
- package/src/base/motion/aura.ts +52 -10
- package/src/base/motion/hover-3d.ts +10 -5
- package/src/base/motion/hover-gallery.ts +19 -12
- package/src/base/motion/limits.ts +10 -0
- package/src/base/motion/marquee.ts +18 -11
- package/src/base/motion/text-rotate.ts +34 -16
- package/src/base/notification.ts +292 -0
- package/src/base/number.ts +93 -12
- package/src/base/otp.ts +143 -27
- package/src/base/overlay-runtime.ts +32 -24
- package/src/base/overlay-shell.ts +186 -0
- package/src/base/period-picker.ts +868 -0
- package/src/base/popover.ts +625 -74
- package/src/base/popup.ts +219 -78
- package/src/base/portal-core.ts +99 -2
- package/src/base/price-text.ts +51 -17
- package/src/base/progress.ts +100 -18
- package/src/base/qr-code.ts +64 -17
- package/src/base/qty-stepper.ts +145 -21
- package/src/base/radio.ts +43 -2
- package/src/base/range.ts +194 -39
- package/src/base/rating.ts +117 -31
- package/src/base/reason-tip.ts +60 -18
- package/src/base/relation-cells.ts +541 -0
- package/src/{frames → base}/resize-handle.ts +6 -4
- package/src/base/row-fresh.ts +84 -0
- package/src/base/section-spy.ts +79 -0
- package/src/base/segmented.ts +99 -56
- package/src/base/select.ts +8 -2
- package/src/base/shared.ts +520 -73
- package/src/base/spinner.ts +107 -0
- package/src/base/state-panel.ts +77 -22
- package/src/base/status-tone.ts +1 -1
- package/src/base/sticky-edge.ts +96 -29
- package/src/base/swap.ts +39 -21
- package/src/base/switch.ts +158 -38
- package/src/base/tabs.ts +292 -0
- package/src/base/tag-input.ts +129 -55
- package/src/base/tag.ts +203 -91
- package/src/base/text.ts +491 -77
- package/src/base/textarea.ts +89 -40
- package/src/base/time-picker.ts +341 -57
- package/src/base/time-range.ts +846 -0
- package/src/base/tree-select.ts +346 -89
- package/src/base/upload.ts +612 -158
- package/src/base/view-transition.ts +7 -3
- package/src/base/virtual-list.ts +49 -14
- package/src/biz/approval-desk/compile.ts +98 -6
- package/src/biz/approval-desk/index.ts +2 -0
- package/src/biz/approval-desk/shell.ts +53 -13
- package/src/biz/auth-panel/compile.ts +14 -4
- package/src/biz/auth-panel/shell.ts +28 -8
- package/src/biz/category-crud/compile.ts +64 -13
- package/src/biz/category-crud/index.ts +2 -0
- package/src/biz/category-crud/shell.ts +30 -8
- package/src/biz/checkout-page/compile.ts +38 -4
- package/src/biz/checkout-page/index.ts +1 -0
- package/src/biz/checkout-page/shell.ts +28 -10
- package/src/biz/compose.ts +9 -4
- package/src/biz/data-components.ts +2 -0
- package/src/biz/define.ts +1 -1
- package/src/biz/import-wizard/compile.ts +5 -2
- package/src/biz/import-wizard/index.ts +1 -0
- package/src/biz/import-wizard/shell.ts +36 -20
- package/src/biz/index.ts +5 -4
- package/src/biz/landing-page/compile.ts +4 -3
- package/src/biz/landing-page/shell.ts +25 -5
- package/src/biz/layout-contracts.ts +918 -0
- package/src/biz/link/hub.ts +199 -8
- package/src/biz/link/shared.ts +62 -16
- package/src/biz/master-sub/compile.ts +318 -38
- package/src/biz/master-sub/detail-head.ts +145 -21
- package/src/biz/master-sub/index.ts +6 -3
- package/src/biz/master-sub/shell.ts +232 -66
- package/src/biz/multi-board/compile.ts +89 -38
- package/src/biz/multi-board/composition.ts +7 -20
- package/src/biz/multi-board/index.ts +25 -9
- package/src/biz/multi-board/prose-fold.ts +17 -13
- package/src/biz/multi-board/shell.ts +153 -38
- package/src/biz/names.ts +1 -0
- package/src/biz/notification-center/compile.ts +28 -7
- package/src/biz/notification-center/index.ts +2 -0
- package/src/biz/notification-center/shell.ts +51 -11
- package/src/biz/page-templates/domain-templates.ts +147 -20
- package/src/biz/page-templates/result-page/compile.ts +5 -2
- package/src/biz/page-templates/result-page/index.ts +1 -0
- package/src/biz/page-templates/result-page/shell.ts +20 -6
- package/src/biz/page-templates/shared.ts +1 -1
- package/src/biz/page-templates/sign-in-page/compile.ts +20 -9
- package/src/biz/page-templates/sign-in-page/index.ts +1 -0
- package/src/biz/page-templates/sign-in-page/shell.ts +30 -14
- package/src/biz/record-detail/compile.ts +43 -12
- package/src/biz/record-detail/index.ts +1 -0
- package/src/biz/record-detail/shell.ts +42 -11
- package/src/biz/settings-center/compile.ts +5 -2
- package/src/biz/settings-center/index.ts +1 -0
- package/src/biz/settings-center/shell.ts +33 -9
- package/src/biz/shared/action-host.ts +146 -48
- package/src/biz/shared/compile-helpers.ts +134 -32
- package/src/biz/shared/coordinator.ts +727 -163
- package/src/biz/shared/focus-return.ts +180 -0
- package/src/biz/shared/object-aliases.ts +7 -1
- package/src/biz/shared/overlay-compile.ts +102 -24
- package/src/biz/shared/overlay-shell.ts +97 -116
- package/src/biz/shared/page-form-actions.ts +151 -0
- package/src/biz/shared/page-form.ts +255 -0
- package/src/biz/shared/pipeline.ts +74 -0
- package/src/biz/shared/runtime-hub.ts +101 -8
- package/src/biz/shared/verbs.ts +129 -0
- package/src/biz/single-form/compile.ts +6 -4
- package/src/biz/single-form/index.ts +2 -0
- package/src/biz/single-form/shell.ts +22 -8
- package/src/biz/standard-crud/compile.ts +213 -38
- package/src/biz/standard-crud/index.ts +2 -1
- package/src/biz/standard-crud/shell.ts +90 -13
- package/src/biz/standard-crud/summary.ts +2 -35
- package/src/biz/step-form/compile.ts +13 -4
- package/src/biz/step-form/hub.ts +168 -49
- package/src/biz/step-form/index.ts +1 -0
- package/src/biz/step-form/shell.ts +35 -17
- package/src/biz/types.ts +49 -6
- package/src/cli/app-layer-check.ts +375 -0
- package/src/cli/kit-cli.ts +179 -33
- package/src/cli/kit-init.ts +152 -3
- package/src/cli/migrate/theme-map.ts +35 -28
- package/src/cli/migrate/ts-rules.ts +2 -2
- package/src/cli/migrate/types.ts +3 -3
- package/src/cli/migrate/yaml-rules.ts +11 -9
- package/src/cli/view-writes.ts +13 -0
- package/src/compile/access-gate-attach.ts +1 -1
- package/src/compile/action-host-attach.ts +1 -1
- package/src/compile/closed-set.ts +102 -6
- package/src/compile/compile-page.ts +461 -273
- package/src/compile/component-candidates.ts +58 -5
- package/src/compile/danger-tier.ts +65 -0
- package/src/compile/hints.ts +6 -59
- package/src/compile/index.ts +2 -2
- package/src/compile/info-structure.ts +155 -0
- package/src/compile/layout-lint/index.ts +4 -1
- package/src/compile/layout-lint/rules-composition.ts +44 -13
- package/src/compile/layout-lint/rules-table.ts +4 -19
- package/src/compile/look-page.ts +551 -0
- package/src/compile/look.ts +376 -0
- package/src/compile/page-composition.ts +405 -67
- package/src/compile/page-hierarchy.ts +131 -0
- package/src/compile/page-pipeline-look.ts +156 -0
- package/src/compile/page-pipeline.ts +200 -0
- package/src/compile/parse.ts +12 -11
- package/src/compile/redirect.ts +1 -1
- package/src/compile/relation-render.ts +120 -0
- package/src/compile/remove-guard.ts +115 -41
- package/src/compile/stages.ts +786 -0
- package/src/compile/styles.ts +286 -48
- package/src/compile/types.ts +63 -6
- package/src/compile/view-check.ts +190 -1
- package/src/data/access-gate.ts +17 -9
- package/src/data/amount-breakdown.ts +52 -23
- package/src/data/anchor-nav.ts +77 -16
- package/src/data/approval-flow.ts +217 -126
- package/src/data/assignment-picker.ts +182 -94
- package/src/data/async-result-panel.ts +114 -46
- package/src/data/audit-log.ts +461 -0
- package/src/data/breadcrumbs.ts +150 -24
- package/src/data/calendar.ts +436 -97
- package/src/data/card-grid.ts +319 -0
- package/src/data/carousel.ts +81 -41
- package/src/data/cell-value.ts +253 -0
- package/src/data/chart.ts +1053 -96
- package/src/data/checklist.ts +82 -38
- package/src/data/code-view.ts +296 -44
- package/src/data/comment-thread.ts +611 -86
- package/src/data/compare-view.ts +227 -0
- package/src/data/confirm-dialog.ts +250 -39
- package/src/data/context-menu.ts +95 -21
- package/src/data/d9-limits.ts +2 -0
- package/src/data/d9-util.ts +13 -5
- package/src/data/diff.ts +109 -49
- package/src/data/display-util.ts +9 -4
- package/src/data/dock.ts +38 -18
- package/src/data/embed.ts +143 -8
- package/src/data/engine-ports.ts +135 -0
- package/src/data/field-mapper.ts +116 -54
- package/src/data/file-list.ts +522 -0
- package/src/data/flow-editor.ts +695 -158
- package/src/data/flow-node-options.ts +24 -5
- package/src/data/flow-remote-options.ts +94 -19
- package/src/data/footer.ts +88 -26
- package/src/data/form-draft-registry.ts +183 -12
- package/src/data/gantt.ts +640 -117
- package/src/data/graph-view.ts +51 -0
- package/src/data/heat-calendar.ts +412 -0
- package/src/data/hero.ts +40 -13
- package/src/data/image-viewer.ts +265 -62
- package/src/data/index.ts +75 -6
- package/src/data/item-list.ts +219 -58
- package/src/data/json-view.ts +909 -0
- package/src/data/kanban.ts +346 -91
- package/src/data/kit-contract.ts +230 -0
- package/src/data/leaderboard.ts +343 -0
- package/src/data/level-class.ts +21 -0
- package/src/data/log-stream.ts +347 -0
- package/src/data/markdown-view.ts +597 -0
- package/src/data/matrix.ts +234 -120
- package/src/data/media-grid.ts +165 -38
- package/src/data/mega-menu.ts +43 -26
- package/src/data/menu-bar.ts +254 -0
- package/src/data/menu-dom.ts +55 -19
- package/src/data/menu.ts +138 -48
- package/src/data/mockup.ts +37 -25
- package/src/data/modal-dialog.ts +126 -98
- package/src/data/navbar.ts +152 -66
- package/src/data/notice-list.ts +101 -49
- package/src/data/notify-renderer.ts +80 -15
- package/src/data/object-form.ts +1504 -164
- package/src/data/org-chart.ts +544 -0
- package/src/data/outcome-watch.ts +90 -21
- package/src/data/pager.ts +129 -45
- package/src/data/panel-head.ts +238 -76
- package/src/data/permission-matrix.ts +379 -120
- package/src/data/permission-tree.ts +146 -78
- package/src/data/pricing-table.ts +112 -43
- package/src/data/prompt-dialog.ts +49 -21
- package/src/data/reaction-bar.ts +67 -32
- package/src/data/record-card.ts +245 -72
- package/src/data/record-picker.ts +61 -28
- package/src/data/redirect.ts +39 -15
- package/src/data/request-console.ts +141 -38
- package/src/data/resident.ts +11 -13
- package/src/data/result-panel.ts +65 -27
- package/src/data/rich-text.ts +260 -127
- package/src/data/row-confirm.ts +47 -0
- package/src/data/row-editor.ts +384 -105
- package/src/data/rule-builder.ts +136 -81
- package/src/data/schedule-grid.ts +238 -0
- package/src/data/segment-bar.ts +221 -0
- package/src/data/shape-util.ts +90 -36
- package/src/data/stage-flow.ts +244 -0
- package/src/data/staged-rows.ts +207 -24
- package/src/data/stat-group.ts +493 -100
- package/src/data/static-lazy.ts +21 -0
- package/src/data/static-registry.ts +46 -4
- package/src/data/status-strip.ts +171 -0
- package/src/data/steps.ts +69 -36
- package/src/data/summary-strip.ts +136 -0
- package/src/data/summary-util.ts +116 -0
- package/src/data/survey.ts +134 -47
- package/src/data/system-switcher.ts +53 -24
- package/src/data/target-progress.ts +208 -0
- package/src/data/text-action-button.ts +28 -7
- package/src/data/text-diff.ts +731 -0
- package/src/data/tile-grid.ts +343 -0
- package/src/data/timeline.ts +205 -36
- package/src/data/tour-guide.ts +113 -47
- package/src/data/transfer.ts +204 -47
- package/src/data/tree-table.ts +228 -81
- package/src/data/tree.ts +193 -69
- package/src/data/trend-line.ts +68 -12
- package/src/data/virtual-rows.ts +248 -98
- package/src/data/waterfall.ts +171 -0
- package/src/data/watermark.ts +35 -6
- package/src/data/wrap.ts +28 -6
- package/src/frames/blank-frame.ts +6 -4
- package/src/frames/index.ts +4 -4
- package/src/frames/inherited-shell.ts +219 -0
- package/src/frames/page-bar.ts +208 -28
- package/src/frames/page-status.ts +3 -2
- package/src/frames/resident-components.ts +18 -0
- package/src/frames/shared.ts +73 -26
- package/src/frames/single-frame.ts +20 -4
- package/src/frames/split-frame/shell.ts +27 -17
- package/src/frames/split-frame/wiring.ts +16 -12
- package/src/frames/tabs-frame/shell.ts +14 -7
- package/src/frames/tabs-frame/wiring.ts +2 -1
- package/src/frames/top-main-frame.ts +55 -3
- package/src/frames/types.ts +5 -2
- package/src/frames/workspace-frame/extras.ts +23 -7
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/pipeline-key.ts +6 -0
- package/src/frames/workspace-frame/shell.ts +24 -3
- package/src/frames/workspace-frame/state.ts +42 -8
- package/src/frames/workspace-frame/view.ts +773 -194
- package/src/generated/kit-grammar-runtime.ts +1061 -77
- package/src/generated/kit-page.ts +272 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/kit-text.ts +210 -5
- package/src/i18n/resolve-text-refs.ts +1 -1
- package/src/object-renderer/action-group.ts +204 -22
- package/src/object-renderer/action-more.ts +66 -19
- package/src/object-renderer/arrange.ts +270 -28
- package/src/object-renderer/category-tone.ts +96 -0
- package/src/object-renderer/collapse-wiring.ts +19 -9
- package/src/object-renderer/collection-expand.ts +3 -3
- package/src/object-renderer/collection-parts.ts +459 -103
- package/src/object-renderer/collection-table.ts +406 -59
- package/src/object-renderer/collection.ts +333 -71
- package/src/object-renderer/compile-data.ts +13 -3
- package/src/object-renderer/defaults.ts +14 -5
- package/src/object-renderer/emit-events.ts +46 -20
- package/src/object-renderer/emit-object.ts +35 -6
- package/src/object-renderer/emit-static.ts +831 -153
- package/src/object-renderer/field-value.ts +12 -239
- package/src/object-renderer/filter-plan.ts +3 -3
- package/src/object-renderer/filter-toolbar.ts +190 -0
- package/src/object-renderer/form-detail.ts +87 -2
- package/src/{compile → object-renderer}/fragment.ts +2 -2
- package/src/object-renderer/index.ts +1 -1
- package/src/object-renderer/key-field.ts +21 -0
- package/src/object-renderer/layout-facts.ts +55 -7
- package/src/object-renderer/layout-plan.ts +6 -3
- package/src/object-renderer/overlay-decide.ts +124 -0
- package/src/object-renderer/pick-component.ts +8 -2
- package/src/object-renderer/pipeline-mode.ts +6 -0
- package/src/object-renderer/relation-field.ts +79 -0
- package/src/object-renderer/render-object.ts +72 -27
- package/src/object-renderer/request-actions.ts +119 -21
- package/src/object-renderer/table-actions.ts +479 -111
- package/src/object-renderer/table-gap.ts +2 -1
- package/src/object-renderer/table-reorder.ts +237 -0
- package/src/object-renderer/table-summary.ts +26 -12
- package/src/object-renderer/table-tools.ts +437 -130
- package/src/object-renderer/types.ts +100 -17
- package/src/object-renderer/value-present.ts +49 -0
- package/src/page-target/ai-surface.ts +15 -22
- package/src/page-target/compile.ts +5 -6
- package/src/page-target/drift.ts +0 -7
- package/src/page-target/intent-schema.ts +46 -43
- package/src/page-target/target.ts +4 -5
- package/src/page-target/writer-policy.ts +4 -5
- package/src/recipes/app-blocks.ts +66 -0
- package/src/recipes/chrome-surface.ts +20 -0
- package/src/recipes/code-view.ts +57 -0
- package/src/recipes/color-role.ts +442 -0
- package/src/recipes/compact-group.ts +32 -0
- package/src/recipes/composition-projector.ts +321 -0
- package/src/recipes/container.ts +93 -26
- package/src/recipes/control.ts +85 -8
- package/src/recipes/desc-list.ts +108 -0
- package/src/recipes/divider.ts +74 -0
- package/src/recipes/emphasis.ts +102 -13
- package/src/recipes/field-text.ts +72 -0
- package/src/recipes/form-section.ts +177 -0
- package/src/recipes/frame-bleed.ts +6 -5
- package/src/recipes/index.ts +39 -5
- package/src/recipes/inherited-shell.ts +43 -0
- package/src/recipes/json-view.ts +50 -0
- package/src/recipes/look.ts +56 -0
- package/src/recipes/mark.ts +138 -0
- package/src/recipes/markdown.ts +96 -0
- package/src/recipes/overlay.ts +151 -37
- package/src/recipes/page-width.ts +51 -0
- package/src/recipes/pipeline-runtime.ts +366 -0
- package/src/recipes/placeholder.ts +38 -20
- package/src/recipes/rail-grid.ts +6 -3
- package/src/recipes/self-owned.ts +59 -0
- package/src/recipes/slot-align.ts +5 -3
- package/src/recipes/stat-state.ts +6 -6
- package/src/recipes/state.ts +64 -11
- package/src/recipes/status.ts +21 -20
- package/src/recipes/strip.ts +114 -0
- package/src/recipes/surface-edge.ts +3 -1
- package/src/recipes/surface.ts +40 -7
- package/src/recipes/table-gap.ts +4 -3
- package/src/recipes/table-native-edit.ts +25 -12
- package/src/recipes/table-row.ts +56 -20
- package/src/recipes/tabs.ts +140 -31
- package/src/recipes/text-diff.ts +97 -0
- package/src/recipes/text-fit.ts +132 -0
- package/src/recipes/title-row.ts +72 -5
- package/src/recipes/typography.ts +2 -2
- package/src/shared/action-func.ts +106 -0
- package/src/shared/color-scheme.ts +127 -0
- package/src/shared/confirm-decl.ts +5 -2
- package/src/shared/danger-facts.ts +55 -0
- package/src/shared/diagnostics.ts +16 -0
- package/src/shared/dom-attrs-registry.ts +1009 -0
- package/src/shared/dom-attrs.ts +743 -0
- package/src/shared/envelope.ts +1 -1
- package/src/shared/field-kind.ts +49 -0
- package/src/shared/field-value-format.ts +292 -0
- package/src/shared/focus-ring.ts +8 -0
- package/src/shared/glyphs.ts +127 -0
- package/src/shared/hints.ts +56 -0
- package/src/{base → shared}/icons.ts +40 -1
- package/src/shared/identifier-field.ts +66 -0
- package/src/shared/kit-error.ts +1 -1
- package/src/shared/list-pager.ts +23 -0
- package/src/shared/list-title.ts +29 -0
- package/src/{object-renderer → shared}/merge-class.ts +3 -2
- package/src/shared/order-value.ts +15 -0
- package/src/shared/page-attrs-runtime.ts +327 -0
- package/src/shared/page-attrs.ts +262 -0
- package/src/shared/path-guard.ts +1 -1
- package/src/shared/pipeline-mode.ts +64 -0
- package/src/shared/primitives-types.ts +8 -0
- package/src/shared/row-key.ts +15 -0
- package/src/shared/theme-runtime-shared.ts +181 -21
- package/src/shared/theme-usage.ts +16 -0
- package/src/shared/value-table-contract.ts +68 -0
- package/src/spatial/action-func.ts +4 -0
- package/src/spatial/declared-actions.ts +116 -0
- package/src/spatial/emit.ts +660 -0
- package/src/spatial/expand.ts +1482 -0
- package/src/spatial/field-types.ts +48 -0
- package/src/spatial/index.ts +82 -0
- package/src/spatial/layout.ts +697 -0
- package/src/spatial/look-apply.ts +206 -0
- package/src/spatial/page-decl.ts +44 -0
- package/src/spatial/page-object.ts +349 -0
- package/src/spatial/recognize.ts +491 -0
- package/src/spatial/self-report.ts +571 -0
- package/src/spatial/shape.ts +205 -0
- package/src/spatial/spatial-map.ts +136 -0
- package/src/spatial/tone.ts +145 -0
- package/src/theme/index.ts +11 -2
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +563 -28
- package/src/theme/kit-theme.tpl +527 -28
- package/src/theme/look-carrier.ts +65 -0
- package/src/theme/nine-dim-structure.ts +538 -176
- package/src/theme/private-vars.ts +153 -0
- package/src/theme/surface-layers.ts +12 -3
- package/src/theme/theme-tokens.ts +1602 -90
- package/src/theme/theme-types.ts +38 -59
- package/src/theme/value-table.ts +2379 -0
- package/src/app/envelope.ts +0 -1
- package/src/app/notify-renderer.ts +0 -1
- package/src/app/paged-list-adapter.ts +0 -1
- package/src/app/theme-runtime-shared.ts +0 -1
- package/src/compile/kit-error.ts +0 -1
- package/src/frames/list-summary.ts +0 -100
- package/src/recipes/nowrap.ts +0 -16
- package/src/theme/block-theme.ts +0 -202
- /package/src/{base → shared}/class-candidates.ts +0 -0
package/src/data/chart.ts
CHANGED
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
// 没装配图表引擎、没数据、配置非法、引擎加载失败,都显示降级空态,不抛。
|
|
11
11
|
// 颜色只取 `--soma-*` 令牌(读运行期计算值交给引擎主题,源码里不写裸色值);样式类只用语义色名与 utilityScales 内的尺度。
|
|
12
12
|
|
|
13
|
+
import { kitApplyLevelClass } from './level-class';
|
|
14
|
+
import { kitLevelClassFor } from '../recipes/pipeline-runtime';
|
|
13
15
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
16
|
+
import { kitMarkDataFacts, kitMarkLevel } from './kit-contract';
|
|
14
17
|
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
15
18
|
import { createLoadingGate, type KitLoadingGate } from '../base/loading-gate';
|
|
16
19
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
@@ -23,11 +26,23 @@ import {
|
|
|
23
26
|
chartMarkDashPattern, defaultReadoutColumn, formatReadoutValue, parseChartMarks, parseReadout, resolveChartMarks, stepChartColumn,
|
|
24
27
|
type ChartMark, type ChartMarkSpec, type ReadoutConfig, type ResolvedChartMark, type VizTone,
|
|
25
28
|
} from 'soma-foundation/kit-viz';
|
|
26
|
-
import { classCandidates } from '../
|
|
27
|
-
import { mergeClass } from '../
|
|
29
|
+
import { classCandidates } from '../shared/class-candidates';
|
|
30
|
+
import { mergeClass } from '../shared/merge-class';
|
|
31
|
+
import { isDarkColorScheme, unwrapLightDark } from '../shared/color-scheme';
|
|
32
|
+
import { KIT_THEME_APPLIED_EVENT } from '../shared/theme-runtime-shared';
|
|
33
|
+
import { kitShellRecipe } from '../recipes/container';
|
|
34
|
+
import { kitDividerRecipe } from '../recipes/divider';
|
|
35
|
+
import { kitApplyChartTones, kitClearChartTones } from '../recipes/self-owned';
|
|
28
36
|
import { kitFocusRingRecipe } from '../recipes/state';
|
|
37
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
38
|
+
import { kitTypographyRecipe } from '../recipes/typography';
|
|
39
|
+
import { KIT_SKELETON_BAR_LAST_TEXT, KIT_SKELETON_BAR_LINE } from '../recipes/placeholder';
|
|
40
|
+
import { cleanSummaryFloat, SERIES_BG, TONE_BG } from './summary-util';
|
|
29
41
|
import { KIT_NOTICE_HEADLINE, KIT_STAT_VALUES_NUM, KIT_STAT_VALUES_ROW } from '../recipes/status';
|
|
30
42
|
import { KIT_GRAMMAR_RUNTIME as grammarJson } from '../generated/kit-grammar-runtime';
|
|
43
|
+
import {
|
|
44
|
+
KIT_ATTR_CHART_INDEX, KIT_ATTR_CHART_READOUT, KIT_ATTR_CHART_READY, KIT_ATTR_CHART_SERIES, KIT_ATTR_CHART_TIP, KIT_ATTR_STATE, KIT_ATTR_TIP_ALIGN,
|
|
45
|
+
} from '../shared/dom-attrs';
|
|
31
46
|
|
|
32
47
|
// 参考线 / 图例 / 数值格式的闭集与限值只读 kit-grammar.json#dataLimits.chart,代码里不手抄
|
|
33
48
|
const CHART_LIMITS = (grammarJson as unknown as { dataLimits: { chart: {
|
|
@@ -85,27 +100,58 @@ const ROLE_TYPES: ReadonlySet<string> = new Set(['line', 'area', 'bar', 'combo']
|
|
|
85
100
|
|
|
86
101
|
const ROOT_CLASS = 'relative w-full';
|
|
87
102
|
/** 图已就绪的根标记:引擎加载完并出过图后才有(截图 / 渲染测量据此判断,不靠固定等待) */
|
|
88
|
-
export const KIT_CHART_READY_ATTR =
|
|
103
|
+
export const KIT_CHART_READY_ATTR = KIT_ATTR_CHART_READY;
|
|
89
104
|
const STAGE_CLASS = 'h-72 w-full';
|
|
90
|
-
|
|
105
|
+
// 空态框 = 凹槽面的壳配方(容器边,KT-B2)
|
|
106
|
+
const EMPTY_INNER_CLASS = mergeClass(mergeClass('flex h-72 w-full items-center justify-center', kitTypographyRecipe('textMuted')), kitShellRecipe({ tone: 'sunken', shadow: false }));
|
|
91
107
|
|
|
92
108
|
/**
|
|
93
109
|
* 逐列读数区的类:排版与表面取 kit 配方(说明条标题 / StatGroup 多值行的字阶与等宽数字),不手写字阶;
|
|
94
|
-
*
|
|
110
|
+
* 容器是下沉面(井色 + rounded-card,与空态同一表面),键盘焦点环取条目焦点环配方。
|
|
95
111
|
*/
|
|
96
|
-
|
|
112
|
+
// 逐列读数区是说明块 = 子块出口(层级策略 sub,2026-11-25 第 4 关;不再取凹槽色)
|
|
113
|
+
const READOUT_CLASS = `sub-block px-3 py-2 ${KIT_STAT_VALUES_ROW}`;
|
|
97
114
|
const READOUT_TITLE_CLASS = KIT_NOTICE_HEADLINE;
|
|
98
115
|
const READOUT_ITEM_CLASS = 'inline-flex items-baseline gap-1.5';
|
|
99
116
|
const READOUT_VALUE_CLASS = KIT_STAT_VALUES_NUM;
|
|
100
117
|
const READOUT_NOTE_CLASS = 'text-fg-subtle';
|
|
101
|
-
const ROOT_FOCUS_CLASS = mergeClass('rounded-
|
|
118
|
+
const ROOT_FOCUS_CLASS = mergeClass('rounded-card', kitFocusRingRecipe('item'));
|
|
102
119
|
const READOUT_TOP_CLASS = 'mb-2';
|
|
103
120
|
const READOUT_BOTTOM_CLASS = 'mt-2';
|
|
104
121
|
|
|
122
|
+
/**
|
|
123
|
+
* 悬停数据卡(组件卡 ChartCommon §6:浅色数据卡,浮起面 + 发丝边 + 影,跟随指针):标题 + 逐系列「色块 名称 数值」,数值等宽右对齐。
|
|
124
|
+
* 只给指针用(aria-hidden,pointer-events-none);键盘与读屏走逐列读数区与读屏数据表。
|
|
125
|
+
*/
|
|
126
|
+
const TIP_CLASS = mergeClass('pointer-events-none absolute z-10 flex flex-col gap-1.5 px-3 py-2 text-xs', kitSurfaceRecipe('raised'));
|
|
127
|
+
const TIP_FLIP_X_CLASS = '-translate-x-full';
|
|
128
|
+
const TIP_FLIP_Y_CLASS = '-translate-y-full';
|
|
129
|
+
const TIP_ROW_CLASS = 'flex items-center gap-2';
|
|
130
|
+
const TIP_DOT_CLASS = 'size-2 shrink-0 rounded-full';
|
|
131
|
+
const TIP_NAME_CLASS = 'text-fg-muted';
|
|
132
|
+
const TIP_VALUE_CLASS = mergeClass('ms-auto ps-4 text-end', KIT_STAT_VALUES_NUM);
|
|
133
|
+
/** 悬停数据卡距指针的间距(像素,跟随定位用;取 legendGap 同一档) */
|
|
134
|
+
const TIP_OFFSET_PX = CHART_STYLE.legendGap;
|
|
135
|
+
/** 非直角坐标 SVG 图元委托提示序号属性(供指针悬停扇区/散点/漏斗层/雷达/热力格精准读数) */
|
|
136
|
+
export const KIT_CHART_ITEM_ATTR = KIT_ATTR_CHART_INDEX;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 空 / 加载态保留的空坐标网格(只有横向网格线,组件卡 ChartCommon §4 / §7):图区尺寸与真图一致,文字 / 骨架条叠在网格上。
|
|
140
|
+
* 线数取 gridMaxLines(与真图同一上限)。
|
|
141
|
+
*/
|
|
142
|
+
const GRID_PLACE_CLASS = 'absolute inset-0 flex flex-col justify-between py-3';
|
|
143
|
+
const GRID_LINE_CLASS = kitDividerRecipe('top');
|
|
144
|
+
const GRID_OVER_CLASS = mergeClass('relative flex h-72 w-full flex-col items-center justify-center gap-3', kitTypographyRecipe('textMuted'));
|
|
145
|
+
const GRID_SKELETON_CLASS = 'flex w-1/2 flex-col gap-3';
|
|
146
|
+
/** 有直角坐标网格的图型(空 / 加载时保留网格;饼 / 仪表盘等没有网格,仍用整块面板) */
|
|
147
|
+
const GRID_TYPES: ReadonlySet<string> = new Set(['line', 'bar', 'area', 'combo', 'scatter', 'candlestick', 'boxplot', 'bullet']);
|
|
148
|
+
|
|
105
149
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
106
150
|
export const KIT_CHART_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
107
|
-
['relative', 'absolute', 'inset-0', 'invisible', 'w-full', 'h-72', 'hidden', 'sr-only',
|
|
108
|
-
|
|
151
|
+
['relative', 'absolute', 'inset-0', 'invisible', 'w-full', 'h-72', 'size-full', 'hidden', 'sr-only',
|
|
152
|
+
EMPTY_INNER_CLASS, TIP_CLASS, TIP_FLIP_X_CLASS, TIP_FLIP_Y_CLASS, TIP_ROW_CLASS, TIP_DOT_CLASS, TIP_NAME_CLASS, TIP_VALUE_CLASS,
|
|
153
|
+
GRID_PLACE_CLASS, GRID_LINE_CLASS, GRID_OVER_CLASS, GRID_SKELETON_CLASS, KIT_SKELETON_BAR_LINE, KIT_SKELETON_BAR_LAST_TEXT,
|
|
154
|
+
...SERIES_BG, ...Object.values(TONE_BG)],
|
|
109
155
|
KIT_STATE_PANEL_CLASS_CANDIDATES,
|
|
110
156
|
READOUT_CLASS, READOUT_TITLE_CLASS, READOUT_ITEM_CLASS, READOUT_VALUE_CLASS, READOUT_NOTE_CLASS, ROOT_FOCUS_CLASS,
|
|
111
157
|
READOUT_TOP_CLASS, READOUT_BOTTOM_CLASS,
|
|
@@ -115,10 +161,12 @@ export const KIT_CHART_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
|
115
161
|
|
|
116
162
|
export type KitChartType =
|
|
117
163
|
| 'line' | 'bar' | 'area' | 'pie' | 'donut' | 'funnel' | 'gauge'
|
|
118
|
-
| 'scatter' | 'combo' | 'radar' | 'heatmap' | 'boxplot' | 'candlestick' | 'sankey' | 'treemap' | 'sunburst' | 'chord'
|
|
164
|
+
| 'scatter' | 'combo' | 'radar' | 'heatmap' | 'boxplot' | 'candlestick' | 'sankey' | 'treemap' | 'sunburst' | 'chord'
|
|
165
|
+
| 'rose' | 'network' | 'bullet';
|
|
119
166
|
export const KIT_CHART_TYPES: readonly KitChartType[] = Object.freeze([
|
|
120
167
|
'line', 'bar', 'area', 'pie', 'donut', 'funnel', 'gauge',
|
|
121
168
|
'scatter', 'combo', 'radar', 'heatmap', 'boxplot', 'candlestick', 'sankey', 'treemap', 'sunburst', 'chord',
|
|
169
|
+
'rose', 'network', 'bullet',
|
|
122
170
|
]);
|
|
123
171
|
|
|
124
172
|
export interface KitChartConfig {
|
|
@@ -150,10 +198,14 @@ export interface KitChartConfig {
|
|
|
150
198
|
readout?: ReadoutConfig;
|
|
151
199
|
/** 点击 / Enter 选中列抛 point_pick(K3) */
|
|
152
200
|
interact?: { pick: boolean };
|
|
201
|
+
/** 涨跌色反转开关(K 线):缺省 good = 涨为成功色、跌为危险色;bad = 涨为危险色、跌为成功色(红涨绿跌习惯 / 成本类指标) */
|
|
202
|
+
upIs?: 'good' | 'bad';
|
|
153
203
|
/** 图例位置:auto = 多系列时在底部(饼 / 漏斗始终在底部),none 关闭 */
|
|
154
204
|
legend?: 'auto' | 'top' | 'bottom' | 'none';
|
|
155
205
|
/** 纵轴 / 标签的数值前后缀(引擎字符串模板,不含函数) */
|
|
156
206
|
valueFormat?: { prefix: string; suffix: string };
|
|
207
|
+
/** heatmap 色阶模式:sequential(顺序 10 阶)| diverging(发散 17 阶);未指定时按数据是否同时含正负自动判定 */
|
|
208
|
+
scale?: 'sequential' | 'diverging';
|
|
157
209
|
}
|
|
158
210
|
|
|
159
211
|
export interface KitChartRefLine {
|
|
@@ -165,22 +217,51 @@ export interface KitChartRefLine {
|
|
|
165
217
|
|
|
166
218
|
/** 引擎端口里的系列类型:area 走 line,donut 走 pie;combo 同时要柱和线两种 */
|
|
167
219
|
export function engineSeriesOf(type: KitChartType): string {
|
|
168
|
-
return type === 'area' ? 'line' : type === 'donut' ? 'pie' : type === 'combo' ? 'bar' : type;
|
|
220
|
+
return type === 'area' ? 'line' : type === 'donut' || type === 'rose' ? 'pie' : type === 'combo' || type === 'bullet' ? 'bar' : type === 'network' ? 'graph' : type;
|
|
169
221
|
}
|
|
170
222
|
|
|
171
|
-
/** 一张图要装的全部引擎系列类型(combo = bar + line) */
|
|
172
|
-
export function engineSeriesListOf(type: KitChartType): string[] {
|
|
173
|
-
|
|
223
|
+
/** 一张图要装的全部引擎系列类型(combo = bar + line;bar 等直角图含 baseline / ideal / projection / line 系列时补齐 line) */
|
|
224
|
+
export function engineSeriesListOf(type: KitChartType, config?: Pick<KitChartConfig, 'roles' | 'line'>): string[] {
|
|
225
|
+
// bullet = 横条(实际值)+ 方块散点(目标刻度)
|
|
226
|
+
const out = type === 'combo' ? ['bar', 'line'] : type === 'bullet' ? ['bar', 'scatter'] : [engineSeriesOf(type)];
|
|
227
|
+
const needsLine = (config?.line?.length ?? 0) > 0
|
|
228
|
+
|| Object.values(config?.roles ?? {}).some((r) => r === 'ideal' || r === 'baseline' || r === 'projection');
|
|
229
|
+
if (needsLine && !out.includes('line')) out.push('line');
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** 扫描实际产出的 option.series,补齐全部引擎系列类型(防止 bar + baseline/line 等运行时报未导入系列) */
|
|
234
|
+
function renderedSeriesTypesOf(config: KitChartConfig, option: Record<string, unknown>): string[] {
|
|
235
|
+
const types = new Set(engineSeriesListOf(config.type, config));
|
|
236
|
+
if (Array.isArray(option.series)) {
|
|
237
|
+
for (const s of option.series) {
|
|
238
|
+
if (s !== null && typeof s === 'object' && typeof (s as { type?: unknown }).type === 'string') {
|
|
239
|
+
types.add((s as { type: string }).type);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return [...types];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** 角色后缀去重:字段名已含同义角色词(如「预测」「理想」)时不拼成「预测(预测)」「理想(理想)」 */
|
|
247
|
+
function appendRoleSuffix(name: string, suffix: string): string {
|
|
248
|
+
if (suffix === '') return name;
|
|
249
|
+
const trimmed = name.trim();
|
|
250
|
+
if (trimmed === '') return name;
|
|
251
|
+
const core = suffix.replace(/^[\s((]+|[\s))]+$/g, '').trim().toLowerCase();
|
|
252
|
+
if (core !== '' && trimmed.toLowerCase().includes(core)) return name;
|
|
253
|
+
return `${name}${suffix}`;
|
|
174
254
|
}
|
|
175
255
|
|
|
176
256
|
/** 数据要求:除 x / y 外还必须给的字段,以及 y 最少几个字段(纯函数,chartConfigOf 用) */
|
|
177
|
-
const MIN_Y: Readonly<Partial<Record<KitChartType, number>>> = Object.freeze({ boxplot: 5, candlestick: 4 });
|
|
257
|
+
const MIN_Y: Readonly<Partial<Record<KitChartType, number>>> = Object.freeze({ boxplot: 5, candlestick: 4, bullet: 2 });
|
|
178
258
|
const NEEDS_VALUE: ReadonlySet<KitChartType> = new Set<KitChartType>(['heatmap', 'sankey', 'chord']);
|
|
179
259
|
|
|
180
260
|
/** 各类型需要的引擎组件:直角坐标系要 grid + legend;pie / donut / funnel 只要 legend;gauge 都不要 */
|
|
181
261
|
export function engineComponentsOf(type: KitChartType, withMarkLine = false, extra: readonly string[] = []): string[] {
|
|
182
|
-
if (type === 'gauge' || type === 'sankey' || type === 'treemap' || type === 'sunburst' || type === 'chord') return [];
|
|
183
|
-
if (type === 'pie' || type === 'donut' || type === 'funnel') return ['legend'];
|
|
262
|
+
if (type === 'gauge' || type === 'sankey' || type === 'treemap' || type === 'sunburst' || type === 'chord' || type === 'network') return [];
|
|
263
|
+
if (type === 'pie' || type === 'donut' || type === 'rose' || type === 'funnel') return ['legend'];
|
|
264
|
+
if (type === 'bullet') return ['grid'];
|
|
184
265
|
if (type === 'radar') return ['radar', 'legend'];
|
|
185
266
|
if (type === 'heatmap') return ['grid', 'visualMap'];
|
|
186
267
|
if (type === 'boxplot' || type === 'candlestick') return ['grid'];
|
|
@@ -301,6 +382,8 @@ export function chartConfigOf(chartRaw: unknown): KitChartConfig | null {
|
|
|
301
382
|
const vf = recOf(src.value_format);
|
|
302
383
|
const prefix = affixOf(vf.prefix);
|
|
303
384
|
const suffix = affixOf(vf.suffix);
|
|
385
|
+
const rawScale = str(src.scale || src.mode);
|
|
386
|
+
const scale = type === 'heatmap' && (rawScale === 'sequential' || rawScale === 'diverging') ? rawScale : undefined;
|
|
304
387
|
return {
|
|
305
388
|
...(lineFields.length > 0 ? { line: lineFields } : {}),
|
|
306
389
|
...(y2Fields.length > 0 ? { y2: y2Fields } : {}),
|
|
@@ -310,7 +393,9 @@ export function chartConfigOf(chartRaw: unknown): KitChartConfig | null {
|
|
|
310
393
|
...(readout !== undefined ? { readout } : {}),
|
|
311
394
|
...(interactRaw !== undefined && interactRaw !== null ? { interact: { pick: interactRec.pick === true || interactRec.pick === 'true' } } : {}),
|
|
312
395
|
...(legend !== 'auto' ? { legend } : {}),
|
|
396
|
+
...(str(src.up_is) === 'bad' ? { upIs: 'bad' as const } : {}),
|
|
313
397
|
...(prefix !== '' || suffix !== '' ? { valueFormat: { prefix, suffix } } : {}),
|
|
398
|
+
...(scale !== undefined ? { scale } : {}),
|
|
314
399
|
type, x, y, stack, min, max, warnAt: num(src.warnAt), dangerAt: num(src.dangerAt),
|
|
315
400
|
...(value !== '' ? { value } : {}),
|
|
316
401
|
...(str(src.parent) !== '' ? { parent: str(src.parent) } : {}),
|
|
@@ -369,20 +454,82 @@ export function chartHierarchy(
|
|
|
369
454
|
export interface KitChartTheme {
|
|
370
455
|
/** 系列色(解析后的运行期颜色值,取自 --soma-c-*) */
|
|
371
456
|
palette: string[];
|
|
457
|
+
/** 数据文字(标签、仪表读数、矩形树名):--soma-text-secondary */
|
|
372
458
|
text: string;
|
|
373
|
-
|
|
459
|
+
/** 网格线(数值轴横线、雷达 / 仪表网格、热力色阶起点):--soma-chart-grid,十六进制实色 */
|
|
460
|
+
grid: string;
|
|
461
|
+
/** 类目轴基线:--soma-chart-axis,十六进制实色 */
|
|
462
|
+
axis: string;
|
|
463
|
+
/** 刻度字 / 图例字 / 轴名(弱化墨 --soma-text-muted);缺省退回 text */
|
|
464
|
+
tick?: string;
|
|
465
|
+
/** 刻度字号(px,读 --soma-font-size-xs 的计算值 = 字阶最小档);读不到不设,用引擎默认 */
|
|
466
|
+
tickPx?: number;
|
|
374
467
|
/** 理想线色(中性令牌 --soma-text-muted 的运行期值);缺省退回 text */
|
|
375
468
|
ideal?: string;
|
|
376
469
|
/** 主色(标记 primary 语气、焦点带;--soma-c-primary 的运行期值);缺省退回 palette[0] */
|
|
377
470
|
primary?: string;
|
|
378
471
|
/** 预测线系列名后缀(如「(预测)」,来自 kit 文案);缺省不加 */
|
|
379
472
|
projectionSuffix?: string;
|
|
473
|
+
/** gauge 底轨色(图表未填充底弧 --soma-chart-idle 的运行期值);缺省退回 grid */
|
|
474
|
+
track?: string;
|
|
380
475
|
/** gauge 阈值着色:正常 / 警告 / 危险(取自 --soma-c-success / warning / danger);缺省退回系列色 */
|
|
381
476
|
ok?: string;
|
|
382
477
|
warn?: string;
|
|
383
478
|
danger?: string;
|
|
384
479
|
/** 柱宽 / 类间距的比例(百分数,取 --soma-chart-bar-ratio;强调级越低越细);缺省用引擎默认 */
|
|
385
480
|
barRatioPct?: number;
|
|
481
|
+
/** 热力顺序色阶(--soma-chart-seq-1..10);缺省回落 [grid, palette[0]] */
|
|
482
|
+
seqRamp?: string[];
|
|
483
|
+
/** 热力发散色阶(--soma-chart-div-1..17);缺省回落 [grid, palette[0]] */
|
|
484
|
+
divRamp?: string[];
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** 十进制好数列 1-2-5(刻度步长的尾数,与引擎 / d3 nice 刻度同一序列;算法常量,不是视觉取值) */
|
|
488
|
+
const NICE_MANTISSAS: readonly number[] = [1, 2, 5, 10];
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* 数值轴步长:含 0 的数据跨度分成至多 maxLines − 1 段、步长取好数(纯函数)。堆叠序列按同一下标求和;没有数值或跨度为 0 返回 undefined(交给引擎)。
|
|
492
|
+
*/
|
|
493
|
+
export function gridIntervalOf(series: ReadonlyArray<Record<string, unknown>>, maxLines: number): number | undefined {
|
|
494
|
+
return gridAxisOf(series, maxLines)?.interval;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* 数值轴的步长与上下界(纯函数):界对齐到步长整数倍。只给步长时引擎仍按自己的好数取上界(实拍:数据最大 32、步长 10 时顶上多出一条 35),
|
|
499
|
+
* 所以上下界一起给,横线 = 跨度 / 步长 + 1 ≤ maxLines。
|
|
500
|
+
*/
|
|
501
|
+
export function gridAxisOf(series: ReadonlyArray<Record<string, unknown>>, maxLines: number): { interval: number; min: number; max: number } | undefined {
|
|
502
|
+
const vals: number[] = [0];
|
|
503
|
+
const stacks = new Map<string, number[]>();
|
|
504
|
+
for (const s of series) {
|
|
505
|
+
const data = Array.isArray(s.data) ? s.data : [];
|
|
506
|
+
const nums = data.map((d) => (typeof d === 'number' && Number.isFinite(d) ? d : null));
|
|
507
|
+
if (typeof s.stack === 'string') {
|
|
508
|
+
const acc = stacks.get(s.stack) ?? [];
|
|
509
|
+
nums.forEach((v, i) => { acc[i] = (acc[i] ?? 0) + (v ?? 0); });
|
|
510
|
+
stacks.set(s.stack, acc);
|
|
511
|
+
} else {
|
|
512
|
+
for (const v of nums) if (v !== null) vals.push(v);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
for (const acc of stacks.values()) vals.push(...acc.filter((v) => Number.isFinite(v)));
|
|
516
|
+
const lo = Math.min(...vals);
|
|
517
|
+
const hi = Math.max(...vals);
|
|
518
|
+
const span = hi - lo;
|
|
519
|
+
if (!(span > 0) || maxLines < 2) return undefined;
|
|
520
|
+
// 步长从好数里取最小的那个,使对齐后的格数 ≤ maxLines − 1(先按跨度估,再按对齐后的格数逐级放大)
|
|
521
|
+
const raw = span / (maxLines - 1);
|
|
522
|
+
let pow = 10 ** Math.floor(Math.log10(raw));
|
|
523
|
+
for (let guard = 0; guard < 4; guard += 1) {
|
|
524
|
+
for (const k of NICE_MANTISSAS) {
|
|
525
|
+
const interval = k * pow;
|
|
526
|
+
const min = Math.floor(lo / interval) * interval;
|
|
527
|
+
const max = Math.ceil(hi / interval) * interval;
|
|
528
|
+
if (Math.round((max - min) / interval) <= maxLines - 1) return { interval, min, max };
|
|
529
|
+
}
|
|
530
|
+
pow *= 10;
|
|
531
|
+
}
|
|
532
|
+
return undefined;
|
|
386
533
|
}
|
|
387
534
|
|
|
388
535
|
/** 把 #rrggbb 色按 pct% 混入面板面色(pct = 系列色占比);无法解析(非 #rrggbb)时原样返回。强调级低的图表填充更浅,主图表 100 = 实心。 */
|
|
@@ -419,11 +566,61 @@ export function gaugeBands(config: KitChartConfig, theme: KitChartTheme): Array<
|
|
|
419
566
|
return bands.sort((a, b) => a[0] - b[0]);
|
|
420
567
|
}
|
|
421
568
|
|
|
569
|
+
/** gauge 进度弧的颜色:值落在哪一段就取哪一段的阈值色(底轨不带阈值色);纯函数 */
|
|
570
|
+
export function gaugeValueColor(config: KitChartConfig, theme: KitChartTheme, value: number | null): string {
|
|
571
|
+
const min = config.min ?? 0;
|
|
572
|
+
const span = (config.max ?? 100) - min;
|
|
573
|
+
const ratio = value === null || span <= 0 ? 0 : Math.min(1, Math.max(0, (value - min) / span));
|
|
574
|
+
const bands = gaugeBands(config, theme);
|
|
575
|
+
return (bands.find(([upTo]) => ratio < upTo) ?? bands[bands.length - 1])?.[1] ?? theme.palette[0] ?? '';
|
|
576
|
+
}
|
|
577
|
+
|
|
422
578
|
/**
|
|
423
579
|
* 生成引擎 option(纯函数)。键名对照 map 只对数据键生效:配置里的 x / y 先经 map 取源键。
|
|
424
580
|
* option 不含 tooltip(端口禁止)。
|
|
425
581
|
*/
|
|
582
|
+
/**
|
|
583
|
+
* 引擎 option 生成(含共用缺省):各图型选项由 buildChartOptionCore 产出,这里统一补:
|
|
584
|
+
* 动画(入场 600 / 更新 300 / cubicInOut / 超 2000 点关动画)、悬停高亮(聚焦本系列、其余降到 0.3)、柱顶圆角 4 与最小柱高 2。
|
|
585
|
+
* 取值同 05-图表与统计 的「共用」键(ECharts globalDefault / shadcn chart / Tremor),数字在 design kit-limits#dataLimits.chart.style。
|
|
586
|
+
*/
|
|
426
587
|
export function buildChartOption(
|
|
588
|
+
config: KitChartConfig,
|
|
589
|
+
rows: ReadonlyArray<Record<string, unknown>>,
|
|
590
|
+
theme: KitChartTheme,
|
|
591
|
+
mapRaw?: unknown,
|
|
592
|
+
view: { focus?: number } = {},
|
|
593
|
+
): Record<string, unknown> {
|
|
594
|
+
const core = buildChartOptionCore(config, rows, theme, mapRaw, view);
|
|
595
|
+
const blur = CHART_STYLE.blurOpacity;
|
|
596
|
+
const series = Array.isArray(core.series) ? core.series.map((s: unknown) => {
|
|
597
|
+
if (s === null || typeof s !== 'object') return s;
|
|
598
|
+
const item = s as Record<string, unknown>;
|
|
599
|
+
const type = item.type;
|
|
600
|
+
if (type === 'line' || type === 'bar' || type === 'scatter' || type === 'radar') {
|
|
601
|
+
const stacked = item.stack !== undefined;
|
|
602
|
+
const round = type === 'bar' && !stacked && config.type !== 'bullet';
|
|
603
|
+
const itemStyle = item.itemStyle as Record<string, unknown> | undefined;
|
|
604
|
+
return {
|
|
605
|
+
...item,
|
|
606
|
+
emphasis: { focus: 'series', ...(item.emphasis as Record<string, unknown> | undefined) },
|
|
607
|
+
blur: item.blur ?? { itemStyle: { opacity: blur }, lineStyle: { opacity: blur }, areaStyle: { opacity: blur } },
|
|
608
|
+
...(round ? { barMinHeight: item.barMinHeight ?? CHART_STYLE.barMinHeight, itemStyle: { borderRadius: [CHART_STYLE.barRadius, CHART_STYLE.barRadius, 0, 0], ...itemStyle } } : {}),
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
return s;
|
|
612
|
+
}) : core.series;
|
|
613
|
+
return {
|
|
614
|
+
animationDuration: CHART_STYLE.animationMs,
|
|
615
|
+
animationDurationUpdate: CHART_STYLE.animationUpdateMs,
|
|
616
|
+
animationEasing: 'cubicInOut',
|
|
617
|
+
animationThreshold: CHART_STYLE.animationThreshold,
|
|
618
|
+
...core,
|
|
619
|
+
...(series !== undefined ? { series } : {}),
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function buildChartOptionCore(
|
|
427
624
|
config: KitChartConfig,
|
|
428
625
|
rows: ReadonlyArray<Record<string, unknown>>,
|
|
429
626
|
theme: KitChartTheme,
|
|
@@ -439,11 +636,36 @@ export function buildChartOption(
|
|
|
439
636
|
|
|
440
637
|
// 图例位置与数值前后缀:legend 缺省按各图型原习惯(auto),value_format 只拼引擎字符串模板
|
|
441
638
|
const fmt = config.valueFormat;
|
|
639
|
+
// 单位只写一次:数值轴刻度只写数,前后缀进数值轴的轴名(axisUnitName);数据标签 / 仪表读数仍带单位(valueTemplate / labelTemplate)
|
|
442
640
|
const valueTemplate = fmt ? `${fmt.prefix}{value}${fmt.suffix}` : undefined;
|
|
443
641
|
const labelTemplate = fmt ? `{b}: ${fmt.prefix}{c}${fmt.suffix}` : undefined;
|
|
642
|
+
const axisUnitName = fmt ? `${fmt.prefix}${fmt.suffix}`.trim() : '';
|
|
643
|
+
const tick = theme.tick ?? theme.text;
|
|
644
|
+
const tickText = { color: tick, ...(theme.tickPx !== undefined ? { fontSize: theme.tickPx } : {}) };
|
|
444
645
|
const legendShown = (auto: boolean): boolean => (config.legend === 'none' ? false : config.legend === 'top' || config.legend === 'bottom' ? true : auto);
|
|
445
646
|
const legendOf = (auto: boolean): Record<string, unknown> | undefined =>
|
|
446
|
-
|
|
647
|
+
// 图例标记 8×8 圆角 2、项间距 16(共用取值:shadcn chart legend / ECharts legend)
|
|
648
|
+
(legendShown(auto) ? {
|
|
649
|
+
...(config.legend === 'top' ? { top: 0 } : { bottom: 0 }), textStyle: tickText,
|
|
650
|
+
icon: 'roundRect', itemWidth: CHART_STYLE.legendMarkPx, itemHeight: CHART_STYLE.legendMarkPx, itemGap: CHART_STYLE.legendGap,
|
|
651
|
+
} : undefined);
|
|
652
|
+
// 直角坐标轴样式(落地工单第一批 §2):数值轴无轴线、无刻度线,只有 ≤ gridMaxLines 条横向网格(grid 色 1px);
|
|
653
|
+
// 类目轴一条基线(axis 色)、无刻度线、无竖网格;刻度字 = 弱化墨、字阶最小档、等宽数字,离轴 axisLabelGapPx
|
|
654
|
+
const tickLabel = { ...tickText, margin: CHART_STYLE.axisLabelGapPx, fontVariantNumeric: 'tabular-nums' };
|
|
655
|
+
const valueAxisStyle = (withUnit: boolean): Record<string, unknown> => ({
|
|
656
|
+
axisLine: { show: false },
|
|
657
|
+
axisTick: { show: false },
|
|
658
|
+
splitNumber: CHART_STYLE.gridMaxLines - 1,
|
|
659
|
+
splitLine: { lineStyle: { color: theme.grid, width: CHART_STYLE.gridLineWidth } },
|
|
660
|
+
axisLabel: tickLabel,
|
|
661
|
+
...(withUnit && axisUnitName !== '' ? { name: axisUnitName, nameLocation: 'end', nameTextStyle: { ...tickText, align: 'left' } } : {}),
|
|
662
|
+
});
|
|
663
|
+
const categoryAxisStyle = {
|
|
664
|
+
axisLine: { lineStyle: { color: theme.axis, width: CHART_STYLE.gridLineWidth } },
|
|
665
|
+
axisTick: { show: false },
|
|
666
|
+
splitLine: { show: false },
|
|
667
|
+
axisLabel: tickLabel,
|
|
668
|
+
};
|
|
447
669
|
const toneColor = (tone: KitChartRefLine['tone'] | VizTone): string =>
|
|
448
670
|
(tone === 'success' ? (theme.ok ?? theme.palette[0] ?? theme.text)
|
|
449
671
|
: tone === 'warning' ? (theme.warn ?? theme.palette[1] ?? theme.text)
|
|
@@ -459,29 +681,118 @@ export function buildChartOption(
|
|
|
459
681
|
const style = MARK_SPEC.roles[role]!;
|
|
460
682
|
return { color: toneColor(style.tone), dash: chartMarkDashPattern(style.dash), symbol: style.symbol };
|
|
461
683
|
};
|
|
684
|
+
const hasY2 = config.type === 'combo' && (config.y2?.length ?? 0) > 0;
|
|
685
|
+
/** 估算参考线标签像素宽(中文约 12px、ASCII 约 7px),避免在无布局环境下被 SVG 右边界裁切 */
|
|
686
|
+
const estimateLabelPx = (text: string): number => {
|
|
687
|
+
let px = 0;
|
|
688
|
+
for (const ch of text) px += ch.charCodeAt(0) > 127 ? 12 : 7;
|
|
689
|
+
return px;
|
|
690
|
+
};
|
|
691
|
+
/** 估算参考线的数值坐标(用于判定右侧相邻标签是否过近并错开 y 偏移) */
|
|
692
|
+
const primaryValues = (): number[] => {
|
|
693
|
+
const firstY = config.y[0];
|
|
694
|
+
if (firstY === undefined) return [];
|
|
695
|
+
const k = src(firstY);
|
|
696
|
+
return rows.map((r) => num(r[k])).filter((v): v is number => v !== null);
|
|
697
|
+
};
|
|
698
|
+
const statValueOf = (stat: KitChartRefLine['stat'], vals: readonly number[]): number | null => {
|
|
699
|
+
if (vals.length === 0 || stat === undefined) return null;
|
|
700
|
+
if (stat === 'max') return Math.max(...vals);
|
|
701
|
+
if (stat === 'min') return Math.min(...vals);
|
|
702
|
+
if (stat === 'average') return vals.reduce((a, b) => a + b, 0) / vals.length;
|
|
703
|
+
const sorted = [...vals].sort((a, b) => a - b);
|
|
704
|
+
const mid = Math.floor(sorted.length / 2);
|
|
705
|
+
return sorted.length % 2 === 1 ? sorted[mid]! : (sorted[mid - 1]! + sorted[mid]!) / 2;
|
|
706
|
+
};
|
|
462
707
|
/** 参考线与标记竖线 / 横线合并成引擎 markLine,只挂在第一条系列上(虚线 / 实线由角色定,不带 tooltip) */
|
|
463
708
|
const markLineOf = (): Record<string, unknown> => {
|
|
464
709
|
const refs = config.refLines ?? [];
|
|
465
710
|
const lines = resolvedMarks.filter((m) => m.kind === 'line');
|
|
466
711
|
if (refs.length === 0 && lines.length === 0) return {};
|
|
712
|
+
const vals = primaryValues();
|
|
713
|
+
const yLines: Array<{ key: string; yVal: number | null; label: string }> = [];
|
|
714
|
+
refs.forEach((r, idx) => {
|
|
715
|
+
if (r.label !== '') yLines.push({ key: `r:${idx}`, yVal: r.value !== undefined ? r.value : statValueOf(r.stat, vals), label: r.label });
|
|
716
|
+
});
|
|
717
|
+
lines.forEach((m, idx) => {
|
|
718
|
+
if (m.axis === 'y' && m.label !== '') yLines.push({ key: `m:${idx}`, yVal: typeof m.at === 'number' ? m.at : null, label: m.label });
|
|
719
|
+
});
|
|
720
|
+
const numericVals = [...vals, ...yLines.map((x) => x.yVal).filter((v): v is number => v !== null)];
|
|
721
|
+
// 直角坐标值轴默认含 0,估算可见纵轴跨度时把 0 纳入上下界,避免相邻参考线被误判为相距甚远
|
|
722
|
+
const ySpan = numericVals.length > 0 ? Math.max(0, ...numericVals) - Math.min(0, ...numericVals) : 0;
|
|
723
|
+
const closeGap = ySpan > 0 ? ySpan * 0.14 : 0;
|
|
724
|
+
const dyByKey = new Map<string, number>();
|
|
725
|
+
const posByKey = new Map<string, 'end' | 'insideEndTop' | 'insideEndBottom'>();
|
|
726
|
+
if (yLines.length > 0) {
|
|
727
|
+
const sorted = [...yLines].sort((a, b) => (b.yVal ?? 0) - (a.yVal ?? 0));
|
|
728
|
+
const clusters: Array<typeof sorted> = [];
|
|
729
|
+
for (const item of sorted) {
|
|
730
|
+
const lastCluster = clusters[clusters.length - 1];
|
|
731
|
+
const prev = lastCluster?.[lastCluster.length - 1];
|
|
732
|
+
const isClose = prev !== undefined && (
|
|
733
|
+
item.yVal === null || prev.yVal === null || Math.abs(prev.yVal - item.yVal) <= closeGap
|
|
734
|
+
);
|
|
735
|
+
if (lastCluster && isClose) lastCluster.push(item);
|
|
736
|
+
else clusters.push([item]);
|
|
737
|
+
}
|
|
738
|
+
for (const cluster of clusters) {
|
|
739
|
+
if (cluster.length === 1) {
|
|
740
|
+
posByKey.set(cluster[0]!.key, hasY2 ? 'insideEndTop' : 'end');
|
|
741
|
+
dyByKey.set(cluster[0]!.key, 0);
|
|
742
|
+
} else {
|
|
743
|
+
const mid = (cluster.length - 1) / 2;
|
|
744
|
+
cluster.forEach((item, i) => {
|
|
745
|
+
if (hasY2) {
|
|
746
|
+
posByKey.set(item.key, i <= mid ? 'insideEndTop' : 'insideEndBottom');
|
|
747
|
+
dyByKey.set(item.key, Math.round((i - mid) * 14));
|
|
748
|
+
} else {
|
|
749
|
+
posByKey.set(item.key, 'end');
|
|
750
|
+
dyByKey.set(item.key, Math.round((i - mid) * 16));
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
467
756
|
return {
|
|
468
757
|
markLine: {
|
|
469
758
|
silent: true,
|
|
470
759
|
symbol: 'none',
|
|
471
760
|
data: [
|
|
472
|
-
...refs.map((r) =>
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
761
|
+
...refs.map((r, idx) => {
|
|
762
|
+
const key = `r:${idx}`;
|
|
763
|
+
const dy = dyByKey.get(key) ?? 0;
|
|
764
|
+
const position = posByKey.get(key) ?? (hasY2 ? 'insideEndTop' : 'end');
|
|
765
|
+
return {
|
|
766
|
+
...(r.value !== undefined ? { yAxis: r.value } : { type: r.stat }),
|
|
767
|
+
name: r.label,
|
|
768
|
+
lineStyle: { type: 'dashed', color: toneColor(r.tone) },
|
|
769
|
+
label: {
|
|
770
|
+
show: r.label !== '',
|
|
771
|
+
formatter: r.label,
|
|
772
|
+
color: toneColor(r.tone),
|
|
773
|
+
position,
|
|
774
|
+
...(dy !== 0 ? { offset: [0, dy] } : {}),
|
|
775
|
+
},
|
|
776
|
+
};
|
|
777
|
+
}),
|
|
778
|
+
...lines.map((m, idx) => {
|
|
479
779
|
const s = roleOf(m.role);
|
|
780
|
+
const key = `m:${idx}`;
|
|
781
|
+
const isY = m.axis === 'y';
|
|
782
|
+
const dy = isY ? (dyByKey.get(key) ?? 0) : 0;
|
|
783
|
+
const position = isY ? (posByKey.get(key) ?? (hasY2 ? 'insideEndTop' : 'end')) : 'end';
|
|
480
784
|
return {
|
|
481
785
|
...(m.axis === 'x' ? { xAxis: m.at } : { yAxis: m.at }),
|
|
482
786
|
name: m.label,
|
|
483
787
|
lineStyle: { type: s.dash === null ? 'solid' : [...s.dash], color: s.color, width: CHART_NUM.marks.lineWidth },
|
|
484
|
-
label: {
|
|
788
|
+
label: {
|
|
789
|
+
show: m.label !== '',
|
|
790
|
+
formatter: m.label,
|
|
791
|
+
color: s.color,
|
|
792
|
+
position,
|
|
793
|
+
rotate: 0,
|
|
794
|
+
...(dy !== 0 ? { offset: [0, dy] } : {}),
|
|
795
|
+
},
|
|
485
796
|
};
|
|
486
797
|
}),
|
|
487
798
|
],
|
|
@@ -532,9 +843,18 @@ export function buildChartOption(
|
|
|
532
843
|
},
|
|
533
844
|
};
|
|
534
845
|
};
|
|
535
|
-
/** 直角坐标系的 grid:底部图例留 32,顶部图例把上沿让到 40 */
|
|
846
|
+
/** 直角坐标系的 grid:底部图例留 32,顶部图例把上沿让到 40;有右侧参考线外置标签时按标签宽留出右边距避免裁切 */
|
|
847
|
+
const rightMarkLabels = hasY2
|
|
848
|
+
? []
|
|
849
|
+
: [
|
|
850
|
+
...(config.refLines ?? []).map((r) => r.label).filter((s) => s !== ''),
|
|
851
|
+
...resolvedMarks.filter((m) => m.kind === 'line' && m.axis === 'y' && m.label !== '').map((m) => m.label),
|
|
852
|
+
];
|
|
853
|
+
const rightLabelPad = rightMarkLabels.length > 0
|
|
854
|
+
? Math.min(136, Math.max(48, Math.max(...rightMarkLabels.map(estimateLabelPx)) + 20))
|
|
855
|
+
: 24;
|
|
536
856
|
const gridFor = (multi: boolean): Record<string, unknown> => ({
|
|
537
|
-
left: 8, right:
|
|
857
|
+
left: 8, right: rightLabelPad, containLabel: true,
|
|
538
858
|
top: legendShown(multi) && config.legend === 'top' ? 40 : 24,
|
|
539
859
|
bottom: legendShown(multi) && config.legend !== 'top' ? 32 : 8,
|
|
540
860
|
});
|
|
@@ -549,12 +869,16 @@ export function buildChartOption(
|
|
|
549
869
|
type: 'gauge',
|
|
550
870
|
min: config.min ?? 0,
|
|
551
871
|
max: config.max ?? 100,
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
872
|
+
// 组件卡 ChartCommon §6:轨宽 10、圆端、刻度与分割线默认隐藏(ECharts 默认带分割线与刻度,kit 取进度环形简化版)
|
|
873
|
+
// 底轨 = 凹陷面角色的整圈;进度 = 圆端弧,阈值只改进度色;不画指针与锚点(组件卡 ChartCommon §6 仪表盘)
|
|
874
|
+
axisLine: { roundCap: true, lineStyle: { width: CHART_STYLE.gaugeWidth, color: [[1, theme.track ?? theme.grid]] } },
|
|
875
|
+
progress: { show: true, roundCap: true, width: CHART_STYLE.gaugeWidth, itemStyle: { color: gaugeValueColor(config, theme, value) } },
|
|
876
|
+
axisLabel: { show: false },
|
|
877
|
+
axisTick: { show: false },
|
|
878
|
+
splitLine: { show: false },
|
|
879
|
+
pointer: { show: false },
|
|
880
|
+
anchor: { show: false },
|
|
881
|
+
title: { color: theme.text, offsetCenter: ['0%', '40%'] },
|
|
558
882
|
detail: { color: theme.text, valueAnimation: false, ...(valueTemplate !== undefined ? { formatter: valueTemplate } : {}) },
|
|
559
883
|
data: [{ name: label(first[xKey]), value }],
|
|
560
884
|
}],
|
|
@@ -573,13 +897,65 @@ export function buildChartOption(
|
|
|
573
897
|
sort: 'none',
|
|
574
898
|
left: '10%',
|
|
575
899
|
width: '80%',
|
|
900
|
+
// 取值:片间 2px 缝、最小片 10%、标签外置带 20px 引线(共用取值 05 漏斗图:ECharts funnel 默认 / G2 Funnel)
|
|
901
|
+
gap: CHART_STYLE.funnelGap,
|
|
902
|
+
minSize: `${CHART_STYLE.funnelMinSizePct}%`,
|
|
903
|
+
labelLine: { show: true, length: CHART_STYLE.funnelLabelLineLength, lineStyle: { color: theme.grid, width: CHART_STYLE.gridLineWidth } },
|
|
576
904
|
data: rows.map((r) => ({ name: label(r[xKey]), value: numeric(r[yKey]) })),
|
|
577
905
|
label: { color: theme.text, ...(labelTemplate !== undefined ? { formatter: labelTemplate } : {}) },
|
|
578
906
|
}],
|
|
579
907
|
};
|
|
580
908
|
}
|
|
581
909
|
|
|
582
|
-
if (config.type === '
|
|
910
|
+
if (config.type === 'bullet') {
|
|
911
|
+
// 子弹图:x = 名称,y[0] = 实际值(窄横条),y[1] = 目标值(竖向方块刻度);横向条、名称在纵轴、自上而下
|
|
912
|
+
const names = rows.map((r) => label(r[xKey]));
|
|
913
|
+
const actualKey = src(config.y[0]!);
|
|
914
|
+
const targetKey = src(config.y[1]!);
|
|
915
|
+
const [markW, markH] = CHART_STYLE.bulletTargetSize;
|
|
916
|
+
return {
|
|
917
|
+
color: theme.palette,
|
|
918
|
+
textStyle: { color: theme.text },
|
|
919
|
+
grid: gridFor(false),
|
|
920
|
+
xAxis: { type: 'value', ...valueAxisStyle(false) },
|
|
921
|
+
yAxis: { type: 'category', data: names, inverse: true, ...categoryAxisStyle },
|
|
922
|
+
series: [
|
|
923
|
+
{ type: 'bar', name: config.y[0]!, barWidth: `${CHART_STYLE.bulletBarPct}%`, data: rows.map((r) => numeric(r[actualKey])) },
|
|
924
|
+
{
|
|
925
|
+
type: 'scatter', name: config.y[1]!, symbol: 'rect', symbolSize: [markW, markH], z: 3,
|
|
926
|
+
itemStyle: { color: theme.text },
|
|
927
|
+
data: rows.map((r, i) => [numeric(r[targetKey]), i]),
|
|
928
|
+
},
|
|
929
|
+
],
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
if (config.type === 'network') {
|
|
934
|
+
// 关系网络:每行一条边,x = 起点,y[0] = 终点,value 字段(可选)= 边权;节点由边两端去重,力导向布局
|
|
935
|
+
const weightKey = src(config.value ?? '');
|
|
936
|
+
const edges = rows
|
|
937
|
+
.map((r) => ({ source: label(r[xKey]), target: label(r[src(config.y[0]!)]), value: weightKey === '' ? 1 : numeric(r[weightKey]) }))
|
|
938
|
+
.filter((l) => l.source !== '' && l.target !== '' && l.source !== l.target);
|
|
939
|
+
const names: string[] = [];
|
|
940
|
+
for (const l of edges) for (const n of [l.source, l.target]) if (!names.includes(n)) names.push(n);
|
|
941
|
+
return {
|
|
942
|
+
color: theme.palette,
|
|
943
|
+
textStyle: { color: theme.text },
|
|
944
|
+
series: [{
|
|
945
|
+
type: 'graph',
|
|
946
|
+
layout: 'force',
|
|
947
|
+
roam: false,
|
|
948
|
+
symbolSize: CHART_STYLE.networkNodeSize,
|
|
949
|
+
force: { repulsion: CHART_STYLE.networkRepulsion },
|
|
950
|
+
data: names.map((name) => ({ name })),
|
|
951
|
+
links: edges,
|
|
952
|
+
label: { show: true, position: 'right', color: theme.text },
|
|
953
|
+
lineStyle: { color: theme.grid, width: CHART_STYLE.lineWidth, curveness: 0 },
|
|
954
|
+
}],
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
if (config.type === 'pie' || config.type === 'donut' || config.type === 'rose') {
|
|
583
959
|
const yKey = src(config.y[0]!);
|
|
584
960
|
return {
|
|
585
961
|
color: theme.palette,
|
|
@@ -587,7 +963,9 @@ export function buildChartOption(
|
|
|
587
963
|
legend: legendOf(true),
|
|
588
964
|
series: [{
|
|
589
965
|
type: 'pie',
|
|
590
|
-
|
|
966
|
+
// rose = 南丁格尔玫瑰(半径编码数值,内缘留小孔);donut = 环;pie = 实心
|
|
967
|
+
...(config.type === 'rose' ? { roseType: 'radius' } : {}),
|
|
968
|
+
radius: config.type === 'rose' ? [`${CHART_STYLE.roseInnerPct}%`, `${CHART_STYLE.roseOuterPct}%`] : config.type === 'donut' ? ['40%', '65%'] : '60%',
|
|
591
969
|
data: rows.map((r) => ({ name: label(r[xKey]), value: numeric(r[yKey]) })),
|
|
592
970
|
label: { color: theme.text, ...(labelTemplate !== undefined ? { formatter: labelTemplate } : {}) },
|
|
593
971
|
}],
|
|
@@ -596,11 +974,6 @@ export function buildChartOption(
|
|
|
596
974
|
|
|
597
975
|
const yKeys = config.y.map(src);
|
|
598
976
|
const valueKey = src(config.value ?? '');
|
|
599
|
-
const axisStyle = {
|
|
600
|
-
axisLine: { lineStyle: { color: theme.line } },
|
|
601
|
-
axisLabel: { color: theme.text },
|
|
602
|
-
splitLine: { lineStyle: { color: theme.line } },
|
|
603
|
-
};
|
|
604
977
|
const gridBox = { left: 8, right: 8, top: 24, bottom: 8, containLabel: true };
|
|
605
978
|
|
|
606
979
|
if (config.type === 'scatter') {
|
|
@@ -609,8 +982,9 @@ export function buildChartOption(
|
|
|
609
982
|
textStyle: { color: theme.text },
|
|
610
983
|
grid: gridFor(config.y.length > 1),
|
|
611
984
|
legend: legendOf(config.y.length > 1),
|
|
612
|
-
|
|
613
|
-
|
|
985
|
+
// 散点两轴都是数值轴:横轴不带单位名(单位描述纵轴的数值)
|
|
986
|
+
xAxis: { type: 'value', ...valueAxisStyle(false) },
|
|
987
|
+
yAxis: { type: 'value', ...valueAxisStyle(true) },
|
|
614
988
|
series: config.y.map((y, i) => ({
|
|
615
989
|
type: 'scatter',
|
|
616
990
|
name: y,
|
|
@@ -629,12 +1003,12 @@ export function buildChartOption(
|
|
|
629
1003
|
return {
|
|
630
1004
|
color: theme.palette,
|
|
631
1005
|
textStyle: { color: theme.text },
|
|
632
|
-
legend: config.y.length > 1 ? { bottom: 0, textStyle:
|
|
1006
|
+
legend: config.y.length > 1 ? { bottom: 0, textStyle: tickText } : undefined,
|
|
633
1007
|
radar: {
|
|
634
1008
|
indicator,
|
|
635
|
-
axisName:
|
|
636
|
-
axisLine: { lineStyle: { color: theme.
|
|
637
|
-
splitLine: { lineStyle: { color: theme.
|
|
1009
|
+
axisName: tickText,
|
|
1010
|
+
axisLine: { lineStyle: { color: theme.grid } },
|
|
1011
|
+
splitLine: { lineStyle: { color: theme.grid } },
|
|
638
1012
|
},
|
|
639
1013
|
series: [{
|
|
640
1014
|
type: 'radar',
|
|
@@ -655,11 +1029,16 @@ export function buildChartOption(
|
|
|
655
1029
|
}
|
|
656
1030
|
const cells = rows.map((r) => [xs.indexOf(label(r[xKey])), ys.indexOf(label(r[yKeys[0]!])), numeric(r[valueKey])]);
|
|
657
1031
|
const values = cells.map((c) => c[2]!);
|
|
1032
|
+
const isDiverging = config.scale === 'diverging'
|
|
1033
|
+
|| (config.scale !== 'sequential' && values.some((v) => v < 0) && values.some((v) => v > 0));
|
|
1034
|
+
const ramp = isDiverging
|
|
1035
|
+
? (theme.divRamp && theme.divRamp.length > 0 ? theme.divRamp : undefined)
|
|
1036
|
+
: (theme.seqRamp && theme.seqRamp.length > 0 ? theme.seqRamp : undefined);
|
|
658
1037
|
return {
|
|
659
1038
|
textStyle: { color: theme.text },
|
|
660
1039
|
grid: { left: 8, right: 8, top: 16, bottom: 48, containLabel: true },
|
|
661
|
-
xAxis: { type: 'category', data: xs, splitArea: { show: false }, ...
|
|
662
|
-
yAxis: { type: 'category', data: ys, ...
|
|
1040
|
+
xAxis: { type: 'category', data: xs, splitArea: { show: false }, ...categoryAxisStyle },
|
|
1041
|
+
yAxis: { type: 'category', data: ys, ...categoryAxisStyle },
|
|
663
1042
|
visualMap: {
|
|
664
1043
|
min: Math.min(...values, 0),
|
|
665
1044
|
max: Math.max(...values, 1),
|
|
@@ -668,7 +1047,7 @@ export function buildChartOption(
|
|
|
668
1047
|
left: 'center',
|
|
669
1048
|
bottom: 0,
|
|
670
1049
|
textStyle: { color: theme.text },
|
|
671
|
-
inRange: { color: [theme.
|
|
1050
|
+
inRange: { color: ramp ?? [theme.grid, theme.palette[0] ?? theme.text] },
|
|
672
1051
|
},
|
|
673
1052
|
series: [{ type: 'heatmap', data: cells }],
|
|
674
1053
|
};
|
|
@@ -681,9 +1060,20 @@ export function buildChartOption(
|
|
|
681
1060
|
color: theme.palette,
|
|
682
1061
|
textStyle: { color: theme.text },
|
|
683
1062
|
grid: gridBox,
|
|
684
|
-
xAxis: { type: 'category', data: rows.map((r) => label(r[xKey])), ...
|
|
685
|
-
yAxis: { type: 'value', scale: true, ...
|
|
686
|
-
series: [{
|
|
1063
|
+
xAxis: { type: 'category', data: rows.map((r) => label(r[xKey])), ...categoryAxisStyle },
|
|
1064
|
+
yAxis: { type: 'value', scale: true, ...valueAxisStyle(true) },
|
|
1065
|
+
series: [{
|
|
1066
|
+
type: config.type,
|
|
1067
|
+
data: rows.map((r) => yKeys.slice(0, width).map((k) => numeric(r[k]))),
|
|
1068
|
+
// K 线涨跌色走语义令牌(不用引擎内置红绿);up_is: bad 反转
|
|
1069
|
+
...(config.type === 'candlestick' ? (() => {
|
|
1070
|
+
const good = theme.ok ?? theme.palette[0] ?? theme.text;
|
|
1071
|
+
const bad = theme.danger ?? theme.palette[2] ?? theme.text;
|
|
1072
|
+
const rise = config.upIs === 'bad' ? bad : good;
|
|
1073
|
+
const fall = config.upIs === 'bad' ? good : bad;
|
|
1074
|
+
return { itemStyle: { color: rise, color0: fall, borderColor: rise, borderColor0: fall } };
|
|
1075
|
+
})() : {}),
|
|
1076
|
+
}],
|
|
687
1077
|
};
|
|
688
1078
|
}
|
|
689
1079
|
|
|
@@ -729,9 +1119,15 @@ export function buildChartOption(
|
|
|
729
1119
|
const plainYs = [...basicYs.filter((y) => toneOfRole(y) === null), ...basicYs.filter((y) => toneOfRole(y) !== null)];
|
|
730
1120
|
const idealYs = config.y.filter(isIdeal);
|
|
731
1121
|
const projectionYs = config.y.filter(isProjection);
|
|
732
|
-
const projectionName = (y: string): string =>
|
|
1122
|
+
const projectionName = (y: string): string => appendRoleSuffix(y, theme.projectionSuffix ?? '');
|
|
733
1123
|
/** 空值(null / undefined / 非数)保持 null:引擎据此断线留白,不补零不插值 */
|
|
734
1124
|
const cell = (r: Record<string, unknown>, key: string): number | null => num(r[key]);
|
|
1125
|
+
// 面积渐变:自系列色顶部 areaTopOpacity 渐到底部 areaBottomOpacity(共用取值 05:0.4 → 0);色非 #rrggbb 时退回平填 areaOpacity
|
|
1126
|
+
const areaGradient = (color: string): Record<string, unknown> => {
|
|
1127
|
+
if (!/^#[0-9a-f]{6}$/i.test(color)) return { opacity: CHART_STYLE.areaOpacity };
|
|
1128
|
+
const alpha = (a: number): string => `${color}${Math.round(a * 255).toString(16).padStart(2, '0')}`;
|
|
1129
|
+
return { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: alpha(CHART_STYLE.areaTopOpacity) }, { offset: 1, color: alpha(CHART_STYLE.areaBottomOpacity) }] } };
|
|
1130
|
+
};
|
|
735
1131
|
const idealSeries = idealYs.map((y) => {
|
|
736
1132
|
const key = src(y);
|
|
737
1133
|
const color = theme.ideal ?? theme.text;
|
|
@@ -776,7 +1172,7 @@ export function buildChartOption(
|
|
|
776
1172
|
...(seriesType === 'line' ? { connectNulls: false } : {}),
|
|
777
1173
|
...(seriesType === 'bar' && theme.barRatioPct !== undefined ? { barCategoryGap: `${Math.max(0, 100 - theme.barRatioPct)}%` } : {}),
|
|
778
1174
|
...(seriesType === 'line' ? { lineStyle: { width: CHART_STYLE.lineWidth }, symbolSize: CHART_STYLE.symbolSize } : {}),
|
|
779
|
-
...(config.type === 'area' ? { areaStyle:
|
|
1175
|
+
...(config.type === 'area' ? { areaStyle: areaGradient(toneOfRole(y) !== null ? toneColor(toneOfRole(y) as VizTone) : theme.palette[i % Math.max(1, theme.palette.length)] ?? theme.text) } : {}),
|
|
780
1176
|
...(config.stack && (!combo || seriesType === 'bar') ? { stack: 'total' } : {}),
|
|
781
1177
|
...(combo && y2Set.has(y) ? { yAxisIndex: 1 } : {}),
|
|
782
1178
|
...(toneOfRole(y) !== null ? (() => { const c = toneColor(toneOfRole(y) as VizTone); return { color: c, itemStyle: { color: c } }; })() : {}),
|
|
@@ -807,21 +1203,23 @@ export function buildChartOption(
|
|
|
807
1203
|
],
|
|
808
1204
|
}
|
|
809
1205
|
: legend;
|
|
810
|
-
|
|
1206
|
+
// 单位名只挂主纵轴(左);组合图右侧第二纵轴不重复、也不画第二套网格
|
|
1207
|
+
const valueAxis = (extra: Record<string, unknown> = {}, withUnit = true): Record<string, unknown> => ({
|
|
811
1208
|
type: 'value',
|
|
812
|
-
|
|
813
|
-
axisLabel: { color: theme.text, ...(valueTemplate !== undefined ? { formatter: valueTemplate } : {}) },
|
|
1209
|
+
...valueAxisStyle(withUnit),
|
|
814
1210
|
...extra,
|
|
815
1211
|
});
|
|
1212
|
+
// 横网格条数上限:引擎的 splitNumber 只是提示(数据最大 32 时它取步长 5、画 8 条),主纵轴按数据跨度直接给好数步长,保证 ≤ gridMaxLines 条
|
|
1213
|
+
const primaryAxis = gridAxisOf(series.filter((s) => (s as { yAxisIndex?: number }).yAxisIndex !== 1), CHART_STYLE.gridMaxLines);
|
|
816
1214
|
return {
|
|
817
1215
|
color: theme.palette,
|
|
818
1216
|
textStyle: { color: theme.text },
|
|
819
1217
|
grid: gridFor(config.y.length > 1),
|
|
820
1218
|
legend: legendWithIdeal,
|
|
821
|
-
xAxis: { type: 'category', data: cats,
|
|
1219
|
+
xAxis: { type: 'category', data: cats, ...categoryAxisStyle },
|
|
822
1220
|
yAxis: combo && y2Set.size > 0
|
|
823
|
-
? [valueAxis(), valueAxis({ position: 'right', splitLine: { show: false } })]
|
|
824
|
-
: valueAxis(),
|
|
1221
|
+
? [valueAxis(primaryAxis ?? {}), valueAxis({ position: 'right', splitLine: { show: false } }, false)]
|
|
1222
|
+
: valueAxis(primaryAxis ?? {}),
|
|
825
1223
|
series,
|
|
826
1224
|
};
|
|
827
1225
|
}
|
|
@@ -835,6 +1233,7 @@ const CHART_TYPE_TEXT: Readonly<Record<KitChartType, KitTextKey>> = Object.freez
|
|
|
835
1233
|
radar: 'soma.kit.chart_type_radar', heatmap: 'soma.kit.chart_type_heatmap', boxplot: 'soma.kit.chart_type_boxplot',
|
|
836
1234
|
candlestick: 'soma.kit.chart_type_candlestick', sankey: 'soma.kit.chart_type_sankey', treemap: 'soma.kit.chart_type_treemap',
|
|
837
1235
|
sunburst: 'soma.kit.chart_type_sunburst', chord: 'soma.kit.chart_type_chord',
|
|
1236
|
+
rose: 'soma.kit.chart_type_rose', network: 'soma.kit.chart_type_network', bullet: 'soma.kit.chart_type_bullet',
|
|
838
1237
|
});
|
|
839
1238
|
|
|
840
1239
|
/** 系列数:直角坐标 / 雷达按 y 字段数,其余图型(扇区、阶段、单值、层级、连线)都是一个系列;箱线 / K 线的 y 是同一系列的五 / 四个统计量 */
|
|
@@ -885,12 +1284,14 @@ export function chartAltOf(
|
|
|
885
1284
|
}
|
|
886
1285
|
}
|
|
887
1286
|
const withNotes = noteByRow.size > 0;
|
|
1287
|
+
const idealSuffix = kitText('soma.kit.chart_ideal', { name: '' }, at);
|
|
1288
|
+
const projSuffix = kitText('soma.kit.chart_projection', { name: '' }, at);
|
|
888
1289
|
return {
|
|
889
1290
|
label,
|
|
890
|
-
// 理想线 / 预测线的表头标注;空值(null /
|
|
1291
|
+
// 理想线 / 预测线的表头标注;空值(null / 缺值)单元格为空串(字段名已含角色词时不拼成「预测(预测)」)
|
|
891
1292
|
columns: [
|
|
892
|
-
...fields.map((f) => (config.roles?.[f] === 'ideal' ?
|
|
893
|
-
: config.roles?.[f] === 'projection' ?
|
|
1293
|
+
...fields.map((f) => (config.roles?.[f] === 'ideal' ? appendRoleSuffix(f, idealSuffix)
|
|
1294
|
+
: config.roles?.[f] === 'projection' ? appendRoleSuffix(f, projSuffix) : f)),
|
|
894
1295
|
...(withNotes ? [kitText('soma.kit.chart_marks_col', undefined, at)] : []),
|
|
895
1296
|
],
|
|
896
1297
|
rows: shown.slice(0, cap).map((r, i) => [...fields.map((f) => cell(r[src(f)])), ...(withNotes ? [(noteByRow.get(i) ?? []).join('、')] : [])]),
|
|
@@ -907,7 +1308,150 @@ interface ChartInstanceLike {
|
|
|
907
1308
|
dispose(): void;
|
|
908
1309
|
highlight?(p: { seriesIndex: number; dataIndex: number } | null): void;
|
|
909
1310
|
onColumn?(handler: (kind: 'hover' | 'click' | 'leave', col: { dataIndex: number } | null) => void): () => void;
|
|
910
|
-
onPointer?(handler: (kind: 'hover' | 'click' | 'leave', p: { dataIndex: number } | null) => void): () => void;
|
|
1311
|
+
onPointer?(handler: (kind: 'hover' | 'click' | 'leave', p: { dataIndex: number; seriesIndex?: number } | null) => void): () => void;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
export interface KitChartSwatch {
|
|
1315
|
+
bgCls: string;
|
|
1316
|
+
color: string | undefined;
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
* 解析系列或槽位在图中的真实色标(背景工具类 + 运行期实色),与 buildChartOptionCore 100% 同构:
|
|
1321
|
+
* - ideal / baseline 角色 -> 中性弱化色(不占序列调色板槽位);
|
|
1322
|
+
* - projection 角色 -> 与第 0 槽同色(不占序列调色板槽位);
|
|
1323
|
+
* - ok / caution / overload 等语义角色 -> 对应语义色(排在无角色普通系列之后,不挤占普通系列的调色板槽位);
|
|
1324
|
+
* - 普通无角色系列 -> 按其在无角色普通系列中的真实槽位取 orderedBg[slot] 与 theme.palette[slot]。
|
|
1325
|
+
*/
|
|
1326
|
+
export function chartSeriesSwatchOf(
|
|
1327
|
+
config: KitChartConfig,
|
|
1328
|
+
theme: KitChartTheme,
|
|
1329
|
+
orderedTokens: readonly string[],
|
|
1330
|
+
field: string,
|
|
1331
|
+
mapRaw?: unknown,
|
|
1332
|
+
): KitChartSwatch {
|
|
1333
|
+
const orderedBg = orderedTokens.map((tok) => {
|
|
1334
|
+
const idx = KIT_CHART_SERIES_TOKENS.indexOf(tok);
|
|
1335
|
+
return SERIES_BG[idx >= 0 ? idx : 0]!;
|
|
1336
|
+
});
|
|
1337
|
+
const palette = theme.palette;
|
|
1338
|
+
const slotSwatch = (slot: number): KitChartSwatch => {
|
|
1339
|
+
const bgLen = Math.max(1, orderedBg.length);
|
|
1340
|
+
const safeBg = ((slot % bgLen) + bgLen) % bgLen;
|
|
1341
|
+
const palLen = Math.max(1, palette.length);
|
|
1342
|
+
const safePal = ((slot % palLen) + palLen) % palLen;
|
|
1343
|
+
return {
|
|
1344
|
+
bgCls: orderedBg[safeBg] ?? SERIES_BG[safeBg % SERIES_BG.length]!,
|
|
1345
|
+
color: palette.length > 0 ? palette[safePal] : undefined,
|
|
1346
|
+
};
|
|
1347
|
+
};
|
|
1348
|
+
const map = recOf(mapRaw);
|
|
1349
|
+
const src = (k: string): string => (typeof map[k] === 'string' && map[k] !== '' ? String(map[k]) : k);
|
|
1350
|
+
const matchedY = config.y.find((y) => y === field || src(y) === src(field)) ?? field;
|
|
1351
|
+
if (config.type === 'bullet' && config.y[1] !== undefined && matchedY === config.y[1]) {
|
|
1352
|
+
return { bgCls: TONE_BG.neutral, color: theme.text };
|
|
1353
|
+
}
|
|
1354
|
+
const role = config.roles?.[matchedY];
|
|
1355
|
+
if (role === 'ideal' || role === 'baseline') {
|
|
1356
|
+
return { bgCls: TONE_BG.neutral, color: theme.ideal ?? theme.text };
|
|
1357
|
+
}
|
|
1358
|
+
if (role === 'projection') {
|
|
1359
|
+
return slotSwatch(0);
|
|
1360
|
+
}
|
|
1361
|
+
const roleTone = role !== undefined ? (SERIES_TONE_ROLES[role] ?? null) : null;
|
|
1362
|
+
if (roleTone !== null) {
|
|
1363
|
+
if (roleTone === 'success') return { bgCls: TONE_BG.success, color: theme.ok ?? palette[0] ?? theme.text };
|
|
1364
|
+
if (roleTone === 'warning') return { bgCls: TONE_BG.warning, color: theme.warn ?? palette[1] ?? theme.text };
|
|
1365
|
+
if (roleTone === 'danger') return { bgCls: TONE_BG.danger, color: theme.danger ?? palette[2] ?? theme.text };
|
|
1366
|
+
if (roleTone === 'primary') return { bgCls: TONE_BG.primary, color: theme.primary ?? palette[0] ?? theme.text };
|
|
1367
|
+
if (roleTone === 'info') return { bgCls: TONE_BG.info, color: theme.primary ?? palette[0] ?? theme.text };
|
|
1368
|
+
return { bgCls: TONE_BG.neutral, color: theme.ideal ?? theme.text };
|
|
1369
|
+
}
|
|
1370
|
+
const isRefRole = (y: string): boolean => {
|
|
1371
|
+
const r = config.roles?.[y];
|
|
1372
|
+
return r === 'ideal' || r === 'baseline' || r === 'projection';
|
|
1373
|
+
};
|
|
1374
|
+
const hasSemanticTone = (y: string): boolean => (SERIES_TONE_ROLES[config.roles?.[y] ?? ''] ?? null) !== null;
|
|
1375
|
+
const plainUnroled = config.y.filter((y) => !isRefRole(y) && !hasSemanticTone(y));
|
|
1376
|
+
const slot = plainUnroled.indexOf(matchedY);
|
|
1377
|
+
if (slot >= 0) return slotSwatch(slot);
|
|
1378
|
+
return { bgCls: TONE_BG.neutral, color: theme.ideal ?? theme.text };
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
/** 计算选项结构签名:图表类型、图例显隐、纵轴数与系列集合一致时可安全走 'merge',保留用户已点击隐藏的图例开关态 */
|
|
1382
|
+
function optionMergeSignatureOf(config: KitChartConfig, option: Record<string, unknown>): string {
|
|
1383
|
+
const seriesSig = Array.isArray(option.series)
|
|
1384
|
+
? option.series.map((s) => {
|
|
1385
|
+
if (s === null || typeof s !== 'object') return '';
|
|
1386
|
+
const item = s as Record<string, unknown>;
|
|
1387
|
+
const ml = item.markLine !== undefined ? '1' : '0';
|
|
1388
|
+
const ma = item.markArea !== undefined ? '1' : '0';
|
|
1389
|
+
const mp = item.markPoint !== undefined ? '1' : '0';
|
|
1390
|
+
return `${String(item.type ?? '')}:${String(item.name ?? '')}:${String(item.stack ?? '')}:${String(item.yAxisIndex ?? 0)}:${ml}${ma}${mp}`;
|
|
1391
|
+
}).join('|')
|
|
1392
|
+
: '';
|
|
1393
|
+
const legendSig = option.legend !== undefined ? `1:${config.legend ?? 'auto'}` : '0';
|
|
1394
|
+
const yAxisSig = Array.isArray(option.yAxis) ? String(option.yAxis.length) : option.yAxis !== undefined ? '1' : '0';
|
|
1395
|
+
return `${config.type}::${legendSig}::${yAxisSig}::${seriesSig}`;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
function fmtTipShare(part: number, total: number): string {
|
|
1399
|
+
if (!Number.isFinite(part) || !Number.isFinite(total) || total <= 0) return '';
|
|
1400
|
+
const pct = cleanSummaryFloat((Math.max(0, part) / total) * 100);
|
|
1401
|
+
const rounded = Number((Math.round((pct + Number.EPSILON) * 10) / 10).toFixed(1));
|
|
1402
|
+
return `${Object.is(rounded, -0) ? 0 : rounded}%`;
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
/** 为非直角坐标图型的 SVG 图元补齐数据项提示委托属性(兼容无像素布局环境下的 DOM 事件悬停委托) */
|
|
1406
|
+
function annotateStageSvgItems(
|
|
1407
|
+
stageEl: HTMLElement | null,
|
|
1408
|
+
config: KitChartConfig,
|
|
1409
|
+
rows: ReadonlyArray<Record<string, unknown>>,
|
|
1410
|
+
): void {
|
|
1411
|
+
if (!stageEl || KIT_CHART_COLUMN_TYPES.has(config.type) || rows.length === 0) return;
|
|
1412
|
+
const svg = stageEl.querySelector('svg');
|
|
1413
|
+
if (!svg) return;
|
|
1414
|
+
const allShapes = Array.from(svg.querySelectorAll('path, circle, rect, polygon')).filter((el) => {
|
|
1415
|
+
if (el.closest('defs') !== null) return false;
|
|
1416
|
+
const fill = (el.getAttribute('fill') ?? '').trim().toLowerCase();
|
|
1417
|
+
return fill !== 'none' && fill !== 'transparent' && !/\b0\s*\)$/.test(fill);
|
|
1418
|
+
});
|
|
1419
|
+
if (config.type === 'pie' || config.type === 'donut' || config.type === 'rose') {
|
|
1420
|
+
const sectors = allShapes.filter((el) => {
|
|
1421
|
+
const d = el.getAttribute('d') ?? '';
|
|
1422
|
+
const arc = /A\s*(\d+(?:\.\d+)?)/i.exec(d);
|
|
1423
|
+
return arc !== null && Number.parseFloat(arc[1]!) > 5;
|
|
1424
|
+
});
|
|
1425
|
+
sectors.slice(0, rows.length).forEach((el, i) => el.setAttribute(KIT_CHART_ITEM_ATTR, String(i)));
|
|
1426
|
+
return;
|
|
1427
|
+
}
|
|
1428
|
+
if (config.type === 'funnel' || config.type === 'heatmap' || config.type === 'treemap' || config.type === 'sunburst') {
|
|
1429
|
+
const polys = allShapes.filter((el) => el.tagName.toLowerCase() !== 'path' || !/[Aa]/.test(el.getAttribute('d') ?? ''));
|
|
1430
|
+
polys.slice(0, rows.length).forEach((el, i) => el.setAttribute(KIT_CHART_ITEM_ATTR, String(i)));
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1433
|
+
if (config.type === 'scatter') {
|
|
1434
|
+
const dots = allShapes.filter((el) => {
|
|
1435
|
+
if (el.tagName.toLowerCase() === 'circle') return true;
|
|
1436
|
+
const d = el.getAttribute('d') ?? '';
|
|
1437
|
+
return /[Aa]/.test(d) && !/[LlHhVv]/.test(d);
|
|
1438
|
+
});
|
|
1439
|
+
dots.slice(0, rows.length * config.y.length).forEach((el, idx) => {
|
|
1440
|
+
el.setAttribute(KIT_CHART_ITEM_ATTR, String(idx % rows.length));
|
|
1441
|
+
el.setAttribute(KIT_ATTR_CHART_SERIES, String(Math.floor(idx / rows.length)));
|
|
1442
|
+
});
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
if (config.type === 'radar') {
|
|
1446
|
+
const dots = allShapes.filter((el) => {
|
|
1447
|
+
if (el.tagName.toLowerCase() === 'circle') return true;
|
|
1448
|
+
const d = el.getAttribute('d') ?? '';
|
|
1449
|
+
return /[Aa]/.test(d) && !/[LlHhVv]/.test(d);
|
|
1450
|
+
});
|
|
1451
|
+
dots.slice(0, rows.length * config.y.length).forEach((el, idx) => {
|
|
1452
|
+
el.setAttribute(KIT_CHART_ITEM_ATTR, String(Math.floor(idx / rows.length)));
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
911
1455
|
}
|
|
912
1456
|
|
|
913
1457
|
interface ChartEnginePort {
|
|
@@ -916,8 +1460,8 @@ interface ChartEnginePort {
|
|
|
916
1460
|
}
|
|
917
1461
|
|
|
918
1462
|
/** 把 --soma-* 令牌解析成运行期颜色值:直接读宿主的计算样式,源码不出现裸色值,也不写内联样式 */
|
|
919
|
-
function resolveToken(host: HTMLElement, token: string): string {
|
|
920
|
-
const value =
|
|
1463
|
+
function resolveToken(host: HTMLElement, token: string, dark = isDarkColorScheme(host)): string {
|
|
1464
|
+
const value = readComputedToken(host, token, dark);
|
|
921
1465
|
return value === '' ? `var(${token})` : value;
|
|
922
1466
|
}
|
|
923
1467
|
|
|
@@ -928,25 +1472,72 @@ function pctToken(host: HTMLElement, token: string): number | null {
|
|
|
928
1472
|
return Number.isFinite(n) ? n : null;
|
|
929
1473
|
}
|
|
930
1474
|
|
|
1475
|
+
/**
|
|
1476
|
+
* 系列令牌的取用顺序:页面样式在图表宿主上写的 --kit-chart-order(编译期按分类色自动序列求出,theme/theme-tokens#kitChartOrderCss——
|
|
1477
|
+
* 系列色与同页分类标签同名同色);没写或不合法时按 1…8 原序。
|
|
1478
|
+
*/
|
|
1479
|
+
export function chartSeriesTokensOf(host: HTMLElement): readonly string[] {
|
|
1480
|
+
const raw = typeof getComputedStyle === 'function' ? getComputedStyle(host).getPropertyValue('--kit-chart-order').trim() : '';
|
|
1481
|
+
const order = raw.split(/\s+/).map(Number).filter((n) => Number.isInteger(n) && n >= 1 && n <= KIT_CHART_SERIES_TOKENS.length);
|
|
1482
|
+
if (order.length === 0) return KIT_CHART_SERIES_TOKENS;
|
|
1483
|
+
const seen = [...new Set(order)];
|
|
1484
|
+
for (let i = 1; i <= KIT_CHART_SERIES_TOKENS.length; i += 1) if (!seen.includes(i)) seen.push(i);
|
|
1485
|
+
return seen.map((i) => KIT_CHART_SERIES_TOKENS[i - 1]!);
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
export const KIT_CHART_SEQ_TOKENS: readonly string[] = Object.freeze(
|
|
1489
|
+
Array.from({ length: 10 }, (_, i) => `--soma-chart-seq-${i + 1}`),
|
|
1490
|
+
);
|
|
1491
|
+
export const KIT_CHART_DIV_TOKENS: readonly string[] = Object.freeze(
|
|
1492
|
+
Array.from({ length: 17 }, (_, i) => `--soma-chart-div-${i + 1}`),
|
|
1493
|
+
);
|
|
1494
|
+
|
|
1495
|
+
function readComputedToken(host: HTMLElement, token: string, dark = isDarkColorScheme(host)): string {
|
|
1496
|
+
const view = host.ownerDocument?.defaultView;
|
|
1497
|
+
const raw = view && typeof view.getComputedStyle === 'function'
|
|
1498
|
+
? view.getComputedStyle(host).getPropertyValue(token).trim()
|
|
1499
|
+
: (typeof getComputedStyle === 'function' ? getComputedStyle(host).getPropertyValue(token).trim() : '');
|
|
1500
|
+
return raw === '' ? '' : unwrapLightDark(raw, dark);
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
function readTokenRamp(host: HTMLElement, tokens: readonly string[], dark = isDarkColorScheme(host)): string[] | undefined {
|
|
1504
|
+
const vals = tokens.map((t) => readComputedToken(host, t, dark));
|
|
1505
|
+
return vals.every((v) => v !== '') ? vals : undefined;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
931
1508
|
function themeOf(host: HTMLElement): KitChartTheme {
|
|
932
|
-
|
|
1509
|
+
const dark = isDarkColorScheme(host);
|
|
1510
|
+
// 图表填充重量(强调级作用域重写 --soma-chart-fill-mix / --soma-chart-bar-ratio):每次绘制读(含换主题后的重绘),与系列色同一次取值
|
|
933
1511
|
const fillMix = pctToken(host, '--soma-chart-fill-mix');
|
|
934
1512
|
const barRatio = pctToken(host, '--soma-chart-bar-ratio');
|
|
935
|
-
|
|
1513
|
+
// 刻度字号 = 字阶最小档(--soma-font-size-xs,求解写成 px)
|
|
1514
|
+
const tickPx = pctToken(host, '--soma-font-size-xs');
|
|
1515
|
+
const surface = resolveToken(host, '--soma-surface-panel', dark);
|
|
1516
|
+
const idleRaw = readComputedToken(host, '--soma-chart-idle', dark);
|
|
1517
|
+
const seqRamp = readTokenRamp(host, KIT_CHART_SEQ_TOKENS, dark);
|
|
1518
|
+
const divRamp = readTokenRamp(host, KIT_CHART_DIV_TOKENS, dark);
|
|
936
1519
|
return {
|
|
937
|
-
palette:
|
|
938
|
-
const c = resolveToken(host, n);
|
|
1520
|
+
palette: chartSeriesTokensOf(host).map((n) => {
|
|
1521
|
+
const c = resolveToken(host, n, dark);
|
|
939
1522
|
return fillMix === null ? c : mixTowardSurface(c, surface, fillMix);
|
|
940
1523
|
}),
|
|
941
1524
|
...(barRatio !== null ? { barRatioPct: barRatio } : {}),
|
|
942
|
-
text: resolveToken(host, '--soma-text-secondary'),
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
1525
|
+
text: resolveToken(host, '--soma-text-secondary', dark),
|
|
1526
|
+
// 网格 / 轴是图表自己的结构色(不借分隔线发丝灰),配色方案求出十六进制实色(引擎解析不了 color-mix 字串)
|
|
1527
|
+
grid: resolveToken(host, '--soma-chart-grid', dark),
|
|
1528
|
+
axis: resolveToken(host, '--soma-chart-axis', dark),
|
|
1529
|
+
tick: resolveToken(host, '--soma-text-muted', dark),
|
|
1530
|
+
...(tickPx !== null ? { tickPx } : {}),
|
|
1531
|
+
ideal: resolveToken(host, '--soma-text-muted', dark),
|
|
1532
|
+
primary: resolveToken(host, '--soma-c-primary', dark),
|
|
1533
|
+
// Gauge 未填充底弧优先读取 --soma-chart-idle(不再借用语义成功色;无该令牌的旧 mock 环境回落 --soma-chart-idle 变量或凹陷面)
|
|
1534
|
+
track: idleRaw !== '' ? idleRaw : (readComputedToken(host, '--soma-surface-sunken', dark) || 'var(--soma-chart-idle)'),
|
|
946
1535
|
projectionSuffix: kitText('soma.kit.chart_projection', { name: '' }, host),
|
|
947
|
-
ok: resolveToken(host, '--soma-c-success'),
|
|
948
|
-
warn: resolveToken(host, '--soma-c-warning'),
|
|
949
|
-
danger: resolveToken(host, '--soma-c-danger'),
|
|
1536
|
+
ok: resolveToken(host, '--soma-c-success', dark),
|
|
1537
|
+
warn: resolveToken(host, '--soma-c-warning', dark),
|
|
1538
|
+
danger: resolveToken(host, '--soma-c-danger', dark),
|
|
1539
|
+
...(seqRamp !== undefined ? { seqRamp } : {}),
|
|
1540
|
+
...(divRamp !== undefined ? { divRamp } : {}),
|
|
950
1541
|
};
|
|
951
1542
|
}
|
|
952
1543
|
|
|
@@ -957,7 +1548,7 @@ export function createChart(): SomaComponentDefinition {
|
|
|
957
1548
|
layer: 'data',
|
|
958
1549
|
props: {
|
|
959
1550
|
data: { type: 'array', default: [], desc: '行数组' },
|
|
960
|
-
chart: { type: 'object', default: {}, desc: '图形配置 { type: line | bar | area | pie | donut | funnel | gauge | scatter | combo | radar | heatmap | boxplot | candlestick | sankey | treemap | sunburst | chord, x: 字段, y: [字段…], stack?: bool(line / area / bar / combo 的 y 项也可写 { field, role?: ideal }:ideal = 理想线,虚线中性色、不占序列配色、图例排最后;数据点 null = 断线留白,不补零不连线), min? / max? / warnAt? / dangerAt?(gauge;radar 的 max 为各指标量程上限), value?: 字段, parent?: 字段 };funnel 行序即流程顺序;gauge 取列表第一行;scatter:x 与每个 y 字段都是数值;combo:柱线组合,line: [字段…] 里的 y 画折线、其余画柱,y2: [字段…] 挂右侧第二纵轴;ref_lines: [{ value 或 stat(average|max|min|median), label?, tone?(neutral|success|warning|danger) }] 虚线参考线(直角坐标系图型);legend: auto|top|bottom|none;value_format: { prefix?, suffix? } 纵轴与标签的数值前后缀;radar:每行一个指标(x 作名)、每个 y 字段一条系列;heatmap:x / y[0] 为横纵类目、value 为格值;boxplot:y 依次为 最小 / 下四分位 / 中位 / 上四分位 / 最大;candlestick:y 依次为 开盘 / 收盘 / 最低 / 最高;sankey / chord:每行一条连线,x 来源、y[0] 去向、value 流量;treemap / sunburst:x 名称、y[0] 数值、parent 父名称(空 =
|
|
1551
|
+
chart: { type: 'object', default: {}, desc: '图形配置 { type: line | bar | area | pie | donut | funnel | gauge | scatter | combo | radar | heatmap | boxplot | candlestick | sankey | treemap | sunburst | chord | rose | network | bullet, x: 字段, y: [字段…], stack?: bool(line / area / bar / combo 的 y 项也可写 { field, role?: ideal }:ideal = 理想线,虚线中性色、不占序列配色、图例排最后;数据点 null = 断线留白,不补零不连线), min? / max? / warnAt? / dangerAt?(gauge;radar 的 max 为各指标量程上限), value?: 字段, parent?: 字段 };funnel 行序即流程顺序;gauge 取列表第一行;scatter:x 与每个 y 字段都是数值;combo:柱线组合,line: [字段…] 里的 y 画折线、其余画柱,y2: [字段…] 挂右侧第二纵轴;ref_lines: [{ value 或 stat(average|max|min|median), label?, tone?(neutral|success|warning|danger) }] 虚线参考线(直角坐标系图型);legend: auto|top|bottom|none;value_format: { prefix?, suffix? } 纵轴与标签的数值前后缀;radar:每行一个指标(x 作名)、每个 y 字段一条系列;heatmap:x / y[0] 为横纵类目、value 为格值;boxplot:y 依次为 最小 / 下四分位 / 中位 / 上四分位 / 最大;candlestick:y 依次为 开盘 / 收盘 / 最低 / 最高;sankey / chord:每行一条连线,x 来源、y[0] 去向、value 流量;treemap / sunburst:x 名称、y[0] 数值、parent 父名称(空 = 根);rose:同 pie(x 名、y[0] 值,半径编码数值);network:每行一条边,x 起点、y[0] 终点、value 边权(可选),力导向布局;bullet:x 名称、y[0] 实际值(横条)、y[1] 目标值(刻度);折线 / 面积 / 柱 / 组合另可写 marks: [{ kind: line|band|point, axis?: x|y, at? / from? / to?: 字面量或 { field }, series?, label?, role? }](竖线 / 区间带 / 标记点,取色线型由 role 决定)、readout: { place?, title?, note?, items: [{ field, label?, format?, unit? }], default? }(逐列读数区)、interact: { pick?: bool }(点击 / Enter 选中列抛 point_pick);y 项 role 另有 projection(预测线)与 ok / caution / overload(语义取色);up_is?: good | bad(K 线涨跌色反转开关:good 涨为成功色,bad 涨为危险色)' },
|
|
961
1552
|
map: { type: 'object', default: {}, desc: '键名对照:chart 里的字段名 -> 数据里的键' },
|
|
962
1553
|
empty: { type: 'string', default: '', desc: '无数据时的空态文案;缺省取内置文案(按页面语言)' },
|
|
963
1554
|
title: { type: 'string', default: '', desc: '图表标题:进可访问名(role=img)与读屏数据表标题;缺省只用「图型 + 系列数 + 数据点数」' },
|
|
@@ -979,7 +1570,7 @@ export function createChart(): SomaComponentDefinition {
|
|
|
979
1570
|
`<div data-soma-id="root" class="${ROOT_CLASS}">`
|
|
980
1571
|
+ `<div data-soma-id="stageWrap" class="hidden"><div data-soma-id="stage" class="${STAGE_CLASS}"></div></div>`
|
|
981
1572
|
+ '<div data-soma-id="altWrap" class="sr-only"></div>'
|
|
982
|
-
+ `<div data-soma-id="emptyWrap"><div data-soma-id="emptyText" class="${EMPTY_INNER_CLASS}"></div></div>`
|
|
1573
|
+
+ `<div data-soma-id="emptyWrap"><div data-soma-id="emptyGrid" class="hidden" aria-hidden="true"></div><div data-soma-id="emptyText" class="${EMPTY_INNER_CLASS}"></div></div>`
|
|
983
1574
|
+ '</div>',
|
|
984
1575
|
controllerFactory: createKitController((api) => {
|
|
985
1576
|
const P = (): Record<string, unknown> => api.props();
|
|
@@ -988,6 +1579,9 @@ export function createChart(): SomaComponentDefinition {
|
|
|
988
1579
|
let stage: HTMLElement | null = null;
|
|
989
1580
|
let emptyWrap: HTMLElement | null = null;
|
|
990
1581
|
let emptyText: HTMLElement | null = null;
|
|
1582
|
+
let emptyGrid: HTMLElement | null = null;
|
|
1583
|
+
let tipEl: HTMLElement | null = null;
|
|
1584
|
+
let pointerAt: { x: number; y: number } | null = null;
|
|
991
1585
|
let altWrap: HTMLElement | null = null;
|
|
992
1586
|
let instance: ChartInstanceLike | null = null;
|
|
993
1587
|
// 交互状态(K2 / K3):读数区 DOM、当前列、键盘漫游标记、最近一次出图的上下文(焦点带重建 option 用)
|
|
@@ -997,6 +1591,7 @@ export function createChart(): SomaComponentDefinition {
|
|
|
997
1591
|
let defaultCol = -1;
|
|
998
1592
|
let kbdActive = false;
|
|
999
1593
|
let offColumn: (() => void) | null = null;
|
|
1594
|
+
let lastOptionSig: string | null = null;
|
|
1000
1595
|
let drawn: { config: KitChartConfig; rows: Array<Record<string, unknown>>; theme: KitChartTheme; map: unknown; reduceMotion: boolean } | null = null;
|
|
1001
1596
|
let creating: Promise<void> | null = null;
|
|
1002
1597
|
let resizeObs: ResizeObserver | null = null;
|
|
@@ -1012,7 +1607,7 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1012
1607
|
revealed = true;
|
|
1013
1608
|
engineGate = null;
|
|
1014
1609
|
// 只收起加载占位;数据旁的错误提示条(keepStage 的 error 面板)保留
|
|
1015
|
-
if (emptyText?.getAttribute(
|
|
1610
|
+
if (emptyText?.getAttribute(KIT_ATTR_STATE) === 'loading' || emptyText?.getAttribute(KIT_ATTR_STATE) === null) {
|
|
1016
1611
|
emptyWrap?.classList.remove('absolute', 'inset-0');
|
|
1017
1612
|
emptyWrap?.classList.add('hidden');
|
|
1018
1613
|
}
|
|
@@ -1027,6 +1622,7 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1027
1622
|
if (!alive) return;
|
|
1028
1623
|
if (phase === 'visible' && !revealed) {
|
|
1029
1624
|
showPanel('loading', str(P().loading_text, kitText('soma.kit.loading', undefined, root ?? undefined)), {}, true);
|
|
1625
|
+
emptyWrap?.classList.remove('relative');
|
|
1030
1626
|
emptyWrap?.classList.add('absolute', 'inset-0');
|
|
1031
1627
|
} else if (phase === 'idle' && settled) reveal();
|
|
1032
1628
|
});
|
|
@@ -1043,8 +1639,9 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1043
1639
|
engineGate = null;
|
|
1044
1640
|
};
|
|
1045
1641
|
|
|
1046
|
-
//
|
|
1047
|
-
//
|
|
1642
|
+
// 主题切换:系列色 / 网格 / 轴取自运行期计算值,主题变了要重算并 setOption。
|
|
1643
|
+
// 三个来源——系统偏好 prefers-color-scheme、<html> 上 soma-scheme-dark / soma-scheme-light 类的变化,
|
|
1644
|
+
// 以及运行期换主题后的「主题已应用」事件(KIT_THEME_APPLIED_EVENT:换色族 / 对比度 / 中性灰时明暗类与媒体都不变)
|
|
1048
1645
|
let schemeOff: (() => void) | null = null;
|
|
1049
1646
|
const schemeKey = (): string => {
|
|
1050
1647
|
const cl = typeof document !== 'undefined' ? document.documentElement.classList : null;
|
|
@@ -1057,10 +1654,10 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1057
1654
|
const offs: Array<() => void> = [];
|
|
1058
1655
|
if (typeof matchMedia === 'function') {
|
|
1059
1656
|
const mq = matchMedia('(prefers-color-scheme: dark)');
|
|
1060
|
-
if (typeof mq
|
|
1657
|
+
if (typeof mq?.addEventListener === 'function') {
|
|
1061
1658
|
mq.addEventListener('change', repaint);
|
|
1062
1659
|
offs.push(() => mq.removeEventListener('change', repaint));
|
|
1063
|
-
} else if (typeof mq
|
|
1660
|
+
} else if (typeof mq?.addListener === 'function') {
|
|
1064
1661
|
mq.addListener(repaint);
|
|
1065
1662
|
offs.push(() => mq.removeListener(repaint));
|
|
1066
1663
|
}
|
|
@@ -1075,6 +1672,11 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1075
1672
|
mo.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
|
1076
1673
|
offs.push(() => mo.disconnect());
|
|
1077
1674
|
}
|
|
1675
|
+
if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
|
|
1676
|
+
const onApplied = (): void => { last = schemeKey(); repaint(); };
|
|
1677
|
+
document.addEventListener(KIT_THEME_APPLIED_EVENT, onApplied);
|
|
1678
|
+
offs.push(() => document.removeEventListener(KIT_THEME_APPLIED_EVENT, onApplied));
|
|
1679
|
+
}
|
|
1078
1680
|
schemeOff = () => { for (const off of offs) off(); };
|
|
1079
1681
|
};
|
|
1080
1682
|
const unwatchScheme = (): void => {
|
|
@@ -1089,9 +1691,43 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1089
1691
|
const showPanel = (kind: KitStateKind, text: string, o: Partial<KitStatePanelOptions> = {}, keepStage = false): void => {
|
|
1090
1692
|
if (!stageWrap || !emptyWrap || !emptyText) return;
|
|
1091
1693
|
emptyWrap.classList.remove('absolute', 'inset-0');
|
|
1694
|
+
emptyWrap.classList.add('relative');
|
|
1092
1695
|
if (keepStage) stageWrap.classList.remove('hidden'); else { stageWrap.classList.add('hidden'); clearAlt(); }
|
|
1093
1696
|
emptyWrap.classList.remove('hidden');
|
|
1697
|
+
// 空 / 加载且是直角坐标图型:保留空坐标网格,文字或骨架条叠在网格上(图区尺寸不变);其余整块面板
|
|
1698
|
+
const config = chartConfigOf(P().chart);
|
|
1699
|
+
const gridded = (kind === 'empty' || kind === 'loading') && config !== null && GRID_TYPES.has(config.type);
|
|
1700
|
+
paintGridPlace(gridded);
|
|
1701
|
+
if (!gridded) { paintKitStatePanel(emptyText, kind, { ...o, text }); return; }
|
|
1702
|
+
if (kind === 'loading') {
|
|
1703
|
+
const doc = emptyText.ownerDocument;
|
|
1704
|
+
const skeleton = doc.createElement('div');
|
|
1705
|
+
skeleton.className = GRID_SKELETON_CLASS;
|
|
1706
|
+
skeleton.setAttribute('aria-hidden', 'true');
|
|
1707
|
+
for (const cls of [KIT_SKELETON_BAR_LINE, KIT_SKELETON_BAR_LINE, KIT_SKELETON_BAR_LAST_TEXT]) {
|
|
1708
|
+
const bar = doc.createElement('div');
|
|
1709
|
+
bar.className = cls;
|
|
1710
|
+
skeleton.appendChild(bar);
|
|
1711
|
+
}
|
|
1712
|
+
paintKitStatePanel(emptyText, kind, { ...o, text, skeleton });
|
|
1713
|
+
emptyText.className = GRID_OVER_CLASS;
|
|
1714
|
+
return;
|
|
1715
|
+
}
|
|
1094
1716
|
paintKitStatePanel(emptyText, kind, { ...o, text });
|
|
1717
|
+
emptyText.className = GRID_OVER_CLASS;
|
|
1718
|
+
};
|
|
1719
|
+
/** 空坐标网格:横向发丝线 gridMaxLines 条(只在直角坐标图的空 / 加载态显示) */
|
|
1720
|
+
const paintGridPlace = (on: boolean): void => {
|
|
1721
|
+
if (!emptyGrid) return;
|
|
1722
|
+
emptyGrid.textContent = '';
|
|
1723
|
+
if (!on) { emptyGrid.className = 'hidden'; return; }
|
|
1724
|
+
emptyGrid.className = GRID_PLACE_CLASS;
|
|
1725
|
+
const doc = emptyGrid.ownerDocument;
|
|
1726
|
+
for (let i = 0; i < CHART_STYLE.gridMaxLines; i += 1) {
|
|
1727
|
+
const line = doc.createElement('div');
|
|
1728
|
+
line.className = GRID_LINE_CLASS;
|
|
1729
|
+
emptyGrid.appendChild(line);
|
|
1730
|
+
}
|
|
1095
1731
|
};
|
|
1096
1732
|
// 文字替代:只在真有图(舞台可见)时给舞台 role=img + 可访问名,并在旁边放读屏数据表;
|
|
1097
1733
|
// 空 / 加载 / 错误 / 降级面板没有图,不带 role=img。role=img 会把子孙当装饰,所以数据表是舞台的兄弟而不是子孙。
|
|
@@ -1226,18 +1862,301 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1226
1862
|
api.emit('point_pick', { index: col, x: row[xKey] === undefined || row[xKey] === null ? '' : String(row[xKey]), row });
|
|
1227
1863
|
announce(col, true);
|
|
1228
1864
|
};
|
|
1229
|
-
|
|
1865
|
+
// ── 悬停数据卡:指针悬停某一列或图元时出卡(标题 + 逐系列色块 / 名称 / 数值 / 占比),跟随指针并防边裁切;读数区保留给键盘 ──
|
|
1866
|
+
const hideTip = (): void => {
|
|
1867
|
+
if (tipEl) tipEl.className = 'hidden';
|
|
1868
|
+
};
|
|
1869
|
+
const placeTip = (): void => {
|
|
1870
|
+
if (!tipEl || !root || pointerAt === null || tipEl.classList.contains('hidden')) return;
|
|
1871
|
+
const rootRect = root.getBoundingClientRect();
|
|
1872
|
+
const roomW = root.clientWidth || Math.round(rootRect.width);
|
|
1873
|
+
const roomH = root.clientHeight || stageWrap?.clientHeight || Math.round(rootRect.height);
|
|
1874
|
+
const tipRect = tipEl.getBoundingClientRect();
|
|
1875
|
+
const w = tipEl.offsetWidth || Math.round(tipRect.width);
|
|
1876
|
+
const h = tipEl.offsetHeight || Math.round(tipRect.height);
|
|
1877
|
+
const flipX = roomW > 0 && (w > 0 ? pointerAt.x + TIP_OFFSET_PX + w > roomW : pointerAt.x > roomW - 120);
|
|
1878
|
+
const flipY = roomH > 0 && (h > 0 ? pointerAt.y + TIP_OFFSET_PX + h > roomH : pointerAt.y > roomH - 80);
|
|
1879
|
+
tipEl.classList.toggle(TIP_FLIP_X_CLASS, flipX && w === 0);
|
|
1880
|
+
tipEl.classList.toggle(TIP_FLIP_Y_CLASS, flipY && h === 0);
|
|
1881
|
+
tipEl.setAttribute(KIT_ATTR_TIP_ALIGN, `${flipY ? 'top' : 'bottom'}-${flipX ? 'end' : 'start'}`);
|
|
1882
|
+
const rawLeft = flipX
|
|
1883
|
+
? (w > 0 ? pointerAt.x - TIP_OFFSET_PX - w : pointerAt.x - TIP_OFFSET_PX)
|
|
1884
|
+
: pointerAt.x + TIP_OFFSET_PX;
|
|
1885
|
+
const rawTop = flipY
|
|
1886
|
+
? (h > 0 ? pointerAt.y - TIP_OFFSET_PX - h : pointerAt.y - TIP_OFFSET_PX)
|
|
1887
|
+
: pointerAt.y + TIP_OFFSET_PX;
|
|
1888
|
+
const maxLeft = roomW > 0 && w > 0 ? Math.max(0, roomW - w) : Number.POSITIVE_INFINITY;
|
|
1889
|
+
const maxTop = roomH > 0 && h > 0 ? Math.max(0, roomH - h) : Number.POSITIVE_INFINITY;
|
|
1890
|
+
tipEl.style.left = `${Math.round(Math.min(maxLeft, Math.max(0, rawLeft)))}px`;
|
|
1891
|
+
tipEl.style.top = `${Math.round(Math.min(maxTop, Math.max(0, rawTop)))}px`;
|
|
1892
|
+
};
|
|
1893
|
+
const onPointerMove = (event: PointerEvent): void => {
|
|
1894
|
+
if (!root) return;
|
|
1895
|
+
const box = root.getBoundingClientRect();
|
|
1896
|
+
pointerAt = { x: event.clientX - box.left, y: event.clientY - box.top };
|
|
1897
|
+
placeTip();
|
|
1898
|
+
};
|
|
1899
|
+
const appendTipDot = (doc: Document, swatch: KitChartSwatch): HTMLElement => {
|
|
1900
|
+
const dot = doc.createElement('span');
|
|
1901
|
+
dot.className = mergeClass(TIP_DOT_CLASS, swatch.bgCls);
|
|
1902
|
+
if (swatch.color && !swatch.color.startsWith('var(')) {
|
|
1903
|
+
const svg = doc.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
1904
|
+
svg.setAttribute('viewBox', '0 0 8 8');
|
|
1905
|
+
svg.setAttribute('class', 'size-full');
|
|
1906
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
1907
|
+
const circle = doc.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
1908
|
+
circle.setAttribute('cx', '4');
|
|
1909
|
+
circle.setAttribute('cy', '4');
|
|
1910
|
+
circle.setAttribute('r', '4');
|
|
1911
|
+
circle.setAttribute('fill', swatch.color);
|
|
1912
|
+
svg.appendChild(circle);
|
|
1913
|
+
dot.appendChild(svg);
|
|
1914
|
+
}
|
|
1915
|
+
return dot;
|
|
1916
|
+
};
|
|
1917
|
+
/** 悬停卡内容:直角坐标列与非直角坐标(饼/环/玫瑰/漏斗/散点/雷达/热力等)统一构建标题、真实色标、数值与占比 */
|
|
1918
|
+
const showTip = (col: number, seriesIndex?: number): void => {
|
|
1919
|
+
const d = drawn;
|
|
1920
|
+
if (!tipEl || !d || col < 0) { hideTip(); return; }
|
|
1921
|
+
const m = recOf(d.map);
|
|
1922
|
+
const src = (k: string): string => (typeof m[k] === 'string' && m[k] !== '' ? String(m[k]) : k);
|
|
1923
|
+
const empty = kitText('soma.kit.chart_readout_empty', undefined, root ?? undefined);
|
|
1924
|
+
const orderedTokens = root ? chartSeriesTokensOf(root) : KIT_CHART_SERIES_TOKENS;
|
|
1925
|
+
const orderedBg = orderedTokens.map((tok) => {
|
|
1926
|
+
const idx = KIT_CHART_SERIES_TOKENS.indexOf(tok);
|
|
1927
|
+
return SERIES_BG[idx >= 0 ? idx : 0]!;
|
|
1928
|
+
});
|
|
1929
|
+
const palette = d.theme.palette;
|
|
1930
|
+
const slotSwatch = (slot: number): KitChartSwatch => {
|
|
1931
|
+
const bgLen = Math.max(1, orderedBg.length);
|
|
1932
|
+
const safeBg = ((slot % bgLen) + bgLen) % bgLen;
|
|
1933
|
+
const palLen = Math.max(1, palette.length);
|
|
1934
|
+
const safePal = ((slot % palLen) + palLen) % palLen;
|
|
1935
|
+
return {
|
|
1936
|
+
bgCls: orderedBg[safeBg] ?? SERIES_BG[safeBg % SERIES_BG.length]!,
|
|
1937
|
+
color: palette.length > 0 ? palette[safePal] : undefined,
|
|
1938
|
+
};
|
|
1939
|
+
};
|
|
1940
|
+
const withAffix = (valText: string): string => {
|
|
1941
|
+
const vf = d.config.valueFormat;
|
|
1942
|
+
if (!vf || valText === empty) return valText;
|
|
1943
|
+
return `${vf.prefix}${valText}${vf.suffix}`;
|
|
1944
|
+
};
|
|
1945
|
+
|
|
1946
|
+
let title = '';
|
|
1947
|
+
const tipRows: Array<{ swatch: KitChartSwatch; label: string; value: string }> = [];
|
|
1948
|
+
const ctype = d.config.type;
|
|
1949
|
+
|
|
1950
|
+
if (KIT_CHART_COLUMN_TYPES.has(ctype)) {
|
|
1951
|
+
if (col >= d.rows.length) { hideTip(); return; }
|
|
1952
|
+
const row = d.rows[col];
|
|
1953
|
+
const items = d.config.readout?.items ?? d.config.y.map((field) => ({ field, label: field, format: 'number' as const, unit: '' }));
|
|
1954
|
+
title = d.config.readout !== undefined && d.config.readout.title !== '' ? cellText(row, d.config.readout.title, m) : cellText(row, d.config.x, m);
|
|
1955
|
+
for (const it of items) {
|
|
1956
|
+
const key = src(it.field);
|
|
1957
|
+
const rawText = formatReadoutValue(row?.[key], it.format, it.unit, empty);
|
|
1958
|
+
tipRows.push({
|
|
1959
|
+
swatch: chartSeriesSwatchOf(d.config, d.theme, orderedTokens, it.field, m),
|
|
1960
|
+
label: it.label,
|
|
1961
|
+
value: d.config.readout !== undefined ? rawText : withAffix(rawText),
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
} else if (ctype === 'pie' || ctype === 'donut' || ctype === 'rose' || ctype === 'funnel' || ctype === 'treemap' || ctype === 'sunburst') {
|
|
1965
|
+
if (col >= d.rows.length) { hideTip(); return; }
|
|
1966
|
+
const row = d.rows[col]!;
|
|
1967
|
+
const yField = d.config.y[0]!;
|
|
1968
|
+
const yKey = src(yField);
|
|
1969
|
+
const rawVal = num(row[yKey]);
|
|
1970
|
+
const valText = withAffix(formatReadoutValue(row[yKey], 'number', '', empty));
|
|
1971
|
+
const sumVal = d.rows.reduce((acc, r) => acc + Math.max(0, num(r[yKey]) ?? 0), 0);
|
|
1972
|
+
const topVal = ctype === 'funnel' ? num(d.rows[0]?.[yKey]) : null;
|
|
1973
|
+
const base = topVal !== null && topVal > 0 ? topVal : sumVal;
|
|
1974
|
+
const share = rawVal !== null ? fmtTipShare(rawVal, base) : '';
|
|
1975
|
+
title = cellText(row, d.config.x, m);
|
|
1976
|
+
tipRows.push({
|
|
1977
|
+
swatch: slotSwatch(col),
|
|
1978
|
+
label: yField,
|
|
1979
|
+
value: share !== '' ? `${valText} (${share})` : valText,
|
|
1980
|
+
});
|
|
1981
|
+
} else if (ctype === 'scatter') {
|
|
1982
|
+
if (col >= d.rows.length) { hideTip(); return; }
|
|
1983
|
+
const row = d.rows[col]!;
|
|
1984
|
+
const xText = formatReadoutValue(row[src(d.config.x)], 'number', '', empty);
|
|
1985
|
+
title = `${d.config.x}: ${xText}`;
|
|
1986
|
+
const fields = seriesIndex !== undefined && seriesIndex >= 0 && seriesIndex < d.config.y.length
|
|
1987
|
+
? [d.config.y[seriesIndex]!]
|
|
1988
|
+
: d.config.y;
|
|
1989
|
+
for (const field of fields) {
|
|
1990
|
+
tipRows.push({
|
|
1991
|
+
swatch: chartSeriesSwatchOf(d.config, d.theme, orderedTokens, field, m),
|
|
1992
|
+
label: field,
|
|
1993
|
+
value: withAffix(formatReadoutValue(row[src(field)], 'number', '', empty)),
|
|
1994
|
+
});
|
|
1995
|
+
}
|
|
1996
|
+
} else if (ctype === 'radar') {
|
|
1997
|
+
if (col < d.config.y.length) {
|
|
1998
|
+
const field = d.config.y[col]!;
|
|
1999
|
+
const swatch = chartSeriesSwatchOf(d.config, d.theme, orderedTokens, field, m);
|
|
2000
|
+
title = field;
|
|
2001
|
+
for (const r of d.rows) {
|
|
2002
|
+
tipRows.push({
|
|
2003
|
+
swatch,
|
|
2004
|
+
label: cellText(r, d.config.x, m),
|
|
2005
|
+
value: withAffix(formatReadoutValue(r[src(field)], 'number', '', empty)),
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
} else if (col < d.rows.length) {
|
|
2009
|
+
const row = d.rows[col]!;
|
|
2010
|
+
title = cellText(row, d.config.x, m);
|
|
2011
|
+
for (const field of d.config.y) {
|
|
2012
|
+
tipRows.push({
|
|
2013
|
+
swatch: chartSeriesSwatchOf(d.config, d.theme, orderedTokens, field, m),
|
|
2014
|
+
label: field,
|
|
2015
|
+
value: withAffix(formatReadoutValue(row[src(field)], 'number', '', empty)),
|
|
2016
|
+
});
|
|
2017
|
+
}
|
|
2018
|
+
} else {
|
|
2019
|
+
hideTip();
|
|
2020
|
+
return;
|
|
2021
|
+
}
|
|
2022
|
+
} else if (ctype === 'heatmap') {
|
|
2023
|
+
if (col >= d.rows.length || !d.config.value) { hideTip(); return; }
|
|
2024
|
+
const row = d.rows[col]!;
|
|
2025
|
+
const valField = d.config.value;
|
|
2026
|
+
const valKey = src(valField);
|
|
2027
|
+
const rawVal = num(row[valKey]);
|
|
2028
|
+
const allVals = d.rows.map((r) => num(r[valKey]) ?? 0);
|
|
2029
|
+
const lo = Math.min(...allVals, 0);
|
|
2030
|
+
const hi = Math.max(...allVals, 1);
|
|
2031
|
+
const isDiv = d.config.scale === 'diverging'
|
|
2032
|
+
|| (d.config.scale !== 'sequential' && allVals.some((v) => v < 0) && allVals.some((v) => v > 0));
|
|
2033
|
+
const ramp = isDiv ? d.theme.divRamp : d.theme.seqRamp;
|
|
2034
|
+
let rampColor = palette[0];
|
|
2035
|
+
if (ramp && ramp.length > 0 && rawVal !== null) {
|
|
2036
|
+
const ratio = hi > lo ? Math.min(1, Math.max(0, (rawVal - lo) / (hi - lo))) : 0.5;
|
|
2037
|
+
rampColor = ramp[Math.min(ramp.length - 1, Math.round(ratio * (ramp.length - 1)))];
|
|
2038
|
+
}
|
|
2039
|
+
const xCat = cellText(row, d.config.x, m);
|
|
2040
|
+
const yCat = cellText(row, d.config.y[0]!, m);
|
|
2041
|
+
title = [xCat, yCat].filter((s) => s !== '').join(' · ');
|
|
2042
|
+
tipRows.push({
|
|
2043
|
+
swatch: { bgCls: slotSwatch(0).bgCls, color: rampColor },
|
|
2044
|
+
label: valField,
|
|
2045
|
+
value: withAffix(formatReadoutValue(row[valKey], 'number', '', empty)),
|
|
2046
|
+
});
|
|
2047
|
+
} else if (ctype === 'gauge') {
|
|
2048
|
+
const row = d.rows[0];
|
|
2049
|
+
if (!row) { hideTip(); return; }
|
|
2050
|
+
const yField = d.config.y[0]!;
|
|
2051
|
+
const rawVal = num(row[src(yField)]);
|
|
2052
|
+
const span = (d.config.max ?? 100) - (d.config.min ?? 0);
|
|
2053
|
+
const share = rawVal !== null && span > 0 ? fmtTipShare(Math.max(0, rawVal - (d.config.min ?? 0)), span) : '';
|
|
2054
|
+
const valText = withAffix(formatReadoutValue(row[src(yField)], 'number', '', empty));
|
|
2055
|
+
title = cellText(row, d.config.x, m);
|
|
2056
|
+
tipRows.push({
|
|
2057
|
+
swatch: { bgCls: TONE_BG.primary, color: gaugeValueColor(d.config, d.theme, rawVal) },
|
|
2058
|
+
label: yField,
|
|
2059
|
+
value: share !== '' ? `${valText} (${share})` : valText,
|
|
2060
|
+
});
|
|
2061
|
+
} else {
|
|
2062
|
+
if (col >= d.rows.length) { hideTip(); return; }
|
|
2063
|
+
const row = d.rows[col]!;
|
|
2064
|
+
title = ctype === 'sankey' || ctype === 'chord' || ctype === 'network'
|
|
2065
|
+
? [cellText(row, d.config.x, m), cellText(row, d.config.y[0]!, m)].filter((s) => s !== '').join(' -> ')
|
|
2066
|
+
: cellText(row, d.config.x, m);
|
|
2067
|
+
if (ctype === 'sankey' || ctype === 'chord' || ctype === 'network') {
|
|
2068
|
+
const valField = d.config.value ?? d.config.y[0]!;
|
|
2069
|
+
tipRows.push({
|
|
2070
|
+
swatch: slotSwatch(col),
|
|
2071
|
+
label: valField,
|
|
2072
|
+
value: withAffix(formatReadoutValue(row[src(valField)], 'number', '', empty)),
|
|
2073
|
+
});
|
|
2074
|
+
} else {
|
|
2075
|
+
const openVal = ctype === 'candlestick' ? (num(row[src(d.config.y[0]!)]) ?? 0) : 0;
|
|
2076
|
+
const closeVal = ctype === 'candlestick' ? (num(row[src(d.config.y[1]!)]) ?? 0) : 0;
|
|
2077
|
+
const rise = closeVal >= openVal;
|
|
2078
|
+
const goodSwatch: KitChartSwatch = { bgCls: TONE_BG.success, color: d.theme.ok ?? palette[0] ?? d.theme.text };
|
|
2079
|
+
const badSwatch: KitChartSwatch = { bgCls: TONE_BG.danger, color: d.theme.danger ?? palette[2] ?? d.theme.text };
|
|
2080
|
+
const candleSwatch = d.config.upIs === 'bad' ? (rise ? badSwatch : goodSwatch) : (rise ? goodSwatch : badSwatch);
|
|
2081
|
+
for (const field of d.config.y) {
|
|
2082
|
+
tipRows.push({
|
|
2083
|
+
swatch: ctype === 'candlestick' ? candleSwatch : chartSeriesSwatchOf(d.config, d.theme, orderedTokens, field, m),
|
|
2084
|
+
label: field,
|
|
2085
|
+
value: withAffix(formatReadoutValue(row[src(field)], 'number', '', empty)),
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
if (tipRows.length === 0) { hideTip(); return; }
|
|
2092
|
+
const doc = tipEl.ownerDocument;
|
|
2093
|
+
tipEl.textContent = '';
|
|
2094
|
+
if (title !== '') {
|
|
2095
|
+
const head = doc.createElement('div');
|
|
2096
|
+
head.className = READOUT_TITLE_CLASS;
|
|
2097
|
+
head.textContent = title.slice(0, CHART_NUM.readout.titleMax);
|
|
2098
|
+
tipEl.appendChild(head);
|
|
2099
|
+
}
|
|
2100
|
+
for (const it of tipRows) {
|
|
2101
|
+
const line = doc.createElement('div');
|
|
2102
|
+
line.className = TIP_ROW_CLASS;
|
|
2103
|
+
const dot = appendTipDot(doc, it.swatch);
|
|
2104
|
+
const name = doc.createElement('span');
|
|
2105
|
+
name.className = TIP_NAME_CLASS;
|
|
2106
|
+
name.textContent = it.label;
|
|
2107
|
+
const value = doc.createElement('span');
|
|
2108
|
+
value.className = TIP_VALUE_CLASS;
|
|
2109
|
+
value.textContent = it.value;
|
|
2110
|
+
line.append(dot, name, value);
|
|
2111
|
+
tipEl.appendChild(line);
|
|
2112
|
+
}
|
|
2113
|
+
tipEl.className = kitLevelClassFor(tipEl, TIP_CLASS);
|
|
2114
|
+
placeTip();
|
|
2115
|
+
};
|
|
2116
|
+
const handleChartHoverEvent = (kind: 'hover' | 'click' | 'leave', p: { dataIndex: number; seriesIndex?: number } | null): void => {
|
|
2117
|
+
if (kind === 'hover' && p) showTip(p.dataIndex, p.seriesIndex);
|
|
2118
|
+
else if (kind === 'leave') hideTip();
|
|
1230
2119
|
if (!interactiveOf(drawn?.config)) return;
|
|
1231
|
-
if (kind === 'click') { if (
|
|
2120
|
+
if (kind === 'click') { if (p) pick(p.dataIndex); return; }
|
|
1232
2121
|
if (kbdActive) return;
|
|
1233
|
-
if (kind === 'hover' &&
|
|
2122
|
+
if (kind === 'hover' && p) setColumn(p.dataIndex, 'pointer');
|
|
1234
2123
|
else if (kind === 'leave') setColumn(defaultCol, 'default');
|
|
1235
2124
|
};
|
|
1236
2125
|
const bindColumns = (inst: ChartInstanceLike): void => {
|
|
1237
2126
|
offColumn?.();
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
2127
|
+
const offs: Array<() => void> = [];
|
|
2128
|
+
const hasCol = inst.onColumn !== undefined;
|
|
2129
|
+
const hasPtr = inst.onPointer !== undefined;
|
|
2130
|
+
if (hasCol) {
|
|
2131
|
+
offs.push(inst.onColumn!((kind, col) => {
|
|
2132
|
+
if (KIT_CHART_COLUMN_TYPES.has(drawn?.config.type ?? '')) handleChartHoverEvent(kind, col);
|
|
2133
|
+
}));
|
|
2134
|
+
}
|
|
2135
|
+
if (hasPtr) {
|
|
2136
|
+
offs.push(inst.onPointer!((kind, p) => {
|
|
2137
|
+
if (!hasCol || !KIT_CHART_COLUMN_TYPES.has(drawn?.config.type ?? '')) handleChartHoverEvent(kind, p);
|
|
2138
|
+
}));
|
|
2139
|
+
}
|
|
2140
|
+
offColumn = offs.length > 0 ? () => { for (const fn of offs) fn(); } : null;
|
|
2141
|
+
};
|
|
2142
|
+
const onStagePointerOver = (event: PointerEvent): void => {
|
|
2143
|
+
const el = (event.target as Element | null)?.closest?.(`[${KIT_CHART_ITEM_ATTR}]`);
|
|
2144
|
+
if (!el) return;
|
|
2145
|
+
const idx = Number.parseInt(el.getAttribute(KIT_CHART_ITEM_ATTR) ?? '', 10);
|
|
2146
|
+
if (!Number.isFinite(idx) || idx < 0) return;
|
|
2147
|
+
const sAttr = el.getAttribute(KIT_ATTR_CHART_SERIES);
|
|
2148
|
+
const sIdx = sAttr !== null ? Number.parseInt(sAttr, 10) : undefined;
|
|
2149
|
+
if (root && pointerAt === null) {
|
|
2150
|
+
const box = root.getBoundingClientRect();
|
|
2151
|
+
pointerAt = { x: event.clientX - box.left, y: event.clientY - box.top };
|
|
2152
|
+
}
|
|
2153
|
+
showTip(idx, sIdx !== undefined && Number.isFinite(sIdx) ? sIdx : undefined);
|
|
2154
|
+
};
|
|
2155
|
+
const onStagePointerOut = (event: PointerEvent): void => {
|
|
2156
|
+
const fromEl = (event.target as Element | null)?.closest?.(`[${KIT_CHART_ITEM_ATTR}]`);
|
|
2157
|
+
if (!fromEl) return;
|
|
2158
|
+
const toEl = (event.relatedTarget as Element | null)?.closest?.(`[${KIT_CHART_ITEM_ATTR}]`);
|
|
2159
|
+
if (toEl !== fromEl) hideTip();
|
|
1241
2160
|
};
|
|
1242
2161
|
const onKeyDown = (event: KeyboardEvent): void => {
|
|
1243
2162
|
const d = drawn;
|
|
@@ -1277,7 +2196,9 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1277
2196
|
readoutEl.className = `${READOUT_CLASS} ${top ? READOUT_TOP_CLASS : READOUT_BOTTOM_CLASS}`;
|
|
1278
2197
|
readoutEl.setAttribute('aria-hidden', 'true');
|
|
1279
2198
|
// data-kit-chart-readout:渲染判定 chart.readout.hover 的稳定选择器
|
|
1280
|
-
readoutEl.setAttribute(
|
|
2199
|
+
readoutEl.setAttribute(KIT_ATTR_CHART_READOUT, '');
|
|
2200
|
+
// 读数区是图上方 / 下方的一条摘要带(淡底带),不是浮出层
|
|
2201
|
+
kitMarkLevel(readoutEl, 'band'); kitApplyLevelClass(readoutEl);
|
|
1281
2202
|
if (top) root.insertBefore(readoutEl, stageWrap); else stageWrap.after(readoutEl);
|
|
1282
2203
|
}
|
|
1283
2204
|
if (liveEl && !liveEl.isConnected) root.appendChild(liveEl);
|
|
@@ -1316,6 +2237,8 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1316
2237
|
const retryLabel = str(p.retry_text);
|
|
1317
2238
|
const retry = retryLabel !== '' ? (): void => { api.emit('retry', {}); } : null;
|
|
1318
2239
|
const loading = p.loading === true || p.loading === 'true';
|
|
2240
|
+
// 数据状态自报(每次绘制都写):与面板同一判据——出错 > 加载 > 空;配置 / 引擎问题也按出错报,与下面画错误面板同口径
|
|
2241
|
+
kitMarkDataFacts(root, { error: errorText !== '' || config === null || (rows.length > 0 && portOf() === null), loading: rows.length === 0 && loading, empty: rows.length === 0 });
|
|
1319
2242
|
if (rows.length === 0 && errorText !== '') { showPanel('error', errorText, { retry, retryLabel }); return; }
|
|
1320
2243
|
if (rows.length === 0 && loading) { showPanel('loading', str(p.loading_text, kitText('soma.kit.loading', undefined, root))); return; }
|
|
1321
2244
|
// 配置 / 引擎问题是页面或环境的错,不是「没数据」:按错误态画(无重试)
|
|
@@ -1336,15 +2259,17 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1336
2259
|
drawn = { config, rows, theme, map: p.map, reduceMotion };
|
|
1337
2260
|
syncInteractive(config, rows, str(p.aria_label) !== '' ? str(p.aria_label) : alt.label);
|
|
1338
2261
|
const marked = chartMarkComponentsOf(config);
|
|
2262
|
+
const requiredSeries = renderedSeriesTypesOf(config, option);
|
|
1339
2263
|
if (instance === null) {
|
|
1340
2264
|
if (creating === null) {
|
|
1341
2265
|
creating = (async () => {
|
|
1342
2266
|
try {
|
|
1343
|
-
await port.ensure(
|
|
2267
|
+
await port.ensure(requiredSeries, engineComponentsOf(config.type, marked.markLine, marked.extra));
|
|
1344
2268
|
const locale = str(p.locale);
|
|
1345
2269
|
const created = await port.create(stage!, { theme: { color: theme.palette }, ...(locale !== '' ? { locale } : {}) });
|
|
1346
2270
|
if (!alive) { created.dispose(); return; }
|
|
1347
2271
|
instance = created;
|
|
2272
|
+
lastOptionSig = null;
|
|
1348
2273
|
bindColumns(created);
|
|
1349
2274
|
if (typeof ResizeObserver === 'function') {
|
|
1350
2275
|
resizeObs = new ResizeObserver(() => instance?.resize());
|
|
@@ -1364,9 +2289,13 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1364
2289
|
}
|
|
1365
2290
|
// 异步期间又有新一轮 paint 或已卸载:交给最新一轮
|
|
1366
2291
|
if (!alive || mine !== seq || instance === null) return;
|
|
1367
|
-
await port.ensure(
|
|
2292
|
+
await port.ensure(requiredSeries, engineComponentsOf(config.type, marked.markLine, marked.extra));
|
|
1368
2293
|
if (!alive || mine !== seq) return;
|
|
1369
|
-
|
|
2294
|
+
const nextSig = optionMergeSignatureOf(config, option);
|
|
2295
|
+
const updateMode: 'merge' | 'replace' = lastOptionSig !== null && lastOptionSig === nextSig ? 'merge' : 'replace';
|
|
2296
|
+
lastOptionSig = nextSig;
|
|
2297
|
+
instance.setOption(option, updateMode);
|
|
2298
|
+
annotateStageSvgItems(stage, config, rows);
|
|
1370
2299
|
endEngineWait();
|
|
1371
2300
|
} catch {
|
|
1372
2301
|
creating = null;
|
|
@@ -1379,12 +2308,30 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1379
2308
|
attach(rootEl) {
|
|
1380
2309
|
alive = true;
|
|
1381
2310
|
root = rootEl;
|
|
2311
|
+
// 新模式:警告 / 危险色降一档由图表在自己宿主上改写两个变量(主题不再按组件名写 Chart,recipes/self-owned);
|
|
2312
|
+
// 写在首次取主题(themeOf(root))之前,根节点继承得到;旧版不写,宿主不变
|
|
2313
|
+
const toned = kitApplyChartTones(api.host);
|
|
1382
2314
|
stageWrap = find('stageWrap');
|
|
1383
2315
|
stage = find('stage');
|
|
1384
2316
|
emptyWrap = find('emptyWrap');
|
|
2317
|
+
// 空 / 加载 / 出错面板与舞台同尺寸叠放,是成块的子内容(子块,含空状态块)
|
|
2318
|
+
if (emptyWrap) { kitMarkLevel(emptyWrap, 'sub'); kitApplyLevelClass(emptyWrap); }
|
|
1385
2319
|
emptyText = find('emptyText');
|
|
2320
|
+
emptyGrid = find('emptyGrid');
|
|
1386
2321
|
altWrap = find('altWrap');
|
|
1387
2322
|
watchScheme();
|
|
2323
|
+
tipEl = rootEl.ownerDocument.createElement('div');
|
|
2324
|
+
tipEl.className = 'hidden';
|
|
2325
|
+
tipEl.setAttribute('aria-hidden', 'true');
|
|
2326
|
+
tipEl.setAttribute(KIT_ATTR_CHART_TIP, '');
|
|
2327
|
+
// 悬停读数气泡 = 浮起(§8.2 气泡)
|
|
2328
|
+
kitMarkLevel(tipEl, 'float'); kitApplyLevelClass(tipEl);
|
|
2329
|
+
rootEl.appendChild(tipEl);
|
|
2330
|
+
const stageHost = stageWrap;
|
|
2331
|
+
stageHost?.addEventListener('pointermove', onPointerMove);
|
|
2332
|
+
stageHost?.addEventListener('pointerover', onStagePointerOver);
|
|
2333
|
+
stageHost?.addEventListener('pointerout', onStagePointerOut);
|
|
2334
|
+
stageHost?.addEventListener('pointerleave', hideTip);
|
|
1388
2335
|
// 读数区(视觉)与读屏播报区(仅键盘驱动更新):由 kit 自己渲染,位置在 paint 里按 readout.place 摆
|
|
1389
2336
|
readoutEl = rootEl.ownerDocument.createElement('div');
|
|
1390
2337
|
readoutEl.className = 'hidden';
|
|
@@ -1398,11 +2345,13 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1398
2345
|
rootEl.addEventListener('focusout', onFocusOut);
|
|
1399
2346
|
return () => {
|
|
1400
2347
|
alive = false;
|
|
2348
|
+
if (toned) kitClearChartTones(api.host);
|
|
1401
2349
|
rootEl.removeEventListener('keydown', onKeyDown);
|
|
1402
2350
|
rootEl.removeEventListener('focusin', onFocusIn);
|
|
1403
2351
|
rootEl.removeEventListener('focusout', onFocusOut);
|
|
1404
2352
|
offColumn?.();
|
|
1405
2353
|
offColumn = null;
|
|
2354
|
+
lastOptionSig = null;
|
|
1406
2355
|
readoutEl?.remove();
|
|
1407
2356
|
liveEl?.remove();
|
|
1408
2357
|
readoutEl = null;
|
|
@@ -1419,6 +2368,14 @@ export function createChart(): SomaComponentDefinition {
|
|
|
1419
2368
|
stage = null;
|
|
1420
2369
|
emptyWrap = null;
|
|
1421
2370
|
emptyText = null;
|
|
2371
|
+
emptyGrid = null;
|
|
2372
|
+
stageHost?.removeEventListener('pointermove', onPointerMove);
|
|
2373
|
+
stageHost?.removeEventListener('pointerover', onStagePointerOver);
|
|
2374
|
+
stageHost?.removeEventListener('pointerout', onStagePointerOut);
|
|
2375
|
+
stageHost?.removeEventListener('pointerleave', hideTip);
|
|
2376
|
+
tipEl?.remove();
|
|
2377
|
+
tipEl = null;
|
|
2378
|
+
pointerAt = null;
|
|
1422
2379
|
altWrap = null;
|
|
1423
2380
|
};
|
|
1424
2381
|
},
|