From 7ff99f520167c215b5b022fad7ca94b50199e383 Mon Sep 17 00:00:00 2001 From: niclas Date: Thu, 29 Feb 2024 16:30:18 +0100 Subject: [PATCH] Add [graph] pre filtering for large data --- .../docs/01_attachements/javascripts/graph.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/mkdocs/site/docs/01_attachements/javascripts/graph.js b/tools/mkdocs/site/docs/01_attachements/javascripts/graph.js index 226d43b..cffb5ba 100644 --- a/tools/mkdocs/site/docs/01_attachements/javascripts/graph.js +++ b/tools/mkdocs/site/docs/01_attachements/javascripts/graph.js @@ -5,6 +5,12 @@ document$.subscribe(function () { const Parent_Node_COLOR = "#ff0000"; + function applyTableFilter(tf) { + var valuesToSelect = ['1', '2', '3']; + tf.setFilterValue(4, valuesToSelect); + tf.filter(); + }; + function parseFilteredTable(tf, allData) { var data = []; tf.getFilteredData().forEach((row, i) => { @@ -427,6 +433,8 @@ document$.subscribe(function () { // Restart the simulation with new data simulation.nodes(nodes); simulation.force("link").links(links); + linkDistance = Math.sqrt((width * height) / nodes.length); + simulation.force("link").distance(linkDistance); simulation.alpha(1).restart(); } }); @@ -473,7 +481,13 @@ document$.subscribe(function () { }); tf.init(); - var data = parseTable(table); + var allData = parseTable(table); + if (allData.length > 1000) { + applyTableFilter(tf); + data = parseFilteredTable(tf, allData); + } else { + data = allData; + } var graphId = "graph" + index; var div = document.createElement("div"); div.id = graphId; @@ -482,7 +496,7 @@ document$.subscribe(function () { // Listen for table filtering events tf.emitter.on(['after-filtering'], function () { - filterTableAndGraph(tf, simulation, data); + filterTableAndGraph(tf, simulation, allData); }); } });