Skip to content

Commit 5aa2a6e

Browse files
Merge pull request #344 from github/file-viz
More visualization changes
2 parents 0cc5a07 + 1acebc7 commit 5aa2a6e

File tree

2 files changed

+114
-9
lines changed

2 files changed

+114
-9
lines changed

stack-graphs/src/visualization/visualization.css

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
stroke: black;
8686
}
8787

88+
.sg .node.definition .background {
89+
stroke-width: 2px;
90+
}
91+
8892
/* --- push symbol --- */
8993

9094
.sg .node.push_scoped_symbol .push_scope {
@@ -102,6 +106,10 @@
102106
fill: black;
103107
}
104108

109+
.sg .node.reference .background {
110+
stroke-width: 2px;
111+
}
112+
105113
/* --- root --- */
106114

107115
.sg .node.root .background {
@@ -128,6 +136,10 @@
128136
fill: black;
129137
}
130138

139+
.sg .node.scope.exported .background {
140+
stroke-width: 2px;
141+
}
142+
131143
/* --- plain labeled node --- */
132144

133145
.sg .node.scope.plain_labeled_node .border {
@@ -139,10 +151,6 @@
139151
rx: 6px;
140152
}
141153

142-
.sg .node.scope.plain_labeled_node.exported .background {
143-
stroke: black;
144-
}
145-
146154
/* --- path highlight --- */
147155

148156
.sg .node.path-node .border {
@@ -314,6 +322,40 @@
314322
margin: 0px 1px;
315323
}
316324

325+
/* ------------------------------------------------------------------------------------------------
326+
* Legend
327+
*/
328+
329+
#sg-legend {
330+
position: absolute;
331+
left: 10px;
332+
top: 10px;
333+
background-color: #bbbbbb;
334+
padding: 6px;
335+
border-radius: 6px;
336+
z-index: 1;
337+
}
338+
339+
#sg-legend h1 {
340+
font-variant: small-caps;
341+
font-weight: bold;
342+
font-size: inherit;
343+
border-bottom: solid 1px #777777;
344+
margin: 0px;
345+
}
346+
347+
#sg-legend ul {
348+
list-style: none;
349+
padding: 0px;
350+
margin: 0px;
351+
}
352+
353+
#sg-legend li {
354+
padding: 3px 6px;
355+
margin: 3px 0px;
356+
border: 1px solid white;
357+
}
358+
317359
/* ------------------------------------------------------------------------------------------------
318360
* Help
319361
*/
@@ -419,6 +461,9 @@
419461
.sg .node.global .background {
420462
fill: #0077bb; /* blue */
421463
}
464+
#sg-legend .global {
465+
background-color: #0077bb; /* blue */
466+
}
422467
.sg .edge.global path,
423468
.sg .edge.global text {
424469
stroke: #0077bb; /* blue */
@@ -427,7 +472,9 @@
427472
.sg .node.file-0 .background {
428473
fill: #77aadd; /* light blue */
429474
}
430-
475+
#sg-legend .file-0 {
476+
background-color: #77aadd; /* light blue */
477+
}
431478
.sg .node.file-0 .arrow,
432479
.sg .edge.file-0 text
433480
{
@@ -447,6 +494,9 @@
447494
{
448495
fill: #ee8866; /* orange */
449496
}
497+
#sg-legend .file-1 {
498+
background-color: #ee8866; /* orange */
499+
}
450500
.sg .node.file-1 .arrow {
451501
fill: #3d1407; /* orange (darkened) */
452502
}
@@ -464,6 +514,9 @@
464514
{
465515
fill: #eedd88; /* light yellow */
466516
}
517+
#sg-legend .file-2 {
518+
background-color: #eedd88; /* light yellow */
519+
}
467520
.sg .node.file-2 .arrow {
468521
fill: #413809; /* light yellow (darkened) */
469522
}
@@ -481,6 +534,9 @@
481534
{
482535
fill: #ffaabb; /* pink */
483536
}
537+
#sg-legend .file-3 {
538+
background-color: #ffaabb; /* pink */
539+
}
484540
.sg .node.file-3 .arrow {
485541
fill: #550011; /* pink (darkened) */
486542
}
@@ -498,6 +554,9 @@
498554
{
499555
fill: #99ddff; /* light cyan */
500556
}
557+
#sg-legend .file-4 {
558+
background-color: #99ddff; /* light cyan */
559+
}
501560
.sg .node.file-4 .arrow {
502561
fill: #003652; /* light cyan (darkened) */
503562
}
@@ -515,6 +574,9 @@
515574
{
516575
fill: #44bb99; /* mint */
517576
}
577+
#sg-legend .file-5 {
578+
background-color: #44bb99; /* mint */
579+
}
518580
.sg .node.file-5 .arrow {
519581
fill: #0e251f; /* mint (darkened) */
520582
}
@@ -532,6 +594,9 @@
532594
{
533595
fill: #bbcc33; /* pear */
534596
}
597+
#sg-legend .file-6 {
598+
background-color: #bbcc33; /* pear */
599+
}
535600
.sg .node.file-6 .arrow {
536601
fill: #25290a; /* pear (darkened) */
537602
}
@@ -549,6 +614,9 @@
549614
{
550615
fill: #aaaa00; /* olive */
551616
}
617+
#sg-legend .file-7 {
618+
background-color: #aaaa00; /* olive */
619+
}
552620
.sg .node.file-7 .arrow {
553621
fill: #222200; /* olive (darkened) */
554622
}

stack-graphs/src/visualization/visualization.js

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ class StackGraph {
163163
// render UI
164164
this.render_help();
165165
this.render_tooltip();
166-
this.render_graph()
166+
this.render_legend();
167+
this.render_graph();
167168

168169
// pan & zoom
169170
let zoom = d3.zoom()
@@ -471,9 +472,9 @@ class StackGraph {
471472
}
472473
}
473474

474-
/* ------------------------------------------------------------------------------------------------
475-
* Path Highlighting
476-
*/
475+
// ------------------------------------------------------------------------------------------------
476+
// Path Highlighting
477+
//
477478

478479
paths_mouseover(e, node) {
479480
if (this.paths_lock !== null) {
@@ -781,6 +782,30 @@ class StackGraph {
781782
|| (this.current_edge !== null && path.derived.edges.hasOwnProperty(this.edge_to_id_str(this.current_edge)));
782783
}
783784

785+
// ------------------------------------------------------------------------------------------------
786+
// Legend
787+
//
788+
789+
render_legend() {
790+
const legend = d3.select('body').append('div')
791+
.attr('id', 'sg-legend')
792+
legend.append("h1").text("Files");
793+
const items = legend.append("ul");
794+
items.append("li")
795+
.classed("global", true)
796+
.text("[global]");
797+
for (const file in this.F) {
798+
items.append("li")
799+
.classed('file-' + this.F[file], true)
800+
.text(file);
801+
}
802+
}
803+
804+
legend_update() {
805+
const legend = d3.select('#sg-legend');
806+
legend.style('visibility', this.show_file_legend() ? null : 'hidden');
807+
}
808+
784809
// ------------------------------------------------------------------------------------------------
785810
// Help
786811
//
@@ -802,6 +827,10 @@ class StackGraph {
802827
Pan by dragging the background with the mouse.
803828
Zoom using the scroll wheel.
804829
`);
830+
this.show_files_legend_toggle = this.new_setting(help_content, "sg-files-legend", "Show files legend (<kbd>f</kbd>)", true);
831+
this.show_files_legend_toggle.on("change", (e => {
832+
this.legend_update();
833+
}));
805834
this.show_all_node_labels_toggle = this.new_setting(help_content, "sg-scope-labels", "Show all node labels (<kbd>l</kbd>)", false);
806835
this.show_all_node_labels_toggle.on("change", (e => {
807836
this.render_graph();
@@ -838,6 +867,10 @@ class StackGraph {
838867

839868
help_keypress(e) {
840869
switch (e.keyCode) {
870+
case 70: // f
871+
this.show_files_legend_toggle.property("checked", !this.show_files_legend_toggle.property("checked"));
872+
this.legend_update();
873+
break;
841874
case 72: // h
842875
this.help_toggle.property("checked", !this.help_toggle.property("checked"));
843876
break;
@@ -860,6 +893,10 @@ class StackGraph {
860893
return this.show_all_node_labels_toggle.property("checked");
861894
}
862895

896+
show_file_legend() {
897+
return this.show_files_legend_toggle.property("checked");
898+
}
899+
863900
new_setting(element, id, html, initial) {
864901
const toggle = element.append("div");
865902
const toggle_input = toggle.append('input')

0 commit comments

Comments
 (0)