Skip to content

Commit 5d4500c

Browse files
committed
Merge branch 'main' into 412-user-guide-and-api-documentation
2 parents fc5d1b4 + 2cba652 commit 5d4500c

File tree

6 files changed

+71
-11
lines changed

6 files changed

+71
-11
lines changed

skore-ui/src/ShareApp.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function getItemSubtitle(created_at: Date, updated_at: Date) {
3838
:columns="data.columns"
3939
:data="data.data"
4040
:index="data.index"
41+
:indexNames="data.indexNames"
4142
/>
4243
<ImageWidget
4344
v-if="['image/svg+xml', 'image/png', 'image/jpeg', 'image/webp'].includes(mediaType)"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"index": [["france", "paris", "1"]],
3+
"columns": ["age", "number", "gender"],
4+
"data": [
5+
[
6+
">70",
7+
"loremipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitamet loremipsumdolorsitamet loremipsumdolorsitamet",
8+
"M"
9+
]
10+
],
11+
"index_names": ["country", "city", "district"],
12+
"column_names": [null]
13+
}

skore-ui/src/components/DataFrameWidget.vue

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface DataFrameWidgetProps {
88
index: any[];
99
columns: any[];
1010
data: any[][];
11+
indexNames: any[];
1112
}
1213
const props = defineProps<DataFrameWidgetProps>();
1314
@@ -61,6 +62,14 @@ const visibleRows = computed(() => {
6162
return rows.value.slice(pageStart.value, pageEnd.value);
6263
});
6364
65+
const indexNamesColSpan = computed(() => {
66+
const hasIndexNames = props.indexNames.some((name) => name !== null);
67+
if (hasIndexNames) {
68+
return props.indexNames.length;
69+
}
70+
return 1;
71+
});
72+
6473
function nextPage() {
6574
if (currentPage.value < totalPages.value - 1) {
6675
currentPage.value++;
@@ -90,13 +99,31 @@ watch([() => toValue(props.data), () => toValue(props.columns)], () => {
9099
<table>
91100
<thead>
92101
<tr>
93-
<th>index</th>
102+
<th :colspan="indexNamesColSpan">index</th>
94103
<th v-for="(name, i) in props.columns" :key="i">{{ name }}</th>
95104
</tr>
105+
<tr v-if="indexNamesColSpan > 1">
106+
<th v-for="(name, i) in props.indexNames" :key="i" class="named-index">
107+
{{ name }}
108+
</th>
109+
<th v-for="(name, i) in props.columns" :key="i"></th>
110+
</tr>
96111
</thead>
97112
<tbody>
98113
<tr v-for="(row, i) in visibleRows" :key="i">
99-
<td v-for="(value, i) in row" :key="i">{{ value }}</td>
114+
<template v-if="indexNamesColSpan === 1">
115+
<td v-for="(value, i) in row" :key="i" :colspan="i === 0 ? indexNamesColSpan : 1">
116+
{{ value }}
117+
</td>
118+
</template>
119+
<template v-else>
120+
<td v-for="(value, i) in row[0].split(', ')" :key="i" class="named-index">
121+
{{ value }}
122+
</td>
123+
<td v-for="(value, i) in row.slice(1)" :key="i">
124+
{{ value }}
125+
</td>
126+
</template>
100127
</tr>
101128
</tbody>
102129
</table>
@@ -155,19 +182,24 @@ watch([() => toValue(props.data), () => toValue(props.columns)], () => {
155182
& tr {
156183
& th {
157184
padding: var(--spacing-padding-small);
185+
text-align: right;
158186
159-
&:first-child {
187+
&:first-child,
188+
&.named-index {
189+
background-color: var(--background-color-elevated);
190+
}
191+
192+
&[colspan="1"]:first-child:not(.named-index) {
160193
position: sticky;
161194
left: 0;
162-
background-color: var(--background-color-elevated);
163-
text-align: left;
164195
}
165196
}
166197
}
167198
}
168199
169200
& tbody {
170201
& tr {
202+
position: relative;
171203
padding: var(--spacing-padding-small);
172204
173205
& td {
@@ -176,16 +208,18 @@ watch([() => toValue(props.data), () => toValue(props.columns)], () => {
176208
font-size: var(--text-size-highlight);
177209
font-weight: var(--text-weight-highlight);
178210
179-
&:first-child {
180-
position: sticky;
181-
left: 0;
182-
width: auto;
211+
&:first-child,
212+
&.named-index {
183213
background-color: var(--background-color-elevated);
184214
color: var(--text-color-normal);
185215
font-size: var(--text-size-normal);
186216
font-weight: var(--text-weight-normal);
187217
text-align: left;
188-
white-space: nowrap;
218+
}
219+
220+
&:first-child:not(.named-index) {
221+
position: sticky;
222+
left: 0;
189223
}
190224
}
191225
@@ -195,6 +229,7 @@ watch([() => toValue(props.data), () => toValue(props.columns)], () => {
195229
}
196230
}
197231
232+
/* stylelint-disable no-descending-specificity */
198233
& > thead > tr:not(:last-child) > th,
199234
& > thead > tr:not(:last-child) > td,
200235
& > tbody > tr:not(:last-child) > th,

skore-ui/src/views/ComponentsView.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import datatable from "@/assets/fixtures/datatable.json";
77
import htmlSnippet from "@/assets/fixtures/html-snippet.html?raw";
88
import markdownString from "@/assets/fixtures/markdown.md?raw";
99
import multiIndexDatatable from "@/assets/fixtures/multi-index-datatable.json";
10+
import namedIndexDatatable from "@/assets/fixtures/named-index-datatable.json";
1011
import spec from "@/assets/fixtures/vega.json";
1112
1213
import DataFrameWidget from "@/components/DataFrameWidget.vue";
@@ -221,12 +222,21 @@ const isCached = ref(false);
221222
:index="datatable.index"
222223
:columns="datatable.columns"
223224
:data="datatable.data"
225+
:index-names="datatable.index_names"
224226
/>
225227
<div>multi index</div>
226228
<DataFrameWidget
227229
:index="multiIndexDatatable.index"
228230
:columns="multiIndexDatatable.columns"
229231
:data="multiIndexDatatable.data"
232+
:index-names="multiIndexDatatable.index_names"
233+
/>
234+
<div>named index</div>
235+
<DataFrameWidget
236+
:index="namedIndexDatatable.index"
237+
:columns="namedIndexDatatable.columns"
238+
:data="namedIndexDatatable.data"
239+
:index-names="namedIndexDatatable.index_names"
230240
/>
231241
</TabsItem>
232242
<TabsItem :value="3">

skore-ui/src/views/project/ProjectView.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ onBeforeUnmount(() => {
126126
:columns="data.columns"
127127
:data="data.data"
128128
:index="data.index"
129+
:indexNames="data.indexNames"
129130
/>
130131
<ImageWidget
131132
v-if="

skore-ui/tests/components/DataFrameWidget.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function generateFakeProps(numItems: number) {
2020
]);
2121
}
2222

23-
return { index, columns, data };
23+
return { index, columns, data, indexNames: [] };
2424
}
2525

2626
function mountComponent(props: any) {

0 commit comments

Comments
 (0)