Graph sidebar shows only categories present in current data
- Count tags per category before rendering sidebar - Only display categories that have tags in current view - Show count next to each category name Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1284,8 +1284,15 @@ const GraphView = {
|
||||
area.innerHTML = '<div class="graph-container"></div>';
|
||||
const container = area.querySelector(".graph-container");
|
||||
|
||||
// Count tags per category
|
||||
const categoryCounts = new Map();
|
||||
tags.forEach(tag => {
|
||||
const cat = Utils.getCategory(tag);
|
||||
categoryCounts.set(cat, (categoryCounts.get(cat) || 0) + 1);
|
||||
});
|
||||
|
||||
this.renderSVG(container, nodes, links);
|
||||
this.renderSidebar(container, nodes.length, links.length);
|
||||
this.renderSidebar(container, nodes.length, links.length, categoryCounts);
|
||||
this.renderControls(container);
|
||||
this.renderLegend(container);
|
||||
},
|
||||
@@ -1362,10 +1369,19 @@ const GraphView = {
|
||||
.on("end", (e, d) => { if (!e.active) sim.alphaTarget(0); d.fx = null; d.fy = null; });
|
||||
},
|
||||
|
||||
renderSidebar(container, nodeCount, edgeCount) {
|
||||
renderSidebar(container, nodeCount, edgeCount, categoryCounts) {
|
||||
const { graphFilters, graphSettings } = State.get();
|
||||
const sidebar = document.createElement("div");
|
||||
sidebar.className = "graph-sidebar";
|
||||
|
||||
// Only show categories that have tags in current data
|
||||
const categoryHTML = Object.entries(CONFIG.CATEGORIES)
|
||||
.filter(([key]) => categoryCounts.has(key) && categoryCounts.get(key) > 0)
|
||||
.map(([key, val]) => {
|
||||
const count = categoryCounts.get(key) || 0;
|
||||
return `<label class="graph-checkbox"><input type="checkbox" data-category="${key}" ${graphFilters.categories.has(key) ? "checked" : ""}><span class="color-dot" style="background:${val.color}"></span>${Utils.escapeHtml(val.name)} (${count})</label>`;
|
||||
}).join("");
|
||||
|
||||
sidebar.innerHTML = `
|
||||
<div class="graph-section">
|
||||
<div class="graph-section__title">Stats</div>
|
||||
@@ -1374,7 +1390,7 @@ const GraphView = {
|
||||
</div>
|
||||
<div class="graph-section">
|
||||
<div class="graph-section__title">Categorías</div>
|
||||
${Object.entries(CONFIG.CATEGORIES).map(([key, val]) => `<label class="graph-checkbox"><input type="checkbox" data-category="${key}" ${graphFilters.categories.has(key) ? "checked" : ""}><span class="color-dot" style="background:${val.color}"></span>${Utils.escapeHtml(val.name)}</label>`).join("")}
|
||||
${categoryHTML || '<span class="empty">Sin categorías</span>'}
|
||||
</div>
|
||||
<div class="graph-section">
|
||||
<div class="graph-section__title">Relaciones</div>
|
||||
|
||||
Reference in New Issue
Block a user