2021-03-29 20:49:50 +02:00
|
|
|
|
2021-03-30 16:30:50 +02:00
|
|
|
const CONFIG = {
|
2021-05-04 18:40:06 +02:00
|
|
|
'title': "Remote Biometric Identification",
|
|
|
|
'subtitle': "A survey of the European Union",
|
2021-04-27 16:10:23 +02:00
|
|
|
// 'nodeSize': 8,
|
|
|
|
'nodeRadius': 5,
|
2021-05-06 10:55:14 +02:00
|
|
|
'nodeRepositionPadding': 12,
|
2021-03-30 16:30:50 +02:00
|
|
|
'baseUrl': 'https://www.securityvision.io/wiki/index.php/',
|
2021-08-13 11:57:57 +02:00
|
|
|
'dataUrl': 'remote_biometric_identification.json',
|
2021-03-31 16:24:46 +02:00
|
|
|
'preSimulate': false, // run simulation before starting, so we don't start with lines jumping around
|
2021-03-30 16:30:50 +02:00
|
|
|
'labels': {
|
|
|
|
'rotate': true,
|
|
|
|
},
|
2021-04-16 11:15:57 +02:00
|
|
|
'countries': ['Austria', 'Italy', 'Belgium', 'Latvia', 'Bulgaria', 'Lithuania', 'Croatia', 'Luxembourg', 'Cyprus', 'Malta', 'Czechia', 'Netherlands', 'Denmark', 'Poland', 'Estonia', 'Portugal', 'Finland ', 'Romania', 'France', 'Slovakia', 'Germany', 'Slovenia', 'Greece', 'Spain', 'Hungary', 'Sweden', 'Ireland'],
|
2021-03-31 16:24:46 +02:00
|
|
|
'eu': {
|
|
|
|
'lonMin': -10,
|
2021-03-31 17:02:00 +02:00
|
|
|
'lonMax': 35,
|
|
|
|
'center': [11, 47],
|
2021-04-16 11:15:57 +02:00
|
|
|
},
|
2021-08-13 11:20:44 +02:00
|
|
|
"institution_map": {
|
|
|
|
"Local Government": "Government",
|
|
|
|
"Regional Government": "Government",
|
|
|
|
"International Organization": "Government",
|
|
|
|
"Watchdog": "Government",
|
|
|
|
// "NGO": "Organisation",
|
|
|
|
"Foundation": "NGO",
|
|
|
|
"University": "Research",
|
|
|
|
"Expert Group": "Research",
|
|
|
|
},
|
2021-05-06 10:55:14 +02:00
|
|
|
"filters": {
|
|
|
|
"Institution": {
|
|
|
|
"label": "Institution",
|
|
|
|
"type": "categories",
|
|
|
|
},
|
2021-08-12 09:00:05 +02:00
|
|
|
// TODO: nested filters
|
|
|
|
// TODO:restructure, allow for groups of types:
|
|
|
|
// [12:08, 07-05-2021] Francesco Ragazzi: Government / Regional / local can be the same
|
|
|
|
// [12:08, 07-05-2021] Francesco Ragazzi: Also IO
|
|
|
|
// [12:08, 07-05-2021] Francesco Ragazzi: NGO, Foundation can be grouped
|
|
|
|
// [12:08, 07-05-2021] Francesco Ragazzi: University, Research, Expert group can be grouped
|
|
|
|
// [12:08, 07-05-2021] Francesco Ragazzi: Watchdog and can also be grouped with government
|
2021-05-06 10:55:14 +02:00
|
|
|
"Government": {
|
|
|
|
// "label": "Institution",
|
|
|
|
"type": "institution_types",
|
|
|
|
},
|
2021-08-13 11:20:44 +02:00
|
|
|
"Law Enforcement": {
|
2021-05-06 10:55:14 +02:00
|
|
|
// "label": "Institution",
|
|
|
|
"type": "institution_types",
|
|
|
|
},
|
|
|
|
"Company": {
|
|
|
|
// "label": "Institution",
|
|
|
|
"type": "institution_types",
|
|
|
|
},
|
2021-08-13 11:20:44 +02:00
|
|
|
"NGO": {
|
2021-05-06 10:55:14 +02:00
|
|
|
// "label": "Institution",
|
|
|
|
"type": "institution_types",
|
|
|
|
},
|
2021-08-13 11:20:44 +02:00
|
|
|
|
|
|
|
// "Regional Government": {
|
|
|
|
// // "label": "Institution",
|
|
|
|
// "type": "institution_types",
|
|
|
|
// },
|
|
|
|
// "Local Government": {
|
|
|
|
// // "label": "Institution",
|
|
|
|
// "type": "institution_types",
|
|
|
|
// },
|
|
|
|
// "Foundation": {
|
|
|
|
// // "label": "Institution",
|
|
|
|
// "type": "institution_types",
|
|
|
|
// },
|
|
|
|
// "University": {
|
|
|
|
// // "label": "Institution",
|
|
|
|
// "type": "institution_types",
|
|
|
|
// },
|
2021-05-06 10:55:14 +02:00
|
|
|
"Research": {
|
|
|
|
// "label": "Institution",
|
|
|
|
"type": "institution_types",
|
|
|
|
},
|
2021-08-13 11:20:44 +02:00
|
|
|
// "Labour Union": {
|
|
|
|
// // "label": "Institution",
|
|
|
|
// "type": "institution_types",
|
|
|
|
// },
|
|
|
|
// "Watchdog": {
|
|
|
|
// // "label": "Institution",
|
|
|
|
// "type": "institution_types",
|
|
|
|
// },
|
|
|
|
// "Expert Group": {
|
|
|
|
// // "label": "Institution",
|
|
|
|
// "type": "institution_types",
|
|
|
|
// },
|
|
|
|
// "International Organization": {
|
|
|
|
// // "label": "Institution",
|
|
|
|
// "type": "institution_types",
|
|
|
|
// },
|
|
|
|
// "Art Project": {
|
|
|
|
// // "label": "Institution",
|
|
|
|
// "type": "institution_types",
|
|
|
|
// },
|
2021-05-06 10:55:14 +02:00
|
|
|
"Deployments": {
|
|
|
|
"label": "Deployment",
|
|
|
|
"type": "categories",
|
|
|
|
},
|
|
|
|
|
|
|
|
/* "Technology", "Dataset"*/
|
|
|
|
},
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
"link_properties": [
|
|
|
|
"Clients",
|
|
|
|
"Managed by",
|
|
|
|
"Used by",
|
|
|
|
"Funded by",
|
|
|
|
"Provided by",
|
|
|
|
"Software Deployed",
|
|
|
|
"Software Developer",
|
|
|
|
"Dataset Developer",
|
2021-08-12 09:00:05 +02:00
|
|
|
"Related Institutions",
|
2021-10-13 18:35:49 +02:00
|
|
|
"Is Department Of",
|
2021-08-12 09:00:05 +02:00
|
|
|
"Involved Entities",
|
2021-04-17 21:15:03 +02:00
|
|
|
],
|
|
|
|
|
2021-08-12 09:00:05 +02:00
|
|
|
"link_labels": {
|
|
|
|
"Clients": {
|
|
|
|
"label": "is client of",
|
|
|
|
"swap": true,
|
|
|
|
},
|
|
|
|
"Managed by": {
|
|
|
|
"label": "manages",
|
|
|
|
"swap": true,
|
|
|
|
},
|
|
|
|
"Used by": {
|
|
|
|
"label": "uses",
|
|
|
|
"swap": true,
|
|
|
|
},
|
|
|
|
"Funded by": {
|
|
|
|
"label": "is funded by",
|
|
|
|
"swap": false,
|
|
|
|
},
|
|
|
|
"Provided by": {
|
|
|
|
"label": "provides",
|
|
|
|
"swap": true,
|
|
|
|
},
|
|
|
|
"Software Deployed": {
|
|
|
|
"label": "is used in",
|
|
|
|
"swap": true,
|
|
|
|
},
|
|
|
|
"Software Developer": {
|
|
|
|
"label": "is developed by",
|
|
|
|
"swap": false,
|
|
|
|
},
|
|
|
|
"Dataset Developer": {
|
|
|
|
"label": "develops dataset for",
|
|
|
|
"swap": true,
|
|
|
|
},
|
|
|
|
"Related Institutions": {
|
|
|
|
"label": "is related to",
|
|
|
|
"swap": true,
|
|
|
|
},
|
2021-10-13 18:35:49 +02:00
|
|
|
"Is Department Of": {
|
|
|
|
"label": "is part of",
|
|
|
|
"swap": false,
|
|
|
|
},
|
2021-08-12 09:00:05 +02:00
|
|
|
"Involved Entities": {
|
|
|
|
"label": "is involved in",
|
|
|
|
"swap": true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
"geo_properties": [
|
|
|
|
"Geolocation",
|
|
|
|
"City Coordinates",
|
|
|
|
"Country Coordinates",
|
|
|
|
],
|
|
|
|
|
|
|
|
"geo_property_map": { // used to work around a bug in SMW
|
|
|
|
"City Coordinates": "City",
|
|
|
|
"Country Coordinates": "City Country",
|
2021-04-19 22:47:06 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
"alluvial_cats": ["Deployments"],
|
|
|
|
"alluvial_props": {
|
|
|
|
"Country": ["Country"],
|
|
|
|
"City": ["City"],
|
|
|
|
// ["Deployment type"], // TODO: select this
|
2021-08-12 09:00:05 +02:00
|
|
|
"Institution": ["Institution Type"], // TODO: select this (local gov, etc.)
|
2021-04-19 22:47:06 +02:00
|
|
|
"Dataset": ["Datasets used"],
|
|
|
|
"Company": ["Managed by", "Provided by", "Developped by (institutions)"],
|
|
|
|
"Tech": ["Technologies Used", "Software Deployed"],
|
|
|
|
"Funding": ["Funded by"],
|
2021-04-29 15:36:27 +02:00
|
|
|
},
|
|
|
|
"zoom": {
|
|
|
|
"scale_min": .2,
|
2021-08-13 11:20:44 +02:00
|
|
|
"scale_max": 10,
|
2021-04-29 15:36:27 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
"cases": [
|
|
|
|
"Data-lab Burglary-Free Neighbourhood",
|
|
|
|
"Dragonfly Project",
|
|
|
|
]
|
2021-04-17 21:15:03 +02:00
|
|
|
};
|
2021-03-31 17:02:00 +02:00
|
|
|
|
2021-08-12 09:00:05 +02:00
|
|
|
|
|
|
|
function getLinkLabelConfig(linkName){
|
|
|
|
if(CONFIG.link_labels.hasOwnProperty(linkName)){
|
|
|
|
return CONFIG.link_labels[linkName];
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
'label': linkName,
|
|
|
|
'swap': false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
// let width = window.innerWidth;
|
|
|
|
// let height = window.innerHeight;
|
2021-03-31 17:02:00 +02:00
|
|
|
|
2021-04-16 11:15:57 +02:00
|
|
|
|
2021-04-28 11:18:02 +02:00
|
|
|
function getSymbolForCategories(classes) {
|
2021-04-29 15:36:27 +02:00
|
|
|
if (!Array.isArray(classes)) {
|
2021-04-28 11:18:02 +02:00
|
|
|
classes = [classes];
|
|
|
|
}
|
|
|
|
if (classes.includes('Institution')) {
|
|
|
|
return d3.symbol()
|
|
|
|
.type(d3.symbolTriangle)
|
|
|
|
.size(CONFIG.nodeRadius * 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
return d3.symbol()
|
|
|
|
.type(d3.symbolCircle)
|
|
|
|
.size(CONFIG.nodeRadius * 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns a symbol function
|
|
|
|
function getSymbolForNode(n) {
|
|
|
|
const classes = getCategories(n);
|
|
|
|
return getSymbolForCategories(classes);
|
|
|
|
}
|
|
|
|
|
2021-04-28 09:38:06 +02:00
|
|
|
// Slugify a string, by https://lucidar.me/en/web-dev/how-to-slugify-a-string-in-javascript/
|
|
|
|
function slugify(str) {
|
|
|
|
str = str.replace(/^\s+|\s+$/g, '');
|
|
|
|
|
|
|
|
// Make the string lowercase
|
|
|
|
str = str.toLowerCase();
|
|
|
|
|
|
|
|
// Remove accents, swap ñ for n, etc
|
|
|
|
var from = "ÁÄÂÀÃÅČÇĆĎÉĚËÈÊẼĔȆÍÌÎÏŇÑÓÖÒÔÕØŘŔŠŤÚŮÜÙÛÝŸŽáäâàãåčçćďéěëèêẽĕȇíìîïňñóöòôõøðřŕšťúůüùûýÿžþÞĐđßÆa·/_,:;";
|
|
|
|
var to = "AAAAAACCCDEEEEEEEEIIIINNOOOOOORRSTUUUUUYYZaaaaaacccdeeeeeeeeiiiinnooooooorrstuuuuuyyzbBDdBAa------";
|
|
|
|
for (var i = 0, l = from.length; i < l; i++) {
|
|
|
|
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove invalid chars
|
|
|
|
str = str.replace(/[^a-z0-9 -]/g, '')
|
|
|
|
// Collapse whitespace and replace by -
|
|
|
|
.replace(/\s+/g, '-')
|
|
|
|
// Collapse dashes
|
|
|
|
.replace(/-+/g, '-');
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
2021-04-16 11:15:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-30 16:30:50 +02:00
|
|
|
function getSizeForNode(node) {
|
|
|
|
// if (node.hasOwnProperty('https://schema.org/thumbnailUrl')) return nodeSize;
|
|
|
|
// if (weights[node['@id']]) return nodeSize * weights[node['@id']];
|
|
|
|
// if (node['@id'] == firstNodeId) return nodeSize * 1.2;
|
|
|
|
// // everynode has at least one link. these should equal 1
|
|
|
|
// return nodeSize * (.7 + Math.min(20, linkMap[node['@id']].length) / 40);
|
|
|
|
if (node.parent) {
|
|
|
|
return 2;
|
|
|
|
}
|
2021-03-31 16:24:46 +02:00
|
|
|
// if(getCategories(node).indexOf('City') !== -1) {
|
|
|
|
// return 2;
|
|
|
|
// }
|
2021-03-30 16:30:50 +02:00
|
|
|
return CONFIG.nodeSize;
|
2021-03-29 20:49:50 +02:00
|
|
|
}
|
|
|
|
|
2021-03-30 16:30:50 +02:00
|
|
|
function splitText(text) {
|
|
|
|
var characters = [" ", "-", "_", '\xAD'];
|
|
|
|
var charSplitPos = {};
|
|
|
|
var mid = Math.floor(text.length / 2);
|
|
|
|
var splitPos = false;
|
|
|
|
var splitPosChar = false;
|
|
|
|
// split sentences
|
|
|
|
var _iteratorNormalCompletion6 = true;
|
|
|
|
var _didIteratorError6 = false;
|
|
|
|
var _iteratorError6 = undefined;
|
|
|
|
|
|
|
|
try {
|
|
|
|
for (var _iterator6 = characters[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
|
|
|
|
var char = _step6.value;
|
|
|
|
|
|
|
|
if (text.indexOf(char) < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var tmid = text.substr(0, mid).lastIndexOf(char);
|
|
|
|
if (tmid === -1) {
|
|
|
|
tmid = text.indexOf(char);
|
|
|
|
}
|
|
|
|
tmid += 1; // we want to cut _after_ the character
|
|
|
|
// console.log("Char", char, tmid);
|
|
|
|
if (splitPos === false || Math.abs(tmid - mid) < Math.abs(splitPos - mid)) {
|
|
|
|
// console.log("least!");
|
|
|
|
splitPos = tmid;
|
|
|
|
splitPosChar = char;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// console.log("pos",splitPos)
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
_didIteratorError6 = true;
|
|
|
|
_iteratorError6 = err;
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (!_iteratorNormalCompletion6 && _iterator6.return) {
|
|
|
|
_iterator6.return();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (_didIteratorError6) {
|
|
|
|
throw _iteratorError6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-29 20:49:50 +02:00
|
|
|
|
2021-03-30 16:30:50 +02:00
|
|
|
if (splitPos === false) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-29 20:49:50 +02:00
|
|
|
|
2021-03-30 16:30:50 +02:00
|
|
|
var text1 = text.substr(0, splitPos).trim();
|
|
|
|
var text2 = text.substr(splitPos).trim();
|
2021-03-29 20:49:50 +02:00
|
|
|
|
2021-03-30 16:30:50 +02:00
|
|
|
if (splitPosChar == '\xAD') {
|
|
|
|
text1 += "-";
|
|
|
|
}
|
2021-03-29 20:49:50 +02:00
|
|
|
|
2021-03-30 16:30:50 +02:00
|
|
|
// find most equal split
|
|
|
|
return [text1, text2];
|
|
|
|
};
|
2021-03-29 20:49:50 +02:00
|
|
|
|
2021-03-30 16:30:50 +02:00
|
|
|
function getTitle(obj) {
|
2021-04-17 21:15:03 +02:00
|
|
|
return obj.fulltext;
|
2021-03-30 16:30:50 +02:00
|
|
|
}
|
2021-03-31 16:24:46 +02:00
|
|
|
function getCategories(obj) {
|
2021-04-17 21:15:03 +02:00
|
|
|
// console.log(obj);
|
2021-05-06 10:55:14 +02:00
|
|
|
let cats = obj.printouts['Category'].map(n => n.fulltext.split(':')[1]);
|
2021-08-12 09:00:05 +02:00
|
|
|
if (obj.printouts.hasOwnProperty("Institution Type") && obj.printouts['Institution Type'].length) {
|
2021-05-06 10:55:14 +02:00
|
|
|
obj.printouts['Institution Type'].forEach(type => {
|
|
|
|
cats.push(getInstitutionClass(type.fulltext));
|
|
|
|
});
|
|
|
|
}
|
2021-08-13 11:20:44 +02:00
|
|
|
// return
|
2021-05-06 10:55:14 +02:00
|
|
|
return cats;
|
|
|
|
}
|
|
|
|
function getInstitutionClass(name) {
|
2021-08-12 09:00:05 +02:00
|
|
|
return "Institution-" + slugify(name);
|
2021-03-31 16:24:46 +02:00
|
|
|
}
|
2021-03-30 16:30:50 +02:00
|
|
|
function getClasses(obj) {
|
2021-03-31 16:24:46 +02:00
|
|
|
const classes = getCategories(obj);
|
2021-03-30 16:30:50 +02:00
|
|
|
return 'node ' + classes.join(' ');
|
|
|
|
}
|
2021-03-31 17:02:00 +02:00
|
|
|
|
2021-04-29 15:36:27 +02:00
|
|
|
function getLinkId(link) {
|
|
|
|
return "link_" + link.nr;
|
|
|
|
// return "link-" + link.source.id + '-' + link.target.id + '-' + slugify(link.name);
|
|
|
|
}
|
|
|
|
|
2021-03-31 17:02:00 +02:00
|
|
|
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
class NodeMap {
|
|
|
|
constructor(parent) {
|
2021-10-13 18:35:49 +02:00
|
|
|
this.ready = false;
|
|
|
|
this.readyCallback = false;
|
2021-04-17 21:15:03 +02:00
|
|
|
this.root = d3.select(parent);
|
|
|
|
this.resizeEvent = window.addEventListener('resize', this.resize.bind(this));
|
2021-04-29 15:36:27 +02:00
|
|
|
this.tooltipEl = document.getElementById('tooltip');
|
2021-10-07 08:04:30 +02:00
|
|
|
this.sourcesEl = document.getElementById('sources');
|
2021-04-29 15:36:27 +02:00
|
|
|
this.selectedNode = null;
|
2021-08-13 11:57:57 +02:00
|
|
|
|
|
|
|
document.getElementById('closeSelection').addEventListener('click', (ev) => this.deselectNode());
|
2021-04-17 21:15:03 +02:00
|
|
|
}
|
2021-04-16 11:15:57 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
resize() {
|
|
|
|
this.width = window.innerWidth;
|
|
|
|
this.height = window.innerHeight;
|
|
|
|
this.vbWidth = 2000;
|
|
|
|
this.vbHeight = 2000;
|
|
|
|
this.svg
|
|
|
|
.attr("viewBox", [0, 0, this.vbWidth, this.vbHeight])
|
|
|
|
.attr("width", this.width)
|
|
|
|
.attr("height", this.height);
|
|
|
|
}
|
2021-03-31 17:02:00 +02:00
|
|
|
|
2021-04-16 11:15:57 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
reset() {
|
|
|
|
this.root.select('svg').remove();
|
|
|
|
this.render();
|
|
|
|
}
|
2021-04-16 11:15:57 +02:00
|
|
|
|
2021-08-13 11:20:44 +02:00
|
|
|
// calculate which text labels overlap.
|
2021-04-19 19:49:33 +02:00
|
|
|
calculateLabels() {
|
2021-08-13 11:20:44 +02:00
|
|
|
let els;
|
|
|
|
if(this.selectedNode === null) {
|
|
|
|
els = document.querySelectorAll('.node text')
|
|
|
|
} else {
|
|
|
|
// only related texts are visible
|
|
|
|
// so only these need to be considered
|
|
|
|
els = document.querySelectorAll('.node.linkedSelected text, .node.selected text')
|
|
|
|
}
|
2021-04-19 19:49:33 +02:00
|
|
|
for (let i = 0; i < els.length; i++) {
|
|
|
|
const el = els[i];
|
|
|
|
let overlapping = false;
|
|
|
|
for (let index = 0; index < i; index++) {
|
|
|
|
const el2 = els[index];
|
|
|
|
const box1 = el.getBoundingClientRect()
|
|
|
|
const box2 = el2.getBoundingClientRect()
|
|
|
|
const overlap = !(box1.right < box2.left ||
|
|
|
|
box1.left > box2.right ||
|
|
|
|
box1.bottom < box2.top ||
|
|
|
|
box1.top > box2.bottom)
|
2021-04-19 22:47:06 +02:00
|
|
|
if (overlap) {
|
2021-04-19 19:49:33 +02:00
|
|
|
// TODO: try to flip labels horizontally to see if that helps
|
|
|
|
el.classList.add('overlapping');
|
|
|
|
overlapping = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-04-19 22:47:06 +02:00
|
|
|
if (!overlapping)
|
2021-04-19 19:49:33 +02:00
|
|
|
el.classList.remove('overlapping');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
render() {
|
|
|
|
this.svg = this.root.append('svg')
|
2021-08-12 09:00:05 +02:00
|
|
|
this.svg.append('defs').html(`<marker markerHeight="3" markerWidth="3" refY="0" refX="6" viewBox="0 -3 8 6" preserveAspectRatio="none" orient="auto" id="arrowHead" ><path d="M0,-3L8,0L0,3"></path></marker><marker markerHeight="3" markerWidth="3" refY="0" refX="6" viewBox="0 -3 8 6" preserveAspectRatio="none" orient="auto" id="arrowHeadSelected"><path d="M0,-3L8,0L0,3"></path></marker><marker markerHeight="3" markerWidth="3" refY="0" refX="6" viewBox="0 -3 8 6" preserveAspectRatio="none" orient="auto" id="arrowHeadSelectedRelated"><path d="M0,-3L8,0L0,3"></path></marker>
|
2021-04-28 10:24:07 +02:00
|
|
|
<!--Sketching:-->
|
|
|
|
<defs>
|
|
|
|
<filter id="tint">
|
|
|
|
<feColorMatrix values="1.1 0 0 0 0 0 1.1 0 0 0 0 0 0.9 0 0 0 0 0 1 0" />
|
|
|
|
</filter>
|
|
|
|
<filter id="splotch">
|
|
|
|
<feTurbulence type="fractalNoise" baseFrequency=".01" numOctaves="4" />
|
|
|
|
<feColorMatrix values="0 0 0 0 0, 0 0 0 0 0, 0 0 0 0 0, 0 0 0 -0.9 1.2" result="texture" />
|
|
|
|
<feComposite in="SourceGraphic" in2="texture" operator="in" />
|
|
|
|
<feGaussianBlur stdDeviation="3.5" />
|
|
|
|
</filter>
|
|
|
|
<filter id="pencil">
|
|
|
|
<feTurbulence baseFrequency="0.03" numOctaves="6" type="fractalNoise" />
|
|
|
|
<feDisplacementMap scale="4" in="SourceGraphic" xChannelSelector="R" yChannelSelector="G" />
|
|
|
|
<feGaussianBlur stdDeviation="0.5" />
|
|
|
|
</filter>
|
|
|
|
</defs>`);
|
2021-04-28 09:38:06 +02:00
|
|
|
|
2021-08-12 09:00:05 +02:00
|
|
|
this.svg.on('click', (e) => { console.log(e); this.deselectNode() })
|
2021-05-04 18:40:06 +02:00
|
|
|
|
|
|
|
// const noise = 0.001;
|
|
|
|
// this.svg.append('defs').append('filter').attr('id', 'splotch').html( `${
|
|
|
|
// noise
|
|
|
|
// ? `<feTurbulence
|
|
|
|
// type="fractalNoise"
|
|
|
|
// baseFrequency="${noise}"
|
|
|
|
// numOctaves="4"
|
|
|
|
// ></feTurbulence>
|
|
|
|
// <feColorMatrix
|
|
|
|
// values="0 0 0 0 0, 0 0 0 0 0, 0 0 0 0 0, 0 0 0 -0.9 0.2"
|
|
|
|
// result="texture"
|
|
|
|
// ></feColorMatrix>
|
|
|
|
// <feComposite
|
|
|
|
// in="SourceGraphic"
|
|
|
|
// in2="texture"
|
|
|
|
// operator="in"
|
|
|
|
// ></feComposite>`
|
|
|
|
// : ``
|
|
|
|
// }`)
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
this.resize();
|
|
|
|
|
|
|
|
this.projection = d3.geoHill()
|
|
|
|
.rotate([-12, 0, 0])
|
2021-04-19 19:49:33 +02:00
|
|
|
.translate([this.vbWidth, this.vbHeight * 3])
|
|
|
|
.scale(this.vbHeight * 3);
|
2021-04-17 21:15:03 +02:00
|
|
|
|
|
|
|
this.nodeSize = this.vbHeight / 200;
|
|
|
|
|
|
|
|
this.proj = d3.geoPath().projection(this.projection);
|
|
|
|
const graticule = d3.geoGraticule10();
|
|
|
|
const euCenter = this.projection(CONFIG.eu.center);
|
|
|
|
|
2021-04-19 19:49:33 +02:00
|
|
|
this.container = this.svg.append("g").attr("id", "container");
|
2021-04-17 21:15:03 +02:00
|
|
|
// container.append("circle").attr("cx", euCenter[0]).attr("cy", euCenter[1]).attr("r", 500).attr("fill","red")
|
|
|
|
|
2021-04-19 19:49:33 +02:00
|
|
|
this.g_countries = this.container.append("g").attr("id", "countries");
|
|
|
|
this.g_borders = this.container.append("g").attr("id", "borders");
|
|
|
|
this.g_graticule = this.container.append("g").attr('id', 'graticule')
|
2021-04-17 21:15:03 +02:00
|
|
|
.append('path')
|
|
|
|
.attr("class", "graticule")
|
|
|
|
.attr("fill", "none")
|
|
|
|
.attr('d', this.proj(graticule))
|
|
|
|
.attr("stroke-width", "!px")
|
|
|
|
.attr("stroke", (n) => {
|
|
|
|
return "lightgray";
|
|
|
|
});
|
|
|
|
;
|
2021-04-16 11:15:57 +02:00
|
|
|
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
const c = this.g_countries.selectAll("path")
|
|
|
|
.data(this.countries)
|
|
|
|
.enter()
|
|
|
|
.append("path")
|
2021-04-28 09:38:06 +02:00
|
|
|
.attr("class", (n) => {
|
2021-04-17 21:15:03 +02:00
|
|
|
if (CONFIG.countries.indexOf(n.properties.name) !== -1) {
|
2021-04-28 09:38:06 +02:00
|
|
|
return 'country eu_country';
|
2021-04-17 21:15:03 +02:00
|
|
|
}
|
2021-04-28 09:38:06 +02:00
|
|
|
return "country";
|
|
|
|
})
|
|
|
|
.attr("d", this.proj)
|
2021-08-12 09:00:05 +02:00
|
|
|
// .attr("filter", 'url(#splotch)')
|
2021-04-28 09:38:06 +02:00
|
|
|
// .attr("fill", );
|
2021-03-31 17:02:00 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
this.g_borders
|
|
|
|
.append("path")
|
|
|
|
.attr("class", "borders")
|
|
|
|
.attr("d", this.proj(this.borders))
|
2021-03-31 17:02:00 +02:00
|
|
|
|
2021-04-28 10:24:07 +02:00
|
|
|
let zoomTimeout = null;
|
2021-04-29 15:36:27 +02:00
|
|
|
this.zoom = d3.zoom()
|
|
|
|
.scaleExtent([CONFIG.zoom.scale_min, CONFIG.zoom.scale_max])
|
|
|
|
.on("start", () => {
|
|
|
|
this.svg.node().classList.add("dragging");
|
|
|
|
}).on("end", () => {
|
|
|
|
this.svg.node().classList.remove("dragging");
|
|
|
|
}).on("zoom", (evt) => {
|
|
|
|
this.container.attr("transform", evt.transform);
|
|
|
|
const oldZoom = this.svg.classed('zoomed');
|
|
|
|
const newZoom = evt.transform.k > 2.0;
|
|
|
|
if (zoomTimeout) {
|
|
|
|
clearTimeout(zoomTimeout)
|
|
|
|
}
|
2021-08-12 09:00:05 +02:00
|
|
|
document.querySelector(':root').style.setProperty('--zoom', evt.transform.k);
|
2021-08-13 11:20:44 +02:00
|
|
|
document.querySelector(':root').style.setProperty('--zoom-sqrt', Math.pow(evt.transform.k, 1/3));
|
2021-04-29 15:36:27 +02:00
|
|
|
zoomTimeout = setTimeout(() => {
|
|
|
|
this.g_nodes.attr('style', `font-size:${22000 / this.height / evt.transform.k}pt`)
|
|
|
|
setTimeout(() => {
|
|
|
|
this.calculateLabels();
|
|
|
|
}, 500);
|
|
|
|
}, 250);
|
|
|
|
if (oldZoom != newZoom) {
|
|
|
|
this.svg.classed('zoomed', newZoom);
|
2021-04-28 10:24:07 +02:00
|
|
|
|
2021-04-29 15:36:27 +02:00
|
|
|
}
|
|
|
|
});
|
2021-10-13 18:35:49 +02:00
|
|
|
// this.title = this.container.append('g').attr('id', 'header');
|
|
|
|
|
|
|
|
// const titleFeature = {
|
|
|
|
// "type": "LineString",
|
|
|
|
// "coordinates": []
|
|
|
|
// };
|
|
|
|
// const title2Feature = {
|
|
|
|
// "type": "LineString",
|
|
|
|
// "coordinates": []
|
|
|
|
// };
|
|
|
|
// const subtitleFeature = {
|
|
|
|
// "type": "LineString",
|
|
|
|
// "coordinates": []
|
|
|
|
// };
|
|
|
|
// for (let index = 26; index < 70; index++) {
|
|
|
|
// // projection apparently tries to find the shortest path between two points
|
|
|
|
// // which is NOT following a lat/lon line on the globe
|
|
|
|
// titleFeature.coordinates.push([index, 52]);
|
|
|
|
// title2Feature.coordinates.push([index, 50.5]);
|
|
|
|
// subtitleFeature.coordinates.push([index, 49]);
|
|
|
|
// }
|
|
|
|
// this.title.append("path")
|
|
|
|
// .attr("id", "titlePath")
|
|
|
|
// .attr("d", this.proj(titleFeature))
|
|
|
|
// ;
|
|
|
|
// this.title.append("path")
|
|
|
|
// .attr("id", "title2Path")
|
|
|
|
// .attr("d", this.proj(title2Feature))
|
|
|
|
// ;
|
|
|
|
// this.title.append("path")
|
|
|
|
// .attr("id", "subtitlePath")
|
|
|
|
// .attr("d", this.proj(subtitleFeature))
|
|
|
|
// ;
|
|
|
|
// this.title.append("text")
|
|
|
|
// .html('<textPath xlink:href="#titlePath">Remote Biometric</textPath>')
|
|
|
|
// this.title.append("text")
|
|
|
|
// .html('<textPath xlink:href="#title2Path">Identification</textPath>')
|
|
|
|
// this.title.append("text")
|
|
|
|
// .attr("id", "subtitle")
|
|
|
|
// .html('<textPath xlink:href="#subtitlePath">' + CONFIG.subtitle + '</textPath>')
|
2021-04-28 09:38:06 +02:00
|
|
|
|
2021-04-19 19:49:33 +02:00
|
|
|
this.link = this.container.append("g")
|
2021-04-17 21:15:03 +02:00
|
|
|
.attr('class', 'links')
|
|
|
|
.selectAll(".link");
|
2021-04-28 10:24:07 +02:00
|
|
|
this.g_nodes = this.container.append("g")
|
|
|
|
.attr('class', 'nodes');
|
|
|
|
this.node = this.g_nodes
|
2021-04-19 19:49:33 +02:00
|
|
|
.selectAll(".node");
|
2021-04-17 21:15:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
this.graph.nodes.forEach((d) => {
|
|
|
|
for (const prop of CONFIG.geo_properties) {
|
|
|
|
// console.log(this,d.printouts, prop)
|
|
|
|
if (d.printouts[prop].length) {
|
|
|
|
// console.log("fix node", d);
|
|
|
|
var p = this.projection([d.printouts[prop][0].lon, d.printouts[prop][0].lat]);
|
2021-04-27 16:10:23 +02:00
|
|
|
|
|
|
|
// initial positions:
|
2021-04-17 21:15:03 +02:00
|
|
|
d.x = p[0];
|
|
|
|
d.y = p[1];
|
2021-04-27 16:10:23 +02:00
|
|
|
|
|
|
|
//These are used when we need to move overlapping points:
|
|
|
|
d.originalX = p[0];
|
|
|
|
d.originalY = p[1];
|
|
|
|
|
|
|
|
// target pos for the force layout
|
2021-04-17 21:15:03 +02:00
|
|
|
d.fx = p[0];
|
|
|
|
d.fy = p[1];
|
|
|
|
// d.targetLat = d.printouts[prop][0].lat;
|
|
|
|
// d.targetLon = d.printouts[prop][0].lon;
|
|
|
|
break
|
2021-03-31 17:02:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-27 16:10:23 +02:00
|
|
|
this.store.configureTree();
|
|
|
|
|
2021-03-31 17:02:00 +02:00
|
|
|
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
// this.nodeMap = Object.fromEntries(this.graph.nodes.map(d => [d['id'], d]));
|
|
|
|
// this.links = this.graph.links.filter(l => this.nodeMap[l.source] && nodeMap[l.target]).map(d => Object.create(d));
|
|
|
|
// console.log(this.nodeMap, this.graph.links);
|
|
|
|
|
|
|
|
|
|
|
|
this.simulation = d3.forceSimulation()
|
|
|
|
.force("link", d3.forceLink()
|
|
|
|
.id(d => d['@id'])
|
|
|
|
.iterations(2) // increase to make more rigid
|
|
|
|
.distance((l) => {
|
|
|
|
// if (getCategories(l.source).indexOf('City') || getCategories(l.target).indexOf('City')) {
|
|
|
|
// // if(l.source.lat || l.target.lat) {
|
|
|
|
// return 2;
|
|
|
|
// }
|
|
|
|
return this.nodeSize * 5;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
// .force("charge", d3.forceManyBody()
|
|
|
|
// .strength(-10)
|
|
|
|
// )
|
|
|
|
// .force("center", d3.forceCenter(width / 2, height / 2))
|
|
|
|
.force("collision", d3.forceCollide(this.nodeSize))
|
|
|
|
// TODO look at simpler labels https://github.com/d3fc/d3fc/tree/master/packages/d3fc-label-layout
|
|
|
|
// TODO look at rects https://github.com/emeeks/d3-bboxCollide
|
2021-04-27 16:10:23 +02:00
|
|
|
// .force("posX", d3.forceX(n => n.targetX || 0).strength(n => n.targetX ? 1 : 0)) // TODO: should not be or 0
|
|
|
|
// .force("posY", d3.forceY(n => n.targetY || 0).strength(n => n.targetY ? 1 : 0))
|
2021-04-17 21:15:03 +02:00
|
|
|
;
|
|
|
|
|
2021-04-28 10:24:07 +02:00
|
|
|
this.svg
|
2021-04-29 15:36:27 +02:00
|
|
|
.call(this.zoom)
|
|
|
|
.call(this.zoom.transform, d3.zoomIdentity.scale(.5, .5));
|
2021-04-28 10:24:07 +02:00
|
|
|
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
this.update();
|
2021-04-19 19:49:33 +02:00
|
|
|
|
|
|
|
setTimeout(() => this.calculateLabels(), 1000);
|
2021-10-13 18:35:49 +02:00
|
|
|
|
|
|
|
this.ready = true;
|
|
|
|
if(this.readyCallback)
|
|
|
|
this.readyCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
triggerReset(){
|
|
|
|
const cb = () => {
|
|
|
|
this.deselectNode();
|
|
|
|
this.resetZoom();
|
|
|
|
}
|
|
|
|
if(this.ready){
|
|
|
|
cb();
|
|
|
|
} else {
|
|
|
|
this.readyCallback = cb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
triggerSelect(toSelect){
|
|
|
|
const cb = () => {
|
|
|
|
const node = this.graph.nodes.filter(n => n.id == toSelect)[0]
|
|
|
|
this.selectNode(node);
|
|
|
|
}
|
|
|
|
if(this.ready){
|
|
|
|
cb();
|
|
|
|
} else {
|
|
|
|
this.readyCallback = cb;
|
|
|
|
}
|
2021-03-31 17:02:00 +02:00
|
|
|
}
|
2021-04-17 21:15:03 +02:00
|
|
|
|
2021-04-29 15:36:27 +02:00
|
|
|
resetZoom() {
|
|
|
|
this.deselectNode();
|
|
|
|
this.svg
|
|
|
|
.transition()
|
|
|
|
.duration(2000) // milliseconds
|
|
|
|
.call(this.zoom.transform, d3.zoomIdentity.scale(.5, .5));
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
getSizeForNode(node) {
|
|
|
|
return this.nodeSize;
|
2021-03-31 17:02:00 +02:00
|
|
|
}
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-27 16:10:23 +02:00
|
|
|
getNodeRadius(node) {
|
|
|
|
return CONFIG.nodeRadius;
|
|
|
|
}
|
|
|
|
|
|
|
|
resolveOverlaps() {
|
|
|
|
// reset:
|
|
|
|
this.graph.nodes.forEach((n) => {
|
|
|
|
if (n.hasOwnProperty('originalX')) {
|
|
|
|
n.x = n.originalX;
|
|
|
|
n.y = n.originalY;
|
|
|
|
n.fx = n.originalX;
|
|
|
|
n.fy = n.originalY;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
this.store.configureTree();
|
|
|
|
|
|
|
|
let moved = 0;
|
|
|
|
|
|
|
|
// resolve overlapping points by repositioning
|
|
|
|
this.graph.nodes.forEach((n) => {
|
|
|
|
// only for fixed points:
|
|
|
|
if (!n.hasOwnProperty('originalX')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const startX = n.originalX;
|
|
|
|
const startY = n.originalY;
|
|
|
|
let alpha = 0; // angle
|
|
|
|
let step = 1;
|
|
|
|
const d_alpha = Math.PI / 4;
|
2021-04-28 09:38:06 +02:00
|
|
|
const r = this.getNodeRadius(n) + CONFIG.nodeRepositionPadding / 2;
|
2021-04-27 16:10:23 +02:00
|
|
|
let foundNodes;
|
|
|
|
let i = 0;
|
|
|
|
// find a new pos until it's not overlapping anymore...
|
|
|
|
while ((foundNodes = this.store.findVisibleInCircle(n.x, n.y, r)).length > 1) {
|
|
|
|
this.store.quadtree.remove(n); // remove uses the current x,y so we need to do this before reconfiguring these
|
|
|
|
n.x = startX + Math.cos(alpha) * r * 2 * step;
|
|
|
|
n.y = startY + Math.sin(alpha) * r * 2 * step;
|
|
|
|
this.store.quadtree.add(n);
|
|
|
|
alpha += d_alpha;
|
|
|
|
// on to the next round:
|
2021-04-28 09:38:06 +02:00
|
|
|
if (alpha > Math.PI * 2) {
|
2021-04-27 16:10:23 +02:00
|
|
|
step++;
|
2021-04-28 09:38:06 +02:00
|
|
|
alpha -= Math.PI * 2;
|
|
|
|
alpha += d_alpha - 2; // little offset
|
2021-04-27 16:10:23 +02:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
|
|
|
|
// if(n.fulltext == 'Control Room (Venice)') {
|
|
|
|
// console.log(startX, startY, n.x, n.y, r, foundNodes);
|
|
|
|
// // this.store.configureTree();
|
|
|
|
// // this.store.findVisibleInCircle(n.x, n.y, r).forEach((found) => console.log(found.x, found.y, found));
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
n.fx = n.x;
|
|
|
|
n.fy = n.y;
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
// we moved something, update tree
|
2021-04-28 09:38:06 +02:00
|
|
|
|
2021-04-27 16:10:23 +02:00
|
|
|
console.debug('resolved for', n.fulltext, i);
|
2021-04-28 09:38:06 +02:00
|
|
|
moved++;
|
2021-04-27 16:10:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(`moved ${moved} nodes`);
|
|
|
|
}
|
|
|
|
|
2021-04-29 15:36:27 +02:00
|
|
|
showTooltip(el, node, links) {
|
2021-08-12 09:00:05 +02:00
|
|
|
if(el.tagName != 'path'){
|
|
|
|
let parentEl = el.parentNode;
|
|
|
|
if(parentEl.tagName != 'g'){
|
|
|
|
parentEl = parentEl.parentNode;
|
|
|
|
}
|
|
|
|
el = parentEl.querySelector('path');
|
|
|
|
}
|
2021-10-07 08:04:30 +02:00
|
|
|
|
|
|
|
const categories = getCategories(node);
|
|
|
|
if (categories.includes('Deployments')){
|
|
|
|
this.tooltipEl.classList.add('deploymentTooltip');
|
|
|
|
} else {
|
|
|
|
this.tooltipEl.classList.remove('deploymentTooltip');
|
|
|
|
}
|
2021-08-12 09:00:05 +02:00
|
|
|
|
2021-04-29 15:36:27 +02:00
|
|
|
// TODO: make links optional (otherwise collect links here)
|
|
|
|
this.tooltipEl.innerHTML = `
|
2021-10-07 08:04:30 +02:00
|
|
|
<span class='category'>${categories[0]}</span>
|
2021-04-29 15:36:27 +02:00
|
|
|
<h3>${node.fulltext}</h3>
|
|
|
|
`;
|
|
|
|
if (links.length) {
|
|
|
|
const rels = links.length === 1 ? 'relationship' : 'relationships';
|
|
|
|
this.tooltipEl.innerHTML += `
|
|
|
|
<span class='clickForMore'>Click to examine ${links.length} ${rels}</span>
|
|
|
|
`;
|
|
|
|
}
|
2021-10-07 08:04:30 +02:00
|
|
|
|
2021-04-29 15:36:27 +02:00
|
|
|
const rect = el.getBoundingClientRect()
|
|
|
|
const rectTT = this.tooltipEl.getBoundingClientRect();
|
|
|
|
this.tooltipEl.style.top = (rect.top - rectTT.height) + 'px';
|
|
|
|
this.tooltipEl.style.left = (rect.left + rect.width / 2 - rectTT.width / 2) + 'px';
|
|
|
|
// console.log(el, node, rect.top);
|
|
|
|
|
2021-08-12 09:00:05 +02:00
|
|
|
this.tooltipEl.classList.add('visible', 'node');
|
|
|
|
}
|
|
|
|
|
|
|
|
showRelationTooltip(link, evt) {
|
|
|
|
const {label, swap} = getLinkLabelConfig(link.name);
|
2021-10-07 08:04:30 +02:00
|
|
|
this.tooltipEl.classList.remove('deploymentTooltip');
|
2021-08-12 09:00:05 +02:00
|
|
|
if(swap){
|
|
|
|
this.tooltipEl.innerHTML = `
|
|
|
|
<span class='relation'>
|
|
|
|
<span class='entity'>${link.target.fulltext}</span>
|
|
|
|
${label}
|
|
|
|
<span class='entity'>${link.source.fulltext}</span>
|
|
|
|
</span>
|
|
|
|
`;
|
|
|
|
} else {
|
|
|
|
this.tooltipEl.innerHTML = `
|
|
|
|
<span class='relation'>
|
|
|
|
<span class='entity'>${link.source.fulltext}</span>
|
|
|
|
${label}
|
|
|
|
<span class='entity'>${link.target.fulltext}</span>
|
|
|
|
</span>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const rectTT = this.tooltipEl.getBoundingClientRect();
|
|
|
|
|
|
|
|
this.trackerEv = (evt) => {
|
|
|
|
this.tooltipEl.style.top = (evt.clientY - rectTT.height - 10) + 'px';
|
|
|
|
this.tooltipEl.style.left = (evt.clientX - rectTT.width / 2) + 'px';
|
|
|
|
};
|
|
|
|
window.addEventListener('mousemove', this.trackerEv);
|
|
|
|
|
|
|
|
this.tooltipEl.classList.add('visible', 'link');
|
2021-04-29 15:36:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hideTooltip() {
|
2021-08-12 09:00:05 +02:00
|
|
|
this.tooltipEl.classList.remove('visible', 'node', 'link');
|
|
|
|
if(this.trackerEv){
|
|
|
|
window.removeEventListener('mousemove', this.trackerEv);
|
|
|
|
this.trackerEv = null;
|
|
|
|
}
|
2021-04-29 15:36:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
selectNode(node) {
|
|
|
|
this.deselectNode(); // remove potential old selection
|
|
|
|
|
|
|
|
this.selectedNode = node;
|
|
|
|
let links = [];
|
|
|
|
let connectedNodes = [];
|
|
|
|
for (let link of this.graph.links) {
|
|
|
|
if (link.source == node || link.target == node) {
|
|
|
|
links.push(link);
|
|
|
|
const otherNode = node == link.target ? link.source : link.target;
|
|
|
|
connectedNodes.push(otherNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let allNodes = [...connectedNodes, node];
|
|
|
|
|
|
|
|
this.zoomFit(allNodes);
|
|
|
|
|
|
|
|
document.getElementById(node.id).classList.add('selected');
|
|
|
|
connectedNodes.forEach(n => document.getElementById(n.id).classList.add('linkedSelected'));
|
|
|
|
links.forEach(l => document.getElementById(getLinkId(l)).classList.add('linkedSelected'));
|
|
|
|
|
2021-08-12 09:00:05 +02:00
|
|
|
this.container.classed('selectedNode', true);
|
2021-08-13 11:57:57 +02:00
|
|
|
|
|
|
|
document.body.classList.add('selectedNode');
|
2021-10-07 08:04:30 +02:00
|
|
|
|
|
|
|
this.showSources(node);
|
2021-04-29 15:36:27 +02:00
|
|
|
// TODO: show details;
|
|
|
|
|
|
|
|
// alert('not yet implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
deselectNode() {
|
2021-10-07 08:04:30 +02:00
|
|
|
this.hideSources();
|
2021-04-29 15:36:27 +02:00
|
|
|
this.selectedNode = null;
|
|
|
|
let nodeEls = document.getElementsByClassName('selected');
|
|
|
|
while (nodeEls.length) {
|
|
|
|
nodeEls[0].classList.remove('selected');
|
|
|
|
}
|
|
|
|
let els = document.getElementsByClassName('linkedSelected');
|
|
|
|
while (els.length) {
|
|
|
|
els[0].classList.remove('linkedSelected');
|
|
|
|
}
|
2021-08-12 09:00:05 +02:00
|
|
|
this.container.classed('selectedNode', false);
|
2021-08-13 11:57:57 +02:00
|
|
|
document.body.classList.remove('selectedNode');
|
2021-04-29 15:36:27 +02:00
|
|
|
}
|
|
|
|
|
2021-10-07 08:04:30 +02:00
|
|
|
showSources(node){
|
|
|
|
|
|
|
|
const categories = getCategories(node);
|
|
|
|
if (!categories.includes('Deployments')){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!node.printouts['Source'].length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { // give potential visible sources time to hide
|
|
|
|
let sources = [];
|
|
|
|
for(let source of node.printouts['Source']){
|
|
|
|
const url = document.createElement('a');
|
|
|
|
url.href = source;
|
|
|
|
const hostname = url.hostname.startsWith('www.') ? url.hostname.substring(4) : url.hostname;
|
|
|
|
sources .push(`<a href="${source}" target="_blank">${hostname}</a>`);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const title = node.printouts['Source'].length > 1 ? "Sources" : "Source"
|
|
|
|
this.sourcesEl.innerHTML = `<h3>${title}</h3> ` + sources.join(', ');
|
|
|
|
this.sourcesEl.classList.add('visible');
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
hideSources(){
|
|
|
|
this.sourcesEl.classList.remove('visible');
|
|
|
|
}
|
|
|
|
|
2021-10-13 18:35:49 +02:00
|
|
|
hoverNode(evt, n){
|
|
|
|
console.log('hover!', n)
|
|
|
|
// d3.select(this).classed('hover', true);
|
|
|
|
const links = document.getElementsByClassName('link');
|
|
|
|
const linkedLinks = [];
|
|
|
|
for (let link of links) {
|
|
|
|
const l = d3.select(link).datum();
|
|
|
|
if (n == l.target || n == l.source) {
|
|
|
|
link.classList.add('linkedHover');
|
|
|
|
// make sure it's the last element, so it's drawn on top
|
|
|
|
// link.parentNode.appendChild(link); .. causes gliches
|
|
|
|
// find related related node:
|
|
|
|
const otherNode = n == l.target ? l.source : l.target;
|
|
|
|
const otherNodeEl = document.getElementById(otherNode.id);
|
|
|
|
otherNodeEl.classList.add('linkedHover');
|
|
|
|
linkedLinks.push(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(evt){
|
|
|
|
this.showTooltip(evt.target, n, linkedLinks);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
endHoverNode(n){
|
|
|
|
this.hideTooltip();
|
|
|
|
const links = document.getElementsByClassName('linkedHover');
|
|
|
|
while (links.length) {
|
|
|
|
links[0].classList.remove('linkedHover');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
update() {
|
2021-04-29 15:36:27 +02:00
|
|
|
// console.log(this.graph)
|
2021-04-27 16:10:23 +02:00
|
|
|
|
|
|
|
this.resolveOverlaps();
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
// see also: https://www.createwithdata.com/enter-exit-with-d3-join/
|
|
|
|
this.node = this.node.data(this.graph.nodes, d => d.id)
|
|
|
|
.join((enter) => {
|
2021-08-13 11:20:44 +02:00
|
|
|
// let group = enter.insert("g", ":first-child")
|
2021-04-29 15:36:27 +02:00
|
|
|
let group = enter.append("g")
|
|
|
|
.attr("class", getClasses)
|
|
|
|
.attr("id", (n) => getIdForTitle(n.fulltext));
|
2021-04-17 21:15:03 +02:00
|
|
|
// group.call(drag(simulation));
|
2021-05-04 18:40:06 +02:00
|
|
|
group.on("click", (evt, n) => {
|
|
|
|
evt.stopPropagation(); this.selectNode(n);
|
|
|
|
});
|
2021-04-29 15:36:27 +02:00
|
|
|
group.on("mouseover", (evt, n) => {
|
2021-10-13 18:35:49 +02:00
|
|
|
this.hoverNode(evt, n);
|
2021-04-29 15:36:27 +02:00
|
|
|
});
|
|
|
|
group.on("mouseout", (evt, n) => {
|
2021-10-13 18:35:49 +02:00
|
|
|
this.endHoverNode(n);
|
2021-04-29 15:36:27 +02:00
|
|
|
});
|
2021-04-28 11:18:02 +02:00
|
|
|
// group.append('circle').attr("r", 5 /*this.nodeSize*/);
|
|
|
|
group.append('path')
|
|
|
|
.attr('d', (n) => {
|
|
|
|
return getSymbolForNode(n)(n);
|
|
|
|
})
|
2021-08-12 09:00:05 +02:00
|
|
|
var nodeTitle = group.append('text').attr("class", "nodeTitle").attr("y", "4").attr('x', 5);
|
|
|
|
// nodeTitle.on('mouseover', (evt, n) =>{
|
|
|
|
// console.log(evt,n)
|
|
|
|
// });
|
2021-04-17 21:15:03 +02:00
|
|
|
nodeTitle
|
2021-04-19 19:49:33 +02:00
|
|
|
.each(function (node, i, nodes) {
|
2021-04-17 21:15:03 +02:00
|
|
|
var textLength = void 0;
|
|
|
|
const self = d3.select(this);
|
|
|
|
const titleText = getTitle(node);
|
|
|
|
var titleTexts = false;
|
|
|
|
if (titleText.length > 20) {
|
|
|
|
titleTexts = splitText(titleText);
|
|
|
|
}
|
|
|
|
if (titleTexts !== false) {
|
2021-08-12 09:00:05 +02:00
|
|
|
const tspan1 = self.append("tspan").text(titleTexts[0]).attr("y", "4").attr("x", "5");
|
2021-04-19 19:49:33 +02:00
|
|
|
const tspan = self.append("tspan").text(titleTexts[1]).attr("dy", "1em").attr("x", "5");
|
|
|
|
// const textLength1 = tspan.node().getComputedTextLength();
|
|
|
|
// const textLength2 = tspan.node().getComputedTextLength();
|
|
|
|
// textLength = Math.max(textLength1, textLength2);
|
2021-04-17 21:15:03 +02:00
|
|
|
} else {
|
|
|
|
self.text(titleText);
|
2021-04-19 19:49:33 +02:00
|
|
|
// textLength = self.node().getComputedTextLength();
|
2021-04-17 21:15:03 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return group;
|
|
|
|
});
|
2021-04-16 11:15:57 +02:00
|
|
|
|
2021-04-19 19:49:33 +02:00
|
|
|
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
this.link = this.link
|
|
|
|
.data(this.graph.links)
|
|
|
|
.join(
|
|
|
|
enter => {
|
2021-04-28 09:38:06 +02:00
|
|
|
let group = enter.append("g")
|
2021-04-29 15:36:27 +02:00
|
|
|
.attr("class", (l) => "link " + slugify(l.name))
|
|
|
|
.attr("id", getLinkId);
|
2021-04-19 19:49:33 +02:00
|
|
|
group.append("path")
|
2021-08-13 11:20:44 +02:00
|
|
|
// .attr("marker-end", "url(#arrowHead)")
|
2021-04-29 15:36:27 +02:00
|
|
|
.attr('id', (d, i) => 'linkpath_' + i)
|
2021-08-12 09:00:05 +02:00
|
|
|
.on("mouseover", (ev, link) => {
|
|
|
|
d3.select(ev.target).classed('hover', true);
|
2021-04-19 22:47:06 +02:00
|
|
|
const nodes = document.getElementsByClassName('node');
|
|
|
|
for (let n of nodes) {
|
|
|
|
const d = d3.select(n).datum();
|
|
|
|
if (d == link.target || d == link.source) {
|
|
|
|
n.classList.add('linkHover');
|
|
|
|
}
|
2021-04-19 19:49:33 +02:00
|
|
|
}
|
2021-08-12 09:00:05 +02:00
|
|
|
|
|
|
|
this.showRelationTooltip(link, ev);
|
|
|
|
}).on("mouseout", (ev, link) => {
|
|
|
|
this.hideTooltip();
|
|
|
|
d3.select(ev.target).classed('hover', false);
|
2021-04-19 22:47:06 +02:00
|
|
|
const nodes = document.getElementsByClassName('linkHover');
|
2021-04-29 15:36:27 +02:00
|
|
|
while (nodes.length) {
|
|
|
|
nodes[0].classList.remove('linkHover');
|
2021-04-19 22:47:06 +02:00
|
|
|
}
|
2021-04-29 15:36:27 +02:00
|
|
|
}).on("click", (ev, link) => {
|
2021-05-04 18:40:06 +02:00
|
|
|
ev.stopPropagation();
|
2021-04-29 15:36:27 +02:00
|
|
|
this.selectNode(link.source);
|
|
|
|
})
|
|
|
|
;
|
2021-04-17 21:15:03 +02:00
|
|
|
group.filter((l) => l.name != "City").append("text").attr("class", "labelText").text(function (l) {
|
|
|
|
return l.name;
|
|
|
|
});
|
|
|
|
// group.append("text")
|
|
|
|
// .attr("class", "labelText")
|
|
|
|
// .attr("dx", 20)
|
|
|
|
// .attr("dy", 0)
|
|
|
|
// .style("fill", "red")
|
|
|
|
// .append("textPath")
|
|
|
|
// .attr("xlink:href", function (d, i) { return "#linkid_" + i; })
|
|
|
|
// .attr("startOffset","50%")
|
|
|
|
// .text((d,i) => d.name );
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
this.simulation.nodes(this.graph.nodes);
|
|
|
|
this.simulation.force("link")
|
|
|
|
.links(this.graph.links);
|
|
|
|
|
|
|
|
this.simulation.on("tick", () => {
|
|
|
|
|
|
|
|
// console.log('t', link._groups[0].length);
|
|
|
|
const _mapGraph = this;
|
|
|
|
this.link.each(function (l) {
|
|
|
|
let sourceX, targetX, midX, dx, dy, angle;
|
|
|
|
|
|
|
|
// This mess makes the arrows exactly perfect.
|
|
|
|
// thanks to http://bl.ocks.org/curran/9b73eb564c1c8a3d8f3ab207de364bf4
|
|
|
|
if (l.source.x < l.target.x) {
|
|
|
|
sourceX = l.source.x;
|
|
|
|
targetX = l.target.x;
|
|
|
|
} else if (l.target.x < l.source.x) {
|
|
|
|
targetX = l.target.x;
|
|
|
|
sourceX = l.source.x;
|
|
|
|
} else if (l.target.isCircle) {
|
|
|
|
targetX = sourceX = l.target.x;
|
|
|
|
} else if (l.source.isCircle) {
|
|
|
|
targetX = sourceX = l.source.x;
|
|
|
|
} else {
|
|
|
|
midX = (l.source.x + l.target.x) / 2;
|
|
|
|
if (midX > l.target.x) {
|
|
|
|
midX = l.target.x;
|
|
|
|
} else if (midX > l.source.x) {
|
|
|
|
midX = l.source.x;
|
|
|
|
} else if (midX < l.target.x) {
|
|
|
|
midX = l.target.x;
|
|
|
|
} else if (midX < l.source.x) {
|
|
|
|
midX = l.source.x;
|
|
|
|
}
|
|
|
|
targetX = sourceX = midX;
|
|
|
|
}
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
dx = targetX - sourceX;
|
|
|
|
dy = l.target.y - l.source.y;
|
|
|
|
angle = Math.atan2(dx, dy);
|
|
|
|
|
|
|
|
/* DISABLED
|
|
|
|
srcSize = (typeof nodePositions[l.source.index] != 'undefined') ? selectedNodeSize : nodeSize;
|
|
|
|
tgtSize = (typeof nodePositions[l.target.index] != 'undefined') ? selectedNodeSize : nodeSize;
|
|
|
|
*/
|
|
|
|
var srcSize = _mapGraph.getSizeForNode(l.source);
|
|
|
|
var tgtSize = _mapGraph.getSizeForNode(l.target);
|
|
|
|
|
|
|
|
// Compute the line endpoint such that the arrow
|
2021-10-07 08:04:30 +02:00
|
|
|
// it not in the center, but rather slightly out of it
|
|
|
|
// use a small ofset for the angle to compensate roughly for the curve
|
|
|
|
l.sourceX = sourceX + Math.sin(angle+.5) * srcSize;
|
|
|
|
l.targetX = targetX - Math.sin(angle-.5) * tgtSize;
|
|
|
|
l.sourceY = l.source.y + Math.cos(angle+.5) * srcSize;
|
|
|
|
l.targetY = l.target.y - Math.cos(angle-.5) * tgtSize;
|
2021-04-17 21:15:03 +02:00
|
|
|
|
|
|
|
// const coor_source = _mapGraph.projection.invert([l.source.x, l.source.y]);
|
|
|
|
// const coor_target = _mapGraph.projection.invert([l.target.x, l.target.y]);
|
|
|
|
// const middleCoor = [coor_source[0] * .5 + coor_target[0] * .5, coor_source[1] * .5 + coor_target[1] * .5];
|
|
|
|
// const middlePoint = _mapGraph.projection(middleCoor);
|
|
|
|
|
2021-10-07 08:04:30 +02:00
|
|
|
// find radius of arc based on distance between points
|
2021-04-17 21:15:03 +02:00
|
|
|
const dr = Math.sqrt(dx * dx + dy * dy);
|
|
|
|
|
|
|
|
// "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y
|
|
|
|
let rel = d3.select(this);
|
2021-10-07 08:04:30 +02:00
|
|
|
rel.select("path")
|
2021-04-17 21:15:03 +02:00
|
|
|
.attr('d', `M ${l.sourceX},${l.sourceY} A ${dr},${dr} 0 0,1 ${l.targetX},${l.targetY}`)
|
|
|
|
|
|
|
|
rel.select('text')
|
|
|
|
.attr("transform", function (d) {
|
|
|
|
const dx = (l.target.x - l.source.x) / 2;
|
|
|
|
const dy = (l.target.y - l.source.y) / 2;
|
|
|
|
const x = l.source.x + dx;
|
|
|
|
const y = l.source.y + dy;
|
|
|
|
const deg = Math.atan(dy / dx) * 180 / Math.PI;
|
|
|
|
// if dx/dy == 0/0 -> deg == NaN
|
|
|
|
if (isNaN(deg)) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
// return "";
|
|
|
|
return "translate(" + x + " " + y + ") rotate(" + (CONFIG.labels.rotate ? deg : 0) + ")";
|
|
|
|
});
|
2021-03-30 16:30:50 +02:00
|
|
|
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
})
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
this.node
|
|
|
|
.attr("transform", d => `translate(${d.x}, ${d.y})`);
|
2021-03-29 20:49:50 +02:00
|
|
|
});
|
|
|
|
|
2021-03-31 17:02:00 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
this.simulation.alpha = 0;
|
|
|
|
this.simulation.restart();
|
2021-04-19 19:49:33 +02:00
|
|
|
this.calculateLabels()
|
2021-04-17 21:15:03 +02:00
|
|
|
}
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
setWorld(world) {
|
|
|
|
this.borders = topojson.mesh(world, world.objects.countries, (a, b) => a !== b)
|
|
|
|
this.countries = topojson.feature(world, world.objects.countries).features;
|
|
|
|
}
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
setStore(store) {
|
|
|
|
this.store = store;
|
|
|
|
this.graph = this.store.graph;
|
|
|
|
store.registerMap(this);
|
|
|
|
}
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
// alias for update (redraw is used in dc)
|
|
|
|
redraw() {
|
|
|
|
this.update()
|
|
|
|
}
|
2021-04-29 15:36:27 +02:00
|
|
|
|
|
|
|
// viewBox + preserveAspectRatio can lead to a visible area that is larger than
|
|
|
|
// the viewBox. Try to get this
|
|
|
|
getVisibleBox() {
|
|
|
|
const svgEl = this.svg.node()
|
|
|
|
const vbRatio = svgEl.viewBox.baseVal.width / svgEl.viewBox.baseVal.height;
|
|
|
|
const wRatio = this.width / this.height;
|
|
|
|
if (wRatio > vbRatio) {
|
|
|
|
// wider
|
|
|
|
return {
|
|
|
|
width: (wRatio / vbRatio) * svgEl.viewBox.baseVal.width,
|
|
|
|
height: svgEl.viewBox.baseVal.height
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// taller
|
|
|
|
return {
|
|
|
|
width: svgEl.viewBox.baseVal.width,
|
|
|
|
height: (vbRatio / wRatio) * svgEl.viewBox.baseVal.height
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-13 11:20:44 +02:00
|
|
|
// zoom & translate the graph to fit the provided nodes
|
2021-04-29 15:36:27 +02:00
|
|
|
zoomFit(nodes, paddingPercent = 0.8, transitionDuration = 2000) {
|
|
|
|
// var bounds = root.node().getBBox();
|
|
|
|
const x0 = Math.min(...nodes.map(n => n.x - CONFIG.nodeRadius));
|
|
|
|
const x1 = Math.max(...nodes.map(n => n.x + CONFIG.nodeRadius));
|
|
|
|
const y0 = Math.min(...nodes.map(n => n.y - CONFIG.nodeRadius));
|
|
|
|
const y1 = Math.max(...nodes.map(n => n.y + CONFIG.nodeRadius));
|
|
|
|
|
|
|
|
const width = x1 - x0;
|
|
|
|
const height = y1 - y0;
|
|
|
|
|
|
|
|
const visibleBox = this.getVisibleBox();
|
|
|
|
const fullWidth = visibleBox.width, //2000, //this.width, TODO: use viewbox now, but consider the overflowing of the vbox
|
|
|
|
fullHeight = visibleBox.height; //2000; //this.height;
|
|
|
|
const viewBox = this.svg.node().viewBox.baseVal;
|
|
|
|
const midX = x0 + width / 2,
|
|
|
|
midY = y0 + height / 2;
|
|
|
|
if (width == 0 || height == 0) return; // nothing to fit
|
|
|
|
let scale = paddingPercent / Math.max(width / fullWidth, height / fullHeight);
|
|
|
|
scale = Math.min(CONFIG.zoom.scale_max, scale);
|
|
|
|
const translate = [fullWidth / 2 - midX, fullHeight / 2 - midY];
|
|
|
|
const transform = d3.zoomIdentity.translate(
|
|
|
|
-midX * scale + viewBox.width / 2,
|
|
|
|
-midY * scale + viewBox.height / 2)
|
|
|
|
.scale(scale);
|
|
|
|
// console.log("zoomFit", x0, x1, y0, y1, translate, scale, transform);
|
|
|
|
this.svg
|
|
|
|
.transition()
|
|
|
|
.duration(transitionDuration || 0) // milliseconds
|
|
|
|
.call(this.zoom.transform, transform);
|
|
|
|
// .call(this.zoom.translateTo, midX, midY)
|
|
|
|
// .call(this.zoom.scaleTo, scale);
|
|
|
|
}
|
2021-04-16 11:15:57 +02:00
|
|
|
}
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-19 22:47:06 +02:00
|
|
|
class AlluvialMap {
|
|
|
|
constructor(parent) {
|
|
|
|
this.root = d3.select(parent);
|
|
|
|
this.resizeEvent = window.addEventListener('resize', this.resize.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
setData(results) {
|
|
|
|
this.graph = JsonToAlluvial(results);
|
|
|
|
}
|
|
|
|
|
|
|
|
resize() {
|
|
|
|
this.width = window.innerWidth;
|
|
|
|
this.height = window.innerHeight;
|
|
|
|
this.vbWidth = 2000;
|
|
|
|
this.vbHeight = 2000;
|
|
|
|
this.svg
|
|
|
|
.attr("viewBox", [0, 0, this.vbWidth, this.vbHeight])
|
|
|
|
.attr("width", this.width)
|
|
|
|
.attr("height", this.height);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
console.warning("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
|
|
|
// this.alluvial = this.parseGraph(this.store.graph)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
this.svg = this.root.append('svg')
|
2021-08-12 09:00:05 +02:00
|
|
|
|
2021-04-19 22:47:06 +02:00
|
|
|
this.resize();
|
|
|
|
|
|
|
|
this.sankey = d3.sankey()
|
|
|
|
.nodeId(d => d.id)
|
|
|
|
// .nodeAlign('justify')
|
|
|
|
.nodeWidth(40) // height
|
|
|
|
.nodePadding(10)
|
|
|
|
.extent([[1, 5], [2000 - 1, 2000 - 5]]);
|
2021-04-29 15:36:27 +02:00
|
|
|
// console.log(this.graph);
|
2021-04-19 22:47:06 +02:00
|
|
|
let s = this.sankey({
|
|
|
|
nodes: this.graph.nodes.map(d => Object.assign({}, d)),
|
|
|
|
links: this.graph.links.map(d => Object.assign({}, d))
|
|
|
|
});
|
|
|
|
|
|
|
|
this.nodes = s.nodes;
|
|
|
|
this.links = s.links;
|
|
|
|
|
|
|
|
const scale = d3.scaleOrdinal(d3.schemeCategory10);
|
2021-04-27 16:10:23 +02:00
|
|
|
const color = (c) => c == "Unknown" ? "#333" : scale(c);
|
2021-04-19 22:47:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
this.svg.append("g")
|
|
|
|
.attr("stroke", "#000")
|
|
|
|
.selectAll("rect")
|
|
|
|
.data(this.nodes)
|
|
|
|
.join("rect")
|
|
|
|
.attr("x", d => d.y0)
|
|
|
|
.attr("y", d => d.x0)
|
|
|
|
.attr("height", d => d.x1 - d.x0)
|
|
|
|
.attr("width", d => d.y1 - d.y0)
|
|
|
|
// .attr("fill", d => color(d.box === undefined ? d.name : d.box))
|
|
|
|
.attr("fill", d => color(d.name))
|
|
|
|
// .attr("fill", 'blue')
|
|
|
|
.append("title")
|
|
|
|
.text(d => `${d.box}: ${d.name}\n${d.value}`);
|
|
|
|
|
|
|
|
const link = this.svg.append("g")
|
|
|
|
.attr("fill", "none")
|
|
|
|
.attr("stroke-opacity", 0.5)
|
|
|
|
.selectAll("g")
|
|
|
|
.data(this.links)
|
|
|
|
.join("g")
|
|
|
|
.style("mix-blend-mode", "multiply");
|
|
|
|
|
2021-04-27 16:10:23 +02:00
|
|
|
|
2021-04-19 22:47:06 +02:00
|
|
|
|
|
|
|
const edgeColor = 'path'; // either: path, none, input, output
|
|
|
|
if (edgeColor === "path") {
|
|
|
|
const gradient = link.append("linearGradient")
|
2021-04-27 16:10:23 +02:00
|
|
|
.attr("id", (d, i) => {
|
2021-04-19 22:47:06 +02:00
|
|
|
const id = `link-${i}`; // thanks https://talk.observablehq.com/t/how-do-i-work-with-the-d3-sankey-example/1696/3
|
|
|
|
d.uid = `url(#${id})`;
|
|
|
|
return id;
|
|
|
|
})
|
|
|
|
.attr("gradientUnits", "userSpaceOnUse")
|
|
|
|
.attr("y1", d => d.source.x1)
|
|
|
|
.attr("y2", d => d.target.x0)
|
2021-04-27 16:10:23 +02:00
|
|
|
.attr("x1", 0)
|
2021-04-19 22:47:06 +02:00
|
|
|
.attr("x2", 0);
|
2021-04-27 16:10:23 +02:00
|
|
|
// .attr("y1", "0%")
|
|
|
|
// .attr("y2", "100%")
|
|
|
|
// .attr("x1", "0%")
|
|
|
|
// .attr("x2", "0%");
|
2021-04-19 22:47:06 +02:00
|
|
|
|
|
|
|
gradient.append("stop")
|
|
|
|
.attr("offset", "0%")
|
|
|
|
.attr("stop-color", d => color(d.source.name));
|
|
|
|
|
|
|
|
gradient.append("stop")
|
|
|
|
.attr("offset", "100%")
|
|
|
|
.attr("stop-color", d => color(d.target.name));
|
|
|
|
}
|
|
|
|
|
|
|
|
link.append("path")
|
|
|
|
// .attr("d", d3.sankeyLinkHorizontal())
|
|
|
|
.attr("d", d3.linkVertical()
|
|
|
|
.source(function (d) { return [d.y0, d.source.x1]; })
|
|
|
|
.target(function (d) { return [d.y1, d.target.x0]; })
|
|
|
|
)
|
|
|
|
|
|
|
|
.attr("stroke", d => edgeColor === "none" ? "#aaa"
|
|
|
|
: edgeColor === "path" ? d.uid
|
|
|
|
: edgeColor === "input" ? color(d.source)
|
|
|
|
: color(d.target))
|
|
|
|
// .attr("stroke", 'red')
|
|
|
|
.attr("stroke-width", d => Math.max(1, d.width));
|
|
|
|
|
|
|
|
link.append("title")
|
|
|
|
.text(d => `${d.source.name} → ${d.target.name}\n${d.value}`);
|
|
|
|
|
|
|
|
this.svg.append("g")
|
|
|
|
.attr("font-family", "sans-serif")
|
|
|
|
// .attr("font-size", 10)
|
|
|
|
.attr("class", 'flow_label')
|
|
|
|
.selectAll("text")
|
|
|
|
.data(this.nodes)
|
|
|
|
.join("text")
|
|
|
|
.attr("x", d => (d.y1 + d.y0) / 2)
|
|
|
|
.attr("y", d => d.x0 < this.width / 2 ? d.x1 + 6 : d.x0 - 6)
|
|
|
|
.attr("dy", "0.35em")
|
|
|
|
.attr("text-anchor", d => d.x0 < this.width / 2 ? "start" : "end")
|
|
|
|
.text(d => d.name);
|
|
|
|
|
|
|
|
return this.svg.node();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-29 15:36:27 +02:00
|
|
|
titleIdMap = {};
|
|
|
|
function getIdForTitle(title) {
|
|
|
|
if (!titleIdMap.hasOwnProperty(title)) {
|
|
|
|
titleIdMap[title] = slugify(title) + `-${Object.keys(titleIdMap).length}`
|
|
|
|
}
|
|
|
|
return titleIdMap[title];
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
JsonToGraph = function (data) {
|
|
|
|
let nodes = [];
|
|
|
|
let links = [];
|
|
|
|
|
|
|
|
let smwBugFixLocationMaps = {};
|
|
|
|
console.log(data)
|
2021-04-29 15:36:27 +02:00
|
|
|
let i = 0;
|
|
|
|
let linkI = 0;
|
2021-04-17 21:15:03 +02:00
|
|
|
for (const node_id in data.results) {
|
|
|
|
if (Object.hasOwnProperty.call(data.results, node_id)) {
|
2021-04-29 15:36:27 +02:00
|
|
|
i++;
|
2021-04-17 21:15:03 +02:00
|
|
|
let node = data.results[node_id];
|
2021-04-29 15:36:27 +02:00
|
|
|
node.id = getIdForTitle(node.fulltext); //node_id;
|
2021-08-13 11:20:44 +02:00
|
|
|
// group institution types
|
|
|
|
if(node.printouts['Institution Type'].length ){
|
|
|
|
for (let idx = 0; idx < node.printouts['Institution Type'].length; idx++) {
|
|
|
|
const type = node.printouts['Institution Type'][idx];
|
|
|
|
if(CONFIG.institution_map.hasOwnProperty(type.fulltext)){
|
|
|
|
node.printouts['Institution Type'][idx].fulltext = CONFIG.institution_map[type.fulltext];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// node.printouts['Institution Type'] = CONFIG.institution_map[node.printouts['Institution Type']];
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
nodes.push(node);
|
|
|
|
// console.log(node_id, node);
|
|
|
|
|
|
|
|
// work around SMW bug in Ask. 1/2
|
|
|
|
for (const idx of Object.keys(CONFIG.geo_property_map)) {
|
|
|
|
if (node.printouts[idx].length) {
|
|
|
|
const srcProp = CONFIG.geo_property_map[idx];
|
|
|
|
const loc = node.printouts[srcProp][0].fulltext;
|
|
|
|
smwBugFixLocationMaps[loc] = node.printouts[idx];
|
|
|
|
// console.debug("Set location for", loc, node.printouts[idx])
|
2021-03-30 16:30:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
for (const prop of CONFIG.link_properties) {
|
|
|
|
if (!node.printouts.hasOwnProperty(prop)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (const target_node of node.printouts[prop]) {
|
|
|
|
links.push({
|
2021-04-29 15:36:27 +02:00
|
|
|
"source": node.id,
|
|
|
|
"target": getIdForTitle(target_node.fulltext),
|
|
|
|
"name": prop,
|
2021-04-17 21:15:03 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-16 11:15:57 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
let fixes = 0;
|
|
|
|
nodes.forEach((node) => {
|
|
|
|
// work around SMW bug in Ask. 2/2
|
|
|
|
for (const idx of Object.keys(CONFIG.geo_property_map)) {
|
|
|
|
if (!node.printouts[idx].length) {
|
|
|
|
const srcProp = CONFIG.geo_property_map[idx];
|
|
|
|
// only retrievable if we know the name of the location (which for some reason _is_ often there)
|
|
|
|
if (!node.printouts[srcProp].length) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const loc = node.printouts[srcProp][0].fulltext;
|
|
|
|
if (!smwBugFixLocationMaps.hasOwnProperty(loc)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
node.printouts[idx] = smwBugFixLocationMaps[loc]
|
|
|
|
fixes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-04-19 19:49:33 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
console.debug(`Fixed location for ${fixes} nodes`);
|
2021-04-16 11:15:57 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
nodeMap = Object.fromEntries(nodes.map(d => [d['id'], d]));
|
|
|
|
links = links.filter(l => nodeMap[l.source] && nodeMap[l.target]).map(l => {
|
|
|
|
l.source = nodeMap[l.source];
|
|
|
|
l.target = nodeMap[l.target];
|
2021-04-29 15:36:27 +02:00
|
|
|
l.nr = linkI++;
|
2021-04-17 21:15:03 +02:00
|
|
|
return l;
|
2021-04-29 15:36:27 +02:00
|
|
|
}).filter((link, index, self) =>
|
|
|
|
// remove incidental duplicates
|
|
|
|
index === self.findIndex((l) => (
|
|
|
|
l.source.id === link.source.id && l.target.id === link.target.id && l.name === link.name
|
|
|
|
))
|
|
|
|
);
|
2021-03-30 16:30:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
return { nodes, links }
|
2021-04-16 11:15:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-19 22:47:06 +02:00
|
|
|
JsonToAlluvial = function (data) {
|
|
|
|
let boxes = {};
|
|
|
|
let links = [];
|
|
|
|
|
|
|
|
for (const box in CONFIG.alluvial_props) {
|
|
|
|
boxes[box] = []
|
|
|
|
}
|
|
|
|
|
|
|
|
const relevant_categories = CONFIG.alluvial_cats.map(c => "Category:" + c);
|
|
|
|
|
|
|
|
// gather boxes ('node' in alluvial)
|
|
|
|
for (const node_id in data) {
|
|
|
|
if (Object.hasOwnProperty.call(data, node_id)) {
|
|
|
|
let node = data[node_id];
|
|
|
|
|
|
|
|
// we only want deployments
|
|
|
|
if (!relevant_categories.includes(node.printouts["Category"][0].fulltext)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const box in CONFIG.alluvial_props) {
|
|
|
|
let has_any = false;
|
|
|
|
for (const prop of CONFIG.alluvial_props[box]) {
|
|
|
|
// console.log(box, prop);
|
|
|
|
if (!node.printouts.hasOwnProperty(prop)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (const target_node of node.printouts[prop]) {
|
|
|
|
boxes[box].push(target_node.fulltext)
|
|
|
|
has_any = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!has_any) {
|
|
|
|
boxes[box].push("Unknown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const nodes = [];
|
|
|
|
// reduce the items in the boxes by count. And convert to 'nodes' of the Sankey
|
|
|
|
for (const box in CONFIG.alluvial_props) {
|
|
|
|
boxes[box] = boxes[box].reduce(function (acc, curr) {
|
|
|
|
if (typeof acc[curr] == 'undefined') {
|
|
|
|
acc[curr] = 1;
|
|
|
|
} else {
|
|
|
|
acc[curr] += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
boxSorted = Object.keys(boxes[box]).sort(function (a, b) { return boxes[box][a] - boxes[box][b] }).reverse()
|
|
|
|
useBox = boxSorted.splice(0, 10);
|
|
|
|
restBox = boxSorted;
|
|
|
|
// gather stats:
|
|
|
|
boxes[box] = {
|
|
|
|
'counts': boxes[box],
|
|
|
|
'use': useBox,
|
|
|
|
'rest': restBox,
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const name of useBox) {
|
|
|
|
nodes.push({
|
|
|
|
name,
|
|
|
|
"id": box + "::" + name,
|
|
|
|
box,
|
|
|
|
"about": "" // TODO, what can we say here?
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
if (restBox.length) {
|
|
|
|
nodes.push({
|
|
|
|
"name": "Other",
|
|
|
|
"id": box + "::" + "Other",
|
|
|
|
box,
|
|
|
|
"about": restBox, //some extra stats for use
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let linkMap = {};
|
|
|
|
// another round: now, we collect the links
|
|
|
|
for (const node_id in data) {
|
|
|
|
if (Object.hasOwnProperty.call(data, node_id)) {
|
|
|
|
let node = data[node_id];
|
|
|
|
|
|
|
|
// we only want deployments
|
|
|
|
if (!relevant_categories.includes(node.printouts["Category"][0].fulltext)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let prev_box = null;
|
|
|
|
for (const box in CONFIG.alluvial_props) {
|
|
|
|
let cur_box = [];
|
|
|
|
let has_any = false;
|
|
|
|
for (const prop of CONFIG.alluvial_props[box]) {
|
|
|
|
// console.log(box, prop);
|
|
|
|
if (!node.printouts.hasOwnProperty(prop)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (const target_node of node.printouts[prop]) {
|
|
|
|
if (boxes[box].use.includes(target_node.fulltext)) {
|
|
|
|
cur_box.push(box + "::" + target_node.fulltext)
|
|
|
|
} else {
|
|
|
|
cur_box.push(box + "::" + "Other")
|
|
|
|
}
|
|
|
|
has_any = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!has_any) {
|
|
|
|
cur_box.push(box + "::" + "Unknown")
|
|
|
|
}
|
|
|
|
if (prev_box !== null) {
|
|
|
|
// TODO: links
|
|
|
|
for (let source of prev_box) {
|
|
|
|
for (let target of cur_box) {
|
|
|
|
if (typeof linkMap[source] == 'undefined') {
|
|
|
|
linkMap[source] = {};
|
|
|
|
}
|
|
|
|
if (typeof linkMap[source][target] == 'undefined') {
|
|
|
|
linkMap[source][target] = 0;
|
|
|
|
}
|
|
|
|
linkMap[source][target] += 1 / (prev_box.length * cur_box.length) // TODO: is this right?
|
|
|
|
// links.push({
|
|
|
|
// source,
|
|
|
|
// target,
|
|
|
|
// value: 1 / (prev_box.length * cur_box.length) // TODO: is this right?
|
|
|
|
// })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prev_box = cur_box;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const source in linkMap) {
|
|
|
|
for (const target in linkMap[source]) {
|
|
|
|
links.push({
|
|
|
|
source,
|
|
|
|
target,
|
|
|
|
value: linkMap[source][target]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log(boxes);
|
|
|
|
|
|
|
|
// let fixes = 0;
|
|
|
|
// nodes.forEach((node) => {
|
|
|
|
// // work around SMW bug in Ask. 2/2
|
|
|
|
// for (const idx of Object.keys(CONFIG.geo_property_map)) {
|
|
|
|
// if (!node.printouts[idx].length) {
|
|
|
|
// const srcProp = CONFIG.geo_property_map[idx];
|
|
|
|
// // only retrievable if we know the name of the location (which for some reason _is_ often there)
|
|
|
|
// if (!node.printouts[srcProp].length) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// const loc = node.printouts[srcProp][0].fulltext;
|
|
|
|
// if (!smwBugFixLocationMaps.hasOwnProperty(loc)) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// node.printouts[idx] = smwBugFixLocationMaps[loc]
|
|
|
|
// fixes++;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
|
|
|
|
// console.debug(`Fixed location for ${fixes} nodes`);
|
|
|
|
|
|
|
|
// console.log(links.length);
|
|
|
|
|
|
|
|
// nodeMap = Object.fromEntries(nodes.map(d => [d['id'], d]));
|
|
|
|
// links = links.filter(l => nodeMap[l.source] && nodeMap[l.target]).map(l => {
|
|
|
|
// l.source = nodeMap[l.source];
|
|
|
|
// l.target = nodeMap[l.target];
|
|
|
|
// return l;
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { nodes, links, boxes }
|
|
|
|
}
|
2021-04-16 11:15:57 +02:00
|
|
|
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
class Store {
|
|
|
|
constructor(graph, parent) {
|
|
|
|
this.nodes = graph.nodes;
|
|
|
|
this.links = graph.links;
|
2021-04-27 16:10:23 +02:00
|
|
|
// graph is a filtered version of this.nodes & this.links
|
2021-04-17 21:15:03 +02:00
|
|
|
this.graph = {
|
|
|
|
'nodes': [],
|
|
|
|
'links': []
|
2021-04-16 11:15:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
this.root = document.querySelector(parent);
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
this._maps = [];
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
this.filters = {
|
|
|
|
'categories': [],
|
2021-05-06 10:55:14 +02:00
|
|
|
'institution_types': [],
|
2021-04-17 21:15:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.filter();
|
2021-03-30 16:30:50 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-27 16:10:23 +02:00
|
|
|
configureTree() {
|
|
|
|
// set up the tree, we do this only after all points are configured.
|
|
|
|
this.quadtree = d3.quadtree(
|
|
|
|
this.nodes,
|
|
|
|
(n) => n.x,
|
|
|
|
(n) => n.y
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// from: https://observablehq.com/@d3/quadtree-findincircle
|
|
|
|
findInCircle(x, y, radius, filter) {
|
|
|
|
if (typeof this.quadtree === 'undefined') {
|
|
|
|
this.configureTree();
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = [],
|
|
|
|
radius2 = radius * radius,
|
|
|
|
accept = filter
|
|
|
|
? d => filter(d) && result.push(d)
|
|
|
|
: d => result.push(d);
|
|
|
|
|
|
|
|
this.quadtree.visit((node, x1, y1, x2, y2) => {
|
|
|
|
if (node.length) {
|
|
|
|
return x1 >= x + radius || y1 >= y + radius || x2 < x - radius || y2 < y - radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
const dx = +this.quadtree._x.call(null, node.data) - x,
|
|
|
|
dy = +this.quadtree._y.call(null, node.data) - y;
|
|
|
|
if (dx * dx + dy * dy < radius2) {
|
|
|
|
do { accept(node.data); } while (node = node.next);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
findVisibleInCircle(x, y, radius) {
|
|
|
|
return this.findInCircle(x, y, radius, (n) => !n.filtered);
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
registerMap(map) {
|
|
|
|
this._maps.push(map);
|
|
|
|
return this;
|
2021-03-30 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
update() {
|
|
|
|
this._maps.forEach(m => {
|
|
|
|
m.update();
|
|
|
|
});
|
2021-03-30 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2021-05-06 10:55:14 +02:00
|
|
|
isFiltered(node) {
|
2021-08-12 09:00:05 +02:00
|
|
|
if (this.filters.categories.includes(node.printouts['Category'][0].fulltext.split(':')[1]))
|
2021-05-06 10:55:14 +02:00
|
|
|
return true;
|
2021-08-12 09:00:05 +02:00
|
|
|
if (node.printouts['Institution Type'].length && this.filters.institution_types.includes(node.printouts['Institution Type'][0].fulltext))
|
2021-05-06 10:55:14 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
filter() {
|
|
|
|
// add and remove nodes from data based on type filters
|
|
|
|
this.nodes.forEach((n) => {
|
2021-05-06 10:55:14 +02:00
|
|
|
if (!this.isFiltered(n)) {
|
2021-04-17 21:15:03 +02:00
|
|
|
if (n.filtered || typeof n.filtered === 'undefined') {
|
|
|
|
n.filtered = false;
|
|
|
|
this.graph.nodes.push(n);
|
|
|
|
}
|
|
|
|
} else if (!n.filtered) {
|
|
|
|
n.filtered = true;
|
|
|
|
this.graph.nodes.forEach((d, i) => {
|
|
|
|
if (n.id === d.id) {
|
|
|
|
this.graph.nodes.splice(i, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
// add and remove links from data based on availability of nodes
|
|
|
|
this.links.forEach((l) => {
|
2021-05-06 10:55:14 +02:00
|
|
|
// if (this.graph.nodes.includes(l.source) && this.graph.nodes.includes(l.target)) {
|
|
|
|
if (!l.source.filtered && !l.target.filtered) {
|
2021-04-17 21:15:03 +02:00
|
|
|
if (l.filtered || typeof l.filtered === 'undefined')
|
|
|
|
this.graph.links.push(l);
|
|
|
|
l.filtered = false;
|
|
|
|
} else {
|
|
|
|
if (l.filtered === false) {
|
2021-05-06 10:55:14 +02:00
|
|
|
console.log('filter', l.id);
|
2021-04-17 21:15:03 +02:00
|
|
|
this.graph.links.forEach((d, i) => {
|
2021-05-06 10:55:14 +02:00
|
|
|
if (l.nr === d.nr) {
|
2021-04-17 21:15:03 +02:00
|
|
|
this.graph.links.splice(i, 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
l.filtered = true;
|
|
|
|
}
|
|
|
|
});
|
2021-05-06 10:55:14 +02:00
|
|
|
|
|
|
|
console.log(this.graph.nodes.length, this.graph.links.length)
|
2021-04-17 21:15:03 +02:00
|
|
|
}
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
render() {
|
2021-05-06 10:55:14 +02:00
|
|
|
Object.keys(CONFIG.filters).forEach(f => {
|
|
|
|
const settings = CONFIG.filters[f];
|
|
|
|
|
2021-08-13 11:20:44 +02:00
|
|
|
// if (settings.type == 'institution_types')
|
|
|
|
// // TODO; For now, skip
|
|
|
|
// return;
|
2021-04-28 11:18:02 +02:00
|
|
|
|
2021-05-06 10:55:14 +02:00
|
|
|
let categories = [f];
|
2021-08-12 09:00:05 +02:00
|
|
|
if (settings.type == 'institution_types')
|
2021-05-06 10:55:14 +02:00
|
|
|
categories = ['Institution', getInstitutionClass(f)];
|
2021-08-12 09:00:05 +02:00
|
|
|
|
2021-08-13 11:20:44 +02:00
|
|
|
let labelEl = document.createElement('label');
|
|
|
|
labelEl.setAttribute('id', 'filter-'+slugify(f));
|
|
|
|
labelEl.classList.add(settings.type)
|
2021-04-17 21:15:03 +02:00
|
|
|
let inputEl = document.createElement('input')
|
|
|
|
let textEl = document.createElement('span');
|
2021-04-28 11:18:02 +02:00
|
|
|
let svg = d3.select(labelEl).append('svg')
|
2021-04-29 15:36:27 +02:00
|
|
|
.attr("viewBox", [-12, -12, 24, 24]);
|
2021-04-28 11:18:02 +02:00
|
|
|
svg.append('g')
|
2021-05-06 10:55:14 +02:00
|
|
|
.attr("class", "node " + categories.join(' '))
|
2021-04-28 11:18:02 +02:00
|
|
|
.append('path')
|
2021-05-06 10:55:14 +02:00
|
|
|
.attr('d', getSymbolForCategories(categories)());
|
2021-04-17 21:15:03 +02:00
|
|
|
inputEl.type = "checkbox";
|
2021-08-13 11:20:44 +02:00
|
|
|
textEl.innerText = settings.hasOwnProperty('label') ? settings.label : f;
|
2021-04-17 21:15:03 +02:00
|
|
|
labelEl.appendChild(inputEl);
|
|
|
|
labelEl.appendChild(textEl);
|
|
|
|
|
2021-05-06 10:55:14 +02:00
|
|
|
if (!this.filters[settings.type].includes(f)) {
|
2021-04-17 21:15:03 +02:00
|
|
|
inputEl.checked = true;
|
|
|
|
}
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
inputEl.addEventListener('change', (e) => {
|
|
|
|
if (e.target.checked) {
|
2021-05-06 10:55:14 +02:00
|
|
|
this.filters[settings.type].forEach((d, i) => {
|
2021-04-17 21:15:03 +02:00
|
|
|
if (d == f) {
|
2021-05-06 10:55:14 +02:00
|
|
|
this.filters[settings.type].splice(i, 1);
|
2021-04-17 21:15:03 +02:00
|
|
|
}
|
|
|
|
});
|
2021-08-13 11:20:44 +02:00
|
|
|
this.root.classList.remove('filter-'+slugify(f))
|
2021-04-17 21:15:03 +02:00
|
|
|
} else {
|
2021-05-06 10:55:14 +02:00
|
|
|
if (!this.filters[settings.type].includes(f)) {
|
|
|
|
this.filters[settings.type].push(f);
|
2021-04-17 21:15:03 +02:00
|
|
|
}
|
2021-08-13 11:20:44 +02:00
|
|
|
this.root.classList.add('filter-'+slugify(f))
|
2021-04-17 21:15:03 +02:00
|
|
|
}
|
|
|
|
this.filter();
|
|
|
|
this.update();
|
|
|
|
})
|
|
|
|
|
|
|
|
this.root.appendChild(labelEl);
|
|
|
|
})
|
2021-03-30 16:30:50 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
}
|
2021-03-30 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 11:15:57 +02:00
|
|
|
|
2021-04-19 22:47:06 +02:00
|
|
|
var mapGraph = new NodeMap('#map')
|
2021-04-27 16:10:23 +02:00
|
|
|
// var alluvialGraph = new AlluvialMap('#alluvial')
|
2021-04-19 22:47:06 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
// REQUEST ATLAS & GRAPH
|
|
|
|
const req_data = new Request(CONFIG.dataUrl, { method: 'GET' });
|
|
|
|
const req_world = new Request('https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json', { method: 'GET' });
|
|
|
|
Promise.all([fetch(req_data), fetch(req_world)])
|
|
|
|
.then(([res_data, res_world]) => {
|
|
|
|
return Promise.all([res_data.json(), res_world.json()]);
|
2021-04-16 11:15:57 +02:00
|
|
|
})
|
2021-04-17 21:15:03 +02:00
|
|
|
.then(([data, world]) => {
|
|
|
|
var graph = JsonToGraph(data);
|
2021-08-13 11:20:44 +02:00
|
|
|
var store = new Store(graph, '#filter-items');
|
2021-04-19 22:47:06 +02:00
|
|
|
|
2021-04-17 21:15:03 +02:00
|
|
|
mapGraph.setWorld(world);
|
|
|
|
mapGraph.setStore(store);
|
2021-04-27 16:10:23 +02:00
|
|
|
// alluvialGraph.setData(data.results);
|
2021-04-17 21:15:03 +02:00
|
|
|
|
2021-04-19 22:47:06 +02:00
|
|
|
store.render()
|
2021-04-17 21:15:03 +02:00
|
|
|
mapGraph.render()
|
2021-04-27 16:10:23 +02:00
|
|
|
// alluvialGraph.render()
|
2021-04-17 21:15:03 +02:00
|
|
|
|
|
|
|
}).catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
});
|
|
|
|
;
|