StackGenVis: Alignment of Data, Algorithms, and Models for Stacking Ensemble Learning Using Performance Metrics https://doi.org/10.1109/TVCG.2020.3030352
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
StackGenVis/frontend/node_modules/planar-graph-to-polyline/lib/trim-leaves.js

55 lines
1.1 KiB

4 years ago
'use strict'
module.exports = trimLeaves
var e2a = require('edges-to-adjacency-list')
function trimLeaves(edges, positions) {
var adj = e2a(edges, positions.length)
var live = new Array(positions.length)
var nbhd = new Array(positions.length)
var dead = []
for(var i=0; i<positions.length; ++i) {
var count = adj[i].length
nbhd[i] = count
live[i] = true
if(count <= 1) {
dead.push(i)
}
}
while(dead.length > 0) {
var v = dead.pop()
live[v] = false
var n = adj[v]
for(var i=0; i<n.length; ++i) {
var u = n[i]
if(--nbhd[u] === 0) {
dead.push(u)
}
}
}
var newIndex = new Array(positions.length)
var npositions = []
for(var i=0; i<positions.length; ++i) {
if(live[i]) {
var v = npositions.length
newIndex[i] = v
npositions.push(positions[i])
} else {
newIndex[i] = -1
}
}
var nedges = []
for(var i=0; i<edges.length; ++i) {
var e = edges[i]
if(live[e[0]] && live[e[1]]) {
nedges.push([ newIndex[e[0]], newIndex[e[1]] ])
}
}
return [ nedges, npositions ]
}