Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Commit 474a83b

Browse files
Switch treemap to vertical slice layout on narrow screens
Below 600px width, use d3.treemapSlice instead of squarify so each taxonomy gets a full-width horizontal bar. Prevents text overflow and keeps all labels readable on mobile.
1 parent fa841eb commit 474a83b

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

templates/_main.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,16 @@ window.addEventListener("load", function() {
375375
try {
376376
var hpData = JSON.parse(hpDataEl.textContent.trim());
377377
var hpW = hpChartEl.clientWidth || 800;
378-
var hpH = 300;
379378
var children = (hpData.taxonomies || []).map(function(t) {
380379
return { name: t.name, value: t.count, slug: t.slug };
381380
});
382381
if (children.length > 0) {
382+
var useSlice = hpW < 600;
383+
var hpH = useSlice ? children.length * 44 + 8 : 300;
383384
var root = d3.hierarchy({ name: "root", children: children }).sum(function(d) { return d.value || 0; }).sort(function(a, b) { return b.value - a.value; });
384-
d3.treemap().size([hpW, hpH]).padding(3).round(true)(root);
385+
var tm = d3.treemap().size([hpW, hpH]).padding(3).round(true);
386+
if (useSlice) tm.tile(d3.treemapSlice);
387+
tm(root);
385388
var colors = ["#71B9BC", "#5C9699", "#7CCE86", "#D0A27D", "#E589C6", "#8E8CE9", "#A3A2ED", "#505050"];
386389
var svg = d3.select(hpChartEl).append("svg").attr("width", hpW).attr("height", hpH);
387390
var cell = svg.selectAll("g").data(root.leaves()).enter().append("g")

0 commit comments

Comments
 (0)