@joniguerini/lume 0.0.0-stage → 1.9.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/LICENSE +25 -0
- package/README.md +62 -2
- package/base.css +165 -0
- package/bin/lumeui.mjs +163 -0
- package/components/alert.css +156 -0
- package/components/banner.css +98 -0
- package/components/button.css +291 -0
- package/components/calendar.css +532 -0
- package/components/carousel.css +175 -0
- package/components/chart.css +813 -0
- package/components/chat.css +670 -0
- package/components/checkbox.css +212 -0
- package/components/chip.css +224 -0
- package/components/code.css +36 -0
- package/components/color-picker.css +192 -0
- package/components/command.css +148 -0
- package/components/content.css +211 -0
- package/components/editor.css +174 -0
- package/components/feedback.css +320 -0
- package/components/filters.css +103 -0
- package/components/form.css +455 -0
- package/components/image-viewer.css +237 -0
- package/components/layers.css +138 -0
- package/components/link.css +87 -0
- package/components/loading.css +260 -0
- package/components/menu.css +180 -0
- package/components/modal.css +209 -0
- package/components/navigation.css +507 -0
- package/components/notifications.css +186 -0
- package/components/number-field.css +52 -0
- package/components/otp.css +119 -0
- package/components/panel.css +208 -0
- package/components/picker.css +207 -0
- package/components/rating.css +143 -0
- package/components/resizable.css +173 -0
- package/components/scrollbar.css +110 -0
- package/components/select.css +477 -0
- package/components/shell.css +837 -0
- package/components/slider.css +189 -0
- package/components/sortable.css +287 -0
- package/components/surfaces.css +182 -0
- package/components/switch.css +115 -0
- package/components/table.css +228 -0
- package/components/tabs.css +190 -0
- package/components/tags.css +83 -0
- package/components/toast.css +164 -0
- package/components/toolbar.css +80 -0
- package/components/upload.css +181 -0
- package/ds.css +48 -0
- package/fonts/Geist-LICENSE.txt +92 -0
- package/fonts/Geist-Variable.woff2 +0 -0
- package/fonts/GeistSerif-Regular.woff2 +0 -0
- package/fonts/JetBrainsMono-LICENSE.txt +93 -0
- package/fonts/JetBrainsMono-Variable.woff2 +0 -0
- package/fonts.css +29 -0
- package/icons/icons.d.ts +5 -0
- package/icons/icons.js +266 -0
- package/js/back-to-top.d.ts +2 -0
- package/js/back-to-top.js +62 -0
- package/js/banner.js +87 -0
- package/js/calendar.d.ts +3 -0
- package/js/calendar.js +472 -0
- package/js/carousel.d.ts +2 -0
- package/js/carousel.js +258 -0
- package/js/charts/bar.js +361 -0
- package/js/charts/core.js +604 -0
- package/js/charts/donut.js +206 -0
- package/js/charts/figures.js +97 -0
- package/js/charts/heatmap.js +410 -0
- package/js/charts/line.js +268 -0
- package/js/charts/scatter.js +211 -0
- package/js/charts.d.ts +12 -0
- package/js/charts.js +27 -0
- package/js/code-block.d.ts +3 -0
- package/js/code-block.js +32 -0
- package/js/color-picker.d.ts +4 -0
- package/js/color-picker.js +448 -0
- package/js/command-palette.js +233 -0
- package/js/composer.js +573 -0
- package/js/context-menu.d.ts +2 -0
- package/js/context-menu.js +154 -0
- package/js/date-picker.d.ts +2 -0
- package/js/date-picker.js +430 -0
- package/js/drawer.js +48 -0
- package/js/editor.d.ts +5 -0
- package/js/editor.js +615 -0
- package/js/field-support.js +77 -0
- package/js/file-upload.d.ts +2 -0
- package/js/file-upload.js +230 -0
- package/js/filters.js +266 -0
- package/js/form.d.ts +2 -0
- package/js/form.js +409 -0
- package/js/i18n.d.ts +14 -0
- package/js/i18n.js +83 -0
- package/js/image-viewer.d.ts +4 -0
- package/js/image-viewer.js +275 -0
- package/js/menu.d.ts +4 -0
- package/js/menu.js +237 -0
- package/js/messages.js +908 -0
- package/js/modal.d.ts +7 -0
- package/js/modal.js +183 -0
- package/js/notifications.d.ts +4 -0
- package/js/notifications.js +204 -0
- package/js/number-field.d.ts +2 -0
- package/js/number-field.js +175 -0
- package/js/otp-field.d.ts +2 -0
- package/js/otp-field.js +107 -0
- package/js/pagination.d.ts +3 -0
- package/js/pagination.js +143 -0
- package/js/popover.d.ts +2 -0
- package/js/popover.js +155 -0
- package/js/progress-ring.js +48 -0
- package/js/rating.d.ts +3 -0
- package/js/rating.js +130 -0
- package/js/resizable.d.ts +2 -0
- package/js/resizable.js +311 -0
- package/js/scrollbar.d.ts +2 -0
- package/js/scrollbar.js +273 -0
- package/js/segmented.js +60 -0
- package/js/select.d.ts +3 -0
- package/js/select.js +784 -0
- package/js/shell.d.ts +6 -0
- package/js/shell.js +373 -0
- package/js/slider.d.ts +2 -0
- package/js/slider.js +89 -0
- package/js/sortable.d.ts +5 -0
- package/js/sortable.js +463 -0
- package/js/stepper.d.ts +2 -0
- package/js/stepper.js +72 -0
- package/js/tabs.js +99 -0
- package/js/tag-field.d.ts +2 -0
- package/js/tag-field.js +177 -0
- package/js/theme.d.ts +9 -0
- package/js/theme.js +114 -0
- package/js/time-picker.d.ts +2 -0
- package/js/time-picker.js +279 -0
- package/js/toast.d.ts +17 -0
- package/js/toast.js +171 -0
- package/js/toolbar.d.ts +2 -0
- package/js/toolbar.js +107 -0
- package/js/tooltip.d.ts +2 -0
- package/js/tooltip.js +208 -0
- package/js/tree.d.ts +2 -0
- package/js/tree.js +168 -0
- package/lume.css +11574 -0
- package/lume.d.ts +104 -0
- package/lume.js +67 -0
- package/package.json +66 -4
- package/react/Alert.d.ts +24 -0
- package/react/Alert.js +21 -0
- package/react/AppShell.d.ts +67 -0
- package/react/AppShell.js +94 -0
- package/react/Avatar.d.ts +39 -0
- package/react/Avatar.js +40 -0
- package/react/Badge.d.ts +17 -0
- package/react/Badge.js +10 -0
- package/react/Button.d.ts +32 -0
- package/react/Button.js +17 -0
- package/react/Calendar.d.ts +48 -0
- package/react/Calendar.js +67 -0
- package/react/Carousel.d.ts +30 -0
- package/react/Carousel.js +38 -0
- package/react/Charts.d.ts +186 -0
- package/react/Charts.js +58 -0
- package/react/Chip.d.ts +34 -0
- package/react/Chip.js +26 -0
- package/react/Choice.d.ts +72 -0
- package/react/Choice.js +51 -0
- package/react/ColorPicker.d.ts +43 -0
- package/react/ColorPicker.js +73 -0
- package/react/Content.d.ts +58 -0
- package/react/Content.js +42 -0
- package/react/Controls.d.ts +97 -0
- package/react/Controls.js +118 -0
- package/react/Editor.d.ts +28 -0
- package/react/Editor.js +57 -0
- package/react/Field.d.ts +90 -0
- package/react/Field.js +65 -0
- package/react/Form.d.ts +36 -0
- package/react/Form.js +45 -0
- package/react/Icon.d.ts +13 -0
- package/react/Icon.js +8 -0
- package/react/IconButton.d.ts +19 -0
- package/react/IconButton.js +12 -0
- package/react/ImageViewer.d.ts +20 -0
- package/react/ImageViewer.js +22 -0
- package/react/InlineAction.d.ts +15 -0
- package/react/InlineAction.js +12 -0
- package/react/Layers.d.ts +118 -0
- package/react/Layers.js +115 -0
- package/react/Link.d.ts +32 -0
- package/react/Link.js +26 -0
- package/react/Loading.d.ts +67 -0
- package/react/Loading.js +49 -0
- package/react/Navigation.d.ts +181 -0
- package/react/Navigation.js +197 -0
- package/react/Notices.d.ts +43 -0
- package/react/Notices.js +89 -0
- package/react/Panel.d.ts +57 -0
- package/react/Panel.js +33 -0
- package/react/Pickers.d.ts +83 -0
- package/react/Pickers.js +70 -0
- package/react/Rating.d.ts +39 -0
- package/react/Rating.js +41 -0
- package/react/Resizable.d.ts +44 -0
- package/react/Resizable.js +30 -0
- package/react/Select.d.ts +53 -0
- package/react/Select.js +79 -0
- package/react/Sortable.d.ts +52 -0
- package/react/Sortable.js +113 -0
- package/react/Table.d.ts +60 -0
- package/react/Table.js +34 -0
- package/react/Toolbar.d.ts +45 -0
- package/react/Toolbar.js +45 -0
- package/react/cx.d.ts +2 -0
- package/react/cx.js +5 -0
- package/react/icon-names.d.ts +1 -0
- package/react/icon-names.js +2 -0
- package/react/index.d.ts +42 -0
- package/react/index.js +52 -0
- package/react/useController.d.ts +8 -0
- package/react/useController.js +16 -0
- package/react/useLocale.d.ts +5 -0
- package/react/useLocale.js +15 -0
- package/tokens.css +739 -0
- package/tokens.js +4911 -0
package/js/carousel.js
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Carrossel — destaques e galerias que passam um por vez.
|
|
3
|
+
*
|
|
4
|
+
* <section class="ds-carousel" aria-label="Destaques">
|
|
5
|
+
* <div class="ds-carousel__viewport">
|
|
6
|
+
* <div class="ds-carousel__slide">…</div> …
|
|
7
|
+
* </div>
|
|
8
|
+
* </section>
|
|
9
|
+
*
|
|
10
|
+
* const carousel = createCarousel(document.querySelector('.ds-carousel'), {
|
|
11
|
+
* loop: false, // depois do último volta ao primeiro
|
|
12
|
+
* autoplay: 0, // ms entre um slide e outro; 0 desliga. Com autoplay sempre há o botão de pausa
|
|
13
|
+
* dots: true, // pontos para ir direto a um slide
|
|
14
|
+
* count: true, // “2 / 5”
|
|
15
|
+
* onChange: (index) => {},
|
|
16
|
+
* });
|
|
17
|
+
* carousel.next(); carousel.prev(); carousel.goTo(2); carousel.pause(); carousel.play(); carousel.destroy();
|
|
18
|
+
*
|
|
19
|
+
* Quantos aparecem de uma vez vem do CSS (--ds-carousel-per-view), então muda com media query sem mexer aqui.
|
|
20
|
+
* Arrastar é a rolagem nativa (scroll-snap): toque, trackpad e Shift + roda funcionam sem código.
|
|
21
|
+
*
|
|
22
|
+
* Acessibilidade (padrão ARIA de carrossel): aria-roledescription “carrossel” e “slide”, cada slide com “2 de 5”,
|
|
23
|
+
* os que estão fora da vista ficam inert (o Tab não cai neles), setas ← → Home End na área dos slides.
|
|
24
|
+
* Com autoplay: para com o mouse em cima ou o foco dentro, não começa com prefers-reduced-motion e o anúncio
|
|
25
|
+
* do leitor de tela só liga quando está parado (aria-live off enquanto passa sozinho).
|
|
26
|
+
*/
|
|
27
|
+
import { icon } from '../icons/icons.js';
|
|
28
|
+
import { msg } from './i18n.js';
|
|
29
|
+
|
|
30
|
+
const reduceMotion = () => window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
|
31
|
+
|
|
32
|
+
export function createCarousel(root, options = {}) {
|
|
33
|
+
const o = { loop: false, autoplay: 0, dots: true, count: true, ...options };
|
|
34
|
+
const viewport = root.querySelector('.ds-carousel__viewport');
|
|
35
|
+
if (!viewport) throw new Error('createCarousel: falta .ds-carousel__viewport');
|
|
36
|
+
const slides = () => [...viewport.children].filter((el) => el.classList.contains('ds-carousel__slide'));
|
|
37
|
+
// rótulo próprio do slide (aria-label ou aria-labelledby) fica; os outros ganham “2 de 5”
|
|
38
|
+
const own = new WeakSet(slides().filter((s) => s.hasAttribute('aria-label') || s.hasAttribute('aria-labelledby')));
|
|
39
|
+
|
|
40
|
+
let index = 0;
|
|
41
|
+
let stops = 1; // posições possíveis: slides − por vista + 1
|
|
42
|
+
let userPaused = reduceMotion();
|
|
43
|
+
let hovered = false;
|
|
44
|
+
let focused = false;
|
|
45
|
+
let timer = null;
|
|
46
|
+
let frame = 0;
|
|
47
|
+
let target = null; // durante a rolagem pedida por código, a rolagem não mexe no índice
|
|
48
|
+
let settle = 0;
|
|
49
|
+
|
|
50
|
+
const bar = document.createElement('div');
|
|
51
|
+
bar.className = 'ds-carousel__bar';
|
|
52
|
+
root.append(bar);
|
|
53
|
+
|
|
54
|
+
const perView = () => Math.max(1, Math.round(Number(getComputedStyle(root).getPropertyValue('--ds-carousel-per-view')) || 1));
|
|
55
|
+
const step = () => {
|
|
56
|
+
const [a, b] = slides();
|
|
57
|
+
if (!a) return 1;
|
|
58
|
+
return b ? b.offsetLeft - a.offsetLeft : a.offsetWidth;
|
|
59
|
+
};
|
|
60
|
+
const rolling = () => Boolean(o.autoplay) && !userPaused && !hovered && !focused;
|
|
61
|
+
|
|
62
|
+
function renderBar() {
|
|
63
|
+
const parts = [];
|
|
64
|
+
if (o.autoplay) {
|
|
65
|
+
const label = userPaused ? msg('carousel.play') : msg('carousel.pause');
|
|
66
|
+
parts.push(`<button type="button" class="ds-icon-btn ds-icon-btn--sm ds-icon-btn--muted" data-carousel="toggle" aria-label="${label}">${icon(userPaused ? 'play' : 'pause', { size: 16 })}</button>`);
|
|
67
|
+
}
|
|
68
|
+
parts.push(
|
|
69
|
+
`<div class="ds-carousel__dots"${o.dots && stops > 1 ? '' : ' hidden'}>${Array.from(
|
|
70
|
+
{ length: stops },
|
|
71
|
+
(_, i) => `<button type="button" class="ds-carousel__dot" data-carousel-dot="${i}" aria-label="${msg('carousel.goTo', i + 1)}"${i === index ? ' aria-current="true"' : ''}></button>`,
|
|
72
|
+
).join('')}</div>`,
|
|
73
|
+
);
|
|
74
|
+
if (o.count && stops > 1) parts.push(`<span class="ds-carousel__count" aria-hidden="true">${index + 1} / ${stops}</span>`);
|
|
75
|
+
parts.push(`<div class="ds-carousel__nav"${stops > 1 ? '' : ' hidden'}>
|
|
76
|
+
<button type="button" class="ds-icon-btn ds-icon-btn--muted" data-carousel="prev" aria-label="${msg('carousel.prev')}">${icon('chevron-left', { size: 20 })}</button>
|
|
77
|
+
<button type="button" class="ds-icon-btn ds-icon-btn--muted" data-carousel="next" aria-label="${msg('carousel.next')}">${icon('chevron-right', { size: 20 })}</button>
|
|
78
|
+
</div>`);
|
|
79
|
+
bar.innerHTML = parts.join('');
|
|
80
|
+
syncBar();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function syncBar() {
|
|
84
|
+
bar.querySelectorAll('[data-carousel-dot]').forEach((dot) => {
|
|
85
|
+
if (Number(dot.dataset.carouselDot) === index) dot.setAttribute('aria-current', 'true');
|
|
86
|
+
else dot.removeAttribute('aria-current');
|
|
87
|
+
});
|
|
88
|
+
const count = bar.querySelector('.ds-carousel__count');
|
|
89
|
+
if (count) count.textContent = `${index + 1} / ${stops}`;
|
|
90
|
+
const prev = bar.querySelector('[data-carousel="prev"]');
|
|
91
|
+
const next = bar.querySelector('[data-carousel="next"]');
|
|
92
|
+
const focusedArrow = [prev, next].find((b) => b && b === document.activeElement);
|
|
93
|
+
if (prev) prev.disabled = !o.loop && index === 0;
|
|
94
|
+
if (next) next.disabled = !o.loop && index === stops - 1;
|
|
95
|
+
// a seta com foco chegou à ponta: o foco passa para a outra, em vez de cair no body
|
|
96
|
+
if (focusedArrow?.disabled) (focusedArrow === prev ? next : prev)?.focus();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function syncSlides() {
|
|
100
|
+
const list = slides();
|
|
101
|
+
const view = perView();
|
|
102
|
+
list.forEach((slide, i) => {
|
|
103
|
+
const visible = i >= index && i < index + view;
|
|
104
|
+
slide.setAttribute('role', 'group');
|
|
105
|
+
slide.setAttribute('aria-roledescription', msg('carousel.slide'));
|
|
106
|
+
if (!own.has(slide)) slide.setAttribute('aria-label', msg('carousel.position', i + 1, list.length));
|
|
107
|
+
slide.inert = !visible;
|
|
108
|
+
if (visible) slide.removeAttribute('aria-hidden');
|
|
109
|
+
else slide.setAttribute('aria-hidden', 'true');
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function measure() {
|
|
114
|
+
stops = Math.max(1, slides().length - perView() + 1);
|
|
115
|
+
index = Math.min(index, stops - 1);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function setIndex(next, { notify = true } = {}) {
|
|
119
|
+
if (next === index) return;
|
|
120
|
+
index = next;
|
|
121
|
+
syncBar();
|
|
122
|
+
syncSlides();
|
|
123
|
+
if (notify) o.onChange?.(index);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function goTo(to, { smooth = true } = {}) {
|
|
127
|
+
let next = to;
|
|
128
|
+
if (o.loop) next = ((to % stops) + stops) % stops;
|
|
129
|
+
next = Math.min(Math.max(next, 0), stops - 1);
|
|
130
|
+
const animate = smooth && !reduceMotion();
|
|
131
|
+
target = animate ? next : null;
|
|
132
|
+
clearTimeout(settle);
|
|
133
|
+
if (animate) settle = setTimeout(() => (target = null), 900);
|
|
134
|
+
viewport.scrollTo({ left: next * step(), behavior: animate ? 'smooth' : 'auto' });
|
|
135
|
+
setIndex(next);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const onScrollEnd = () => {
|
|
139
|
+
target = null;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const onScroll = () => {
|
|
143
|
+
if (target !== null) return;
|
|
144
|
+
cancelAnimationFrame(frame);
|
|
145
|
+
frame = requestAnimationFrame(() => setIndex(Math.min(stops - 1, Math.max(0, Math.round(viewport.scrollLeft / step())))));
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
function schedule() {
|
|
149
|
+
clearInterval(timer);
|
|
150
|
+
timer = null;
|
|
151
|
+
viewport.setAttribute('aria-live', rolling() ? 'off' : 'polite');
|
|
152
|
+
if (rolling()) timer = setInterval(() => goTo(index === stops - 1 ? 0 : index + 1), o.autoplay);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function setPaused(value) {
|
|
156
|
+
userPaused = value;
|
|
157
|
+
renderBar();
|
|
158
|
+
schedule();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const onBarClick = (event) => {
|
|
162
|
+
const dot = event.target.closest('[data-carousel-dot]');
|
|
163
|
+
if (dot) return goTo(Number(dot.dataset.carouselDot));
|
|
164
|
+
const action = event.target.closest('[data-carousel]')?.dataset.carousel;
|
|
165
|
+
if (action === 'prev') goTo(index - 1);
|
|
166
|
+
if (action === 'next') goTo(index + 1);
|
|
167
|
+
if (action === 'toggle') {
|
|
168
|
+
setPaused(!userPaused);
|
|
169
|
+
bar.querySelector('[data-carousel="toggle"]')?.focus();
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const onKey = (event) => {
|
|
174
|
+
if (event.target !== viewport) return;
|
|
175
|
+
const keys = { ArrowLeft: index - 1, ArrowRight: index + 1, Home: 0, End: stops - 1 };
|
|
176
|
+
if (!(event.key in keys)) return;
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
goTo(keys[event.key]);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const onEnter = () => { hovered = true; schedule(); };
|
|
182
|
+
const onLeave = () => { hovered = false; schedule(); };
|
|
183
|
+
const onFocusIn = () => { focused = true; schedule(); };
|
|
184
|
+
const onFocusOut = (event) => {
|
|
185
|
+
if (root.contains(event.relatedTarget)) return;
|
|
186
|
+
focused = false;
|
|
187
|
+
schedule();
|
|
188
|
+
};
|
|
189
|
+
const onLocale = () => {
|
|
190
|
+
root.setAttribute('aria-roledescription', msg('carousel.label'));
|
|
191
|
+
renderBar();
|
|
192
|
+
syncSlides();
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const resize = typeof ResizeObserver === 'function'
|
|
196
|
+
? new ResizeObserver(() => {
|
|
197
|
+
const before = stops;
|
|
198
|
+
measure();
|
|
199
|
+
if (before !== stops) renderBar();
|
|
200
|
+
syncSlides();
|
|
201
|
+
viewport.scrollTo({ left: index * step(), behavior: 'auto' });
|
|
202
|
+
})
|
|
203
|
+
: null;
|
|
204
|
+
|
|
205
|
+
root.setAttribute('aria-roledescription', msg('carousel.label'));
|
|
206
|
+
if (!viewport.hasAttribute('tabindex')) viewport.tabIndex = 0;
|
|
207
|
+
measure();
|
|
208
|
+
renderBar();
|
|
209
|
+
syncSlides();
|
|
210
|
+
schedule();
|
|
211
|
+
|
|
212
|
+
bar.addEventListener('click', onBarClick);
|
|
213
|
+
viewport.addEventListener('scroll', onScroll, { passive: true });
|
|
214
|
+
viewport.addEventListener('scrollend', onScrollEnd);
|
|
215
|
+
viewport.addEventListener('keydown', onKey);
|
|
216
|
+
root.addEventListener('pointerenter', onEnter);
|
|
217
|
+
root.addEventListener('pointerleave', onLeave);
|
|
218
|
+
root.addEventListener('focusin', onFocusIn);
|
|
219
|
+
root.addEventListener('focusout', onFocusOut);
|
|
220
|
+
document.documentElement.addEventListener('ds:localechange', onLocale);
|
|
221
|
+
resize?.observe(viewport);
|
|
222
|
+
|
|
223
|
+
return {
|
|
224
|
+
get index() {
|
|
225
|
+
return index;
|
|
226
|
+
},
|
|
227
|
+
get paused() {
|
|
228
|
+
return userPaused;
|
|
229
|
+
},
|
|
230
|
+
goTo: (i) => goTo(i),
|
|
231
|
+
next: () => goTo(index + 1),
|
|
232
|
+
prev: () => goTo(index - 1),
|
|
233
|
+
pause: () => setPaused(true),
|
|
234
|
+
play: () => setPaused(false),
|
|
235
|
+
destroy() {
|
|
236
|
+
clearInterval(timer);
|
|
237
|
+
cancelAnimationFrame(frame);
|
|
238
|
+
resize?.disconnect();
|
|
239
|
+
bar.removeEventListener('click', onBarClick);
|
|
240
|
+
viewport.removeEventListener('scroll', onScroll);
|
|
241
|
+
viewport.removeEventListener('scrollend', onScrollEnd);
|
|
242
|
+
clearTimeout(settle);
|
|
243
|
+
viewport.removeEventListener('keydown', onKey);
|
|
244
|
+
root.removeEventListener('pointerenter', onEnter);
|
|
245
|
+
root.removeEventListener('pointerleave', onLeave);
|
|
246
|
+
root.removeEventListener('focusin', onFocusIn);
|
|
247
|
+
root.removeEventListener('focusout', onFocusOut);
|
|
248
|
+
document.documentElement.removeEventListener('ds:localechange', onLocale);
|
|
249
|
+
bar.remove();
|
|
250
|
+
root.removeAttribute('aria-roledescription');
|
|
251
|
+
viewport.removeAttribute('aria-live');
|
|
252
|
+
slides().forEach((slide) => {
|
|
253
|
+
slide.inert = false;
|
|
254
|
+
['role', 'aria-roledescription', 'aria-hidden', ...(own.has(slide) ? [] : ['aria-label'])].forEach((a) => slide.removeAttribute(a));
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
}
|
package/js/charts/bar.js
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lume — gráfico de barras (colunas e barras horizontais).
|
|
3
|
+
*
|
|
4
|
+
* createBarChart(host, {
|
|
5
|
+
* categories: ['Jan', 'Fev', …],
|
|
6
|
+
* series: [{ name: 'Receita', values: [12, 18, …], color? }],
|
|
7
|
+
* orientation: 'vertical' | 'horizontal',
|
|
8
|
+
* layout: 'grouped' | 'stacked' | 'percent',
|
|
9
|
+
* labels: 'auto' | 'none' | 'all' | 'max' | 'last',
|
|
10
|
+
* highlight: índice da categoria em destaque (o resto fica cinza),
|
|
11
|
+
* diverging: true — acima/abaixo de zero nas cores divergentes,
|
|
12
|
+
* ordinal: true — categorias em sequência (funil, faixas) numa rampa de um tom,
|
|
13
|
+
* format, axisFormat, height, title, subtitle, label, card, table, texture, tooltipLabels,
|
|
14
|
+
* }) → { update(options), setLoading(bool), destroy(), el }
|
|
15
|
+
*
|
|
16
|
+
* Marcas: no máximo 24 px de espessura, ponta de dados com raio de 4 px e base reta,
|
|
17
|
+
* 2 px de respiro entre barras vizinhas e entre segmentos empilhados.
|
|
18
|
+
*/
|
|
19
|
+
import {
|
|
20
|
+
createFrame, normalizeSeries, formatter, axisFormatter, niceTicks, linear, textWidth, fitText, labelStep,
|
|
21
|
+
barPath, tag, escapeHtml, yAxis, xAxis, texturePatterns, clamp, FONTS,
|
|
22
|
+
} from './core.js';
|
|
23
|
+
import { msg } from '../i18n.js';
|
|
24
|
+
|
|
25
|
+
const GAP = 2;
|
|
26
|
+
const MAX_BAR = 24;
|
|
27
|
+
|
|
28
|
+
export function createBarChart(host, input) {
|
|
29
|
+
let source = input;
|
|
30
|
+
let o = normalize(source);
|
|
31
|
+
const hidden = new Set();
|
|
32
|
+
const frame = createFrame(host, o, { kind: 'bar' });
|
|
33
|
+
let geo = null;
|
|
34
|
+
|
|
35
|
+
function normalize(opts) {
|
|
36
|
+
return {
|
|
37
|
+
orientation: 'vertical',
|
|
38
|
+
layout: 'grouped',
|
|
39
|
+
labels: 'auto',
|
|
40
|
+
height: 280,
|
|
41
|
+
categories: [],
|
|
42
|
+
...opts,
|
|
43
|
+
series: normalizeSeries(opts.series),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const visible = () => o.series.filter((s) => !hidden.has(s.index));
|
|
48
|
+
const isStack = () => o.layout === 'stacked' || o.layout === 'percent';
|
|
49
|
+
|
|
50
|
+
function color(s, c, v) {
|
|
51
|
+
if (o.highlight != null) return c === o.highlight ? s.paint : 'var(--ds-color-chart-muted)';
|
|
52
|
+
if (o.diverging) return v < 0 ? 'var(--ds-color-chart-div-2)' : 'var(--ds-color-chart-div-6)';
|
|
53
|
+
if (o.ordinal) {
|
|
54
|
+
const n = o.categories.length;
|
|
55
|
+
const step = n > 1 ? Math.round((c / (n - 1)) * 4) : 0;
|
|
56
|
+
return `var(--ds-color-chart-ord-${5 - step})`;
|
|
57
|
+
}
|
|
58
|
+
return s.paint;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const textured = () => o.texture && o.highlight == null && !o.diverging && !o.ordinal;
|
|
62
|
+
|
|
63
|
+
function legend() {
|
|
64
|
+
if (o.series.length > 1 && !o.ordinal) {
|
|
65
|
+
frame.setLegend(
|
|
66
|
+
o.series.map((s) => ({ name: s.name, color: s.paint, mark: 'rect', hidden: hidden.has(s.index) })),
|
|
67
|
+
(i) => {
|
|
68
|
+
if (hidden.has(i)) hidden.delete(i);
|
|
69
|
+
else if (visible().length > 1) hidden.add(i);
|
|
70
|
+
legend();
|
|
71
|
+
render();
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
} else if (o.diverging && (o.positiveLabel || o.negativeLabel)) {
|
|
75
|
+
frame.setLegend([
|
|
76
|
+
{ name: o.positiveLabel ?? msg('chart.above'), color: 'var(--ds-color-chart-div-6)' },
|
|
77
|
+
{ name: o.negativeLabel ?? msg('chart.below'), color: 'var(--ds-color-chart-div-2)' },
|
|
78
|
+
]);
|
|
79
|
+
} else frame.setLegend([]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Valores prontos para desenhar (percent normaliza por categoria). */
|
|
83
|
+
function matrix(vs) {
|
|
84
|
+
return o.categories.map((_, c) => {
|
|
85
|
+
const row = vs.map((s) => s.values[c]);
|
|
86
|
+
if (o.layout !== 'percent') return row;
|
|
87
|
+
const total = row.reduce((a, v) => a + Math.max(0, v ?? 0), 0);
|
|
88
|
+
return row.map((v) => (v == null ? null : total ? Math.max(0, v) / total : 0));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function domain(rows) {
|
|
93
|
+
if (o.layout === 'percent') return [0, 1];
|
|
94
|
+
if (isStack()) return [0, Math.max(0, ...rows.map((r) => r.reduce((a, v) => a + Math.max(0, v ?? 0), 0)))];
|
|
95
|
+
const all = rows.flat().filter((v) => v != null);
|
|
96
|
+
return [Math.min(0, ...all), Math.max(0, ...all)];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function labelMode() {
|
|
100
|
+
if (o.labels !== 'auto') return o.labels;
|
|
101
|
+
return o.orientation === 'horizontal' && (visible().length === 1 || isStack()) ? 'all' : 'none';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function render() {
|
|
105
|
+
const W = frame.width;
|
|
106
|
+
if (!W) return;
|
|
107
|
+
const vs = visible();
|
|
108
|
+
const n = o.categories.length;
|
|
109
|
+
if (!n || !vs.length) {
|
|
110
|
+
geo = null;
|
|
111
|
+
frame.empty();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const rows = matrix(vs);
|
|
115
|
+
const fmt = formatter(o.layout === 'percent' ? 'percent' : o.format);
|
|
116
|
+
const afmt = axisFormatter(o.layout === 'percent' ? 'percent' : o.format, o.layout === 'percent' ? undefined : o.axisFormat);
|
|
117
|
+
const mode = labelMode();
|
|
118
|
+
const [dmin, dmax] = domain(rows);
|
|
119
|
+
|
|
120
|
+
/** Quais posições ganham rótulo de valor: seletivo, nunca um número em cada barra por padrão. */
|
|
121
|
+
const totals = rows.map((r) => (isStack() ? r.reduce((a, v) => a + Math.max(0, v ?? 0), 0) : null));
|
|
122
|
+
const peak = (() => {
|
|
123
|
+
let best = null;
|
|
124
|
+
rows.forEach((r, c) => r.forEach((v, j) => {
|
|
125
|
+
const val = isStack() ? totals[c] : v;
|
|
126
|
+
if (val != null && (best == null || val > best.v)) best = { c, j: isStack() ? null : j, v: val };
|
|
127
|
+
}));
|
|
128
|
+
return best;
|
|
129
|
+
})();
|
|
130
|
+
const wantsLabel = (c, j) => {
|
|
131
|
+
if (mode === 'all') return true;
|
|
132
|
+
if (mode === 'last') return c === n - 1;
|
|
133
|
+
if (mode === 'max') return peak && peak.c === c && (peak.j == null || peak.j === j);
|
|
134
|
+
return false;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const defs = textured() ? `<defs>${texturePatterns(frame.id, o.series.map((s) => s.paint))}</defs>` : '';
|
|
138
|
+
const fill = (s, c, v) => {
|
|
139
|
+
const base = `--c:${color(s, c, v)}`;
|
|
140
|
+
return textured() ? `${base};--t:url(#${frame.id}-t${s.index})` : base;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
let svg = '';
|
|
144
|
+
let H;
|
|
145
|
+
const marks = [];
|
|
146
|
+
|
|
147
|
+
if (o.orientation === 'horizontal') {
|
|
148
|
+
const k = isStack() ? 1 : vs.length;
|
|
149
|
+
const thick = clamp(o.barSize ?? (k > 1 ? 12 : 20), 4, MAX_BAR);
|
|
150
|
+
const groupH = k * thick + (k - 1) * GAP;
|
|
151
|
+
const rowH = Math.max(o.rowHeight ?? 36, groupH + 14);
|
|
152
|
+
const showAxis = mode !== 'all';
|
|
153
|
+
const top = 4;
|
|
154
|
+
const bottom = showAxis ? 28 : 4;
|
|
155
|
+
H = top + n * rowH + bottom;
|
|
156
|
+
const catW = Math.min(W * 0.38, Math.max(...o.categories.map((l) => textWidth(l, FONTS.label))));
|
|
157
|
+
const left = Math.ceil(catW) + 14;
|
|
158
|
+
const valueStrings = rows.flatMap((r, c) => (isStack() ? [fmt(totals[c])] : r.map((v) => (v == null ? '' : fmt(v)))));
|
|
159
|
+
const right = mode === 'none' ? 12 : Math.ceil(Math.max(...valueStrings.map((s) => textWidth(s, FONTS.value)))) + 12;
|
|
160
|
+
// Barras negativas levam o valor à esquerda da ponta: reserve esse espaço antes do eixo.
|
|
161
|
+
const negatives = isStack() || mode === 'none' ? [] : rows.flat().filter((v) => v != null && v < 0).map((v) => textWidth(fmt(v), FONTS.value));
|
|
162
|
+
const negPad = negatives.length ? Math.ceil(Math.max(...negatives)) + 8 : 0;
|
|
163
|
+
const plotW = Math.max(40, W - left - negPad - right);
|
|
164
|
+
const { ticks, min, max } = niceTicks(dmin, dmax, Math.max(2, Math.round(plotW / 90)));
|
|
165
|
+
const x = linear(min, max, left + negPad, left + negPad + plotW);
|
|
166
|
+
const x0 = x(0);
|
|
167
|
+
|
|
168
|
+
svg += showAxis
|
|
169
|
+
? xAxis({ ticks, x, top, bottom: top + n * rowH, format: afmt })
|
|
170
|
+
: tag('line', { x1: Math.round(x0) + 0.5, x2: Math.round(x0) + 0.5, y1: top, y2: top + n * rowH, class: 'ds-chart__baseline' });
|
|
171
|
+
svg += tag('rect', { class: 'ds-chart__band', 'data-band': '', x: 0, y: 0, width: 0, height: 0, rx: 8 });
|
|
172
|
+
|
|
173
|
+
o.categories.forEach((cat, c) => {
|
|
174
|
+
const rowY = top + c * rowH;
|
|
175
|
+
const gy = rowY + (rowH - groupH) / 2;
|
|
176
|
+
svg += tag('text', { x: left - 14, y: rowY + rowH / 2, class: 'ds-chart__label', 'text-anchor': 'end', 'dominant-baseline': 'middle' }, escapeHtml(fitText(cat, catW)));
|
|
177
|
+
let cum = 0;
|
|
178
|
+
const segs = rows[c].map((v, j) => ({ v, s: vs[j] })).filter((d) => d.v != null && (!isStack() || d.v > 0));
|
|
179
|
+
let edge = x0;
|
|
180
|
+
segs.forEach(({ v, s }, j) => {
|
|
181
|
+
const by = isStack() ? gy : gy + vs.indexOf(s) * (thick + GAP);
|
|
182
|
+
let xa;
|
|
183
|
+
let xb;
|
|
184
|
+
let end;
|
|
185
|
+
if (isStack()) {
|
|
186
|
+
xa = x(cum) + (j > 0 ? GAP : 0);
|
|
187
|
+
cum += v;
|
|
188
|
+
xb = x(cum);
|
|
189
|
+
end = j === segs.length - 1 ? 'right' : 'none-h';
|
|
190
|
+
} else {
|
|
191
|
+
xa = Math.min(x0, x(v));
|
|
192
|
+
xb = Math.max(x0, x(v));
|
|
193
|
+
end = v < 0 ? 'left' : 'right';
|
|
194
|
+
}
|
|
195
|
+
edge = Math.max(edge, xb);
|
|
196
|
+
const d = barPath(xa, by, xb - xa, thick, end);
|
|
197
|
+
if (d) svg += tag('path', { d, class: 'ds-chart__bar', 'data-c': c, 'data-end': end, style: `${fill(s, c, v)};--d:${Math.min(c, 12) * 28}ms` });
|
|
198
|
+
if (!isStack() && wantsLabel(c, vs.indexOf(s))) {
|
|
199
|
+
const tx = v < 0 ? xa - 6 : xb + 6;
|
|
200
|
+
svg += tag('text', { x: tx, y: by + thick / 2, class: 'ds-chart__value', 'text-anchor': v < 0 ? 'end' : 'start', 'dominant-baseline': 'middle' }, escapeHtml(fmt(v)));
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
if (isStack() && wantsLabel(c)) svg += tag('text', { x: edge + 6, y: gy + thick / 2, class: 'ds-chart__value', 'dominant-baseline': 'middle' }, escapeHtml(fmt(totals[c])));
|
|
204
|
+
marks.push({ c, x: Math.max(edge, x0), y: rowY + rowH / 2, band: [0, rowY + 2, W, rowH - 4] });
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
geo = { horizontal: true, rowH, top, n, marks };
|
|
208
|
+
} else {
|
|
209
|
+
H = o.height;
|
|
210
|
+
const valueSpace = mode === 'none' ? 0 : 18;
|
|
211
|
+
const top = 10 + valueSpace;
|
|
212
|
+
const bottom = 28;
|
|
213
|
+
const plotH = Math.max(40, H - top - bottom);
|
|
214
|
+
const { ticks, min, max } = niceTicks(dmin, dmax, Math.max(2, Math.round(plotH / 56)));
|
|
215
|
+
const left = Math.ceil(Math.max(...ticks.map((t) => textWidth(afmt(t))))) + 14;
|
|
216
|
+
const right = 8;
|
|
217
|
+
const plotW = Math.max(40, W - left - right);
|
|
218
|
+
const y = linear(min, max, top + plotH, top);
|
|
219
|
+
const y0 = y(0);
|
|
220
|
+
const band = plotW / n;
|
|
221
|
+
const k = isStack() ? 1 : vs.length;
|
|
222
|
+
const barW = isStack() ? clamp(band * 0.56, 2, MAX_BAR) : clamp((band * 0.72 - (k - 1) * GAP) / k, 2, MAX_BAR);
|
|
223
|
+
const groupW = k * barW + (k - 1) * GAP;
|
|
224
|
+
|
|
225
|
+
svg += yAxis({ ticks, y, left, right: left + plotW, format: afmt });
|
|
226
|
+
svg += tag('rect', { class: 'ds-chart__band', 'data-band': '', x: 0, y: 0, width: 0, height: 0, rx: 8 });
|
|
227
|
+
|
|
228
|
+
const step = labelStep(o.categories, band);
|
|
229
|
+
o.categories.forEach((cat, c) => {
|
|
230
|
+
const bx = left + c * band;
|
|
231
|
+
const gx = bx + (band - groupW) / 2;
|
|
232
|
+
let topY = y0;
|
|
233
|
+
let cum = 0;
|
|
234
|
+
const segs = rows[c].map((v, j) => ({ v, s: vs[j], j })).filter((d) => d.v != null && (!isStack() || d.v > 0));
|
|
235
|
+
segs.forEach(({ v, s, j }, idx) => {
|
|
236
|
+
let ya;
|
|
237
|
+
let yb;
|
|
238
|
+
let end;
|
|
239
|
+
const bx2 = isStack() ? gx : gx + j * (barW + GAP);
|
|
240
|
+
if (isStack()) {
|
|
241
|
+
ya = y(cum + v);
|
|
242
|
+
yb = y(cum) - (idx > 0 ? GAP : 0);
|
|
243
|
+
cum += v;
|
|
244
|
+
end = idx === segs.length - 1 ? 'top' : 'none';
|
|
245
|
+
} else {
|
|
246
|
+
ya = Math.min(y0, y(v));
|
|
247
|
+
yb = Math.max(y0, y(v));
|
|
248
|
+
end = v < 0 ? 'bottom' : 'top';
|
|
249
|
+
}
|
|
250
|
+
topY = Math.min(topY, ya);
|
|
251
|
+
const d = barPath(bx2, ya, barW, yb - ya, end);
|
|
252
|
+
if (d) svg += tag('path', { d, class: 'ds-chart__bar', 'data-c': c, 'data-end': end, style: `${fill(s, c, v)};--d:${Math.min(c, 16) * 24}ms` });
|
|
253
|
+
if (!isStack() && wantsLabel(c, j)) {
|
|
254
|
+
const ty = v < 0 ? yb + 14 : ya - 7;
|
|
255
|
+
svg += tag('text', { x: bx2 + barW / 2, y: ty, class: 'ds-chart__value', 'text-anchor': 'middle' }, escapeHtml(fmt(v)));
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
if (isStack() && wantsLabel(c)) svg += tag('text', { x: gx + barW / 2, y: topY - 7, class: 'ds-chart__value', 'text-anchor': 'middle' }, escapeHtml(fmt(totals[c])));
|
|
259
|
+
if (c % step === 0) {
|
|
260
|
+
svg += tag('text', { x: bx + band / 2, y: top + plotH + 20, class: 'ds-chart__tick', 'text-anchor': 'middle' }, escapeHtml(fitText(cat, band * step - 6, FONTS.tick)));
|
|
261
|
+
}
|
|
262
|
+
marks.push({ c, x: bx + band / 2, y: topY, band: [bx + 2, top - valueSpace - 6, band - 4, plotH + valueSpace + 6] });
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
geo = { horizontal: false, band, left, top, plotH, n, marks };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
frame.plot.innerHTML = `<svg class="ds-chart__svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" aria-hidden="true">${defs}${svg}</svg>`;
|
|
269
|
+
|
|
270
|
+
// Tabela: os números de verdade, mesmo os que o gráfico não rotula.
|
|
271
|
+
const raw = formatter(o.format);
|
|
272
|
+
const cols = [{ label: o.categoryLabel ?? msg('chart.category') }, ...o.series.map((s) => ({ label: s.name ?? msg('chart.value'), num: true }))];
|
|
273
|
+
if (isStack() && o.series.length > 1) cols.push({ label: msg('chart.total'), num: true });
|
|
274
|
+
frame.setTable({
|
|
275
|
+
columns: cols,
|
|
276
|
+
rows: o.categories.map((cat, c) => {
|
|
277
|
+
const vals = o.series.map((s) => s.values[c]);
|
|
278
|
+
const row = [cat, ...vals.map((v) => (v == null ? '—' : raw(v)))];
|
|
279
|
+
if (isStack() && o.series.length > 1) row.push(raw(vals.reduce((a, v) => a + (v ?? 0), 0)));
|
|
280
|
+
return row;
|
|
281
|
+
}),
|
|
282
|
+
});
|
|
283
|
+
frame.refresh();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
frame.interact({
|
|
287
|
+
count: () => (geo ? geo.n : 0),
|
|
288
|
+
hit(px, py) {
|
|
289
|
+
if (!geo) return null;
|
|
290
|
+
if (geo.horizontal) {
|
|
291
|
+
const c = Math.floor((py - geo.top) / geo.rowH);
|
|
292
|
+
return c >= 0 && c < geo.n ? c : null;
|
|
293
|
+
}
|
|
294
|
+
if (px < geo.left) return null;
|
|
295
|
+
const c = Math.floor((px - geo.left) / geo.band);
|
|
296
|
+
return c >= 0 && c < geo.n ? c : null;
|
|
297
|
+
},
|
|
298
|
+
anchor: (c) => geo.marks[c],
|
|
299
|
+
highlight(c) {
|
|
300
|
+
const svg = frame.plot.querySelector('svg');
|
|
301
|
+
if (!svg) return;
|
|
302
|
+
const band = svg.querySelector('[data-band]');
|
|
303
|
+
svg.querySelectorAll('[data-active]').forEach((el) => el.removeAttribute('data-active'));
|
|
304
|
+
if (c == null || !geo) {
|
|
305
|
+
band.setAttribute('width', 0);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const [bx, by, bw, bh] = geo.marks[c].band;
|
|
309
|
+
band.setAttribute('x', bx);
|
|
310
|
+
band.setAttribute('y', by);
|
|
311
|
+
band.setAttribute('width', bw);
|
|
312
|
+
band.setAttribute('height', bh);
|
|
313
|
+
svg.querySelectorAll(`[data-c="${c}"]`).forEach((el) => el.setAttribute('data-active', ''));
|
|
314
|
+
},
|
|
315
|
+
describe(c) {
|
|
316
|
+
const vs = visible();
|
|
317
|
+
const raw = formatter(o.format);
|
|
318
|
+
const pct = formatter('percent');
|
|
319
|
+
const vals = vs.map((s) => s.values[c]);
|
|
320
|
+
const total = vals.reduce((a, v) => a + Math.max(0, v ?? 0), 0);
|
|
321
|
+
const rows = vs.map((s, j) => {
|
|
322
|
+
const v = vals[j];
|
|
323
|
+
let value = v == null ? '—' : raw(v);
|
|
324
|
+
if (o.layout === 'percent' && v != null && total) value = `${pct(Math.max(0, v) / total)} · ${raw(v)}`;
|
|
325
|
+
return { color: color(s, c, v ?? 0), mark: 'rect', value, name: s.name ?? '' };
|
|
326
|
+
});
|
|
327
|
+
let note;
|
|
328
|
+
if (isStack() && vs.length > 1) note = `Total: ${raw(total)}`;
|
|
329
|
+
if (o.ordinal && c > 0) {
|
|
330
|
+
const prev = vs[0].values[c - 1];
|
|
331
|
+
const cur = vs[0].values[c];
|
|
332
|
+
if (prev && cur != null) note = msg('chart.ofPrevious', pct(cur / prev));
|
|
333
|
+
}
|
|
334
|
+
return { title: o.tooltipLabels?.[c] ?? o.categories[c], rows, note };
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
function summary() {
|
|
339
|
+
return msg('chart.summaryBar', o.title ?? o.label ?? msg('chart.chart'), o.orientation === 'horizontal', o.layout, o.categories.length, o.series.length);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
frame.setLabel(summary());
|
|
343
|
+
frame.onResize(render);
|
|
344
|
+
legend();
|
|
345
|
+
render();
|
|
346
|
+
|
|
347
|
+
return {
|
|
348
|
+
el: frame.figure,
|
|
349
|
+
update(next) {
|
|
350
|
+
source = { ...source, ...next };
|
|
351
|
+
o = normalize(source);
|
|
352
|
+
[...hidden].forEach((i) => i >= o.series.length && hidden.delete(i));
|
|
353
|
+
frame.setHead(o);
|
|
354
|
+
frame.setLabel(summary());
|
|
355
|
+
legend();
|
|
356
|
+
render();
|
|
357
|
+
},
|
|
358
|
+
setLoading: frame.setLoading,
|
|
359
|
+
destroy: frame.destroy,
|
|
360
|
+
};
|
|
361
|
+
}
|