2017-01-29 23:51:08 +00:00
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
define({
|
2017-01-29 23:51:08 +00:00
|
|
|
get: function get(url) {
|
2016-05-26 16:37:24 +00:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
var req = new XMLHttpRequest();
|
2017-01-29 23:51:08 +00:00
|
|
|
req.open('GET', url);
|
2016-05-26 16:37:24 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
req.onload = function onload() {
|
|
|
|
if (req.status === 200) {
|
2016-05-26 16:37:24 +00:00
|
|
|
resolve(req.response);
|
2017-01-29 23:51:08 +00:00
|
|
|
} else {
|
2016-05-26 16:37:24 +00:00
|
|
|
reject(Error(req.statusText));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
req.onerror = function onerror() {
|
|
|
|
reject(Error('Network Error'));
|
2016-05-26 16:37:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
req.send();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
getJSON: function getJSON(url) {
|
|
|
|
return require('helper').get(url).then(JSON.parse);
|
2016-05-26 16:37:24 +00:00
|
|
|
},
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
sortByKey: function sortByKey(key, d) {
|
2016-05-26 16:37:24 +00:00
|
|
|
return d.slice().sort(function (a, b) {
|
|
|
|
return a[key] - b[key];
|
|
|
|
}).reverse();
|
|
|
|
},
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
limit: function limit(key, m, d) {
|
|
|
|
return d.filter(function (n) {
|
|
|
|
return n[key].isAfter(m);
|
2016-05-26 16:37:24 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
sum: function sum(a) {
|
|
|
|
return a.reduce(function (b, c) {
|
|
|
|
return b + c;
|
2016-05-26 16:37:24 +00:00
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
one: function one() {
|
2016-05-26 16:37:24 +00:00
|
|
|
return 1;
|
|
|
|
},
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
dictGet: function dictGet(dict, key) {
|
2016-05-26 16:37:24 +00:00
|
|
|
var k = key.shift();
|
|
|
|
|
|
|
|
if (!(k in dict)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
if (key.length === 0) {
|
2016-05-26 16:37:24 +00:00
|
|
|
return dict[k];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.dictGet(dict[k], key);
|
|
|
|
},
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
listReplace: function listReplace(s, subst) {
|
2016-05-27 21:59:01 +00:00
|
|
|
for (var key in subst) {
|
2017-04-30 12:59:39 +00:00
|
|
|
if (subst.hasOwnProperty(key)) {
|
|
|
|
var re = new RegExp(key, 'g');
|
|
|
|
s = s.replace(re, subst[key]);
|
|
|
|
}
|
2016-05-26 16:37:24 +00:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Helpers working with nodes */
|
2017-01-29 23:51:08 +00:00
|
|
|
offline: function offline(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
return !d.is_online;
|
2016-05-26 16:37:24 +00:00
|
|
|
},
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
online: function online(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
return d.is_online;
|
2016-05-26 16:37:24 +00:00
|
|
|
},
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
hasLocation: function hasLocation(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
return 'location' in d &&
|
|
|
|
Math.abs(d.location.latitude) < 90 &&
|
|
|
|
Math.abs(d.location.longitude) < 180;
|
2016-05-26 16:37:24 +00:00
|
|
|
},
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
subtract: function subtract(a, b) {
|
2016-05-26 16:37:24 +00:00
|
|
|
var ids = {};
|
|
|
|
|
|
|
|
b.forEach(function (d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
ids[d.node_id] = true;
|
2016-05-26 16:37:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return a.filter(function (d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
return !(d.node_id in ids);
|
2016-05-26 16:37:24 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Helpers working with links */
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
showDistance: function showDistance(d) {
|
2016-05-26 16:37:24 +00:00
|
|
|
if (isNaN(d.distance)) {
|
2017-01-29 23:51:08 +00:00
|
|
|
return '';
|
2016-05-26 16:37:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
return d.distance.toFixed(0) + ' m';
|
2016-05-26 16:37:24 +00:00
|
|
|
},
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
showTq: function showTq(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
return (d * 100).toFixed(0) + '%';
|
2016-05-26 16:37:24 +00:00
|
|
|
},
|
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
attributeEntry: function attributeEntry(V, label, value) {
|
2017-10-29 19:52:17 +00:00
|
|
|
if (value === undefined) {
|
2017-01-29 23:51:08 +00:00
|
|
|
return '';
|
2016-05-26 16:37:24 +00:00
|
|
|
}
|
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
if (typeof value !== 'object') {
|
|
|
|
value = V.h('td', value);
|
2016-05-26 16:37:24 +00:00
|
|
|
}
|
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
return V.h('tr', [
|
|
|
|
V.h('th', _.t(label)),
|
|
|
|
value
|
|
|
|
]);
|
2016-05-26 16:37:24 +00:00
|
|
|
},
|
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
showStat: function showStat(V, o, subst) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var content;
|
|
|
|
subst = typeof subst !== 'undefined' ? subst : {};
|
2016-05-26 16:37:24 +00:00
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
content = V.h('img', { attrs: { src: require('helper').listReplace(o.image, subst) } });
|
2016-05-26 16:37:24 +00:00
|
|
|
|
|
|
|
if (o.href) {
|
2017-10-29 14:11:24 +00:00
|
|
|
return V.h('p', V.h('a', {
|
|
|
|
attrs:
|
|
|
|
{
|
|
|
|
href: require('helper').listReplace(o.href, subst),
|
|
|
|
target: '_blank',
|
|
|
|
title: require('helper').listReplace(o.title, subst)
|
|
|
|
}
|
|
|
|
}, content));
|
2016-05-26 16:37:24 +00:00
|
|
|
}
|
2017-10-29 14:11:24 +00:00
|
|
|
return V.h('p', content);
|
2017-02-05 01:34:09 +00:00
|
|
|
},
|
2017-02-05 21:42:59 +00:00
|
|
|
|
2017-02-05 01:34:09 +00:00
|
|
|
getTileBBox: function getTileBBox(s, map, tileSize, margin) {
|
|
|
|
var tl = map.unproject([s.x - margin, s.y - margin]);
|
|
|
|
var br = map.unproject([s.x + margin + tileSize, s.y + margin + tileSize]);
|
|
|
|
|
2017-02-06 00:50:08 +00:00
|
|
|
return { minX: br.lat, minY: tl.lng, maxX: tl.lat, maxY: br.lng };
|
2017-02-09 08:29:01 +00:00
|
|
|
},
|
2017-10-28 23:38:43 +00:00
|
|
|
positionClients: function positionClients(ctx, p, startAngle, node, startDistance) {
|
|
|
|
if (node.clients === 0) {
|
2017-02-09 08:29:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var radius = 3;
|
|
|
|
var a = 1.2;
|
2017-10-28 23:38:43 +00:00
|
|
|
var mode = 0;
|
2017-02-09 08:29:01 +00:00
|
|
|
|
2017-10-29 10:36:29 +00:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.fillStyle = 'rgba(220, 0, 103, 0.7)';
|
|
|
|
|
2017-10-28 23:38:43 +00:00
|
|
|
for (var orbit = 0, i = 0; i < node.clients; orbit++) {
|
2017-02-09 08:29:01 +00:00
|
|
|
var distance = startDistance + orbit * 2 * radius * a;
|
|
|
|
var n = Math.floor((Math.PI * distance) / (a * radius));
|
2017-10-28 23:38:43 +00:00
|
|
|
var delta = node.clients - i;
|
2017-02-09 08:29:01 +00:00
|
|
|
|
|
|
|
for (var j = 0; j < Math.min(delta, n); i++, j++) {
|
2017-10-28 23:38:43 +00:00
|
|
|
if (mode !== 1 && i >= (node.clients_wifi24 + node.clients_wifi5)) {
|
|
|
|
mode = 1;
|
|
|
|
ctx.fill();
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.fillStyle = 'rgba(10, 156, 146, 0.7)';
|
|
|
|
} else if (mode === 0 && i >= node.clients_wifi24) {
|
|
|
|
mode = 2;
|
|
|
|
ctx.fill();
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.fillStyle = 'rgba(227, 166, 25, 0.7)';
|
|
|
|
}
|
2017-02-09 08:29:01 +00:00
|
|
|
var angle = 2 * Math.PI / n * j;
|
|
|
|
var x = p.x + distance * Math.cos(angle + startAngle);
|
|
|
|
var y = p.y + distance * Math.sin(angle + startAngle);
|
|
|
|
|
|
|
|
ctx.moveTo(x, y);
|
|
|
|
ctx.arc(x, y, radius, 0, 2 * Math.PI);
|
|
|
|
}
|
|
|
|
}
|
2017-10-29 10:36:29 +00:00
|
|
|
ctx.fill();
|
2016-05-26 16:37:24 +00:00
|
|
|
}
|
|
|
|
});
|