Skip to content

Commit c33a72e

Browse files
Add graph legend (#1363)
Adds a legend explaining the color of the nodes in the agda-unimath dependency graph introduced in #1348.
1 parent 23f1480 commit c33a72e

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,4 @@ CONTRIBUTORS.md
431431
MAINTAINERS.md
432432
/website/css/Agda-highlight.css
433433
/website/images/agda_dependency_graph.svg
434+
/website/images/agda_dependency_graph_legend.html

ART.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
<div align="center" style="margin: 2em 0;">
44
<figure>
5-
<img src="website/images/agda_dependency_graph.svg" alt="A dependency graph of the library, color coded by field. Fredrik Bakke. 2025 - perpetuity" width="95%" style="border-radius: 10px;">
6-
<figcaption>A dependency graph of the library, color coded by field. Fredrik Bakke. 2025 - perpetuity</figcaption>
5+
<img src="website/images/agda_dependency_graph.svg" alt="A dependency graph of the library, color coded by namespace. Fredrik Bakke. 2025 — perpetuity" width="95%" style="border-radius: 10px;">
6+
<br>
7+
<span>
8+
{{#include website/images/agda_dependency_graph_legend.html}}
9+
</span>
10+
<figcaption>A dependency graph of the library, color coded by namespace. Fredrik Bakke. 2025 — perpetuity</figcaption>
11+
712
</figure>
813
</div>
914

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ CONTRIBUTORS.md: ${AGDAFILES} ${CONTRIBUTORS_FILE} ./scripts/generate_contributo
145145
website/css/Agda-highlight.css: ./scripts/generate_agda_css.py ./theme/catppuccin.css
146146
@python3 ./scripts/generate_agda_css.py
147147

148-
website/images/agda_dependency_graph.svg: ${AGDAFILES}
148+
website/images/agda_dependency_graph.svg website/images/agda_dependency_graph_legend.html &: ${AGDAFILES}
149149
@python3 ./scripts/generate_dependency_graph_rendering.py website/images/agda_dependency_graph svg || true
150150

151151
.PHONY: website-prepare
152152
website-prepare: agda-html ./SUMMARY.md ./CONTRIBUTORS.md ./MAINTAINERS.md \
153-
./website/css/Agda-highlight.css ./website/images/agda_dependency_graph.svg
153+
./website/css/Agda-highlight.css ./website/images/agda_dependency_graph.svg \
154+
./website/images/agda_dependency_graph_legend.html
154155
@cp $(METAFILES) ./docs/
155156
@mkdir -p ./docs/website
156157
@cp -r ./website/images ./docs/website/

scripts/generate_dependency_graph_rendering.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ def build_dependency_graph(root_dir, most_imported_drop_count=20):
133133

134134
return graph, file_sizes
135135

136+
def generate_html_legend(label_colors, used_labels, output_file, label_counts):
137+
"""Generate an HTML legend with used namespaces and their colors."""
138+
sorted_labels = sorted(used_labels, key=lambda label: label_counts.get(label, 0), reverse=True)
139+
with open(output_file, 'w') as f:
140+
f.write('<div class="art-fredrik-dependency-graph-legend">\n')
141+
for label in sorted_labels:
142+
if label in label_colors:
143+
color = label_colors[label]
144+
f.write(f' <pre class="art-fredrik-dependency-graph-label" id="{label}"><span class="art-fredrik-dependency-graph-dot" style="background-color: #{color};"></span>{label}</pre>\n')
145+
f.write('</div>\n')
146+
136147
def render_graph(graph, file_sizes, output_file, format, repo):
137148
"""Render the dependency graph using Graphviz."""
138149
# Fetch GitHub labels and colors
@@ -147,14 +158,25 @@ def render_graph(graph, file_sizes, output_file, format, repo):
147158
node_sizes = {node: max(0.05, 0.3 * math.sqrt(file_sizes.get(node, 0) / max_lines)) for node in graph}
148159
node_colors = {node: module_based_color(node[:node.rfind(".")], label_colors) for node in graph}
149160

161+
used_labels = set()
162+
label_counts = defaultdict(int)
163+
150164
for node, dependencies in graph.items():
151165
node_color = node_colors[node]
166+
label = node[:node.rfind(".")]
167+
used_labels.add(label)
168+
label_counts[label] += 1
152169
dot.node(node, shape="circle", style="filled", fillcolor=node_color, color="#FFFFFF00", width=str(node_sizes[node]), height=str(node_sizes[node]), label="")
153170
for dep in dependencies:
154171
if dep in graph: # Ensure we're not linking to removed nodes
155172
edge_color = node_color + "10"
156173
dot.edge(node, dep, color=edge_color, arrowhead="none")
157174

175+
# Generate HTML legend
176+
html_legend_output_file = output_file + "_legend.html"
177+
generate_html_legend(label_colors, used_labels, html_legend_output_file, label_counts)
178+
eprint(f"HTML Legend saved as {html_legend_output_file}")
179+
158180
dot.render(output_file, format=format, cleanup=True)
159181

160182
if __name__ == "__main__":

theme/css/general.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,27 @@ kbd {
252252
span.prefer-nobreak {
253253
display: inline-block;
254254
}
255+
256+
.art-fredrik-dependency-graph-legend {
257+
line-height: 1;
258+
display: flex;
259+
flex-wrap: wrap;
260+
gap: 0.5rem;
261+
}
262+
263+
.art-fredrik-dependency-graph-dot {
264+
height: 10px;
265+
width: 10px;
266+
border-radius: 50%;
267+
display: inline-block;
268+
margin-right: 2.5px;
269+
margin-left: 4px;
270+
}
271+
272+
.art-fredrik-dependency-graph-label {
273+
white-space: nowrap;
274+
font-size: 50%;
275+
display: inline-block;
276+
margin: 0;
277+
padding: 0.1rem 0.3rem;
278+
}

0 commit comments

Comments
 (0)