Skip to content

Commit 2ffd497

Browse files
author
Rosa Hase
committed
added option to minimize the graph to related edges of current page only
1 parent d164f83 commit 2ffd497

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

docs/ObsidianVault/assets/javascripts/interactive_graph.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// draw graph in sidebar, change global to true if prefered
2+
function draw_graph_sidebar(myChart, global=false) {
3+
draw_graph(myChart, global)
4+
}
5+
6+
// draw graph in modal view
7+
function draw_graph_modal(myChart, global=true) {
8+
draw_graph(myChart, global)
9+
}
10+
111
// add graph button next to light/dark mode switch if activated, but before search
212
$('.md-search').before('<form class="md-header__option"> \
313
<label id="graph_button" class="md-header__button md-icon"> \
@@ -27,10 +37,9 @@ function init_graph(params) {
2737

2838
var myChart = init_graph();
2939

30-
function draw_graph(myChart, modal=false) {
31-
console.log(modal);
40+
function draw_graph(myChart, global=true) {
3241
var _option = $.extend(true, {}, option);
33-
if(!modal) {
42+
if(!global) {
3443
_option.series[0].data = graph_nodes();
3544
_option.series[0].links = graph_links();
3645
}
@@ -132,7 +141,8 @@ $.getJSON(document.currentScript.src + '/../graph.json', function (graph) {
132141
}
133142
]
134143
};
135-
draw_graph(myChart);
144+
// initial draw in sidebar
145+
draw_graph_sidebar(myChart);
136146
});
137147

138148
$("#__palette_0").change(function(){
@@ -155,9 +165,10 @@ $('#graph_button').on('click', function (params) {
155165
$('#modal_background').remove();
156166
add_graph_div();
157167
myChart = init_graph();
158-
draw_graph(myChart);
168+
// re-draw sidebar, e.g. switch back from modal view
169+
draw_graph_sidebar(myChart);
159170
}
160171
});
161172
myChart = init_graph();
162-
draw_graph(myChart, true);
173+
draw_graph_modal(myChart);
163174
});

0 commit comments

Comments
 (0)