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.
Files changed (194) hide show
  1. package/experimental/Calendar/CalendarEventRow.vue +0 -4
  2. package/experimental/Calendar/calendarUtils.ts +33 -21
  3. package/experimental/CommandPalette/CommandPaletteItem.vue +9 -1
  4. package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
  5. package/experimental/MultiEmailInput/types.ts +12 -3
  6. package/experimental/SpriteIcons/IconPicker.vue +2 -1
  7. package/experimental/Stepper/StepIndicator.vue +129 -0
  8. package/experimental/Stepper/Stepper.api.md +117 -0
  9. package/experimental/Stepper/Stepper.md +95 -0
  10. package/experimental/Stepper/Stepper.vue +82 -0
  11. package/experimental/Stepper/StepperHorizontal.vue +93 -0
  12. package/experimental/Stepper/StepperVertical.vue +291 -0
  13. package/experimental/Stepper/index.ts +11 -0
  14. package/experimental/Stepper/resolve.ts +87 -0
  15. package/experimental/Stepper/types.ts +89 -0
  16. package/experimental.ts +2 -21
  17. package/package.json +1 -3
  18. package/src/charts/CalendarHeatmapChart.vue +353 -0
  19. package/src/charts/DonutChart.vue +34 -58
  20. package/src/charts/HeatmapChart.vue +26 -64
  21. package/src/charts/NumberCard.vue +62 -7
  22. package/src/charts/PercentageBarChart.vue +243 -0
  23. package/src/charts/SankeyChart.vue +14 -11
  24. package/src/charts/ScatterChart.vue +24 -20
  25. package/src/charts/axisChartCommon.ts +182 -18
  26. package/src/charts/axisFormat.ts +8 -3
  27. package/src/charts/calendarHeatmapOptions.ts +604 -0
  28. package/src/charts/colorMath.ts +26 -0
  29. package/src/charts/components/ChartContainer.vue +63 -53
  30. package/src/charts/components/ChartLegend.vue +216 -24
  31. package/src/charts/components/ChartScale.vue +85 -0
  32. package/src/charts/core/dataLabelFit.ts +45 -6
  33. package/src/charts/core/useAxisChart.ts +36 -19
  34. package/src/charts/core/useChart.ts +6 -1
  35. package/src/charts/core/usePlotKeyboard.ts +13 -2
  36. package/src/charts/docs/BarChart.md +11 -3
  37. package/src/charts/docs/CalendarHeatmapChart.api.md +165 -0
  38. package/src/charts/docs/CalendarHeatmapChart.md +33 -0
  39. package/src/charts/docs/ChartContainer.api.md +6 -0
  40. package/src/charts/docs/ChartLegend.api.md +1 -1
  41. package/src/charts/docs/ChartLegend.md +25 -3
  42. package/src/charts/docs/DonutChart.api.md +12 -0
  43. package/src/charts/docs/DonutChart.md +17 -0
  44. package/src/charts/docs/HeatmapChart.api.md +1 -1
  45. package/src/charts/docs/LineChart.md +5 -3
  46. package/src/charts/docs/NumberCard.api.md +6 -0
  47. package/src/charts/docs/NumberCard.md +6 -0
  48. package/src/charts/docs/Overview.md +13 -6
  49. package/src/charts/docs/PercentageBarChart.api.md +148 -0
  50. package/src/charts/docs/PercentageBarChart.md +42 -0
  51. package/src/charts/docs/ScatterChart.md +2 -3
  52. package/src/charts/donutChartOptions.ts +22 -130
  53. package/src/charts/format.ts +4 -1
  54. package/src/charts/heatmapOptions.ts +17 -12
  55. package/src/charts/hiddenSeries.ts +8 -3
  56. package/src/charts/index.ts +12 -0
  57. package/src/charts/legendOverflow.ts +40 -0
  58. package/src/charts/numberCardFormat.ts +19 -13
  59. package/src/charts/referenceLines.ts +2 -1
  60. package/src/charts/scatterOptions.ts +16 -3
  61. package/src/charts/seriesData.ts +8 -3
  62. package/src/charts/slices.ts +228 -0
  63. package/src/charts/tokens.ts +99 -0
  64. package/src/charts/types.ts +318 -9
  65. package/src/components/Avatar/Avatar.md +27 -2
  66. package/src/components/Avatar/Avatar.vue +29 -12
  67. package/src/components/Breadcrumbs/Breadcrumbs.vue +2 -1
  68. package/src/components/Combobox/Combobox.vue +9 -2
  69. package/src/components/Combobox/ComboboxResults.vue +6 -1
  70. package/src/components/Combobox/utils.ts +2 -1
  71. package/src/components/DatePicker/DatePicker.md +7 -0
  72. package/src/components/DatePicker/DatePicker.vue +6 -0
  73. package/src/components/DatePicker/DateTimePicker.vue +6 -0
  74. package/src/components/DatePicker/composables.ts +18 -1
  75. package/src/components/DatePicker/utils.ts +53 -0
  76. package/src/components/Dialog/Dialog.md +3 -1
  77. package/src/components/Duration/Duration.api.md +16 -3
  78. package/src/components/Duration/Duration.md +21 -0
  79. package/src/components/Duration/Duration.vue +29 -8
  80. package/src/components/Duration/duration.ts +105 -44
  81. package/src/components/Duration/index.ts +1 -0
  82. package/src/components/Duration/types.ts +30 -1
  83. package/src/components/HoverCard/HoverCard.vue +21 -5
  84. package/src/components/Menu/utils.ts +3 -2
  85. package/src/components/MobileNav/MobileNavItem.vue +3 -22
  86. package/src/components/MultiSelect/MultiSelect.api.md +5 -0
  87. package/src/components/MultiSelect/MultiSelect.vue +34 -0
  88. package/src/components/MultiSelect/MultiSelectResults.vue +3 -4
  89. package/src/components/MultiSelect/types.ts +6 -0
  90. package/src/components/Select/Select.vue +4 -4
  91. package/src/components/Select/utils.ts +1 -0
  92. package/src/components/SettingsDialog/SettingsDialog.api.md +7 -2
  93. package/src/components/SettingsDialog/SettingsDialog.md +2 -1
  94. package/src/components/SettingsDialog/SettingsRow.vue +12 -2
  95. package/src/components/Sidebar/SidebarItem.vue +3 -33
  96. package/src/components/SidebarRail/SidebarRailItem.vue +4 -17
  97. package/src/components/Switch/Switch.vue +3 -3
  98. package/src/components/Tooltip/Tooltip.vue +8 -0
  99. package/src/components/shared/deferredTrigger.ts +174 -0
  100. package/src/components/shared/navLink.ts +45 -0
  101. package/src/components/shared/selection/utils.ts +8 -1
  102. package/src/data-fetching/useCall/useCall.ts +25 -26
  103. package/src/data-fetching/useFrappeFetch.ts +48 -2
  104. package/src/data-fetching/useList/useList.ts +11 -3
  105. package/src/data-fetching/utils.ts +15 -1
  106. package/src/molecules/editor/components/MediaNodeView.vue +10 -1
  107. package/src/molecules/editor/components/MediaResizeGuide.vue +71 -0
  108. package/src/molecules/editor/components/media-node-view-utils.ts +7 -0
  109. package/src/molecules/editor/composables/useNodeViewResize.ts +142 -10
  110. package/src/molecules/editor/extensions/attachment/attachment-engine.ts +1 -1
  111. package/src/molecules/editor/extensions/content-paste/paste-html-utils.ts +16 -6
  112. package/src/molecules/editor/extensions/iframe/IframeNodeView.vue +29 -10
  113. package/src/molecules/editor/extensions/iframe/iframe-allowlist.ts +35 -16
  114. package/src/molecules/editor/extensions/iframe/iframe-embed-utils.ts +1 -1
  115. package/src/molecules/editor/extensions/iframe/iframe-extension.ts +30 -30
  116. package/src/molecules/editor/extensions/link/LinkEditorPopup.vue +1 -1
  117. package/src/molecules/editor/extensions/link/link-paste-plugin.ts +1 -1
  118. package/src/molecules/editor/extensions/shared/media-upload-engine.ts +1 -1
  119. package/src/molecules/editor/useEditor.ts +12 -6
  120. package/src/molecules/list/ListRow.vue +8 -1
  121. package/src/utils/dialog.ts +57 -16
  122. package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
  123. package/tailwind/content.js +1 -1
  124. package/tailwind/plugin.js +22 -0
  125. package/vite/README.md +5 -3
  126. package/vite/codeLanguages.js +41 -17
  127. package/vite/doctypeInterfaceGenerator.js +52 -39
  128. package/vitepress/index.node.ts +0 -2
  129. package/experimental/TextEditor/TextEditor.api.md +0 -161
  130. package/experimental/TextEditor/TextEditor.vue +0 -298
  131. package/experimental/TextEditor/classIcon.ts +0 -21
  132. package/experimental/TextEditor/commands.js +0 -344
  133. package/experimental/TextEditor/components/CodeBlockComponent.vue +0 -103
  134. package/experimental/TextEditor/components/FontColor.vue +0 -153
  135. package/experimental/TextEditor/components/ImageViewerModal.vue +0 -463
  136. package/experimental/TextEditor/components/InsertImage.vue +0 -54
  137. package/experimental/TextEditor/components/InsertLink.vue +0 -13
  138. package/experimental/TextEditor/components/InsertVideo.vue +0 -14
  139. package/experimental/TextEditor/components/LinkPopup.vue +0 -99
  140. package/experimental/TextEditor/components/MediaNodeView.vue +0 -398
  141. package/experimental/TextEditor/components/MentionList.vue +0 -95
  142. package/experimental/TextEditor/components/TextEditorBubbleMenu.vue +0 -78
  143. package/experimental/TextEditor/components/TextEditorFixedMenu.vue +0 -78
  144. package/experimental/TextEditor/components/TextEditorFloatingMenu.vue +0 -61
  145. package/experimental/TextEditor/components/TextEditorMenu.vue +0 -218
  146. package/experimental/TextEditor/components/index.js +0 -0
  147. package/experimental/TextEditor/extensions/code-block.ts +0 -119
  148. package/experimental/TextEditor/extensions/color/color-extension.ts +0 -140
  149. package/experimental/TextEditor/extensions/color/color-styles.css +0 -25
  150. package/experimental/TextEditor/extensions/color/index.ts +0 -2
  151. package/experimental/TextEditor/extensions/content-paste-extension.ts +0 -160
  152. package/experimental/TextEditor/extensions/copy-styles.ts +0 -160
  153. package/experimental/TextEditor/extensions/emoji/EmojiList.vue +0 -55
  154. package/experimental/TextEditor/extensions/emoji/emoji-extension.ts +0 -55
  155. package/experimental/TextEditor/extensions/emoji/emojis.json +0 -7422
  156. package/experimental/TextEditor/extensions/heading/heading.ts +0 -20
  157. package/experimental/TextEditor/extensions/highlight/highlight-extension.ts +0 -241
  158. package/experimental/TextEditor/extensions/highlight/highlight-styles.css +0 -31
  159. package/experimental/TextEditor/extensions/highlight/index.ts +0 -2
  160. package/experimental/TextEditor/extensions/iframe/IframeNodeView.vue +0 -308
  161. package/experimental/TextEditor/extensions/iframe/InsertIframe.vue +0 -209
  162. package/experimental/TextEditor/extensions/iframe/iframe-extension.ts +0 -404
  163. package/experimental/TextEditor/extensions/iframe/index.ts +0 -11
  164. package/experimental/TextEditor/extensions/iframe/utils.ts +0 -283
  165. package/experimental/TextEditor/extensions/image/image-extension.ts +0 -661
  166. package/experimental/TextEditor/extensions/image/index.ts +0 -5
  167. package/experimental/TextEditor/extensions/image-group/ImageGroupNodeView.vue +0 -182
  168. package/experimental/TextEditor/extensions/image-group/ImageGroupUploadDialog.vue +0 -740
  169. package/experimental/TextEditor/extensions/image-group/image-group-extension.ts +0 -187
  170. package/experimental/TextEditor/extensions/image-viewer-extension.ts +0 -162
  171. package/experimental/TextEditor/extensions/link/index.ts +0 -1
  172. package/experimental/TextEditor/extensions/link/link-extension.ts +0 -323
  173. package/experimental/TextEditor/extensions/link/linkPasteHandler.ts +0 -51
  174. package/experimental/TextEditor/extensions/mention/index.ts +0 -1
  175. package/experimental/TextEditor/extensions/mention/mention-extension.ts +0 -204
  176. package/experimental/TextEditor/extensions/mention/style.css +0 -11
  177. package/experimental/TextEditor/extensions/shared/color-utils.ts +0 -236
  178. package/experimental/TextEditor/extensions/slash-commands/SlashCommandsList.vue +0 -59
  179. package/experimental/TextEditor/extensions/slash-commands/slash-commands-extension.ts +0 -184
  180. package/experimental/TextEditor/extensions/suggestion/SuggestionList.vue +0 -130
  181. package/experimental/TextEditor/extensions/suggestion/createSuggestionExtension.ts +0 -151
  182. package/experimental/TextEditor/extensions/suggestion/index.ts +0 -5
  183. package/experimental/TextEditor/extensions/tag/index.ts +0 -1
  184. package/experimental/TextEditor/extensions/tag/tag-extension.ts +0 -170
  185. package/experimental/TextEditor/extensions/toc-node/TocNodeView.vue +0 -439
  186. package/experimental/TextEditor/extensions/toc-node/index.ts +0 -3
  187. package/experimental/TextEditor/extensions/toc-node/toc-node-extension.ts +0 -167
  188. package/experimental/TextEditor/extensions/video-extension.ts +0 -653
  189. package/experimental/TextEditor/hljs-github.css +0 -197
  190. package/experimental/TextEditor/index.ts +0 -21
  191. package/experimental/TextEditor/style.css +0 -190
  192. package/experimental/TextEditor/types.ts +0 -72
  193. package/experimental/TextEditor/utils.js +0 -11
  194. package/src/utils/url-validation.ts +0 -39
@@ -36,37 +36,15 @@
36
36
  v-bind="plotAttrs"
37
37
  />
38
38
 
39
- <!-- `text-2xs` is `AXIS_LABEL_FONT_SIZE` as a class: 11px and tight,
40
- because these read as axis labels rather than as captions. -->
41
- <div
42
- data-slot="chart-scale"
43
- class="ms-2 flex shrink-0 flex-col items-center justify-end"
44
- >
45
- <span class="text-2xs tabular-nums text-ink-gray-5">
46
- {{ scale.max }}
47
- </span>
48
- <!-- Grows into the room it has and stops: a ramp as tall as the card
49
- reads as a second column of data rather than as a key to one. -->
50
- <span
51
- class="mt-2 min-h-8 max-h-20 w-2 flex-1 rounded-1"
52
- :style="{ backgroundImage: scale.gradient }"
53
- />
54
- <!-- Holds the whole label row, so `min` starts where an x-axis label
55
- starts. Its own height until the first layout, or the first frame
56
- would draw a collapsed box. -->
57
- <span
58
- data-slot="chart-scale-min"
59
- class="text-2xs tabular-nums text-ink-gray-5"
60
- :style="{
61
- marginTop: `${AXIS_LABEL_MARGIN}px`,
62
- height: xLabelRowHeight
63
- ? `${Math.max(xLabelRowHeight - AXIS_LABEL_MARGIN, 0)}px`
64
- : undefined,
65
- }"
66
- >
67
- {{ scale.min }}
68
- </span>
69
- </div>
39
+ <ChartScale
40
+ class="ms-2 shrink-0"
41
+ vertical
42
+ :min="matrix.min"
43
+ :max="matrix.max"
44
+ :stops="matrix.stops"
45
+ :format="format"
46
+ :label-row-height="xLabelRowHeight"
47
+ />
70
48
  </div>
71
49
 
72
50
  <!-- The tooltip hangs off the pointer, which a reader walking the grid
@@ -98,17 +76,16 @@ import { LabelLayout } from 'echarts/features'
98
76
  import { registerChartModules, useChart } from './core/useChart'
99
77
  import { usePlotKeyboard } from './core/usePlotKeyboard'
100
78
  import { useTooltipDismiss } from './core/useTooltipDismiss'
101
- import { AXIS_LABEL_MARGIN } from './axisChartCommon'
102
79
  import {
103
80
  buildHeatmapMatrix,
104
81
  buildHeatmapOption,
105
82
  heatmapCategoryLabel,
106
- sampleRamp,
107
83
  } from './heatmapOptions'
108
84
  import { formatLabel, formatValue } from './format'
109
- import { useChartTokens } from './tokens'
85
+ import { useChartTokens, useResolvedConfig } from './tokens'
110
86
  import { chartAriaLabel, documentDir, plotReading } from './utils'
111
87
  import ChartContainer from './components/ChartContainer.vue'
88
+ import ChartScale from './components/ChartScale.vue'
112
89
  import ChartTooltip from './components/ChartTooltip.vue'
113
90
  import type {
114
91
  ChartExposedRefs,
@@ -138,18 +115,21 @@ const plotEl = ref<HTMLElement>()
138
115
 
139
116
  const dir = computed(() => props.dir ?? documentDir())
140
117
 
141
- const config = computed<HeatmapChartConfig>(() => ({
142
- data: props.data,
143
- xColumn: props.x,
144
- yColumn: props.y,
145
- valueColumn: props.value,
146
- min: props.min,
147
- max: props.max,
148
- showDataLabels: props.showDataLabels,
149
- palette: props.palette,
150
- dir: dir.value,
151
- echartOptions: props.echartOptions,
152
- }))
118
+ const config = useResolvedConfig<HeatmapChartConfig>(
119
+ () => ({
120
+ data: props.data,
121
+ xColumn: props.x,
122
+ yColumn: props.y,
123
+ valueColumn: props.value,
124
+ min: props.min,
125
+ max: props.max,
126
+ showDataLabels: props.showDataLabels,
127
+ palette: props.palette,
128
+ dir: dir.value,
129
+ echartOptions: props.echartOptions,
130
+ }),
131
+ plotEl,
132
+ )
153
133
 
154
134
  const { tokens } = useChartTokens(plotEl)
155
135
 
@@ -391,23 +371,5 @@ const keyboard = usePlotKeyboard({
391
371
 
392
372
  const plotAttrs = keyboard.attrs
393
373
 
394
- /** The ramp scale in the chrome, painted from the stops the cells came from. */
395
- const scale = computed(() => {
396
- const { min, max, stops } = matrix.value
397
- return {
398
- min: shorten(min),
399
- max: shorten(max),
400
- // Upright, low end at the foot. The labels sit above and below the ramp
401
- // rather than either side of it, so this reads the same in both directions
402
- // and RTL has nothing to flip.
403
- gradient: `linear-gradient(to top, ${sampleRamp(stops).join(', ')})`,
404
- }
405
- })
406
-
407
- /** The scale endpoints sit in a narrow strip, so they read shortened. */
408
- function shorten(value: number) {
409
- return props.format ? props.format(value) : formatValue(value, 1, true)
410
- }
411
-
412
374
  defineExpose<ChartExposedRefs>({ chart: computed(() => chart.value) })
413
375
  </script>
@@ -62,7 +62,11 @@
62
62
  class="relative flex min-w-0 flex-col gap-1.5"
63
63
  :class="{ 'pb-10': showSparkline }"
64
64
  >
65
- <div class="flex min-w-0 items-center justify-between gap-3">
65
+ <div
66
+ v-if="showTitleRow"
67
+ data-slot="chart-header"
68
+ class="flex min-w-0 items-center justify-between gap-3"
69
+ >
66
70
  <!-- The font-size class is on the row, not on the title span, so slot
67
71
  content sized in `em` follows the card's smaller title. Zero
68
72
  height for the same reason `#actions` has it. -->
@@ -172,6 +176,39 @@
172
176
  </span>
173
177
  </slot>
174
178
  </div>
179
+
180
+ <!-- Past 100 the track shrinks to 100's share of the reading and the
181
+ rest fills beside it, so a reading over its whole shows how far. -->
182
+ <div
183
+ v-if="showProgress"
184
+ class="mt-0.5 flex h-1 gap-0.5"
185
+ role="meter"
186
+ aria-valuemin="0"
187
+ :aria-valuemax="Math.max(progressValue, 100)"
188
+ :aria-valuenow="progressValue"
189
+ :aria-valuetext="`${Math.round(progressValue)}%`"
190
+ :aria-label="title"
191
+ >
192
+ <div
193
+ class="h-full overflow-hidden rounded-full bg-surface-gray-3"
194
+ :style="{ width: `${progressWhole}%` }"
195
+ >
196
+ <!-- At least as wide as it is tall: a reading of 0.05% is not 0. -->
197
+ <div
198
+ v-if="progressValue > 0"
199
+ class="h-full min-w-1 rounded-full"
200
+ :style="{
201
+ width: `${Math.min(progressValue, 100)}%`,
202
+ ...progressStyle,
203
+ }"
204
+ />
205
+ </div>
206
+ <div
207
+ v-if="progressWhole < 100"
208
+ class="h-full flex-1 rounded-full"
209
+ :style="progressStyle"
210
+ />
211
+ </div>
175
212
  </template>
176
213
  </div>
177
214
  </ChartCard>
@@ -225,11 +262,13 @@ const TONE_CLASSES: Record<DeltaTone, string> = {
225
262
  neutral: 'text-ink-gray-6',
226
263
  }
227
264
 
228
- const direction = computed(() => deltaDirection(props.delta))
229
- const toneClass = computed(
230
- () => TONE_CLASSES[deltaTone(props.delta, props.negativeIsBetter)],
231
- )
265
+ const direction = computed(() => deltaDirection(props))
266
+ const toneClass = computed(() => TONE_CLASSES[deltaTone(props)])
232
267
  const formattedDelta = computed(() => formatCardDelta(props, props.delta))
268
+ // An empty row would still take the column's gap above the number.
269
+ const showTitleRow = computed(() =>
270
+ Boolean(props.title || slots['title-suffix'] || slots.actions),
271
+ )
233
272
  const showEmptySlot = computed(() => isEmpty.value && Boolean(slots.empty))
234
273
  // Only over a reading. The em dash a card with no value prints is not a number
235
274
  // the color says anything about, and the loading skeleton is not one either.
@@ -289,10 +328,15 @@ const areaPath = computed(() =>
289
328
  )
290
329
 
291
330
  const { tokens } = useChartTokens(root)
331
+ const defaultColor = computed(
332
+ () => paletteColors('sequential', tokens.value, 1)[0],
333
+ )
292
334
  const sparklineColor = computed(
293
- () =>
294
- props.sparkline?.color ?? paletteColors('sequential', tokens.value, 1)[0],
335
+ () => props.sparkline?.color ?? defaultColor.value,
295
336
  )
337
+ const progressStyle = computed(() => ({
338
+ backgroundColor: props.progress?.color ?? defaultColor.value,
339
+ }))
296
340
 
297
341
  // Time runs with the reading direction, so an RTL card reads oldest-first from
298
342
  // the right. Mirroring the box is enough: the line carries no text.
@@ -311,6 +355,17 @@ const formattedValue = computed(() =>
311
355
  // one would collapse it and take the block's other variants with it.
312
356
  const valueText = computed(() => formattedValue.value || '—')
313
357
 
358
+ const showProgress = computed(
359
+ () =>
360
+ props.progress != null &&
361
+ Number.isFinite(props.progress.value) &&
362
+ !isEmpty.value,
363
+ )
364
+ const progressValue = computed(() => Math.max(props.progress?.value ?? 0, 0))
365
+ const progressWhole = computed(() =>
366
+ progressValue.value > 100 ? (100 / progressValue.value) * 100 : 100,
367
+ )
368
+
314
369
  // Not counted up, and never printed beside the em dash: nothing measured
315
370
  // against a target reads as a target of its own.
316
371
  const targetText = computed(() =>
@@ -0,0 +1,243 @@
1
+ <template>
2
+ <ChartContainer
3
+ :title="title"
4
+ :subtitle="subtitle"
5
+ :loading="loading"
6
+ :error="error"
7
+ :empty="isEmpty"
8
+ centered
9
+ :dir="dir"
10
+ >
11
+ <template v-if="$slots.actions" #actions><slot name="actions" /></template>
12
+ <template v-if="$slots['title-suffix']" #title-suffix>
13
+ <slot name="title-suffix" />
14
+ </template>
15
+
16
+ <!-- The container owns the three states, so an app that wants a retry
17
+ button beside the message or a skeleton of its own reaches them here
18
+ rather than dropping the chart and rebuilding the chrome. -->
19
+ <template v-if="$slots.loading" #loading><slot name="loading" /></template>
20
+ <template v-if="$slots.error" #error="slotProps">
21
+ <slot name="error" v-bind="slotProps" />
22
+ </template>
23
+ <template v-if="$slots.empty" #empty><slot name="empty" /></template>
24
+
25
+ <template #default>
26
+ <div ref="root" class="flex h-full w-full items-center">
27
+ <!-- With every slice at zero the track is drawn bare, as the ring is. -->
28
+ <div
29
+ role="group"
30
+ :aria-label="chartAriaLabel(title, subtitle)"
31
+ class="flex h-3 w-full gap-0.5 rounded-1"
32
+ :style="
33
+ drawn.length ? undefined : { backgroundColor: tokens.gridline }
34
+ "
35
+ >
36
+ <!-- Grown by share rather than by value: grow factors that sum to
37
+ less than 1 leave part of the track empty. The floor keeps a
38
+ sliver of a share on the track, so its legend entry points at
39
+ something. -->
40
+ <button
41
+ v-for="slice in drawn"
42
+ :key="slice.name"
43
+ type="button"
44
+ class="h-full min-w-1 overflow-hidden rounded-1 transition-opacity focus-visible:focus-ring motion-reduce:transition-none"
45
+ :style="{
46
+ flex: `${slice.percent} 1 0`,
47
+ backgroundColor: slice.color,
48
+ opacity:
49
+ highlighted && highlighted !== slice.name
50
+ ? BLUR_OPACITY
51
+ : undefined,
52
+ }"
53
+ :aria-label="sliceLabel(slice)"
54
+ @mouseenter="hover(slice, $event)"
55
+ @mousemove="track($event)"
56
+ @mouseleave="clearHover"
57
+ @focus="focusSlice(slice, $event)"
58
+ @blur="clearHover"
59
+ @click="emit('select', sliceEvent(slice))"
60
+ />
61
+ </div>
62
+ </div>
63
+
64
+ <ChartTooltip
65
+ :open="tooltip.open"
66
+ :x="tooltip.x"
67
+ :y="tooltip.y"
68
+ :items="tooltip.items"
69
+ :rows="tooltip.rows"
70
+ :dir="dir"
71
+ >
72
+ <template v-if="$slots.tooltip" #default="slotProps">
73
+ <slot name="tooltip" v-bind="slotProps" />
74
+ </template>
75
+ </ChartTooltip>
76
+ </template>
77
+
78
+ <template v-if="legendItems.length" #legend>
79
+ <ChartLegend
80
+ :items="legendItems"
81
+ @change="toggleSlice"
82
+ @highlight="hovered = $event"
83
+ />
84
+ </template>
85
+ </ChartContainer>
86
+ </template>
87
+
88
+ <script setup lang="ts">
89
+ import { computed, reactive, ref, watch } from 'vue'
90
+ import { BLUR_OPACITY } from './axisChartCommon'
91
+ import { formatPercent, formatValue } from './format'
92
+ import { pruneHiddenSeries, toggleHiddenSeries } from './hiddenSeries'
93
+ import { useTooltipDismiss } from './core/useTooltipDismiss'
94
+ import {
95
+ buildSlices,
96
+ drawnSlices,
97
+ sliceEvent,
98
+ sliceLegendItems,
99
+ sliceTooltipItem,
100
+ } from './slices'
101
+ import { useChartTokens } from './tokens'
102
+ import { chartAriaLabel, documentDir } from './utils'
103
+ import ChartContainer from './components/ChartContainer.vue'
104
+ import ChartLegend from './components/ChartLegend.vue'
105
+ import ChartTooltip from './components/ChartTooltip.vue'
106
+ import type {
107
+ ChartTooltipItem,
108
+ DonutSlice,
109
+ PercentageBarChartEmits,
110
+ PercentageBarChartProps,
111
+ PercentageBarChartSlots,
112
+ } from './types'
113
+
114
+ // The donut's slices laid along one track. No echarts: each slice is a button,
115
+ // so it takes its own tab stop and focus ring where a canvas region cannot.
116
+
117
+ const props = defineProps<PercentageBarChartProps>()
118
+
119
+ const hiddenSlices = defineModel<string[]>('hiddenSlices', {
120
+ default: () => [],
121
+ })
122
+
123
+ const emit = defineEmits<PercentageBarChartEmits>()
124
+
125
+ defineSlots<PercentageBarChartSlots>()
126
+
127
+ const root = ref<HTMLElement>()
128
+ const dir = computed(() => props.dir ?? documentDir())
129
+
130
+ const { tokens } = useChartTokens(root)
131
+
132
+ const slices = computed(() =>
133
+ buildSlices(
134
+ {
135
+ data: props.data,
136
+ categoryColumn: props.category,
137
+ valueColumn: props.value,
138
+ maxSlices: props.maxSlices,
139
+ order: props.order,
140
+ palette: props.palette,
141
+ colors: props.colors,
142
+ },
143
+ { tokens: tokens.value, hiddenSlices: hiddenSlices.value },
144
+ ),
145
+ )
146
+ const drawn = computed(() => drawnSlices(slices.value))
147
+ const isEmpty = computed(() => slices.value.every((slice) => slice.hidden))
148
+
149
+ /** Slice under the pointer, under the keyboard focus, or under the legend. */
150
+ const hovered = ref<string | null>(null)
151
+
152
+ /**
153
+ * The rest of the track steps back from the hovered slice, as the ring does. A
154
+ * hidden slice under the legend has no block to step back from.
155
+ */
156
+ const highlighted = computed(() =>
157
+ drawn.value.some((slice) => slice.name === hovered.value)
158
+ ? hovered.value
159
+ : null,
160
+ )
161
+
162
+ const tooltip = reactive({
163
+ open: false,
164
+ x: 0,
165
+ y: 0,
166
+ items: [] as ChartTooltipItem[],
167
+ /** Plural: a slice groups, and "Others" groups the whole tail. */
168
+ rows: [] as Record<string, any>[],
169
+ })
170
+
171
+ useTooltipDismiss({
172
+ plot: root,
173
+ data: () => drawn.value,
174
+ close: () => {
175
+ tooltip.open = false
176
+ },
177
+ })
178
+
179
+ function hover(slice: DonutSlice, event: MouseEvent) {
180
+ readSlice(slice)
181
+ track(event)
182
+ tooltip.open = true
183
+ }
184
+
185
+ // A keyboard reader has no pointer to anchor the tooltip to, so it hangs off the
186
+ // bottom of the slice itself.
187
+ function focusSlice(slice: DonutSlice, event: FocusEvent) {
188
+ readSlice(slice)
189
+ const rect = (event.currentTarget as HTMLElement).getBoundingClientRect()
190
+ tooltip.x = rect.left + rect.width / 2
191
+ tooltip.y = rect.bottom
192
+ tooltip.open = true
193
+ }
194
+
195
+ function readSlice(slice: DonutSlice) {
196
+ hovered.value = slice.name
197
+ tooltip.items = [sliceTooltipItem(slice, formatMeasure)]
198
+ tooltip.rows = slice.rows
199
+ }
200
+
201
+ function track(event: MouseEvent) {
202
+ tooltip.x = event.clientX
203
+ tooltip.y = event.clientY
204
+ }
205
+
206
+ function clearHover() {
207
+ hovered.value = null
208
+ tooltip.open = false
209
+ }
210
+
211
+ /** The width is what the bar says, so the name carries the share in words. */
212
+ function sliceLabel(slice: DonutSlice) {
213
+ return `${slice.label}, ${formatMeasure(slice.value)}, ${formatPercent(
214
+ slice.percent,
215
+ )}`
216
+ }
217
+
218
+ function formatMeasure(value: number) {
219
+ return props.format ? props.format(value) : formatValue(value)
220
+ }
221
+
222
+ const legendItems = computed(() =>
223
+ sliceLegendItems(slices.value, formatMeasure),
224
+ )
225
+
226
+ function toggleSlice(name: string) {
227
+ hiddenSlices.value = toggleHiddenSeries(
228
+ hiddenSlices.value,
229
+ name,
230
+ drawn.value.map((slice) => slice.name),
231
+ )
232
+ }
233
+
234
+ // Slices that disappear while hidden shouldn't stay in the hidden list forever.
235
+ // Only ever assigns when something really went away: `slices` reads
236
+ // `hiddenSlices`, so an unconditional write here would feed itself.
237
+ watch(
238
+ () => slices.value.map((slice) => slice.name),
239
+ (names) => {
240
+ hiddenSlices.value = pruneHiddenSeries(hiddenSlices.value, names)
241
+ },
242
+ )
243
+ </script>
@@ -60,7 +60,7 @@ import { usePlotKeyboard } from './core/usePlotKeyboard'
60
60
  import { useTooltipDismiss } from './core/useTooltipDismiss'
61
61
  import { buildSankeyGraph, buildSankeyOption } from './sankeyOptions'
62
62
  import { formatLabel, formatValue } from './format'
63
- import { useChartTokens } from './tokens'
63
+ import { useChartTokens, useResolvedConfig } from './tokens'
64
64
  import {
65
65
  chartAriaLabel,
66
66
  documentDir,
@@ -93,16 +93,19 @@ const plotEl = ref<HTMLElement>()
93
93
 
94
94
  const dir = computed(() => props.dir ?? documentDir())
95
95
 
96
- const config = computed<SankeyChartConfig>(() => ({
97
- data: props.data,
98
- sourceColumn: props.source,
99
- targetColumn: props.target,
100
- valueColumn: props.value,
101
- vertical: props.vertical,
102
- nodeAlign: props.nodeAlign,
103
- palette: props.palette,
104
- echartOptions: props.echartOptions,
105
- }))
96
+ const config = useResolvedConfig<SankeyChartConfig>(
97
+ () => ({
98
+ data: props.data,
99
+ sourceColumn: props.source,
100
+ targetColumn: props.target,
101
+ valueColumn: props.value,
102
+ vertical: props.vertical,
103
+ nodeAlign: props.nodeAlign,
104
+ palette: props.palette,
105
+ echartOptions: props.echartOptions,
106
+ }),
107
+ plotEl,
108
+ )
106
109
 
107
110
  const { tokens } = useChartTokens(plotEl)
108
111
 
@@ -72,7 +72,7 @@ import { useTooltipDismiss } from './core/useTooltipDismiss'
72
72
  import { buildScatterOption, buildScatterSeries } from './scatterOptions'
73
73
  import { formatLabel, formatValue } from './format'
74
74
  import { pruneHiddenSeries, toggleHiddenSeries } from './hiddenSeries'
75
- import { useChartTokens } from './tokens'
75
+ import { useChartTokens, useResolvedConfig } from './tokens'
76
76
  import { chartAriaLabel, documentDir, plotReading } from './utils'
77
77
  import ChartContainer from './components/ChartContainer.vue'
78
78
  import ChartLegend from './components/ChartLegend.vue'
@@ -119,21 +119,24 @@ const dir = computed(() => props.dir ?? documentDir())
119
119
  const formatX = computed(() => props.xAxis?.format ?? props.format)
120
120
  const formatY = computed(() => props.yAxis?.format ?? props.format)
121
121
 
122
- const config = computed<ScatterChartConfig>(() => ({
123
- data: props.data,
124
- xColumn: props.x,
125
- yColumn: props.y,
126
- sizeColumn: props.size,
127
- splitByColumn: props.splitBy,
128
- labelColumn: props.label,
129
- showDataLabels: props.showDataLabels,
130
- xAxis: toValueAxis(props.xAxis),
131
- yAxis: toValueAxis(props.yAxis),
132
- referenceLines: props.referenceLines,
133
- palette: props.palette,
134
- dir: dir.value,
135
- echartOptions: props.echartOptions,
136
- }))
122
+ const config = useResolvedConfig<ScatterChartConfig>(
123
+ () => ({
124
+ data: props.data,
125
+ xColumn: props.x,
126
+ yColumn: props.y,
127
+ sizeColumn: props.size,
128
+ splitByColumn: props.splitBy,
129
+ labelColumn: props.label,
130
+ showDataLabels: props.showDataLabels,
131
+ xAxis: toValueAxis(props.xAxis),
132
+ yAxis: toValueAxis(props.yAxis),
133
+ referenceLines: props.referenceLines,
134
+ palette: props.palette,
135
+ dir: dir.value,
136
+ echartOptions: props.echartOptions,
137
+ }),
138
+ plotEl,
139
+ )
137
140
 
138
141
  function toValueAxis(axis?: ScatterChartProps['xAxis']) {
139
142
  if (!axis) return undefined
@@ -141,6 +144,7 @@ function toValueAxis(axis?: ScatterChartProps['xAxis']) {
141
144
  title: axis.title,
142
145
  min: axis.min,
143
146
  max: axis.max,
147
+ integer: axis.integer,
144
148
  echartOptions: axis.echartOptions,
145
149
  }
146
150
  }
@@ -157,9 +161,7 @@ const isEmpty = computed(() =>
157
161
 
158
162
  // The y-axis title is chrome rather than an echarts axis name, so it lines up
159
163
  // with the chart title above the plot. The x-axis title is drawn on its axis.
160
- const yAxisTitle = computed(() =>
161
- props.yAxis?.title ? formatLabel(props.yAxis.title) : undefined,
162
- )
164
+ const yAxisTitle = computed(() => props.yAxis?.title || undefined)
163
165
 
164
166
  // A malformed config throws while building the option; surfacing it as an error
165
167
  // state beats letting it bubble out of a render and blank the whole page.
@@ -303,7 +305,9 @@ function toggleSeries(name: string) {
303
305
  hiddenSeries.value = toggleHiddenSeries(
304
306
  hiddenSeries.value,
305
307
  name,
306
- series.value.length,
308
+ series.value
309
+ .filter((entry) => !hiddenSeries.value.includes(entry.name))
310
+ .map((entry) => entry.name),
307
311
  )
308
312
  }
309
313