@bk2k/ui 0.6.7 → 0.6.8
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/BUILDING.md +32 -0
- package/CHANGELOG.md +57 -0
- package/USAGE.md +14 -8
- package/custom-elements.json +1 -1
- package/dist/charts/frame.d.ts +2 -0
- package/dist/charts/frame.js +2 -1
- package/dist/components/bk-button.d.ts +18 -3
- package/dist/components/bk-button.js +19 -8
- package/dist/components/bk-chart-bar.d.ts +46 -9
- package/dist/components/bk-chart-bar.js +127 -37
- package/dist/components/bk-combobox.d.ts +29 -5
- package/dist/components/bk-combobox.js +61 -19
- package/dist/components/bk-dialog.d.ts +4 -1
- package/dist/components/bk-dialog.js +6 -2
- package/dist/components/bk-facts-item.js +8 -6
- package/dist/components/bk-facts.d.ts +6 -4
- package/dist/components/bk-facts.js +19 -8
- package/dist/components/bk-input-time-zone.d.ts +3 -0
- package/dist/components/bk-model-viewer.d.ts +12 -1
- package/dist/components/bk-model-viewer.js +15 -2
- package/dist/components/bk-period-nav.d.ts +102 -0
- package/dist/components/bk-period-nav.js +69 -0
- package/dist/components/bk-select.js +2 -1
- package/dist/components/bk-shell-app.d.ts +3 -2
- package/dist/components/bk-shell-app.js +16 -3
- package/dist/components/bk-sortable.d.ts +3 -0
- package/dist/components/bk-sortable.js +3 -0
- package/dist/components/bk-split.d.ts +3 -0
- package/dist/components/bk-split.js +3 -0
- package/dist/components/bk-table.d.ts +16 -12
- package/dist/components/bk-table.js +96 -14
- package/dist/i18n/de.js +7 -0
- package/dist/i18n.d.ts +7 -0
- package/dist/i18n.js +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/cloak.d.ts +3 -0
- package/dist/internal/cloak.js +4 -0
- package/dist/internal/handle-menu.d.ts +2 -3
- package/dist/internal/handle-menu.js +14 -3
- package/dist/internal/late.d.ts +15 -0
- package/dist/internal/late.js +30 -0
- package/dist/jsx.d.ts +36 -5
- package/dist/standalone/all.js +119 -118
- package/dist/standalone/bk-action-bar.js +1 -1
- package/dist/standalone/bk-alert-offline.js +1 -1
- package/dist/standalone/bk-alert.js +1 -1
- package/dist/standalone/bk-attachment.js +1 -1
- package/dist/standalone/bk-avatar-group.js +1 -1
- package/dist/standalone/bk-avatar.js +1 -1
- package/dist/standalone/bk-breadcrumbs.js +1 -1
- package/dist/standalone/bk-button-copy.js +2 -2
- package/dist/standalone/bk-button-group.js +2 -2
- package/dist/standalone/bk-button-share.js +2 -2
- package/dist/standalone/bk-button-top.js +1 -1
- package/dist/standalone/bk-button.js +15 -7
- package/dist/standalone/bk-calendar-week.js +1 -1
- package/dist/standalone/bk-calendar.js +1 -1
- package/dist/standalone/bk-card.js +1 -1
- package/dist/standalone/bk-carousel-controls.js +2 -2
- package/dist/standalone/bk-carousel.js +1 -1
- package/dist/standalone/bk-chart-bar-list.js +3 -3
- package/dist/standalone/bk-chart-bar.js +164 -105
- package/dist/standalone/bk-chart-bridge.js +4 -4
- package/dist/standalone/bk-chart-bullet.js +3 -3
- package/dist/standalone/bk-chart-calendar.js +4 -4
- package/dist/standalone/bk-chart-heatmap.js +4 -4
- package/dist/standalone/bk-chart-histogram.js +2 -2
- package/dist/standalone/bk-chart-legend.js +3 -3
- package/dist/standalone/bk-chart-line.js +5 -5
- package/dist/standalone/bk-chart-scatter.js +3 -3
- package/dist/standalone/bk-chart-sparkline.js +3 -3
- package/dist/standalone/bk-chart-stacked-bar.js +4 -4
- package/dist/standalone/bk-chart-tracker.js +3 -3
- package/dist/standalone/bk-chart-waterfall.js +2 -2
- package/dist/standalone/bk-checkbox-group.js +2 -2
- package/dist/standalone/bk-checkbox.js +1 -1
- package/dist/standalone/bk-chip-group.js +2 -2
- package/dist/standalone/bk-chip.js +2 -2
- package/dist/standalone/bk-code-diff.js +1 -1
- package/dist/standalone/bk-code-stack.js +2 -2
- package/dist/standalone/bk-code.js +2 -2
- package/dist/standalone/bk-color-panel.js +2 -2
- package/dist/standalone/bk-columns.js +1 -1
- package/dist/standalone/bk-combobox.js +49 -30
- package/dist/standalone/bk-command-menu.js +2 -2
- package/dist/standalone/bk-command-palette.js +3 -3
- package/dist/standalone/bk-composer.js +2 -2
- package/dist/standalone/bk-delta.js +1 -1
- package/dist/standalone/bk-diagram.js +1 -1
- package/dist/standalone/bk-dialog.js +1 -1
- package/dist/standalone/bk-drawer.js +2 -2
- package/dist/standalone/bk-error-summary.js +1 -1
- package/dist/standalone/bk-facts-item.js +8 -6
- package/dist/standalone/bk-facts.js +19 -8
- package/dist/standalone/bk-fieldset.js +1 -1
- package/dist/standalone/bk-filter-bar.js +1 -1
- package/dist/standalone/bk-folder-browser.js +1 -1
- package/dist/standalone/bk-form-guard.js +1 -1
- package/dist/standalone/bk-form-steps.js +1 -1
- package/dist/standalone/bk-image-compare.js +1 -1
- package/dist/standalone/bk-image-crop.js +2 -2
- package/dist/standalone/bk-image-editor.js +2 -1
- package/dist/standalone/bk-image-viewer.js +1 -1
- package/dist/standalone/bk-input-code.js +2 -2
- package/dist/standalone/bk-input-color.js +1 -1
- package/dist/standalone/bk-input-date-range.js +2 -2
- package/dist/standalone/bk-input-date.js +1 -1
- package/dist/standalone/bk-input-file.js +2 -2
- package/dist/standalone/bk-input-group.js +2 -2
- package/dist/standalone/bk-input-inline.js +2 -2
- package/dist/standalone/bk-input-number.js +2 -2
- package/dist/standalone/bk-input-rating.js +2 -2
- package/dist/standalone/bk-input-rich.js +1 -1
- package/dist/standalone/bk-input-search.js +1 -1
- package/dist/standalone/bk-input-slider-range.js +2 -2
- package/dist/standalone/bk-input-slider.js +2 -2
- package/dist/standalone/bk-input-text.js +1 -1
- package/dist/standalone/bk-input-time.js +3 -3
- package/dist/standalone/bk-item.js +1 -1
- package/dist/standalone/bk-kbd-shortcuts.js +1 -1
- package/dist/standalone/bk-kbd.js +1 -1
- package/dist/standalone/bk-lightbox.js +2 -2
- package/dist/standalone/bk-listbox-columns.js +2 -2
- package/dist/standalone/bk-listbox-search.js +3 -3
- package/dist/standalone/bk-listbox-transfer.js +3 -3
- package/dist/standalone/bk-listbox.js +2 -2
- package/dist/standalone/bk-logo.js +1 -1
- package/dist/standalone/bk-menu-bar.js +1 -1
- package/dist/standalone/bk-menu-item.js +1 -1
- package/dist/standalone/bk-menu-list.js +1 -1
- package/dist/standalone/bk-menu.js +2 -2
- package/dist/standalone/bk-message-approval.js +1 -1
- package/dist/standalone/bk-message-branches.js +1 -1
- package/dist/standalone/bk-message-citation.js +1 -1
- package/dist/standalone/bk-message-feedback.js +1 -1
- package/dist/standalone/bk-message-list.js +1 -1
- package/dist/standalone/bk-message-reasoning.js +1 -1
- package/dist/standalone/bk-message-source.js +1 -1
- package/dist/standalone/bk-message-tool-group.js +1 -1
- package/dist/standalone/bk-message-tool.js +1 -1
- package/dist/standalone/bk-message.js +1 -1
- package/dist/standalone/bk-meter.js +1 -1
- package/dist/standalone/bk-model-viewer.js +1 -1
- package/dist/standalone/bk-nav-group.js +1 -1
- package/dist/standalone/bk-nav-item.js +1 -1
- package/dist/standalone/bk-nav-toc.js +1 -1
- package/dist/standalone/bk-nav.js +1 -1
- package/dist/standalone/bk-overflow.js +1 -1
- package/dist/standalone/bk-page-footer.js +1 -1
- package/dist/standalone/bk-page-pager.js +1 -1
- package/dist/standalone/bk-pagination.js +1 -1
- package/dist/standalone/bk-pane.js +1 -1
- package/dist/standalone/bk-panel.js +1 -1
- package/dist/standalone/bk-period-nav.js +69 -0
- package/dist/standalone/bk-picture.js +1 -1
- package/dist/standalone/bk-popover-help.js +1 -1
- package/dist/standalone/bk-popover.js +1 -1
- package/dist/standalone/bk-preview.js +1 -1
- package/dist/standalone/bk-progress.js +1 -1
- package/dist/standalone/bk-qr-code.js +1 -1
- package/dist/standalone/bk-radio-group.js +2 -2
- package/dist/standalone/bk-radio.js +1 -1
- package/dist/standalone/bk-rating.js +1 -1
- package/dist/standalone/bk-scroll.js +1 -1
- package/dist/standalone/bk-segmented.js +2 -2
- package/dist/standalone/bk-select-cascade.js +1 -1
- package/dist/standalone/bk-select-tree.js +1 -1
- package/dist/standalone/bk-select.js +3 -2
- package/dist/standalone/bk-shell-app.js +42 -38
- package/dist/standalone/bk-shell-sites.js +1 -1
- package/dist/standalone/bk-sortable.js +7 -4
- package/dist/standalone/bk-split-grid.js +1 -1
- package/dist/standalone/bk-split.js +7 -4
- package/dist/standalone/bk-stat.js +2 -2
- package/dist/standalone/bk-steps-item.js +1 -1
- package/dist/standalone/bk-swatch-group.js +2 -2
- package/dist/standalone/bk-switch.js +2 -2
- package/dist/standalone/bk-table.js +130 -80
- package/dist/standalone/bk-tabs-item.js +1 -1
- package/dist/standalone/bk-tabs.js +1 -1
- package/dist/standalone/bk-tasks-item.js +1 -1
- package/dist/standalone/bk-text.js +1 -1
- package/dist/standalone/bk-time-countdown.js +1 -1
- package/dist/standalone/bk-time-relative.js +1 -1
- package/dist/standalone/bk-timeline-item.js +1 -1
- package/dist/standalone/bk-toast-group.js +1 -1
- package/dist/standalone/bk-toast.js +1 -1
- package/dist/standalone/bk-tooltip.js +1 -1
- package/dist/standalone/bk-tree-item.js +2 -2
- package/dist/standalone/bk-video.js +1 -1
- package/dist/standalone/bk-zoom.js +3 -3
- package/dist/standalone/chunks/{bk-alert-offline-BoMEYxnE.js → bk-alert-offline-B1bQxOZp.js} +1 -1
- package/dist/standalone/chunks/{bk-carousel-B7-9OanA.js → bk-carousel-BCwIQhG5.js} +1 -1
- package/dist/standalone/chunks/{bk-diagram-CpOpicmo.js → bk-diagram-DWK8CvRZ.js} +2 -2
- package/dist/standalone/chunks/{bk-dialog-a2BtUBf2.js → bk-dialog-DX0cPJ1o.js} +7 -3
- package/dist/standalone/chunks/{bk-image-editor-z_Uj83fy.js → bk-image-editor-DXEj9gCu.js} +1 -1
- package/dist/standalone/chunks/{bk-input-date-range-BQkbPlSJ.js → bk-input-date-range-Cbx_lpf0.js} +1 -1
- package/dist/standalone/chunks/{bk-input-rich-Dte_b4Ev.js → bk-input-rich-ZB68vziu.js} +3 -3
- package/dist/standalone/chunks/{bk-input-text-CUNQG1ah.js → bk-input-text-DD32uWNO.js} +1 -1
- package/dist/standalone/chunks/{bk-kbd-B7bz8hmV.js → bk-kbd-B_TlKzWj.js} +1 -1
- package/dist/standalone/chunks/{bk-model-viewer-D1XJPgAG.js → bk-model-viewer-Dr81ahVv.js} +19 -5
- package/dist/standalone/chunks/{bk-qr-code-CbI9rdOK.js → bk-qr-code-QaYvZwOR.js} +1 -1
- package/dist/standalone/chunks/{bk-toast-group-Cix-Urgi.js → bk-toast-group-BSeO_rPs.js} +1 -1
- package/dist/standalone/chunks/{choice-field-BnuK9mp_.js → choice-field-CGvE4tyb.js} +1 -1
- package/dist/standalone/chunks/{clipboard-DBGdJ-1S.js → clipboard-BKlrP5rj.js} +1 -28
- package/dist/standalone/chunks/clipboard-Crzt1Sh9.js +29 -0
- package/dist/standalone/chunks/{date-field-BQ5k-DDL.js → date-field-BlI6grfT.js} +2 -2
- package/dist/standalone/chunks/{form-control-D7dqSP9M.js → form-control-CyXQIJ2x.js} +1 -1
- package/dist/standalone/chunks/{frame-BW1nKuoM.js → frame-abXBnl8a.js} +3 -1
- package/dist/standalone/chunks/handle-menu-ZVR_msk2.js +49 -0
- package/dist/standalone/chunks/{i18n-CNsBRNPu.js → i18n-B6Al9xCK.js} +7 -0
- package/dist/standalone/chunks/{i18n-CrZgrRu9.js → i18n-BI16HQmm.js} +1 -1
- package/dist/standalone/chunks/{marks-CdqbbJpM.js → marks-0kbeB4n8.js} +2 -2
- package/dist/standalone/chunks/{popover-base-oDhxsYMr.js → popover-base-ac49G87f.js} +1 -1
- package/dist/standalone/chunks/{ramp-EclrETaQ.js → ramp-ggoyjMvC.js} +1 -1
- package/dist/standalone/chunks/{summary-BwL-Gp8w.js → summary-BK-B4m5A.js} +1 -1
- package/dist/standalone/chunks/{text-field-CTp2b-Ai.js → text-field-4IUUpRHE.js} +2 -2
- package/dist/standalone/chunks/{toggle-control-DXkgmz7R.js → toggle-control-ioV2jhNY.js} +1 -1
- package/dist/standalone/confirm.js +3 -3
- package/dist/standalone/i18n-de.js +8 -1
- package/dist/standalone/toast.js +1 -1
- package/dist/standalone/tokens.css +4 -1
- package/dist/tokens.css +4 -1
- package/package.json +1 -1
- package/dist/standalone/chunks/handle-menu-DsxWvv4D.js +0 -22
package/dist/charts/frame.d.ts
CHANGED
|
@@ -61,6 +61,8 @@ export interface MarkSpecs {
|
|
|
61
61
|
labelSize: number;
|
|
62
62
|
/** Clearance of labels from lines, bars and each other (--bk-space-1). */
|
|
63
63
|
clear: number;
|
|
64
|
+
/** Thickness of the mark of a chosen category (--bk-chart-indicator-width, default --bk-indicator-width). */
|
|
65
|
+
indicator: number;
|
|
64
66
|
font: string;
|
|
65
67
|
}
|
|
66
68
|
/**
|
package/dist/charts/frame.js
CHANGED
|
@@ -3,7 +3,7 @@ import { styleMap } from "../internal/style-map.js";
|
|
|
3
3
|
import { srOnly, interactive, headingType } from "../internal/styles.js";
|
|
4
4
|
import { chartT } from "./i18n.js";
|
|
5
5
|
import { CHART_SLOTS, slotColor } from "./chart-tokens.js";
|
|
6
|
-
const DEFAULT_SPECS = { barMax: 24, radius: 4, gap: 2, lineWidth: 2, marker: 8, ring: 2, hitMin: 24, bubbleMax: 40, labelSize: 12, clear: 4, font: "system-ui, sans-serif" };
|
|
6
|
+
const DEFAULT_SPECS = { barMax: 24, radius: 4, gap: 2, lineWidth: 2, marker: 8, ring: 2, hitMin: 24, bubbleMax: 40, labelSize: 12, clear: 4, indicator: 2, font: "system-ui, sans-serif" };
|
|
7
7
|
function seriesColor(s, i, count = 2) {
|
|
8
8
|
if (s.color)
|
|
9
9
|
return s.color;
|
|
@@ -186,6 +186,7 @@ class ChartController {
|
|
|
186
186
|
bubbleMax: px("--bk-chart-bubble-max", 40),
|
|
187
187
|
labelSize: px("--bk-chart-label-size", 12) || parseFloat(cs.fontSize) * 0.85,
|
|
188
188
|
clear: px("--bk-space-1", 4),
|
|
189
|
+
indicator: Math.max(1, px("--bk-chart-indicator-width", px("--bk-indicator-width", 2))),
|
|
189
190
|
font: cs.fontFamily || DEFAULT_SPECS.font
|
|
190
191
|
};
|
|
191
192
|
probe.remove();
|
|
@@ -46,10 +46,13 @@ export type ButtonSize = "sm" | "md" | "lg";
|
|
|
46
46
|
* - `collapse` shows only the icon when the nearest size container is narrow. Set
|
|
47
47
|
* `container-type: inline-size` on a toolbar or header, and the button collapses below 640px of its width
|
|
48
48
|
* (`collapse="sm"`: 480px, `collapse="lg"`: 960px). The label stays the accessible name and
|
|
49
|
-
* becomes the tooltip. The button needs an icon, and `collapse` has no effect without a container ancestor.
|
|
49
|
+
* becomes the tooltip. The button needs an icon, and `collapse` has no effect without a container ancestor. The
|
|
50
|
+
* start icon stays. A button with only an end icon (`icon-end`) keeps the end icon.
|
|
50
51
|
*
|
|
51
52
|
* The element passes `aria-current` on the host (a page in a pager, the current step) to the inner control and
|
|
52
|
-
* sets the `pressed` look on the button.
|
|
53
|
+
* sets the `pressed` look on the button. It also passes `aria-expanded` and `aria-controls` on the host (a
|
|
54
|
+
* disclosure button of the app) to the inner control. `pressed` sets `aria-pressed`. A popover, a menu or a tooltip
|
|
55
|
+
* that controls the button (setTriggerAria) replaces `aria-expanded` and `aria-controls` while it is attached.
|
|
53
56
|
*
|
|
54
57
|
* `disabled-reason` turns the button off and says why ("A group has at most 4 items"). Unlike
|
|
55
58
|
* `disabled`, the button stays focusable (`aria-disabled`), so keyboard and screen reader users can
|
|
@@ -122,7 +125,7 @@ export type ButtonSize = "sm" | "md" | "lg";
|
|
|
122
125
|
*
|
|
123
126
|
* @keyboard Enter, Space - Activate the button (a link button: Enter follows the link).
|
|
124
127
|
* @keyboard Tab - Move focus to the button, also when it is disabled with a `disabled-reason`.
|
|
125
|
-
* @a11y A native `<button>` (or `<a>` with `href`) inside. An icon-only button uses `label` as its accessible name. A disabled button with `disabled-reason` stays focusable (`aria-disabled`) and has the reason as its description. `aria
|
|
128
|
+
* @a11y A native `<button>` (or `<a>` with `href`) inside. An icon-only button uses `label` as its accessible name. A disabled button with `disabled-reason` stays focusable (`aria-disabled`) and has the reason as its description. The inner control gets `aria-current`, `aria-expanded` and `aria-controls` of the host, and `aria-pressed` from `pressed`.
|
|
126
129
|
* @fires {CustomEvent<NavigateDetail>} navigate - The user makes a plain click on the link (primary button, no modifier key, no other `target`, no `download`). `detail.href` is the resolved address. Bubbles, composed, cancelable: `preventDefault()` stops the browser, and the router of the app handles the navigation.
|
|
127
130
|
* @tag bk-button
|
|
128
131
|
*/
|
|
@@ -202,6 +205,12 @@ export declare class BkButton extends LitElement implements AriaForwarding {
|
|
|
202
205
|
current: {
|
|
203
206
|
attribute: string;
|
|
204
207
|
};
|
|
208
|
+
hostExpanded: {
|
|
209
|
+
attribute: string;
|
|
210
|
+
};
|
|
211
|
+
hostControls: {
|
|
212
|
+
attribute: string;
|
|
213
|
+
};
|
|
205
214
|
count: {
|
|
206
215
|
type: NumberConstructor;
|
|
207
216
|
};
|
|
@@ -273,6 +282,10 @@ export declare class BkButton extends LitElement implements AriaForwarding {
|
|
|
273
282
|
* pager or the current step; a toggle uses `pressed`.
|
|
274
283
|
*/
|
|
275
284
|
current: string | undefined;
|
|
285
|
+
/** `aria-expanded` on the host (a disclosure button of the app). A popup that controls the button (setTriggerAria) wins. */
|
|
286
|
+
hostExpanded: string | undefined;
|
|
287
|
+
/** `aria-controls` on the host: the ids of elements in the same document or shadow root as the button. */
|
|
288
|
+
hostControls: string | undefined;
|
|
276
289
|
/** Count badge on an icon-only button (unread items); `99+` above 99, none for 0 or unset. */
|
|
277
290
|
count: number | undefined;
|
|
278
291
|
/** A dot on an icon-only button: something new, without a number. */
|
|
@@ -295,6 +308,8 @@ export declare class BkButton extends LitElement implements AriaForwarding {
|
|
|
295
308
|
get inactive(): boolean;
|
|
296
309
|
/** Trigger ARIA set by popovers, menus and tooltips; rendered onto the inner control. */
|
|
297
310
|
private forwarded;
|
|
311
|
+
/** The elements of the ids in `aria-controls` on the host, in the root of the button (the inner control cannot refer to them by id). */
|
|
312
|
+
private hostControlled;
|
|
298
313
|
/** Used by `<bk-popover>`, `<bk-menu>` and `<bk-tooltip>` (see setTriggerAria). */
|
|
299
314
|
forwardAria(aria: TriggerAria): void;
|
|
300
315
|
static styles: import("lit").CSSResult[];
|
|
@@ -46,6 +46,8 @@ class BkButton extends LitElement {
|
|
|
46
46
|
floating: { type: Boolean, reflect: true },
|
|
47
47
|
collapse: { reflect: true },
|
|
48
48
|
current: { attribute: "aria-current" },
|
|
49
|
+
hostExpanded: { attribute: "aria-expanded" },
|
|
50
|
+
hostControls: { attribute: "aria-controls" },
|
|
49
51
|
count: { type: Number },
|
|
50
52
|
dot: { type: Boolean, reflect: true }
|
|
51
53
|
};
|
|
@@ -130,6 +132,14 @@ class BkButton extends LitElement {
|
|
|
130
132
|
}
|
|
131
133
|
/** Trigger ARIA set by popovers, menus and tooltips; rendered onto the inner control. */
|
|
132
134
|
forwarded = { haspopup: null, expanded: null, controls: null, description: null, hideTitle: false };
|
|
135
|
+
/** The elements of the ids in `aria-controls` on the host, in the root of the button (the inner control cannot refer to them by id). */
|
|
136
|
+
hostControlled() {
|
|
137
|
+
if (!this.hostControls || !this.isConnected)
|
|
138
|
+
return null;
|
|
139
|
+
const root = this.getRootNode();
|
|
140
|
+
const found = this.hostControls.split(/\s+/).map((id) => root.getElementById?.(id)).filter((el) => !!el);
|
|
141
|
+
return found.length ? found : null;
|
|
142
|
+
}
|
|
133
143
|
/** Used by `<bk-popover>`, `<bk-menu>` and `<bk-tooltip>` (see setTriggerAria). */
|
|
134
144
|
forwardAria(aria) {
|
|
135
145
|
const f = this.forwarded;
|
|
@@ -332,18 +342,19 @@ class BkButton extends LitElement {
|
|
|
332
342
|
@media (forced-colors: active) { .count, .dot { border: var(--bk-border-width) solid CanvasText; } .dot { background: Highlight; } }
|
|
333
343
|
:host(:state(round)) .control { border-radius: var(--bk-radius-full); }
|
|
334
344
|
|
|
335
|
-
/* collapse: icon only when the nearest size container is narrow (thresholds can't be tokens)
|
|
345
|
+
/* collapse: icon only when the nearest size container is narrow (thresholds can't be tokens). The start icon stays;
|
|
346
|
+
a button with only an end icon keeps the end icon. */
|
|
336
347
|
@container (max-width: 480px) {
|
|
337
348
|
:host([collapse="sm"]) .control { padding: 0; width: var(--_bk-button-h); }
|
|
338
|
-
:host([collapse="sm"]) :is(.label, slot[name="end"]) { display: none; }
|
|
349
|
+
:host([collapse="sm"]) :is(.label, .has-start slot[name="end"]) { display: none; }
|
|
339
350
|
}
|
|
340
351
|
@container (max-width: 640px) {
|
|
341
352
|
:host([collapse=""]) .control, :host([collapse="md"]) .control { padding: 0; width: var(--_bk-button-h); }
|
|
342
|
-
:host([collapse=""]) :is(.label, slot[name="end"]), :host([collapse="md"]) :is(.label, slot[name="end"]) { display: none; }
|
|
353
|
+
:host([collapse=""]) :is(.label, .has-start slot[name="end"]), :host([collapse="md"]) :is(.label, .has-start slot[name="end"]) { display: none; }
|
|
343
354
|
}
|
|
344
355
|
@container (max-width: 960px) {
|
|
345
356
|
:host([collapse="lg"]) .control { padding: 0; width: var(--_bk-button-h); }
|
|
346
|
-
:host([collapse="lg"]) :is(.label, slot[name="end"]) { display: none; }
|
|
357
|
+
:host([collapse="lg"]) :is(.label, .has-start slot[name="end"]) { display: none; }
|
|
347
358
|
}
|
|
348
359
|
`];
|
|
349
360
|
/** Whether `collapse` is set (a container query can hide the text). */
|
|
@@ -356,8 +367,8 @@ class BkButton extends LitElement {
|
|
|
356
367
|
super.connectedCallback();
|
|
357
368
|
const root = this.getRootNode();
|
|
358
369
|
this.inOverlay = !!this.closest("dialog, bk-dialog, bk-drawer, [popover]") || root instanceof ShadowRoot && !!root.host.matches("bk-dialog, bk-drawer");
|
|
359
|
-
if (this.collapsible && !this.icon && !this.querySelector(":scope > [slot=start]")) {
|
|
360
|
-
console.warn("<bk-button collapse> needs an icon (icon
|
|
370
|
+
if (this.collapsible && !this.icon && !this.iconEnd && !this.querySelector(":scope > :is([slot=start], [slot=end])")) {
|
|
371
|
+
console.warn("<bk-button collapse> needs an icon (icon, icon-end, or the start or end slot): it is all that stays visible.", this);
|
|
361
372
|
}
|
|
362
373
|
}
|
|
363
374
|
/**
|
|
@@ -429,10 +440,10 @@ class BkButton extends LitElement {
|
|
|
429
440
|
const labelTip = !reason && !f.hideTitle && !this.hideTooltip && !this.inOverlay && this.iconOnly && name ? name : void 0;
|
|
430
441
|
const title = f.hideTitle || this.hideTooltip || reason || labelTip ? void 0 : name;
|
|
431
442
|
const popup = ifDefined(f.haspopup ?? void 0);
|
|
432
|
-
const expanded = ifDefined(f.expanded === null ? void 0 : String(f.expanded));
|
|
443
|
+
const expanded = ifDefined(f.expanded === null ? this.hostExpanded ?? void 0 : String(f.expanded));
|
|
433
444
|
const description = ifDefined(reason ? void 0 : [f.description, this.badgeDescription].filter(Boolean).join(". ") || void 0);
|
|
434
445
|
const current = ifDefined(this.current ?? void 0);
|
|
435
|
-
const controls = controlsList(f.controls);
|
|
446
|
+
const controls = controlsList(f.controls ?? this.hostControlled());
|
|
436
447
|
if (this.href) {
|
|
437
448
|
return this.withReason(reason, name, labelTip, html`<a part="control" class=${cls}
|
|
438
449
|
href=${ifDefined(inactive ? void 0 : this.links.href(this.href))} @click=${this.links.click} target=${ifDefined(this.target)}
|
|
@@ -43,12 +43,20 @@ export interface ChartBarSelectDetail {
|
|
|
43
43
|
* chart describes its data in one line for screen readers (`show-summary` shows it, `summary` replaces it).
|
|
44
44
|
*
|
|
45
45
|
* **Clickable categories.** With `href` (a template such as `?day={x}`), each category is a real `<a>` over its band
|
|
46
|
-
* and its label.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* and its label. The link resolver of the app resolves each address. A template of one field (`href="{url}"`) takes
|
|
47
|
+
* the address of each row as it is. With `clickable`, each category is a button that fires a cancelable `select` with
|
|
48
|
+
* `{ category, index }`. When no listener cancels the event, the category becomes `current`. `current` marks the chosen
|
|
49
|
+
* category. Its bars keep their colour, its label is bold, and a mark (--bk-chart-bar-current-mark) stands under its
|
|
50
|
+
* label. The bars of the other categories use `--bk-chart-bar-rest`.
|
|
51
|
+
*
|
|
52
|
+
* **Missing values.** A value that is null or undefined draws no bar. A short outline at the baseline shows the place
|
|
53
|
+
* of the bar. A category without any value has no link or button, and its name says "no value".
|
|
54
|
+
*
|
|
55
|
+
* **Second label.** `detail` names a field of the row (a date, for example). The chart shows its value under the
|
|
56
|
+
* category label, and the data table shows it in a column.
|
|
49
57
|
*
|
|
50
58
|
* ```html
|
|
51
|
-
* <bk-chart-bar aria-label="Views per day" x="day" href="?day={date}" current="
|
|
59
|
+
* <bk-chart-bar aria-label="Views per day" x="day" detail="date" labels href="?day={date}" current="Wed" .data=${days}></bk-chart-bar>
|
|
52
60
|
* ```
|
|
53
61
|
*
|
|
54
62
|
* This is content without a surface. Put it in a `<bk-surface>` or `<bk-card>`.
|
|
@@ -92,9 +100,13 @@ export interface ChartBarSelectDetail {
|
|
|
92
100
|
* @cssprop --bk-chart-tooltip-max-width - Maximum tooltip width (default --bk-popup-width-md).
|
|
93
101
|
* @cssprop --bk-chart-bar-rest - Colour of the bars of the categories that are not `current` (default --bk-chart-other).
|
|
94
102
|
* @cssprop --bk-chart-bar-current-label - Colour of the label of the `current` category (default --bk-text).
|
|
103
|
+
* @cssprop --bk-chart-bar-current-mark - Colour of the mark under the label of the `current` category (default --bk-accent-solid).
|
|
104
|
+
* @cssprop --bk-chart-indicator-width - Thickness of the mark under the label of the `current` category (default --bk-indicator-width).
|
|
105
|
+
* @cssprop --bk-chart-bar-detail - Colour of the second label (`detail`) under a category (default --bk-chart-label).
|
|
106
|
+
* @cssprop --bk-chart-bar-stub - Colour of the outline that marks a bar without a value (default --bk-chart-axis).
|
|
95
107
|
* @cssprop --bk-chart-category-hover - Background of the link or button of a category under the pointer (default --bk-hover).
|
|
96
108
|
* @cssprop --bk-chart-category-radius - Radius of the link or button of a category (default --bk-radius-sm).
|
|
97
|
-
* @keyboard ←, → - Move to the previous or next category (↑ and ↓ in a horizontal chart).
|
|
109
|
+
* @keyboard ←, → - Move to the previous or next category (↑ and ↓ in a horizontal chart). The chart draws from left to right in every writing direction, and the arrow keys follow the drawing. With `href` or `clickable`, the keys skip a category without a link or button.
|
|
98
110
|
* @keyboard ↑, ↓ - Move between the series of a category (← and → in a horizontal chart).
|
|
99
111
|
* @keyboard Home, End - Move to the first or last category.
|
|
100
112
|
* @keyboard Shift + ←, Shift + → - With `selectable`: extend the range.
|
|
@@ -103,7 +115,7 @@ export interface ChartBarSelectDetail {
|
|
|
103
115
|
* @keyboard Tab - With `href`: move to the link of the next category.
|
|
104
116
|
* @keyboard Enter - With `href`: follow the link. With `clickable`: choose the category.
|
|
105
117
|
* @keyboard Space - With `clickable`: choose the category.
|
|
106
|
-
* @a11y A `figure` that its heading names. The bars are one tab stop of `img` marks. With `href`, the categories are links in the tab order. The category and its values name each link, and `aria-current="page"` marks `current`. With `clickable`, they are buttons in a `toolbar` (one tab stop, arrow keys) with `aria-current="true"`.
|
|
118
|
+
* @a11y A `figure` that its heading names. The bars are one tab stop of `img` marks. With `href`, the categories are links in the tab order. The category, its second label and its values name each link, and `aria-current="page"` marks `current`. With `clickable`, they are buttons in a `toolbar` (one tab stop, arrow keys) with `aria-current="true"`. A category without a value is an `img` that is not in the tab order; its name says "no value". The mark of `current` has a contrast of at least 3:1 and uses `Highlight` in forced colours.
|
|
107
119
|
*/
|
|
108
120
|
export declare class BkChartBar extends LitElement {
|
|
109
121
|
static properties: {
|
|
@@ -117,6 +129,10 @@ export declare class BkChartBar extends LitElement {
|
|
|
117
129
|
xLabel: {
|
|
118
130
|
attribute: string;
|
|
119
131
|
};
|
|
132
|
+
detail: {};
|
|
133
|
+
detailLabel: {
|
|
134
|
+
attribute: string;
|
|
135
|
+
};
|
|
120
136
|
orientation: {
|
|
121
137
|
reflect: boolean;
|
|
122
138
|
useDefault: boolean;
|
|
@@ -197,6 +213,10 @@ export declare class BkChartBar extends LitElement {
|
|
|
197
213
|
x: string;
|
|
198
214
|
/** Column header of the categories in the data table (default "Category"). */
|
|
199
215
|
xLabel: string | undefined;
|
|
216
|
+
/** Field of a row that contains a second label. The chart shows it under the category label (a date, for example). */
|
|
217
|
+
detail: string | undefined;
|
|
218
|
+
/** Column header of the second label in the data table (default "Detail"). */
|
|
219
|
+
detailLabel: string | undefined;
|
|
200
220
|
/** `vertical` columns (default) or `horizontal` bars (for long or many category names). */
|
|
201
221
|
orientation: "vertical" | "horizontal";
|
|
202
222
|
/** `grouped` side by side (default), `stacked`, or `percent` (stacked to 100 %). */
|
|
@@ -218,7 +238,9 @@ export declare class BkChartBar extends LitElement {
|
|
|
218
238
|
selectable: boolean;
|
|
219
239
|
/**
|
|
220
240
|
* Makes each category a link. The template can contain `{x}` (the category) and `{<field>}` (a field of the row),
|
|
221
|
-
* for example `?day={x}`. The values are URL-encoded.
|
|
241
|
+
* for example `?day={x}`. The values are URL-encoded. A template of one field only (`{url}`) takes the value of the
|
|
242
|
+
* field as it is: each row brings its own address. A category without a value, or without a value for a field of the
|
|
243
|
+
* template, has no link. Not with `selectable`.
|
|
222
244
|
*/
|
|
223
245
|
href: string | undefined;
|
|
224
246
|
/** The `target` of the category links. */
|
|
@@ -271,8 +293,19 @@ export declare class BkChartBar extends LitElement {
|
|
|
271
293
|
/** The value of a category in `current`, `select` and the `href` template (a date as its ISO string). */
|
|
272
294
|
private rawKey;
|
|
273
295
|
private isCurrent;
|
|
274
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* The `href` of the link of a category: the template with the values of its row. A template of one field takes the
|
|
298
|
+
* value as it is. Null when a field of the template has no value in the row.
|
|
299
|
+
*/
|
|
275
300
|
private categoryHref;
|
|
301
|
+
/** True when no series of the row has a value: the category draws placeholders and has no link or button. */
|
|
302
|
+
private isEmpty;
|
|
303
|
+
/** The second label of a category (the `detail` field), or an empty string. */
|
|
304
|
+
private detailText;
|
|
305
|
+
/** The name of a category in tooltips and accessible names: the category and its second label. */
|
|
306
|
+
private categoryName;
|
|
307
|
+
/** True when the chart reserves room for the mark of a chosen category (links, buttons, or `current`). */
|
|
308
|
+
private get marksCurrent();
|
|
276
309
|
/** Fires `select` for the category `i` of the view. When no listener cancels the event, the category becomes `current`. */
|
|
277
310
|
private choose;
|
|
278
311
|
/** The name of the link or button of a category: the category and its values. */
|
|
@@ -296,7 +329,11 @@ export declare class BkChartBar extends LitElement {
|
|
|
296
329
|
private onMove;
|
|
297
330
|
private onUp;
|
|
298
331
|
private onKey;
|
|
299
|
-
/**
|
|
332
|
+
/**
|
|
333
|
+
* Keys on the links or buttons of the categories: arrow keys, Home and End move the focus; Escape hides the tooltip.
|
|
334
|
+
* The keys skip a category without a link or button. The chart draws from left to right in every writing direction,
|
|
335
|
+
* and the arrow keys follow the drawing.
|
|
336
|
+
*/
|
|
300
337
|
private onCategoryKey;
|
|
301
338
|
private toggleTable;
|
|
302
339
|
private tableModel;
|
|
@@ -23,6 +23,8 @@ class BkChartBar extends LitElement {
|
|
|
23
23
|
series: { attribute: false },
|
|
24
24
|
x: {},
|
|
25
25
|
xLabel: { attribute: "x-label" },
|
|
26
|
+
detail: {},
|
|
27
|
+
detailLabel: { attribute: "detail-label" },
|
|
26
28
|
orientation: { reflect: true, useDefault: true },
|
|
27
29
|
mode: { reflect: true, useDefault: true },
|
|
28
30
|
labels: { type: Boolean, reflect: true },
|
|
@@ -110,15 +112,52 @@ class BkChartBar extends LitElement {
|
|
|
110
112
|
const v = row?.[this.x];
|
|
111
113
|
return this.rawKey(v) === c || v instanceof Date && this.rawKey(v).startsWith(c) || this.category(row) === c;
|
|
112
114
|
}
|
|
113
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* The `href` of the link of a category: the template with the values of its row. A template of one field takes the
|
|
117
|
+
* value as it is. Null when a field of the template has no value in the row.
|
|
118
|
+
*/
|
|
114
119
|
categoryHref(row) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
const template = this.href ?? "";
|
|
121
|
+
const known = (key) => key in row || key === "x";
|
|
122
|
+
const field = (key) => key in row ? row[key] : row[this.x];
|
|
123
|
+
const blank = (v) => v === void 0 || v === null || v === "";
|
|
124
|
+
const whole = /^\{([\w-]+)\}$/.exec(template);
|
|
125
|
+
if (whole && known(whole[1])) {
|
|
126
|
+
const v = field(whole[1]);
|
|
127
|
+
return blank(v) ? null : this.rawKey(v);
|
|
128
|
+
}
|
|
129
|
+
let missing = false;
|
|
130
|
+
const href = template.replace(/\{([\w-]+)\}/g, (m, key) => {
|
|
131
|
+
if (!known(key))
|
|
132
|
+
return m;
|
|
133
|
+
const v = field(key);
|
|
134
|
+
if (blank(v))
|
|
135
|
+
missing = true;
|
|
136
|
+
return encodeURIComponent(this.rawKey(v));
|
|
121
137
|
});
|
|
138
|
+
return missing ? null : href;
|
|
139
|
+
}
|
|
140
|
+
/** True when no series of the row has a value: the category draws placeholders and has no link or button. */
|
|
141
|
+
isEmpty(row) {
|
|
142
|
+
return this.effectiveSeries.every((se) => num(row?.[se.key]) === null);
|
|
143
|
+
}
|
|
144
|
+
/** The second label of a category (the `detail` field), or an empty string. */
|
|
145
|
+
detailText(row) {
|
|
146
|
+
if (!this.detail)
|
|
147
|
+
return "";
|
|
148
|
+
const v = row?.[this.detail];
|
|
149
|
+
if (v instanceof Date)
|
|
150
|
+
return formatTime(this.i18n.locale, v.getTime());
|
|
151
|
+
return v === void 0 || v === null ? "" : String(v);
|
|
152
|
+
}
|
|
153
|
+
/** The name of a category in tooltips and accessible names: the category and its second label. */
|
|
154
|
+
categoryName(row) {
|
|
155
|
+
const category = this.category(row), detail = this.detailText(row);
|
|
156
|
+
return detail ? chartT(this.i18n.locale, "chartCategoryDetail", { category, detail }) : category;
|
|
157
|
+
}
|
|
158
|
+
/** True when the chart reserves room for the mark of a chosen category (links, buttons, or `current`). */
|
|
159
|
+
get marksCurrent() {
|
|
160
|
+
return this.pickMode !== null || this.current !== void 0 && this.current !== null && this.current !== "";
|
|
122
161
|
}
|
|
123
162
|
/** Fires `select` for the category `i` of the view. When no listener cancels the event, the category becomes `current`. */
|
|
124
163
|
choose(i) {
|
|
@@ -149,9 +188,14 @@ class BkChartBar extends LitElement {
|
|
|
149
188
|
}
|
|
150
189
|
.mark.rest { fill: var(--bk-chart-bar-rest, var(--bk-chart-other)); }
|
|
151
190
|
text.current { fill: var(--bk-chart-bar-current-label, var(--bk-text)); font-weight: var(--bk-weight-medium); }
|
|
191
|
+
text.detail { fill: var(--bk-chart-bar-detail, var(--bk-chart-label)); }
|
|
192
|
+
.current-mark { fill: var(--bk-chart-bar-current-mark, var(--bk-accent-solid)); }
|
|
193
|
+
.stub { fill: none; stroke: var(--bk-chart-bar-stub, var(--bk-chart-axis)); stroke-width: 1; }
|
|
152
194
|
@media (forced-colors: active) {
|
|
153
195
|
.ghost { fill: none; stroke: CanvasText; } .selection { fill: Highlight; stroke: Highlight; }
|
|
154
196
|
.mark.rest { fill: GrayText; }
|
|
197
|
+
.current-mark { fill: Highlight; }
|
|
198
|
+
.stub { stroke: GrayText; }
|
|
155
199
|
.cat:hover { outline: var(--bk-border-width) solid Highlight; outline-offset: var(--bk-focus-offset-inset); }
|
|
156
200
|
}
|
|
157
201
|
`, markStyles];
|
|
@@ -227,7 +271,12 @@ class BkChartBar extends LitElement {
|
|
|
227
271
|
}
|
|
228
272
|
const fs = s.labelSize, font = s.font;
|
|
229
273
|
const cats = rows.map((r) => this.category(r));
|
|
230
|
-
const
|
|
274
|
+
const details = rows.map((r) => this.detailText(r));
|
|
275
|
+
const hasDetail = details.some(Boolean);
|
|
276
|
+
const catW = Math.max(0, ...cats.map((c) => measureText(c, fs, font)), ...details.map((d) => measureText(d, fs, font)));
|
|
277
|
+
const empty = rows.map((r) => this.isEmpty(r));
|
|
278
|
+
const lineStep = fs + s.clear;
|
|
279
|
+
const markSpace = this.marksCurrent ? s.clear + s.indicator : 0;
|
|
231
280
|
const groupThick = (band) => {
|
|
232
281
|
if (this.contiguous)
|
|
233
282
|
return { t: Math.max(1, band - s.gap), groupW: Math.max(1, band - s.gap) };
|
|
@@ -242,7 +291,7 @@ class BkChartBar extends LitElement {
|
|
|
242
291
|
if (!horizontal) {
|
|
243
292
|
H = this.chart.height;
|
|
244
293
|
y0 = Math.max(labelPad, fs / 2 + 2);
|
|
245
|
-
y1 = H - (fs + 10 + s.clear);
|
|
294
|
+
y1 = H - (fs + 10 + s.clear + (hasDetail ? lineStep : 0) + markSpace);
|
|
246
295
|
ticks = niceTicks(lo, hi, Math.max(2, Math.round((y1 - y0) / 48)));
|
|
247
296
|
if (percent)
|
|
248
297
|
ticks = niceTicks(0, 1, 4);
|
|
@@ -253,7 +302,8 @@ class BkChartBar extends LitElement {
|
|
|
253
302
|
} else {
|
|
254
303
|
const per = stacked ? 1 : Math.max(1, k);
|
|
255
304
|
const groupW2 = this.contiguous ? s.barMax : per * (s.barMax * (1 + gh) + (gh ? s.gap : 0)) + (per - 1) * s.gap;
|
|
256
|
-
const
|
|
305
|
+
const reach = (hasDetail ? lineStep / 2 + fs / 2 : fs / 2) + markSpace;
|
|
306
|
+
const band = Math.max(groupW2 / 0.7, s.hitMin + 8, Math.ceil(2 * reach + 2 * s.clear));
|
|
257
307
|
x0 = Math.ceil(Math.min(catW, W * 0.35) + 8);
|
|
258
308
|
y0 = 2;
|
|
259
309
|
y1 = y0 + n * band;
|
|
@@ -325,14 +375,18 @@ class BkChartBar extends LitElement {
|
|
|
325
375
|
const hw = stacked ? Math.max(t, Math.min(s.hitMin, bands.width)) : Math.max(t + s.gap, Math.min(s.hitMin, bands.width / Math.max(1, k)));
|
|
326
376
|
const hx = off + t / 2 - hw / 2;
|
|
327
377
|
const [hy, hh] = stacked ? [y - s.gap / 2, Math.max(h + s.gap, 4)] : [y0, y1 - y0];
|
|
328
|
-
bar = { i, j, value: raw, share, path: v === null ? "" : barPath(off, y, t, h, s.radius, end), x: off, y, w: t, h, hx, hy, hw, hh, ax: off + t / 2, ay: negative ? y + h : y };
|
|
378
|
+
bar = { i, j, value: raw, share, path: v === null ? "" : barPath(off, y, t, h, s.radius, end), x: off, y, w: t, h, hx, hy, hw, hh, ax: off + t / 2, ay: negative ? y + h : y, stub: "" };
|
|
329
379
|
} else {
|
|
330
380
|
const x = Math.min(pa, pb), w = Math.abs(pb - pa);
|
|
331
381
|
const end = !outer ? "none" : negative ? "left" : "right";
|
|
332
382
|
const hh = stacked ? Math.max(t, Math.min(s.hitMin, bands.width)) : Math.max(t + s.gap, Math.min(s.hitMin, bands.width / Math.max(1, k)));
|
|
333
383
|
const hy = off + t / 2 - hh / 2;
|
|
334
384
|
const [hx, hw] = stacked ? [x - s.gap / 2, Math.max(w + s.gap, 4)] : [x0, x1 - x0];
|
|
335
|
-
bar = { i, j, value: raw, share, path: v === null ? "" : barPath(x, off, w, t, s.radius, end), x, y: off, w, h: t, hx, hy, hw, hh, ax: negative ? x : x + w, ay: off + t / 2 };
|
|
385
|
+
bar = { i, j, value: raw, share, path: v === null ? "" : barPath(x, off, w, t, s.radius, end), x, y: off, w, h: t, hx, hy, hw, hh, ax: negative ? x : x + w, ay: off + t / 2, stub: "" };
|
|
386
|
+
}
|
|
387
|
+
if (raw === null && (!stacked || empty[i] && j === 0)) {
|
|
388
|
+
const len = Math.max(s.clear, Math.round(t / 2));
|
|
389
|
+
bar.stub = horizontal ? barPath(zero, off, len, t, s.radius, "right") : barPath(off, zero - len, t, len, s.radius, "top");
|
|
336
390
|
}
|
|
337
391
|
bars.push(bar);
|
|
338
392
|
const g = ghostOf(i, j);
|
|
@@ -353,13 +407,13 @@ class BkChartBar extends LitElement {
|
|
|
353
407
|
if (ys.some((y, idx) => idx && y - ys[idx - 1] < fs + 2))
|
|
354
408
|
seriesLabels = [];
|
|
355
409
|
}
|
|
356
|
-
return { H, x0, x1, y0, y1, ticks, fmtTick, valueScale, bands, bars, ghosts, marks, cmp: !!cmpRows, t, zero, cats, values, totals, seriesLabels, horizontal, stacked, percent, series, n, k };
|
|
410
|
+
return { H, x0, x1, y0, y1, ticks, fmtTick, valueScale, bands, bars, ghosts, marks, cmp: !!cmpRows, t, zero, cats, details, hasDetail, empty, lineStep, values, totals, seriesLabels, horizontal, stacked, percent, series, n, k };
|
|
357
411
|
}
|
|
358
412
|
/* ---------------------------------------------------------------- interaction */
|
|
359
413
|
markLabel(b) {
|
|
360
414
|
const se = this.effectiveSeries[b.j];
|
|
361
|
-
const cat = this.
|
|
362
|
-
const value =
|
|
415
|
+
const cat = this.categoryName(this.viewRows[b.i]);
|
|
416
|
+
const value = b.value === null ? chartT(this.i18n.locale, "chartNoValue") : this.mode === "percent" ? `${formatPercent(this.i18n.locale, b.share, 1)} (${this.fmt(b.value)})` : this.fmt(b.value);
|
|
363
417
|
return chartT(this.i18n.locale, "chartMark", { category: cat, series: se?.label ?? "", value });
|
|
364
418
|
}
|
|
365
419
|
tooltipFor(b) {
|
|
@@ -383,7 +437,7 @@ class BkChartBar extends LitElement {
|
|
|
383
437
|
}
|
|
384
438
|
if (this.mode !== "grouped" && series.length > 1)
|
|
385
439
|
rows.push({ label: chartT(locale, "chartTotal"), value: this.fmt(total), color: "", marker: "rect", active: false });
|
|
386
|
-
return { title: this.
|
|
440
|
+
return { title: this.categoryName(row), rows, x: b.ax, y: b.ay };
|
|
387
441
|
}
|
|
388
442
|
enter(b) {
|
|
389
443
|
this.hot = { i: b.i, j: b.j };
|
|
@@ -492,26 +546,31 @@ class BkChartBar extends LitElement {
|
|
|
492
546
|
await this.updateComplete;
|
|
493
547
|
this.renderRoot.querySelector(`.hit[data-i="${i}"][data-j="${j}"]`)?.focus();
|
|
494
548
|
}
|
|
495
|
-
/**
|
|
549
|
+
/**
|
|
550
|
+
* Keys on the links or buttons of the categories: arrow keys, Home and End move the focus; Escape hides the tooltip.
|
|
551
|
+
* The keys skip a category without a link or button. The chart draws from left to right in every writing direction,
|
|
552
|
+
* and the arrow keys follow the drawing.
|
|
553
|
+
*/
|
|
496
554
|
onCategoryKey = async (e) => {
|
|
497
|
-
const
|
|
498
|
-
const
|
|
499
|
-
|
|
555
|
+
const from = e.target.closest("a.cat, button.cat");
|
|
556
|
+
const items = [...this.renderRoot.querySelectorAll("a.cat, button.cat")];
|
|
557
|
+
const at = from ? items.indexOf(from) : -1;
|
|
558
|
+
if (at < 0)
|
|
500
559
|
return;
|
|
501
560
|
const h = this.orientation === "horizontal";
|
|
502
|
-
let
|
|
561
|
+
let to = at;
|
|
503
562
|
switch (e.key) {
|
|
504
563
|
case (h ? "ArrowDown" : "ArrowRight"):
|
|
505
|
-
|
|
564
|
+
to = Math.min(items.length - 1, at + 1);
|
|
506
565
|
break;
|
|
507
566
|
case (h ? "ArrowUp" : "ArrowLeft"):
|
|
508
|
-
|
|
567
|
+
to = Math.max(0, at - 1);
|
|
509
568
|
break;
|
|
510
569
|
case "Home":
|
|
511
|
-
|
|
570
|
+
to = 0;
|
|
512
571
|
break;
|
|
513
572
|
case "End":
|
|
514
|
-
|
|
573
|
+
to = items.length - 1;
|
|
515
574
|
break;
|
|
516
575
|
case "Escape":
|
|
517
576
|
this.chart.hideTooltip();
|
|
@@ -519,6 +578,7 @@ class BkChartBar extends LitElement {
|
|
|
519
578
|
default:
|
|
520
579
|
return;
|
|
521
580
|
}
|
|
581
|
+
const i = Number(items[to].dataset.i);
|
|
522
582
|
e.preventDefault();
|
|
523
583
|
this.active = { i, j: this.active.j };
|
|
524
584
|
this.requestUpdate();
|
|
@@ -537,6 +597,8 @@ class BkChartBar extends LitElement {
|
|
|
537
597
|
const cmp = !!this.compare?.length && this.mode === "grouped" && !this.contiguous;
|
|
538
598
|
const cmpLabel = this.compareLabel || chartT(locale, "chartPrevious");
|
|
539
599
|
const columns = [this.xLabel || chartT(locale, "chartCategory")];
|
|
600
|
+
if (this.detail)
|
|
601
|
+
columns.push(this.detailLabel || chartT(locale, "chartDetail"));
|
|
540
602
|
for (const se of series)
|
|
541
603
|
columns.push(se.label, ...cmp ? [`${se.label} \xB7 ${cmpLabel}`, `${se.label} \xB7 ${chartT(locale, "chartChange")}`] : []);
|
|
542
604
|
if (stacked)
|
|
@@ -544,6 +606,8 @@ class BkChartBar extends LitElement {
|
|
|
544
606
|
const rows = (this.data ?? []).map((r, i) => {
|
|
545
607
|
const vs = series.map((s) => num(r[s.key]));
|
|
546
608
|
const cells = [this.category(r)];
|
|
609
|
+
if (this.detail)
|
|
610
|
+
cells.push(this.detailText(r));
|
|
547
611
|
vs.forEach((v, j) => {
|
|
548
612
|
cells.push(this.fmt(v));
|
|
549
613
|
if (cmp) {
|
|
@@ -581,26 +645,47 @@ class BkChartBar extends LitElement {
|
|
|
581
645
|
const cur = this.viewRows.map((r) => this.isCurrent(r));
|
|
582
646
|
const anyCur = cur.some(Boolean);
|
|
583
647
|
let catLabels;
|
|
648
|
+
const width = (text) => measureText(text, fs, font);
|
|
649
|
+
const currentMark = (cx, w, base2, anchor) => {
|
|
650
|
+
const mw = Math.max(Math.round(w), Math.round(L.t), s.hitMin);
|
|
651
|
+
const x = anchor === "middle" ? Math.round(cx - mw / 2) : Math.round(cx - mw);
|
|
652
|
+
const y = Math.round(base2 + fs * 0.25 + s.clear / 2);
|
|
653
|
+
return svg`<rect class="current-mark" x=${x} y=${y} width=${mw} height=${s.indicator} rx=${s.indicator / 2}></rect>`;
|
|
654
|
+
};
|
|
584
655
|
if (!h) {
|
|
585
|
-
const
|
|
586
|
-
const
|
|
587
|
-
|
|
588
|
-
return Math.min(Math.max(L.bands.center(i), L.x0 + half), L.x1 - half);
|
|
589
|
-
};
|
|
656
|
+
const base1 = L.y1 + fs + 4 + s.clear, base2 = base1 + L.lineStep;
|
|
657
|
+
const maxW = Math.max(...L.cats.map(width), ...L.details.map(width));
|
|
658
|
+
const place = (w, i) => Math.min(Math.max(L.bands.center(i), L.x0 + w / 2), L.x1 - w / 2);
|
|
590
659
|
const pick = (every2) => L.cats.map((c, i) => {
|
|
591
660
|
if (i % every2)
|
|
592
661
|
return null;
|
|
593
662
|
const text = fitText(c, L.bands.width * every2 - 4, fs, font);
|
|
594
|
-
|
|
663
|
+
const detail = L.details[i] ? fitText(L.details[i], L.bands.width * every2 - 4, fs, font) : "";
|
|
664
|
+
const w = Math.max(width(text), width(detail));
|
|
665
|
+
return { text, detail, x: place(w, i), w };
|
|
595
666
|
});
|
|
596
667
|
const clear = (shown2) => shown2.filter((p) => p !== null).every((p, j, all) => j === 0 || p.x - p.w / 2 >= all[j - 1].x + all[j - 1].w / 2 + 4);
|
|
597
668
|
let every = Math.max(1, Math.ceil((maxW + 8) / Math.max(1, L.bands.width)));
|
|
598
669
|
let shown = pick(every);
|
|
599
670
|
while (every < L.cats.length && !clear(shown))
|
|
600
671
|
shown = pick(++every);
|
|
601
|
-
catLabels = shown.map((p, i) =>
|
|
672
|
+
catLabels = shown.map((p, i) => {
|
|
673
|
+
const mark = cur[i] ? currentMark(p?.x ?? L.bands.center(i), Math.min(p?.w ?? 0, L.bands.width), L.hasDetail ? base2 : base1, "middle") : nothing;
|
|
674
|
+
if (!p)
|
|
675
|
+
return svg`${mark}`;
|
|
676
|
+
return svg`<text class=${cur[i] ? "current" : ""} x=${p.x} y=${base1} text-anchor="middle">${p.text}</text>
|
|
677
|
+
${p.detail ? svg`<text class="detail" x=${p.x} y=${base2} text-anchor="middle">${p.detail}</text>` : nothing}${mark}`;
|
|
678
|
+
});
|
|
602
679
|
} else {
|
|
603
|
-
|
|
680
|
+
const room = L.x0 - 8;
|
|
681
|
+
catLabels = L.cats.map((c, i) => {
|
|
682
|
+
const centre = L.bands.center(i);
|
|
683
|
+
const text = fitText(c, room, fs, font), detail = L.details[i] ? fitText(L.details[i], room, fs, font) : "";
|
|
684
|
+
const y1 = L.hasDetail ? centre - L.lineStep / 2 : centre, y2 = centre + L.lineStep / 2;
|
|
685
|
+
const mark = cur[i] ? currentMark(room, Math.max(width(text), width(detail)), (L.hasDetail ? y2 : y1) + fs * 0.32, "end") : nothing;
|
|
686
|
+
return svg`<text class=${cur[i] ? "current" : ""} x=${room} y=${y1} dy="0.32em" text-anchor="end">${text}</text>
|
|
687
|
+
${detail ? svg`<text class="detail" x=${room} y=${y2} dy="0.32em" text-anchor="end">${detail}</text>` : nothing}${mark}`;
|
|
688
|
+
});
|
|
604
689
|
}
|
|
605
690
|
const series = L.series;
|
|
606
691
|
const hot = this.hot;
|
|
@@ -630,6 +715,7 @@ class BkChartBar extends LitElement {
|
|
|
630
715
|
const selection = sel && this.selectable ? h ? svg`<rect class="selection" x=${L.x0} y=${L.bands.start(sel[0])} width=${L.x1 - L.x0} height=${(sel[1] - sel[0] + 1) * L.bands.width}></rect>` : svg`<rect class="selection" x=${L.bands.start(sel[0])} y=${L.y0} width=${(sel[1] - sel[0] + 1) * L.bands.width} height=${L.y1 - L.y0}></rect>` : nothing;
|
|
631
716
|
const marks = L.bars.map((b) => b.path ? svg`<path class="mark ${hot && hot.i === b.i && hot.j === b.j ? "hot" : ""} ${anyCur && !cur[b.i] ? "rest" : ""}" data-slot=${seriesSlot(series[b.j], b.j)}
|
|
632
717
|
style=${styleMap({ "--_bk-chart-c": seriesColor(series[b.j], b.j, series.length) })} d=${b.path}></path>` : svg``);
|
|
718
|
+
const stubs = L.bars.map((b) => b.stub ? svg`<path class="stub" d=${b.stub}></path>` : svg``);
|
|
633
719
|
const valueLabels = [];
|
|
634
720
|
if (this.labels && !L.percent) {
|
|
635
721
|
const ends = L.stacked ? L.totals.map((tot, i) => {
|
|
@@ -670,16 +756,20 @@ class BkChartBar extends LitElement {
|
|
|
670
756
|
this.enter(first(i));
|
|
671
757
|
}
|
|
672
758
|
};
|
|
673
|
-
const
|
|
759
|
+
const hrefs = L.cats.map((_, i) => mode === "link" && !L.empty[i] ? this.categoryHref(this.viewRows[i]) : null);
|
|
760
|
+
const live = (i) => mode === "link" ? hrefs[i] !== null : !L.empty[i];
|
|
761
|
+
const tab = live(a.i) ? a.i : L.cats.findIndex((_, i) => live(i));
|
|
762
|
+
const cats = L.cats.map((_, i) => !live(i) ? html`<div class="cat" data-i=${i} role="img" aria-label=${this.categoryLabel(i)} aria-current=${cur[i] ? mode === "link" ? "page" : "true" : nothing}
|
|
763
|
+
style=${styleMap(box(i))} @pointerenter=${() => on.enter(i)}></div>` : mode === "link" ? html`<a class="cat interactive" part="category" data-i=${i} href=${this.links.href(hrefs[i])}
|
|
674
764
|
target=${ifDefined(this.target)} rel=${ifDefined(this.rel)} aria-current=${cur[i] ? "page" : nothing} aria-label=${this.categoryLabel(i)}
|
|
675
|
-
style=${styleMap(box(i))} @click=${this.links.click} @pointerenter=${() => on.enter(i)} @focus=${() => on.focus(i)} @blur=${this.onBlur}></a>` : html`<button type="button" class="cat interactive" part="category" data-i=${i} tabindex=${i ===
|
|
765
|
+
style=${styleMap(box(i))} @click=${this.links.click} @pointerenter=${() => on.enter(i)} @focus=${() => on.focus(i)} @blur=${this.onBlur}></a>` : html`<button type="button" class="cat interactive" part="category" data-i=${i} tabindex=${i === tab ? 0 : -1}
|
|
676
766
|
aria-current=${cur[i] ? "true" : nothing} aria-label=${this.categoryLabel(i)}
|
|
677
767
|
style=${styleMap(box(i))} @click=${() => this.choose(i)} @pointerenter=${() => on.enter(i)} @focus=${() => on.focus(i)} @blur=${this.onBlur}></button>`);
|
|
678
768
|
return html`<div class="plot" part="plot" style=${styleMap(h ? { height: `${L.H}px` } : {})}>
|
|
679
769
|
<svg width=${W} height=${L.H} aria-hidden="true">
|
|
680
770
|
${textureDefs()}
|
|
681
771
|
<g>${grid}${catLabels}</g>
|
|
682
|
-
<g>${markGeo.back}${ghosts}${marks}${markGeo.front}</g>
|
|
772
|
+
<g>${markGeo.back}${ghosts}${marks}${stubs}${markGeo.front}</g>
|
|
683
773
|
<g>${valueLabels}${seriesLabels}</g>
|
|
684
774
|
</svg>
|
|
685
775
|
<div class="cats" role=${mode === "button" ? "toolbar" : "group"} aria-orientation=${ifDefined(mode === "button" ? h ? "vertical" : "horizontal" : void 0)}
|
|
@@ -699,7 +789,7 @@ class BkChartBar extends LitElement {
|
|
|
699
789
|
@keydown=${this.onKey} @pointerleave=${this.onLeave} @pointerdown=${this.onDown} @pointermove=${this.onMove} @pointerup=${this.onUp}>
|
|
700
790
|
${textureDefs()}
|
|
701
791
|
<g aria-hidden="true">${grid}${catLabels}</g>
|
|
702
|
-
<g aria-hidden="true">${markGeo.back}${selection}${ghosts}${marks}${markGeo.front}</g>
|
|
792
|
+
<g aria-hidden="true">${markGeo.back}${selection}${ghosts}${marks}${stubs}${markGeo.front}</g>
|
|
703
793
|
<g aria-hidden="true">${valueLabels}${seriesLabels}</g>
|
|
704
794
|
<g>${hits}</g>
|
|
705
795
|
${ring}
|