|
7 | 7 | let marginRight = 20;
|
8 | 8 | let marginBottom = 20;
|
9 | 9 | let marginLeft = 20;
|
| 10 | + let chunkWidth = 18; |
10 | 11 | export let DATA_MIN = 1;
|
11 | 12 | export let DATA_MAX = 822;
|
12 | 13 |
|
|
35 | 36 | ]
|
36 | 37 | }
|
37 | 38 | ];
|
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); |
41 | 42 |
|
42 | 43 | // 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); |
45 | 46 |
|
46 |
| - for (let i = 0; i < chunks; i++) { |
| 47 | + for (let i = 0; i < numChunks; i++) { |
47 | 48 | const start = i * pointsPerRect;
|
48 | 49 | const end = Math.min((i + 1) * pointsPerRect, DATA_MAX);
|
49 | 50 |
|
|
67 | 68 | )
|
68 | 69 | .paddingOuter(0.05)
|
69 | 70 | .round(true);
|
| 71 | + $: xChunk = d3.scaleLinear([0, numChunks], [marginLeft, width - marginRight]); |
70 | 72 | $: x = d3.scaleLinear([DATA_MIN, DATA_MAX], [marginLeft, width - marginRight]);
|
71 | 73 | $: d3.select(gy).call(d3.axisLeft(y));
|
72 | 74 | $: d3.select(gx).call(d3.axisBottom(x));
|
|
78 | 80 | {#each chunkedData as d}
|
79 | 81 | <g>
|
80 | 82 | {#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)} |
83 | 85 | <rect
|
84 | 86 | x={start}
|
85 | 87 | y={y(d.label)}
|
|
0 commit comments