@seed-ship/mcp-ui-solid 6.24.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/README.md +61 -0
- package/dist/adapters/connector.cjs +3 -3
- package/dist/adapters/connector.cjs.map +1 -1
- package/dist/adapters/connector.d.cts +108 -0
- package/dist/adapters/connector.d.ts +1 -2
- package/dist/adapters/connector.js +3 -3
- package/dist/adapters/connector.js.map +1 -1
- package/dist/adapters/index.d.cts +21 -0
- package/dist/adapters/index.d.ts +6 -7
- package/dist/adapters/macro-run.d.cts +99 -0
- package/dist/adapters/macro-run.d.ts +1 -2
- package/dist/adapters/presentation.d.cts +1 -2
- package/dist/adapters/presentation.d.ts +1 -2
- package/dist/adapters.d.cts +1 -1
- package/dist/adapters.d.ts +1 -1
- package/dist/components/ActionGroupRenderer.cjs +6 -6
- package/dist/components/ActionGroupRenderer.cjs.map +1 -1
- package/dist/components/ActionGroupRenderer.d.cts +38 -0
- package/dist/components/ActionGroupRenderer.d.ts +1 -2
- package/dist/components/ActionGroupRenderer.js +6 -6
- package/dist/components/ActionGroupRenderer.js.map +1 -1
- package/dist/components/ActionRenderer.d.cts +9 -0
- package/dist/components/ActionRenderer.d.ts +0 -1
- package/dist/components/AgentCard.d.cts +19 -0
- package/dist/components/AgentCard.d.ts +1 -2
- package/dist/components/AgentHandoff.d.cts +11 -0
- package/dist/components/AgentHandoff.d.ts +1 -2
- package/dist/components/ArtifactRenderer.d.cts +11 -0
- package/dist/components/ArtifactRenderer.d.ts +0 -1
- package/dist/components/AutocompleteDropdown.cjs +6 -6
- package/dist/components/AutocompleteDropdown.cjs.map +1 -1
- package/dist/components/AutocompleteDropdown.d.cts +70 -0
- package/dist/components/AutocompleteDropdown.d.ts +1 -2
- package/dist/components/AutocompleteDropdown.js +6 -6
- package/dist/components/AutocompleteDropdown.js.map +1 -1
- package/dist/components/AutocompleteFormField.cjs +6 -5
- package/dist/components/AutocompleteFormField.cjs.map +1 -1
- package/dist/components/AutocompleteFormField.d.cts +51 -0
- package/dist/components/AutocompleteFormField.d.ts +1 -2
- package/dist/components/AutocompleteFormField.d.ts.map +1 -1
- package/dist/components/AutocompleteFormField.js +6 -5
- package/dist/components/AutocompleteFormField.js.map +1 -1
- package/dist/components/BriefingDiff.d.cts +11 -0
- package/dist/components/BriefingDiff.d.ts +1 -2
- package/dist/components/CarouselRenderer.d.cts +12 -0
- package/dist/components/CarouselRenderer.d.ts +1 -2
- package/dist/components/ChartJSRenderer.cjs +216 -6
- package/dist/components/ChartJSRenderer.cjs.map +1 -1
- package/dist/components/ChartJSRenderer.d.cts +62 -0
- package/dist/components/ChartJSRenderer.d.ts +1 -2
- package/dist/components/ChartJSRenderer.d.ts.map +1 -1
- package/dist/components/ChartJSRenderer.js +217 -7
- package/dist/components/ChartJSRenderer.js.map +1 -1
- package/dist/components/ChatPrompt.cjs +5 -5
- package/dist/components/ChatPrompt.cjs.map +1 -1
- package/dist/components/ChatPrompt.d.cts +69 -0
- package/dist/components/ChatPrompt.d.ts +1 -2
- package/dist/components/ChatPrompt.js +5 -5
- package/dist/components/ChatPrompt.js.map +1 -1
- package/dist/components/CodeBlockRenderer.d.cts +23 -0
- package/dist/components/CodeBlockRenderer.d.ts +1 -2
- package/dist/components/ComponentToolbar.cjs +5 -5
- package/dist/components/ComponentToolbar.cjs.map +1 -1
- package/dist/components/ComponentToolbar.d.cts +46 -0
- package/dist/components/ComponentToolbar.d.ts +0 -1
- package/dist/components/ComponentToolbar.js +5 -5
- package/dist/components/ComponentToolbar.js.map +1 -1
- package/dist/components/DataPreviewSection.d.cts +11 -0
- package/dist/components/DataPreviewSection.d.ts +1 -2
- package/dist/components/DegradedFallback.cjs +1 -1
- package/dist/components/DegradedFallback.cjs.map +1 -1
- package/dist/components/DegradedFallback.d.cts +43 -0
- package/dist/components/DegradedFallback.d.ts +0 -1
- package/dist/components/DegradedFallback.js +1 -1
- package/dist/components/DegradedFallback.js.map +1 -1
- package/dist/components/DraggableGridItem.d.cts +94 -0
- package/dist/components/DraggableGridItem.d.ts +1 -2
- package/dist/components/EditableLayoutContext.d.cts +4 -0
- package/dist/components/EditableLayoutContext.d.ts +0 -1
- package/dist/components/EditableUIResourceRenderer.d.cts +42 -0
- package/dist/components/EditableUIResourceRenderer.d.ts +1 -2
- package/dist/components/ElicitationForm.d.cts +67 -0
- package/dist/components/ElicitationForm.d.ts +1 -2
- package/dist/components/ExpandableWrapper.cjs +10 -7
- package/dist/components/ExpandableWrapper.cjs.map +1 -1
- package/dist/components/ExpandableWrapper.d.cts +49 -0
- package/dist/components/ExpandableWrapper.d.ts +0 -1
- package/dist/components/ExpandableWrapper.d.ts.map +1 -1
- package/dist/components/ExpandableWrapper.js +10 -7
- package/dist/components/ExpandableWrapper.js.map +1 -1
- package/dist/components/FeedbackInline.d.cts +70 -0
- package/dist/components/FeedbackInline.d.ts +0 -1
- package/dist/components/FooterRenderer.d.cts +15 -0
- package/dist/components/FooterRenderer.d.ts +0 -1
- package/dist/components/FormFieldRenderer.cjs +13 -12
- package/dist/components/FormFieldRenderer.cjs.map +1 -1
- package/dist/components/FormFieldRenderer.d.cts +19 -0
- package/dist/components/FormFieldRenderer.d.ts +1 -2
- package/dist/components/FormFieldRenderer.d.ts.map +1 -1
- package/dist/components/FormFieldRenderer.js +13 -12
- package/dist/components/FormFieldRenderer.js.map +1 -1
- package/dist/components/FormRenderer.cjs +1 -1
- package/dist/components/FormRenderer.cjs.map +1 -1
- package/dist/components/FormRenderer.d.cts +14 -0
- package/dist/components/FormRenderer.d.ts +1 -2
- package/dist/components/FormRenderer.js +1 -1
- package/dist/components/FormRenderer.js.map +1 -1
- package/dist/components/GenerativeUIErrorBoundary.cjs +1 -1
- package/dist/components/GenerativeUIErrorBoundary.cjs.map +1 -1
- package/dist/components/GenerativeUIErrorBoundary.d.cts +58 -0
- package/dist/components/GenerativeUIErrorBoundary.d.ts +1 -2
- package/dist/components/GenerativeUIErrorBoundary.default.d.cts +1 -0
- package/dist/components/GenerativeUIErrorBoundary.default.d.ts +1 -2
- package/dist/components/GenerativeUIErrorBoundary.js +1 -1
- package/dist/components/GenerativeUIErrorBoundary.js.map +1 -1
- package/dist/components/GhostText.cjs +2 -2
- package/dist/components/GhostText.cjs.map +1 -1
- package/dist/components/GhostText.d.cts +112 -0
- package/dist/components/GhostText.d.ts +0 -1
- package/dist/components/GhostText.js +2 -2
- package/dist/components/GhostText.js.map +1 -1
- package/dist/components/GraphRenderer.cjs +100 -29
- package/dist/components/GraphRenderer.cjs.map +1 -1
- package/dist/components/GraphRenderer.d.cts +66 -0
- package/dist/components/GraphRenderer.d.ts +2 -3
- package/dist/components/GraphRenderer.d.ts.map +1 -1
- package/dist/components/GraphRenderer.js +100 -29
- package/dist/components/GraphRenderer.js.map +1 -1
- package/dist/components/GridRenderer.d.cts +49 -0
- package/dist/components/GridRenderer.d.ts +1 -2
- package/dist/components/IframeFallbackLink.d.cts +22 -0
- package/dist/components/IframeFallbackLink.d.ts +0 -1
- package/dist/components/ImageGalleryRenderer.d.cts +22 -0
- package/dist/components/ImageGalleryRenderer.d.ts +1 -2
- package/dist/components/LightboxOverlay.d.cts +31 -0
- package/dist/components/LightboxOverlay.d.ts +1 -2
- package/dist/components/MapRenderer.d.cts +77 -0
- package/dist/components/MapRenderer.d.ts +1 -2
- package/dist/components/MissingValue.cjs +2 -2
- package/dist/components/MissingValue.cjs.map +1 -1
- package/dist/components/MissingValue.d.cts +26 -0
- package/dist/components/MissingValue.d.ts +0 -1
- package/dist/components/MissingValue.js +2 -2
- package/dist/components/MissingValue.js.map +1 -1
- package/dist/components/ModalRenderer.cjs +39 -31
- package/dist/components/ModalRenderer.cjs.map +1 -1
- package/dist/components/ModalRenderer.d.cts +66 -0
- package/dist/components/ModalRenderer.d.ts +1 -2
- package/dist/components/ModalRenderer.d.ts.map +1 -1
- package/dist/components/ModalRenderer.js +40 -32
- package/dist/components/ModalRenderer.js.map +1 -1
- package/dist/components/PortalDropdownMenu.cjs +6 -3
- package/dist/components/PortalDropdownMenu.cjs.map +1 -1
- package/dist/components/PortalDropdownMenu.d.cts +55 -0
- package/dist/components/PortalDropdownMenu.d.ts +0 -1
- package/dist/components/PortalDropdownMenu.d.ts.map +1 -1
- package/dist/components/PortalDropdownMenu.js +7 -4
- package/dist/components/PortalDropdownMenu.js.map +1 -1
- package/dist/components/PresentationFeedback.d.cts +112 -0
- package/dist/components/PresentationFeedback.d.ts +0 -1
- package/dist/components/RenderContext.d.cts +41 -0
- package/dist/components/RenderContext.d.ts +1 -2
- package/dist/components/ResizeHandle.d.cts +49 -0
- package/dist/components/ResizeHandle.d.ts +0 -1
- package/dist/components/SafeHtml.d.cts +45 -0
- package/dist/components/SafeHtml.d.ts +0 -1
- package/dist/components/ScratchpadPanel.cjs +38 -44
- package/dist/components/ScratchpadPanel.cjs.map +1 -1
- package/dist/components/ScratchpadPanel.d.cts +34 -0
- package/dist/components/ScratchpadPanel.d.ts +1 -2
- package/dist/components/ScratchpadPanel.d.ts.map +1 -1
- package/dist/components/ScratchpadPanel.js +38 -44
- package/dist/components/ScratchpadPanel.js.map +1 -1
- package/dist/components/SplitStepper.d.cts +11 -0
- package/dist/components/SplitStepper.d.ts +1 -2
- package/dist/components/StreamingUIRenderer.d.cts +58 -0
- package/dist/components/StreamingUIRenderer.d.ts +3 -4
- package/dist/components/UIResourceRenderer.cjs +20 -20
- package/dist/components/UIResourceRenderer.cjs.map +1 -1
- package/dist/components/UIResourceRenderer.d.cts +181 -0
- package/dist/components/UIResourceRenderer.d.ts +3 -4
- package/dist/components/UIResourceRenderer.default.d.cts +1 -0
- package/dist/components/UIResourceRenderer.default.d.ts +1 -2
- package/dist/components/UIResourceRenderer.js +20 -20
- package/dist/components/UIResourceRenderer.js.map +1 -1
- package/dist/components/VerifiedText.d.cts +22 -0
- package/dist/components/VerifiedText.d.ts +1 -2
- package/dist/components/VideoRenderer.d.cts +41 -0
- package/dist/components/VideoRenderer.d.ts +1 -2
- package/dist/components/chart-data-table.d.cts +68 -0
- package/dist/components/chart-data-table.d.ts +0 -1
- package/dist/components/chart-missing-plugin.cjs +4 -4
- package/dist/components/chart-missing-plugin.cjs.map +1 -1
- package/dist/components/chart-missing-plugin.d.cts +128 -0
- package/dist/components/chart-missing-plugin.d.ts +4 -3
- package/dist/components/chart-missing-plugin.d.ts.map +1 -1
- package/dist/components/chart-missing-plugin.js +4 -4
- package/dist/components/chart-missing-plugin.js.map +1 -1
- package/dist/components/index.d.cts +62 -0
- package/dist/components/index.d.ts +57 -58
- package/dist/components.d.cts +2 -2
- package/dist/components.d.ts +2 -2
- package/dist/context/AutocompleteContext.d.cts +76 -0
- package/dist/context/AutocompleteContext.d.ts +1 -2
- package/dist/context/MCPActionContext.d.cts +169 -0
- package/dist/context/MCPActionContext.d.ts +0 -1
- package/dist/context/MCPUIConfigContext.d.cts +201 -0
- package/dist/context/MCPUIConfigContext.d.ts +1 -2
- package/dist/context/MCPUIMathContext.d.cts +17 -0
- package/dist/context/MCPUIMathContext.d.ts +0 -1
- package/dist/context/MCPUIStringsContext.d.cts +802 -0
- package/dist/context/MCPUIStringsContext.d.ts +1 -2
- package/dist/context/MCPUITelemetryContext.d.cts +35 -0
- package/dist/context/MCPUITelemetryContext.d.ts +1 -2
- package/dist/context/index.d.cts +7 -0
- package/dist/context/index.d.ts +2 -3
- package/dist/hooks/createResponsiveGrid.d.cts +5 -0
- package/dist/hooks/createResponsiveGrid.d.ts +0 -1
- package/dist/hooks/index.d.cts +25 -0
- package/dist/hooks/index.d.ts +20 -21
- package/dist/hooks/useAction.d.cts +164 -0
- package/dist/hooks/useAction.d.ts +2 -3
- package/dist/hooks/useAutocomplete.d.cts +118 -0
- package/dist/hooks/useAutocomplete.d.ts +1 -2
- package/dist/hooks/useChatBus.d.cts +55 -0
- package/dist/hooks/useChatBus.d.ts +1 -2
- package/dist/hooks/useConditionalField.d.cts +34 -0
- package/dist/hooks/useConditionalField.d.ts +1 -2
- package/dist/hooks/useDataValidator.d.cts +41 -0
- package/dist/hooks/useDataValidator.d.ts +1 -2
- package/dist/hooks/useDragDrop.d.cts +99 -0
- package/dist/hooks/useDragDrop.d.ts +1 -2
- package/dist/hooks/useFormPersistence.d.cts +80 -0
- package/dist/hooks/useFormPersistence.d.ts +0 -1
- package/dist/hooks/useModal.d.cts +106 -0
- package/dist/hooks/useModal.d.ts +0 -1
- package/dist/hooks/useResize.d.cts +86 -0
- package/dist/hooks/useResize.d.ts +1 -2
- package/dist/hooks/useStreamingUI.d.cts +117 -0
- package/dist/hooks/useStreamingUI.d.ts +1 -2
- package/dist/hooks.d.cts +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/index.d.cts +91 -92
- package/dist/index.d.ts +91 -92
- package/dist/plugins/duckdb.d.cts +1 -2
- package/dist/plugins/duckdb.d.ts +1 -2
- package/dist/plugins/groq.d.cts +12 -0
- package/dist/plugins/groq.d.ts +1 -2
- package/dist/plugins/index.d.cts +9 -0
- package/dist/plugins/index.d.ts +3 -4
- package/dist/plugins/katex.d.cts +1 -2
- package/dist/plugins/katex.d.ts +1 -2
- package/dist/plugins/rest.d.cts +12 -0
- package/dist/plugins/rest.d.ts +1 -2
- package/dist/plugins/supabase.d.cts +12 -0
- package/dist/plugins/supabase.d.ts +1 -2
- package/dist/services/chat-bus.d.cts +100 -0
- package/dist/services/chat-bus.d.ts +1 -2
- package/dist/services/chat-prompt-controller.d.cts +92 -0
- package/dist/services/chat-prompt-controller.d.ts +1 -2
- package/dist/services/component-registry.d.cts +119 -0
- package/dist/services/component-registry.d.ts +1 -2
- package/dist/services/data-validator.d.cts +27 -0
- package/dist/services/data-validator.d.ts +1 -2
- package/dist/services/index.d.cts +9 -0
- package/dist/services/index.d.ts +4 -5
- package/dist/services/telemetry.d.cts +86 -0
- package/dist/services/telemetry.d.ts +1 -2
- package/dist/services/validation.d.cts +169 -0
- package/dist/services/validation.d.ts +1 -2
- package/dist/stores/scratchpad-store.d.cts +109 -0
- package/dist/stores/scratchpad-store.d.ts +1 -2
- package/dist/stores/server-capabilities-store.d.cts +171 -0
- package/dist/stores/server-capabilities-store.d.ts +0 -1
- package/dist/test-setup.d.cts +5 -0
- package/dist/test-setup.d.ts +0 -1
- package/dist/testing/index.d.cts +34 -0
- package/dist/testing/index.d.ts +1 -2
- package/dist/types/chat-bus.d.cts +783 -0
- package/dist/types/chat-bus.d.ts +4 -5
- package/dist/types/index.d.cts +1616 -0
- package/dist/types/index.d.ts +0 -1
- package/dist/types-export.d.cts +1 -2
- package/dist/types-export.d.ts +1 -2
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/degraded-projections.d.cts +119 -0
- package/dist/utils/degraded-projections.d.ts +0 -1
- package/dist/utils/duplicate-mount-registry.d.cts +83 -0
- package/dist/utils/duplicate-mount-registry.d.ts +0 -1
- package/dist/utils/escape-html.d.cts +12 -0
- package/dist/utils/escape-html.d.ts +0 -1
- package/dist/utils/format-string.d.cts +25 -0
- package/dist/utils/format-string.d.ts +0 -1
- package/dist/utils/iframe-coep.d.cts +53 -0
- package/dist/utils/iframe-coep.d.ts +1 -2
- package/dist/utils/logger.d.cts +57 -0
- package/dist/utils/logger.d.ts +0 -1
- package/dist/utils/math-markdown.cjs +1 -1
- package/dist/utils/math-markdown.cjs.map +1 -1
- package/dist/utils/math-markdown.d.cts +15 -0
- package/dist/utils/math-markdown.d.ts +1 -2
- package/dist/utils/math-markdown.js +1 -1
- package/dist/utils/math-markdown.js.map +1 -1
- package/dist/utils/missing-value.d.cts +78 -0
- package/dist/utils/missing-value.d.ts +0 -1
- package/dist/utils/pan-zoom.d.cts +234 -0
- package/dist/utils/pan-zoom.d.ts +0 -1
- package/dist/utils/perf.d.cts +18 -0
- package/dist/utils/perf.d.ts +0 -1
- package/dist/utils/safe-url.d.cts +33 -0
- package/dist/utils/safe-url.d.ts +0 -1
- package/dist/utils/sanitize-html.d.cts +142 -0
- package/dist/utils/sanitize-html.d.ts +0 -1
- package/dist/utils/stable-key.d.cts +32 -0
- package/dist/utils/stable-key.d.ts +0 -1
- package/dist/utils/theme.cjs +91 -0
- package/dist/utils/theme.cjs.map +1 -0
- package/dist/utils/theme.d.cts +10 -0
- package/dist/utils/theme.d.ts +10 -0
- package/dist/utils/theme.d.ts.map +1 -0
- package/dist/utils/theme.js +91 -0
- package/dist/utils/theme.js.map +1 -0
- package/dist/validation.d.cts +3 -4
- package/dist/validation.d.ts +3 -4
- package/docs/SECURITY-DEPENDENCIES.md +209 -0
- package/docs/THEMING.md +205 -0
- package/docs/ZOD4-STABLE-MIGRATION-2026-10-26.md +181 -0
- package/package.json +12 -9
- package/src/adapters/connector.ts +3 -3
- package/src/components/ActionGroupRenderer.tsx +6 -6
- package/src/components/AutocompleteDropdown.tsx +17 -17
- package/src/components/AutocompleteFormField.tsx +10 -9
- package/src/components/ChartJSRenderer.tsx +483 -239
- package/src/components/ChatPrompt.tsx +16 -16
- package/src/components/ComponentToolbar.tsx +5 -5
- package/src/components/DegradedFallback.tsx +9 -9
- package/src/components/ExpandableWrapper.tsx +15 -11
- package/src/components/FormFieldRenderer.tsx +52 -51
- package/src/components/FormRenderer.tsx +12 -12
- package/src/components/GenerativeUIErrorBoundary.tsx +6 -6
- package/src/components/GhostText.tsx +7 -7
- package/src/components/GraphRenderer.tsx +83 -67
- package/src/components/MissingValue.tsx +2 -2
- package/src/components/ModalRenderer.tsx +11 -5
- package/src/components/PortalDropdownMenu.tsx +6 -2
- package/src/components/ScratchpadPanel.tsx +144 -141
- package/src/components/UIResourceRenderer.tsx +101 -101
- package/src/components/chart-missing-plugin.ts +5 -3
- package/src/styles/autocomplete.css +53 -53
- package/src/utils/math-markdown.ts +1 -1
- package/src/utils/theme.ts +101 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VerifiedText — renders LLM text with inline verification badges
|
|
3
|
+
* v3.1.0: Highlights verified vs hallucinated numbers
|
|
4
|
+
*
|
|
5
|
+
* @experimental
|
|
6
|
+
*
|
|
7
|
+
* Modes:
|
|
8
|
+
* - highlight: ✅/⚠️ badges next to numbers (default)
|
|
9
|
+
* - strip: replaces hallucinated numbers with the `verifiedStripLabel`
|
|
10
|
+
* chrome string ('[unverified]' by default)
|
|
11
|
+
* - annotate: tooltip on hover with closest source number
|
|
12
|
+
*/
|
|
13
|
+
import type { DataValidation, HallucinatedNumber } from "../types/chat-bus.cjs";
|
|
14
|
+
export interface VerifiedTextProps {
|
|
15
|
+
text: string;
|
|
16
|
+
validation: DataValidation;
|
|
17
|
+
/** Display mode (default: 'highlight') */
|
|
18
|
+
mode?: 'highlight' | 'strip' | 'annotate';
|
|
19
|
+
/** Callback when a hallucinated number is clicked */
|
|
20
|
+
onHallucinationClick?: (item: HallucinatedNumber) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare function VerifiedText(props: VerifiedTextProps): import("solid-js").JSX.Element;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* chrome string ('[unverified]' by default)
|
|
11
11
|
* - annotate: tooltip on hover with closest source number
|
|
12
12
|
*/
|
|
13
|
-
import type { DataValidation, HallucinatedNumber } from
|
|
13
|
+
import type { DataValidation, HallucinatedNumber } from "../types/chat-bus.js";
|
|
14
14
|
export interface VerifiedTextProps {
|
|
15
15
|
text: string;
|
|
16
16
|
validation: DataValidation;
|
|
@@ -20,4 +20,3 @@ export interface VerifiedTextProps {
|
|
|
20
20
|
onHallucinationClick?: (item: HallucinatedNumber) => void;
|
|
21
21
|
}
|
|
22
22
|
export declare function VerifiedText(props: VerifiedTextProps): import("solid-js").JSX.Element;
|
|
23
|
-
//# sourceMappingURL=VerifiedText.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VideoRenderer - Video embed component
|
|
3
|
+
* Sprint 5: Media Components
|
|
4
|
+
*
|
|
5
|
+
* Supports YouTube, Vimeo, and direct video files
|
|
6
|
+
*/
|
|
7
|
+
import { Component } from 'solid-js';
|
|
8
|
+
import type { UIComponent, VideoComponentParams } from "../types.cjs";
|
|
9
|
+
export interface VideoRendererProps {
|
|
10
|
+
/**
|
|
11
|
+
* UIComponent containing video params
|
|
12
|
+
*/
|
|
13
|
+
component?: UIComponent;
|
|
14
|
+
/**
|
|
15
|
+
* Direct video params (alternative to component)
|
|
16
|
+
*/
|
|
17
|
+
params?: VideoComponentParams;
|
|
18
|
+
/**
|
|
19
|
+
* Error callback
|
|
20
|
+
*/
|
|
21
|
+
onError?: (error: Error) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Forwarded to the underlying `<ExpandableWrapper>` (v6.3.1).
|
|
24
|
+
* @see ExpandableWrapperProps.toolbarVariant
|
|
25
|
+
*/
|
|
26
|
+
toolbarVariant?: 'hover' | 'always-visible';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Video provider type
|
|
30
|
+
*/
|
|
31
|
+
type VideoProvider = 'youtube' | 'vimeo' | 'direct';
|
|
32
|
+
export declare const VideoRenderer: Component<VideoRendererProps>;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a URL is from a supported video provider
|
|
35
|
+
*/
|
|
36
|
+
export declare function isSupportedVideoUrl(url: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Get video provider from URL
|
|
39
|
+
*/
|
|
40
|
+
export declare function getVideoProvider(url: string): VideoProvider;
|
|
41
|
+
export {};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Supports YouTube, Vimeo, and direct video files
|
|
6
6
|
*/
|
|
7
7
|
import { Component } from 'solid-js';
|
|
8
|
-
import type { UIComponent, VideoComponentParams } from
|
|
8
|
+
import type { UIComponent, VideoComponentParams } from "../types.js";
|
|
9
9
|
export interface VideoRendererProps {
|
|
10
10
|
/**
|
|
11
11
|
* UIComponent containing video params
|
|
@@ -39,4 +39,3 @@ export declare function isSupportedVideoUrl(url: string): boolean;
|
|
|
39
39
|
*/
|
|
40
40
|
export declare function getVideoProvider(url: string): VideoProvider;
|
|
41
41
|
export {};
|
|
42
|
-
//# sourceMappingURL=VideoRenderer.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column headers and series names of the accessible chart data table.
|
|
3
|
+
*
|
|
4
|
+
* `chartToDataTable` is a pure helper with no access to `MCPUIStrings`, so
|
|
5
|
+
* the wording is injected: it takes an optional trailing `labels` partial,
|
|
6
|
+
* which `ChartJSRenderer` feeds from `useMCPUIStrings()`. Left out, the
|
|
7
|
+
* English defaults below apply — the pre-v6.20.0 behaviour.
|
|
8
|
+
*
|
|
9
|
+
* `x` / `y` / `r` stay untranslated on purpose: they are the Chart.js point
|
|
10
|
+
* property NAMES the cells mirror, not prose.
|
|
11
|
+
*
|
|
12
|
+
* @since v6.20.0
|
|
13
|
+
*/
|
|
14
|
+
export interface ChartDataTableLabels {
|
|
15
|
+
/** Series column of the per-point table. */
|
|
16
|
+
series: string;
|
|
17
|
+
/** Point-index column of the per-point table. */
|
|
18
|
+
point: string;
|
|
19
|
+
/** Label column (categorical table, and per-point table when labelled). */
|
|
20
|
+
label: string;
|
|
21
|
+
/** Fallback dataset name. Template — `{n}`. */
|
|
22
|
+
seriesName: string;
|
|
23
|
+
/** Chart.js point property names — machine tokens, rarely overridden. */
|
|
24
|
+
x: string;
|
|
25
|
+
y: string;
|
|
26
|
+
r: string;
|
|
27
|
+
/**
|
|
28
|
+
* A value column header followed by the chart's `unit`. Template — `{label}`,
|
|
29
|
+
* `{unit}`. Only applied when the chart has a unit. Optional so that a
|
|
30
|
+
* complete labels table written for 6.20.0–6.23.0 still type-checks.
|
|
31
|
+
* @since v6.24.0
|
|
32
|
+
*/
|
|
33
|
+
withUnit?: string;
|
|
34
|
+
}
|
|
35
|
+
/** English defaults for {@link ChartDataTableLabels}. */
|
|
36
|
+
export declare const CHART_DATA_TABLE_LABELS: Required<ChartDataTableLabels>;
|
|
37
|
+
export interface ChartDataTable {
|
|
38
|
+
columns: string[];
|
|
39
|
+
rows: Array<Array<string | number>>;
|
|
40
|
+
/**
|
|
41
|
+
* Same shape as `rows`: `true` for a VALUE cell whose source entry is
|
|
42
|
+
* missing (`null` / non-finite, or a point whose `y` is). A slot past the
|
|
43
|
+
* end of a shorter or empty dataset has no entry and is not flagged. Label,
|
|
44
|
+
* series, point-index, `x` and `r` cells are never missing. `rows` itself
|
|
45
|
+
* still holds `''` there. @since v6.24.0
|
|
46
|
+
*/
|
|
47
|
+
missing: boolean[][];
|
|
48
|
+
}
|
|
49
|
+
interface ChartDatasetLike {
|
|
50
|
+
label?: string;
|
|
51
|
+
data?: unknown[];
|
|
52
|
+
}
|
|
53
|
+
export interface ChartDataLike {
|
|
54
|
+
type?: string;
|
|
55
|
+
/** Unit of the values: appended to the value column headers. @since v6.24.0 */
|
|
56
|
+
unit?: string;
|
|
57
|
+
data?: {
|
|
58
|
+
labels?: Array<string | number>;
|
|
59
|
+
datasets?: ChartDatasetLike[];
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Project Chart.js data into an accessible table without flattening point
|
|
64
|
+
* coordinates. Categorical charts use a compact wide table; scatter, bubble,
|
|
65
|
+
* and object-valued line charts use one row per point so x/y/r remain distinct.
|
|
66
|
+
*/
|
|
67
|
+
export declare function chartToDataTable(params: ChartDataLike, labels?: Partial<ChartDataTableLabels>): ChartDataTable;
|
|
68
|
+
export {};
|
|
@@ -149,7 +149,7 @@ function drawMissingBarStubs(chart) {
|
|
|
149
149
|
ctx.restore();
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
-
function drawNoDataText(chart, text, fontFamily) {
|
|
152
|
+
function drawNoDataText(chart, text, fontFamily, color) {
|
|
153
153
|
const ctx = chart == null ? void 0 : chart.ctx;
|
|
154
154
|
const area = chart == null ? void 0 : chart.chartArea;
|
|
155
155
|
if (!ctx || !area || !text) return;
|
|
@@ -157,7 +157,7 @@ function drawNoDataText(chart, text, fontFamily) {
|
|
|
157
157
|
const cy = (area.top + (area.bottom ?? area.top + (area.height ?? 0))) / 2;
|
|
158
158
|
ctx.save();
|
|
159
159
|
ctx.font = `12px ${fontFamily || "sans-serif"}`;
|
|
160
|
-
ctx.fillStyle = NO_DATA_TEXT_COLOR;
|
|
160
|
+
ctx.fillStyle = color || NO_DATA_TEXT_COLOR;
|
|
161
161
|
ctx.textAlign = "center";
|
|
162
162
|
ctx.textBaseline = "middle";
|
|
163
163
|
ctx.fillText(text, cx, cy);
|
|
@@ -167,11 +167,11 @@ function createMissingValuesPlugin(options) {
|
|
|
167
167
|
return {
|
|
168
168
|
id: "mcpuiMissingValues",
|
|
169
169
|
afterDatasetsDraw(chart) {
|
|
170
|
-
var _a;
|
|
170
|
+
var _a, _b;
|
|
171
171
|
try {
|
|
172
172
|
drawMissingBarStubs(chart);
|
|
173
173
|
if (options.allMissing) {
|
|
174
|
-
drawNoDataText(chart, options.getNoDataText(), (_a = options.getFontFamily) == null ? void 0 : _a.call(options));
|
|
174
|
+
drawNoDataText(chart, options.getNoDataText(), (_a = options.getFontFamily) == null ? void 0 : _a.call(options), (_b = options.getTextColor) == null ? void 0 : _b.call(options));
|
|
175
175
|
}
|
|
176
176
|
} catch {
|
|
177
177
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-missing-plugin.cjs","sources":["../../src/components/chart-missing-plugin.ts"],"sourcesContent":["/**\n * Missing values in a Chart.js chart (v6.24.0) — everything the renderer adds\n * to its Chart.js config when a payload says a value is MISSING (`null`).\n *\n * The rule: absence is never zero. Chart.js already keeps the slot of a `null`\n * (no label dropped) and draws nothing for it; what it does not do is make the\n * absence READABLE. A null bar is a zero-height bar that is skipped when\n * drawn, a null line point is a hole the line may bridge (`spanGaps`), and the\n * legend, tooltip and axis know nothing of either. This module supplies:\n *\n * - {@link createMissingValuesPlugin} — a PER-CHART plugin (never\n * `Chart.register`ed, so it can leak into no other chart) that outlines a\n * dashed stub where a bar should have been (not on stacked or overlaid\n * bars, whose baseline belongs to another series), and says \"no data\" on a\n * chart with nothing to draw;\n * - {@link createMissingLegendGenerator} — marks a fully-missing series in the\n * legend;\n * - {@link createTooltipLabel} — names a missing value, and appends the unit;\n * - {@link withDatasetsNoGapSpan} — the shallow-cloned data with\n * `spanGaps: false`;\n * - {@link applyUnitAxisTitle} — the unit as the value axis title.\n *\n * Runtime-free on purpose (no `solid-js`, no `chart.js` import): the renderer\n * hands in the Chart.js pieces it loaded and the chrome strings (lazily, as\n * getters, so a late locale change is honoured at draw time). Every function\n * is defensive — a drawing hook that throws would blank the whole chart.\n *\n * Chart.js 4.5.1 facts this relies on (verified in `dist/chart.js`):\n * - a bar whose parsed value is `null` gets `base = head = vScale.getBasePixel()`\n * and no `skip` flag (BarController.updateElements), and `BarController.draw`\n * skips it (`getParsed(i)[vScale.axis] !== null`) — so nothing is painted;\n * - the bar element still carries its true index-axis thickness (`width` for a\n * vertical bar, `height` for a horizontal one).\n */\n\nimport type { MCPUIStrings } from '../context/MCPUIStringsContext';\nimport { formatMCPUIString } from '../utils/format-string';\nimport { isMissingChartValue } from '../utils/missing-value';\n\ntype Strings = Required<MCPUIStrings>;\n\n/** Length, in px along the value axis, of the dashed stub of a missing bar. */\nexport const MISSING_BAR_STUB_LENGTH = 12;\n/** Stroke of the stub when the dataset names no border colour. */\nexport const MISSING_BAR_FALLBACK_COLOR = '#9ca3af';\n/** Colour of the centred \"no data\" text. */\nexport const NO_DATA_TEXT_COLOR = '#6b7280';\nconst STUB_DASH = [4, 3];\n\n/** Chart types whose value axis is `y` and whose points are `{x, y}`. */\nconst POINT_CHART_TYPES = new Set(['scatter', 'bubble']);\n\n/**\n * The category of convention line a chart shows under its canvas:\n * `'gaps'` (a line breaks), `'bars'` (a dashed outline stands in for the\n * bar) or `'omitted'` (nothing is drawn: scatter, bubble, stacked bars).\n */\nexport type MissingNoteKind = 'gaps' | 'bars' | 'omitted';\n\n/**\n * Whether a bar chart's bars are stacked or overlaid (`stacked` on either\n * axis). A missing bar there has no slot of its own at the baseline — the\n * baseline belongs to the series below — so no dashed outline is drawn.\n */\nexport function isStackedChart(options: any): boolean {\n return Boolean(options?.scales?.x?.stacked || options?.scales?.y?.stacked);\n}\n\n/** Which convention note a chart gets: how ITS missing values are drawn. */\nexport function missingNoteKind(chartType: string | undefined, options?: any): MissingNoteKind {\n if (chartType === 'bar') return isStackedChart(options) ? 'omitted' : 'bars';\n if (chartType === 'scatter' || chartType === 'bubble') return 'omitted';\n return 'gaps';\n}\n\n// ─── Data ──────────────────────────────────────────────────────────────────\n\n/**\n * Chart.js data with every dataset shallow-cloned and `spanGaps: false`, so a\n * line breaks at a missing value instead of joining its neighbours. Never\n * mutates its input; `labels` and every other key are carried by reference.\n */\nexport function withDatasetsNoGapSpan<D extends { datasets?: unknown }>(data: D): D {\n const datasets = Array.isArray(data?.datasets) ? data.datasets : null;\n if (!datasets) return data;\n return {\n ...data,\n datasets: datasets.map((dataset: unknown) =>\n dataset !== null && typeof dataset === 'object'\n ? { ...(dataset as object), spanGaps: false }\n : dataset\n ),\n };\n}\n\n// ─── Legend ────────────────────────────────────────────────────────────────\n\ntype LegendGenerator = (chart: any) => any[];\n\n/**\n * Wraps a Chart.js legend label generator so a fully-missing dataset reads\n * `\"{series} (no data)\"` (`strings.chartLegendNoData`). Every other item is\n * passed through untouched.\n */\nexport function createMissingLegendGenerator(\n base: LegendGenerator,\n fullyMissing: readonly boolean[],\n getStrings: () => Strings\n): LegendGenerator {\n return function generateLabels(this: unknown, chart: any) {\n const items = base.call(this, chart);\n if (!Array.isArray(items)) return items;\n return items.map((item) => {\n const index = item?.datasetIndex;\n if (typeof index !== 'number' || !fullyMissing[index]) return item;\n const text = typeof item.text === 'string' ? item.text : String(item.text ?? '');\n return {\n ...item,\n text: formatMCPUIString(getStrings().chartLegendNoData, { series: text }),\n };\n });\n };\n}\n\n// ─── Tooltip ───────────────────────────────────────────────────────────────\n\n/** Whether a Chart.js tooltip item stands for a missing value. */\nexport function isMissingTooltipItem(item: any): boolean {\n if (item === null || item === undefined) return false;\n if (item.raw === null || item.raw === undefined || isMissingChartValue(item.raw)) return true;\n const parsed = item.parsed;\n if (parsed !== null && typeof parsed === 'object') {\n const chartType = item.chart?.config?.type;\n const valueKey =\n chartType === 'radar' ? 'r' : item.chart?.options?.indexAxis === 'y' ? 'x' : 'y';\n if (valueKey in parsed && parsed[valueKey] === null) return true;\n }\n return false;\n}\n\n/**\n * Tooltip `label` callback: names a missing value (`\"{series}: Missing\n * value\"`) and, with a `unit`, appends it to a present one. Otherwise it is\n * Chart.js's default composition (dataset label, `\": \"`, formatted value) —\n * including its `mode: 'dataset'` branch, which prefixes the CATEGORY label\n * instead, since every item of that tooltip belongs to the same dataset.\n * Hence a regular function: Chart.js calls it with the tooltip as `this`.\n *\n * `unit` is left off scatter and bubble tooltips: their formatted value is the\n * pair `(x, y)`, to which one unit does not belong.\n */\nexport function createTooltipLabel(\n getStrings: () => Strings,\n unit: string | undefined,\n chartType: string | undefined\n): (this: any, item: any) => string {\n const applyUnit = unit !== undefined && !POINT_CHART_TYPES.has(chartType ?? '');\n return function label(this: any, item: any) {\n const strings = getStrings();\n const prefixLabel = this?.options?.mode === 'dataset' ? item?.label : item?.dataset?.label;\n const prefix = typeof prefixLabel === 'string' && prefixLabel !== '' ? `${prefixLabel}: ` : '';\n\n if (isMissingTooltipItem(item)) return `${prefix}${strings.missingValue}`;\n\n const formatted = item?.formattedValue;\n if (formatted === null || formatted === undefined) return prefix;\n const value = applyUnit\n ? formatMCPUIString(strings.chartValueWithUnit, { value: formatted, unit: unit as string })\n : String(formatted);\n return `${prefix}${value}`;\n };\n}\n\n// ─── Axis ──────────────────────────────────────────────────────────────────\n\n/**\n * Sets the chart's `unit` as the title of its value axis, in place on the\n * `options` object the renderer just built (never on the payload's).\n *\n * Only bar, line, scatter and bubble have a value axis to title. The value\n * axis is `y`, or `x` when the index axis is `y` (a horizontal bar or line).\n * An existing `scales[axis].title` is the payload's own word and is kept; the\n * rest of the scale config (a `timeAxis` block sets `scales.x`) is kept too.\n */\nexport function applyUnitAxisTitle(\n options: any,\n chartType: string | undefined,\n unit: string | undefined\n): void {\n if (unit === undefined) return;\n if (chartType !== 'bar' && chartType !== 'line' && !POINT_CHART_TYPES.has(chartType ?? '')) {\n return;\n }\n const horizontal = (chartType === 'bar' || chartType === 'line') && options?.indexAxis === 'y';\n const axis = horizontal ? 'x' : 'y';\n if (options.scales?.[axis]?.title !== undefined) return;\n options.scales = {\n ...options.scales,\n [axis]: { ...options.scales?.[axis], title: { display: true, text: unit } },\n };\n}\n\n// ─── Plugin ────────────────────────────────────────────────────────────────\n\nexport interface MissingValuesPluginOptions {\n /** At least one dataset and every one of them has no observed value. */\n allMissing: boolean;\n /** Lazy: read at draw time. */\n getNoDataText: () => string;\n /** Lazy: `Chart.defaults.font.family`, when the build exposes it. */\n getFontFamily?: () => string | undefined;\n}\n\n/** A dataset colour for entry `index`, as a string, or `undefined`. */\nfunction colorAt(color: unknown, index: number): string | undefined {\n if (typeof color === 'string' && color !== '') return color;\n if (Array.isArray(color) && color.length > 0) {\n const picked = color[index % color.length];\n return typeof picked === 'string' && picked !== '' ? picked : undefined;\n }\n return undefined;\n}\n\n/**\n * Draws a dashed outline stub for every missing bar of every visible,\n * non-stacked bar dataset, so a missing value is a visible mark, not a bar\n * that \"is\" zero.\n *\n * The stub sits on the value-axis base, as thick as the bar would have been,\n * and runs {@link MISSING_BAR_STUB_LENGTH}px toward the middle of the chart\n * area (up from a bottom baseline, down from a top one, right from a left\n * one). Clipped to the chart area.\n */\nexport function drawMissingBarStubs(chart: any): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n const datasets = chart?.data?.datasets;\n if (!ctx || !area || !Array.isArray(datasets)) return;\n\n const left = area.left;\n const top = area.top;\n const right = area.right ?? left + (area.width ?? 0);\n const bottom = area.bottom ?? top + (area.height ?? 0);\n\n let saved = false;\n datasets.forEach((dataset: any, datasetIndex: number) => {\n const meta = chart.getDatasetMeta?.(datasetIndex);\n if (!meta) return;\n const isBar = meta.type === 'bar' || meta.controller?.constructor?.id === 'bar';\n if (!isBar) return;\n // Stacked or overlaid bars: the baseline under a missing segment is the\n // series below, so an outline there would point at the wrong series.\n if (meta.vScale?.options?.stacked || meta.iScale?.options?.stacked) return;\n if (typeof chart.isDatasetVisible === 'function' && !chart.isDatasetVisible(datasetIndex)) {\n return;\n }\n const values: unknown[] = Array.isArray(dataset?.data) ? dataset.data : [];\n const elements: any[] = Array.isArray(meta.data) ? meta.data : [];\n\n values.forEach((value, index) => {\n if (!isMissingChartValue(value)) return;\n const element = elements[index];\n if (!element) return;\n const props = element.getProps?.(['x', 'y', 'base', 'width', 'height'], true) ?? element;\n const { x, y, base, width, height } = props;\n if (![x, y, base].every((n) => Number.isFinite(n))) return;\n const horizontal = element.horizontal === true;\n const thickness = horizontal ? height : width;\n if (!Number.isFinite(thickness) || thickness <= 0) return;\n\n let rect: [number, number, number, number];\n if (horizontal) {\n const dir = base < (left + right) / 2 ? 1 : -1;\n rect = [Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), y - thickness / 2, MISSING_BAR_STUB_LENGTH, thickness];\n } else {\n const dir = base > (top + bottom) / 2 ? -1 : 1;\n rect = [x - thickness / 2, Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), thickness, MISSING_BAR_STUB_LENGTH];\n }\n\n if (!saved) {\n ctx.save();\n ctx.beginPath();\n ctx.rect(left, top, right - left, bottom - top);\n ctx.clip();\n saved = true;\n }\n ctx.strokeStyle = colorAt(dataset?.borderColor, index) ?? MISSING_BAR_FALLBACK_COLOR;\n ctx.lineWidth = 1;\n ctx.setLineDash(STUB_DASH);\n ctx.strokeRect(...rect);\n });\n });\n if (saved) {\n ctx.setLineDash?.([]);\n ctx.restore();\n }\n}\n\n/** Draws `text` centred in the chart area (a chart with nothing to plot). */\nexport function drawNoDataText(chart: any, text: string, fontFamily?: string): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n if (!ctx || !area || !text) return;\n const cx = (area.left + (area.right ?? area.left + (area.width ?? 0))) / 2;\n const cy = (area.top + (area.bottom ?? area.top + (area.height ?? 0))) / 2;\n ctx.save();\n ctx.font = `12px ${fontFamily || 'sans-serif'}`;\n ctx.fillStyle = NO_DATA_TEXT_COLOR;\n ctx.textAlign = 'center';\n ctx.textBaseline = 'middle';\n ctx.fillText(text, cx, cy);\n ctx.restore();\n}\n\n/**\n * The per-chart plugin object. Passed as `config.plugins = [plugin]`: Chart.js\n * scopes it to that one chart. Both hooks swallow their own errors — a\n * decoration must never take the chart down.\n */\nexport function createMissingValuesPlugin(options: MissingValuesPluginOptions) {\n return {\n id: 'mcpuiMissingValues',\n afterDatasetsDraw(chart: any) {\n try {\n drawMissingBarStubs(chart);\n if (options.allMissing) {\n drawNoDataText(chart, options.getNoDataText(), options.getFontFamily?.());\n }\n } catch {\n // Cosmetic layer: never break the chart.\n }\n },\n };\n}\n"],"names":["formatMCPUIString","isMissingChartValue","_a","_b"],"mappings":";;;;AA0CO,MAAM,0BAA0B;AAEhC,MAAM,6BAA6B;AAEnC,MAAM,qBAAqB;AAClC,MAAM,YAAY,CAAC,GAAG,CAAC;AAGvB,MAAM,oBAAoB,oBAAI,IAAI,CAAC,WAAW,QAAQ,CAAC;AAchD,SAAS,eAAe,SAAuB;;AACpD,SAAO,UAAQ,8CAAS,WAAT,mBAAiB,MAAjB,mBAAoB,cAAW,8CAAS,WAAT,mBAAiB,MAAjB,mBAAoB,QAAO;AAC3E;AAGO,SAAS,gBAAgB,WAA+B,SAAgC;AAC7F,MAAI,cAAc,MAAO,QAAO,eAAe,OAAO,IAAI,YAAY;AACtE,MAAI,cAAc,aAAa,cAAc,SAAU,QAAO;AAC9D,SAAO;AACT;AASO,SAAS,sBAAwD,MAAY;AAClF,QAAM,WAAW,MAAM,QAAQ,6BAAM,QAAQ,IAAI,KAAK,WAAW;AACjE,MAAI,CAAC,SAAU,QAAO;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,SAAS;AAAA,MAAI,CAAC,YACtB,YAAY,QAAQ,OAAO,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MAAI,YAAY;AAChB,MAAI,eAAe;AACnB,MAAI,SAAS,MAAM,IAAI,EAAE;AACzB,MAAI,QAAA;AACN;AAOO,SAAS,0BAA0B,SAAqC;AAC7E,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,kBAAkB,OAAY;;AAC5B,UAAI;AACF,4BAAoB,KAAK;AACzB,YAAI,QAAQ,YAAY;AACtB,yBAAe,OAAO,QAAQ,cAAA,IAAiB,aAAQ,kBAAR,gCAAyB;AAAA,QAC1E;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EAAA;AAEJ;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"chart-missing-plugin.cjs","sources":["../../src/components/chart-missing-plugin.ts"],"sourcesContent":["/**\n * Missing values in a Chart.js chart (v6.24.0) — everything the renderer adds\n * to its Chart.js config when a payload says a value is MISSING (`null`).\n *\n * The rule: absence is never zero. Chart.js already keeps the slot of a `null`\n * (no label dropped) and draws nothing for it; what it does not do is make the\n * absence READABLE. A null bar is a zero-height bar that is skipped when\n * drawn, a null line point is a hole the line may bridge (`spanGaps`), and the\n * legend, tooltip and axis know nothing of either. This module supplies:\n *\n * - {@link createMissingValuesPlugin} — a PER-CHART plugin (never\n * `Chart.register`ed, so it can leak into no other chart) that outlines a\n * dashed stub where a bar should have been (not on stacked or overlaid\n * bars, whose baseline belongs to another series), and says \"no data\" on a\n * chart with nothing to draw;\n * - {@link createMissingLegendGenerator} — marks a fully-missing series in the\n * legend;\n * - {@link createTooltipLabel} — names a missing value, and appends the unit;\n * - {@link withDatasetsNoGapSpan} — the shallow-cloned data with\n * `spanGaps: false`;\n * - {@link applyUnitAxisTitle} — the unit as the value axis title.\n *\n * Runtime-free on purpose (no `solid-js`, no `chart.js` import): the renderer\n * hands in the Chart.js pieces it loaded and the chrome strings (lazily, as\n * getters, so a late locale change is honoured at draw time). Every function\n * is defensive — a drawing hook that throws would blank the whole chart.\n *\n * Chart.js 4.5.1 facts this relies on (verified in `dist/chart.js`):\n * - a bar whose parsed value is `null` gets `base = head = vScale.getBasePixel()`\n * and no `skip` flag (BarController.updateElements), and `BarController.draw`\n * skips it (`getParsed(i)[vScale.axis] !== null`) — so nothing is painted;\n * - the bar element still carries its true index-axis thickness (`width` for a\n * vertical bar, `height` for a horizontal one).\n */\n\nimport type { MCPUIStrings } from '../context/MCPUIStringsContext';\nimport { formatMCPUIString } from '../utils/format-string';\nimport { isMissingChartValue } from '../utils/missing-value';\n\ntype Strings = Required<MCPUIStrings>;\n\n/** Length, in px along the value axis, of the dashed stub of a missing bar. */\nexport const MISSING_BAR_STUB_LENGTH = 12;\n/** Stroke of the stub when the dataset names no border colour. */\nexport const MISSING_BAR_FALLBACK_COLOR = '#9ca3af';\n/** Colour of the centred \"no data\" text. */\nexport const NO_DATA_TEXT_COLOR = '#6b7280';\nconst STUB_DASH = [4, 3];\n\n/** Chart types whose value axis is `y` and whose points are `{x, y}`. */\nconst POINT_CHART_TYPES = new Set(['scatter', 'bubble']);\n\n/**\n * The category of convention line a chart shows under its canvas:\n * `'gaps'` (a line breaks), `'bars'` (a dashed outline stands in for the\n * bar) or `'omitted'` (nothing is drawn: scatter, bubble, stacked bars).\n */\nexport type MissingNoteKind = 'gaps' | 'bars' | 'omitted';\n\n/**\n * Whether a bar chart's bars are stacked or overlaid (`stacked` on either\n * axis). A missing bar there has no slot of its own at the baseline — the\n * baseline belongs to the series below — so no dashed outline is drawn.\n */\nexport function isStackedChart(options: any): boolean {\n return Boolean(options?.scales?.x?.stacked || options?.scales?.y?.stacked);\n}\n\n/** Which convention note a chart gets: how ITS missing values are drawn. */\nexport function missingNoteKind(chartType: string | undefined, options?: any): MissingNoteKind {\n if (chartType === 'bar') return isStackedChart(options) ? 'omitted' : 'bars';\n if (chartType === 'scatter' || chartType === 'bubble') return 'omitted';\n return 'gaps';\n}\n\n// ─── Data ──────────────────────────────────────────────────────────────────\n\n/**\n * Chart.js data with every dataset shallow-cloned and `spanGaps: false`, so a\n * line breaks at a missing value instead of joining its neighbours. Never\n * mutates its input; `labels` and every other key are carried by reference.\n */\nexport function withDatasetsNoGapSpan<D extends { datasets?: unknown }>(data: D): D {\n const datasets = Array.isArray(data?.datasets) ? data.datasets : null;\n if (!datasets) return data;\n return {\n ...data,\n datasets: datasets.map((dataset: unknown) =>\n dataset !== null && typeof dataset === 'object'\n ? { ...(dataset as object), spanGaps: false }\n : dataset\n ),\n };\n}\n\n// ─── Legend ────────────────────────────────────────────────────────────────\n\ntype LegendGenerator = (chart: any) => any[];\n\n/**\n * Wraps a Chart.js legend label generator so a fully-missing dataset reads\n * `\"{series} (no data)\"` (`strings.chartLegendNoData`). Every other item is\n * passed through untouched.\n */\nexport function createMissingLegendGenerator(\n base: LegendGenerator,\n fullyMissing: readonly boolean[],\n getStrings: () => Strings\n): LegendGenerator {\n return function generateLabels(this: unknown, chart: any) {\n const items = base.call(this, chart);\n if (!Array.isArray(items)) return items;\n return items.map((item) => {\n const index = item?.datasetIndex;\n if (typeof index !== 'number' || !fullyMissing[index]) return item;\n const text = typeof item.text === 'string' ? item.text : String(item.text ?? '');\n return {\n ...item,\n text: formatMCPUIString(getStrings().chartLegendNoData, { series: text }),\n };\n });\n };\n}\n\n// ─── Tooltip ───────────────────────────────────────────────────────────────\n\n/** Whether a Chart.js tooltip item stands for a missing value. */\nexport function isMissingTooltipItem(item: any): boolean {\n if (item === null || item === undefined) return false;\n if (item.raw === null || item.raw === undefined || isMissingChartValue(item.raw)) return true;\n const parsed = item.parsed;\n if (parsed !== null && typeof parsed === 'object') {\n const chartType = item.chart?.config?.type;\n const valueKey =\n chartType === 'radar' ? 'r' : item.chart?.options?.indexAxis === 'y' ? 'x' : 'y';\n if (valueKey in parsed && parsed[valueKey] === null) return true;\n }\n return false;\n}\n\n/**\n * Tooltip `label` callback: names a missing value (`\"{series}: Missing\n * value\"`) and, with a `unit`, appends it to a present one. Otherwise it is\n * Chart.js's default composition (dataset label, `\": \"`, formatted value) —\n * including its `mode: 'dataset'` branch, which prefixes the CATEGORY label\n * instead, since every item of that tooltip belongs to the same dataset.\n * Hence a regular function: Chart.js calls it with the tooltip as `this`.\n *\n * `unit` is left off scatter and bubble tooltips: their formatted value is the\n * pair `(x, y)`, to which one unit does not belong.\n */\nexport function createTooltipLabel(\n getStrings: () => Strings,\n unit: string | undefined,\n chartType: string | undefined\n): (this: any, item: any) => string {\n const applyUnit = unit !== undefined && !POINT_CHART_TYPES.has(chartType ?? '');\n return function label(this: any, item: any) {\n const strings = getStrings();\n const prefixLabel = this?.options?.mode === 'dataset' ? item?.label : item?.dataset?.label;\n const prefix = typeof prefixLabel === 'string' && prefixLabel !== '' ? `${prefixLabel}: ` : '';\n\n if (isMissingTooltipItem(item)) return `${prefix}${strings.missingValue}`;\n\n const formatted = item?.formattedValue;\n if (formatted === null || formatted === undefined) return prefix;\n const value = applyUnit\n ? formatMCPUIString(strings.chartValueWithUnit, { value: formatted, unit: unit as string })\n : String(formatted);\n return `${prefix}${value}`;\n };\n}\n\n// ─── Axis ──────────────────────────────────────────────────────────────────\n\n/**\n * Sets the chart's `unit` as the title of its value axis, in place on the\n * `options` object the renderer just built (never on the payload's).\n *\n * Only bar, line, scatter and bubble have a value axis to title. The value\n * axis is `y`, or `x` when the index axis is `y` (a horizontal bar or line).\n * An existing `scales[axis].title` is the payload's own word and is kept; the\n * rest of the scale config (a `timeAxis` block sets `scales.x`) is kept too.\n */\nexport function applyUnitAxisTitle(\n options: any,\n chartType: string | undefined,\n unit: string | undefined\n): void {\n if (unit === undefined) return;\n if (chartType !== 'bar' && chartType !== 'line' && !POINT_CHART_TYPES.has(chartType ?? '')) {\n return;\n }\n const horizontal = (chartType === 'bar' || chartType === 'line') && options?.indexAxis === 'y';\n const axis = horizontal ? 'x' : 'y';\n if (options.scales?.[axis]?.title !== undefined) return;\n options.scales = {\n ...options.scales,\n [axis]: { ...options.scales?.[axis], title: { display: true, text: unit } },\n };\n}\n\n// ─── Plugin ────────────────────────────────────────────────────────────────\n\nexport interface MissingValuesPluginOptions {\n /** At least one dataset and every one of them has no observed value. */\n allMissing: boolean;\n /** Lazy: read at draw time. */\n getNoDataText: () => string;\n /** Lazy: `Chart.defaults.font.family`, when the build exposes it. */\n getFontFamily?: () => string | undefined;\n /** Lazy host theme override; omission retains the historical grey. */\n getTextColor?: () => string | undefined;\n}\n\n/** A dataset colour for entry `index`, as a string, or `undefined`. */\nfunction colorAt(color: unknown, index: number): string | undefined {\n if (typeof color === 'string' && color !== '') return color;\n if (Array.isArray(color) && color.length > 0) {\n const picked = color[index % color.length];\n return typeof picked === 'string' && picked !== '' ? picked : undefined;\n }\n return undefined;\n}\n\n/**\n * Draws a dashed outline stub for every missing bar of every visible,\n * non-stacked bar dataset, so a missing value is a visible mark, not a bar\n * that \"is\" zero.\n *\n * The stub sits on the value-axis base, as thick as the bar would have been,\n * and runs {@link MISSING_BAR_STUB_LENGTH}px toward the middle of the chart\n * area (up from a bottom baseline, down from a top one, right from a left\n * one). Clipped to the chart area.\n */\nexport function drawMissingBarStubs(chart: any): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n const datasets = chart?.data?.datasets;\n if (!ctx || !area || !Array.isArray(datasets)) return;\n\n const left = area.left;\n const top = area.top;\n const right = area.right ?? left + (area.width ?? 0);\n const bottom = area.bottom ?? top + (area.height ?? 0);\n\n let saved = false;\n datasets.forEach((dataset: any, datasetIndex: number) => {\n const meta = chart.getDatasetMeta?.(datasetIndex);\n if (!meta) return;\n const isBar = meta.type === 'bar' || meta.controller?.constructor?.id === 'bar';\n if (!isBar) return;\n // Stacked or overlaid bars: the baseline under a missing segment is the\n // series below, so an outline there would point at the wrong series.\n if (meta.vScale?.options?.stacked || meta.iScale?.options?.stacked) return;\n if (typeof chart.isDatasetVisible === 'function' && !chart.isDatasetVisible(datasetIndex)) {\n return;\n }\n const values: unknown[] = Array.isArray(dataset?.data) ? dataset.data : [];\n const elements: any[] = Array.isArray(meta.data) ? meta.data : [];\n\n values.forEach((value, index) => {\n if (!isMissingChartValue(value)) return;\n const element = elements[index];\n if (!element) return;\n const props = element.getProps?.(['x', 'y', 'base', 'width', 'height'], true) ?? element;\n const { x, y, base, width, height } = props;\n if (![x, y, base].every((n) => Number.isFinite(n))) return;\n const horizontal = element.horizontal === true;\n const thickness = horizontal ? height : width;\n if (!Number.isFinite(thickness) || thickness <= 0) return;\n\n let rect: [number, number, number, number];\n if (horizontal) {\n const dir = base < (left + right) / 2 ? 1 : -1;\n rect = [Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), y - thickness / 2, MISSING_BAR_STUB_LENGTH, thickness];\n } else {\n const dir = base > (top + bottom) / 2 ? -1 : 1;\n rect = [x - thickness / 2, Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), thickness, MISSING_BAR_STUB_LENGTH];\n }\n\n if (!saved) {\n ctx.save();\n ctx.beginPath();\n ctx.rect(left, top, right - left, bottom - top);\n ctx.clip();\n saved = true;\n }\n ctx.strokeStyle = colorAt(dataset?.borderColor, index) ?? MISSING_BAR_FALLBACK_COLOR;\n ctx.lineWidth = 1;\n ctx.setLineDash(STUB_DASH);\n ctx.strokeRect(...rect);\n });\n });\n if (saved) {\n ctx.setLineDash?.([]);\n ctx.restore();\n }\n}\n\n/** Draws `text` centred in the chart area (a chart with nothing to plot). */\nexport function drawNoDataText(chart: any, text: string, fontFamily?: string, color?: string): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n if (!ctx || !area || !text) return;\n const cx = (area.left + (area.right ?? area.left + (area.width ?? 0))) / 2;\n const cy = (area.top + (area.bottom ?? area.top + (area.height ?? 0))) / 2;\n ctx.save();\n ctx.font = `12px ${fontFamily || 'sans-serif'}`;\n ctx.fillStyle = color || NO_DATA_TEXT_COLOR;\n ctx.textAlign = 'center';\n ctx.textBaseline = 'middle';\n ctx.fillText(text, cx, cy);\n ctx.restore();\n}\n\n/**\n * The per-chart plugin object. Passed as `config.plugins = [plugin]`: Chart.js\n * scopes it to that one chart. Both hooks swallow their own errors — a\n * decoration must never take the chart down.\n */\nexport function createMissingValuesPlugin(options: MissingValuesPluginOptions) {\n return {\n id: 'mcpuiMissingValues',\n afterDatasetsDraw(chart: any) {\n try {\n drawMissingBarStubs(chart);\n if (options.allMissing) {\n drawNoDataText(chart, options.getNoDataText(), options.getFontFamily?.(), options.getTextColor?.());\n }\n } catch {\n // Cosmetic layer: never break the chart.\n }\n },\n };\n}\n"],"names":["formatMCPUIString","isMissingChartValue","_a","_b"],"mappings":";;;;AA0CO,MAAM,0BAA0B;AAEhC,MAAM,6BAA6B;AAEnC,MAAM,qBAAqB;AAClC,MAAM,YAAY,CAAC,GAAG,CAAC;AAGvB,MAAM,oBAAoB,oBAAI,IAAI,CAAC,WAAW,QAAQ,CAAC;AAchD,SAAS,eAAe,SAAuB;;AACpD,SAAO,UAAQ,8CAAS,WAAT,mBAAiB,MAAjB,mBAAoB,cAAW,8CAAS,WAAT,mBAAiB,MAAjB,mBAAoB,QAAO;AAC3E;AAGO,SAAS,gBAAgB,WAA+B,SAAgC;AAC7F,MAAI,cAAc,MAAO,QAAO,eAAe,OAAO,IAAI,YAAY;AACtE,MAAI,cAAc,aAAa,cAAc,SAAU,QAAO;AAC9D,SAAO;AACT;AASO,SAAS,sBAAwD,MAAY;AAClF,QAAM,WAAW,MAAM,QAAQ,6BAAM,QAAQ,IAAI,KAAK,WAAW;AACjE,MAAI,CAAC,SAAU,QAAO;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,SAAS;AAAA,MAAI,CAAC,YACtB,YAAY,QAAQ,OAAO,YAAY,WACnC,EAAE,GAAI,SAAoB,UAAU,UACpC;AAAA,IAAA;AAAA,EACN;AAEJ;AAWO,SAAS,6BACd,MACA,cACA,YACiB;AACjB,SAAO,SAAS,eAA8B,OAAY;AACxD,UAAM,QAAQ,KAAK,KAAK,MAAM,KAAK;AACnC,QAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO;AAClC,WAAO,MAAM,IAAI,CAAC,SAAS;AACzB,YAAM,QA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AiB,aAAQ,kBAAR,mCAA2B,aAAQ,iBAAR,gCAAwB;AAAA,QACpG;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EAAA;AAEJ;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Missing values in a Chart.js chart (v6.24.0) — everything the renderer adds
|
|
3
|
+
* to its Chart.js config when a payload says a value is MISSING (`null`).
|
|
4
|
+
*
|
|
5
|
+
* The rule: absence is never zero. Chart.js already keeps the slot of a `null`
|
|
6
|
+
* (no label dropped) and draws nothing for it; what it does not do is make the
|
|
7
|
+
* absence READABLE. A null bar is a zero-height bar that is skipped when
|
|
8
|
+
* drawn, a null line point is a hole the line may bridge (`spanGaps`), and the
|
|
9
|
+
* legend, tooltip and axis know nothing of either. This module supplies:
|
|
10
|
+
*
|
|
11
|
+
* - {@link createMissingValuesPlugin} — a PER-CHART plugin (never
|
|
12
|
+
* `Chart.register`ed, so it can leak into no other chart) that outlines a
|
|
13
|
+
* dashed stub where a bar should have been (not on stacked or overlaid
|
|
14
|
+
* bars, whose baseline belongs to another series), and says "no data" on a
|
|
15
|
+
* chart with nothing to draw;
|
|
16
|
+
* - {@link createMissingLegendGenerator} — marks a fully-missing series in the
|
|
17
|
+
* legend;
|
|
18
|
+
* - {@link createTooltipLabel} — names a missing value, and appends the unit;
|
|
19
|
+
* - {@link withDatasetsNoGapSpan} — the shallow-cloned data with
|
|
20
|
+
* `spanGaps: false`;
|
|
21
|
+
* - {@link applyUnitAxisTitle} — the unit as the value axis title.
|
|
22
|
+
*
|
|
23
|
+
* Runtime-free on purpose (no `solid-js`, no `chart.js` import): the renderer
|
|
24
|
+
* hands in the Chart.js pieces it loaded and the chrome strings (lazily, as
|
|
25
|
+
* getters, so a late locale change is honoured at draw time). Every function
|
|
26
|
+
* is defensive — a drawing hook that throws would blank the whole chart.
|
|
27
|
+
*
|
|
28
|
+
* Chart.js 4.5.1 facts this relies on (verified in `dist/chart.js`):
|
|
29
|
+
* - a bar whose parsed value is `null` gets `base = head = vScale.getBasePixel()`
|
|
30
|
+
* and no `skip` flag (BarController.updateElements), and `BarController.draw`
|
|
31
|
+
* skips it (`getParsed(i)[vScale.axis] !== null`) — so nothing is painted;
|
|
32
|
+
* - the bar element still carries its true index-axis thickness (`width` for a
|
|
33
|
+
* vertical bar, `height` for a horizontal one).
|
|
34
|
+
*/
|
|
35
|
+
import type { MCPUIStrings } from "../context/MCPUIStringsContext.cjs";
|
|
36
|
+
type Strings = Required<MCPUIStrings>;
|
|
37
|
+
/** Length, in px along the value axis, of the dashed stub of a missing bar. */
|
|
38
|
+
export declare const MISSING_BAR_STUB_LENGTH = 12;
|
|
39
|
+
/** Stroke of the stub when the dataset names no border colour. */
|
|
40
|
+
export declare const MISSING_BAR_FALLBACK_COLOR = "#9ca3af";
|
|
41
|
+
/** Colour of the centred "no data" text. */
|
|
42
|
+
export declare const NO_DATA_TEXT_COLOR = "#6b7280";
|
|
43
|
+
/**
|
|
44
|
+
* The category of convention line a chart shows under its canvas:
|
|
45
|
+
* `'gaps'` (a line breaks), `'bars'` (a dashed outline stands in for the
|
|
46
|
+
* bar) or `'omitted'` (nothing is drawn: scatter, bubble, stacked bars).
|
|
47
|
+
*/
|
|
48
|
+
export type MissingNoteKind = 'gaps' | 'bars' | 'omitted';
|
|
49
|
+
/**
|
|
50
|
+
* Whether a bar chart's bars are stacked or overlaid (`stacked` on either
|
|
51
|
+
* axis). A missing bar there has no slot of its own at the baseline — the
|
|
52
|
+
* baseline belongs to the series below — so no dashed outline is drawn.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isStackedChart(options: any): boolean;
|
|
55
|
+
/** Which convention note a chart gets: how ITS missing values are drawn. */
|
|
56
|
+
export declare function missingNoteKind(chartType: string | undefined, options?: any): MissingNoteKind;
|
|
57
|
+
/**
|
|
58
|
+
* Chart.js data with every dataset shallow-cloned and `spanGaps: false`, so a
|
|
59
|
+
* line breaks at a missing value instead of joining its neighbours. Never
|
|
60
|
+
* mutates its input; `labels` and every other key are carried by reference.
|
|
61
|
+
*/
|
|
62
|
+
export declare function withDatasetsNoGapSpan<D extends {
|
|
63
|
+
datasets?: unknown;
|
|
64
|
+
}>(data: D): D;
|
|
65
|
+
type LegendGenerator = (chart: any) => any[];
|
|
66
|
+
/**
|
|
67
|
+
* Wraps a Chart.js legend label generator so a fully-missing dataset reads
|
|
68
|
+
* `"{series} (no data)"` (`strings.chartLegendNoData`). Every other item is
|
|
69
|
+
* passed through untouched.
|
|
70
|
+
*/
|
|
71
|
+
export declare function createMissingLegendGenerator(base: LegendGenerator, fullyMissing: readonly boolean[], getStrings: () => Strings): LegendGenerator;
|
|
72
|
+
/** Whether a Chart.js tooltip item stands for a missing value. */
|
|
73
|
+
export declare function isMissingTooltipItem(item: any): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Tooltip `label` callback: names a missing value (`"{series}: Missing
|
|
76
|
+
* value"`) and, with a `unit`, appends it to a present one. Otherwise it is
|
|
77
|
+
* Chart.js's default composition (dataset label, `": "`, formatted value) —
|
|
78
|
+
* including its `mode: 'dataset'` branch, which prefixes the CATEGORY label
|
|
79
|
+
* instead, since every item of that tooltip belongs to the same dataset.
|
|
80
|
+
* Hence a regular function: Chart.js calls it with the tooltip as `this`.
|
|
81
|
+
*
|
|
82
|
+
* `unit` is left off scatter and bubble tooltips: their formatted value is the
|
|
83
|
+
* pair `(x, y)`, to which one unit does not belong.
|
|
84
|
+
*/
|
|
85
|
+
export declare function createTooltipLabel(getStrings: () => Strings, unit: string | undefined, chartType: string | undefined): (this: any, item: any) => string;
|
|
86
|
+
/**
|
|
87
|
+
* Sets the chart's `unit` as the title of its value axis, in place on the
|
|
88
|
+
* `options` object the renderer just built (never on the payload's).
|
|
89
|
+
*
|
|
90
|
+
* Only bar, line, scatter and bubble have a value axis to title. The value
|
|
91
|
+
* axis is `y`, or `x` when the index axis is `y` (a horizontal bar or line).
|
|
92
|
+
* An existing `scales[axis].title` is the payload's own word and is kept; the
|
|
93
|
+
* rest of the scale config (a `timeAxis` block sets `scales.x`) is kept too.
|
|
94
|
+
*/
|
|
95
|
+
export declare function applyUnitAxisTitle(options: any, chartType: string | undefined, unit: string | undefined): void;
|
|
96
|
+
export interface MissingValuesPluginOptions {
|
|
97
|
+
/** At least one dataset and every one of them has no observed value. */
|
|
98
|
+
allMissing: boolean;
|
|
99
|
+
/** Lazy: read at draw time. */
|
|
100
|
+
getNoDataText: () => string;
|
|
101
|
+
/** Lazy: `Chart.defaults.font.family`, when the build exposes it. */
|
|
102
|
+
getFontFamily?: () => string | undefined;
|
|
103
|
+
/** Lazy host theme override; omission retains the historical grey. */
|
|
104
|
+
getTextColor?: () => string | undefined;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Draws a dashed outline stub for every missing bar of every visible,
|
|
108
|
+
* non-stacked bar dataset, so a missing value is a visible mark, not a bar
|
|
109
|
+
* that "is" zero.
|
|
110
|
+
*
|
|
111
|
+
* The stub sits on the value-axis base, as thick as the bar would have been,
|
|
112
|
+
* and runs {@link MISSING_BAR_STUB_LENGTH}px toward the middle of the chart
|
|
113
|
+
* area (up from a bottom baseline, down from a top one, right from a left
|
|
114
|
+
* one). Clipped to the chart area.
|
|
115
|
+
*/
|
|
116
|
+
export declare function drawMissingBarStubs(chart: any): void;
|
|
117
|
+
/** Draws `text` centred in the chart area (a chart with nothing to plot). */
|
|
118
|
+
export declare function drawNoDataText(chart: any, text: string, fontFamily?: string, color?: string): void;
|
|
119
|
+
/**
|
|
120
|
+
* The per-chart plugin object. Passed as `config.plugins = [plugin]`: Chart.js
|
|
121
|
+
* scopes it to that one chart. Both hooks swallow their own errors — a
|
|
122
|
+
* decoration must never take the chart down.
|
|
123
|
+
*/
|
|
124
|
+
export declare function createMissingValuesPlugin(options: MissingValuesPluginOptions): {
|
|
125
|
+
id: string;
|
|
126
|
+
afterDatasetsDraw(chart: any): void;
|
|
127
|
+
};
|
|
128
|
+
export {};
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
* - the bar element still carries its true index-axis thickness (`width` for a
|
|
33
33
|
* vertical bar, `height` for a horizontal one).
|
|
34
34
|
*/
|
|
35
|
-
import type { MCPUIStrings } from
|
|
35
|
+
import type { MCPUIStrings } from "../context/MCPUIStringsContext.js";
|
|
36
36
|
type Strings = Required<MCPUIStrings>;
|
|
37
37
|
/** Length, in px along the value axis, of the dashed stub of a missing bar. */
|
|
38
38
|
export declare const MISSING_BAR_STUB_LENGTH = 12;
|
|
@@ -100,6 +100,8 @@ export interface MissingValuesPluginOptions {
|
|
|
100
100
|
getNoDataText: () => string;
|
|
101
101
|
/** Lazy: `Chart.defaults.font.family`, when the build exposes it. */
|
|
102
102
|
getFontFamily?: () => string | undefined;
|
|
103
|
+
/** Lazy host theme override; omission retains the historical grey. */
|
|
104
|
+
getTextColor?: () => string | undefined;
|
|
103
105
|
}
|
|
104
106
|
/**
|
|
105
107
|
* Draws a dashed outline stub for every missing bar of every visible,
|
|
@@ -113,7 +115,7 @@ export interface MissingValuesPluginOptions {
|
|
|
113
115
|
*/
|
|
114
116
|
export declare function drawMissingBarStubs(chart: any): void;
|
|
115
117
|
/** Draws `text` centred in the chart area (a chart with nothing to plot). */
|
|
116
|
-
export declare function drawNoDataText(chart: any, text: string, fontFamily?: string): void;
|
|
118
|
+
export declare function drawNoDataText(chart: any, text: string, fontFamily?: string, color?: string): void;
|
|
117
119
|
/**
|
|
118
120
|
* The per-chart plugin object. Passed as `config.plugins = [plugin]`: Chart.js
|
|
119
121
|
* scopes it to that one chart. Both hooks swallow their own errors — a
|
|
@@ -124,4 +126,3 @@ export declare function createMissingValuesPlugin(options: MissingValuesPluginOp
|
|
|
124
126
|
afterDatasetsDraw(chart: any): void;
|
|
125
127
|
};
|
|
126
128
|
export {};
|
|
127
|
-
//# sourceMappingURL=chart-missing-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-missing-plugin.d.ts","sourceRoot":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alG;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,0BAA0B;;6BAGhD,GAAG;EAW/B"}
|
|
@@ -147,7 +147,7 @@ function drawMissingBarStubs(chart) {
|
|
|
147
147
|
ctx.restore();
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
function drawNoDataText(chart, text, fontFamily) {
|
|
150
|
+
function drawNoDataText(chart, text, fontFamily, color) {
|
|
151
151
|
const ctx = chart == null ? void 0 : chart.ctx;
|
|
152
152
|
const area = chart == null ? void 0 : chart.chartArea;
|
|
153
153
|
if (!ctx || !area || !text) return;
|
|
@@ -155,7 +155,7 @@ function drawNoDataText(chart, text, fontFamily) {
|
|
|
155
155
|
const cy = (area.top + (area.bottom ?? area.top + (area.height ?? 0))) / 2;
|
|
156
156
|
ctx.save();
|
|
157
157
|
ctx.font = `12px ${fontFamily || "sans-serif"}`;
|
|
158
|
-
ctx.fillStyle = NO_DATA_TEXT_COLOR;
|
|
158
|
+
ctx.fillStyle = color || NO_DATA_TEXT_COLOR;
|
|
159
159
|
ctx.textAlign = "center";
|
|
160
160
|
ctx.textBaseline = "middle";
|
|
161
161
|
ctx.fillText(text, cx, cy);
|
|
@@ -165,11 +165,11 @@ function createMissingValuesPlugin(options) {
|
|
|
165
165
|
return {
|
|
166
166
|
id: "mcpuiMissingValues",
|
|
167
167
|
afterDatasetsDraw(chart) {
|
|
168
|
-
var _a;
|
|
168
|
+
var _a, _b;
|
|
169
169
|
try {
|
|
170
170
|
drawMissingBarStubs(chart);
|
|
171
171
|
if (options.allMissing) {
|
|
172
|
-
drawNoDataText(chart, options.getNoDataText(), (_a = options.getFontFamily) == null ? void 0 : _a.call(options));
|
|
172
|
+
drawNoDataText(chart, options.getNoDataText(), (_a = options.getFontFamily) == null ? void 0 : _a.call(options), (_b = options.getTextColor) == null ? void 0 : _b.call(options));
|
|
173
173
|
}
|
|
174
174
|
} catch {
|
|
175
175
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-missing-plugin.js","sources":["../../src/components/chart-missing-plugin.ts"],"sourcesContent":["/**\n * Missing values in a Chart.js chart (v6.24.0) — everything the renderer adds\n * to its Chart.js config when a payload says a value is MISSING (`null`).\n *\n * The rule: absence is never zero. Chart.js already keeps the slot of a `null`\n * (no label dropped) and draws nothing for it; what it does not do is make the\n * absence READABLE. A null bar is a zero-height bar that is skipped when\n * drawn, a null line point is a hole the line may bridge (`spanGaps`), and the\n * legend, tooltip and axis know nothing of either. This module supplies:\n *\n * - {@link createMissingValuesPlugin} — a PER-CHART plugin (never\n * `Chart.register`ed, so it can leak into no other chart) that outlines a\n * dashed stub where a bar should have been (not on stacked or overlaid\n * bars, whose baseline belongs to another series), and says \"no data\" on a\n * chart with nothing to draw;\n * - {@link createMissingLegendGenerator} — marks a fully-missing series in the\n * legend;\n * - {@link createTooltipLabel} — names a missing value, and appends the unit;\n * - {@link withDatasetsNoGapSpan} — the shallow-cloned data with\n * `spanGaps: false`;\n * - {@link applyUnitAxisTitle} — the unit as the value axis title.\n *\n * Runtime-free on purpose (no `solid-js`, no `chart.js` import): the renderer\n * hands in the Chart.js pieces it loaded and the chrome strings (lazily, as\n * getters, so a late locale change is honoured at draw time). Every function\n * is defensive — a drawing hook that throws would blank the whole chart.\n *\n * Chart.js 4.5.1 facts this relies on (verified in `dist/chart.js`):\n * - a bar whose parsed value is `null` gets `base = head = vScale.getBasePixel()`\n * and no `skip` flag (BarController.updateElements), and `BarController.draw`\n * skips it (`getParsed(i)[vScale.axis] !== null`) — so nothing is painted;\n * - the bar element still carries its true index-axis thickness (`width` for a\n * vertical bar, `height` for a horizontal one).\n */\n\nimport type { MCPUIStrings } from '../context/MCPUIStringsContext';\nimport { formatMCPUIString } from '../utils/format-string';\nimport { isMissingChartValue } from '../utils/missing-value';\n\ntype Strings = Required<MCPUIStrings>;\n\n/** Length, in px along the value axis, of the dashed stub of a missing bar. */\nexport const MISSING_BAR_STUB_LENGTH = 12;\n/** Stroke of the stub when the dataset names no border colour. */\nexport const MISSING_BAR_FALLBACK_COLOR = '#9ca3af';\n/** Colour of the centred \"no data\" text. */\nexport const NO_DATA_TEXT_COLOR = '#6b7280';\nconst STUB_DASH = [4, 3];\n\n/** Chart types whose value axis is `y` and whose points are `{x, y}`. */\nconst POINT_CHART_TYPES = new Set(['scatter', 'bubble']);\n\n/**\n * The category of convention line a chart shows under its canvas:\n * `'gaps'` (a line breaks), `'bars'` (a dashed outline stands in for the\n * bar) or `'omitted'` (nothing is drawn: scatter, bubble, stacked bars).\n */\nexport type MissingNoteKind = 'gaps' | 'bars' | 'omitted';\n\n/**\n * Whether a bar chart's bars are stacked or overlaid (`stacked` on either\n * axis). A missing bar there has no slot of its own at the baseline — the\n * baseline belongs to the series below — so no dashed outline is drawn.\n */\nexport function isStackedChart(options: any): boolean {\n return Boolean(options?.scales?.x?.stacked || options?.scales?.y?.stacked);\n}\n\n/** Which convention note a chart gets: how ITS missing values are drawn. */\nexport function missingNoteKind(chartType: string | undefined, options?: any): MissingNoteKind {\n if (chartType === 'bar') return isStackedChart(options) ? 'omitted' : 'bars';\n if (chartType === 'scatter' || chartType === 'bubble') return 'omitted';\n return 'gaps';\n}\n\n// ─── Data ──────────────────────────────────────────────────────────────────\n\n/**\n * Chart.js data with every dataset shallow-cloned and `spanGaps: false`, so a\n * line breaks at a missing value instead of joining its neighbours. Never\n * mutates its input; `labels` and every other key are carried by reference.\n */\nexport function withDatasetsNoGapSpan<D extends { datasets?: unknown }>(data: D): D {\n const datasets = Array.isArray(data?.datasets) ? data.datasets : null;\n if (!datasets) return data;\n return {\n ...data,\n datasets: datasets.map((dataset: unknown) =>\n dataset !== null && typeof dataset === 'object'\n ? { ...(dataset as object), spanGaps: false }\n : dataset\n ),\n };\n}\n\n// ─── Legend ────────────────────────────────────────────────────────────────\n\ntype LegendGenerator = (chart: any) => any[];\n\n/**\n * Wraps a Chart.js legend label generator so a fully-missing dataset reads\n * `\"{series} (no data)\"` (`strings.chartLegendNoData`). Every other item is\n * passed through untouched.\n */\nexport function createMissingLegendGenerator(\n base: LegendGenerator,\n fullyMissing: readonly boolean[],\n getStrings: () => Strings\n): LegendGenerator {\n return function generateLabels(this: unknown, chart: any) {\n const items = base.call(this, chart);\n if (!Array.isArray(items)) return items;\n return items.map((item) => {\n const index = item?.datasetIndex;\n if (typeof index !== 'number' || !fullyMissing[index]) return item;\n const text = typeof item.text === 'string' ? item.text : String(item.text ?? '');\n return {\n ...item,\n text: formatMCPUIString(getStrings().chartLegendNoData, { series: text }),\n };\n });\n };\n}\n\n// ─── Tooltip ───────────────────────────────────────────────────────────────\n\n/** Whether a Chart.js tooltip item stands for a missing value. */\nexport function isMissingTooltipItem(item: any): boolean {\n if (item === null || item === undefined) return false;\n if (item.raw === null || item.raw === undefined || isMissingChartValue(item.raw)) return true;\n const parsed = item.parsed;\n if (parsed !== null && typeof parsed === 'object') {\n const chartType = item.chart?.config?.type;\n const valueKey =\n chartType === 'radar' ? 'r' : item.chart?.options?.indexAxis === 'y' ? 'x' : 'y';\n if (valueKey in parsed && parsed[valueKey] === null) return true;\n }\n return false;\n}\n\n/**\n * Tooltip `label` callback: names a missing value (`\"{series}: Missing\n * value\"`) and, with a `unit`, appends it to a present one. Otherwise it is\n * Chart.js's default composition (dataset label, `\": \"`, formatted value) —\n * including its `mode: 'dataset'` branch, which prefixes the CATEGORY label\n * instead, since every item of that tooltip belongs to the same dataset.\n * Hence a regular function: Chart.js calls it with the tooltip as `this`.\n *\n * `unit` is left off scatter and bubble tooltips: their formatted value is the\n * pair `(x, y)`, to which one unit does not belong.\n */\nexport function createTooltipLabel(\n getStrings: () => Strings,\n unit: string | undefined,\n chartType: string | undefined\n): (this: any, item: any) => string {\n const applyUnit = unit !== undefined && !POINT_CHART_TYPES.has(chartType ?? '');\n return function label(this: any, item: any) {\n const strings = getStrings();\n const prefixLabel = this?.options?.mode === 'dataset' ? item?.label : item?.dataset?.label;\n const prefix = typeof prefixLabel === 'string' && prefixLabel !== '' ? `${prefixLabel}: ` : '';\n\n if (isMissingTooltipItem(item)) return `${prefix}${strings.missingValue}`;\n\n const formatted = item?.formattedValue;\n if (formatted === null || formatted === undefined) return prefix;\n const value = applyUnit\n ? formatMCPUIString(strings.chartValueWithUnit, { value: formatted, unit: unit as string })\n : String(formatted);\n return `${prefix}${value}`;\n };\n}\n\n// ─── Axis ──────────────────────────────────────────────────────────────────\n\n/**\n * Sets the chart's `unit` as the title of its value axis, in place on the\n * `options` object the renderer just built (never on the payload's).\n *\n * Only bar, line, scatter and bubble have a value axis to title. The value\n * axis is `y`, or `x` when the index axis is `y` (a horizontal bar or line).\n * An existing `scales[axis].title` is the payload's own word and is kept; the\n * rest of the scale config (a `timeAxis` block sets `scales.x`) is kept too.\n */\nexport function applyUnitAxisTitle(\n options: any,\n chartType: string | undefined,\n unit: string | undefined\n): void {\n if (unit === undefined) return;\n if (chartType !== 'bar' && chartType !== 'line' && !POINT_CHART_TYPES.has(chartType ?? '')) {\n return;\n }\n const horizontal = (chartType === 'bar' || chartType === 'line') && options?.indexAxis === 'y';\n const axis = horizontal ? 'x' : 'y';\n if (options.scales?.[axis]?.title !== undefined) return;\n options.scales = {\n ...options.scales,\n [axis]: { ...options.scales?.[axis], title: { display: true, text: unit } },\n };\n}\n\n// ─── Plugin ────────────────────────────────────────────────────────────────\n\nexport interface MissingValuesPluginOptions {\n /** At least one dataset and every one of them has no observed value. */\n allMissing: boolean;\n /** Lazy: read at draw time. */\n getNoDataText: () => string;\n /** Lazy: `Chart.defaults.font.family`, when the build exposes it. */\n getFontFamily?: () => string | undefined;\n}\n\n/** A dataset colour for entry `index`, as a string, or `undefined`. */\nfunction colorAt(color: unknown, index: number): string | undefined {\n if (typeof color === 'string' && color !== '') return color;\n if (Array.isArray(color) && color.length > 0) {\n const picked = color[index % color.length];\n return typeof picked === 'string' && picked !== '' ? picked : undefined;\n }\n return undefined;\n}\n\n/**\n * Draws a dashed outline stub for every missing bar of every visible,\n * non-stacked bar dataset, so a missing value is a visible mark, not a bar\n * that \"is\" zero.\n *\n * The stub sits on the value-axis base, as thick as the bar would have been,\n * and runs {@link MISSING_BAR_STUB_LENGTH}px toward the middle of the chart\n * area (up from a bottom baseline, down from a top one, right from a left\n * one). Clipped to the chart area.\n */\nexport function drawMissingBarStubs(chart: any): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n const datasets = chart?.data?.datasets;\n if (!ctx || !area || !Array.isArray(datasets)) return;\n\n const left = area.left;\n const top = area.top;\n const right = area.right ?? left + (area.width ?? 0);\n const bottom = area.bottom ?? top + (area.height ?? 0);\n\n let saved = false;\n datasets.forEach((dataset: any, datasetIndex: number) => {\n const meta = chart.getDatasetMeta?.(datasetIndex);\n if (!meta) return;\n const isBar = meta.type === 'bar' || meta.controller?.constructor?.id === 'bar';\n if (!isBar) return;\n // Stacked or overlaid bars: the baseline under a missing segment is the\n // series below, so an outline there would point at the wrong series.\n if (meta.vScale?.options?.stacked || meta.iScale?.options?.stacked) return;\n if (typeof chart.isDatasetVisible === 'function' && !chart.isDatasetVisible(datasetIndex)) {\n return;\n }\n const values: unknown[] = Array.isArray(dataset?.data) ? dataset.data : [];\n const elements: any[] = Array.isArray(meta.data) ? meta.data : [];\n\n values.forEach((value, index) => {\n if (!isMissingChartValue(value)) return;\n const element = elements[index];\n if (!element) return;\n const props = element.getProps?.(['x', 'y', 'base', 'width', 'height'], true) ?? element;\n const { x, y, base, width, height } = props;\n if (![x, y, base].every((n) => Number.isFinite(n))) return;\n const horizontal = element.horizontal === true;\n const thickness = horizontal ? height : width;\n if (!Number.isFinite(thickness) || thickness <= 0) return;\n\n let rect: [number, number, number, number];\n if (horizontal) {\n const dir = base < (left + right) / 2 ? 1 : -1;\n rect = [Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), y - thickness / 2, MISSING_BAR_STUB_LENGTH, thickness];\n } else {\n const dir = base > (top + bottom) / 2 ? -1 : 1;\n rect = [x - thickness / 2, Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), thickness, MISSING_BAR_STUB_LENGTH];\n }\n\n if (!saved) {\n ctx.save();\n ctx.beginPath();\n ctx.rect(left, top, right - left, bottom - top);\n ctx.clip();\n saved = true;\n }\n ctx.strokeStyle = colorAt(dataset?.borderColor, index) ?? MISSING_BAR_FALLBACK_COLOR;\n ctx.lineWidth = 1;\n ctx.setLineDash(STUB_DASH);\n ctx.strokeRect(...rect);\n });\n });\n if (saved) {\n ctx.setLineDash?.([]);\n ctx.restore();\n }\n}\n\n/** Draws `text` centred in the chart area (a chart with nothing to plot). */\nexport function drawNoDataText(chart: any, text: string, fontFamily?: string): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n if (!ctx || !area || !text) return;\n const cx = (area.left + (area.right ?? area.left + (area.width ?? 0))) / 2;\n const cy = (area.top + (area.bottom ?? area.top + (area.height ?? 0))) / 2;\n ctx.save();\n ctx.font = `12px ${fontFamily || 'sans-serif'}`;\n ctx.fillStyle = NO_DATA_TEXT_COLOR;\n ctx.textAlign = 'center';\n ctx.textBaseline = 'middle';\n ctx.fillText(text, cx, cy);\n ctx.restore();\n}\n\n/**\n * The per-chart plugin object. Passed as `config.plugins = [plugin]`: Chart.js\n * scopes it to that one chart. Both hooks swallow their own errors — a\n * decoration must never take the chart down.\n */\nexport function createMissingValuesPlugin(options: MissingValuesPluginOptions) {\n return {\n id: 'mcpuiMissingValues',\n afterDatasetsDraw(chart: any) {\n try {\n drawMissingBarStubs(chart);\n if (options.allMissing) {\n drawNoDataText(chart, options.getNoDataText(), options.getFontFamily?.());\n }\n } catch {\n // Cosmetic layer: never break the chart.\n }\n },\n };\n}\n"],"names":["_a","_b"],"mappings":";;AA0CO,MAAM,0BAA0B;AAEhC,MAAM,6BAA6B;AAEnC,MAAM,qBAAqB;AAClC,MAAM,YAAY,CAAC,GAAG,CAAC;AAGvB,MAAM,oBAAoB,oBAAI,IAAI,CAAC,WAAW,QAAQ,CAAC;AAchD,SAAS,eAAe,SAAuB;;AACpD,SAAO,UAAQ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,OAAO;AACT,cAAI,gBAAJ,6BAAkB;AAClB,QAAI,QAAA;AAAA,EACN;AACF;AAGO,SAAS,eAAe,OAAY,MAAc,YAA2B;AAClF,QAAM,MAAM,+BAAO;AACnB,QAAM,OAAO,+BAAO;AACpB,MAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAM;AAC5B,QAAM,MAAM,KAAK,QAAQ,KAAK,SAAS,KAAK,QAAQ,KAAK,SAAS,OAAO;AACzE,QAAM,MAAM,KAAK,OAAO,KAAK,UAAU,KAAK,OAAO,KAAK,UAAU,OAAO;AACzE,MAAI,KAAA;AACJ,MAAI,OAAO,QAAQ,cAAc,YAAY;AAC7C,MAAI,YAAY;AAChB,MAAI,YAAY;AAChB,MAAI,eAAe;AACnB,MAAI,SAAS,MAAM,IAAI,EAAE;AACzB,MAAI,QAAA;AACN;AAOO,SAAS,0BAA0B,SAAqC;AAC7E,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,kBAAkB,OAAY;;AAC5B,UAAI;AACF,4BAAoB,KAAK;AACzB,YAAI,QAAQ,YAAY;AACtB,yBAAe,OAAO,QAAQ,cAAA,IAAiB,aAAQ,kBAAR,gCAAyB;AAAA,QAC1E;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"chart-missing-plugin.js","sources":["../../src/components/chart-missing-plugin.ts"],"sourcesContent":["/**\n * Missing values in a Chart.js chart (v6.24.0) — everything the renderer adds\n * to its Chart.js config when a payload says a value is MISSING (`null`).\n *\n * The rule: absence is never zero. Chart.js already keeps the slot of a `null`\n * (no label dropped) and draws nothing for it; what it does not do is make the\n * absence READABLE. A null bar is a zero-height bar that is skipped when\n * drawn, a null line point is a hole the line may bridge (`spanGaps`), and the\n * legend, tooltip and axis know nothing of either. This module supplies:\n *\n * - {@link createMissingValuesPlugin} — a PER-CHART plugin (never\n * `Chart.register`ed, so it can leak into no other chart) that outlines a\n * dashed stub where a bar should have been (not on stacked or overlaid\n * bars, whose baseline belongs to another series), and says \"no data\" on a\n * chart with nothing to draw;\n * - {@link createMissingLegendGenerator} — marks a fully-missing series in the\n * legend;\n * - {@link createTooltipLabel} — names a missing value, and appends the unit;\n * - {@link withDatasetsNoGapSpan} — the shallow-cloned data with\n * `spanGaps: false`;\n * - {@link applyUnitAxisTitle} — the unit as the value axis title.\n *\n * Runtime-free on purpose (no `solid-js`, no `chart.js` import): the renderer\n * hands in the Chart.js pieces it loaded and the chrome strings (lazily, as\n * getters, so a late locale change is honoured at draw time). Every function\n * is defensive — a drawing hook that throws would blank the whole chart.\n *\n * Chart.js 4.5.1 facts this relies on (verified in `dist/chart.js`):\n * - a bar whose parsed value is `null` gets `base = head = vScale.getBasePixel()`\n * and no `skip` flag (BarController.updateElements), and `BarController.draw`\n * skips it (`getParsed(i)[vScale.axis] !== null`) — so nothing is painted;\n * - the bar element still carries its true index-axis thickness (`width` for a\n * vertical bar, `height` for a horizontal one).\n */\n\nimport type { MCPUIStrings } from '../context/MCPUIStringsContext';\nimport { formatMCPUIString } from '../utils/format-string';\nimport { isMissingChartValue } from '../utils/missing-value';\n\ntype Strings = Required<MCPUIStrings>;\n\n/** Length, in px along the value axis, of the dashed stub of a missing bar. */\nexport const MISSING_BAR_STUB_LENGTH = 12;\n/** Stroke of the stub when the dataset names no border colour. */\nexport const MISSING_BAR_FALLBACK_COLOR = '#9ca3af';\n/** Colour of the centred \"no data\" text. */\nexport const NO_DATA_TEXT_COLOR = '#6b7280';\nconst STUB_DASH = [4, 3];\n\n/** Chart types whose value axis is `y` and whose points are `{x, y}`. */\nconst POINT_CHART_TYPES = new Set(['scatter', 'bubble']);\n\n/**\n * The category of convention line a chart shows under its canvas:\n * `'gaps'` (a line breaks), `'bars'` (a dashed outline stands in for the\n * bar) or `'omitted'` (nothing is drawn: scatter, bubble, stacked bars).\n */\nexport type MissingNoteKind = 'gaps' | 'bars' | 'omitted';\n\n/**\n * Whether a bar chart's bars are stacked or overlaid (`stacked` on either\n * axis). A missing bar there has no slot of its own at the baseline — the\n * baseline belongs to the series below — so no dashed outline is drawn.\n */\nexport function isStackedChart(options: any): boolean {\n return Boolean(options?.scales?.x?.stacked || options?.scales?.y?.stacked);\n}\n\n/** Which convention note a chart gets: how ITS missing values are drawn. */\nexport function missingNoteKind(chartType: string | undefined, options?: any): MissingNoteKind {\n if (chartType === 'bar') return isStackedChart(options) ? 'omitted' : 'bars';\n if (chartType === 'scatter' || chartType === 'bubble') return 'omitted';\n return 'gaps';\n}\n\n// ─── Data ──────────────────────────────────────────────────────────────────\n\n/**\n * Chart.js data with every dataset shallow-cloned and `spanGaps: false`, so a\n * line breaks at a missing value instead of joining its neighbours. Never\n * mutates its input; `labels` and every other key are carried by reference.\n */\nexport function withDatasetsNoGapSpan<D extends { datasets?: unknown }>(data: D): D {\n const datasets = Array.isArray(data?.datasets) ? data.datasets : null;\n if (!datasets) return data;\n return {\n ...data,\n datasets: datasets.map((dataset: unknown) =>\n dataset !== null && typeof dataset === 'object'\n ? { ...(dataset as object), spanGaps: false }\n : dataset\n ),\n };\n}\n\n// ─── Legend ────────────────────────────────────────────────────────────────\n\ntype LegendGenerator = (chart: any) => any[];\n\n/**\n * Wraps a Chart.js legend label generator so a fully-missing dataset reads\n * `\"{series} (no data)\"` (`strings.chartLegendNoData`). Every other item is\n * passed through untouched.\n */\nexport function createMissingLegendGenerator(\n base: LegendGenerator,\n fullyMissing: readonly boolean[],\n getStrings: () => Strings\n): LegendGenerator {\n return function generateLabels(this: unknown, chart: any) {\n const items = base.call(this, chart);\n if (!Array.isArray(items)) return items;\n return items.map((item) => {\n const index = item?.datasetIndex;\n if (typeof index !== 'number' || !fullyMissing[index]) return item;\n const text = typeof item.text === 'string' ? item.text : String(item.text ?? '');\n return {\n ...item,\n text: formatMCPUIString(getStrings().chartLegendNoData, { series: text }),\n };\n });\n };\n}\n\n// ─── Tooltip ───────────────────────────────────────────────────────────────\n\n/** Whether a Chart.js tooltip item stands for a missing value. */\nexport function isMissingTooltipItem(item: any): boolean {\n if (item === null || item === undefined) return false;\n if (item.raw === null || item.raw === undefined || isMissingChartValue(item.raw)) return true;\n const parsed = item.parsed;\n if (parsed !== null && typeof parsed === 'object') {\n const chartType = item.chart?.config?.type;\n const valueKey =\n chartType === 'radar' ? 'r' : item.chart?.options?.indexAxis === 'y' ? 'x' : 'y';\n if (valueKey in parsed && parsed[valueKey] === null) return true;\n }\n return false;\n}\n\n/**\n * Tooltip `label` callback: names a missing value (`\"{series}: Missing\n * value\"`) and, with a `unit`, appends it to a present one. Otherwise it is\n * Chart.js's default composition (dataset label, `\": \"`, formatted value) —\n * including its `mode: 'dataset'` branch, which prefixes the CATEGORY label\n * instead, since every item of that tooltip belongs to the same dataset.\n * Hence a regular function: Chart.js calls it with the tooltip as `this`.\n *\n * `unit` is left off scatter and bubble tooltips: their formatted value is the\n * pair `(x, y)`, to which one unit does not belong.\n */\nexport function createTooltipLabel(\n getStrings: () => Strings,\n unit: string | undefined,\n chartType: string | undefined\n): (this: any, item: any) => string {\n const applyUnit = unit !== undefined && !POINT_CHART_TYPES.has(chartType ?? '');\n return function label(this: any, item: any) {\n const strings = getStrings();\n const prefixLabel = this?.options?.mode === 'dataset' ? item?.label : item?.dataset?.label;\n const prefix = typeof prefixLabel === 'string' && prefixLabel !== '' ? `${prefixLabel}: ` : '';\n\n if (isMissingTooltipItem(item)) return `${prefix}${strings.missingValue}`;\n\n const formatted = item?.formattedValue;\n if (formatted === null || formatted === undefined) return prefix;\n const value = applyUnit\n ? formatMCPUIString(strings.chartValueWithUnit, { value: formatted, unit: unit as string })\n : String(formatted);\n return `${prefix}${value}`;\n };\n}\n\n// ─── Axis ──────────────────────────────────────────────────────────────────\n\n/**\n * Sets the chart's `unit` as the title of its value axis, in place on the\n * `options` object the renderer just built (never on the payload's).\n *\n * Only bar, line, scatter and bubble have a value axis to title. The value\n * axis is `y`, or `x` when the index axis is `y` (a horizontal bar or line).\n * An existing `scales[axis].title` is the payload's own word and is kept; the\n * rest of the scale config (a `timeAxis` block sets `scales.x`) is kept too.\n */\nexport function applyUnitAxisTitle(\n options: any,\n chartType: string | undefined,\n unit: string | undefined\n): void {\n if (unit === undefined) return;\n if (chartType !== 'bar' && chartType !== 'line' && !POINT_CHART_TYPES.has(chartType ?? '')) {\n return;\n }\n const horizontal = (chartType === 'bar' || chartType === 'line') && options?.indexAxis === 'y';\n const axis = horizontal ? 'x' : 'y';\n if (options.scales?.[axis]?.title !== undefined) return;\n options.scales = {\n ...options.scales,\n [axis]: { ...options.scales?.[axis], title: { display: true, text: unit } },\n };\n}\n\n// ─── Plugin ────────────────────────────────────────────────────────────────\n\nexport interface MissingValuesPluginOptions {\n /** At least one dataset and every one of them has no observed value. */\n allMissing: boolean;\n /** Lazy: read at draw time. */\n getNoDataText: () => string;\n /** Lazy: `Chart.defaults.font.family`, when the build exposes it. */\n getFontFamily?: () => string | undefined;\n /** Lazy host theme override; omission retains the historical grey. */\n getTextColor?: () => string | undefined;\n}\n\n/** A dataset colour for entry `index`, as a string, or `undefined`. */\nfunction colorAt(color: unknown, index: number): string | undefined {\n if (typeof color === 'string' && color !== '') return color;\n if (Array.isArray(color) && color.length > 0) {\n const picked = color[index % color.length];\n return typeof picked === 'string' && picked !== '' ? picked : undefined;\n }\n return undefined;\n}\n\n/**\n * Draws a dashed outline stub for every missing bar of every visible,\n * non-stacked bar dataset, so a missing value is a visible mark, not a bar\n * that \"is\" zero.\n *\n * The stub sits on the value-axis base, as thick as the bar would have been,\n * and runs {@link MISSING_BAR_STUB_LENGTH}px toward the middle of the chart\n * area (up from a bottom baseline, down from a top one, right from a left\n * one). Clipped to the chart area.\n */\nexport function drawMissingBarStubs(chart: any): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n const datasets = chart?.data?.datasets;\n if (!ctx || !area || !Array.isArray(datasets)) return;\n\n const left = area.left;\n const top = area.top;\n const right = area.right ?? left + (area.width ?? 0);\n const bottom = area.bottom ?? top + (area.height ?? 0);\n\n let saved = false;\n datasets.forEach((dataset: any, datasetIndex: number) => {\n const meta = chart.getDatasetMeta?.(datasetIndex);\n if (!meta) return;\n const isBar = meta.type === 'bar' || meta.controller?.constructor?.id === 'bar';\n if (!isBar) return;\n // Stacked or overlaid bars: the baseline under a missing segment is the\n // series below, so an outline there would point at the wrong series.\n if (meta.vScale?.options?.stacked || meta.iScale?.options?.stacked) return;\n if (typeof chart.isDatasetVisible === 'function' && !chart.isDatasetVisible(datasetIndex)) {\n return;\n }\n const values: unknown[] = Array.isArray(dataset?.data) ? dataset.data : [];\n const elements: any[] = Array.isArray(meta.data) ? meta.data : [];\n\n values.forEach((value, index) => {\n if (!isMissingChartValue(value)) return;\n const element = elements[index];\n if (!element) return;\n const props = element.getProps?.(['x', 'y', 'base', 'width', 'height'], true) ?? element;\n const { x, y, base, width, height } = props;\n if (![x, y, base].every((n) => Number.isFinite(n))) return;\n const horizontal = element.horizontal === true;\n const thickness = horizontal ? height : width;\n if (!Number.isFinite(thickness) || thickness <= 0) return;\n\n let rect: [number, number, number, number];\n if (horizontal) {\n const dir = base < (left + right) / 2 ? 1 : -1;\n rect = [Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), y - thickness / 2, MISSING_BAR_STUB_LENGTH, thickness];\n } else {\n const dir = base > (top + bottom) / 2 ? -1 : 1;\n rect = [x - thickness / 2, Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), thickness, MISSING_BAR_STUB_LENGTH];\n }\n\n if (!saved) {\n ctx.save();\n ctx.beginPath();\n ctx.rect(left, top, right - left, bottom - top);\n ctx.clip();\n saved = true;\n }\n ctx.strokeStyle = colorAt(dataset?.borderColor, index) ?? MISSING_BAR_FALLBACK_COLOR;\n ctx.lineWidth = 1;\n ctx.setLineDash(STUB_DASH);\n ctx.strokeRect(...rect);\n });\n });\n if (saved) {\n ctx.setLineDash?.([]);\n ctx.restore();\n }\n}\n\n/** Draws `text` centred in the chart area (a chart with nothing to plot). */\nexport function drawNoDataText(chart: any, text: string, fontFamily?: string, color?: string): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n if (!ctx || !area || !text) return;\n const cx = (area.left + (area.right ?? area.left + (area.width ?? 0))) / 2;\n const cy = (area.top + (area.bottom ?? area.top + (area.height ?? 0))) / 2;\n ctx.save();\n ctx.font = `12px ${fontFamily || 'sans-serif'}`;\n ctx.fillStyle = color || NO_DATA_TEXT_COLOR;\n ctx.textAlign = 'center';\n ctx.textBaseline = 'middle';\n ctx.fillText(text, cx, cy);\n ctx.restore();\n}\n\n/**\n * The per-chart plugin object. Passed as `config.plugins = [plugin]`: Chart.js\n * scopes it to that one chart. Both hooks swallow their own errors — a\n * decoration must never take the chart down.\n */\nexport function createMissingValuesPlugin(options: MissingValuesPluginOptions) {\n return {\n id: 'mcpuiMissingValues',\n afterDatasetsDraw(chart: any) {\n try {\n drawMissingBarStubs(chart);\n if (options.allMissing) {\n drawNoDataText(chart, options.getNoDataText(), options.getFontFamily?.(), options.getTextColor?.());\n }\n } catch {\n // Cosmetic layer: never break the chart.\n }\n },\n };\n}\n"],"names":["_a","_b"],"mappings":";;AA0CO,MAAM,0BAA0B;AAEhC,MAAM,6BAA6B;AAEnC,MAAM,qBAAqB;AAClC,MAAM,YAAY,CAAC,GAAG,CAAC;AAGvB,MAAM,oBAAoB,oBAAI,IAAI,CAAC,WAAW,QAAQ,CAAC;AAchD,SAAS,eAAe,SAAuB;;AACpD,SAAO,UAAQ,8CAAS,WAAT,mBAAiB,MAAjB,mBAAoB,cAAW,8CAAS,WAAT,mBAAiB,MAAjB,mBAAoB,QAAO;AAC3E;AAGO,SAAS,gBAAgB,WAA+B,SAAgC;AAC7F,MAAI,cAAc,MAAO,QAAO,eAAe,OAAO,IAAI,YAAY;AACtE,MAAI,cAAc,aAAa,cAAc,SAAU,QAAO;AAC9D,SAAO;AACT;AASO,SAAS,sBAAwD,MAAY;AAClF,QAAM,WAAW,MAAM,QAAQ,6BAAM,QAAQ,IAAI,KAAK,WAAW;AACjE,MAAI,CA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