github.com/DerekStrickland/consul@v1.4.5/ui-v2/app/components/tomography-graph.js (about) 1 import Component from '@ember/component'; 2 import { computed, set, get } from '@ember/object'; 3 4 const size = 336; 5 const insetSize = size / 2 - 8; 6 const inset = function(num) { 7 return insetSize * num; 8 }; 9 const milliseconds = function(num, max) { 10 return max > 0 ? parseInt(max * num) / 100 : 0; 11 }; 12 export default Component.extend({ 13 size: size, 14 tomography: 0, 15 max: -999999999, 16 init: function() { 17 this._super(...arguments); 18 this.circle = [inset(1), inset(0.25), inset(0.5), inset(0.75), inset(1)]; 19 this.labels = [inset(-0.25), inset(-0.5), inset(-0.75), inset(-1)]; 20 }, 21 milliseconds: computed('distances', 'max', function() { 22 const max = get(this, 'max'); 23 return [ 24 milliseconds(25, max), 25 milliseconds(50, max), 26 milliseconds(75, max), 27 milliseconds(100, max), 28 ]; 29 }), 30 distances: computed('tomography', function() { 31 const tomography = this.get('tomography'); 32 let distances = tomography.distances || []; 33 distances.forEach((d, i) => { 34 if (d.distance > get(this, 'max')) { 35 set(this, 'max', d.distance); 36 } 37 }); 38 if (tomography.n > 360) { 39 let n = distances.length; 40 // We have more nodes than we want to show, take a random sampling to keep 41 // the number around 360. 42 const sampling = 360 / tomography.n; 43 distances = distances.filter(function(_, i) { 44 return i == 0 || i == n - 1 || Math.random() < sampling; 45 }); 46 } 47 return distances.map((d, i) => { 48 return { 49 rotate: i * 360 / distances.length, 50 y2: -insetSize * (d.distance / get(this, 'max')), 51 node: d.node, 52 distance: d.distance, 53 segment: d.segment, 54 }; 55 }); 56 }), 57 });