Published
Edited
Apr 18, 2022
Insert cell
Insert cell
Insert cell
nodeRadius = 1
Insert cell
Insert cell
amGroups = _.groupBy(rawData.nodes, 'workload.namespace', 'unknown-namespace')
Insert cell
namespaceList = Object.keys(amGroups)
Insert cell
amNodes= _.map(rawData.nodes, (n, i) => ({...n, index: i, namespace: _.get(n, 'workload.namespace', 'unknown-namespace'), group: _.get(n, 'workload.namespace', 'unknown-namespace'), radius: nodeRadius, value: nodeRadius, x: 0 , y: 0}))
Insert cell
// amClusters = _.map(amGroups, (val, key) => ({ radius: 0, cluster: key, id: key, x: Math.random() * 300, y: Math.random()* 300}))
Insert cell
Insert cell
Insert cell
Insert cell
pack = () => d3.pack()
.size([width, height])
.padding(1)
(d3.hierarchy(data).sum( d => 1)
// .sum(d => {

// console.log('d???', d)
// return 0.1
// })
)
Insert cell
Insert cell
Insert cell
zone = (nodes) => {
// const padding = 2;
// this is probably the surrounding square
let x1, x2, y1, y2 = 0;
x1 = d3.min(nodes, d => d.x);
x2 = d3.max(nodes, d => d.x + (d.value +1) * MAGNIFIER);
y1 = d3.min(nodes, d => d.y);
y2 = d3.max(nodes, d => d.y + (d.value + 1) * MAGNIFIER);

const result = {x1, x2, y1, y2 }

return result
}
Insert cell
tmp = d3.group(amNodes, (node) => (node.namespace))
Insert cell
childs = Array.from(tmp)
Insert cell
data = ({
// children: Array.from(d3.group(amNodes, node => node.group), ([, children]) => ({children}))
children: Array.from(tmp, ([ , children]) => ({children}))
// Array.from(
// d3.group(
// amNodes, (node, i) => ({
// id: node.id,
// group: node.namespace,
// value: 1
// }),
// d => d.group
// ),
// ([ , children]) => ({children})
// )
})
Insert cell
function centroid(nodes) {
let x = 0;
let y = 0;
let z = 0;
for (const d of nodes) {
let k = d.r ** 2;
x += d.x * k;
y += d.y * k;
z += k;
}
return {x: x / z, y: y / z};
}
Insert cell
drag = simulation => {
function dragstarted(d) {
if (!d3.event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(d) {
d.fx = d3.event.x;
d.fy = d3.event.y;
}
function dragended(d) {
if (!d3.event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}
return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Insert cell
n = amNodes.length // number of nodes
Insert cell
m = namespaceList.length// number of groups
Insert cell
l = -1
Insert cell
MAGNIFIER = 7
Insert cell
color = d3.scaleOrdinal(d3.range(m), d3.schemeCategory10)
Insert cell
height = 600
Insert cell
d3 = require("d3@5", "d3-array@2")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more