@reshape-biotech/design-system 2.7.31 → 2.7.32

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.
@@ -9,16 +9,39 @@
9
9
  tags: ['autodocs'],
10
10
  });
11
11
 
12
- // Create sample data for a confusion matrix
13
12
  // Format: [row][col] where row = manual label, col = model prediction
14
13
  const confusionMatrix = [
15
14
  [
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)
15
+ {
16
+ value: 2,
17
+ row: 1,
18
+ col: 0,
19
+ classificationLabel: 'False positive',
20
+ percent: 1.5,
21
+ },
22
+ {
23
+ value: 123,
24
+ row: 1,
25
+ col: 1,
26
+ classificationLabel: 'True negative',
27
+ percent: 92.2,
28
+ },
18
29
  ],
19
30
  [
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)
31
+ {
32
+ value: 27,
33
+ row: 0,
34
+ col: 1,
35
+ classificationLabel: 'True positive',
36
+ percent: 77.1,
37
+ },
38
+ {
39
+ value: 8,
40
+ row: 0,
41
+ col: 0,
42
+ classificationLabel: 'False negative',
43
+ percent: 0.5,
44
+ },
22
45
  ],
23
46
  ];
24
47
 
@@ -73,6 +96,7 @@
73
96
  data={confusionMatrix}
74
97
  {rowLabels}
75
98
  {colLabels}
99
+ invertYAxis
76
100
  xAxisName="Model count"
77
101
  yAxisName="Manual count"
78
102
  onCellClick={handleCellClick}
@@ -122,21 +146,3 @@
122
146
  </div>
123
147
  </div>
124
148
  </Story>
125
-
126
- <Story name="Semantic Colors" asChild>
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
- </Story>
@@ -6,12 +6,11 @@
6
6
  highlighted?: boolean;
7
7
  backgroundColor?: string;
8
8
  hideAxisNames?: boolean;
9
+ classificationLabel?: string;
10
+ percent?: number;
9
11
  }
10
12
 
11
13
  export type MatrixChartProps = {
12
- /**
13
- * Matrix data as a 2D array (cells[row][col])
14
- */
15
14
  data: Cell[][];
16
15
  rowLabels: string[];
17
16
  colLabels: string[];
@@ -24,6 +23,7 @@
24
23
 
25
24
  <script lang="ts">
26
25
  import { backgroundColor } from '../../../tokens';
26
+ import { colors } from '../../../tokens/colors';
27
27
  import type { GenericChartProps } from '../chart/Chart.svelte';
28
28
 
29
29
  const {
@@ -44,18 +44,25 @@
44
44
  let container: HTMLElement | undefined = $state();
45
45
 
46
46
  function getCellWithColor(cell: Cell): Cell {
47
- let defaultBackgroundColor: string;
47
+ if (cell.backgroundColor) {
48
+ return { ...cell };
49
+ }
50
+
51
+ let defaultBackgroundColor = backgroundColor.neutral;
48
52
 
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;
53
+ if (cell.percent !== undefined) {
54
+ const baseColor = colors.blue[5].default;
55
+ const minAlpha = Math.round(0.05 * 255);
56
+ const maxAlpha = Math.round(0.5 * 255);
57
+ const alphaRange = maxAlpha - minAlpha;
58
+ const alpha = Math.round(minAlpha + (cell.percent / 100) * alphaRange);
59
+ const alphaHex = alpha.toString(16).padStart(2, '0');
60
+ defaultBackgroundColor = `${baseColor}${alphaHex}`;
54
61
  }
55
62
 
56
63
  return {
57
64
  ...cell,
58
- backgroundColor: cell.backgroundColor || defaultBackgroundColor,
65
+ backgroundColor: defaultBackgroundColor,
59
66
  };
60
67
  }
61
68
 
@@ -92,8 +99,7 @@
92
99
 
93
100
  <div class="flex h-full flex-1 flex-row overflow-hidden">
94
101
  {#if yAxisName && !hideAxisNames}
95
- <!-- 26px is the height of the xAxisName -->
96
- <div class="mr-2 flex h-[calc(100%-26px)] w-10 items-center self-end border-r">
102
+ <div class="mr-2 flex h-[calc(100%)] items-center self-end border-r">
97
103
  <div class="-rotate-90 transform whitespace-nowrap text-sm font-normal text-secondary">
98
104
  {yAxisName}
99
105
  </div>
@@ -101,14 +107,6 @@
101
107
  {/if}
102
108
 
103
109
  <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
110
  <div class="flex flex-1">
113
111
  <div class="flex w-24 flex-col">
114
112
  {#each displayRowLabels as label}
@@ -124,7 +122,7 @@
124
122
  {#each displayData as row}
125
123
  {#each row as cell}
126
124
  <button
127
- class="flex items-center justify-center border border-white"
125
+ class="m-0.5 flex flex-col items-center justify-center rounded-lg border border p-1 text-center"
128
126
  style="background-color: {cell.backgroundColor};"
129
127
  onclick={() => handleCellClick(cell)}
130
128
  onmouseover={() => handleCellHover(cell)}
@@ -132,12 +130,32 @@
132
130
  data-row={cell.row}
133
131
  data-col={cell.col}
134
132
  >
135
- <span class="text-base font-bold text-primary">{cell.value}</span>
133
+ <div class="flex flex-col gap-2">
134
+ {#if cell.percent !== undefined}
135
+ <p class="text-xl text-primary">
136
+ {Math.round(cell.percent)}%
137
+ </p>
138
+ {/if}
139
+ {#if cell.classificationLabel !== undefined}
140
+ <span class="text-secondary">
141
+ {cell.classificationLabel}
142
+ </span>
143
+ {:else}
144
+ <span class="text-secondary">{cell.value}</span>
145
+ {/if}
146
+ </div>
136
147
  </button>
137
148
  {/each}
138
149
  {/each}
139
150
  </div>
140
151
  </div>
152
+ <div class="ml-20 flex h-6 p-2">
153
+ {#each colLabels as label}
154
+ <div class="flex-1 pr-1 text-center text-sm text-secondary">
155
+ {label}
156
+ </div>
157
+ {/each}
158
+ </div>
141
159
  </div>
142
160
  </div>
143
161
 
@@ -5,11 +5,10 @@ export interface Cell {
5
5
  highlighted?: boolean;
6
6
  backgroundColor?: string;
7
7
  hideAxisNames?: boolean;
8
+ classificationLabel?: string;
9
+ percent?: number;
8
10
  }
9
11
  export type MatrixChartProps = {
10
- /**
11
- * Matrix data as a 2D array (cells[row][col])
12
- */
13
12
  data: Cell[][];
14
13
  rowLabels: string[];
15
14
  colLabels: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reshape-biotech/design-system",
3
- "version": "2.7.31",
3
+ "version": "2.7.32",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build",
@@ -388,6 +388,7 @@
388
388
  "eslint-config-prettier": "^9.1.0",
389
389
  "eslint-plugin-svelte": "^3.0.0",
390
390
  "globals": "^15.0.0",
391
+ "jsdom": "^27.0.1",
391
392
  "luxon": "^3.5.0",
392
393
  "marked": "^15.0.0",
393
394
  "phosphor-svelte": "^3.0.1",