2020-09-03 02:37:13 +00:00
|
|
|
import Component from '@glimmer/component';
|
2020-09-04 07:43:27 +00:00
|
|
|
import { tracked } from '@glimmer/tracking';
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
import { scaleLinear } from 'd3-scale';
|
|
|
|
import { max } from 'd3-array';
|
|
|
|
import RSVP from 'rsvp';
|
2020-09-03 02:37:13 +00:00
|
|
|
|
|
|
|
export default class TopoViz extends Component {
|
2020-09-04 07:43:27 +00:00
|
|
|
@tracked heightScale = null;
|
|
|
|
@tracked isLoaded = false;
|
|
|
|
|
2020-09-03 02:37:13 +00:00
|
|
|
get datacenters() {
|
|
|
|
const datacentersMap = this.args.nodes.reduce((datacenters, node) => {
|
|
|
|
if (!datacenters[node.datacenter]) datacenters[node.datacenter] = [];
|
|
|
|
datacenters[node.datacenter].push(node);
|
|
|
|
return datacenters;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
return Object.keys(datacentersMap)
|
|
|
|
.map(key => ({ name: key, nodes: datacentersMap[key] }))
|
|
|
|
.sortBy('name');
|
|
|
|
}
|
2020-09-04 07:43:27 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
async loadNodes() {
|
|
|
|
await RSVP.all(this.args.nodes.map(node => node.reload()));
|
|
|
|
|
|
|
|
// TODO: Make the range dynamic based on the extent of the domain
|
|
|
|
this.heightScale = scaleLinear()
|
|
|
|
.range([15, 50])
|
|
|
|
.domain([0, max(this.args.nodes.map(node => node.resources.memory))]);
|
|
|
|
this.isLoaded = true;
|
|
|
|
}
|
2020-09-03 02:37:13 +00:00
|
|
|
}
|