@redvars/peacock 3.5.0 → 3.6.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/dist/BaseButton-BNFAYn-S.js +219 -0
- package/dist/BaseButton-BNFAYn-S.js.map +1 -0
- package/dist/BaseHyperlinkMixin-BNuwbiEf.js +65 -0
- package/dist/BaseHyperlinkMixin-BNuwbiEf.js.map +1 -0
- package/dist/BaseInput-14YmcfK7.js +27 -0
- package/dist/BaseInput-14YmcfK7.js.map +1 -0
- package/dist/assets/components.css +1 -1
- package/dist/assets/components.css.map +1 -1
- package/dist/assets/styles.css +1 -1
- package/dist/assets/styles.css.map +1 -1
- package/dist/banner.js +14 -30
- package/dist/banner.js.map +1 -1
- package/dist/{button-DMN1dPAg.js → button-colors-Ccys3hvS.js} +5 -468
- package/dist/button-colors-Ccys3hvS.js.map +1 -0
- package/dist/button-group.js +228 -8
- package/dist/button-group.js.map +1 -1
- package/dist/button.js +294 -8
- package/dist/button.js.map +1 -1
- package/dist/calendar-column-view.js +634 -0
- package/dist/calendar-column-view.js.map +1 -0
- package/dist/calendar-event-BrQ_SEKD.js +199 -0
- package/dist/calendar-event-BrQ_SEKD.js.map +1 -0
- package/dist/calendar-month-view.js +376 -0
- package/dist/calendar-month-view.js.map +1 -0
- package/dist/calendar.js +339 -0
- package/dist/calendar.js.map +1 -0
- package/dist/canvas.js +361 -0
- package/dist/canvas.js.map +1 -0
- package/dist/card.js +18 -73
- package/dist/card.js.map +1 -1
- package/dist/cb-compound-expression.js +125 -0
- package/dist/cb-compound-expression.js.map +1 -0
- package/dist/cb-divider.js +150 -0
- package/dist/cb-divider.js.map +1 -0
- package/dist/cb-expression.js +75 -0
- package/dist/cb-expression.js.map +1 -0
- package/dist/cb-predicate.js +137 -0
- package/dist/cb-predicate.js.map +1 -0
- package/dist/chart-bar.js.map +1 -1
- package/dist/chart-doughnut.js +2 -2
- package/dist/chart-doughnut.js.map +1 -1
- package/dist/chart-pie.js +2 -2
- package/dist/chart-pie.js.map +1 -1
- package/dist/chart-stacked-bar.js.map +1 -1
- package/dist/code-editor.js +2 -1
- package/dist/code-editor.js.map +1 -1
- package/dist/code-highlighter.js +2 -1
- package/dist/code-highlighter.js.map +1 -1
- package/dist/condition-builder.js +58 -0
- package/dist/condition-builder.js.map +1 -0
- package/dist/custom-elements-jsdocs.json +10860 -5567
- package/dist/custom-elements.json +16180 -7996
- package/dist/dropdown-button.js +216 -0
- package/dist/dropdown-button.js.map +1 -0
- package/dist/event-manager-D-QCmUgR.js +113 -0
- package/dist/event-manager-D-QCmUgR.js.map +1 -0
- package/dist/fab.js +421 -9
- package/dist/fab.js.map +1 -1
- package/dist/flow-designer-dZnLJOQT.js +1656 -0
- package/dist/flow-designer-dZnLJOQT.js.map +1 -0
- package/dist/flow-designer-node-XMe-jlKg.js +548 -0
- package/dist/flow-designer-node-XMe-jlKg.js.map +1 -0
- package/dist/flow-designer-node.js +4 -0
- package/dist/flow-designer-node.js.map +1 -0
- package/dist/flow-designer.js +16 -0
- package/dist/flow-designer.js.map +1 -0
- package/dist/html-editor.js +358 -0
- package/dist/html-editor.js.map +1 -0
- package/dist/icon-button-CK1ZuE-2.js +247 -0
- package/dist/icon-button-CK1ZuE-2.js.map +1 -0
- package/dist/index.js +31 -8
- package/dist/index.js.map +1 -1
- package/dist/{is-dark-mode-DicqGkCJ.js → is-dark-mode-DOcaw4Yq.js} +2 -27
- package/dist/is-dark-mode-DOcaw4Yq.js.map +1 -0
- package/dist/modal.js +418 -0
- package/dist/modal.js.map +1 -0
- package/dist/{select-4pl4XBj7.js → navigation-rail-DyO0oAZU.js} +2000 -2767
- package/dist/navigation-rail-DyO0oAZU.js.map +1 -0
- package/dist/notification-manager.js +268 -0
- package/dist/notification-manager.js.map +1 -0
- package/dist/notification.js +3 -2
- package/dist/notification.js.map +1 -1
- package/dist/peacock-loader.js +102 -14
- package/dist/peacock-loader.js.map +1 -1
- package/dist/popover-NC7b1lTq.js +1971 -0
- package/dist/popover-NC7b1lTq.js.map +1 -0
- package/dist/popover-content.js +125 -0
- package/dist/popover-content.js.map +1 -0
- package/dist/popover.js +4 -0
- package/dist/popover.js.map +1 -0
- package/dist/search.js +4 -0
- package/dist/search.js.map +1 -1
- package/dist/split-button.js +388 -0
- package/dist/split-button.js.map +1 -0
- package/dist/src/__controllers/floating-controller.d.ts +35 -0
- package/dist/src/__mixins/BaseButtonMixin.d.ts +20 -0
- package/dist/src/__mixins/BaseHyperlinkMixin.d.ts +18 -0
- package/dist/src/__mixins/MixinConstructor.d.ts +1 -0
- package/dist/src/banner/banner.d.ts +0 -4
- package/dist/src/button/BaseButton.d.ts +4 -47
- package/dist/src/button/button/button.d.ts +32 -3
- package/dist/src/button/button-group/button-group.d.ts +2 -2
- package/dist/src/button/icon-button/icon-button.d.ts +33 -8
- package/dist/src/calendar/base-event.d.ts +10 -0
- package/dist/src/calendar/calendar-column-view.d.ts +41 -0
- package/dist/src/calendar/calendar-event.d.ts +7 -0
- package/dist/src/calendar/calendar-month-view.d.ts +31 -0
- package/dist/src/calendar/calendar.d.ts +65 -0
- package/dist/src/calendar/event-manager.d.ts +17 -0
- package/dist/src/calendar/index.d.ts +4 -0
- package/dist/src/calendar/types.d.ts +13 -0
- package/dist/src/calendar/utils.d.ts +31 -0
- package/dist/src/canvas/canvas.d.ts +92 -0
- package/dist/src/canvas/index.d.ts +2 -0
- package/dist/src/card/card.d.ts +4 -15
- package/dist/src/condition-builder/cb-compound-expression.d.ts +31 -0
- package/dist/src/condition-builder/cb-divider.d.ts +26 -0
- package/dist/src/condition-builder/cb-expression.d.ts +31 -0
- package/dist/src/condition-builder/cb-predicate.d.ts +30 -0
- package/dist/src/condition-builder/condition-builder.d.ts +27 -0
- package/dist/src/condition-builder/index.d.ts +5 -0
- package/dist/src/dropdown-button/dropdown-button.d.ts +68 -0
- package/dist/src/dropdown-button/index.d.ts +1 -0
- package/dist/src/fab/fab.d.ts +4 -35
- package/dist/src/flow-designer/commands.d.ts +66 -0
- package/dist/src/flow-designer/flow-designer-node.d.ts +46 -0
- package/dist/src/flow-designer/flow-designer.d.ts +133 -0
- package/dist/src/flow-designer/index.d.ts +7 -0
- package/dist/src/flow-designer/layout.d.ts +30 -0
- package/dist/src/flow-designer/types.d.ts +142 -0
- package/dist/src/flow-designer/validation.d.ts +43 -0
- package/dist/src/flow-designer/workflow-utils.d.ts +40 -0
- package/dist/src/focus-ring/focus-ring.d.ts +11 -5
- package/dist/src/html-editor/html-editor.d.ts +56 -0
- package/dist/src/html-editor/index.d.ts +2 -0
- package/dist/src/index.d.ts +16 -1
- package/dist/src/link/link.d.ts +1 -1
- package/dist/src/menu/menu/menu.d.ts +5 -7
- package/dist/src/menu/menu-item/menu-item.d.ts +14 -13
- package/dist/src/modal/index.d.ts +1 -0
- package/dist/src/modal/modal.d.ts +63 -0
- package/dist/src/navigation-rail/index.d.ts +2 -0
- package/dist/src/navigation-rail/navigation-rail-item.d.ts +55 -0
- package/dist/src/navigation-rail/navigation-rail.d.ts +71 -0
- package/dist/src/notification-manager/index.d.ts +1 -0
- package/dist/src/notification-manager/notification-manager.d.ts +44 -0
- package/dist/src/popover/index.d.ts +2 -0
- package/dist/src/popover/popover-content.d.ts +29 -0
- package/dist/src/popover/popover.d.ts +62 -0
- package/dist/src/sidebar-menu/index.d.ts +3 -0
- package/dist/src/sidebar-menu/sidebar-menu-item.d.ts +58 -0
- package/dist/src/sidebar-menu/sidebar-menu.d.ts +38 -0
- package/dist/src/sidebar-menu/sidebar-sub-menu.d.ts +35 -0
- package/dist/src/split-button/index.d.ts +1 -0
- package/dist/src/split-button/split-button.d.ts +72 -0
- package/dist/src/toolbar/toolbar.d.ts +10 -10
- package/dist/src/tooltip/tooltip.d.ts +5 -15
- package/dist/src/url-field/index.d.ts +1 -0
- package/dist/src/url-field/url-field.d.ts +48 -0
- package/dist/test/flow-designer.test.d.ts +1 -0
- package/dist/test/sidebar-menu.test.d.ts +1 -0
- package/dist/toolbar.js +10 -10
- package/dist/toolbar.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -2
- package/readme.md +73 -65
- package/scss/mixin.scss +16 -0
- package/src/__controllers/floating-controller.ts +237 -0
- package/src/__mixins/BaseButtonMixin.ts +83 -0
- package/src/__mixins/BaseHyperlinkMixin.ts +68 -0
- package/src/__mixins/MixinConstructor.ts +1 -0
- package/src/{__base_element → __mixins}/README.md +2 -2
- package/src/banner/banner.scss +20 -25
- package/src/banner/banner.ts +1 -7
- package/src/button/BaseButton.ts +11 -100
- package/src/button/button/button-sizes.scss +4 -2
- package/src/button/button/button.ts +77 -23
- package/src/button/button-group/button-group.ts +2 -2
- package/src/button/icon-button/icon-button.ts +75 -33
- package/src/calendar/base-event.ts +49 -0
- package/src/calendar/calendar-column-view.scss +326 -0
- package/src/calendar/calendar-column-view.ts +392 -0
- package/src/calendar/calendar-event.ts +20 -0
- package/src/calendar/calendar-month-view.scss +192 -0
- package/src/calendar/calendar-month-view.ts +244 -0
- package/src/calendar/calendar.scss +71 -0
- package/src/calendar/calendar.ts +298 -0
- package/src/calendar/event-manager.ts +117 -0
- package/src/calendar/index.ts +4 -0
- package/src/calendar/types.ts +14 -0
- package/src/calendar/utils.ts +180 -0
- package/src/canvas/canvas.scss +60 -0
- package/src/canvas/canvas.ts +391 -0
- package/src/canvas/index.ts +2 -0
- package/src/card/card.ts +11 -71
- package/src/chart-bar/chart-bar.ts +9 -14
- package/src/chart-bar/chart-stacked-bar.ts +12 -18
- package/src/chart-doughnut/chart-doughnut.ts +23 -27
- package/src/chart-pie/chart-pie.ts +19 -23
- package/src/checkbox/checkbox.scss +17 -34
- package/src/checkbox/checkbox.ts +3 -1
- package/src/code-highlighter/code-highlighter.scss +1 -0
- package/src/code-highlighter/code-highlighter.ts +1 -1
- package/src/condition-builder/cb-compound-expression.scss +37 -0
- package/src/condition-builder/cb-compound-expression.ts +80 -0
- package/src/condition-builder/cb-divider.scss +93 -0
- package/src/condition-builder/cb-divider.ts +56 -0
- package/src/condition-builder/cb-expression.scss +14 -0
- package/src/condition-builder/cb-expression.ts +49 -0
- package/src/condition-builder/cb-predicate.scss +35 -0
- package/src/condition-builder/cb-predicate.ts +102 -0
- package/src/condition-builder/condition-builder.scss +13 -0
- package/src/condition-builder/condition-builder.ts +38 -0
- package/src/condition-builder/index.ts +5 -0
- package/src/date-picker/date-picker.ts +1 -1
- package/src/dropdown-button/demo/index.html +110 -0
- package/src/dropdown-button/dropdown-button.scss +22 -0
- package/src/dropdown-button/dropdown-button.ts +206 -0
- package/src/dropdown-button/index.ts +1 -0
- package/src/elevation/elevation.scss +5 -5
- package/src/fab/fab.ts +29 -100
- package/src/flow-designer/DEMO.md +239 -0
- package/src/flow-designer/commands.ts +278 -0
- package/src/flow-designer/flow-designer-node.ts +172 -0
- package/src/flow-designer/flow-designer.scss +457 -0
- package/src/flow-designer/flow-designer.ts +611 -0
- package/src/flow-designer/index.ts +41 -0
- package/src/flow-designer/layout.ts +357 -0
- package/src/flow-designer/types.ts +166 -0
- package/src/flow-designer/validation.ts +284 -0
- package/src/flow-designer/workflow-utils.ts +282 -0
- package/src/focus-ring/focus-ring.ts +47 -40
- package/src/html-editor/html-editor.scss +146 -0
- package/src/html-editor/html-editor.ts +276 -0
- package/src/html-editor/index.ts +3 -0
- package/src/index.ts +28 -1
- package/src/input/input.ts +3 -1
- package/src/link/link.ts +2 -2
- package/src/menu/menu/menu.scss +2 -2
- package/src/menu/menu/menu.ts +91 -101
- package/src/menu/menu-item/menu-item.scss +4 -0
- package/src/menu/menu-item/menu-item.ts +85 -79
- package/src/modal/index.ts +1 -0
- package/src/modal/modal.scss +206 -0
- package/src/modal/modal.ts +201 -0
- package/src/navigation-rail/index.ts +2 -0
- package/src/navigation-rail/navigation-rail-item.scss +216 -0
- package/src/navigation-rail/navigation-rail-item.ts +223 -0
- package/src/navigation-rail/navigation-rail.scss +72 -0
- package/src/navigation-rail/navigation-rail.ts +149 -0
- package/src/notification/notification.ts +3 -2
- package/src/notification-manager/index.ts +1 -0
- package/src/notification-manager/notification-manager.scss +113 -0
- package/src/notification-manager/notification-manager.ts +199 -0
- package/src/number-field/number-field.ts +6 -4
- package/src/pagination/pagination.ts +6 -4
- package/src/peacock-loader.ts +93 -5
- package/src/popover/index.ts +2 -0
- package/src/popover/popover-content.scss +69 -0
- package/src/popover/popover-content.ts +51 -0
- package/src/popover/popover.scss +7 -0
- package/src/popover/popover.ts +170 -0
- package/src/search/search.ts +4 -0
- package/src/sidebar-menu/demo/index.html +68 -0
- package/src/sidebar-menu/index.ts +3 -0
- package/src/sidebar-menu/sidebar-menu-item.scss +102 -0
- package/src/sidebar-menu/sidebar-menu-item.ts +151 -0
- package/src/{tree-view/tree-view.scss → sidebar-menu/sidebar-menu.scss} +1 -1
- package/src/sidebar-menu/sidebar-menu.ts +182 -0
- package/src/sidebar-menu/sidebar-sub-menu.scss +130 -0
- package/src/sidebar-menu/sidebar-sub-menu.ts +160 -0
- package/src/skeleton/skeleton.scss +18 -24
- package/src/snackbar/snackbar.ts +1 -1
- package/src/split-button/index.ts +1 -0
- package/src/split-button/split-button-colors.scss +56 -0
- package/src/split-button/split-button-sizes.scss +28 -0
- package/src/split-button/split-button.scss +79 -0
- package/src/split-button/split-button.ts +236 -0
- package/src/table/table.ts +2 -2
- package/src/tabs/tab.ts +4 -3
- package/src/text/text.css-component.scss +7 -1
- package/src/time-picker/time-picker.ts +1 -1
- package/src/toolbar/toolbar.ts +10 -10
- package/src/tooltip/tooltip.scss +4 -3
- package/src/tooltip/tooltip.ts +64 -98
- package/src/url-field/index.ts +1 -0
- package/src/url-field/url-field.scss +50 -0
- package/src/url-field/url-field.ts +239 -0
- package/dist/button-DMN1dPAg.js.map +0 -1
- package/dist/button-group-CX9CUUXk.js +0 -435
- package/dist/button-group-CX9CUUXk.js.map +0 -1
- package/dist/fab-C5Nzxk0E.js +0 -497
- package/dist/fab-C5Nzxk0E.js.map +0 -1
- package/dist/is-dark-mode-DicqGkCJ.js.map +0 -1
- package/dist/select-4pl4XBj7.js.map +0 -1
- package/dist/spread-B5cgadZl.js +0 -32
- package/dist/spread-B5cgadZl.js.map +0 -1
- package/dist/src/__base_element/BaseHyperlink.d.ts +0 -20
- package/dist/src/menu/menu/MenuSurfaceController.d.ts +0 -18
- package/dist/src/tree-view/index.d.ts +0 -2
- package/dist/src/tree-view/tree-node.d.ts +0 -69
- package/dist/src/tree-view/tree-view.d.ts +0 -40
- package/dist/src/tree-view/wc-tree-view.d.ts +0 -6
- package/dist/test/tree-view.test.d.ts +0 -1
- package/dist/throttle-C7ZAPqtu.js +0 -24
- package/dist/throttle-C7ZAPqtu.js.map +0 -1
- package/src/__base_element/BaseHyperlink.ts +0 -42
- package/src/menu/menu/MenuSurfaceController.ts +0 -61
- package/src/tree-view/demo/index.html +0 -57
- package/src/tree-view/index.ts +0 -2
- package/src/tree-view/tree-node.scss +0 -101
- package/src/tree-view/tree-node.ts +0 -268
- package/src/tree-view/tree-view.ts +0 -182
- package/src/tree-view/wc-tree-view.ts +0 -9
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { html, LitElement, svg, nothing } from 'lit';
|
|
2
|
+
import { property } from 'lit/decorators.js';
|
|
3
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
4
|
+
import IndividualComponent from '@/IndividualComponent.js';
|
|
5
|
+
import styles from './canvas.scss';
|
|
6
|
+
|
|
7
|
+
export type CanvasDirection = 'up' | 'down' | 'left' | 'right';
|
|
8
|
+
|
|
9
|
+
export type CanvasStrokeVariant = 'solid' | 'dashed' | 'animated-dashed';
|
|
10
|
+
|
|
11
|
+
export interface CanvasPoint {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface CanvasPathSegment {
|
|
17
|
+
direction: CanvasDirection;
|
|
18
|
+
length: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface BaseCanvasShape {
|
|
22
|
+
color?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface BaseCanvasStrokeShape extends BaseCanvasShape {
|
|
26
|
+
variant?: CanvasStrokeVariant;
|
|
27
|
+
showArrow?: boolean;
|
|
28
|
+
clickable?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface CanvasCircleShape extends BaseCanvasShape {
|
|
32
|
+
type: 'circle';
|
|
33
|
+
x?: number;
|
|
34
|
+
y?: number;
|
|
35
|
+
radius?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface CanvasRectShape extends BaseCanvasShape {
|
|
39
|
+
type: 'rect';
|
|
40
|
+
x?: number;
|
|
41
|
+
y?: number;
|
|
42
|
+
width?: number;
|
|
43
|
+
height?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface CanvasLineShape extends BaseCanvasStrokeShape {
|
|
47
|
+
type: 'line';
|
|
48
|
+
start?: CanvasPoint;
|
|
49
|
+
end?: CanvasPoint;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface CanvasConnectorShape extends BaseCanvasStrokeShape {
|
|
53
|
+
type: 'connector';
|
|
54
|
+
start?: CanvasPoint;
|
|
55
|
+
path?: CanvasPathSegment[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type CanvasShape =
|
|
59
|
+
| CanvasCircleShape
|
|
60
|
+
| CanvasRectShape
|
|
61
|
+
| CanvasLineShape
|
|
62
|
+
| CanvasConnectorShape;
|
|
63
|
+
|
|
64
|
+
interface CanvasBounds {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @label Canvas
|
|
73
|
+
* @tag wc-canvas
|
|
74
|
+
* @rawTag canvas
|
|
75
|
+
* @summary A Material 3 inspired SVG canvas for drawing shapes, lines, and connectors on a dotted grid.
|
|
76
|
+
*
|
|
77
|
+
* @cssprop --canvas-background - Background color for the canvas wrapper. Defaults to surface-container-low.
|
|
78
|
+
* @cssprop --canvas-dot-color - Color of the background grid dots. Defaults to outline-variant.
|
|
79
|
+
* @cssprop --canvas-line-color - Default stroke color for lines and connectors. Defaults to on-surface.
|
|
80
|
+
* @cssprop --canvas-hover-color - Stroke color on hover for clickable shapes. Defaults to primary.
|
|
81
|
+
* @cssprop --canvas-arrow-color - Stroke color for arrow markers. Defaults to on-surface.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```html
|
|
85
|
+
* <wc-canvas id="my-canvas"></wc-canvas>
|
|
86
|
+
* <script>
|
|
87
|
+
* document.querySelector('#my-canvas').shapes = [
|
|
88
|
+
* { type: 'circle', x: 0, y: 0, radius: 0.25, color: 'red' },
|
|
89
|
+
* ];
|
|
90
|
+
* </script>
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
@IndividualComponent
|
|
94
|
+
export class Canvas extends LitElement {
|
|
95
|
+
static styles = [styles];
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Array of shape objects to render on the canvas.
|
|
99
|
+
*/
|
|
100
|
+
@property({ type: Array })
|
|
101
|
+
shapes: CanvasShape[] = [];
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Padding around the computed viewbox (in grid units).
|
|
105
|
+
*/
|
|
106
|
+
@property({ type: Number, reflect: true })
|
|
107
|
+
padding: number = 1;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Zoom multiplier for the canvas dimensions.
|
|
111
|
+
*/
|
|
112
|
+
@property({ type: Number, reflect: true })
|
|
113
|
+
zoom: number = 1;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Optional viewbox override string (e.g. "0 0 100 100").
|
|
117
|
+
*/
|
|
118
|
+
@property({ type: String })
|
|
119
|
+
viewbox?: string;
|
|
120
|
+
|
|
121
|
+
private unitSize: number = 1;
|
|
122
|
+
|
|
123
|
+
private gap: number = this.unitSize * 10;
|
|
124
|
+
|
|
125
|
+
private static getNextPoint(
|
|
126
|
+
point: CanvasPoint,
|
|
127
|
+
direction: CanvasDirection,
|
|
128
|
+
length: number,
|
|
129
|
+
): CanvasPoint {
|
|
130
|
+
if (direction === 'down') return { x: point.x, y: point.y + length };
|
|
131
|
+
if (direction === 'up') return { x: point.x, y: point.y - length };
|
|
132
|
+
if (direction === 'left') return { x: point.x - length, y: point.y };
|
|
133
|
+
if (direction === 'right') return { x: point.x + length, y: point.y };
|
|
134
|
+
return { x: point.x, y: point.y };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private static updateComputationArea(
|
|
138
|
+
point: CanvasPoint,
|
|
139
|
+
area: CanvasBounds,
|
|
140
|
+
): CanvasBounds {
|
|
141
|
+
const nextArea = { ...area };
|
|
142
|
+
if (point.x > nextArea.width) nextArea.width = point.x;
|
|
143
|
+
else if (point.x < nextArea.x) nextArea.x = point.x;
|
|
144
|
+
if (point.y > nextArea.height) nextArea.height = point.y;
|
|
145
|
+
else if (point.y < nextArea.y) nextArea.y = point.y;
|
|
146
|
+
return nextArea;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private static getStrokeVariantClasses(variant?: CanvasStrokeVariant) {
|
|
150
|
+
return {
|
|
151
|
+
line: true,
|
|
152
|
+
'no-color': false,
|
|
153
|
+
'variant-dashed': variant === 'dashed' || variant === 'animated-dashed',
|
|
154
|
+
'variant-animated-dashed': variant === 'animated-dashed',
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private computeShapes(initialBounds: CanvasBounds) {
|
|
159
|
+
const dotRadius = this.unitSize;
|
|
160
|
+
let computedViewbox = { ...initialBounds };
|
|
161
|
+
|
|
162
|
+
const shapes = this.shapes.map(shape => {
|
|
163
|
+
switch (shape.type) {
|
|
164
|
+
case 'circle': {
|
|
165
|
+
const r = shape.radius || 1;
|
|
166
|
+
const cx = shape.x || 0;
|
|
167
|
+
const cy = shape.y || 0;
|
|
168
|
+
if (cx + Math.ceil(r) > computedViewbox.width)
|
|
169
|
+
computedViewbox.width = cx + Math.ceil(r);
|
|
170
|
+
if (cx - Math.ceil(r) < computedViewbox.x)
|
|
171
|
+
computedViewbox.x = cx - Math.ceil(r);
|
|
172
|
+
if (cy + Math.ceil(r) > computedViewbox.height)
|
|
173
|
+
computedViewbox.height = cy + Math.ceil(r);
|
|
174
|
+
if (cy - Math.ceil(r) < computedViewbox.y)
|
|
175
|
+
computedViewbox.y = cy - Math.ceil(r);
|
|
176
|
+
|
|
177
|
+
return svg`<circle
|
|
178
|
+
cx=${cx * this.gap + dotRadius}
|
|
179
|
+
cy=${cy * this.gap + dotRadius}
|
|
180
|
+
r=${r * this.gap}
|
|
181
|
+
fill=${shape.color || 'var(--canvas-line-color, var(--color-on-surface))'}
|
|
182
|
+
/>`;
|
|
183
|
+
}
|
|
184
|
+
case 'rect': {
|
|
185
|
+
const w = shape.width || 1;
|
|
186
|
+
const h = shape.height || 1;
|
|
187
|
+
const rx = shape.x || 0;
|
|
188
|
+
const ry = shape.y || 0;
|
|
189
|
+
if (rx + Math.ceil(w) > computedViewbox.width)
|
|
190
|
+
computedViewbox.width = rx + Math.ceil(w);
|
|
191
|
+
if (rx - Math.ceil(w) < computedViewbox.x)
|
|
192
|
+
computedViewbox.x = rx - Math.ceil(w);
|
|
193
|
+
if (ry + Math.ceil(h) > computedViewbox.height)
|
|
194
|
+
computedViewbox.height = ry + Math.ceil(h);
|
|
195
|
+
if (ry - Math.ceil(h) < computedViewbox.y)
|
|
196
|
+
computedViewbox.y = ry - Math.ceil(h);
|
|
197
|
+
|
|
198
|
+
return svg`<rect
|
|
199
|
+
x=${rx * this.gap + dotRadius}
|
|
200
|
+
y=${ry * this.gap}
|
|
201
|
+
width=${w * this.gap + dotRadius}
|
|
202
|
+
height=${h * this.gap + dotRadius}
|
|
203
|
+
fill=${shape.color || 'var(--canvas-line-color, var(--color-on-surface))'}
|
|
204
|
+
/>`;
|
|
205
|
+
}
|
|
206
|
+
case 'line': {
|
|
207
|
+
const start = shape.start || { x: 0, y: 0 };
|
|
208
|
+
const end = shape.end || { x: 0, y: 0 };
|
|
209
|
+
const pathString = `M${start.x * this.gap + dotRadius} ${start.y * this.gap + dotRadius} L${end.x * this.gap + dotRadius} ${end.y * this.gap + dotRadius}`;
|
|
210
|
+
const strokeColor =
|
|
211
|
+
shape.color ||
|
|
212
|
+
'var(--canvas-line-color, var(--color-on-surface))';
|
|
213
|
+
|
|
214
|
+
return svg`<path
|
|
215
|
+
class=${classMap({
|
|
216
|
+
...Canvas.getStrokeVariantClasses(shape.variant),
|
|
217
|
+
clickable: !!shape.clickable,
|
|
218
|
+
'no-color': !shape.color,
|
|
219
|
+
})}
|
|
220
|
+
stroke-width="2"
|
|
221
|
+
stroke-linecap="round"
|
|
222
|
+
stroke-linejoin="round"
|
|
223
|
+
stroke=${strokeColor}
|
|
224
|
+
marker-end=${shape.showArrow ? 'url(#endarrow)' : ''}
|
|
225
|
+
d=${pathString}
|
|
226
|
+
stroke-dasharray=${shape.variant === 'dashed' || shape.variant === 'animated-dashed' ? '6,6' : nothing}
|
|
227
|
+
fill="none"
|
|
228
|
+
/>`;
|
|
229
|
+
}
|
|
230
|
+
case 'connector': {
|
|
231
|
+
const start = shape.start || { x: 0, y: 0 };
|
|
232
|
+
let pathString = `M${start.x * this.gap + dotRadius} ${start.y * this.gap + dotRadius}`;
|
|
233
|
+
let current = { ...start };
|
|
234
|
+
computedViewbox = Canvas.updateComputationArea(current, computedViewbox);
|
|
235
|
+
|
|
236
|
+
const pathSegments = shape.path || [];
|
|
237
|
+
for (let i = 0; i < pathSegments.length; i += 1) {
|
|
238
|
+
const path = pathSegments[i];
|
|
239
|
+
|
|
240
|
+
if (i === 0) {
|
|
241
|
+
const point = Canvas.getNextPoint(current, path.direction, 1);
|
|
242
|
+
pathString += ` L${point.x * this.gap + dotRadius} ${point.y * this.gap + dotRadius}`;
|
|
243
|
+
current = { ...point };
|
|
244
|
+
computedViewbox = Canvas.updateComputationArea(current, computedViewbox);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const point = Canvas.getNextPoint(
|
|
248
|
+
current,
|
|
249
|
+
path.direction,
|
|
250
|
+
path.length - 2,
|
|
251
|
+
);
|
|
252
|
+
pathString += ` L${point.x * this.gap + dotRadius} ${point.y * this.gap + dotRadius}`;
|
|
253
|
+
current = { ...point };
|
|
254
|
+
computedViewbox = Canvas.updateComputationArea(current, computedViewbox);
|
|
255
|
+
|
|
256
|
+
if (i === pathSegments.length - 1) {
|
|
257
|
+
const endPoint = Canvas.getNextPoint(current, path.direction, 1);
|
|
258
|
+
pathString += ` L${endPoint.x * this.gap + dotRadius} ${endPoint.y * this.gap + dotRadius}`;
|
|
259
|
+
current = { ...endPoint };
|
|
260
|
+
computedViewbox = Canvas.updateComputationArea(current, computedViewbox);
|
|
261
|
+
} else {
|
|
262
|
+
const nextPath = pathSegments[i + 1];
|
|
263
|
+
const midPoint = Canvas.getNextPoint(current, path.direction, 1);
|
|
264
|
+
const nextPoint = Canvas.getNextPoint(
|
|
265
|
+
midPoint,
|
|
266
|
+
nextPath.direction,
|
|
267
|
+
1,
|
|
268
|
+
);
|
|
269
|
+
pathString += ` Q ${midPoint.x * this.gap + dotRadius} ${midPoint.y * this.gap + dotRadius} ${nextPoint.x * this.gap + dotRadius} ${nextPoint.y * this.gap + dotRadius}`;
|
|
270
|
+
current = { ...nextPoint };
|
|
271
|
+
computedViewbox = Canvas.updateComputationArea(current, computedViewbox);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const strokeColor =
|
|
276
|
+
shape.color ||
|
|
277
|
+
'var(--canvas-line-color, var(--color-on-surface))';
|
|
278
|
+
|
|
279
|
+
return svg`<g class=${classMap({ clickable: !!shape.clickable })}>
|
|
280
|
+
<path
|
|
281
|
+
class=${classMap({
|
|
282
|
+
...Canvas.getStrokeVariantClasses(shape.variant),
|
|
283
|
+
'no-color': !shape.color,
|
|
284
|
+
})}
|
|
285
|
+
stroke-width="2"
|
|
286
|
+
stroke-linecap="round"
|
|
287
|
+
stroke-linejoin="round"
|
|
288
|
+
stroke=${strokeColor}
|
|
289
|
+
marker-end=${shape.showArrow ? 'url(#endarrow)' : ''}
|
|
290
|
+
d=${pathString}
|
|
291
|
+
stroke-dasharray=${shape.variant === 'dashed' || shape.variant === 'animated-dashed' ? '6,6' : nothing}
|
|
292
|
+
fill="none"
|
|
293
|
+
/>
|
|
294
|
+
<path
|
|
295
|
+
stroke-width="10"
|
|
296
|
+
stroke-linecap="round"
|
|
297
|
+
stroke-linejoin="round"
|
|
298
|
+
stroke="transparent"
|
|
299
|
+
d=${pathString}
|
|
300
|
+
fill="none"
|
|
301
|
+
/>
|
|
302
|
+
</g>`;
|
|
303
|
+
}
|
|
304
|
+
default:
|
|
305
|
+
return nothing;
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// Padding
|
|
310
|
+
computedViewbox.x -= this.padding;
|
|
311
|
+
computedViewbox.y -= this.padding;
|
|
312
|
+
computedViewbox.width += this.padding;
|
|
313
|
+
computedViewbox.height += this.padding;
|
|
314
|
+
computedViewbox.width -= computedViewbox.x;
|
|
315
|
+
computedViewbox.height -= computedViewbox.y;
|
|
316
|
+
|
|
317
|
+
return { shapes, computedViewbox };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
protected render() {
|
|
321
|
+
const dotRadius = this.unitSize;
|
|
322
|
+
let computedViewBox = { width: 0, height: 0, x: 0, y: 0 };
|
|
323
|
+
|
|
324
|
+
const { shapes, computedViewbox } = this.computeShapes(computedViewBox);
|
|
325
|
+
computedViewBox = computedViewbox;
|
|
326
|
+
|
|
327
|
+
if (this.viewbox) {
|
|
328
|
+
const viewBox = this.viewbox.split(' ');
|
|
329
|
+
computedViewBox = {
|
|
330
|
+
x: parseInt(viewBox[0], 10),
|
|
331
|
+
y: parseInt(viewBox[1], 10),
|
|
332
|
+
width: parseInt(viewBox[2], 10),
|
|
333
|
+
height: parseInt(viewBox[3], 10),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const wrapperWidth =
|
|
338
|
+
(computedViewBox.width * this.gap + 2) * dotRadius * this.zoom;
|
|
339
|
+
const wrapperHeight =
|
|
340
|
+
(computedViewBox.height * this.gap + 2) * dotRadius * this.zoom;
|
|
341
|
+
|
|
342
|
+
const svgViewBox = `${computedViewBox.x * this.gap} ${computedViewBox.y * this.gap} ${computedViewBox.width * this.gap + 2 * dotRadius} ${computedViewBox.height * this.gap + 2 * dotRadius}`;
|
|
343
|
+
|
|
344
|
+
return html`
|
|
345
|
+
<div
|
|
346
|
+
class="canvas-wrapper"
|
|
347
|
+
style="width: ${wrapperWidth}px; height: ${wrapperHeight}px;"
|
|
348
|
+
>
|
|
349
|
+
<svg
|
|
350
|
+
class="canvas"
|
|
351
|
+
height="100%"
|
|
352
|
+
width="100%"
|
|
353
|
+
viewBox=${svgViewBox}
|
|
354
|
+
>
|
|
355
|
+
<defs>
|
|
356
|
+
<pattern
|
|
357
|
+
id="canvas-background"
|
|
358
|
+
patternUnits="userSpaceOnUse"
|
|
359
|
+
width=${this.gap}
|
|
360
|
+
height=${this.gap}
|
|
361
|
+
>
|
|
362
|
+
<circle cx="1" cy="1" r=${dotRadius} />
|
|
363
|
+
</pattern>
|
|
364
|
+
|
|
365
|
+
<marker
|
|
366
|
+
id="endarrow"
|
|
367
|
+
markerWidth="15"
|
|
368
|
+
markerHeight="22.5"
|
|
369
|
+
refX="9"
|
|
370
|
+
refY="15"
|
|
371
|
+
markerUnits="userSpaceOnUse"
|
|
372
|
+
orient="auto"
|
|
373
|
+
>
|
|
374
|
+
<polyline points="0 22.5, 7.5 15, 0 7.5"></polyline>
|
|
375
|
+
</marker>
|
|
376
|
+
</defs>
|
|
377
|
+
|
|
378
|
+
<rect
|
|
379
|
+
x=${computedViewBox.x * this.gap}
|
|
380
|
+
y=${computedViewBox.y * this.gap}
|
|
381
|
+
width="100%"
|
|
382
|
+
height="100%"
|
|
383
|
+
fill="url(#canvas-background)"
|
|
384
|
+
/>
|
|
385
|
+
|
|
386
|
+
${shapes}
|
|
387
|
+
</svg>
|
|
388
|
+
</div>
|
|
389
|
+
`;
|
|
390
|
+
}
|
|
391
|
+
}
|
package/src/card/card.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LitElement, html, nothing
|
|
1
|
+
import { LitElement, html, nothing } from 'lit';
|
|
2
2
|
import { property, query, state } from 'lit/decorators.js';
|
|
3
3
|
import { classMap } from 'lit/directives/class-map.js';
|
|
4
4
|
import { dispatchActivationClick, isActivationClick } from '../__utils/dispatch-event-utils.js';
|
|
@@ -7,6 +7,7 @@ import { throttle } from '@/__utils/throttle.js';
|
|
|
7
7
|
import IndividualComponent from '@/IndividualComponent.js';
|
|
8
8
|
import styles from './card.scss';
|
|
9
9
|
import colorStyles from './card-colors.scss';
|
|
10
|
+
import BaseHyperlinkMixin from '@/__mixins/BaseHyperlinkMixin.js';
|
|
10
11
|
|
|
11
12
|
type CardVariant = 'elevated' | 'filled' | 'outlined';
|
|
12
13
|
|
|
@@ -28,7 +29,7 @@ type CardVariant = 'elevated' | 'filled' | 'outlined';
|
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
30
31
|
@IndividualComponent
|
|
31
|
-
export class Card extends LitElement {
|
|
32
|
+
export class Card extends BaseHyperlinkMixin(LitElement) {
|
|
32
33
|
static styles = [styles, colorStyles];
|
|
33
34
|
|
|
34
35
|
#id = crypto.randomUUID();
|
|
@@ -48,17 +49,6 @@ export class Card extends LitElement {
|
|
|
48
49
|
@property({ attribute: 'disabled-reason' })
|
|
49
50
|
disabledReason: string = '';
|
|
50
51
|
|
|
51
|
-
/**
|
|
52
|
-
* Hyperlink to navigate to on click.
|
|
53
|
-
*/
|
|
54
|
-
@property({ reflect: true }) href?: string;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Sets or retrieves the window or frame at which to target content.
|
|
58
|
-
*/
|
|
59
|
-
@property() target: string = '_self';
|
|
60
|
-
|
|
61
|
-
|
|
62
52
|
/**
|
|
63
53
|
* Sets the delay for throttle in milliseconds. Defaults to 200 milliseconds.
|
|
64
54
|
*/
|
|
@@ -76,12 +66,8 @@ export class Card extends LitElement {
|
|
|
76
66
|
|
|
77
67
|
@query('.card') readonly cardElement!: HTMLElement | null;
|
|
78
68
|
|
|
79
|
-
@query('slot') readonly contentSlot!: HTMLSlotElement | null;
|
|
80
|
-
|
|
81
69
|
#tabindex?: number = 0;
|
|
82
70
|
|
|
83
|
-
#slottedTabIndexMap = new WeakMap<HTMLElement, string | null>();
|
|
84
|
-
|
|
85
71
|
override firstUpdated() {
|
|
86
72
|
this.__dispatchClickWithThrottle = throttle(
|
|
87
73
|
this.__dispatchClick,
|
|
@@ -91,52 +77,9 @@ export class Card extends LitElement {
|
|
|
91
77
|
this.renderRoot.querySelector('slot'),
|
|
92
78
|
hasContent => {
|
|
93
79
|
this.slotHasContent = hasContent;
|
|
94
|
-
this.__syncSlottedChildrenTabIndex();
|
|
95
80
|
this.requestUpdate();
|
|
96
81
|
},
|
|
97
82
|
);
|
|
98
|
-
this.__syncSlottedChildrenTabIndex();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
override updated(changedProperties: PropertyValues<this>) {
|
|
102
|
-
if (changedProperties.has('actionable') || changedProperties.has('href')) {
|
|
103
|
-
this.__syncSlottedChildrenTabIndex();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
__syncSlottedChildrenTabIndex() {
|
|
108
|
-
if (!this.contentSlot) return;
|
|
109
|
-
|
|
110
|
-
const shouldDisableTabbing = this.actionable || this.__isLink();
|
|
111
|
-
const assignedChildren = this.contentSlot.assignedElements({ flatten: true });
|
|
112
|
-
|
|
113
|
-
assignedChildren.forEach(node => {
|
|
114
|
-
if (!(node instanceof HTMLElement)) return;
|
|
115
|
-
|
|
116
|
-
if (shouldDisableTabbing) {
|
|
117
|
-
if (!this.#slottedTabIndexMap.has(node)) {
|
|
118
|
-
this.#slottedTabIndexMap.set(node, node.getAttribute('tabindex'));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (node.getAttribute('tabindex') !== '-1') {
|
|
122
|
-
node.setAttribute('tabindex', '-1');
|
|
123
|
-
}
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const originalTabIndex = this.#slottedTabIndexMap.get(node);
|
|
128
|
-
if (originalTabIndex === null) {
|
|
129
|
-
if (node.hasAttribute('tabindex')) {
|
|
130
|
-
node.removeAttribute('tabindex');
|
|
131
|
-
}
|
|
132
|
-
} else if (originalTabIndex !== undefined) {
|
|
133
|
-
if (node.getAttribute('tabindex') !== originalTabIndex) {
|
|
134
|
-
node.setAttribute('tabindex', originalTabIndex);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
this.#slottedTabIndexMap.delete(node);
|
|
139
|
-
});
|
|
140
83
|
}
|
|
141
84
|
|
|
142
85
|
__dispatchClickWithThrottle: (event: MouseEvent | KeyboardEvent) => void =
|
|
@@ -162,10 +105,6 @@ export class Card extends LitElement {
|
|
|
162
105
|
dispatchActivationClick(this.cardElement);
|
|
163
106
|
};
|
|
164
107
|
|
|
165
|
-
__isLink() {
|
|
166
|
-
return !!this.href;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
108
|
__getDisabledReasonID() {
|
|
170
109
|
return this.disabled && this.disabledReason
|
|
171
110
|
? `disabled-reason-${this.#id}`
|
|
@@ -207,6 +146,7 @@ export class Card extends LitElement {
|
|
|
207
146
|
render() {
|
|
208
147
|
|
|
209
148
|
const isLink = this.__isLink();
|
|
149
|
+
const disableSlotTabbing = this.actionable || isLink;
|
|
210
150
|
|
|
211
151
|
const cssClasses = {
|
|
212
152
|
card: true,
|
|
@@ -223,7 +163,7 @@ export class Card extends LitElement {
|
|
|
223
163
|
class=${classMap(cssClasses)}
|
|
224
164
|
id="card"
|
|
225
165
|
>
|
|
226
|
-
${this.renderCardContent()}
|
|
166
|
+
${this.renderCardContent(disableSlotTabbing)}
|
|
227
167
|
</div>`;
|
|
228
168
|
}
|
|
229
169
|
|
|
@@ -240,7 +180,7 @@ export class Card extends LitElement {
|
|
|
240
180
|
aria-disabled=${`${this.disabled}`}
|
|
241
181
|
?disabled=${this.disabled}
|
|
242
182
|
>
|
|
243
|
-
${this.renderCardContent()}
|
|
183
|
+
${this.renderCardContent(disableSlotTabbing)}
|
|
244
184
|
</button>`;
|
|
245
185
|
}
|
|
246
186
|
return html`<a
|
|
@@ -257,13 +197,13 @@ export class Card extends LitElement {
|
|
|
257
197
|
?aria-describedby=${this.__getDisabledReasonID()}
|
|
258
198
|
aria-disabled=${`${this.disabled}`}
|
|
259
199
|
>
|
|
260
|
-
${this.renderCardContent()}
|
|
200
|
+
${this.renderCardContent(disableSlotTabbing)}
|
|
261
201
|
</a>`;
|
|
262
202
|
}
|
|
263
203
|
|
|
264
|
-
renderCardContent() {
|
|
204
|
+
renderCardContent(disableSlotTabbing: boolean) {
|
|
265
205
|
return html`
|
|
266
|
-
|
|
206
|
+
<wc-focus-ring class="focus-ring" for='card'></wc-focus-ring>
|
|
267
207
|
<wc-elevation class="elevation"></wc-elevation>
|
|
268
208
|
<div class="background"></div>
|
|
269
209
|
<div class="outline"></div>
|
|
@@ -271,8 +211,8 @@ export class Card extends LitElement {
|
|
|
271
211
|
|
|
272
212
|
<div class="card-content">
|
|
273
213
|
|
|
274
|
-
<div class="slot-container">
|
|
275
|
-
<slot
|
|
214
|
+
<div class="slot-container" ?inert=${disableSlotTabbing}>
|
|
215
|
+
<slot></slot>
|
|
276
216
|
</div>
|
|
277
217
|
|
|
278
218
|
</div>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { html, LitElement, PropertyValues } from 'lit';
|
|
2
2
|
import { property, query } from 'lit/decorators.js';
|
|
3
3
|
import { styleMap } from 'lit/directives/style-map.js';
|
|
4
|
+
import { select, max, scaleBand, scaleLinear, scaleOrdinal, axisLeft, axisBottom, ScaleOrdinal } from 'd3';
|
|
4
5
|
import IndividualComponent from '@/IndividualComponent.js';
|
|
5
|
-
import * as d3 from 'd3';
|
|
6
6
|
import styles from './chart-bar.scss';
|
|
7
7
|
|
|
8
8
|
export type ChartBarItem = {
|
|
@@ -94,8 +94,7 @@ export class ChartBar extends LitElement {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
private _getPaletteScale() {
|
|
97
|
-
return
|
|
98
|
-
.scaleOrdinal<string, string>()
|
|
97
|
+
return scaleOrdinal<string, string>()
|
|
99
98
|
.domain(this.data.map(d => d.name))
|
|
100
99
|
.range(chartColors);
|
|
101
100
|
}
|
|
@@ -103,7 +102,7 @@ export class ChartBar extends LitElement {
|
|
|
103
102
|
private _resolveColor(
|
|
104
103
|
name: string,
|
|
105
104
|
override: string | undefined,
|
|
106
|
-
scale:
|
|
105
|
+
scale: ScaleOrdinal<string, string>,
|
|
107
106
|
) {
|
|
108
107
|
return override || scale(name);
|
|
109
108
|
}
|
|
@@ -116,7 +115,7 @@ export class ChartBar extends LitElement {
|
|
|
116
115
|
const margin = Math.max(this.margin, 12);
|
|
117
116
|
const data = this.data ?? [];
|
|
118
117
|
|
|
119
|
-
const svg =
|
|
118
|
+
const svg = select(this.svgElement);
|
|
120
119
|
svg.attr('width', width).attr('height', height);
|
|
121
120
|
|
|
122
121
|
const innerWidth = Math.max(width - margin * 2, 0);
|
|
@@ -134,15 +133,13 @@ export class ChartBar extends LitElement {
|
|
|
134
133
|
return;
|
|
135
134
|
}
|
|
136
135
|
|
|
137
|
-
const xScale =
|
|
138
|
-
.scaleBand<string>()
|
|
136
|
+
const xScale = scaleBand<string>()
|
|
139
137
|
.domain(data.map(d => d.name))
|
|
140
138
|
.range([0, innerWidth])
|
|
141
139
|
.padding(0.28);
|
|
142
140
|
|
|
143
|
-
const maxValue =
|
|
144
|
-
const yScale =
|
|
145
|
-
.scaleLinear()
|
|
141
|
+
const maxValue = max(data, d => d.value) ?? 0;
|
|
142
|
+
const yScale = scaleLinear()
|
|
146
143
|
.domain([0, maxValue || 1])
|
|
147
144
|
.nice()
|
|
148
145
|
.range([innerHeight, 0]);
|
|
@@ -150,8 +147,7 @@ export class ChartBar extends LitElement {
|
|
|
150
147
|
const yGrid = container.select<SVGGElement>('.y-grid');
|
|
151
148
|
yGrid
|
|
152
149
|
.call(
|
|
153
|
-
|
|
154
|
-
.axisLeft(yScale)
|
|
150
|
+
axisLeft(yScale)
|
|
155
151
|
.ticks(5)
|
|
156
152
|
.tickSize(-innerWidth)
|
|
157
153
|
.tickFormat(() => ''),
|
|
@@ -165,8 +161,7 @@ export class ChartBar extends LitElement {
|
|
|
165
161
|
xAxis
|
|
166
162
|
.attr('transform', `translate(0,${innerHeight})`)
|
|
167
163
|
.call(
|
|
168
|
-
|
|
169
|
-
.axisBottom(xScale)
|
|
164
|
+
axisBottom(xScale)
|
|
170
165
|
.tickSizeOuter(0)
|
|
171
166
|
.tickFormat(name => {
|
|
172
167
|
const entry = data.find(d => d.name === name);
|