// add graph button next to light/dark mode switch if activated, but before search $('.md-search').before('
\ \
'); // add a div to html in which the graph will be drawn function add_graph_div(params) { $('.md-sidebar--secondary').each(function() { $(this).contents().append('
'); }); }; add_graph_div(); function init_graph(params) { var myChart = echarts.init(document.getElementById('graph'), null, { renderer: 'canvas', useDirtyRect: false }); return myChart; }; var myChart = init_graph(); function draw_graph(myChart) { // draw the graph myChart.setOption(option); // add click event for nodes myChart.on('click', function (params) { if(params.dataType == "node") { window.location = params.value; } }); // redraw on resize window.addEventListener('resize', myChart.resize); }; var option; $.getJSON(document.currentScript.src + '/../graph.json', function (graph) { myChart.hideLoading(); // an offset of 5, so the dot/node is not that small graph.nodes.forEach(function (node) { node.symbolSize += 5; }); // special feature, if u want to have long note titles, u can use this ' •' // to cut everything behind in graph view graph.nodes.forEach(function (node) { node.name = node.name.split(' •')[0]; }); graph.links.forEach(function (link) { link.source = link.source.split(' •')[0]; link.target = link.target.split(' •')[0]; }); option = { tooltip: { show: false, }, legend: [ // categories not supported yet //{ // data: graph.categories.map(function (a) { // return a.name; // }) //} ], darkMode: "auto", backgroundColor: $("body").css("background-color"), series: [ { name: 'Interactive Graph', type: 'graph', layout: 'force', data: graph.nodes, links: graph.links, categories: [], zoom: 2, roam: true, draggable: false, label: { show: true, position: 'right', formatter: '{b}' }, emphasis: { focus: 'adjacency', // gray out not related nodes on mouse over label: { fontWeight: "bold" } }, labelLayout: { hideOverlap: false // true could be a good idea for large graphs }, scaleLimit: { min: 0.5, max: 5 }, lineStyle: { color: 'source', curveness: 0 // 0.3, if not 0, link an backlink will have 2 lines } } ] }; draw_graph(myChart); }); $("#__palette_0").change(function(){ option.backgroundColor = $("body").css("background-color"); myChart.setOption(option); }); $("#__palette_1").change(function(){ option.backgroundColor = $("body").css("background-color"); myChart.setOption(option); }); $('#graph_button').on('click', function (params) { $("body").css({ overflow: "hidden", position: "fixed" }); $('#graph').remove(); $('').appendTo('body'); $('#modal_background').on('click', function (params) { if(params.target === this) { $("body").css({ overflow: "", position: "" }); $('#graph').remove(); $('#modal_background').remove(); add_graph_div(); myChart = init_graph(); draw_graph(myChart); } }); myChart = init_graph(); draw_graph(myChart); });