Skip to content

Commit f149c40

Browse files
committed
url param for starting function
1 parent 5196421 commit f149c40

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

bin/cascade.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ function generateNextLevel(parents, stackDepth) {
6060
/**
6161
* Convert the call map to format D3 wants
6262
* @param calledFunctions
63+
* @param startFunction -- string of the function name we want to use as start of call graph
6364
*/
64-
function convertForCascade(calledFunctions) {
65+
function convertForCascade(calledFunctions, startFunction) {
6566
myMap = calledFunctions;
6667
final = [];
6768
calledAlready = [];
6869
// 1st case -- handle manually
69-
final.push([{ id: 'proceed' }]);
70+
final.push([{ id: startFunction }]);
7071
// all next cases generate automatically
71-
generateNextLevel(['proceed'], 10);
72+
generateNextLevel([startFunction], 10);
7273
return final;
7374
}
7475
exports.convertForCascade = convertForCascade;

bin/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ function startServer(allFunctions, functionMap) {
5252
app.use('/mermaid', express.static(path.join(__dirname, '..', 'graphing/mermaid')));
5353
app.use('/vendor', express.static(path.join(__dirname, '..', 'graphing/vendor')));
5454
app.get('/arcAPI', function (req, res) { res.json(arc_1.convertForArc(allFunctions, functionMap)); });
55-
app.get('/cascadeAPI', function (req, res) { res.json(cascade_1.convertForCascade(functionMap)); });
55+
app.get('/cascadeAPI/:startFunc', function (req, res) {
56+
res.json(cascade_1.convertForCascade(functionMap, req.params.startFunc));
57+
});
5658
app.get('/graphvizAPI', function (req, res) { res.json(graphviz_1.convertForGraphViz(functionMap)); });
5759
app.get('/mermaidAPI', function (req, res) { res.json(mermaid_1.convertForMermaid(functionMap)); });
5860
app.listen(3000);

cascade.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@ function generateNextLevel(parents: string[], stackDepth: number): void {
6969
/**
7070
* Convert the call map to format D3 wants
7171
* @param calledFunctions
72+
* @param startFunction -- string of the function name we want to use as start of call graph
7273
*/
73-
export function convertForCascade(calledFunctions: Map<string, string[]>) {
74+
export function convertForCascade(calledFunctions: Map<string, string[]>, startFunction: string) {
7475
myMap = calledFunctions;
7576
final = [];
7677
calledAlready = [];
7778

7879
// 1st case -- handle manually
79-
final.push([{ id: 'proceed' }]);
80+
final.push([{ id: startFunction }]);
8081
// all next cases generate automatically
81-
generateNextLevel(['proceed'], 10);
82+
generateNextLevel([startFunction], 10);
8283

8384
return final;
8485
}

graphing/cascade/graph.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22
export default function define(runtime, observer) {
33
const main = runtime.module();
44

5-
main.builtin("FileAttachment", runtime.fileAttachments(() => new URL("http://localhost:3000/cascadeAPI", import.meta.url)));
5+
let graphData;
6+
7+
const queryString = window.location.search;
8+
const urlParams = new URLSearchParams(queryString);
9+
const startFunction = urlParams.get('start')
10+
11+
fetch('http://localhost:3000/cascadeAPI/' + startFunction)
12+
.then((response) => {
13+
return response.json();
14+
})
15+
.then((data) => {
16+
graphData = data;
17+
});
18+
619

720
main.variable(observer()).define(["html"], function(html) {
821
return (
@@ -64,13 +77,7 @@ export default function define(runtime, observer) {
6477

6578
main.variable(observer("data")).define("data", ["d3"], function (d3) {
6679

67-
// console.log(main);
68-
// console.log(main._scope.get('temporaryHackName')._value);
69-
// levels = JSON.parse('[[{"id":"abc"}],[{"id":"abc2","parents":["abc"]},{"id":"abc3"}],[{"id": "lol", "parents": ["abc3", "abc2"]}]]');
70-
71-
let levels = main._scope.get('temporaryHackName')._value;
72-
73-
// console.log(levels);
80+
let levels = graphData;
7481

7582
// precompute level depth
7683
levels.forEach((l, i) => l.forEach((n) => (n.level = i)));
@@ -242,9 +249,5 @@ export default function define(runtime, observer) {
242249
return require("d3-scale", "d3-scale-chromatic", "d3-array");
243250
});
244251

245-
main.variable(observer()).define("temporaryHackName", ["FileAttachment"], function (lol) {
246-
return lol().json()
247-
});
248-
249252
return main;
250253
}

graphing/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h2>
1313
WELCOME !!!
1414
</h2>
1515

16-
<a href="cascade/index.html">Cascade</a>
16+
<a href="cascade/index.html?start=proceed">Cascade</a>
1717

1818
<br>
1919

index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ function startServer(allFunctions: string[], functionMap: Map<string, string[]>)
6868
app.use('/vendor', express.static(path.join(__dirname, '..', 'graphing/vendor')));
6969

7070
app.get('/arcAPI', function (req, res) { res.json(convertForArc(allFunctions, functionMap)) });
71-
app.get('/cascadeAPI', function (req, res) { res.json(convertForCascade(functionMap)) });
71+
72+
app.get('/cascadeAPI/:startFunc', function (req, res) {
73+
res.json(convertForCascade(functionMap, req.params.startFunc))
74+
});
75+
7276
app.get('/graphvizAPI', function (req, res) { res.json(convertForGraphViz(functionMap)) });
77+
7378
app.get('/mermaidAPI', function (req, res) { res.json(convertForMermaid(functionMap)) });
7479

7580
app.listen(3000)

0 commit comments

Comments
 (0)