Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 095c2af

Browse files
author
Hendrik van Antwerpen
authored
Merge pull request #279 from github/stack-visualization
Display stacks for each time a path crosses a node
2 parents c8f83d8 + ab81c50 commit 095c2af

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
lines changed

stack-graphs/src/visualization/visualization.css

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
.sg .node text {
4646
font-family: monospace;
47-
font-size: 20px;
47+
font-size: 16px;
4848
}
4949

5050
/* --- drop scopes --- */
@@ -292,6 +292,19 @@
292292
padding-top: 8px;
293293
}
294294

295+
.sg-tooltip-sub-header {
296+
font-variant: small-caps;
297+
font-style: italic;
298+
border-bottom: dashed 1px #555555;
299+
}
300+
301+
.sg-tooltip-sub-header td {
302+
column-span: all;
303+
}
304+
305+
.sg-tooltip-sub-header:not(:first-child) td {
306+
padding-top: 4px;
307+
}
295308

296309
.sg-tooltip-label {
297310
font-variant: small-caps;
@@ -323,7 +336,6 @@
323336
list-style-type: none;
324337
padding: 0px;
325338
margin-left: 10px;
326-
font-size: smaller;
327339
}
328340

329341
.sg-tooltip-sublist-element {
@@ -358,7 +370,7 @@
358370
line-height: 30px;
359371
text-align: center;
360372
margin: 0px;
361-
font-size: 18px;
373+
font-size: 14px;
362374
cursor: pointer;
363375
}
364376

@@ -375,14 +387,22 @@
375387
min-width: 18px;
376388
max-width: 300px;
377389
margin: 0px;
390+
font-size: 14px;
378391
}
379392

380393
#sg-help-toggle:checked ~ .sg-help-content {
381394
visibility: visible;
382395
}
383396

384397
.sg-help-content h1 {
398+
font-variant: small-caps;
399+
font-weight: bold;
385400
font-size: inherit;
401+
border-bottom: solid 1px #777777;
402+
}
403+
404+
.sg-help-content h1:first-child {
405+
margin-top: 0px;
386406
}
387407

388408
.sg-help-content kbd {
@@ -421,4 +441,4 @@
421441
.sg-toggle-label {
422442
margin: 0px 6px;
423443
cursor: pointer;
424-
}
444+
}

stack-graphs/src/visualization/visualization.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@ class StackGraph {
5454
node_ids.push(path.end_node);
5555
const nodes = {};
5656
const edges = {};
57-
nodes[this.node_id_to_str(node_ids[0])] = {};
57+
nodes[this.node_id_to_str(node_ids[0])] = {
58+
stacks: [],
59+
};
5860
for (let i = 1; i < node_ids.length; i++) {
5961
const source = node_ids[i - 1];
6062
const sink = node_ids[i];
6163
const edge_id = this.edge_to_id_str({ source, sink });
6264
edges[edge_id] = {};
63-
nodes[this.node_id_to_str(sink)] = {};
65+
nodes[this.node_id_to_str(sink)] = {
66+
stacks: [],
67+
};
6468
// create jump edges, which are not part of the graph
6569
if (this.N[this.ID[this.node_id_to_str(source)]].type === 'jump_to_scope' && jumps[edge_id] !== true) {
6670
jumps[edge_id] = true;
@@ -81,18 +85,26 @@ class StackGraph {
8185
compute_path_stacks(path) {
8286
let symbol_stack = null;
8387
let scope_stack = null;
84-
for (let edge of path.edges) {
88+
var index = 0;
89+
for (; index < path.edges.length; index++) {
90+
const edge = path.edges[index];
8591
const node_id = this.node_id_to_str(edge.source);
8692
const node = this.N[this.ID[node_id]];
8793
[symbol_stack, scope_stack] = this.compute_stacks_after_node(node, symbol_stack, scope_stack);
88-
path.derived.nodes[node_id].symbol_stack = symbol_stack;
89-
path.derived.nodes[node_id].scope_stack = scope_stack;
94+
path.derived.nodes[node_id].stacks.push({
95+
index,
96+
symbol_stack,
97+
scope_stack,
98+
});
9099
}
91100
const node_id = this.node_id_to_str(path.end_node);
92101
const node = this.N[this.ID[node_id]];
93102
[symbol_stack, scope_stack] = this.compute_stacks_after_node(node, symbol_stack, scope_stack);
94-
path.derived.nodes[node_id].symbol_stack = symbol_stack;
95-
path.derived.nodes[node_id].scope_stack = scope_stack;
103+
path.derived.nodes[node_id].stacks.push({
104+
index,
105+
symbol_stack,
106+
scope_stack,
107+
});
96108
}
97109

98110
compute_stacks_after_node(node, symbol_stack, scope_stack) {
@@ -631,6 +643,13 @@ class StackGraph {
631643
.attr("colspan", "2")
632644
.text(label);
633645
}
646+
function add_sub_header(label) {
647+
const tr = tbody.append("tr")
648+
.attr("class", "sg-tooltip-sub-header");
649+
tr.append("td")
650+
.attr("colspan", "2")
651+
.text(label);
652+
}
634653
function add_row(label, value) {
635654
const tr = tbody.append("tr");
636655
tr.append("td").attr("class", "sg-tooltip-label").text(label);
@@ -657,6 +676,7 @@ class StackGraph {
657676
}
658677
let tooltip_methods = {
659678
add_header,
679+
add_sub_header,
660680
add_row,
661681
};
662682

@@ -735,8 +755,11 @@ class StackGraph {
735755
const node_id = (this.current_node && this.node_to_id_str(this.current_node))
736756
|| (this.current_edge && this.node_id_to_str(this.current_edge.source));
737757
const node_data = path.derived.nodes[node_id];
738-
tooltip.add_row("symbol stack", this.symbol_stack_to_array(node_data.symbol_stack));
739-
tooltip.add_row("scope stack", this.scope_stack_to_array(node_data.scope_stack));
758+
for (const { index, symbol_stack, scope_stack } of node_data.stacks) {
759+
tooltip.add_sub_header(`position ${index}`);
760+
tooltip.add_row("symbol stack", this.symbol_stack_to_array(symbol_stack));
761+
tooltip.add_row("scope stack", this.scope_stack_to_array(scope_stack));
762+
}
740763
}
741764

742765
tooltip_on_current_path(paths_lock) {

0 commit comments

Comments
 (0)