4c3fbebefd
* ui: Move components to the new nested structure * Move data-test attribute to the correct HTML element We don't currently rely on this, but was incorrectly placed on the input rather than the label tag * Fix up left over curly bracket components that were causing issues For some reason the combination of: 1. Old style curly bracket components 2. data-test-* attributes 3. Moving to the new component file structure Meant that our data-test-* selectors where no longer being rendered. Whilst this had no effect on the app, it meant our tests suite could no longer select DOM elements in order to assert various things. Moving the old style curly bracket components to the new style XML/Angle bracket format fixes the issue * Update ui-v2/app/templates/dc/nodes/-services.hbs Co-Authored-By: Greg Hoin <1416421+gregone@users.noreply.github.com> * Update ui-v2/app/templates/dc/nodes/-services.hbs Co-Authored-By: Greg Hoin <1416421+gregone@users.noreply.github.com> Co-authored-by: Greg Hoin <1416421+gregone@users.noreply.github.com>
61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
import Component from '@ember/component';
|
|
import { computed, set, get } from '@ember/object';
|
|
|
|
const size = 336;
|
|
const insetSize = size / 2 - 8;
|
|
const inset = function(num) {
|
|
return insetSize * num;
|
|
};
|
|
const milliseconds = function(num, max) {
|
|
return max > 0 ? parseInt(max * num) / 100 : 0;
|
|
};
|
|
export default Component.extend({
|
|
size: size,
|
|
tomography: 0,
|
|
max: -999999999,
|
|
init: function() {
|
|
this._super(...arguments);
|
|
this.circle = [inset(1), inset(0.25), inset(0.5), inset(0.75), inset(1)];
|
|
this.labels = [inset(-0.25), inset(-0.5), inset(-0.75), inset(-1)];
|
|
},
|
|
milliseconds: computed('distances', 'max', function() {
|
|
const max = get(this, 'max');
|
|
return [
|
|
milliseconds(25, max),
|
|
milliseconds(50, max),
|
|
milliseconds(75, max),
|
|
milliseconds(100, max),
|
|
];
|
|
}),
|
|
distances: computed('tomography', function() {
|
|
const tomography = get(this, 'tomography');
|
|
let distances = get(tomography, 'distances') || [];
|
|
// TODO: This should probably be moved into the milliseconds computedProperty
|
|
/*eslint ember/no-side-effects: "warn"*/
|
|
distances.forEach((d, i) => {
|
|
if (d.distance > get(this, 'max')) {
|
|
set(this, 'max', d.distance);
|
|
}
|
|
});
|
|
let n = get(distances, 'length');
|
|
if (n > 360) {
|
|
// We have more nodes than we want to show, take a random sampling to keep
|
|
// the number around 360.
|
|
const sampling = 360 / n;
|
|
distances = distances.filter(function(_, i) {
|
|
return i == 0 || i == n - 1 || Math.random() < sampling;
|
|
});
|
|
n = get(distances, 'length');
|
|
}
|
|
return distances.map((d, i) => {
|
|
return {
|
|
rotate: (i * 360) / n,
|
|
y2: -insetSize * (d.distance / get(this, 'max')),
|
|
node: d.node,
|
|
distance: d.distance,
|
|
segment: d.segment,
|
|
};
|
|
});
|
|
}),
|
|
});
|