Fix date and consider translation when determining center

This commit is contained in:
Ruben van de Ven 2018-10-16 10:34:14 +02:00
parent 418fc4df6e
commit 2f1ff8f55d
1 changed files with 35 additions and 14 deletions

View File

@ -26,20 +26,20 @@ function getNodeLabel(node){
return label; return label;
} }
function getNodeYear(n){ function getNodeYear(n){
if(typeof n['http://schema.org/dateCreated'] !== 'undefined') { if(typeof n['https://schema.org/dateCreated'] !== 'undefined') {
return n['http://schema.org/dateCreated'].substr(0,4); return n['https://schema.org/dateCreated'].substr(0,4);
} }
if(typeof n['http://schema.org/datePublished'] !== 'undefined') { if(typeof n['https://schema.org/datePublished'] !== 'undefined') {
return n['http://schema.org/datePublished'].substr(0,4); return n['https://schema.org/datePublished'].substr(0,4);
} }
if(typeof n['http://schema.org/startDate'] !== 'undefined') { if(typeof n['https://schema.org/startDate'] !== 'undefined') {
return n['http://schema.org/startDate'].substr(0,4); return n['https://schema.org/startDate'].substr(0,4);
} }
if(typeof n['http://schema.org/endDate'] !== 'undefined') { if(typeof n['https://schema.org/endDate'] !== 'undefined') {
return n['http://schema.org/endDate'].substr(0,4); return n['https://schema.org/endDate'].substr(0,4);
} }
if(typeof n['http://schema.org/foundingDate'] !== 'undefined') { if(typeof n['https://schema.org/foundingDate'] !== 'undefined') {
return n['http://schema.org/foundingDate'].substr(0,4); return n['https://schema.org/foundingDate'].substr(0,4);
} }
return null; return null;
} }
@ -369,6 +369,7 @@ var positionNodesInCenter = function(idxs) {
} }
var positionNodesInCircle = function(idxs, r) { var positionNodesInCircle = function(idxs, r) {
let viewBox = getViewbox(); let viewBox = getViewbox();
let zoom = getZoomValues();
setViewboxForceCenter(); // sets forceCx & forceCy setViewboxForceCenter(); // sets forceCx & forceCy
if(typeof r == 'undefined') { if(typeof r == 'undefined') {
if(idxs.length == 1) { if(idxs.length == 1) {
@ -378,8 +379,8 @@ var positionNodesInCircle = function(idxs, r) {
} }
} }
currentNodePositionRadius = r; currentNodePositionRadius = r;
let forceCx = viewBox[0] + viewBox[2]/2; let forceCx = viewBox[0] + viewBox[2]/2 - zoom['dx'];
let forceCy = viewBox[1] + viewBox[3]/2; let forceCy = viewBox[1] + viewBox[3]/2 - zoom['dy'];
let stepSize = 2*Math.PI / idxs.length; let stepSize = 2*Math.PI / idxs.length;
@ -692,9 +693,29 @@ var deselectNode = function() {
var forceCx, forceCy; var forceCx, forceCy;
var setViewboxForceCenter = function() { var setViewboxForceCenter = function() {
let viewBox = getViewbox(); let viewBox = getViewbox();
forceCx = viewBox[0] + viewBox[2]/2; let zoom = getZoomValues();
forceCy = viewBox[1] + viewBox[3]/2; forceCx = viewBox[0] + viewBox[2]/2 - zoom['dx'];
forceCy = viewBox[1] + viewBox[3]/2 - zoom['dy'];
} }
var getZoomValues = function(){
let zoomContainer = document.getElementById("container");
let dx = 0, dy = 0, scale = 1;
if(zoomContainer.transform.baseVal.length > 0) {
for(let transform of zoomContainer.transform.baseVal) {
if(transform.type == SVGTransform.SVG_TRANSFORM_TRANSLATE) {
dx += transform.matrix.e;
dy += transform.matrix.f;
}
else if (transform.type == SVGTransform.SVG_TRANSFORM_SCALE) {
scale *= transform.matrix.a; // assume simple scale
}
}
}
return {'dx': dx, 'dy': dy, 'scale': scale};
}
setViewboxForceCenter(); // sets forceCx & forceCy setViewboxForceCenter(); // sets forceCx & forceCy
var graphInitialised = false; var graphInitialised = false;