[TASK] Reduce complexity

This commit is contained in:
Xaver Maierhofer 2017-02-13 00:31:31 +01:00 committed by Xaver Maierhofer
parent 8e1026788f
commit d3079b3222
6 changed files with 52 additions and 75 deletions

View File

@ -7,7 +7,6 @@ define([], function () {
}
var self = this;
var container = document.createElement(tag);
self.add = function add(d) {

View File

@ -84,53 +84,46 @@ define(['polyglot', 'moment', 'router', 'leaflet', 'gui', 'helper', 'language'],
return d.target !== undefined;
});
links.forEach(function (d) {
var unknown = (d.source.node === undefined);
var ids;
if (unknown) {
ids = [d.source.id.replace(/:/g, ''), d.target.node.nodeinfo.node_id];
} else {
ids = [d.source.node.nodeinfo.node_id, d.target.node.nodeinfo.node_id];
}
d.id = ids.join('-');
if (unknown || !d.source.node.nodeinfo.location || !d.target.node.nodeinfo.location ||
isNaN(d.source.node.nodeinfo.location.latitude) ||
isNaN(d.source.node.nodeinfo.location.longitude) ||
isNaN(d.target.node.nodeinfo.location.latitude) ||
isNaN(d.target.node.nodeinfo.location.longitude)) {
return;
}
d.latlngs = [];
d.latlngs.push(L.latLng(d.source.node.nodeinfo.location.latitude, d.source.node.nodeinfo.location.longitude));
d.latlngs.push(L.latLng(d.target.node.nodeinfo.location.latitude, d.target.node.nodeinfo.location.longitude));
d.distance = d.latlngs[0].distanceTo(d.latlngs[1]);
});
nodes.forEach(function (d) {
d.neighbours = [];
});
links.forEach(function (d) {
if (d.target.node.flags.gateway === true || (d.source.node !== undefined && d.source.node.flags.gateway === true)) {
var unknown = (d.source.node === undefined);
var ids;
if (unknown) {
d.target.node.neighbours.push({ id: d.source.id, link: d, incoming: true });
ids = [d.source.id.replace(/:/g, ''), d.target.node.nodeinfo.node_id];
} else {
if (d.target.node.flags.gateway === true || d.source.node.flags.gateway === true) {
d.type = 'fastd';
} else {
d.type = 'N/A';
}
var unknown = (d.source.node === undefined);
if (unknown) {
d.target.node.neighbours.push({ id: d.source.id, link: d, incoming: true });
return;
}
ids = [d.source.node.nodeinfo.node_id, d.target.node.nodeinfo.node_id];
d.source.node.neighbours.push({ node: d.target.node, link: d, incoming: false });
d.target.node.neighbours.push({ node: d.source.node, link: d, incoming: true });
if (d.type !== 'fastd' && d.type !== 'L2TP') {
d.source.node.meshlinks = d.source.node.meshlinks ? d.source.node.meshlinks + 1 : 1;
}
}
d.id = ids.join('-');
try {
d.latlngs = [];
d.latlngs.push(L.latLng(d.source.node.nodeinfo.location.latitude, d.source.node.nodeinfo.location.longitude));
d.latlngs.push(L.latLng(d.target.node.nodeinfo.location.latitude, d.target.node.nodeinfo.location.longitude));
d.distance = d.latlngs[0].distanceTo(d.latlngs[1]);
} catch (e) {
// ignore exception
}
});
links.sort(function (a, b) {
return b.tq - a.tq;
});

View File

@ -368,20 +368,14 @@ define(['map/clientlayer', 'map/labelslayer',
var m;
if (highlight !== undefined) {
if (highlight.type === 'node') {
if (highlight.type === 'node' && nodeDict[highlight.o.nodeinfo.node_id]) {
m = nodeDict[highlight.o.nodeinfo.node_id];
if (m) {
m.setStyle({ color: 'orange', weight: 20, fillOpacity: 1, opacity: 0.7, className: 'stroke-first' });
}
} else if (highlight.type === 'link') {
} else if (highlight.type === 'link' && linkDict[highlight.o.id]) {
m = linkDict[highlight.o.id];
if (m) {
m.setStyle({ weight: 4, opacity: 1, dashArray: '5, 10' });
}
}
}
if (!nopanzoom) {
if (m) {
@ -395,12 +389,11 @@ define(['map/clientlayer', 'map/labelslayer',
}
function mapRTree(d) {
var o = { minX: d.nodeinfo.location.latitude, minY: d.nodeinfo.location.longitude,
maxX: d.nodeinfo.location.latitude, maxY: d.nodeinfo.location.longitude };
o.node = d;
return o;
return {
minX: d.nodeinfo.location.latitude, minY: d.nodeinfo.location.longitude,
maxX: d.nodeinfo.location.latitude, maxY: d.nodeinfo.location.longitude,
node: d
};
}
self.setData = function setData(data) {

View File

@ -31,8 +31,6 @@ define(['leaflet', 'helper'],
}
var ctx = canvas.getContext('2d');
var startDistance = 12;
ctx.beginPath();

View File

@ -22,11 +22,7 @@ define(['leaflet', 'rbush', 'helper'],
}
function mapRTree(d) {
var o = { minX: d.position.lat, minY: d.position.lng, maxX: d.position.lat, maxY: d.position.lng };
o.label = d;
return o;
return { minX: d.position.lat, minY: d.position.lng, maxX: d.position.lat, maxY: d.position.lng, label: d };
}
function prepareLabel(fillStyle, fontSize, offset, stroke) {

View File

@ -63,21 +63,6 @@ define(['helper'], function (helper) {
return true;
}
function gotoLocation(d) {
if (!d) {
return false;
}
targets.forEach(function (t) {
if (!t.gotoLocation) {
console.warn('has no gotoLocation', t);
}
t.gotoLocation(d);
});
return true;
}
function loadState(s, update) {
if (!s) {
return false;
@ -202,7 +187,20 @@ define(['helper'], function (helper) {
};
};
self.gotoLocation = gotoLocation;
self.gotoLocation = function gotoLocation(d) {
if (!d) {
return false;
}
targets.forEach(function (t) {
if (!t.gotoLocation) {
console.warn('has no gotoLocation', t);
}
t.gotoLocation(d);
});
return true;
};
self.reset = function reset() {
resetView();