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
@@ -0,0 +1,148 @@
1
+ <!-- Auto Generated by scripts/propsgen.ts -->
2
+ <script setup>
3
+ import PropsTable from '@/components/Docs/PropsTable.vue'
4
+ import SlotsTable from '@/components/Docs/SlotsTable.vue'
5
+ import EmitsTable from '@/components/Docs/EmitsTable.vue'
6
+
7
+ const propsData = [
8
+ {
9
+ name: 'title',
10
+ description: 'Heads the card. Left out, the chart draws no header row at all.',
11
+ required: false,
12
+ type: 'string'
13
+ },
14
+ {
15
+ name: 'subtitle',
16
+ description: 'A second line under the title, e.g. the period the numbers cover.',
17
+ required: false,
18
+ type: 'string'
19
+ },
20
+ {
21
+ name: 'dir',
22
+ description: 'Forces layout direction; defaults to document.documentElement.dir',
23
+ required: false,
24
+ type: 'ChartDir'
25
+ },
26
+ {
27
+ name: 'loading',
28
+ description: 'Draws the placeholder in place of the plot, for data still on its way.',
29
+ required: false,
30
+ type: 'boolean'
31
+ },
32
+ {
33
+ name: 'error',
34
+ description: 'Puts the chart in its error state and prints this message under it. Data\nthe chart cannot draw shows the empty state, not this one.',
35
+ required: false,
36
+ type: 'string | null'
37
+ },
38
+ {
39
+ name: 'data',
40
+ description: 'The rows to draw. One row is one slice, before the "Others" grouping.',
41
+ required: true,
42
+ type: 'Record<string, any>[]'
43
+ },
44
+ {
45
+ name: 'category',
46
+ description: 'Row key holding the slice name.',
47
+ required: true,
48
+ type: 'string'
49
+ },
50
+ {
51
+ name: 'value',
52
+ description: 'Row key holding the slice size.',
53
+ required: true,
54
+ type: 'string'
55
+ },
56
+ {
57
+ name: 'maxSlices',
58
+ description: 'How many slices the bar holds, "Others" included. Past that the bar keeps\nthe largest `maxSlices - 1` and sums the tail into a single "Others" slice,\nnamed `OTHERS_KEY`. Defaults to 9, as on `DonutChart`, so a breakdown cuts\ninto the same slices on either chart.',
59
+ required: false,
60
+ type: 'number'
61
+ },
62
+ {
63
+ name: 'order',
64
+ description: 'The order the slices go along the bar. `\'size\'` puts the biggest first.\n`\'rows\'` keeps the rows\' order, for categories that already have one, such\nas ageing buckets or months. Either way `maxSlices` keeps the largest, and\n"Others" comes last. Defaults to `\'size\'`, as on `DonutChart`.',
65
+ required: false,
66
+ type: 'SliceOrder'
67
+ },
68
+ {
69
+ name: 'hiddenSlices',
70
+ description: 'Slices the legend has switched off, by name. Bind it with\n`v-model:hiddenSlices` to drive the legend from the app. Left unbound, the\nlegend owns it.',
71
+ required: false,
72
+ type: 'string[]',
73
+ default: '[]'
74
+ },
75
+ {
76
+ name: 'format',
77
+ description: 'Prints the tooltip and each slice\'s accessible name.',
78
+ required: false,
79
+ type: 'ChartValueFormatter'
80
+ },
81
+ {
82
+ name: 'palette',
83
+ description: 'Defaults to `\'categorical\'`: slices are unrelated categories, not steps.',
84
+ required: false,
85
+ type: 'ChartPalette'
86
+ },
87
+ {
88
+ name: 'colors',
89
+ description: 'Pins a color to a slice, keyed by its category value, e.g. `{ Overdue:\n\'var(--ink-red-5)\' }`. `OTHERS_KEY` pins "Others". A category grouped into\n"Others" takes that slice\'s color. The other slices keep the palette color\nthey would have had.',
90
+ required: false,
91
+ type: 'Record<string, string>'
92
+ }
93
+ ]
94
+
95
+ const slotsData = [
96
+ {
97
+ name: 'loading',
98
+ description: 'Replaces the whole placeholder, e.g. with a skeleton of the app\'s own.',
99
+ type: 'any'
100
+ },
101
+ {
102
+ name: 'error',
103
+ description: 'Replaces the message, e.g. to put a retry button beside it.',
104
+ type: '{ error?: string | null | undefined; }'
105
+ },
106
+ {
107
+ name: 'empty',
108
+ description: 'Replaces the "no data" line, e.g. with a hint about the filters.',
109
+ type: 'any'
110
+ },
111
+ {
112
+ name: 'actions',
113
+ description: '',
114
+ type: 'any'
115
+ },
116
+ {
117
+ name: 'title-suffix',
118
+ description: 'A mark right after the title, on the same line. The title truncates\naround it and it keeps its width. It renders in the title\'s font size, so\ncontent sized in `em` is smaller on a NumberCard than on a chart.',
119
+ type: 'any'
120
+ },
121
+ {
122
+ name: 'tooltip',
123
+ description: 'Replaces the tooltip body. `items` holds the hovered slice alone. A named\nslice carries one row, and the "Others" slice every row it collapsed.',
124
+ type: 'ChartTooltipSlotProps'
125
+ }
126
+ ]
127
+
128
+ const emitsData = [
129
+ {
130
+ name: 'select',
131
+ description: 'A slice was selected, by click or by Enter on the keyboard cursor. `name`\nidentifies the slice and `label` is what it printed. The collapsed tail is\nnamed `OTHERS_KEY` and carries every row it grouped, so a caller can drill\ninto it as well as into a named slice.',
132
+ type: '[event: DonutSliceEvent]'
133
+ },
134
+ {
135
+ name: 'update:hiddenSlices',
136
+ description: 'The legend switched a slice off or back on. Carries the new list.',
137
+ type: '[value: string[]]'
138
+ }
139
+ ]
140
+ </script>
141
+
142
+ ## API Reference
143
+
144
+ <PropsTable folder="charts" name="PercentageBarChart" :data="propsData"/>
145
+
146
+ <SlotsTable :data="slotsData"/>
147
+
148
+ <EmitsTable :data="emitsData"/>
@@ -0,0 +1,42 @@
1
+ # PercentageBarChart
2
+
3
+ A bar that shows each category's share of a total.
4
+
5
+ It is the ring of `DonutChart` unrolled, for a strip under a number. It draws plain divs, with no echarts, so a chart ref hands back nothing.
6
+
7
+ ## Share of a total
8
+
9
+ `category` and `value` name the two columns the bar needs, the same two as `DonutChart`. Each slice is as wide as its share of the total, and the biggest slice comes first. Hovering a slice shows its value, name and share.
10
+
11
+ `format` formats the values in the tooltip and the legend. The shares are whole numbers that add up to 100.
12
+
13
+ <ComponentPreview name="Charts-PercentageTickets" csr="true" self-layout />
14
+
15
+ ## Grouping the tail
16
+
17
+ `maxSlices` limits how many slices the bar draws, and "Others" counts as one of them. So `maxSlices` of 4 draws three named slices plus "Others", as in this example. It defaults to 9, as on `DonutChart`, so a breakdown is cut into the same slices on either chart. If there are no more categories than the limit, the bar draws them all with no "Others" slice. `select` reports the data rows behind the slice, and for "Others" that is every grouped row.
18
+
19
+ <ComponentPreview name="Charts-PercentageStorage" csr="true" self-layout />
20
+
21
+ ## Keeping the rows' order
22
+
23
+ The biggest slice comes first by default. `order="rows"` draws the slices in the order the rows arrive instead, for categories that already have an order, such as ageing buckets or months. `maxSlices` still keeps the largest slices, and "Others" comes last.
24
+
25
+ ## Pinning a color
26
+
27
+ `colors` pins a color to a category, so a slice keeps its meaning whatever its size. Key it by the category value, and by `OTHERS_KEY` for "Others". A category grouped into "Others" takes that slice's color. The other slices keep the palette colors they would have had. A color can be a CSS variable, such as `var(--ink-red-5)`.
28
+
29
+ ```vue
30
+ <PercentageBarChart
31
+ :data="invoices"
32
+ category="status"
33
+ value="count"
34
+ :colors="{ Overdue: 'var(--ink-red-5)', Paid: 'var(--ink-green-5)' }"
35
+ />
36
+ ```
37
+
38
+ ## Hiding slices
39
+
40
+ `v-model:hiddenSlices` works as on `DonutChart`. Bind it to hide slices from your own code, or to keep hidden slices after a reload. When it is not bound, the legend manages the list. The remaining slices share the whole bar.
41
+
42
+ <!-- @include: ./PercentageBarChart.api.md -->
@@ -52,9 +52,8 @@ charts already use `referenceLines` for that.
52
52
 
53
53
  <ComponentPreview name="Charts-ScatterQuadrants" csr="true" self-layout />
54
54
 
55
- A line outside the plotted range is not drawn, because each scale follows the
56
- data, not the lines. Set `xAxis.min` / `max` or `yAxis.min` / `max` to bring a
57
- distant line into view.
55
+ Each scale stretches to reach the lines on it, so a line outside the data stays
56
+ in view.
58
57
 
59
58
  ## Naming the points
60
59
 
@@ -1,25 +1,10 @@
1
1
  import type { EChartsCoreOption } from 'echarts/core'
2
- import { BLUR_OPACITY, DATA_LABEL_FONT_SIZE, toNumber } from './axisChartCommon'
2
+ import { BLUR_OPACITY, DATA_LABEL_FONT_SIZE } from './axisChartCommon'
3
3
  import { formatPercent } from './format'
4
4
  import { CHART_FONT_FAMILY } from './measureText'
5
- import { paletteColors, type ChartTokens } from './tokens'
6
- import { mergeDeep, OTHERS_KEY, OTHERS_LABEL } from './utils'
7
- import type { ChartPaletteName, DonutChartConfig, DonutSlice } from './types'
8
-
9
- // Plot, legend, tooltip and center readout all read the same `DonutSlice[]`, so
10
- // the four can't disagree about what a slice is worth.
11
-
12
- export type DonutChartOptionContext = {
13
- tokens: ChartTokens
14
- /** Slice names the legend has switched off. Dropped from the ring. */
15
- hiddenSlices?: string[]
16
- }
17
-
18
- export const DEFAULT_MAX_SLICES = 9
19
- /** Below two there is nothing left to group into. */
20
- const MIN_MAX_SLICES = 2
21
-
22
- const DONUT_PALETTE: ChartPaletteName = 'categorical'
5
+ import { buildSlices, drawnSlices, type SliceContext } from './slices'
6
+ import { mergeDeep } from './utils'
7
+ import type { DonutChartConfig } from './types'
23
8
 
24
9
  /** Wide enough a ring to read as a ring, with room for the center readout. */
25
10
  const DONUT_RADIUS = ['64%', '90%']
@@ -44,114 +29,16 @@ const SLICE_RADIUS = 4
44
29
  /** How far the hovered slice grows out of the ring, in px. */
45
30
  const EMPHASIS_SCALE = 4
46
31
 
47
- /**
48
- * The slices of a ring, in drawing order. Hidden slices stay in the list — the
49
- * legend still needs them, and dropping them would shift every color after.
50
- */
51
- export function buildDonutSlices(
52
- config: DonutChartConfig,
53
- { tokens, hiddenSlices = [] }: DonutChartOptionContext,
54
- ): DonutSlice[] {
55
- const grouped = groupRows(config)
56
- const colors = paletteColors(
57
- config.palette,
58
- tokens,
59
- grouped.length,
60
- DONUT_PALETTE,
61
- )
62
-
63
- const visibleTotal = grouped.reduce(
64
- (sum, slice) =>
65
- hiddenSlices.includes(slice.name) ? sum : sum + slice.value,
66
- 0,
67
- )
68
-
69
- return grouped.map((slice, index) => {
70
- const hidden = hiddenSlices.includes(slice.name)
71
- return {
72
- ...slice,
73
- color: colors[index],
74
- hidden,
75
- percent: hidden || !visibleTotal ? 0 : (slice.value / visibleTotal) * 100,
76
- }
77
- })
78
- }
79
-
80
- type UnsizedSlice = Omit<DonutSlice, 'color' | 'hidden' | 'percent'>
81
-
82
- function groupRows(config: DonutChartConfig): UnsizedSlice[] {
83
- const rows = config.data ?? []
84
-
85
- const entries = rows
86
- .map((row) => ({ row, value: toNumber(row[config.valueColumn]) }))
87
- // A ring reads as parts of a whole, and a negative part has no arc to draw.
88
- .filter(
89
- (entry): entry is { row: Record<string, any>; value: number } =>
90
- entry.value !== null && entry.value >= 0,
91
- )
92
- // Biggest first: the ring, the legend and the tail that gets grouped all
93
- // depend on this order.
94
- .sort((a, b) => b.value - a.value)
95
-
96
- const max = Math.max(MIN_MAX_SLICES, config.maxSlices ?? DEFAULT_MAX_SLICES)
97
- // One of the slots goes to "Others" itself.
98
- const keep = entries.length > max ? max - 1 : entries.length
99
-
100
- const seen = new Set<string>()
101
- const slices: UnsizedSlice[] = entries.slice(0, keep).map((entry) => {
102
- const label = categoryLabel(entry.row[config.categoryColumn])
103
- return {
104
- name: uniqueName(label, seen),
105
- label,
106
- value: entry.value,
107
- rows: [entry.row],
108
- isOthers: false,
109
- }
110
- })
111
-
112
- const overflow = entries.slice(keep)
113
- if (!overflow.length) return slices
114
-
115
- return [
116
- ...slices,
117
- {
118
- name: OTHERS_KEY,
119
- label: OTHERS_LABEL,
120
- value: overflow.reduce((sum, entry) => sum + entry.value, 0),
121
- rows: overflow.map((entry) => entry.row),
122
- isOthers: true,
123
- },
124
- ]
125
- }
126
-
127
- function categoryLabel(value: any) {
128
- return value === null || value === undefined || value === ''
129
- ? '(Blank)'
130
- : String(value)
131
- }
132
-
133
- /**
134
- * Two rows can carry the same category value, and echarts addresses a slice by
135
- * name — so a repeat would highlight and hide both at once. The label keeps the
136
- * raw value; only the identity is made unique.
137
- */
138
- function uniqueName(label: string, seen: Set<string>) {
139
- let name = label
140
- let suffix = 2
141
- while (seen.has(name)) name = `${label} (${suffix++})`
142
- seen.add(name)
143
- return name
144
- }
145
-
146
32
  export function buildDonutChartOption(
147
33
  config: DonutChartConfig,
148
- context: DonutChartOptionContext,
34
+ context: SliceContext,
149
35
  ): EChartsCoreOption {
150
36
  const { tokens } = context
151
37
  const isRTL = config.dir === 'rtl'
152
- const slices = buildDonutSlices(config, context)
153
- const visible = slices.filter((slice) => !slice.hidden)
154
- const labels = new Map(slices.map((slice) => [slice.name, slice.label]))
38
+ const slices = buildSlices(config, context)
39
+ // Echarts pads a zero slice like any other. The legend still lists it.
40
+ const plotted = drawnSlices(slices)
41
+ const sliceByName = new Map(slices.map((slice) => [slice.name, slice]))
155
42
 
156
43
  const isHalf = config.variant === 'half'
157
44
 
@@ -184,19 +71,22 @@ export function buildDonutChartOption(
184
71
  ? { startAngle: 0, endAngle: 180 }
185
72
  : { startAngle: 180, endAngle: 0 }
186
73
  : null),
187
- padAngle: SLICE_PAD_ANGLE,
74
+ // A lone slice is the whole ring: padding it opens a gap at the top.
75
+ padAngle: plotted.length > 1 ? SLICE_PAD_ANGLE : 0,
188
76
  itemStyle: { borderRadius: SLICE_RADIUS, borderWidth: 0 },
189
77
  avoidLabelOverlap: true,
190
78
  label: {
191
79
  show: Boolean(config.showDataLabels),
192
80
  color: tokens.dataLabel,
193
81
  fontSize: DATA_LABEL_FONT_SIZE,
194
- // `params.percent` is echarts' own share of the series total, which is
195
- // the visible total — the same denominator the legend uses.
196
- formatter: (params: any) =>
197
- `${labels.get(params.name) ?? params.name} ${formatPercent(
198
- params.percent,
199
- )}`,
82
+ // The slice's own share rather than echarts' `params.percent`, which
83
+ // rounds each slice on its own and so disagrees with the legend.
84
+ formatter: (params: any) => {
85
+ const slice = sliceByName.get(params.name)
86
+ return `${slice?.label ?? params.name} ${formatPercent(
87
+ slice?.percent ?? params.percent,
88
+ )}`
89
+ },
200
90
  },
201
91
  labelLine: {
202
92
  show: Boolean(config.showDataLabels),
@@ -217,7 +107,9 @@ export function buildDonutChartOption(
217
107
  label: { opacity: BLUR_OPACITY },
218
108
  labelLine: { opacity: BLUR_OPACITY },
219
109
  },
220
- data: visible.map((slice) => ({
110
+ // Drawn when every visible slice is zero.
111
+ emptyCircleStyle: { color: tokens.gridline },
112
+ data: plotted.map((slice) => ({
221
113
  name: slice.name,
222
114
  value: slice.value,
223
115
  itemStyle: { color: slice.color },
@@ -23,7 +23,10 @@ const GRAIN_FORMATS: Record<TimeGrain, string> = {
23
23
  year: 'YYYY',
24
24
  }
25
25
 
26
- /** `total_sales` -> `Total Sales`. Used for series names and axis titles. */
26
+ /**
27
+ * `total_sales` -> `Total Sales`. For a column key that has no `label`. Text
28
+ * the caller wrote and values read from the data print as given.
29
+ */
27
30
  export function formatLabel(name: string) {
28
31
  if (!name) return ''
29
32
  return name
@@ -46,9 +46,12 @@ export const HEATMAP_RAMP_SAMPLES = 32
46
46
 
47
47
  const HEATMAP_PALETTE: ChartPaletteName = 'sequential'
48
48
 
49
+ /** What the color scale reads off a config. The calendar heatmap shares it. */
50
+ type HeatmapScaleConfig = Pick<HeatmapChartConfig, 'palette' | 'min' | 'max'>
51
+
49
52
  /** Gap between two cells, in px. Split either side of the shared edge. */
50
- const CELL_BORDER_WIDTH = 2
51
- const CELL_RADIUS = 2
53
+ export const CELL_BORDER_WIDTH = 2
54
+ export const CELL_RADIUS = 2
52
55
 
53
56
  const BLANK_CATEGORY = '(Blank)'
54
57
 
@@ -173,12 +176,14 @@ function categoryAxis() {
173
176
  }
174
177
 
175
178
  /**
176
- * The ends of the color scale. Config wins; the rest comes from the data,
177
- * except on a diverging ramp, where an unset end is mirrored from the larger
178
- * side so -4 in a -4..+12 series reads as deep as +4 does the other way.
179
+ * The ends of the color scale. Config wins; the rest comes from the data. An
180
+ * unset `min` is 0 unless a value is negative, as a count is read: a smallest
181
+ * value at the foot of the ramp would draw as pale as a cell with no value. On
182
+ * a diverging ramp an unset end is mirrored from the larger side so -4 in a
183
+ * -4..+12 series reads as deep as +4 does the other way.
179
184
  */
180
- function resolveScale(
181
- config: HeatmapChartConfig,
185
+ export function resolveScale(
186
+ config: HeatmapScaleConfig,
182
187
  cells: { value: number }[],
183
188
  ): { min: number; max: number } {
184
189
  const values = cells.map((cell) => cell.value)
@@ -193,7 +198,7 @@ function resolveScale(
193
198
  }
194
199
  }
195
200
 
196
- return { min: config.min ?? dataMin, max: config.max ?? dataMax }
201
+ return { min: config.min ?? Math.min(dataMin, 0), max: config.max ?? dataMax }
197
202
  }
198
203
 
199
204
  /**
@@ -203,7 +208,7 @@ function resolveScale(
203
208
  * runs cool to warm, i.e. negative to positive.
204
209
  */
205
210
  export function heatmapRampStops(
206
- config: HeatmapChartConfig,
211
+ config: HeatmapScaleConfig,
207
212
  tokens: ChartTokens,
208
213
  ): string[] {
209
214
  const stops = rampStops(config.palette, tokens, HEATMAP_PALETTE)
@@ -234,7 +239,7 @@ export function sampleRamp(
234
239
  }
235
240
  }
236
241
 
237
- function rampColor(stops: string[], t: number): string {
242
+ export function rampColor(stops: string[], t: number): string {
238
243
  if (!stops.length) return ''
239
244
  try {
240
245
  return interpolateRamp(stops, t)
@@ -422,8 +427,8 @@ export function buildHeatmapOption(
422
427
  * all of them at the top of the ramp, the same place `buildHeatmapMatrix` puts
423
428
  * them.
424
429
  */
425
- function visualMapMin(matrix: HeatmapMatrix) {
426
- return matrix.max > matrix.min ? matrix.min : matrix.max - 1
430
+ export function visualMapMin(scale: { min: number; max: number }) {
431
+ return scale.max > scale.min ? scale.min : scale.max - 1
427
432
  }
428
433
 
429
434
  function cellValue(params: any): number {
@@ -4,14 +4,19 @@
4
4
  * and both paths have to reach the same answer.
5
5
  */
6
6
 
7
- /** Toggles one series, refusing to hide the last visible one — an empty plot reads as a bug. */
7
+ /**
8
+ * Toggles one series, refusing to hide the last one drawn — an empty plot reads
9
+ * as a bug. `drawn` is what the plot draws, not what is unhidden: a slice worth
10
+ * nothing has a legend entry and no mark, so it can neither hold the plot up
11
+ * nor empty it.
12
+ */
8
13
  export function toggleHiddenSeries(
9
14
  hidden: string[],
10
15
  name: string,
11
- seriesCount: number,
16
+ drawn: string[],
12
17
  ): string[] {
13
18
  if (hidden.includes(name)) return hidden.filter((n) => n !== name)
14
- if (hidden.length >= seriesCount - 1) return hidden
19
+ if (drawn.length === 1 && drawn[0] === name) return hidden
15
20
  return [...hidden, name]
16
21
  }
17
22
 
@@ -4,11 +4,13 @@ import './style.css'
4
4
 
5
5
  export { default as AreaChart } from './AreaChart.vue'
6
6
  export { default as BarChart } from './BarChart.vue'
7
+ export { default as CalendarHeatmapChart } from './CalendarHeatmapChart.vue'
7
8
  export { default as DonutChart } from './DonutChart.vue'
8
9
  export { default as FunnelChart } from './FunnelChart.vue'
9
10
  export { default as HeatmapChart } from './HeatmapChart.vue'
10
11
  export { default as LineChart } from './LineChart.vue'
11
12
  export { default as NumberCard } from './NumberCard.vue'
13
+ export { default as PercentageBarChart } from './PercentageBarChart.vue'
12
14
  export { default as SankeyChart } from './SankeyChart.vue'
13
15
  export { default as ScatterChart } from './ScatterChart.vue'
14
16
 
@@ -49,6 +51,9 @@ export type {
49
51
  BarChartEmits,
50
52
  BarChartProps,
51
53
  BarChartSlots,
54
+ CalendarHeatmapChartEmits,
55
+ CalendarHeatmapChartProps,
56
+ CalendarHeatmapChartSlots,
52
57
  ChartActionsSlot,
53
58
  ChartBaseProps,
54
59
  ChartCardProps,
@@ -81,6 +86,9 @@ export type {
81
86
  LineChartSlots,
82
87
  NumberCardProps,
83
88
  NumberCardSlots,
89
+ PercentageBarChartEmits,
90
+ PercentageBarChartProps,
91
+ PercentageBarChartSlots,
84
92
  SankeyChartEmits,
85
93
  SankeyChartProps,
86
94
  SankeyChartSlots,
@@ -94,6 +102,8 @@ export type {
94
102
  // config shapes the option builders read stay internal.
95
103
  export type {
96
104
  AxisTitlePlacement,
105
+ CalendarHeatmapCellEvent,
106
+ CalendarHeatmapWeekStart,
97
107
  ChartDatapointEvent,
98
108
  ChartDir,
99
109
  ChartExposed,
@@ -110,10 +120,12 @@ export type {
110
120
  HeatmapAxisOptions,
111
121
  HeatmapCellEvent,
112
122
  HeatmapPalette,
123
+ NumberCardProgress,
113
124
  NumberCardSparkline,
114
125
  ReferenceLine,
115
126
  ReferenceLineLabelPlacement,
116
127
  SankeyLinkEvent,
117
128
  SankeyNodeAlign,
118
129
  ScatterPointEvent,
130
+ SliceOrder,
119
131
  } from './types'
@@ -0,0 +1,40 @@
1
+ import type { ChartLegendItem } from './types'
2
+ import { OTHERS_KEY } from './utils'
3
+
4
+ /**
5
+ * The entries heaviest first, which is the order the legend falls back to when
6
+ * they do not fit on one row. An entry with no weight, and "Others", keep their
7
+ * given place after the ranked ones — a remainder reads at the end.
8
+ */
9
+ export function rankLegendItems(items: ChartLegendItem[]): ChartLegendItem[] {
10
+ const weight = (item: ChartLegendItem) =>
11
+ item.name === OTHERS_KEY || item.weight === undefined ? -1 : item.weight
12
+ return [...items].sort((a, b) => weight(b) - weight(a))
13
+ }
14
+
15
+ /**
16
+ * How many entries fit on the row, given each entry's width in ranked order.
17
+ * All of them when they fit as they are; otherwise as many as fit beside the
18
+ * "+N more" trigger, whose width `more` gives for the count it hides.
19
+ */
20
+ export function legendFit(
21
+ widths: number[],
22
+ room: number,
23
+ more: (hidden: number) => number,
24
+ gap: number,
25
+ ): number {
26
+ const all =
27
+ widths.reduce((sum, width) => sum + width, 0) +
28
+ gap * Math.max(0, widths.length - 1)
29
+ if (all <= room) return widths.length
30
+
31
+ // Every candidate is tried rather than stopping at the first miss: one more
32
+ // entry can shorten the trigger by a digit and fit where one fewer did not.
33
+ let fit = 0
34
+ let used = 0
35
+ for (let count = 0; count < widths.length && used <= room; count++) {
36
+ if (used + more(widths.length - count) <= room) fit = count
37
+ used += widths[count] + gap
38
+ }
39
+ return fit
40
+ }
@@ -7,26 +7,32 @@ export type DeltaDirection = 'up' | 'down' | 'flat'
7
7
  /** Whether the move is good news. Green, red, or neither. */
8
8
  export type DeltaTone = 'positive' | 'negative' | 'neutral'
9
9
 
10
- export function deltaDirection(
11
- delta: number | null | undefined,
12
- ): DeltaDirection {
10
+ type DeltaConfig = Pick<
11
+ NumberCardConfig,
12
+ 'delta' | 'deltaPrefix' | 'deltaSuffix' | 'deltaFormat' | 'negativeIsBetter'
13
+ >
14
+
15
+ /**
16
+ * A delta that prints the way zero does is flat: an arrow beside "0%" would
17
+ * point at a move the reader cannot see.
18
+ */
19
+ export function deltaDirection(config: DeltaConfig): DeltaDirection {
20
+ const { delta } = config
13
21
  if (!isPresent(delta)) return 'flat'
14
- if (delta > 0) return 'up'
15
- if (delta < 0) return 'down'
16
- return 'flat'
22
+ if (formatCardDelta(config, delta) === formatCardDelta(config, 0)) {
23
+ return 'flat'
24
+ }
25
+ return delta > 0 ? 'up' : 'down'
17
26
  }
18
27
 
19
28
  /**
20
29
  * `negativeIsBetter` flips the colors without touching the arrow: churn falling
21
30
  * still points down, it just stops being red.
22
31
  */
23
- export function deltaTone(
24
- delta: number | null | undefined,
25
- negativeIsBetter = false,
26
- ): DeltaTone {
27
- const direction = deltaDirection(delta)
32
+ export function deltaTone(config: DeltaConfig): DeltaTone {
33
+ const direction = deltaDirection(config)
28
34
  if (direction === 'flat') return 'neutral'
29
- const better = negativeIsBetter ? 'down' : 'up'
35
+ const better = config.negativeIsBetter ? 'down' : 'up'
30
36
  return direction === better ? 'positive' : 'negative'
31
37
  }
32
38
 
@@ -48,7 +54,7 @@ export function formatCardValue(
48
54
  * `-3.1%` next to a down arrow would say it twice.
49
55
  */
50
56
  export function formatCardDelta(
51
- config: Pick<NumberCardConfig, 'deltaPrefix' | 'deltaSuffix' | 'deltaFormat'>,
57
+ config: DeltaConfig,
52
58
  delta: number | null | undefined,
53
59
  ): string {
54
60
  if (!isPresent(delta)) return ''
@@ -2,6 +2,7 @@ import {
2
2
  DATA_LABEL_FONT_SIZE,
3
3
  MARK_Z,
4
4
  dashedLine,
5
+ referenceLineAxis,
5
6
  toNumber,
6
7
  } from './axisChartCommon'
7
8
  import { translucent, type ChartTokens } from './tokens'
@@ -132,7 +133,7 @@ export function buildReferenceLineSeries(
132
133
  * is the same one.
133
134
  */
134
135
  function hostIndex(line: ReferenceLine, ctx: ReferenceLineContext) {
135
- return ctx.hasSecondaryValueAxis && line.axis === 'y2' ? 1 : 0
136
+ return referenceLineAxis(line, ctx.hasSecondaryValueAxis) === 'y2' ? 1 : 0
136
137
  }
137
138
 
138
139
  function markLineEntry(