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

Commit 3f02fef

Browse files
author
Hendrik van Antwerpen
committed
Display stacks for each time the path crosses a node
1 parent b500136 commit 3f02fef

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

stack-graphs/src/visualization/visualization.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

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)