frappe-ui 1.0.2 → 1.2.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/experimental/Calendar/CalendarEventRow.vue +0 -4
- package/experimental/Calendar/calendarUtils.ts +33 -21
- package/experimental/CommandPalette/CommandPaletteItem.vue +9 -1
- package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
- package/experimental/MultiEmailInput/types.ts +12 -3
- package/experimental/SpriteIcons/IconPicker.vue +2 -1
- package/experimental/Stepper/StepIndicator.vue +129 -0
- package/experimental/Stepper/Stepper.api.md +117 -0
- package/experimental/Stepper/Stepper.md +95 -0
- package/experimental/Stepper/Stepper.vue +82 -0
- package/experimental/Stepper/StepperHorizontal.vue +93 -0
- package/experimental/Stepper/StepperVertical.vue +291 -0
- package/experimental/Stepper/index.ts +11 -0
- package/experimental/Stepper/resolve.ts +87 -0
- package/experimental/Stepper/types.ts +89 -0
- package/experimental.ts +2 -21
- package/package.json +1 -3
- package/src/charts/CalendarHeatmapChart.vue +353 -0
- package/src/charts/DonutChart.vue +34 -58
- package/src/charts/HeatmapChart.vue +26 -64
- package/src/charts/NumberCard.vue +62 -7
- package/src/charts/PercentageBarChart.vue +243 -0
- package/src/charts/SankeyChart.vue +14 -11
- package/src/charts/ScatterChart.vue +24 -20
- package/src/charts/axisChartCommon.ts +182 -18
- package/src/charts/axisFormat.ts +8 -3
- package/src/charts/calendarHeatmapOptions.ts +604 -0
- package/src/charts/colorMath.ts +26 -0
- package/src/charts/components/ChartContainer.vue +63 -53
- package/src/charts/components/ChartLegend.vue +216 -24
- package/src/charts/components/ChartScale.vue +85 -0
- package/src/charts/core/dataLabelFit.ts +45 -6
- package/src/charts/core/useAxisChart.ts +36 -19
- package/src/charts/core/useChart.ts +6 -1
- package/src/charts/core/usePlotKeyboard.ts +13 -2
- package/src/charts/docs/BarChart.md +11 -3
- package/src/charts/docs/CalendarHeatmapChart.api.md +165 -0
- package/src/charts/docs/CalendarHeatmapChart.md +33 -0
- package/src/charts/docs/ChartContainer.api.md +6 -0
- package/src/charts/docs/ChartLegend.api.md +1 -1
- package/src/charts/docs/ChartLegend.md +25 -3
- package/src/charts/docs/DonutChart.api.md +12 -0
- package/src/charts/docs/DonutChart.md +17 -0
- package/src/charts/docs/HeatmapChart.api.md +1 -1
- package/src/charts/docs/LineChart.md +5 -3
- package/src/charts/docs/NumberCard.api.md +6 -0
- package/src/charts/docs/NumberCard.md +6 -0
- package/src/charts/docs/Overview.md +13 -6
- package/src/charts/docs/PercentageBarChart.api.md +148 -0
- package/src/charts/docs/PercentageBarChart.md +42 -0
- package/src/charts/docs/ScatterChart.md +2 -3
- package/src/charts/donutChartOptions.ts +22 -130
- package/src/charts/format.ts +4 -1
- package/src/charts/heatmapOptions.ts +17 -12
- package/src/charts/hiddenSeries.ts +8 -3
- package/src/charts/index.ts +12 -0
- package/src/charts/legendOverflow.ts +40 -0
- package/src/charts/numberCardFormat.ts +19 -13
- package/src/charts/referenceLines.ts +2 -1
- package/src/charts/scatterOptions.ts +16 -3
- package/src/charts/seriesData.ts +8 -3
- package/src/charts/slices.ts +228 -0
- package/src/charts/tokens.ts +99 -0
- package/src/charts/types.ts +318 -9
- package/src/components/Avatar/Avatar.md +27 -2
- package/src/components/Avatar/Avatar.vue +29 -12
- package/src/components/Breadcrumbs/Breadcrumbs.vue +2 -1
- package/src/components/Combobox/Combobox.vue +9 -2
- package/src/components/Combobox/ComboboxResults.vue +6 -1
- package/src/components/Combobox/utils.ts +2 -1
- package/src/components/DatePicker/DatePicker.md +7 -0
- package/src/components/DatePicker/DatePicker.vue +6 -0
- package/src/components/DatePicker/DateTimePicker.vue +6 -0
- package/src/components/DatePicker/composables.ts +18 -1
- package/src/components/DatePicker/utils.ts +53 -0
- package/src/components/Dialog/Dialog.md +3 -1
- package/src/components/Duration/Duration.api.md +16 -3
- package/src/components/Duration/Duration.md +21 -0
- package/src/components/Duration/Duration.vue +29 -8
- package/src/components/Duration/duration.ts +105 -44
- package/src/components/Duration/index.ts +1 -0
- package/src/components/Duration/types.ts +30 -1
- package/src/components/HoverCard/HoverCard.vue +21 -5
- package/src/components/Menu/utils.ts +3 -2
- package/src/components/MobileNav/MobileNavItem.vue +3 -22
- package/src/components/MultiSelect/MultiSelect.api.md +5 -0
- package/src/components/MultiSelect/MultiSelect.vue +34 -0
- package/src/components/MultiSelect/MultiSelectResults.vue +3 -4
- package/src/components/MultiSelect/types.ts +6 -0
- package/src/components/Select/Select.vue +4 -4
- package/src/components/Select/utils.ts +1 -0
- package/src/components/SettingsDialog/SettingsDialog.api.md +7 -2
- package/src/components/SettingsDialog/SettingsDialog.md +2 -1
- package/src/components/SettingsDialog/SettingsRow.vue +12 -2
- package/src/components/Sidebar/SidebarItem.vue +3 -33
- package/src/components/SidebarRail/SidebarRailItem.vue +4 -17
- package/src/components/Switch/Switch.vue +3 -3
- package/src/components/Tooltip/Tooltip.vue +8 -0
- package/src/components/shared/deferredTrigger.ts +174 -0
- package/src/components/shared/navLink.ts +45 -0
- package/src/components/shared/selection/utils.ts +8 -1
- package/src/data-fetching/useCall/useCall.ts +25 -26
- package/src/data-fetching/useFrappeFetch.ts +48 -2
- package/src/data-fetching/useList/useList.ts +11 -3
- package/src/data-fetching/utils.ts +15 -1
- package/src/molecules/editor/components/MediaNodeView.vue +10 -1
- package/src/molecules/editor/components/MediaResizeGuide.vue +71 -0
- package/src/molecules/editor/components/media-node-view-utils.ts +7 -0
- package/src/molecules/editor/composables/useNodeViewResize.ts +142 -10
- package/src/molecules/editor/extensions/attachment/attachment-engine.ts +1 -1
- package/src/molecules/editor/extensions/content-paste/paste-html-utils.ts +16 -6
- package/src/molecules/editor/extensions/iframe/IframeNodeView.vue +29 -10
- package/src/molecules/editor/extensions/iframe/iframe-allowlist.ts +35 -16
- package/src/molecules/editor/extensions/iframe/iframe-embed-utils.ts +1 -1
- package/src/molecules/editor/extensions/iframe/iframe-extension.ts +30 -30
- package/src/molecules/editor/extensions/link/LinkEditorPopup.vue +1 -1
- package/src/molecules/editor/extensions/link/link-paste-plugin.ts +1 -1
- package/src/molecules/editor/extensions/shared/media-upload-engine.ts +1 -1
- package/src/molecules/editor/useEditor.ts +12 -6
- package/src/molecules/list/ListRow.vue +8 -1
- package/src/utils/dialog.ts +57 -16
- package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
- package/tailwind/content.js +1 -1
- package/tailwind/plugin.js +22 -0
- package/vite/README.md +5 -3
- package/vite/codeLanguages.js +41 -17
- package/vite/doctypeInterfaceGenerator.js +52 -39
- package/vitepress/index.node.ts +0 -2
- package/experimental/TextEditor/TextEditor.api.md +0 -161
- package/experimental/TextEditor/TextEditor.vue +0 -298
- package/experimental/TextEditor/classIcon.ts +0 -21
- package/experimental/TextEditor/commands.js +0 -344
- package/experimental/TextEditor/components/CodeBlockComponent.vue +0 -103
- package/experimental/TextEditor/components/FontColor.vue +0 -153
- package/experimental/TextEditor/components/ImageViewerModal.vue +0 -463
- package/experimental/TextEditor/components/InsertImage.vue +0 -54
- package/experimental/TextEditor/components/InsertLink.vue +0 -13
- package/experimental/TextEditor/components/InsertVideo.vue +0 -14
- package/experimental/TextEditor/components/LinkPopup.vue +0 -99
- package/experimental/TextEditor/components/MediaNodeView.vue +0 -398
- package/experimental/TextEditor/components/MentionList.vue +0 -95
- package/experimental/TextEditor/components/TextEditorBubbleMenu.vue +0 -78
- package/experimental/TextEditor/components/TextEditorFixedMenu.vue +0 -78
- package/experimental/TextEditor/components/TextEditorFloatingMenu.vue +0 -61
- package/experimental/TextEditor/components/TextEditorMenu.vue +0 -218
- package/experimental/TextEditor/components/index.js +0 -0
- package/experimental/TextEditor/extensions/code-block.ts +0 -119
- package/experimental/TextEditor/extensions/color/color-extension.ts +0 -140
- package/experimental/TextEditor/extensions/color/color-styles.css +0 -25
- package/experimental/TextEditor/extensions/color/index.ts +0 -2
- package/experimental/TextEditor/extensions/content-paste-extension.ts +0 -160
- package/experimental/TextEditor/extensions/copy-styles.ts +0 -160
- package/experimental/TextEditor/extensions/emoji/EmojiList.vue +0 -55
- package/experimental/TextEditor/extensions/emoji/emoji-extension.ts +0 -55
- package/experimental/TextEditor/extensions/emoji/emojis.json +0 -7422
- package/experimental/TextEditor/extensions/heading/heading.ts +0 -20
- package/experimental/TextEditor/extensions/highlight/highlight-extension.ts +0 -241
- package/experimental/TextEditor/extensions/highlight/highlight-styles.css +0 -31
- package/experimental/TextEditor/extensions/highlight/index.ts +0 -2
- package/experimental/TextEditor/extensions/iframe/IframeNodeView.vue +0 -308
- package/experimental/TextEditor/extensions/iframe/InsertIframe.vue +0 -209
- package/experimental/TextEditor/extensions/iframe/iframe-extension.ts +0 -404
- package/experimental/TextEditor/extensions/iframe/index.ts +0 -11
- package/experimental/TextEditor/extensions/iframe/utils.ts +0 -283
- package/experimental/TextEditor/extensions/image/image-extension.ts +0 -661
- package/experimental/TextEditor/extensions/image/index.ts +0 -5
- package/experimental/TextEditor/extensions/image-group/ImageGroupNodeView.vue +0 -182
- package/experimental/TextEditor/extensions/image-group/ImageGroupUploadDialog.vue +0 -740
- package/experimental/TextEditor/extensions/image-group/image-group-extension.ts +0 -187
- package/experimental/TextEditor/extensions/image-viewer-extension.ts +0 -162
- package/experimental/TextEditor/extensions/link/index.ts +0 -1
- package/experimental/TextEditor/extensions/link/link-extension.ts +0 -323
- package/experimental/TextEditor/extensions/link/linkPasteHandler.ts +0 -51
- package/experimental/TextEditor/extensions/mention/index.ts +0 -1
- package/experimental/TextEditor/extensions/mention/mention-extension.ts +0 -204
- package/experimental/TextEditor/extensions/mention/style.css +0 -11
- package/experimental/TextEditor/extensions/shared/color-utils.ts +0 -236
- package/experimental/TextEditor/extensions/slash-commands/SlashCommandsList.vue +0 -59
- package/experimental/TextEditor/extensions/slash-commands/slash-commands-extension.ts +0 -184
- package/experimental/TextEditor/extensions/suggestion/SuggestionList.vue +0 -130
- package/experimental/TextEditor/extensions/suggestion/createSuggestionExtension.ts +0 -151
- package/experimental/TextEditor/extensions/suggestion/index.ts +0 -5
- package/experimental/TextEditor/extensions/tag/index.ts +0 -1
- package/experimental/TextEditor/extensions/tag/tag-extension.ts +0 -170
- package/experimental/TextEditor/extensions/toc-node/TocNodeView.vue +0 -439
- package/experimental/TextEditor/extensions/toc-node/index.ts +0 -3
- package/experimental/TextEditor/extensions/toc-node/toc-node-extension.ts +0 -167
- package/experimental/TextEditor/extensions/video-extension.ts +0 -653
- package/experimental/TextEditor/hljs-github.css +0 -197
- package/experimental/TextEditor/index.ts +0 -21
- package/experimental/TextEditor/style.css +0 -190
- package/experimental/TextEditor/types.ts +0 -72
- package/experimental/TextEditor/utils.js +0 -11
- package/src/utils/url-validation.ts +0 -39
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export type StepValue = string | number
|
|
2
|
+
|
|
3
|
+
/** A step's state, derived from its position relative to the current step. */
|
|
4
|
+
export type StepState =
|
|
5
|
+
| 'complete'
|
|
6
|
+
| 'current'
|
|
7
|
+
| 'upcoming'
|
|
8
|
+
| 'failed'
|
|
9
|
+
| 'skipped'
|
|
10
|
+
|
|
11
|
+
export type StepperSize = 'sm' | 'md'
|
|
12
|
+
export type StepperEdge = 'start' | 'end'
|
|
13
|
+
|
|
14
|
+
/** A step to render. Holds data only; the stepper never writes to it. */
|
|
15
|
+
export interface StepItem {
|
|
16
|
+
/** Unique across the whole tree, sub-steps included. */
|
|
17
|
+
value: StepValue
|
|
18
|
+
|
|
19
|
+
/** Text shown for the step. */
|
|
20
|
+
label: string
|
|
21
|
+
|
|
22
|
+
/** Second line under the label. */
|
|
23
|
+
description?: string
|
|
24
|
+
|
|
25
|
+
/** Trailing text, such as a duration. */
|
|
26
|
+
meta?: string
|
|
27
|
+
|
|
28
|
+
/** The flow passed this step without doing it. */
|
|
29
|
+
skipped?: boolean
|
|
30
|
+
|
|
31
|
+
/** One level of sub-steps. Deeper nesting is ignored. */
|
|
32
|
+
children?: StepItem[]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface StepperProps {
|
|
36
|
+
/** Steps in order. */
|
|
37
|
+
steps: StepItem[]
|
|
38
|
+
|
|
39
|
+
/** Value of the current step; may be a sub-step's value. */
|
|
40
|
+
modelValue?: StepValue | null
|
|
41
|
+
|
|
42
|
+
/** Every step is done. Wins over `modelValue`. */
|
|
43
|
+
completed?: boolean
|
|
44
|
+
|
|
45
|
+
/** The current step is running: its indicator's outline spins. */
|
|
46
|
+
loading?: boolean
|
|
47
|
+
|
|
48
|
+
/** The current step failed. */
|
|
49
|
+
failed?: boolean
|
|
50
|
+
|
|
51
|
+
/** Lays the steps out as a vertical list instead of a segmented bar. */
|
|
52
|
+
vertical?: boolean
|
|
53
|
+
|
|
54
|
+
/** Vertical only: the side the indicators sit on. */
|
|
55
|
+
edge?: StepperEdge
|
|
56
|
+
|
|
57
|
+
/** Size of the indicators and text. */
|
|
58
|
+
size?: StepperSize
|
|
59
|
+
|
|
60
|
+
/** Vertical only: show sub-steps for every step, or only the current one. */
|
|
61
|
+
substeps?: 'all' | 'current'
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Finished steps become buttons that set `v-model`. Off while `completed`
|
|
65
|
+
* is set, since `completed` would override the value a click sets.
|
|
66
|
+
*/
|
|
67
|
+
clickable?: boolean
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface StepperEmits {
|
|
71
|
+
/** Fired when a finished step is clicked (`clickable` only). */
|
|
72
|
+
'update:modelValue': [value: StepValue]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Props every `#step-*` slot receives. */
|
|
76
|
+
export interface StepSlotProps {
|
|
77
|
+
item: StepItem
|
|
78
|
+
/** Position among its siblings. */
|
|
79
|
+
index: number
|
|
80
|
+
state: StepState
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A step with its derived state, as rendered. */
|
|
84
|
+
export interface ResolvedStep {
|
|
85
|
+
item: StepItem
|
|
86
|
+
index: number
|
|
87
|
+
state: StepState
|
|
88
|
+
children: ResolvedStep[]
|
|
89
|
+
}
|
package/experimental.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
export * from './experimental/Accordion'
|
|
4
4
|
export * from './experimental/FloatingWindow'
|
|
5
5
|
export * from './experimental/MultiEmailInput'
|
|
6
|
+
// Stepper. Incubating while its API is reviewed and refined before freezing.
|
|
7
|
+
export * from './experimental/Stepper'
|
|
6
8
|
export { inputFontSizeClasses } from './src/components/Combobox/utils'
|
|
7
9
|
export {
|
|
8
10
|
InputLabel,
|
|
@@ -52,27 +54,6 @@ export type {
|
|
|
52
54
|
PickerShellSlots,
|
|
53
55
|
PickerShellExposed,
|
|
54
56
|
} from './src/components/shared/picker/types'
|
|
55
|
-
// v0 TextEditor family. Moved out of root (#974) — `frappe-ui/editor` is the
|
|
56
|
-
// composition-based replacement. Parked here (#1007), unstable, as an interim
|
|
57
|
-
// import path while apps migrate. Deletion stays human-gated (spec/editor.md
|
|
58
|
-
// §12).
|
|
59
|
-
export {
|
|
60
|
-
TextEditor,
|
|
61
|
-
TextEditorBubbleMenu,
|
|
62
|
-
TextEditorFixedMenu,
|
|
63
|
-
TextEditorFloatingMenu,
|
|
64
|
-
TextEditorContent,
|
|
65
|
-
createEditorButton,
|
|
66
|
-
} from './experimental/TextEditor'
|
|
67
|
-
export {
|
|
68
|
-
ImageExtension,
|
|
69
|
-
type SetImageOptions,
|
|
70
|
-
} from './experimental/TextEditor/extensions/image'
|
|
71
|
-
export {
|
|
72
|
-
createSuggestionExtension,
|
|
73
|
-
type BaseSuggestionItem,
|
|
74
|
-
type CreateSuggestionExtensionOptions,
|
|
75
|
-
} from './experimental/TextEditor/extensions/suggestion'
|
|
76
57
|
// ThemeSwitcher. Moved out of root (#1094) — `Select` bound to
|
|
77
58
|
// `useColorScheme()` is the replacement, and it replaces the behavior rather
|
|
78
59
|
// than the markup: this renders a reka-ui `RadioGroupRoot` of preview cards.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frappe-ui",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A set of components and utilities for rapid UI development",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.19.0"
|
|
@@ -203,7 +203,6 @@
|
|
|
203
203
|
"@tiptap/extensions": "^3.26.0",
|
|
204
204
|
"@tiptap/markdown": "^3.26.0",
|
|
205
205
|
"@tiptap/pm": "^3.26.0",
|
|
206
|
-
"@tiptap/starter-kit": "^3.26.0",
|
|
207
206
|
"@tiptap/suggestion": "^3.26.0",
|
|
208
207
|
"@tiptap/vue-3": "^3.26.0",
|
|
209
208
|
"@vue/compiler-sfc": "^3.5.13",
|
|
@@ -221,7 +220,6 @@
|
|
|
221
220
|
"marked": "^15.0.12",
|
|
222
221
|
"reka-ui": "^2.9.9",
|
|
223
222
|
"socket.io-client": "^4.5.1",
|
|
224
|
-
"tippy.js": "^6.3.7",
|
|
225
223
|
"typescript": "^5.0.2",
|
|
226
224
|
"unplugin-auto-import": "^19.3.0",
|
|
227
225
|
"unplugin-icons": "^22.1.0",
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ChartContainer
|
|
3
|
+
:title="title"
|
|
4
|
+
:subtitle="subtitle"
|
|
5
|
+
:loading="loading"
|
|
6
|
+
:error="error || renderError"
|
|
7
|
+
:empty="isEmpty"
|
|
8
|
+
:dir="dir"
|
|
9
|
+
>
|
|
10
|
+
<template v-if="$slots.actions" #actions><slot name="actions" /></template>
|
|
11
|
+
<template v-if="$slots['title-suffix']" #title-suffix>
|
|
12
|
+
<slot name="title-suffix" />
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<template v-if="$slots.loading" #loading><slot name="loading" /></template>
|
|
16
|
+
<template v-if="$slots.error" #error="slotProps">
|
|
17
|
+
<slot name="error" v-bind="slotProps" />
|
|
18
|
+
</template>
|
|
19
|
+
<template v-if="$slots.empty" #empty><slot name="empty" /></template>
|
|
20
|
+
|
|
21
|
+
<template #default>
|
|
22
|
+
<!-- echarts lays a calendar out left to right only, so the plot keeps
|
|
23
|
+
`ltr` in both directions. -->
|
|
24
|
+
<div
|
|
25
|
+
ref="plotEl"
|
|
26
|
+
class="h-full w-full rounded-2 focus-visible:focus-ring"
|
|
27
|
+
dir="ltr"
|
|
28
|
+
role="img"
|
|
29
|
+
:aria-label="chartAriaLabel(title, subtitle)"
|
|
30
|
+
v-bind="plotAttrs"
|
|
31
|
+
/>
|
|
32
|
+
|
|
33
|
+
<!-- Under the last band rather than under the card, so the scale sits
|
|
34
|
+
with what it explains however much height the card has to spare.
|
|
35
|
+
Ends where the calendar ends, unless the calendar is narrower than
|
|
36
|
+
the scale: then it starts at the plot's edge. -->
|
|
37
|
+
<ChartScale
|
|
38
|
+
v-if="grid && cells.length && layout"
|
|
39
|
+
class="absolute"
|
|
40
|
+
:style="{
|
|
41
|
+
top: `${layout.scaleTop}px`,
|
|
42
|
+
left: `${layout.right}px`,
|
|
43
|
+
transform: `translateX(max(-100%, -${layout.right}px))`,
|
|
44
|
+
}"
|
|
45
|
+
:min="grid.min"
|
|
46
|
+
:max="grid.max"
|
|
47
|
+
:stops="grid.stops"
|
|
48
|
+
:format="format"
|
|
49
|
+
:below-min="clipped.belowMin"
|
|
50
|
+
:above-max="clipped.aboveMax"
|
|
51
|
+
:dir="dir"
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
<span class="sr-only" role="status">{{ reading }}</span>
|
|
55
|
+
|
|
56
|
+
<ChartTooltip
|
|
57
|
+
:open="tooltip.open"
|
|
58
|
+
:x="tooltip.x"
|
|
59
|
+
:y="tooltip.y"
|
|
60
|
+
:label="tooltip.label"
|
|
61
|
+
:items="tooltip.items"
|
|
62
|
+
:rows="tooltip.rows"
|
|
63
|
+
:dir="dir"
|
|
64
|
+
>
|
|
65
|
+
<template v-if="$slots.tooltip" #default="slotProps">
|
|
66
|
+
<slot name="tooltip" v-bind="slotProps" />
|
|
67
|
+
</template>
|
|
68
|
+
</ChartTooltip>
|
|
69
|
+
</template>
|
|
70
|
+
</ChartContainer>
|
|
71
|
+
</template>
|
|
72
|
+
|
|
73
|
+
<script setup lang="ts">
|
|
74
|
+
import { computed, reactive, ref } from 'vue'
|
|
75
|
+
import { HeatmapChart as HeatmapSeries } from 'echarts/charts'
|
|
76
|
+
import {
|
|
77
|
+
CalendarComponent,
|
|
78
|
+
VisualMapContinuousComponent,
|
|
79
|
+
} from 'echarts/components'
|
|
80
|
+
import { registerChartModules, useChart } from './core/useChart'
|
|
81
|
+
import { usePlotKeyboard } from './core/usePlotKeyboard'
|
|
82
|
+
import { useTooltipDismiss } from './core/useTooltipDismiss'
|
|
83
|
+
import {
|
|
84
|
+
buildCalendarHeatmapGrid,
|
|
85
|
+
buildCalendarHeatmapOption,
|
|
86
|
+
layoutCalendar,
|
|
87
|
+
} from './calendarHeatmapOptions'
|
|
88
|
+
import { formatDate, formatLabel, formatValue } from './format'
|
|
89
|
+
import { useChartTokens, useResolvedConfig } from './tokens'
|
|
90
|
+
import { chartAriaLabel, documentDir, plotReading } from './utils'
|
|
91
|
+
import ChartContainer from './components/ChartContainer.vue'
|
|
92
|
+
import ChartScale from './components/ChartScale.vue'
|
|
93
|
+
import ChartTooltip from './components/ChartTooltip.vue'
|
|
94
|
+
import type {
|
|
95
|
+
CalendarHeatmapChartConfig,
|
|
96
|
+
CalendarHeatmapChartEmits,
|
|
97
|
+
CalendarHeatmapChartProps,
|
|
98
|
+
CalendarHeatmapChartSlots,
|
|
99
|
+
CalendarHeatmapDay,
|
|
100
|
+
ChartExposedRefs,
|
|
101
|
+
ChartTooltipItem,
|
|
102
|
+
} from './types'
|
|
103
|
+
|
|
104
|
+
registerChartModules([
|
|
105
|
+
HeatmapSeries,
|
|
106
|
+
CalendarComponent,
|
|
107
|
+
VisualMapContinuousComponent,
|
|
108
|
+
])
|
|
109
|
+
|
|
110
|
+
const props = defineProps<CalendarHeatmapChartProps>()
|
|
111
|
+
|
|
112
|
+
const emit = defineEmits<CalendarHeatmapChartEmits>()
|
|
113
|
+
|
|
114
|
+
defineSlots<CalendarHeatmapChartSlots>()
|
|
115
|
+
|
|
116
|
+
const plotEl = ref<HTMLElement>()
|
|
117
|
+
|
|
118
|
+
const dir = computed(() => props.dir ?? documentDir())
|
|
119
|
+
|
|
120
|
+
const config = useResolvedConfig<CalendarHeatmapChartConfig>(
|
|
121
|
+
() => ({
|
|
122
|
+
data: props.data,
|
|
123
|
+
dateColumn: props.date,
|
|
124
|
+
valueColumn: props.value,
|
|
125
|
+
start: props.start,
|
|
126
|
+
end: props.end,
|
|
127
|
+
weekStart: props.weekStart,
|
|
128
|
+
min: props.min,
|
|
129
|
+
max: props.max,
|
|
130
|
+
palette: props.palette,
|
|
131
|
+
echartOptions: props.echartOptions,
|
|
132
|
+
}),
|
|
133
|
+
plotEl,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
const { tokens } = useChartTokens(plotEl)
|
|
137
|
+
|
|
138
|
+
// A config the grid cannot be built from is reported by `built` below.
|
|
139
|
+
const grid = computed(() => {
|
|
140
|
+
try {
|
|
141
|
+
return buildCalendarHeatmapGrid(config.value, { tokens: tokens.value })
|
|
142
|
+
} catch {
|
|
143
|
+
return undefined
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
const cells = computed(() => grid.value?.cells ?? [])
|
|
147
|
+
const days = computed(() => grid.value?.days ?? [])
|
|
148
|
+
const isEmpty = computed(() => !grid.value?.bands.length)
|
|
149
|
+
|
|
150
|
+
const size = computed(() => ({
|
|
151
|
+
width: plotWidth.value,
|
|
152
|
+
height: plotHeight.value,
|
|
153
|
+
}))
|
|
154
|
+
|
|
155
|
+
const layout = computed(
|
|
156
|
+
() => grid.value && layoutCalendar(grid.value, config.value, size.value),
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
const built = computed(() => {
|
|
160
|
+
try {
|
|
161
|
+
return {
|
|
162
|
+
option: buildCalendarHeatmapOption(
|
|
163
|
+
config.value,
|
|
164
|
+
{ tokens: tokens.value, ...size.value },
|
|
165
|
+
grid.value,
|
|
166
|
+
),
|
|
167
|
+
error: null as string | null,
|
|
168
|
+
}
|
|
169
|
+
} catch (e: any) {
|
|
170
|
+
return { option: undefined, error: e?.message ?? String(e) }
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
const renderError = computed(() => built.value.error)
|
|
175
|
+
|
|
176
|
+
const pointer = reactive({ x: 0, y: 0 })
|
|
177
|
+
|
|
178
|
+
const tooltip = reactive({
|
|
179
|
+
open: false,
|
|
180
|
+
x: 0,
|
|
181
|
+
y: 0,
|
|
182
|
+
label: undefined as string | undefined,
|
|
183
|
+
items: [] as ChartTooltipItem[],
|
|
184
|
+
rows: [] as Record<string, any>[],
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
useTooltipDismiss({
|
|
188
|
+
plot: plotEl,
|
|
189
|
+
data: () => days.value,
|
|
190
|
+
close: () => {
|
|
191
|
+
tooltip.open = false
|
|
192
|
+
},
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
const dayIndexes = computed(
|
|
196
|
+
() => new Map(days.value.map((day, index) => [day.date, index])),
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
/** The day under an echarts event: both series carry it first in the value. */
|
|
200
|
+
function eventDay(params: any): CalendarHeatmapDay | undefined {
|
|
201
|
+
const index = dayIndexes.value.get(params.value?.[0])
|
|
202
|
+
return index === undefined ? undefined : days.value[index]
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** A day with no row has nothing to report, so it does not select. */
|
|
206
|
+
function select(day: CalendarHeatmapDay | undefined) {
|
|
207
|
+
const cell = day?.cell
|
|
208
|
+
if (!cell) return
|
|
209
|
+
emit('select', { date: cell.date, value: cell.value, row: cell.row })
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const {
|
|
213
|
+
chart,
|
|
214
|
+
dispatch,
|
|
215
|
+
width: plotWidth,
|
|
216
|
+
height: plotHeight,
|
|
217
|
+
} = useChart({
|
|
218
|
+
container: plotEl,
|
|
219
|
+
option: () => built.value.option,
|
|
220
|
+
events: {
|
|
221
|
+
mouseover: (params: any) => showTooltip(eventDay(params)),
|
|
222
|
+
mouseout: () => (tooltip.open = false),
|
|
223
|
+
click: (params: any) => select(eventDay(params)),
|
|
224
|
+
},
|
|
225
|
+
onZrEvents: {
|
|
226
|
+
mousemove: (e: any) => {
|
|
227
|
+
pointer.x = e.event?.clientX ?? pointer.x
|
|
228
|
+
pointer.y = e.event?.clientY ?? pointer.y
|
|
229
|
+
if (tooltip.open) {
|
|
230
|
+
tooltip.x = pointer.x
|
|
231
|
+
tooltip.y = pointer.y
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
globalout: () => (tooltip.open = false),
|
|
235
|
+
},
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
function showTooltip(day: CalendarHeatmapDay | undefined) {
|
|
239
|
+
if (!day) {
|
|
240
|
+
tooltip.open = false
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
const { cell } = day
|
|
244
|
+
tooltip.label = formatDate(day.date, 'day', 'ddd, MMM D, YYYY')
|
|
245
|
+
tooltip.items = [
|
|
246
|
+
{
|
|
247
|
+
name: day.date,
|
|
248
|
+
label: formatLabel(props.value),
|
|
249
|
+
color: cell?.color ?? tokens.value.gridline,
|
|
250
|
+
value: cell?.value ?? '',
|
|
251
|
+
formattedValue: !cell
|
|
252
|
+
? 'No data'
|
|
253
|
+
: props.format
|
|
254
|
+
? props.format(cell.value)
|
|
255
|
+
: formatValue(cell.value),
|
|
256
|
+
kind: 'series',
|
|
257
|
+
},
|
|
258
|
+
]
|
|
259
|
+
tooltip.rows = cell ? [cell.row] : []
|
|
260
|
+
tooltip.x = pointer.x
|
|
261
|
+
tooltip.y = pointer.y
|
|
262
|
+
tooltip.open = true
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// One tab stop. The arrow keys walk the grid as it is drawn, every day of it,
|
|
266
|
+
// so a reader finds the date of a gap as well as of a day with data. The grid
|
|
267
|
+
// runs left to right in RTL too, so right is always the next week.
|
|
268
|
+
const reading = ref('')
|
|
269
|
+
|
|
270
|
+
function dayPoint(day: CalendarHeatmapDay) {
|
|
271
|
+
const el = plotEl.value
|
|
272
|
+
if (!el) return undefined
|
|
273
|
+
const rect = el.getBoundingClientRect()
|
|
274
|
+
// echarts types the finder without the calendar's own key.
|
|
275
|
+
const finder: Record<string, number> = { calendarIndex: day.band }
|
|
276
|
+
const at = chart.value?.convertToPixel(finder, day.date) as unknown as
|
|
277
|
+
number[] | undefined
|
|
278
|
+
if (!at || at.some((n) => typeof n !== 'number' || isNaN(n))) {
|
|
279
|
+
return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }
|
|
280
|
+
}
|
|
281
|
+
return { x: rect.left + at[0], y: rect.top + at[1] }
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function readDay(index: number) {
|
|
285
|
+
const day = days.value[index]
|
|
286
|
+
if (!day) return
|
|
287
|
+
const point = dayPoint(day)
|
|
288
|
+
if (point) {
|
|
289
|
+
pointer.x = point.x
|
|
290
|
+
pointer.y = point.y
|
|
291
|
+
}
|
|
292
|
+
dispatch({
|
|
293
|
+
type: 'highlight',
|
|
294
|
+
seriesIndex: day.seriesIndex,
|
|
295
|
+
dataIndex: day.dataIndex,
|
|
296
|
+
})
|
|
297
|
+
showTooltip(day)
|
|
298
|
+
reading.value = plotReading(
|
|
299
|
+
tooltip.label,
|
|
300
|
+
tooltip.items.map((item) => ({
|
|
301
|
+
label: item.label,
|
|
302
|
+
value: item.formattedValue,
|
|
303
|
+
})),
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function downplayDay(index: number | null) {
|
|
308
|
+
const day = index === null ? undefined : days.value[index]
|
|
309
|
+
if (!day) return
|
|
310
|
+
dispatch({
|
|
311
|
+
type: 'downplay',
|
|
312
|
+
seriesIndex: day.seriesIndex,
|
|
313
|
+
dataIndex: day.dataIndex,
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Moves the cursor `count` days on. Past either end of the range, it holds. */
|
|
318
|
+
function walk(count: number) {
|
|
319
|
+
const next = (keyboard.index.value ?? 0) + count
|
|
320
|
+
if (next < 0 || next >= days.value.length) return
|
|
321
|
+
keyboard.goTo(next)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const keyboard = usePlotKeyboard({
|
|
325
|
+
marks: () => days.value,
|
|
326
|
+
key: (day) => day.date,
|
|
327
|
+
move: (index, previous) => {
|
|
328
|
+
downplayDay(previous)
|
|
329
|
+
readDay(index)
|
|
330
|
+
},
|
|
331
|
+
along: (delta) => walk(7 * delta),
|
|
332
|
+
cross: walk,
|
|
333
|
+
activate: (index) => select(days.value[index]),
|
|
334
|
+
clear: (previous) => {
|
|
335
|
+
downplayDay(previous)
|
|
336
|
+
tooltip.open = false
|
|
337
|
+
reading.value = ''
|
|
338
|
+
},
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
const plotAttrs = keyboard.attrs
|
|
342
|
+
|
|
343
|
+
/** Days past an end of the scale: a `max` set under an outlier must say so. */
|
|
344
|
+
const clipped = computed(() => {
|
|
345
|
+
const { min = 0, max = 0 } = grid.value ?? {}
|
|
346
|
+
return {
|
|
347
|
+
belowMin: cells.value.some((cell) => cell.value < min),
|
|
348
|
+
aboveMax: cells.value.some((cell) => cell.value > max),
|
|
349
|
+
}
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
defineExpose<ChartExposedRefs>({ chart: computed(() => chart.value) })
|
|
353
|
+
</script>
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
</ChartTooltip>
|
|
96
96
|
</template>
|
|
97
97
|
|
|
98
|
-
<template v-if="legendItems.length
|
|
98
|
+
<template v-if="legendItems.length" #legend>
|
|
99
99
|
<ChartLegend
|
|
100
100
|
:items="legendItems"
|
|
101
101
|
@change="toggleSlice"
|
|
@@ -112,13 +112,16 @@ import { registerChartModules, useChart } from './core/useChart'
|
|
|
112
112
|
import { pruneHiddenSeries, toggleHiddenSeries } from './hiddenSeries'
|
|
113
113
|
import { useTooltipDismiss } from './core/useTooltipDismiss'
|
|
114
114
|
import { usePlotKeyboard } from './core/usePlotKeyboard'
|
|
115
|
-
import {
|
|
116
|
-
buildDonutChartOption,
|
|
117
|
-
buildDonutSlices,
|
|
118
|
-
HALF_CENTER_Y,
|
|
119
|
-
} from './donutChartOptions'
|
|
115
|
+
import { buildDonutChartOption, HALF_CENTER_Y } from './donutChartOptions'
|
|
120
116
|
import { formatLabel, formatPercent, formatValue } from './format'
|
|
121
|
-
import {
|
|
117
|
+
import {
|
|
118
|
+
buildSlices,
|
|
119
|
+
drawnSlices,
|
|
120
|
+
sliceEvent,
|
|
121
|
+
sliceLegendItems,
|
|
122
|
+
sliceTooltipItem,
|
|
123
|
+
} from './slices'
|
|
124
|
+
import { useChartTokens, useResolvedConfig } from './tokens'
|
|
122
125
|
import {
|
|
123
126
|
chartAriaLabel,
|
|
124
127
|
documentDir,
|
|
@@ -130,7 +133,6 @@ import ChartLegend from './components/ChartLegend.vue'
|
|
|
130
133
|
import ChartTooltip from './components/ChartTooltip.vue'
|
|
131
134
|
import type {
|
|
132
135
|
ChartExposedRefs,
|
|
133
|
-
ChartLegendItem,
|
|
134
136
|
ChartTooltipItem,
|
|
135
137
|
DonutChartConfig,
|
|
136
138
|
DonutChartEmits,
|
|
@@ -157,18 +159,23 @@ const plotEl = ref<HTMLElement>()
|
|
|
157
159
|
const dir = computed(() => props.dir ?? documentDir())
|
|
158
160
|
const isHalf = computed(() => props.variant === 'half')
|
|
159
161
|
|
|
160
|
-
const config =
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
162
|
+
const config = useResolvedConfig<DonutChartConfig>(
|
|
163
|
+
() => ({
|
|
164
|
+
data: props.data,
|
|
165
|
+
categoryColumn: props.category,
|
|
166
|
+
valueColumn: props.value,
|
|
167
|
+
maxSlices: props.maxSlices,
|
|
168
|
+
order: props.order,
|
|
169
|
+
showDataLabels: props.showDataLabels,
|
|
170
|
+
centerLabel: props.centerLabel,
|
|
171
|
+
variant: props.variant,
|
|
172
|
+
palette: props.palette,
|
|
173
|
+
colors: props.colors,
|
|
174
|
+
dir: dir.value,
|
|
175
|
+
echartOptions: props.echartOptions,
|
|
176
|
+
}),
|
|
177
|
+
plotEl,
|
|
178
|
+
)
|
|
172
179
|
|
|
173
180
|
/**
|
|
174
181
|
* The half readout hangs off the arc's flat edge rather than straddling it:
|
|
@@ -192,7 +199,7 @@ const readoutStyle = computed(() =>
|
|
|
192
199
|
const { tokens } = useChartTokens(plotEl)
|
|
193
200
|
|
|
194
201
|
const slices = computed(() =>
|
|
195
|
-
|
|
202
|
+
buildSlices(config.value, {
|
|
196
203
|
tokens: tokens.value,
|
|
197
204
|
hiddenSlices: hiddenSlices.value,
|
|
198
205
|
}),
|
|
@@ -263,14 +270,7 @@ const { chart, dispatch } = useChart({
|
|
|
263
270
|
},
|
|
264
271
|
click: (params: any) => {
|
|
265
272
|
const slice = sliceByName.value.get(params.name)
|
|
266
|
-
if (
|
|
267
|
-
emit('select', {
|
|
268
|
-
name: slice.name,
|
|
269
|
-
label: slice.label,
|
|
270
|
-
value: slice.value,
|
|
271
|
-
percent: slice.percent,
|
|
272
|
-
rows: slice.rows,
|
|
273
|
-
})
|
|
273
|
+
if (slice) emit('select', sliceEvent(slice))
|
|
274
274
|
},
|
|
275
275
|
},
|
|
276
276
|
onZrEvents: {
|
|
@@ -305,32 +305,15 @@ function showTooltip(name: string) {
|
|
|
305
305
|
return
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
tooltip.items = [
|
|
309
|
-
{
|
|
310
|
-
name: slice.name,
|
|
311
|
-
label: slice.label,
|
|
312
|
-
color: slice.color,
|
|
313
|
-
value: slice.value,
|
|
314
|
-
formattedValue: formatMeasure(slice.value),
|
|
315
|
-
percent: slice.percent,
|
|
316
|
-
kind: 'series',
|
|
317
|
-
},
|
|
318
|
-
]
|
|
308
|
+
tooltip.items = [sliceTooltipItem(slice, formatMeasure)]
|
|
319
309
|
tooltip.rows = slice.rows
|
|
320
310
|
tooltip.x = pointer.x
|
|
321
311
|
tooltip.y = pointer.y
|
|
322
312
|
tooltip.open = true
|
|
323
313
|
}
|
|
324
314
|
|
|
325
|
-
const legendItems = computed
|
|
326
|
-
slices.value
|
|
327
|
-
name: slice.name,
|
|
328
|
-
label: slice.label,
|
|
329
|
-
color: slice.color,
|
|
330
|
-
hidden: slice.hidden,
|
|
331
|
-
// A hidden slice has no share of the visible total, so it shows none.
|
|
332
|
-
hint: slice.hidden ? undefined : formatPercent(slice.percent),
|
|
333
|
-
})),
|
|
315
|
+
const legendItems = computed(() =>
|
|
316
|
+
sliceLegendItems(slices.value, formatMeasure),
|
|
334
317
|
)
|
|
335
318
|
|
|
336
319
|
// The ring is one tab stop and the arrow keys walk it: an echarts plot draws
|
|
@@ -362,14 +345,7 @@ const { attrs: plotAttrs } = usePlotKeyboard({
|
|
|
362
345
|
move: readSlice,
|
|
363
346
|
activate: (index) => {
|
|
364
347
|
const slice = visibleSlices.value[index]
|
|
365
|
-
if (
|
|
366
|
-
emit('select', {
|
|
367
|
-
name: slice.name,
|
|
368
|
-
label: slice.label,
|
|
369
|
-
value: slice.value,
|
|
370
|
-
percent: slice.percent,
|
|
371
|
-
rows: slice.rows,
|
|
372
|
-
})
|
|
348
|
+
if (slice) emit('select', sliceEvent(slice))
|
|
373
349
|
},
|
|
374
350
|
clear: () => {
|
|
375
351
|
hovered.value = null
|
|
@@ -382,7 +358,7 @@ function toggleSlice(name: string) {
|
|
|
382
358
|
hiddenSlices.value = toggleHiddenSeries(
|
|
383
359
|
hiddenSlices.value,
|
|
384
360
|
name,
|
|
385
|
-
slices.value.
|
|
361
|
+
drawnSlices(slices.value).map((slice) => slice.name),
|
|
386
362
|
)
|
|
387
363
|
}
|
|
388
364
|
|