@reshape-biotech/design-system 1.2.6 → 1.2.7
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/README.md +3 -1
- package/dist/app.css +97 -97
- package/dist/components/activity/Activity.stories.svelte +104 -104
- package/dist/components/activity/Activity.svelte +112 -112
- package/dist/components/avatar/Avatar.stories.svelte +23 -23
- package/dist/components/avatar/Avatar.svelte +54 -54
- package/dist/components/banner/Banner.stories.svelte +105 -105
- package/dist/components/banner/Banner.svelte +42 -42
- package/dist/components/button/Button.stories.svelte +61 -61
- package/dist/components/button/Button.svelte +95 -95
- package/dist/components/card/Card.stories.svelte +112 -112
- package/dist/components/card/Card.svelte +18 -18
- package/dist/components/checkbox/Checkbox.stories.svelte +8 -8
- package/dist/components/checkbox/Checkbox.svelte +17 -17
- package/dist/components/collapsible/Collapsible.stories.svelte +26 -26
- package/dist/components/collapsible/components/collapsible-content.svelte +20 -20
- package/dist/components/collapsible/components/collapsible-trigger.svelte +12 -12
- package/dist/components/combobox/Combobox.stories.svelte +412 -412
- package/dist/components/combobox/components/combobox-add.svelte +8 -8
- package/dist/components/combobox/components/combobox-content.svelte +39 -39
- package/dist/components/combobox/components/combobox-indicator.svelte +1 -1
- package/dist/components/datepicker/DatePicker.stories.svelte +196 -196
- package/dist/components/datepicker/DatePicker.svelte +173 -173
- package/dist/components/divider/Divider.stories.svelte +7 -7
- package/dist/components/divider/Divider.svelte +9 -9
- package/dist/components/drawer/Drawer.stories.svelte +51 -51
- package/dist/components/drawer/Drawer.svelte +33 -33
- package/dist/components/drawer/DrawerLabel.svelte +10 -10
- package/dist/components/dropdown/Dropdown.stories.svelte +210 -210
- package/dist/components/dropdown/Dropdown.svelte +57 -57
- package/dist/components/dropdown/components/DropdownContent.svelte +16 -16
- package/dist/components/dropdown/components/DropdownMenu.svelte +10 -10
- package/dist/components/dropdown/components/DropdownTrigger.svelte +37 -37
- package/dist/components/dropdown/components/OutlinedButton.svelte +9 -9
- package/dist/components/empty-content/EmptyContent.stories.svelte +38 -38
- package/dist/components/empty-content/EmptyContent.svelte +12 -12
- package/dist/components/graphs/bar-chart/BarChart.stories.svelte +91 -91
- package/dist/components/graphs/bar-chart/BarChart.svelte +147 -147
- package/dist/components/graphs/bar-chart/StackedBarChart.stories.svelte +57 -57
- package/dist/components/graphs/bar-chart/StackedBarChart.svelte +198 -199
- package/dist/components/graphs/chart/Chart.stories.svelte +96 -96
- package/dist/components/graphs/chart/Chart.svelte +207 -207
- package/dist/components/graphs/line/LineChart.stories.svelte +138 -138
- package/dist/components/graphs/line/LineChart.svelte +140 -142
- package/dist/components/graphs/matrix/Matrix.stories.svelte +117 -117
- package/dist/components/graphs/matrix/Matrix.svelte +141 -141
- package/dist/components/graphs/multiline/MultiLineChart.stories.svelte +168 -168
- package/dist/components/graphs/multiline/MultiLineChart.svelte +236 -236
- package/dist/components/graphs/scatterplot/Scatterplot.stories.svelte +84 -84
- package/dist/components/graphs/scatterplot/Scatterplot.svelte +302 -302
- package/dist/components/graphs/utils/duration.d.ts +1 -0
- package/dist/components/graphs/utils/duration.js +33 -0
- package/dist/components/graphs/utils/tooltipFormatter.js +1 -1
- package/dist/components/icon-button/IconButton.stories.svelte +64 -64
- package/dist/components/icon-button/IconButton.svelte +88 -88
- package/dist/components/icons/AnalysisIcon.stories.svelte +18 -18
- package/dist/components/icons/AnalysisIcon.svelte +96 -96
- package/dist/components/icons/Icon.stories.svelte +111 -111
- package/dist/components/icons/Icon.svelte +17 -17
- package/dist/components/icons/PrincipalIcon.svelte +59 -59
- package/dist/components/icons/custom/Halo.svelte +31 -31
- package/dist/components/icons/custom/Well.svelte +27 -27
- package/dist/components/icons/index.js +1 -1
- package/dist/components/image/Image.svelte +42 -42
- package/dist/components/input/Input.stories.svelte +55 -55
- package/dist/components/input/Input.svelte +121 -121
- package/dist/components/label/Label.stories.svelte +18 -18
- package/dist/components/label/Label.svelte +11 -11
- package/dist/components/list/List.stories.svelte +84 -84
- package/dist/components/list/List.svelte +20 -20
- package/dist/components/logo/Logo.stories.svelte +15 -15
- package/dist/components/logo/Logo.svelte +30 -30
- package/dist/components/manual-cfu-counter/ManualCFUCounter.stories.svelte +102 -102
- package/dist/components/manual-cfu-counter/ManualCFUCounter.svelte +557 -557
- package/dist/components/manual-cfu-counter/test/ManualCFUCounterTestWrapper.svelte +11 -11
- package/dist/components/markdown/Markdown.stories.svelte +10 -10
- package/dist/components/markdown/Markdown.svelte +6 -6
- package/dist/components/modal/Modal.stories.svelte +29 -29
- package/dist/components/modal/Modal.svelte +71 -71
- package/dist/components/multi-cfu-counter/MultiCFUCounter.stories.svelte +201 -201
- package/dist/components/multi-cfu-counter/MultiCFUCounter.svelte +606 -606
- package/dist/components/multi-cfu-counter/test/MultiCFUCounterTestWrapper.svelte +17 -17
- package/dist/components/notification-popup/NotificationPopup.stories.svelte +18 -18
- package/dist/components/notification-popup/NotificationPopup.svelte +26 -26
- package/dist/components/notifications/Notifications.stories.svelte +101 -101
- package/dist/components/notifications/Notifications.svelte +9 -9
- package/dist/components/pill/Pill.stories.svelte +8 -8
- package/dist/components/pill/Pill.svelte +27 -27
- package/dist/components/progress-circle/ProgressCircle.stories.svelte +8 -8
- package/dist/components/progress-circle/ProgressCircle.svelte +54 -54
- package/dist/components/required-status-indicator/RequiredStatusIndicator.stories.svelte +18 -18
- package/dist/components/required-status-indicator/RequiredStatusIndicator.svelte +14 -14
- package/dist/components/segmented-control-buttons/ControlButton.svelte +36 -36
- package/dist/components/segmented-control-buttons/SegmentedControlButtons.stories.svelte +35 -35
- package/dist/components/segmented-control-buttons/SegmentedControlButtons.svelte +13 -13
- package/dist/components/select/Select.stories.svelte +77 -77
- package/dist/components/select/Select.svelte +114 -114
- package/dist/components/select-new/Select.stories.svelte +188 -188
- package/dist/components/select-new/components/Group.svelte +17 -17
- package/dist/components/select-new/components/MultiSelectTrigger.svelte +57 -57
- package/dist/components/select-new/components/SelectContent.svelte +22 -22
- package/dist/components/select-new/components/SelectGroupHeading.svelte +10 -10
- package/dist/components/select-new/components/SelectItem.svelte +25 -25
- package/dist/components/select-new/components/SelectTrigger.svelte +38 -38
- package/dist/components/sjsf-wrappers/SjsfNumberInputWrapper.svelte +76 -76
- package/dist/components/sjsf-wrappers/SjsfNumberInputWrapper.svelte.d.ts +1 -1
- package/dist/components/sjsf-wrappers/SjsfTextInputWrapper.svelte +53 -53
- package/dist/components/sjsf-wrappers/SjsfTextInputWrapper.svelte.d.ts +1 -1
- package/dist/components/sjsf-wrappers/sjsfCustomTheme.js +1 -1
- package/dist/components/skeleton-loader/SkeletonLoader.stories.svelte +32 -32
- package/dist/components/skeleton-loader/SkeletonLoader.svelte +10 -10
- package/dist/components/skeleton-loader/StatcardSkeleton.svelte +9 -9
- package/dist/components/skeleton-loader/components/Skeleton.svelte +7 -7
- package/dist/components/skeleton-loader/components/SkeletonImage.svelte +12 -12
- package/dist/components/slider/Slider.stories.svelte +23 -23
- package/dist/components/slider/Slider.svelte +107 -107
- package/dist/components/spinner/Spinner.stories.svelte +8 -8
- package/dist/components/spinner/Spinner.svelte +18 -18
- package/dist/components/stat-card/StatCard.stories.svelte +26 -26
- package/dist/components/stat-card/StatCard.svelte +128 -128
- package/dist/components/status-badge/StatusBadge.stories.svelte +365 -365
- package/dist/components/status-badge/StatusBadge.svelte +54 -54
- package/dist/components/stepper/Stepper.stories.svelte +219 -219
- package/dist/components/stepper/components/stepper-root.svelte +12 -12
- package/dist/components/stepper/components/stepper-step.svelte +83 -83
- package/dist/components/table/Table.stories.svelte +87 -87
- package/dist/components/table/Table.svelte +32 -32
- package/dist/components/table/components/TBody.svelte +7 -7
- package/dist/components/table/components/THead.svelte +7 -7
- package/dist/components/table/components/Td.svelte +8 -8
- package/dist/components/table/components/Th.svelte +8 -8
- package/dist/components/table/components/Tr.svelte +11 -11
- package/dist/components/tabs/Tabs.stories.svelte +20 -20
- package/dist/components/tabs/Tabs.svelte +8 -8
- package/dist/components/tabs/components/Content.svelte +8 -8
- package/dist/components/tabs/components/Tab.svelte +14 -14
- package/dist/components/tabs/components/Tabs.svelte +7 -7
- package/dist/components/tag/Tag.stories.svelte +57 -57
- package/dist/components/tag/Tag.svelte +95 -95
- package/dist/components/textarea/Textarea.stories.svelte +70 -70
- package/dist/components/textarea/Textarea.svelte +76 -76
- package/dist/components/toast/Toast.stories.svelte +204 -204
- package/dist/components/toast/Toast.svelte +53 -53
- package/dist/components/toggle/Toggle.stories.svelte +9 -9
- package/dist/components/toggle/Toggle.svelte +53 -53
- package/dist/components/toggle-icon-button/ToggleIconButton.stories.svelte +152 -152
- package/dist/components/toggle-icon-button/ToggleIconButton.svelte +99 -99
- package/dist/components/tooltip/Tooltip.stories.svelte +105 -105
- package/dist/components/tooltip/Tooltip.svelte +26 -26
- package/dist/fonts/index.js +1 -1
- package/dist/notifications.d.ts +1 -4
- package/dist/notifications.js +1 -1
- package/dist/tailwind-safelist.js +406 -406
- package/dist/tailwind.preset.js +10 -10
- package/dist/tokens/colors.js +18 -18
- package/dist/tokens/typography.js +6 -6
- package/dist/tokens.js +19 -19
- package/dist/types/fonts.d.ts +2 -2
- package/package.json +199 -198
|
@@ -1,142 +1,142 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import Matrix from './Matrix.svelte';
|
|
4
|
+
import { backgroundColor } from '../../../tokens';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const { Story } = defineMeta({
|
|
7
|
+
component: Matrix,
|
|
8
|
+
title: 'Design System/Graphs/Matrix',
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
});
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
// Create sample data for a confusion matrix
|
|
13
|
+
// Format: [row][col] where row = manual label, col = model prediction
|
|
14
|
+
const confusionMatrix = [
|
|
15
|
+
[
|
|
16
|
+
{ value: 2, row: 1, col: 0, backgroundColor: backgroundColor.danger }, // Top-left (Not TNTC/TNTC)
|
|
17
|
+
{ value: 123, row: 1, col: 1, backgroundColor: backgroundColor.success }, // Top-right (Not TNTC/Not TNTC)
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
{ value: 27, row: 0, col: 1, backgroundColor: backgroundColor.success }, // Bottom-right (TNTC/Not TNTC)
|
|
21
|
+
{ value: 8, row: 0, col: 0, backgroundColor: backgroundColor.danger }, // Bottom-left (TNTC/TNTC)
|
|
22
|
+
],
|
|
23
|
+
];
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const rowLabels = ['TNTC', 'Not TNTC'];
|
|
26
|
+
const colLabels = ['TNTC', 'Not TNTC'];
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
function handleCellClick(cell: any) {
|
|
29
|
+
console.log('Cell clicked:', cell);
|
|
30
|
+
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
function handleCellHover(cell: any) {
|
|
33
|
+
console.log('Cell hover:', cell);
|
|
34
|
+
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
36
|
+
// Sample data with more categories
|
|
37
|
+
const multiclassMatrix = [
|
|
38
|
+
[
|
|
39
|
+
{ value: 45, row: 0, col: 0, backgroundColor: backgroundColor.success },
|
|
40
|
+
{ value: 12, row: 0, col: 1, backgroundColor: backgroundColor.neutral },
|
|
41
|
+
{ value: 3, row: 0, col: 2, backgroundColor: backgroundColor.neutral },
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
{ value: 8, row: 1, col: 0, backgroundColor: backgroundColor.neutral },
|
|
45
|
+
{ value: 78, row: 1, col: 1, backgroundColor: backgroundColor.success },
|
|
46
|
+
{ value: 5, row: 1, col: 2, backgroundColor: backgroundColor.neutral },
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
{ value: 2, row: 2, col: 0, backgroundColor: backgroundColor.neutral },
|
|
50
|
+
{ value: 6, row: 2, col: 1, backgroundColor: backgroundColor.neutral },
|
|
51
|
+
{ value: 52, row: 2, col: 2, backgroundColor: backgroundColor.success },
|
|
52
|
+
],
|
|
53
|
+
];
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const multiclassLabels = ['Class A', 'Class B', 'Class C'];
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
// Custom colored matrix
|
|
58
|
+
const customColorMatrix = [
|
|
59
|
+
[
|
|
60
|
+
{ value: 8, row: 0, col: 0, backgroundColor: 'rgba(200, 250, 205, 0.8)' }, // Custom green
|
|
61
|
+
{ value: 27, row: 0, col: 1, backgroundColor: 'rgba(255, 235, 235, 0.8)' }, // Custom red tint
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
{ value: 2, row: 1, col: 0, backgroundColor: 'rgba(255, 235, 235, 0.8)' },
|
|
65
|
+
{ value: 123, row: 1, col: 1, backgroundColor: 'rgba(200, 250, 205, 0.8)' },
|
|
66
|
+
],
|
|
67
|
+
];
|
|
68
68
|
</script>
|
|
69
69
|
|
|
70
70
|
<Story name="TNTC Confusion Matrix" asChild>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
<div class="h-[500px] w-full">
|
|
72
|
+
<Matrix
|
|
73
|
+
data={confusionMatrix}
|
|
74
|
+
{rowLabels}
|
|
75
|
+
{colLabels}
|
|
76
|
+
xAxisName="Model count"
|
|
77
|
+
yAxisName="Manual count"
|
|
78
|
+
onCellClick={handleCellClick}
|
|
79
|
+
onCellHover={handleCellHover}
|
|
80
|
+
/>
|
|
81
|
+
</div>
|
|
82
82
|
</Story>
|
|
83
83
|
|
|
84
84
|
<Story name="Multiple Classes" asChild>
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
<div class="h-[500px] w-full">
|
|
86
|
+
<Matrix
|
|
87
|
+
data={multiclassMatrix}
|
|
88
|
+
rowLabels={multiclassLabels}
|
|
89
|
+
colLabels={multiclassLabels}
|
|
90
|
+
invertYAxis={true}
|
|
91
|
+
xAxisName="Model count"
|
|
92
|
+
yAxisName="Manual count"
|
|
93
|
+
/>
|
|
94
|
+
</div>
|
|
95
95
|
</Story>
|
|
96
96
|
|
|
97
97
|
<Story name="Non-Inverted Axis" asChild>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
<div class="h-[500px] w-full">
|
|
99
|
+
<Matrix
|
|
100
|
+
data={confusionMatrix}
|
|
101
|
+
{rowLabels}
|
|
102
|
+
{colLabels}
|
|
103
|
+
invertYAxis={false}
|
|
104
|
+
xAxisName="Model count"
|
|
105
|
+
yAxisName="Manual count"
|
|
106
|
+
/>
|
|
107
|
+
</div>
|
|
108
108
|
</Story>
|
|
109
109
|
|
|
110
110
|
<Story name="Custom Colors" asChild>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
111
|
+
<div class="h-[500px] w-full">
|
|
112
|
+
<Matrix
|
|
113
|
+
data={customColorMatrix}
|
|
114
|
+
{rowLabels}
|
|
115
|
+
{colLabels}
|
|
116
|
+
invertYAxis={true}
|
|
117
|
+
xAxisName="Model count"
|
|
118
|
+
yAxisName="Manual count"
|
|
119
|
+
/>
|
|
120
|
+
<div class="mt-4 text-center text-sm">
|
|
121
|
+
<p>Using custom colors directly in the cell objects</p>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
124
|
</Story>
|
|
125
125
|
|
|
126
126
|
<Story name="Semantic Colors" asChild>
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
127
|
+
<div class="h-[500px] w-full">
|
|
128
|
+
<Matrix
|
|
129
|
+
data={confusionMatrix}
|
|
130
|
+
{rowLabels}
|
|
131
|
+
{colLabels}
|
|
132
|
+
invertYAxis={true}
|
|
133
|
+
xAxisName="Model count"
|
|
134
|
+
yAxisName="Manual count"
|
|
135
|
+
/>
|
|
136
|
+
<div class="mt-4 text-center text-sm">
|
|
137
|
+
<p>Using semantic colors from tokens:</p>
|
|
138
|
+
<p>Diagonal cells: backgroundColor.success</p>
|
|
139
|
+
<p>Off-diagonal cells: backgroundColor.neutral</p>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
142
|
</Story>
|
|
@@ -1,149 +1,149 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
export interface Cell {
|
|
3
|
+
value: number;
|
|
4
|
+
row: number;
|
|
5
|
+
col: number;
|
|
6
|
+
highlighted?: boolean;
|
|
7
|
+
backgroundColor?: string;
|
|
8
|
+
hideAxisNames?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type MatrixChartProps = {
|
|
12
|
+
/**
|
|
13
|
+
* Matrix data as a 2D array (cells[row][col])
|
|
14
|
+
*/
|
|
15
|
+
data: Cell[][];
|
|
16
|
+
rowLabels: string[];
|
|
17
|
+
colLabels: string[];
|
|
18
|
+
onCellClick?: (cell: Cell) => void;
|
|
19
|
+
onCellHover?: (cell: Cell) => void;
|
|
20
|
+
invertYAxis?: boolean;
|
|
21
|
+
hideAxisNames?: boolean;
|
|
22
|
+
} & Omit<GenericChartProps, 'timeIndex'>;
|
|
23
23
|
</script>
|
|
24
24
|
|
|
25
25
|
<script lang="ts">
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
26
|
+
import { backgroundColor } from '../../../tokens';
|
|
27
|
+
import type { GenericChartProps } from '../chart/Chart.svelte';
|
|
28
|
+
|
|
29
|
+
const {
|
|
30
|
+
data,
|
|
31
|
+
rowLabels,
|
|
32
|
+
colLabels,
|
|
33
|
+
xAxisName,
|
|
34
|
+
yAxisName,
|
|
35
|
+
width = '100%',
|
|
36
|
+
height = '100%',
|
|
37
|
+
onCellClick,
|
|
38
|
+
onCellHover,
|
|
39
|
+
loading = false,
|
|
40
|
+
invertYAxis = false,
|
|
41
|
+
hideAxisNames = false,
|
|
42
|
+
}: MatrixChartProps = $props();
|
|
43
|
+
|
|
44
|
+
let container: HTMLElement | undefined = $state();
|
|
45
|
+
|
|
46
|
+
function getCellWithColor(cell: Cell): Cell {
|
|
47
|
+
let defaultBackgroundColor: string;
|
|
48
|
+
|
|
49
|
+
if (data.length === 2 && data[0].length === 2) {
|
|
50
|
+
const isDiagonal = cell.row === cell.col;
|
|
51
|
+
defaultBackgroundColor = isDiagonal ? backgroundColor.success : backgroundColor.neutral;
|
|
52
|
+
} else {
|
|
53
|
+
defaultBackgroundColor = backgroundColor.neutral;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
...cell,
|
|
58
|
+
backgroundColor: cell.backgroundColor || defaultBackgroundColor,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let displayData = $derived(
|
|
63
|
+
invertYAxis
|
|
64
|
+
? [...data].reverse().map((row) => row.map((cell) => getCellWithColor(cell)))
|
|
65
|
+
: data.map((row) => row.map((cell) => getCellWithColor(cell)))
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
let displayRowLabels = $derived(invertYAxis ? [...rowLabels].reverse() : rowLabels);
|
|
69
|
+
|
|
70
|
+
function handleCellClick(cell: Cell) {
|
|
71
|
+
if (onCellClick) {
|
|
72
|
+
onCellClick(cell);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function handleCellHover(cell: Cell) {
|
|
77
|
+
if (onCellHover) {
|
|
78
|
+
onCellHover(cell);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
81
|
</script>
|
|
82
82
|
|
|
83
83
|
<div class="flex h-full w-full flex-col" style="width: {width}; height: {height};">
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
84
|
+
{#if xAxisName && !hideAxisNames}
|
|
85
|
+
<!-- 80px is the width of the yAxisName, 72px is the width of the yAxisName, 72px is the yLabels -->
|
|
86
|
+
<div class="flex w-[calc(100%-72px-72px)] items-center self-end text-center">
|
|
87
|
+
<div class="mb-2 inline-block w-full border-b pb-3 text-sm font-normal text-secondary">
|
|
88
|
+
{xAxisName}
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
{/if}
|
|
92
|
+
|
|
93
|
+
<div class="flex h-full flex-1 flex-row overflow-hidden">
|
|
94
|
+
{#if yAxisName && !hideAxisNames}
|
|
95
|
+
<!-- 26px is the height of the xAxisName -->
|
|
96
|
+
<div class="mr-2 flex h-[calc(100%-26px)] w-12 items-center self-end border-r">
|
|
97
|
+
<div class="-rotate-90 transform whitespace-nowrap text-sm font-normal text-secondary">
|
|
98
|
+
{yAxisName}
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
{/if}
|
|
102
|
+
|
|
103
|
+
<div bind:this={container} class="relative flex flex-1 flex-col">
|
|
104
|
+
<div class="ml-20 flex h-6">
|
|
105
|
+
{#each colLabels as label}
|
|
106
|
+
<div class="flex-1 pr-1 text-center text-sm text-secondary">
|
|
107
|
+
{label}
|
|
108
|
+
</div>
|
|
109
|
+
{/each}
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<div class="flex flex-1">
|
|
113
|
+
<div class="flex w-20 flex-col">
|
|
114
|
+
{#each displayRowLabels as label}
|
|
115
|
+
<div class="flex flex-1 items-center justify-end pr-2 text-sm text-secondary">
|
|
116
|
+
{label}
|
|
117
|
+
</div>
|
|
118
|
+
{/each}
|
|
119
|
+
</div>
|
|
120
|
+
<div
|
|
121
|
+
class="grid flex-1"
|
|
122
|
+
style="grid-template-columns: repeat({colLabels.length}, 1fr); grid-template-rows: repeat({rowLabels.length}, 1fr);"
|
|
123
|
+
>
|
|
124
|
+
{#each displayData as row}
|
|
125
|
+
{#each row as cell}
|
|
126
|
+
<button
|
|
127
|
+
class="flex items-center justify-center border border-white"
|
|
128
|
+
style="background-color: {cell.backgroundColor};"
|
|
129
|
+
onclick={() => handleCellClick(cell)}
|
|
130
|
+
onmouseover={() => handleCellHover(cell)}
|
|
131
|
+
onfocus={() => handleCellHover(cell)}
|
|
132
|
+
data-row={cell.row}
|
|
133
|
+
data-col={cell.col}
|
|
134
|
+
>
|
|
135
|
+
<span class="text-base font-bold text-primary">{cell.value}</span>
|
|
136
|
+
</button>
|
|
137
|
+
{/each}
|
|
138
|
+
{/each}
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
{#if loading}
|
|
145
|
+
<div class="absolute inset-0 flex items-center justify-center bg-white bg-opacity-70">
|
|
146
|
+
<div class="text-lg">Loading...</div>
|
|
147
|
+
</div>
|
|
148
|
+
{/if}
|
|
149
149
|
</div>
|