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,353 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ChartContainer
|
|
3
|
+
:title="title"
|
|
4
|
+
:subtitle="subtitle"
|
|
5
|
+
:loading="loading"
|
|
6
|
+
:error="error || renderError"
|
|
7
|
+
:empty="isEmpty"
|
|
8
|
+
:dir="dir"
|
|
9
|
+
>
|
|
10
|
+
<template v-if="$slots.actions" #actions><slot name="actions" /></template>
|
|
11
|
+
<template v-if="$slots['title-suffix']" #title-suffix>
|
|
12
|
+
<slot name="title-suffix" />
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<template v-if="$slots.loading" #loading><slot name="loading" /></template>
|
|
16
|
+
<template v-if="$slots.error" #error="slotProps">
|
|
17
|
+
<slot name="error" v-bind="slotProps" />
|
|
18
|
+
</template>
|
|
19
|
+
<template v-if="$slots.empty" #empty><slot name="empty" /></template>
|
|
20
|
+
|
|
21
|
+
<template #default>
|
|
22
|
+
<!-- echarts lays a calendar out left to right only, so the plot keeps
|
|
23
|
+
`ltr` in both directions. -->
|
|
24
|
+
<div
|
|
25
|
+
ref="plotEl"
|
|
26
|
+
class="h-full w-full rounded-2 focus-visible:focus-ring"
|
|
27
|
+
dir="ltr"
|
|
28
|
+
role="img"
|
|
29
|
+
:aria-label="chartAriaLabel(title, subtitle)"
|
|
30
|
+
v-bind="plotAttrs"
|
|
31
|
+
/>
|
|
32
|
+
|
|
33
|
+
<!-- Under the last band rather than under the card, so the scale sits
|
|
34
|
+
with what it explains however much height the card has to spare.
|
|
35
|
+
Ends where the calendar ends, unless the calendar is narrower than
|
|
36
|
+
the scale: then it starts at the plot's edge. -->
|
|
37
|
+
<ChartScale
|
|
38
|
+
v-if="grid && cells.length && layout"
|
|
39
|
+
class="absolute"
|
|
40
|
+
:style="{
|
|
41
|
+
top: `${layout.scaleTop}px`,
|
|
42
|
+
left: `${layout.right}px`,
|
|
43
|
+
transform: `translateX(max(-100%, -${layout.right}px))`,
|
|
44
|
+
}"
|
|
45
|
+
:min="grid.min"
|
|
46
|
+
:max="grid.max"
|
|
47
|
+
:stops="grid.stops"
|
|
48
|
+
:format="format"
|
|
49
|
+
:below-min="clipped.belowMin"
|
|
50
|
+
:above-max="clipped.aboveMax"
|
|
51
|
+
:dir="dir"
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
<span class="sr-only" role="status">{{ reading }}</span>
|
|
55
|
+
|
|
56
|
+
<ChartTooltip
|
|
57
|
+
:open="tooltip.open"
|
|
58
|
+
:x="tooltip.x"
|
|
59
|
+
:y="tooltip.y"
|
|
60
|
+
:label="tooltip.label"
|
|
61
|
+
:items="tooltip.items"
|
|
62
|
+
:rows="tooltip.rows"
|
|
63
|
+
:dir="dir"
|
|
64
|
+
>
|
|
65
|
+
<template v-if="$slots.tooltip" #default="slotProps">
|
|
66
|
+
<slot name="tooltip" v-bind="slotProps" />
|
|
67
|
+
</template>
|
|
68
|
+
</ChartTooltip>
|
|
69
|
+
</template>
|
|
70
|
+
</ChartContainer>
|
|
71
|
+
</template>
|
|
72
|
+
|
|
73
|
+
<script setup lang="ts">
|
|
74
|
+
import { computed, reactive, ref } from 'vue'
|
|
75
|
+
import { HeatmapChart as HeatmapSeries } from 'echarts/charts'
|
|
76
|
+
import {
|
|
77
|
+
CalendarComponent,
|
|
78
|
+
VisualMapContinuousComponent,
|
|
79
|
+
} from 'echarts/components'
|
|
80
|
+
import { registerChartModules, useChart } from './core/useChart'
|
|
81
|
+
import { usePlotKeyboard } from './core/usePlotKeyboard'
|
|
82
|
+
import { useTooltipDismiss } from './core/useTooltipDismiss'
|
|
83
|
+
import {
|
|
84
|
+
buildCalendarHeatmapGrid,
|
|
85
|
+
buildCalendarHeatmapOption,
|
|
86
|
+
layoutCalendar,
|
|
87
|
+
} from './calendarHeatmapOptions'
|
|
88
|
+
import { formatDate, formatLabel, formatValue } from './format'
|
|
89
|
+
import { useChartTokens, useResolvedConfig } from './tokens'
|
|
90
|
+
import { chartAriaLabel, documentDir, plotReading } from './utils'
|
|
91
|
+
import ChartContainer from './components/ChartContainer.vue'
|
|
92
|
+
import ChartScale from './components/ChartScale.vue'
|
|
93
|
+
import ChartTooltip from './components/ChartTooltip.vue'
|
|
94
|
+
import type {
|
|
95
|
+
CalendarHeatmapChartConfig,
|
|
96
|
+
CalendarHeatmapChartEmits,
|
|
97
|
+
CalendarHeatmapChartProps,
|
|
98
|
+
CalendarHeatmapChartSlots,
|
|
99
|
+
CalendarHeatmapDay,
|
|
100
|
+
ChartExposedRefs,
|
|
101
|
+
ChartTooltipItem,
|
|
102
|
+
} from './types'
|
|
103
|
+
|
|
104
|
+
registerChartModules([
|
|
105
|
+
HeatmapSeries,
|
|
106
|
+
CalendarComponent,
|
|
107
|
+
VisualMapContinuousComponent,
|
|
108
|
+
])
|
|
109
|
+
|
|
110
|
+
const props = defineProps<CalendarHeatmapChartProps>()
|
|
111
|
+
|
|
112
|
+
const emit = defineEmits<CalendarHeatmapChartEmits>()
|
|
113
|
+
|
|
114
|
+
defineSlots<CalendarHeatmapChartSlots>()
|
|
115
|
+
|
|
116
|
+
const plotEl = ref<HTMLElement>()
|
|
117
|
+
|
|
118
|
+
const dir = computed(() => props.dir ?? documentDir())
|
|
119
|
+
|
|
120
|
+
const config = useResolvedConfig<CalendarHeatmapChartConfig>(
|
|
121
|
+
() => ({
|
|
122
|
+
data: props.data,
|
|
123
|
+
dateColumn: props.date,
|
|
124
|
+
valueColumn: props.value,
|
|
125
|
+
start: props.start,
|
|
126
|
+
end: props.end,
|
|
127
|
+
weekStart: props.weekStart,
|
|
128
|
+
min: props.min,
|
|
129
|
+
max: props.max,
|
|
130
|
+
palette: props.palette,
|
|
131
|
+
echartOptions: props.echartOptions,
|
|
132
|
+
}),
|
|
133
|
+
plotEl,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
const { tokens } = useChartTokens(plotEl)
|
|
137
|
+
|
|
138
|
+
// A config the grid cannot be built from is reported by `built` below.
|
|
139
|
+
const grid = computed(() => {
|
|
140
|
+
try {
|
|
141
|
+
return buildCalendarHeatmapGrid(config.value, { tokens: tokens.value })
|
|
142
|
+
} catch {
|
|
143
|
+
return undefined
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
const cells = computed(() => grid.value?.cells ?? [])
|
|
147
|
+
const days = computed(() => grid.value?.days ?? [])
|
|
148
|
+
const isEmpty = computed(() => !grid.value?.bands.length)
|
|
149
|
+
|
|
150
|
+
const size = computed(() => ({
|
|
151
|
+
width: plotWidth.value,
|
|
152
|
+
height: plotHeight.value,
|
|
153
|
+
}))
|
|
154
|
+
|
|
155
|
+
const layout = computed(
|
|
156
|
+
() => grid.value && layoutCalendar(grid.value, config.value, size.value),
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
const built = computed(() => {
|
|
160
|
+
try {
|
|
161
|
+
return {
|
|
162
|
+
option: buildCalendarHeatmapOption(
|
|
163
|
+
config.value,
|
|
164
|
+
{ tokens: tokens.value, ...size.value },
|
|
165
|
+
grid.value,
|
|
166
|
+
),
|
|
167
|
+
error: null as string | null,
|
|
168
|
+
}
|
|
169
|
+
} catch (e: any) {
|
|
170
|
+
return { option: undefined, error: e?.message ?? String(e) }
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
const renderError = computed(() => built.value.error)
|
|
175
|
+
|
|
176
|
+
const pointer = reactive({ x: 0, y: 0 })
|
|
177
|
+
|
|
178
|
+
const tooltip = reactive({
|
|
179
|
+
open: false,
|
|
180
|
+
x: 0,
|
|
181
|
+
y: 0,
|
|
182
|
+
label: undefined as string | undefined,
|
|
183
|
+
items: [] as ChartTooltipItem[],
|
|
184
|
+
rows: [] as Record<string, any>[],
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
useTooltipDismiss({
|
|
188
|
+
plot: plotEl,
|
|
189
|
+
data: () => days.value,
|
|
190
|
+
close: () => {
|
|
191
|
+
tooltip.open = false
|
|
192
|
+
},
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
const dayIndexes = computed(
|
|
196
|
+
() => new Map(days.value.map((day, index) => [day.date, index])),
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
/** The day under an echarts event: both series carry it first in the value. */
|
|
200
|
+
function eventDay(params: any): CalendarHeatmapDay | undefined {
|
|
201
|
+
const index = dayIndexes.value.get(params.value?.[0])
|
|
202
|
+
return index === undefined ? undefined : days.value[index]
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** A day with no row has nothing to report, so it does not select. */
|
|
206
|
+
function select(day: CalendarHeatmapDay | undefined) {
|
|
207
|
+
const cell = day?.cell
|
|
208
|
+
if (!cell) return
|
|
209
|
+
emit('select', { date: cell.date, value: cell.value, row: cell.row })
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const {
|
|
213
|
+
chart,
|
|
214
|
+
dispatch,
|
|
215
|
+
width: plotWidth,
|
|
216
|
+
height: plotHeight,
|
|
217
|
+
} = useChart({
|
|
218
|
+
container: plotEl,
|
|
219
|
+
option: () => built.value.option,
|
|
220
|
+
events: {
|
|
221
|
+
mouseover: (params: any) => showTooltip(eventDay(params)),
|
|
222
|
+
mouseout: () => (tooltip.open = false),
|
|
223
|
+
click: (params: any) => select(eventDay(params)),
|
|
224
|
+
},
|
|
225
|
+
onZrEvents: {
|
|
226
|
+
mousemove: (e: any) => {
|
|
227
|
+
pointer.x = e.event?.clientX ?? pointer.x
|
|
228
|
+
pointer.y = e.event?.clientY ?? pointer.y
|
|
229
|
+
if (tooltip.open) {
|
|
230
|
+
tooltip.x = pointer.x
|
|
231
|
+
tooltip.y = pointer.y
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
globalout: () => (tooltip.open = false),
|
|
235
|
+
},
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
function showTooltip(day: CalendarHeatmapDay | undefined) {
|
|
239
|
+
if (!day) {
|
|
240
|
+
tooltip.open = false
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
const { cell } = day
|
|
244
|
+
tooltip.label = formatDate(day.date, 'day', 'ddd, MMM D, YYYY')
|
|
245
|
+
tooltip.items = [
|
|
246
|
+
{
|
|
247
|
+
name: day.date,
|
|
248
|
+
label: formatLabel(props.value),
|
|
249
|
+
color: cell?.color ?? tokens.value.gridline,
|
|
250
|
+
value: cell?.value ?? '',
|
|
251
|
+
formattedValue: !cell
|
|
252
|
+
? 'No data'
|
|
253
|
+
: props.format
|
|
254
|
+
? props.format(cell.value)
|
|
255
|
+
: formatValue(cell.value),
|
|
256
|
+
kind: 'series',
|
|
257
|
+
},
|
|
258
|
+
]
|
|
259
|
+
tooltip.rows = cell ? [cell.row] : []
|
|
260
|
+
tooltip.x = pointer.x
|
|
261
|
+
tooltip.y = pointer.y
|
|
262
|
+
tooltip.open = true
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// One tab stop. The arrow keys walk the grid as it is drawn, every day of it,
|
|
266
|
+
// so a reader finds the date of a gap as well as of a day with data. The grid
|
|
267
|
+
// runs left to right in RTL too, so right is always the next week.
|
|
268
|
+
const reading = ref('')
|
|
269
|
+
|
|
270
|
+
function dayPoint(day: CalendarHeatmapDay) {
|
|
271
|
+
const el = plotEl.value
|
|
272
|
+
if (!el) return undefined
|
|
273
|
+
const rect = el.getBoundingClientRect()
|
|
274
|
+
// echarts types the finder without the calendar's own key.
|
|
275
|
+
const finder: Record<string, number> = { calendarIndex: day.band }
|
|
276
|
+
const at = chart.value?.convertToPixel(finder, day.date) as unknown as
|
|
277
|
+
number[] | undefined
|
|
278
|
+
if (!at || at.some((n) => typeof n !== 'number' || isNaN(n))) {
|
|
279
|
+
return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }
|
|
280
|
+
}
|
|
281
|
+
return { x: rect.left + at[0], y: rect.top + at[1] }
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function readDay(index: number) {
|
|
285
|
+
const day = days.value[index]
|
|
286
|
+
if (!day) return
|
|
287
|
+
const point = dayPoint(day)
|
|
288
|
+
if (point) {
|
|
289
|
+
pointer.x = point.x
|
|
290
|
+
pointer.y = point.y
|
|
291
|
+
}
|
|
292
|
+
dispatch({
|
|
293
|
+
type: 'highlight',
|
|
294
|
+
seriesIndex: day.seriesIndex,
|
|
295
|
+
dataIndex: day.dataIndex,
|
|
296
|
+
})
|
|
297
|
+
showTooltip(day)
|
|
298
|
+
reading.value = plotReading(
|
|
299
|
+
tooltip.label,
|
|
300
|
+
tooltip.items.map((item) => ({
|
|
301
|
+
label: item.label,
|
|
302
|
+
value: item.formattedValue,
|
|
303
|
+
})),
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function downplayDay(index: number | null) {
|
|
308
|
+
const day = index === null ? undefined : days.value[index]
|
|
309
|
+
if (!day) return
|
|
310
|
+
dispatch({
|
|
311
|
+
type: 'downplay',
|
|
312
|
+
seriesIndex: day.seriesIndex,
|
|
313
|
+
dataIndex: day.dataIndex,
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Moves the cursor `count` days on. Past either end of the range, it holds. */
|
|
318
|
+
function walk(count: number) {
|
|
319
|
+
const next = (keyboard.index.value ?? 0) + count
|
|
320
|
+
if (next < 0 || next >= days.value.length) return
|
|
321
|
+
keyboard.goTo(next)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const keyboard = usePlotKeyboard({
|
|
325
|
+
marks: () => days.value,
|
|
326
|
+
key: (day) => day.date,
|
|
327
|
+
move: (index, previous) => {
|
|
328
|
+
downplayDay(previous)
|
|
329
|
+
readDay(index)
|
|
330
|
+
},
|
|
331
|
+
along: (delta) => walk(7 * delta),
|
|
332
|
+
cross: walk,
|
|
333
|
+
activate: (index) => select(days.value[index]),
|
|
334
|
+
clear: (previous) => {
|
|
335
|
+
downplayDay(previous)
|
|
336
|
+
tooltip.open = false
|
|
337
|
+
reading.value = ''
|
|
338
|
+
},
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
const plotAttrs = keyboard.attrs
|
|
342
|
+
|
|
343
|
+
/** Days past an end of the scale: a `max` set under an outlier must say so. */
|
|
344
|
+
const clipped = computed(() => {
|
|
345
|
+
const { min = 0, max = 0 } = grid.value ?? {}
|
|
346
|
+
return {
|
|
347
|
+
belowMin: cells.value.some((cell) => cell.value < min),
|
|
348
|
+
aboveMax: cells.value.some((cell) => cell.value > max),
|
|
349
|
+
}
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
defineExpose<ChartExposedRefs>({ chart: computed(() => chart.value) })
|
|
353
|
+
</script>
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
</ChartTooltip>
|
|
96
96
|
</template>
|
|
97
97
|
|
|
98
|
-
<template v-if="legendItems.length
|
|
98
|
+
<template v-if="legendItems.length" #legend>
|
|
99
99
|
<ChartLegend
|
|
100
100
|
:items="legendItems"
|
|
101
101
|
@change="toggleSlice"
|
|
@@ -112,13 +112,16 @@ import { registerChartModules, useChart } from './core/useChart'
|
|
|
112
112
|
import { pruneHiddenSeries, toggleHiddenSeries } from './hiddenSeries'
|
|
113
113
|
import { useTooltipDismiss } from './core/useTooltipDismiss'
|
|
114
114
|
import { usePlotKeyboard } from './core/usePlotKeyboard'
|
|
115
|
-
import {
|
|
116
|
-
buildDonutChartOption,
|
|
117
|
-
buildDonutSlices,
|
|
118
|
-
HALF_CENTER_Y,
|
|
119
|
-
} from './donutChartOptions'
|
|
115
|
+
import { buildDonutChartOption, HALF_CENTER_Y } from './donutChartOptions'
|
|
120
116
|
import { formatLabel, formatPercent, formatValue } from './format'
|
|
121
|
-
import {
|
|
117
|
+
import {
|
|
118
|
+
buildSlices,
|
|
119
|
+
drawnSlices,
|
|
120
|
+
sliceEvent,
|
|
121
|
+
sliceLegendItems,
|
|
122
|
+
sliceTooltipItem,
|
|
123
|
+
} from './slices'
|
|
124
|
+
import { useChartTokens, useResolvedConfig } from './tokens'
|
|
122
125
|
import {
|
|
123
126
|
chartAriaLabel,
|
|
124
127
|
documentDir,
|
|
@@ -130,7 +133,6 @@ import ChartLegend from './components/ChartLegend.vue'
|
|
|
130
133
|
import ChartTooltip from './components/ChartTooltip.vue'
|
|
131
134
|
import type {
|
|
132
135
|
ChartExposedRefs,
|
|
133
|
-
ChartLegendItem,
|
|
134
136
|
ChartTooltipItem,
|
|
135
137
|
DonutChartConfig,
|
|
136
138
|
DonutChartEmits,
|
|
@@ -157,18 +159,23 @@ const plotEl = ref<HTMLElement>()
|
|
|
157
159
|
const dir = computed(() => props.dir ?? documentDir())
|
|
158
160
|
const isHalf = computed(() => props.variant === 'half')
|
|
159
161
|
|
|
160
|
-
const config =
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
162
|
+
const config = useResolvedConfig<DonutChartConfig>(
|
|
163
|
+
() => ({
|
|
164
|
+
data: props.data,
|
|
165
|
+
categoryColumn: props.category,
|
|
166
|
+
valueColumn: props.value,
|
|
167
|
+
maxSlices: props.maxSlices,
|
|
168
|
+
order: props.order,
|
|
169
|
+
showDataLabels: props.showDataLabels,
|
|
170
|
+
centerLabel: props.centerLabel,
|
|
171
|
+
variant: props.variant,
|
|
172
|
+
palette: props.palette,
|
|
173
|
+
colors: props.colors,
|
|
174
|
+
dir: dir.value,
|
|
175
|
+
echartOptions: props.echartOptions,
|
|
176
|
+
}),
|
|
177
|
+
plotEl,
|
|
178
|
+
)
|
|
172
179
|
|
|
173
180
|
/**
|
|
174
181
|
* The half readout hangs off the arc's flat edge rather than straddling it:
|
|
@@ -192,7 +199,7 @@ const readoutStyle = computed(() =>
|
|
|
192
199
|
const { tokens } = useChartTokens(plotEl)
|
|
193
200
|
|
|
194
201
|
const slices = computed(() =>
|
|
195
|
-
|
|
202
|
+
buildSlices(config.value, {
|
|
196
203
|
tokens: tokens.value,
|
|
197
204
|
hiddenSlices: hiddenSlices.value,
|
|
198
205
|
}),
|
|
@@ -263,14 +270,7 @@ const { chart, dispatch } = useChart({
|
|
|
263
270
|
},
|
|
264
271
|
click: (params: any) => {
|
|
265
272
|
const slice = sliceByName.value.get(params.name)
|
|
266
|
-
if (
|
|
267
|
-
emit('select', {
|
|
268
|
-
name: slice.name,
|
|
269
|
-
label: slice.label,
|
|
270
|
-
value: slice.value,
|
|
271
|
-
percent: slice.percent,
|
|
272
|
-
rows: slice.rows,
|
|
273
|
-
})
|
|
273
|
+
if (slice) emit('select', sliceEvent(slice))
|
|
274
274
|
},
|
|
275
275
|
},
|
|
276
276
|
onZrEvents: {
|
|
@@ -305,32 +305,15 @@ function showTooltip(name: string) {
|
|
|
305
305
|
return
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
tooltip.items = [
|
|
309
|
-
{
|
|
310
|
-
name: slice.name,
|
|
311
|
-
label: slice.label,
|
|
312
|
-
color: slice.color,
|
|
313
|
-
value: slice.value,
|
|
314
|
-
formattedValue: formatMeasure(slice.value),
|
|
315
|
-
percent: slice.percent,
|
|
316
|
-
kind: 'series',
|
|
317
|
-
},
|
|
318
|
-
]
|
|
308
|
+
tooltip.items = [sliceTooltipItem(slice, formatMeasure)]
|
|
319
309
|
tooltip.rows = slice.rows
|
|
320
310
|
tooltip.x = pointer.x
|
|
321
311
|
tooltip.y = pointer.y
|
|
322
312
|
tooltip.open = true
|
|
323
313
|
}
|
|
324
314
|
|
|
325
|
-
const legendItems = computed
|
|
326
|
-
slices.value
|
|
327
|
-
name: slice.name,
|
|
328
|
-
label: slice.label,
|
|
329
|
-
color: slice.color,
|
|
330
|
-
hidden: slice.hidden,
|
|
331
|
-
// A hidden slice has no share of the visible total, so it shows none.
|
|
332
|
-
hint: slice.hidden ? undefined : formatPercent(slice.percent),
|
|
333
|
-
})),
|
|
315
|
+
const legendItems = computed(() =>
|
|
316
|
+
sliceLegendItems(slices.value, formatMeasure),
|
|
334
317
|
)
|
|
335
318
|
|
|
336
319
|
// The ring is one tab stop and the arrow keys walk it: an echarts plot draws
|
|
@@ -362,14 +345,7 @@ const { attrs: plotAttrs } = usePlotKeyboard({
|
|
|
362
345
|
move: readSlice,
|
|
363
346
|
activate: (index) => {
|
|
364
347
|
const slice = visibleSlices.value[index]
|
|
365
|
-
if (
|
|
366
|
-
emit('select', {
|
|
367
|
-
name: slice.name,
|
|
368
|
-
label: slice.label,
|
|
369
|
-
value: slice.value,
|
|
370
|
-
percent: slice.percent,
|
|
371
|
-
rows: slice.rows,
|
|
372
|
-
})
|
|
348
|
+
if (slice) emit('select', sliceEvent(slice))
|
|
373
349
|
},
|
|
374
350
|
clear: () => {
|
|
375
351
|
hovered.value = null
|
|
@@ -382,7 +358,7 @@ function toggleSlice(name: string) {
|
|
|
382
358
|
hiddenSlices.value = toggleHiddenSeries(
|
|
383
359
|
hiddenSlices.value,
|
|
384
360
|
name,
|
|
385
|
-
slices.value.
|
|
361
|
+
drawnSlices(slices.value).map((slice) => slice.name),
|
|
386
362
|
)
|
|
387
363
|
}
|
|
388
364
|
|
|
@@ -36,37 +36,15 @@
|
|
|
36
36
|
v-bind="plotAttrs"
|
|
37
37
|
/>
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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 =
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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>
|