Skip to content

Commit e73921c

Browse files
committed
refactor: make contigousData more readable
1 parent 8d7de71 commit e73921c

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/routes/Detail.svelte

+16-17
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,26 @@
134134
};
135135
let contigousData = $derived(
136136
data.map((d) => {
137-
if (d.label === 'fr') {
138-
return d;
139-
}
137+
// skip for label 'fr'
138+
if (d.label === 'fr') return d;
139+
140+
// init
140141
let contiguousRanges = [];
141-
let start = 0;
142+
let start = null;
143+
144+
//
142145
for (let i = 0; i < d.values.length; i++) {
143-
if (d.values[i]) {
144-
if (start === 0) {
145-
// console.log(d.label, i, data_start);
146-
start = i + data_start;
147-
}
148-
} else {
149-
if (start !== 0) {
150-
contiguousRanges.push([start, i + data_start - 1]);
151-
start = 0;
152-
}
146+
if (d.values[i] && start === null) {
147+
// start a new range
148+
start = i + selection.start;
149+
} else if (!d.values[i] && start !== null) {
150+
contiguousRanges.push([start, i + selection.start - 1]);
151+
start = null; // reset start
153152
}
154153
}
155-
if (start !== 0) {
156-
// console.log(d.label, start, d.values.length - 1 + data_start);
157-
contiguousRanges.push([start, d.values.length - 1 + data_start]);
154+
// if range is still open at the end
155+
if (start !== null) {
156+
contiguousRanges.push([start, d.values.length + selection.start - 1]);
158157
}
159158
return {
160159
label: d.label,

0 commit comments

Comments
 (0)