frappe-ui 1.0.2 → 1.1.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/calendarUtils.ts +33 -21
- package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
- package/experimental/MultiEmailInput/types.ts +12 -3
- 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 -0
- package/package.json +1 -1
- 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/Combobox/Combobox.vue +9 -2
- package/src/components/Combobox/ComboboxResults.vue +6 -1
- package/src/components/Combobox/utils.ts +2 -1
- 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/Menu/utils.ts +3 -2
- 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/Switch/Switch.vue +3 -3
- 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/iframe/IframeNodeView.vue +3 -1
- package/src/molecules/editor/useEditor.ts +12 -6
- package/src/utils/dialog.ts +37 -14
- package/tailwind/content.js +1 -0
- package/vite/README.md +5 -3
- package/vite/codeLanguages.js +41 -17
|
@@ -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
|
-
|
|
56
|
-
|
|
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
|
|
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 {
|
|
6
|
-
import { mergeDeep
|
|
7
|
-
import type {
|
|
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:
|
|
34
|
+
context: SliceContext,
|
|
149
35
|
): EChartsCoreOption {
|
|
150
36
|
const { tokens } = context
|
|
151
37
|
const isRTL = config.dir === 'rtl'
|
|
152
|
-
const slices =
|
|
153
|
-
|
|
154
|
-
const
|
|
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
|
-
|
|
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
|
-
//
|
|
195
|
-
//
|
|
196
|
-
formatter: (params: any) =>
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
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 },
|
package/src/charts/format.ts
CHANGED
|
@@ -23,7 +23,10 @@ const GRAIN_FORMATS: Record<TimeGrain, string> = {
|
|
|
23
23
|
year: 'YYYY',
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/**
|
|
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
|
-
*
|
|
178
|
-
*
|
|
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:
|
|
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:
|
|
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(
|
|
426
|
-
return
|
|
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
|
-
/**
|
|
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
|
-
|
|
16
|
+
drawn: string[],
|
|
12
17
|
): string[] {
|
|
13
18
|
if (hidden.includes(name)) return hidden.filter((n) => n !== name)
|
|
14
|
-
if (
|
|
19
|
+
if (drawn.length === 1 && drawn[0] === name) return hidden
|
|
15
20
|
return [...hidden, name]
|
|
16
21
|
}
|
|
17
22
|
|
package/src/charts/index.ts
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
|
136
|
+
return referenceLineAxis(line, ctx.hasSecondaryValueAxis) === 'y2' ? 1 : 0
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
function markLineEntry(
|