Skip to content

Commit 9793242

Browse files
author
Sebastian Flick
committed
introduce new scale for chunks
1 parent 174a78b commit 9793242

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/routes/Brush.svelte

+10-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
let marginRight = 20;
88
let marginBottom = 20;
99
let marginLeft = 20;
10+
let chunkWidth = 18;
1011
export let DATA_MIN = 1;
1112
export let DATA_MAX = 822;
1213
@@ -35,15 +36,15 @@
3536
]
3637
}
3738
];
38-
39-
const pointsPerRect = 10;
40-
const chunks = Math.floor(DATA_MAX / pointsPerRect);
39+
$: numChunks = Math.max(Math.floor((width - marginLeft - marginRight) / chunkWidth), 1);
40+
$: pointsPerRect = Math.ceil((DATA_MAX - DATA_MIN) / numChunks);
41+
$: console.log(width, numChunks, pointsPerRect);
4142
4243
// create chunks: each chunk is a number counting the number of true values in the chunk
43-
const chunkedData = data.map((d) => {
44-
const chunked = new Array(chunks).fill(0);
44+
$: chunkedData = data.map((d) => {
45+
const chunked = new Array(numChunks).fill(0);
4546
46-
for (let i = 0; i < chunks; i++) {
47+
for (let i = 0; i < numChunks; i++) {
4748
const start = i * pointsPerRect;
4849
const end = Math.min((i + 1) * pointsPerRect, DATA_MAX);
4950
@@ -67,6 +68,7 @@
6768
)
6869
.paddingOuter(0.05)
6970
.round(true);
71+
$: xChunk = d3.scaleLinear([0, numChunks], [marginLeft, width - marginRight]);
7072
$: x = d3.scaleLinear([DATA_MIN, DATA_MAX], [marginLeft, width - marginRight]);
7173
$: d3.select(gy).call(d3.axisLeft(y));
7274
$: d3.select(gx).call(d3.axisBottom(x));
@@ -78,8 +80,8 @@
7880
{#each chunkedData as d}
7981
<g>
8082
{#each d.values as v, j}
81-
{@const start = x(j * pointsPerRect + 1)}
82-
{@const end = x((j + 1) * pointsPerRect)}
83+
{@const start = xChunk(j)}
84+
{@const end = xChunk(j + 1)}
8385
<rect
8486
x={start}
8587
y={y(d.label)}

0 commit comments

Comments
 (0)