Skip to content

Commit bea9453

Browse files
Add Column Spacing slider to toctree graph (#37)
1 parent 305ec44 commit bea9453

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Changelog
99
- Fix TypeError with mixed Path and string types for Python 3.12 compatibility
1010
- Fix AttributeError when title is missing in toctrees
1111
- Fix KeyError during failed builds when accessing root_doc
12+
- Add Column Spacing slider to toctree graph
1213

1314
0.8.0
1415
-----

sphinx_visualized/static/html/toctree-graph.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,19 @@
8282

8383
<div class="bg-card p-3 md:p-4 rounded-lg shadow-lg mb-2 border border-border" id="controls-panel">
8484
<h3 class="m-0 text-base md:text-lg font-semibold text-foreground tracking-tight">Controls</h3>
85-
<div class="flex gap-2 mt-2">
86-
<button id="expand-all-btn" class="flex-1 px-3 md:px-4 py-2 bg-card border border-border rounded-md text-xs md:text-sm hover:bg-accent hover:shadow transition-all duration-200 font-medium">Expand All</button>
87-
<button id="collapse-all-btn" class="flex-1 px-3 md:px-4 py-2 bg-card border border-border rounded-md text-xs md:text-sm hover:bg-accent hover:shadow transition-all duration-200 font-medium">Collapse All</button>
85+
<div class="mt-2">
86+
<h4 class="m-0 mb-2 text-sm font-medium text-foreground">Expand/Collapse</h4>
87+
<div class="flex gap-2">
88+
<button id="expand-all-btn" class="flex-1 px-3 md:px-4 py-2 bg-card border border-border rounded-md text-xs md:text-sm hover:bg-accent hover:shadow transition-all duration-200 font-medium">Expand All</button>
89+
<button id="collapse-all-btn" class="flex-1 px-3 md:px-4 py-2 bg-card border border-border rounded-md text-xs md:text-sm hover:bg-accent hover:shadow transition-all duration-200 font-medium">Collapse All</button>
90+
</div>
91+
</div>
92+
<div class="mt-3">
93+
<h4 class="m-0 mb-2 text-sm font-medium text-foreground">Column Spacing</h4>
94+
<div class="flex items-center gap-2">
95+
<input type="range" id="spacing-slider" min="50" max="600" value="200" step="25" class="flex-1 h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer accent-primary" />
96+
<span id="spacing-value" class="text-xs text-muted-foreground font-medium w-12 text-right">200px</span>
97+
</div>
8898
</div>
8999
</div>
90100
</div>

sphinx_visualized/static/js/toctree-graph.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,22 @@ window.addEventListener('DOMContentLoaded', async () => {
8686
// Rows are separated by dx pixels, columns by dy pixels
8787
const root = d3.hierarchy(window.toctree);
8888
const dx = 30; // Increased vertical spacing (was 20)
89-
const dy = 200; // Increased horizontal spacing for better visibility
89+
90+
// Load column spacing from localStorage or use default
91+
let dy = parseInt(localStorage.getItem('toctree-column-spacing')) || 200;
92+
93+
// Update the spacing display and slider
94+
const updateSpacingDisplay = () => {
95+
const spacingValueEl = document.getElementById('spacing-value');
96+
const spacingSlider = document.getElementById('spacing-slider');
97+
if (spacingValueEl) {
98+
spacingValueEl.textContent = `${dy}px`;
99+
}
100+
if (spacingSlider) {
101+
spacingSlider.value = dy;
102+
}
103+
};
104+
updateSpacingDisplay();
90105

91106
// Define the tree layout and the shape for links
92107
const tree = d3.tree().nodeSize([dx, dy]);
@@ -307,6 +322,15 @@ window.addEventListener('DOMContentLoaded', async () => {
307322
update(null, root);
308323
});
309324

325+
// Column spacing slider control
326+
document.getElementById('spacing-slider')?.addEventListener('input', (e) => {
327+
dy = parseInt(e.target.value);
328+
localStorage.setItem('toctree-column-spacing', dy);
329+
tree.nodeSize([dx, dy]);
330+
updateSpacingDisplay();
331+
update(null, root);
332+
});
333+
310334
// Search functionality
311335
const searchInput = document.getElementById('search');
312336
if (searchInput) {

0 commit comments

Comments
 (0)