You can click a node in the all tree to limit the top of the view.

This commit is contained in:
Herbert Wolverson 2024-07-19 10:56:58 -05:00
parent a5042220ce
commit f004f1ad8a
2 changed files with 27 additions and 1 deletions

View File

@ -2,6 +2,9 @@ import { DashboardGraph } from "./graphs/dashboard_graph";
import {lerpGreenToRedViaOrange} from "./helpers/scaling"; import {lerpGreenToRedViaOrange} from "./helpers/scaling";
import {isRedacted} from "./helpers/redact"; import {isRedacted} from "./helpers/redact";
var allNodes = [];
let rootId = 0;
class AllTreeSankey extends DashboardGraph { class AllTreeSankey extends DashboardGraph {
constructor(id) { constructor(id) {
super(id); super(id);
@ -16,6 +19,20 @@ class AllTreeSankey extends DashboardGraph {
}; };
this.option && this.chart.setOption(this.option); this.option && this.chart.setOption(this.option);
this.chart.hideLoading(); this.chart.hideLoading();
this.chart.on('click', (params) => {
//console.log(params.name);
let name = params.name;
// If it contains a >, it's a link
if (name.indexOf(" > ") === -1) {
for (let i=0; i<allNodes.length; i++) {
if (allNodes[i][1].name === name) {
rootId = i;
break;
}
}
}
});
$("#btnRoot").click(() => { rootId = 0; });
} }
update(data, links) { update(data, links) {
@ -30,8 +47,10 @@ let lastRtt = {};
function start() { function start() {
$.get("/local-api/networkTree", (data) => { $.get("/local-api/networkTree", (data) => {
allNodes = data;
//console.log(data); //console.log(data);
let redact = isRedacted(); let redact = isRedacted();
$("#rootNode").text(data[rootId][1].name);
let nodes = []; let nodes = [];
let links = []; let links = [];
@ -41,6 +60,10 @@ function start() {
if (depth > maxDepth) { if (depth > maxDepth) {
continue; continue;
} }
// If data[i][1].parents does not contain rootId, skip
if (!data[i][1].parents.includes(rootId)) {
continue;
}
let name = data[i][1].name; let name = data[i][1].name;
let bytes = data[i][1].current_throughput[0]; let bytes = data[i][1].current_throughput[0];
let bytesAsMegabits = bytes / 1000000; let bytesAsMegabits = bytes / 1000000;

View File

@ -1,7 +1,10 @@
<div class="row" style="height: 100%;"> <div class="row">
<div class="col-12 small"> <div class="col-12 small">
Top node:: <span id="rootNode"></span> <button class="btn btn-primary btn-sm" id="btnRoot"><i class="fa fa-tree"></i> Reset</button>
<label for="maxDepth">Max Depth:</label> <input type="number" min="2" max="10" id="maxDepth"> <label for="maxDepth">Max Depth:</label> <input type="number" min="2" max="10" id="maxDepth">
</div> </div>
</div>
<div class="row" style="height: 98%;">
<div class="col-12" style="height: 100%;" id="sankey"></div> <div class="col-12" style="height: 100%;" id="sankey"></div>
</div> </div>
<script src="all_tree_sankey.js"></script> <script src="all_tree_sankey.js"></script>