Commit 9f438e73 authored by Maxime Chazalviel's avatar Maxime Chazalviel

Merge branch 'hotfix/scale'

parents 582658fe 102d63eb
......@@ -80,72 +80,75 @@ metExploreD3.GraphNetwork = {
}
// Control if the user can see all the graph
if (anim && previousScale>0.05 && session.isResizable()) {
var vizRect = document.getElementById(panel).getBoundingClientRect();
var graphComponent = d3.select("#"+panel).select("#D3viz").select('#graphComponent');
var graphComponentRect = d3.select("#"+panel).select("#D3viz").node().getElementById('graphComponent').getBoundingClientRect();
var width = parseInt(metExploreD3.GraphPanel.getHeight(panel));
var height = parseInt(metExploreD3.GraphPanel.getWidth(panel));
if(vizRect.top>graphComponentRect.top
|| vizRect.left>graphComponentRect.left
|| vizRect.bottom<graphComponentRect.bottom
|| vizRect.right<graphComponentRect.right)
{
var dataLength =session.getD3Data().getNodesLength();
var delay = 3000;
if (dataLength < generalStyle.getReactionThreshold() || !generalStyle.isDisplayedLabelsForOpt())
delay = 3000;
metExploreD3.fixDelay(metExploreD3.GraphNetwork.task, delay);
var zoomListener = scale.getZoom();
var updateScale = 0.01*dataLength/100;
var newScale = previousScale-(previousScale*updateScale);
zoomListener.scaleBy(d3.select("#"+panel).select("#D3viz"), newScale);
var newWidth = newScale*width;
var newHeight = newScale*height;
var xScale = (width-newWidth)/2;
var yScale = (height-newHeight)/2;
zoomListener.translateBy(d3.select("#"+panel).select("#D3viz"), xScale, yScale);
scale.setZoomScale(newScale);
}
else
{
if(!((vizRect.top+height/10>graphComponentRect.top && vizRect.bottom-height/10<graphComponentRect.bottom)
|| (vizRect.left+width/10>graphComponentRect.left && vizRect.right-width/10<graphComponentRect.right))){
var dataLength =session.getD3Data().getNodesLength();
var delay = 3000;
if (dataLength < generalStyle.getReactionThreshold() || !generalStyle.isDisplayedLabelsForOpt())
delay = 3000;
metExploreD3.fixDelay(metExploreD3.GraphNetwork.task, delay);
var zoomListener = scale.getZoom();
if(updateScale==undefined) updateScale = 0.01;
else updateScale = updateScale/2;
var newScale = previousScale+(previousScale*updateScale);
zoomListener.scaleBy(d3.select("#"+panel).select("#D3viz"), newScale);
var newWidth = newScale*width;
var newHeight = newScale*height;
var xScale = (width-newWidth)/2;
var yScale = (height-newHeight)/2;
zoomListener.translateBy(d3.select("#"+panel).select("#D3viz"), xScale,yScale);
scale.setZoomScale(newScale);
}
}
if (anim && alpha<0.1 && session.isResizable()) {
session.setResizable(false);
metExploreD3.GraphNetwork.task.cancel();
metExploreD3.GraphNetwork.rescale(panel);
// metExploreD3.GraphNetwork.task.cancel();
// var vizRect = document.getElementById(panel).getBoundingClientRect();
// var graphComponent = d3.select("#"+panel).select("#D3viz").select('#graphComponent');
// var graphComponentRect = d3.select("#"+panel).select("#D3viz").node().getElementById('graphComponent').getBoundingClientRect();
//
// var width = parseInt(metExploreD3.GraphPanel.getHeight(panel));
// var height = parseInt(metExploreD3.GraphPanel.getWidth(panel));
//
// if(vizRect.top>graphComponentRect.top
// || vizRect.left>graphComponentRect.left
// || vizRect.bottom<graphComponentRect.bottom
// || vizRect.right<graphComponentRect.right)
// {
// var dataLength =session.getD3Data().getNodesLength();
// var delay = 3000;
// if (dataLength < generalStyle.getReactionThreshold() || !generalStyle.isDisplayedLabelsForOpt())
// delay = 3000;
//
//
//
// var zoomListener = scale.getZoom();
//
// var updateScale = 0.01*dataLength/100;
// var newScale = previousScale-(previousScale*updateScale);
// zoomListener.scaleBy(d3.select("#"+panel).select("#D3viz"), newScale);
//
// var newWidth = newScale*width;
// var newHeight = newScale*height;
// var xScale = (width-newWidth)/2;
// var yScale = (height-newHeight)/2;
// zoomListener.translateBy(d3.select("#"+panel).select("#D3viz"), xScale, yScale);
//
// scale.setZoomScale(newScale);
//
// }
// else
// {
// if(!((vizRect.top+height/10>graphComponentRect.top && vizRect.bottom-height/10<graphComponentRect.bottom)
// || (vizRect.left+width/10>graphComponentRect.left && vizRect.right-width/10<graphComponentRect.right))){
// var dataLength =session.getD3Data().getNodesLength();
// var delay = 3000;
// if (dataLength < generalStyle.getReactionThreshold() || !generalStyle.isDisplayedLabelsForOpt())
// delay = 3000;
//
// metExploreD3.fixDelay(metExploreD3.GraphNetwork.task, delay);
//
// var zoomListener = scale.getZoom();
//
// if(updateScale==undefined) updateScale = 0.01;
// else updateScale = updateScale/2;
//
// var newScale = previousScale+(previousScale*updateScale);
// zoomListener.scaleBy(d3.select("#"+panel).select("#D3viz"), newScale);
//
// var newWidth = newScale*width;
// var newHeight = newScale*height;
// var xScale = (width-newWidth)/2;
// var yScale = (height-newHeight)/2;
//
// zoomListener.translateBy(d3.select("#"+panel).select("#D3viz"), xScale,yScale);
//
// scale.setZoomScale(newScale);
//
// }
// }
}
}
},
......@@ -169,9 +172,12 @@ metExploreD3.GraphNetwork = {
// else d3.select("#"+panelLinked).select("#D3viz").select("#graphComponent").selectAll('text').classed("hide", false);
if(d3EventSourceEvent !==null)
if(d3EventSourceEvent.type==='wheel')
if(d3EventSourceEvent !==null){
if(d3EventSourceEvent.type==='wheel'){
session.setResizable(false);
metExploreD3.GraphNetwork.task.cancel();
}
}
// if visualisation is actived we add item to menu
if(session.isActive()){
......@@ -890,6 +896,7 @@ metExploreD3.GraphNetwork = {
session.setResizable(true);
metExploreD3.GraphNetwork.task = metExploreD3.createDelayedTask(
function(){
metExploreD3.GraphNetwork.rescale(panel);
session.setResizable(false);
}
);
......@@ -1106,6 +1113,7 @@ metExploreD3.GraphNetwork = {
if(force.alpha() >= .005 /*&& force.alpha() < .06*/){
setTimeout(metExploreD3.GraphNetwork.tick(panel), 0);
if(metExploreD3.GraphNetwork.first){
metExploreD3.fixDelay(metExploreD3.GraphNetwork.task, 6000);
metExploreD3.GraphNetwork.refreshViz(panel);
metExploreD3.GraphNetwork.first=false;
}
......@@ -1170,7 +1178,7 @@ metExploreD3.GraphNetwork = {
}, 200);
},
rescale : function(panel){
rescale : function(panel, func){
var mask = metExploreD3.createLoadMask("Rescaling graph", panel);
metExploreD3.showMask(mask);
......@@ -1263,6 +1271,7 @@ metExploreD3.GraphNetwork = {
scaleViz.setZoomScale(scale);
metExploreD3.hideMask(mask);
if (func) func();
}), scale);
});
},
......
......@@ -1071,74 +1071,23 @@ metExploreD3.GraphNode = {
metExploreD3.displayMessage("Warning", 'The node "' + selectedVal + '" doesn\'t exist.')
}
else {
metExploreD3.GraphNetwork.rescale("viz", function(){
var scaleViz = metExploreD3.getScaleById("viz");
var zoom = scaleViz.getZoom();
var scaleViz = metExploreD3.getScaleById("viz");
var zoom = scaleViz.getZoom();
d3.select("#viz").select("#D3viz").select("#graphComponent")
.transition()
.duration(750)
.attr("transform", "translate(0,0)scale(1)")
.each(function () {
zoom.translateBy( d3.select("#viz").select("#D3viz"),0 ,0);
zoom.scaleBy(d3.select("#viz").select("#D3viz"),1);
scaleViz.setZoomScale(1);
var maxX = -100000;
var maxY = -100000;
var minX = 100000;
var minY = 100000;
selected.each(
function (aSelectedNode) {
if (maxX < aSelectedNode.x)
maxX = aSelectedNode.x;
if (maxY < aSelectedNode.y)
maxY = aSelectedNode.y;
if (minX > aSelectedNode.x)
minX = aSelectedNode.x;
if (minY > aSelectedNode.y)
minY = aSelectedNode.y;
});
var dx = maxX - minX,
dy = maxY - minY;
var rectPanel = d3.select("#viz").select("#D3viz").node().getBoundingClientRect();
var width = parseInt(metExploreD3.GraphPanel.getWidth("viz").replace("px", ""));
var height = parseInt(metExploreD3.GraphPanel.getHeight("viz").replace("px", ""));
// var scale = 1;
var scale = (Math.min(height / dy, width / dx)) * 0.7;
var transX = scale * (rectPanel.left - minX);
var transY = scale * (rectPanel.top - minY);
d3.select("#viz").select("#D3viz").select("#graphComponent")
.transition()
.duration(750)
.attr("transform", "translate(" + transX + "," + transY + ")scale(" + scale + ")")
.each(function () {
metExploreD3.GraphLink.tick("viz", scale);
metExploreD3.GraphNode.tick("viz");
metExploreD3.hideMask(mask);
});
zoom.translateBy( d3.select("#viz").select("#D3viz"),transX ,transY);
zoom.scaleBy(d3.select("#viz").select("#D3viz"), scale);
scaleViz.setZoomScale(scale);
d3.select("#viz").select("#D3viz").select("#graphComponent")
.transition()
.duration(750)
.attr("transform", "translate(0,0)scale(1)")
.each(function () {
selected.each(
function (aSelectedNode) {
_MyThisGraphNode.highlightANode(aSelectedNode, 'viz');
selected.each(
function (aSelectedNode) {
_MyThisGraphNode.highlightANode(aSelectedNode, 'viz');
});
});
metExploreD3.hideMask(mask);
});
});
});
}
},
......
......@@ -48,6 +48,7 @@ metExploreD3.GraphPanel = {
* To resize svg viz when layout is modified
*/
resizeViz : function(panel){
console.log("resizeViz");
var scale = metExploreD3.getScaleById(panel);
if(scale!=undefined){
......@@ -116,59 +117,6 @@ metExploreD3.GraphPanel = {
d3.select("#metexplore").text('MetExploreViz').attr('x', $("#viz").width() - 112).attr(
'y', $("#viz").height() - 10);
if(session!=undefined)
{
if(session.isLinked()){
var sessionMain = _metExploreViz.getSessionById("viz");
var force = sessionMain.getForce();
if(force!=undefined){
var h = $("#viz").height();
var w = $("#viz").width();
var forceX = d3.forceX()
.x(w/2)
.strength(0.006);
var forceY = d3.forceY()
.y(h/2)
.strength(0.006);
force
.force('x', forceX)
.force('y', forceY);
var anim=d3.select("#viz").select("#buttonAnim").attr("animation");
if(anim=="true")
force.alpha(1).restart();
}
}
else
{
var force = session.getForce();
if(force!=undefined){
var h = $("#"+panel).height();
var w = $("#"+panel).width();
var forceX = d3.forceX()
.x(w/2)
.strength(0.006);
var forceY = d3.forceY()
.y(h/2)
.strength(0.006);
force
.force('x', forceX)
.force('y', forceY);
if(d3.select("#"+panel).select("#buttonAnim").node()){
var anim=d3.select("#"+panel).select("#buttonAnim").attr("animation");
if(anim=="true")
force.alpha(1).restart();
}
}
}
}
}
},
......@@ -177,15 +125,17 @@ metExploreD3.GraphPanel = {
* @param {} panel : active panel
*/
resizePanels : function(panel){
console.log("resizePanels");
var sessionsStore = _metExploreViz.getSessionsSet();
var session = _metExploreViz.getSessionById(panel);
var h = $("#"+panel).height();
var w = $("#"+panel).width();
console.log(d3.select("#"+panel).select("#D3viz").select("#buttonZoomIn"));
if(d3.select("#"+panel).select("#D3viz").select("#buttonZoomIn")[0]!=null
&& d3.select("#"+panel).select("#D3viz").select("#buttonZoomOut")[0]!=null
&& d3.select("#"+panel).select("#D3viz").select("#buttonHand")[0]!=null)
if(d3.select("#"+panel).select("#D3viz").select("#buttonZoomIn").node()!=null
&& d3.select("#"+panel).select("#D3viz").select("#buttonZoomOut").node()!=null
&& d3.select("#"+panel).select("#D3viz").select("#buttonHand").node()!=null)
{
var x = d3
.select("#"+panel)
......@@ -251,10 +201,6 @@ metExploreD3.GraphPanel = {
.scaleExtent([ 0.01, 30 ])
.extent([[w*.45, h*.45], [w*.55, h*.55]])
.translateExtent([[-w*2, -h*2], [w*3, h*3]]);
var anim=d3.select("#viz").select("#buttonAnim").attr("animation");
if(anim=="true")
force.alpha(1).restart();
}
}
else
......@@ -279,40 +225,9 @@ metExploreD3.GraphPanel = {
.scaleExtent([ 0.01, 30 ])
.extent([[w*.45, h*.45], [w*.55, h*.55]])
.translateExtent([[-w*2, -h*2], [w*3, h*3]]);
if(d3.select("#"+panel).select("#buttonAnim").node()){
var anim=d3.select("#"+panel).select("#buttonAnim").attr("animation");
if(anim=="true")
force.alpha(1).restart();
}
}
}
}
var sessions = _metExploreViz.getSessionsSet();
var session = _metExploreViz.getSessionById(panel);
if(session!=undefined)
{
var anim = metExploreD3.GraphNetwork.isAnimated(panel);;
if (anim == "true") {
if(session.isLinked())
{
for (var key in sessions) {
if(sessions[key].isLinked())
metExploreD3.GraphNetwork.animationButtonOn(sessions[key].getId());
}
var force = _metExploreViz.getSessionById("viz").getForce();
force.alpha(1).restart();
}
else
{
metExploreD3.GraphNetwork.animationButtonOn(panel);
var force = session.getForce();
force.alpha(1).restart();
}
}
}
},
/*****************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment