Skip to content

Commit 4bde800

Browse files
author
Rosa Hase
committed
experimental: just show the edges related to the current page
1 parent f7ca39b commit 4bde800

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

docs/ObsidianVault/assets/javascripts/interactive_graph.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ function init_graph(params) {
2727

2828
var myChart = init_graph();
2929

30-
function draw_graph(myChart) {
30+
function draw_graph(myChart, modal=false) {
31+
console.log(modal);
32+
var _option = $.extend(true, {}, option);
33+
if(!modal) {
34+
_option.series[0].data = graph_nodes();
35+
_option.series[0].links = graph_links();
36+
}
3137
// draw the graph
32-
myChart.setOption(option);
38+
myChart.setOption(_option);
3339

3440
// add click event for nodes
3541
myChart.on('click', function (params) {
@@ -44,6 +50,21 @@ function draw_graph(myChart) {
4450

4551
var option;
4652

53+
function graph_links() {
54+
id = option.series[0].data.find(it => it.value === window.location.pathname).id;
55+
return option.series[0].links.filter(it => it.source === id || it.target === id);
56+
}
57+
58+
function graph_nodes() {
59+
id = option.series[0].data.find(it => it.value === window.location.pathname).id;
60+
links = option.series[0].links.filter(it => it.source === id || it.target === id);
61+
ids = [];
62+
links.forEach(function (link) {
63+
ids.push(link.source, link.target);
64+
});
65+
return option.series[0].data.filter(it => [...new Set(ids)].includes(it.id));
66+
}
67+
4768
$.getJSON(document.currentScript.src + '/../graph.json', function (graph) {
4869
myChart.hideLoading();
4970

@@ -138,5 +159,5 @@ $('#graph_button').on('click', function (params) {
138159
}
139160
});
140161
myChart = init_graph();
141-
draw_graph(myChart);
162+
draw_graph(myChart, true);
142163
});

0 commit comments

Comments
 (0)