Commit 3e3f62fd authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Show reset scale for all zooms, not only select zone

parent 14b9d182
......@@ -191,7 +191,6 @@ d3.boxplot.mousetip.get_match = function(e) {
let j = 0;
while(!found && j < d3.boxplot.lines[i].length) {
let line = d3.boxplot.lines[i][j];
//console.log(c_x, c_y, line[0],line[1],line[2],line[3]);
let x_a = Math.min(line[0], line[1]);
let x_b = Math.max(line[0], line[1]);
let y_a = Math.min(line[2], line[3]);
......@@ -225,10 +224,6 @@ d3.boxplot.mousetip.get_match = function(e) {
x_min = d3.boxplot.get_human_readable_size(match[0] - cx_min, 3, "&nbsp;");
x_max = d3.boxplot.get_human_readable_size(match[1] - cx_min, 3, "&nbsp;");
}
console.log("MATCH:");
console.log(y_zone, y_min, y_max);
console.log(x_zone, x_min, x_max);
console.log(match[4]);
return {
x_zone: x_zone,
y_zone: y_zone,
......
......@@ -101,6 +101,13 @@ d3.boxplot.zoom.translate = function () {
let new_transform = `translate(${translate[0]}, ${translate[1]}) scale(${scale_x}, ${scale_y})`;
d3.boxplot.container.attr("transform", new_transform);
if (translate[0] !== 0 || translate[1] !== 0) {
$("#restore-all").show();
}
else {
$("#restore-all").hide();
}
//Update axis:
d3.boxplot.draw_top_axis();
d3.boxplot.draw_right_axis();
......@@ -183,9 +190,10 @@ d3.boxplot.zoom.zoom = function () {
let new_cursor = d3.boxplot.zoom._cursor_pos(new_rect);
let x_trans = (new_cursor[0] - cursor[0]) * new_scale;
let y_trans = (new_cursor[1] - cursor[1]) * new_scale;
let translate_x = old_transform["translate"][0]+x_trans;
let translate_y = old_transform["translate"][1]-y_trans;
let new_transform = `translate(${old_transform["translate"][0]+x_trans},${old_transform["translate"][1]-y_trans})
scale(${new_scale})`;
let new_transform = `translate(${translate_x},${translate_y}) scale(${new_scale})`;
d3.boxplot.container.attr("transform", new_transform);
d3.boxplot.zoom_scale_lines = new_scale;
......@@ -200,6 +208,14 @@ d3.boxplot.zoom.zoom = function () {
d3.boxplot.draw_right_axis();
d3.boxplot.zoom_bottom_axis();
d3.boxplot.zoom_left_axis();
if ((translate_x <= 0.00001 && translate_x >= -0.00001) &&
(translate_y <= 0.00001 && translate_y >= -0.00001) && new_scale === 1) {
$("#restore-all").hide();
}
else {
$("#restore-all").show();
}
}
}
else if (d3.boxplot.zoom_enabled) {
......
......@@ -390,8 +390,7 @@ d3.boxplot.draw_lines();$("#restore-all").click(function(){if(d3.boxplot.zoom.re
* @returns {{x_zone: string, y_zone: string, x_match: float[], y_match: float[], idy: float}}
*/d3.boxplot.mousetip.get_match=function(e){let rect=$("g.container")[0].getBoundingClientRect();let posX=rect.left+window.scrollX,posY=rect.top+window.scrollY,width_c=rect.width,height_c=rect.height;let c_x=(e.pageX-posX)/width_c*d3.boxplot.scale,c_y=d3.boxplot.scale-(e.pageY-posY)/height_c*d3.boxplot.scale;c_x=c_x/d3.boxplot.scale*d3.boxplot.x_len;c_y=c_y/d3.boxplot.scale*d3.boxplot.y_len;let error_x=d3.boxplot.content_lines_width/d3.boxplot.scale*d3.boxplot.x_len;let error_y=d3.boxplot.content_lines_width/d3.boxplot.scale*d3.boxplot.y_len;// let error_x = 0,
// error_y = 0;
let match=null;let found=false;for(let i=3;i>=0;i--){let j=0;while(!found&&j<d3.boxplot.lines[i].length){let line=d3.boxplot.lines[i][j];//console.log(c_x, c_y, line[0],line[1],line[2],line[3]);
let x_a=Math.min(line[0],line[1]);let x_b=Math.max(line[0],line[1]);let y_a=Math.min(line[2],line[3]);let y_b=Math.max(line[2],line[3]);if(x_a<=c_x&&c_x<=x_b&&y_a<=c_y&&c_y<=y_b){let m=(y_b-y_a)/(x_b-x_a);let p=y_a-m*x_a;let y_xmouse=m*c_x+p;if(y_xmouse-error_y<=c_y&&c_y<=y_xmouse+error_y){match=line;found=true}}j++}}if(match!==null){let y_zone=match[5];let x_zone=match[6];let y_min=null;let y_max=null;if(y_zone in d3.boxplot.y_zones){let cy_min=d3.boxplot.y_zones[y_zone][0]/d3.boxplot.scale*d3.boxplot.y_len;y_min=d3.boxplot.get_human_readable_size(match[2]-cy_min,3,"&nbsp;");y_max=d3.boxplot.get_human_readable_size(match[3]-cy_min,3,"&nbsp;")}let x_min=null;let x_max=null;if(x_zone in d3.boxplot.x_zones){let cx_min=d3.boxplot.x_zones[x_zone][0]/d3.boxplot.scale*d3.boxplot.x_len;x_min=d3.boxplot.get_human_readable_size(match[0]-cx_min,3,"&nbsp;");x_max=d3.boxplot.get_human_readable_size(match[1]-cx_min,3,"&nbsp;")}console.log("MATCH:");console.log(y_zone,y_min,y_max);console.log(x_zone,x_min,x_max);console.log(match[4]);return{x_zone:x_zone,y_zone:y_zone,x_match:[x_min,x_max],y_match:[y_min,y_max],idy:match[4]}}return null};if(!d3||!d3.boxplot){throw"d3.boxplot wasn't included!"}d3.boxplot.zoom={};d3.boxplot.zoom.help_timeout=null;/**
let match=null;let found=false;for(let i=3;i>=0;i--){let j=0;while(!found&&j<d3.boxplot.lines[i].length){let line=d3.boxplot.lines[i][j];let x_a=Math.min(line[0],line[1]);let x_b=Math.max(line[0],line[1]);let y_a=Math.min(line[2],line[3]);let y_b=Math.max(line[2],line[3]);if(x_a<=c_x&&c_x<=x_b&&y_a<=c_y&&c_y<=y_b){let m=(y_b-y_a)/(x_b-x_a);let p=y_a-m*x_a;let y_xmouse=m*c_x+p;if(y_xmouse-error_y<=c_y&&c_y<=y_xmouse+error_y){match=line;found=true}}j++}}if(match!==null){let y_zone=match[5];let x_zone=match[6];let y_min=null;let y_max=null;if(y_zone in d3.boxplot.y_zones){let cy_min=d3.boxplot.y_zones[y_zone][0]/d3.boxplot.scale*d3.boxplot.y_len;y_min=d3.boxplot.get_human_readable_size(match[2]-cy_min,3,"&nbsp;");y_max=d3.boxplot.get_human_readable_size(match[3]-cy_min,3,"&nbsp;")}let x_min=null;let x_max=null;if(x_zone in d3.boxplot.x_zones){let cx_min=d3.boxplot.x_zones[x_zone][0]/d3.boxplot.scale*d3.boxplot.x_len;x_min=d3.boxplot.get_human_readable_size(match[0]-cx_min,3,"&nbsp;");x_max=d3.boxplot.get_human_readable_size(match[1]-cx_min,3,"&nbsp;")}return{x_zone:x_zone,y_zone:y_zone,x_match:[x_min,x_max],y_match:[y_min,y_max],idy:match[4]}}return null};if(!d3||!d3.boxplot){throw"d3.boxplot wasn't included!"}d3.boxplot.zoom={};d3.boxplot.zoom.help_timeout=null;/**
* Initialize zoom.init module
*/d3.boxplot.zoom.init=function(){d3.boxplot.svgcontainer.on("click",d3.boxplot.zoom.click);d3.select(".drawcontainer").on("mousedown",d3.boxplot.zoom.mousedown).on("mouseup",d3.boxplot.zoom.mouseup).on("mousemove",d3.boxplot.zoom.translate);d3.boxplot.svgcontainer.on("wheel",d3.boxplot.zoom.zoom)};/**
* Click event action
......@@ -402,7 +401,7 @@ let x_a=Math.min(line[0],line[1]);let x_b=Math.max(line[0],line[1]);let y_a=Math
*/d3.boxplot.zoom.mouseup=function(){d3.boxplot.translate_start=null;$("#help-trans").fadeOut("slow")};/**
* Translate event action
*/d3.boxplot.zoom.translate=function(){let rect=$("g.container")[0].getBoundingClientRect();let posX=d3.boxplot.posX,posY=d3.boxplot.posY,width_c=rect.width,height_c=rect.height;let cursor_x=(d3.event.pageX-posX)/width_c*d3.boxplot.scale,cursor_y=(d3.event.pageY-posY)/height_c*d3.boxplot.scale;if(d3.boxplot.translate_start!==null&&d3.event.ctrlKey){let old_transform=d3.boxplot.container.attr("transform");//let scale = 1;
let scale_x=1;let scale_y=1;if(old_transform){let scale=old_transform.match(/scale\(([-\d.]+)(,\s*([-\d.]+))?\)/);scale_x=scale[1];scale_y=scale[1];if(scale[3]!==undefined)scale_y=scale[3]}let translate=[d3.boxplot.old_translate[0]+(cursor_x-d3.boxplot.translate_start[0])*scale_x,d3.boxplot.old_translate[1]+(cursor_y-d3.boxplot.translate_start[1])*scale_y];let min_tr=[d3.boxplot.scale-0.2*d3.boxplot.scale,d3.boxplot.scale-0.2*d3.boxplot.scale];let max_tr=[-d3.boxplot.scale*scale_x+200,-d3.boxplot.scale*scale_x+200];if(translate[0]<max_tr[0]){translate[0]=max_tr[0]}else if(translate[0]>min_tr[0]){translate[0]=min_tr[0]}if(translate[1]<max_tr[1]){translate[1]=max_tr[1]}else if(translate[1]>min_tr[1]){translate[1]=min_tr[1]}let new_transform=`translate(${translate[0]}, ${translate[1]}) scale(${scale_x}, ${scale_y})`;d3.boxplot.container.attr("transform",new_transform);//Update axis:
let scale_x=1;let scale_y=1;if(old_transform){let scale=old_transform.match(/scale\(([-\d.]+)(,\s*([-\d.]+))?\)/);scale_x=scale[1];scale_y=scale[1];if(scale[3]!==undefined)scale_y=scale[3]}let translate=[d3.boxplot.old_translate[0]+(cursor_x-d3.boxplot.translate_start[0])*scale_x,d3.boxplot.old_translate[1]+(cursor_y-d3.boxplot.translate_start[1])*scale_y];let min_tr=[d3.boxplot.scale-0.2*d3.boxplot.scale,d3.boxplot.scale-0.2*d3.boxplot.scale];let max_tr=[-d3.boxplot.scale*scale_x+200,-d3.boxplot.scale*scale_x+200];if(translate[0]<max_tr[0]){translate[0]=max_tr[0]}else if(translate[0]>min_tr[0]){translate[0]=min_tr[0]}if(translate[1]<max_tr[1]){translate[1]=max_tr[1]}else if(translate[1]>min_tr[1]){translate[1]=min_tr[1]}let new_transform=`translate(${translate[0]}, ${translate[1]}) scale(${scale_x}, ${scale_y})`;d3.boxplot.container.attr("transform",new_transform);if(translate[0]!==0||translate[1]!==0){$("#restore-all").show()}else{$("#restore-all").hide()}//Update axis:
d3.boxplot.draw_top_axis();d3.boxplot.draw_right_axis();d3.boxplot.zoom_bottom_axis();d3.boxplot.zoom_left_axis()}else if(d3.boxplot.translate_start!==null){let help_trans=$("#help-trans");help_trans.fadeIn("slow")}};/**
* Get cursor position
*
......@@ -411,10 +410,9 @@ d3.boxplot.draw_top_axis();d3.boxplot.draw_right_axis();d3.boxplot.zoom_bottom_a
* @private
*/d3.boxplot.zoom._cursor_pos=function(rect=null){let event=d3.event;if(rect===null){rect=$("g.container")[0].getBoundingClientRect()}let posX=rect.left+window.scrollX,posY=rect.top+window.scrollY,width_c=rect.width,height_c=rect.height;let x=(event.pageX-posX)/width_c*d3.boxplot.scale,y=d3.boxplot.scale-(event.pageY-posY)/height_c*d3.boxplot.scale;return[x,y,rect]};/**
* Zoom staff
*/d3.boxplot.zoom.zoom=function(){if(d3.event.ctrlKey){d3.event.preventDefault();d3.boxplot.mousetip.hide();if(d3.boxplot.zoom_enabled){let cursor=d3.boxplot.zoom._cursor_pos();let zoom_f=1.2;let old_transform=d3.boxplot.container.attr("transform");if(old_transform!==null){let search_tr=old_transform.match(/translate\(([-\de.]+),\s*([-\de.]+)\)/);let search_sc=old_transform.match(/scale\(([-\de.]+)(,\s*[-\de.]+)?\)/);old_transform={"scale":parseFloat(search_sc[1]),"translate":[parseFloat(search_tr[1]),parseFloat(search_tr[2])]}}else{old_transform={"scale":1,"translate":[0,0]}}let new_scale;let new_rect=cursor[2];if(d3.event.deltaY<0){new_scale=old_transform["scale"]*zoom_f;new_rect["width"]*=zoom_f;new_rect["height"]*=zoom_f}else{new_scale=old_transform["scale"]/zoom_f;let scale_ratio=zoom_f;if(new_scale<1){new_scale=1;scale_ratio=old_transform["scale"]}new_rect["width"]/=scale_ratio;new_rect["height"]/=scale_ratio}new_rect["bottom"]=new_rect["y"]+new_rect["height"];new_rect["right"]=new_rect["x"]+new_rect["width"];let new_cursor=d3.boxplot.zoom._cursor_pos(new_rect);let x_trans=(new_cursor[0]-cursor[0])*new_scale;let y_trans=(new_cursor[1]-cursor[1])*new_scale;let new_transform=`translate(${old_transform["translate"][0]+x_trans},${old_transform["translate"][1]-y_trans})
scale(${new_scale})`;d3.boxplot.container.attr("transform",new_transform);d3.boxplot.zoom_scale_lines=new_scale;d3.boxplot.zoom._cursor_pos();//Correct lines stroke width to be not impacted by the zoom:
*/d3.boxplot.zoom.zoom=function(){if(d3.event.ctrlKey){d3.event.preventDefault();d3.boxplot.mousetip.hide();if(d3.boxplot.zoom_enabled){let cursor=d3.boxplot.zoom._cursor_pos();let zoom_f=1.2;let old_transform=d3.boxplot.container.attr("transform");if(old_transform!==null){let search_tr=old_transform.match(/translate\(([-\de.]+),\s*([-\de.]+)\)/);let search_sc=old_transform.match(/scale\(([-\de.]+)(,\s*[-\de.]+)?\)/);old_transform={"scale":parseFloat(search_sc[1]),"translate":[parseFloat(search_tr[1]),parseFloat(search_tr[2])]}}else{old_transform={"scale":1,"translate":[0,0]}}let new_scale;let new_rect=cursor[2];if(d3.event.deltaY<0){new_scale=old_transform["scale"]*zoom_f;new_rect["width"]*=zoom_f;new_rect["height"]*=zoom_f}else{new_scale=old_transform["scale"]/zoom_f;let scale_ratio=zoom_f;if(new_scale<1){new_scale=1;scale_ratio=old_transform["scale"]}new_rect["width"]/=scale_ratio;new_rect["height"]/=scale_ratio}new_rect["bottom"]=new_rect["y"]+new_rect["height"];new_rect["right"]=new_rect["x"]+new_rect["width"];let new_cursor=d3.boxplot.zoom._cursor_pos(new_rect);let x_trans=(new_cursor[0]-cursor[0])*new_scale;let y_trans=(new_cursor[1]-cursor[1])*new_scale;let translate_x=old_transform["translate"][0]+x_trans;let translate_y=old_transform["translate"][1]-y_trans;let new_transform=`translate(${translate_x},${translate_y}) scale(${new_scale})`;d3.boxplot.container.attr("transform",new_transform);d3.boxplot.zoom_scale_lines=new_scale;d3.boxplot.zoom._cursor_pos();//Correct lines stroke width to be not impacted by the zoom:
d3.selectAll("path.content-lines").attr("stroke-width",d3.boxplot.content_lines_width/new_scale);d3.selectAll("line.break-lines").attr("stroke-width",d3.boxplot.break_lines_width/new_scale);//Update axis:
d3.boxplot.draw_top_axis();d3.boxplot.draw_right_axis();d3.boxplot.zoom_bottom_axis();d3.boxplot.zoom_left_axis()}}else if(d3.boxplot.zoom_enabled){let help_zoom=$("#help-zoom");help_zoom.fadeIn("slow");if(d3.boxplot.zoom.help_timeout!==null){window.clearTimeout(d3.boxplot.zoom.help_timeout)}d3.boxplot.zoom.help_timeout=window.setTimeout(()=>{help_zoom.fadeOut("slow")},700)}};/**
d3.boxplot.draw_top_axis();d3.boxplot.draw_right_axis();d3.boxplot.zoom_bottom_axis();d3.boxplot.zoom_left_axis();if(translate_x<=0.00001&&translate_x>=-0.00001&&translate_y<=0.00001&&translate_y>=-0.00001&&new_scale===1){$("#restore-all").hide()}else{$("#restore-all").show()}}}else if(d3.boxplot.zoom_enabled){let help_zoom=$("#help-zoom");help_zoom.fadeIn("slow");if(d3.boxplot.zoom.help_timeout!==null){window.clearTimeout(d3.boxplot.zoom.help_timeout)}d3.boxplot.zoom.help_timeout=window.setTimeout(()=>{help_zoom.fadeOut("slow")},700)}};/**
* Restore previous scale
*
* @param transform: transform object
......
......@@ -311,8 +311,7 @@ if(!d3||!d3.boxplot){throw'd3.boxplot wasn\'t included!'}d3.boxplot.mousetip={};
* @returns {{x_zone: string, y_zone: string, x_match: float[], y_match: float[], idy: float}}
*/d3.boxplot.mousetip.get_match=function(e){let rect=$('g.container')[0].getBoundingClientRect();let posX=rect.left+window.scrollX,posY=rect.top+window.scrollY,width_c=rect.width,height_c=rect.height;let c_x=(e.pageX-posX)/width_c*d3.boxplot.scale,c_y=d3.boxplot.scale-(e.pageY-posY)/height_c*d3.boxplot.scale;c_x=c_x/d3.boxplot.scale*d3.boxplot.x_len;c_y=c_y/d3.boxplot.scale*d3.boxplot.y_len;let error_x=d3.boxplot.content_lines_width/d3.boxplot.scale*d3.boxplot.x_len;let error_y=d3.boxplot.content_lines_width/d3.boxplot.scale*d3.boxplot.y_len;// let error_x = 0,
// error_y = 0;
let match=null;let found=false;for(let i=3;i>=0;i--){let j=0;while(!found&&j<d3.boxplot.lines[i].length){let line=d3.boxplot.lines[i][j];//console.log(c_x, c_y, line[0],line[1],line[2],line[3]);
let x_a=Math.min(line[0],line[1]);let x_b=Math.max(line[0],line[1]);let y_a=Math.min(line[2],line[3]);let y_b=Math.max(line[2],line[3]);if(x_a<=c_x&&c_x<=x_b&&y_a<=c_y&&c_y<=y_b){let m=(y_b-y_a)/(x_b-x_a);let p=y_a-m*x_a;let y_xmouse=m*c_x+p;if(y_xmouse-error_y<=c_y&&c_y<=y_xmouse+error_y){match=line;found=true}}j++}}if(match!==null){let y_zone=match[5];let x_zone=match[6];let y_min=null;let y_max=null;if(y_zone in d3.boxplot.y_zones){let cy_min=d3.boxplot.y_zones[y_zone][0]/d3.boxplot.scale*d3.boxplot.y_len;y_min=d3.boxplot.get_human_readable_size(match[2]-cy_min,3,'&nbsp;');y_max=d3.boxplot.get_human_readable_size(match[3]-cy_min,3,'&nbsp;')}let x_min=null;let x_max=null;if(x_zone in d3.boxplot.x_zones){let cx_min=d3.boxplot.x_zones[x_zone][0]/d3.boxplot.scale*d3.boxplot.x_len;x_min=d3.boxplot.get_human_readable_size(match[0]-cx_min,3,'&nbsp;');x_max=d3.boxplot.get_human_readable_size(match[1]-cx_min,3,'&nbsp;')}console.log('MATCH:');console.log(y_zone,y_min,y_max);console.log(x_zone,x_min,x_max);console.log(match[4]);return{x_zone:x_zone,y_zone:y_zone,x_match:[x_min,x_max],y_match:[y_min,y_max],idy:match[4]}}return null};
let match=null;let found=false;for(let i=3;i>=0;i--){let j=0;while(!found&&j<d3.boxplot.lines[i].length){let line=d3.boxplot.lines[i][j];let x_a=Math.min(line[0],line[1]);let x_b=Math.max(line[0],line[1]);let y_a=Math.min(line[2],line[3]);let y_b=Math.max(line[2],line[3]);if(x_a<=c_x&&c_x<=x_b&&y_a<=c_y&&c_y<=y_b){let m=(y_b-y_a)/(x_b-x_a);let p=y_a-m*x_a;let y_xmouse=m*c_x+p;if(y_xmouse-error_y<=c_y&&c_y<=y_xmouse+error_y){match=line;found=true}}j++}}if(match!==null){let y_zone=match[5];let x_zone=match[6];let y_min=null;let y_max=null;if(y_zone in d3.boxplot.y_zones){let cy_min=d3.boxplot.y_zones[y_zone][0]/d3.boxplot.scale*d3.boxplot.y_len;y_min=d3.boxplot.get_human_readable_size(match[2]-cy_min,3,'&nbsp;');y_max=d3.boxplot.get_human_readable_size(match[3]-cy_min,3,'&nbsp;')}let x_min=null;let x_max=null;if(x_zone in d3.boxplot.x_zones){let cx_min=d3.boxplot.x_zones[x_zone][0]/d3.boxplot.scale*d3.boxplot.x_len;x_min=d3.boxplot.get_human_readable_size(match[0]-cx_min,3,'&nbsp;');x_max=d3.boxplot.get_human_readable_size(match[1]-cx_min,3,'&nbsp;')}return{x_zone:x_zone,y_zone:y_zone,x_match:[x_min,x_max],y_match:[y_min,y_max],idy:match[4]}}return null};
if(!d3||!d3.boxplot){throw"d3.boxplot wasn't included!"}d3.boxplot.zoom={};d3.boxplot.zoom.help_timeout=null;/**
* Initialize zoom.init module
*/d3.boxplot.zoom.init=function(){d3.boxplot.svgcontainer.on("click",d3.boxplot.zoom.click);d3.select(".drawcontainer").on("mousedown",d3.boxplot.zoom.mousedown).on("mouseup",d3.boxplot.zoom.mouseup).on("mousemove",d3.boxplot.zoom.translate);d3.boxplot.svgcontainer.on("wheel",d3.boxplot.zoom.zoom)};/**
......@@ -324,7 +323,7 @@ if(!d3||!d3.boxplot){throw"d3.boxplot wasn't included!"}d3.boxplot.zoom={};d3.bo
*/d3.boxplot.zoom.mouseup=function(){d3.boxplot.translate_start=null;$("#help-trans").fadeOut("slow")};/**
* Translate event action
*/d3.boxplot.zoom.translate=function(){let rect=$("g.container")[0].getBoundingClientRect();let posX=d3.boxplot.posX,posY=d3.boxplot.posY,width_c=rect.width,height_c=rect.height;let cursor_x=(d3.event.pageX-posX)/width_c*d3.boxplot.scale,cursor_y=(d3.event.pageY-posY)/height_c*d3.boxplot.scale;if(d3.boxplot.translate_start!==null&&d3.event.ctrlKey){let old_transform=d3.boxplot.container.attr("transform");//let scale = 1;
let scale_x=1;let scale_y=1;if(old_transform){let scale=old_transform.match(/scale\(([-\d.]+)(,\s*([-\d.]+))?\)/);scale_x=scale[1];scale_y=scale[1];if(scale[3]!==undefined)scale_y=scale[3]}let translate=[d3.boxplot.old_translate[0]+(cursor_x-d3.boxplot.translate_start[0])*scale_x,d3.boxplot.old_translate[1]+(cursor_y-d3.boxplot.translate_start[1])*scale_y];let min_tr=[d3.boxplot.scale-0.2*d3.boxplot.scale,d3.boxplot.scale-0.2*d3.boxplot.scale];let max_tr=[-d3.boxplot.scale*scale_x+200,-d3.boxplot.scale*scale_x+200];if(translate[0]<max_tr[0]){translate[0]=max_tr[0]}else if(translate[0]>min_tr[0]){translate[0]=min_tr[0]}if(translate[1]<max_tr[1]){translate[1]=max_tr[1]}else if(translate[1]>min_tr[1]){translate[1]=min_tr[1]}let new_transform=`translate(${translate[0]}, ${translate[1]}) scale(${scale_x}, ${scale_y})`;d3.boxplot.container.attr("transform",new_transform);//Update axis:
let scale_x=1;let scale_y=1;if(old_transform){let scale=old_transform.match(/scale\(([-\d.]+)(,\s*([-\d.]+))?\)/);scale_x=scale[1];scale_y=scale[1];if(scale[3]!==undefined)scale_y=scale[3]}let translate=[d3.boxplot.old_translate[0]+(cursor_x-d3.boxplot.translate_start[0])*scale_x,d3.boxplot.old_translate[1]+(cursor_y-d3.boxplot.translate_start[1])*scale_y];let min_tr=[d3.boxplot.scale-0.2*d3.boxplot.scale,d3.boxplot.scale-0.2*d3.boxplot.scale];let max_tr=[-d3.boxplot.scale*scale_x+200,-d3.boxplot.scale*scale_x+200];if(translate[0]<max_tr[0]){translate[0]=max_tr[0]}else if(translate[0]>min_tr[0]){translate[0]=min_tr[0]}if(translate[1]<max_tr[1]){translate[1]=max_tr[1]}else if(translate[1]>min_tr[1]){translate[1]=min_tr[1]}let new_transform=`translate(${translate[0]}, ${translate[1]}) scale(${scale_x}, ${scale_y})`;d3.boxplot.container.attr("transform",new_transform);if(translate[0]!==0||translate[1]!==0){$("#restore-all").show()}else{$("#restore-all").hide()}//Update axis:
d3.boxplot.draw_top_axis();d3.boxplot.draw_right_axis();d3.boxplot.zoom_bottom_axis();d3.boxplot.zoom_left_axis()}else if(d3.boxplot.translate_start!==null){let help_trans=$("#help-trans");help_trans.fadeIn("slow")}};/**
* Get cursor position
*
......@@ -333,10 +332,9 @@ d3.boxplot.draw_top_axis();d3.boxplot.draw_right_axis();d3.boxplot.zoom_bottom_a
* @private
*/d3.boxplot.zoom._cursor_pos=function(rect=null){let event=d3.event;if(rect===null){rect=$("g.container")[0].getBoundingClientRect()}let posX=rect.left+window.scrollX,posY=rect.top+window.scrollY,width_c=rect.width,height_c=rect.height;let x=(event.pageX-posX)/width_c*d3.boxplot.scale,y=d3.boxplot.scale-(event.pageY-posY)/height_c*d3.boxplot.scale;return[x,y,rect]};/**
* Zoom staff
*/d3.boxplot.zoom.zoom=function(){if(d3.event.ctrlKey){d3.event.preventDefault();d3.boxplot.mousetip.hide();if(d3.boxplot.zoom_enabled){let cursor=d3.boxplot.zoom._cursor_pos();let zoom_f=1.2;let old_transform=d3.boxplot.container.attr("transform");if(old_transform!==null){let search_tr=old_transform.match(/translate\(([-\de.]+),\s*([-\de.]+)\)/);let search_sc=old_transform.match(/scale\(([-\de.]+)(,\s*[-\de.]+)?\)/);old_transform={"scale":parseFloat(search_sc[1]),"translate":[parseFloat(search_tr[1]),parseFloat(search_tr[2])]}}else{old_transform={"scale":1,"translate":[0,0]}}let new_scale;let new_rect=cursor[2];if(d3.event.deltaY<0){new_scale=old_transform["scale"]*zoom_f;new_rect["width"]*=zoom_f;new_rect["height"]*=zoom_f}else{new_scale=old_transform["scale"]/zoom_f;let scale_ratio=zoom_f;if(new_scale<1){new_scale=1;scale_ratio=old_transform["scale"]}new_rect["width"]/=scale_ratio;new_rect["height"]/=scale_ratio}new_rect["bottom"]=new_rect["y"]+new_rect["height"];new_rect["right"]=new_rect["x"]+new_rect["width"];let new_cursor=d3.boxplot.zoom._cursor_pos(new_rect);let x_trans=(new_cursor[0]-cursor[0])*new_scale;let y_trans=(new_cursor[1]-cursor[1])*new_scale;let new_transform=`translate(${old_transform["translate"][0]+x_trans},${old_transform["translate"][1]-y_trans})
scale(${new_scale})`;d3.boxplot.container.attr("transform",new_transform);d3.boxplot.zoom_scale_lines=new_scale;d3.boxplot.zoom._cursor_pos();//Correct lines stroke width to be not impacted by the zoom:
*/d3.boxplot.zoom.zoom=function(){if(d3.event.ctrlKey){d3.event.preventDefault();d3.boxplot.mousetip.hide();if(d3.boxplot.zoom_enabled){let cursor=d3.boxplot.zoom._cursor_pos();let zoom_f=1.2;let old_transform=d3.boxplot.container.attr("transform");if(old_transform!==null){let search_tr=old_transform.match(/translate\(([-\de.]+),\s*([-\de.]+)\)/);let search_sc=old_transform.match(/scale\(([-\de.]+)(,\s*[-\de.]+)?\)/);old_transform={"scale":parseFloat(search_sc[1]),"translate":[parseFloat(search_tr[1]),parseFloat(search_tr[2])]}}else{old_transform={"scale":1,"translate":[0,0]}}let new_scale;let new_rect=cursor[2];if(d3.event.deltaY<0){new_scale=old_transform["scale"]*zoom_f;new_rect["width"]*=zoom_f;new_rect["height"]*=zoom_f}else{new_scale=old_transform["scale"]/zoom_f;let scale_ratio=zoom_f;if(new_scale<1){new_scale=1;scale_ratio=old_transform["scale"]}new_rect["width"]/=scale_ratio;new_rect["height"]/=scale_ratio}new_rect["bottom"]=new_rect["y"]+new_rect["height"];new_rect["right"]=new_rect["x"]+new_rect["width"];let new_cursor=d3.boxplot.zoom._cursor_pos(new_rect);let x_trans=(new_cursor[0]-cursor[0])*new_scale;let y_trans=(new_cursor[1]-cursor[1])*new_scale;let translate_x=old_transform["translate"][0]+x_trans;let translate_y=old_transform["translate"][1]-y_trans;let new_transform=`translate(${translate_x},${translate_y}) scale(${new_scale})`;d3.boxplot.container.attr("transform",new_transform);d3.boxplot.zoom_scale_lines=new_scale;d3.boxplot.zoom._cursor_pos();//Correct lines stroke width to be not impacted by the zoom:
d3.selectAll("path.content-lines").attr("stroke-width",d3.boxplot.content_lines_width/new_scale);d3.selectAll("line.break-lines").attr("stroke-width",d3.boxplot.break_lines_width/new_scale);//Update axis:
d3.boxplot.draw_top_axis();d3.boxplot.draw_right_axis();d3.boxplot.zoom_bottom_axis();d3.boxplot.zoom_left_axis()}}else if(d3.boxplot.zoom_enabled){let help_zoom=$("#help-zoom");help_zoom.fadeIn("slow");if(d3.boxplot.zoom.help_timeout!==null){window.clearTimeout(d3.boxplot.zoom.help_timeout)}d3.boxplot.zoom.help_timeout=window.setTimeout(()=>{help_zoom.fadeOut("slow")},700)}};/**
d3.boxplot.draw_top_axis();d3.boxplot.draw_right_axis();d3.boxplot.zoom_bottom_axis();d3.boxplot.zoom_left_axis();if(translate_x<=0.00001&&translate_x>=-0.00001&&translate_y<=0.00001&&translate_y>=-0.00001&&new_scale===1){$("#restore-all").hide()}else{$("#restore-all").show()}}}else if(d3.boxplot.zoom_enabled){let help_zoom=$("#help-zoom");help_zoom.fadeIn("slow");if(d3.boxplot.zoom.help_timeout!==null){window.clearTimeout(d3.boxplot.zoom.help_timeout)}d3.boxplot.zoom.help_timeout=window.setTimeout(()=>{help_zoom.fadeOut("slow")},700)}};/**
* Restore previous scale
*
* @param transform: transform object
......
......@@ -576,7 +576,7 @@ dgenies.run.reset_errors = function() {
* Ask server to start uploads
*/
dgenies.run.ask_for_upload = function () {
console.log("Ask for upload...");
console.info("Ask for upload...");
dgenies.post("/ask-upload",
{
"s_id": dgenies.run.s_id
......
......@@ -119,7 +119,7 @@ return!has_errors};/**
* Remove all errors displayed
*/dgenies.run.reset_errors=function(){$("label").removeClass("error");$("div.errors-submit ul.flashes").find("li").remove()};/**
* Ask server to start uploads
*/dgenies.run.ask_for_upload=function(){console.log("Ask for upload...");dgenies.post("/ask-upload",{"s_id":dgenies.run.s_id},function(data,status){if(data["success"]){let allow_upload=data["allowed"];if(allow_upload){$("div#uploading-loading").html("Uploading files...");dgenies.run.ping_interval=window.setInterval(dgenies.run.ping_upload,15000);dgenies.run.upload_next()}else{window.setTimeout(dgenies.run.ask_for_upload,15000)}}else{dgenies.notify("message"in data?data["message"]:"An error has occurred. Please contact the support","danger",3000)}},undefined,false)};/**
*/dgenies.run.ask_for_upload=function(){console.info("Ask for upload...");dgenies.post("/ask-upload",{"s_id":dgenies.run.s_id},function(data,status){if(data["success"]){let allow_upload=data["allowed"];if(allow_upload){$("div#uploading-loading").html("Uploading files...");dgenies.run.ping_interval=window.setInterval(dgenies.run.ping_upload,15000);dgenies.run.upload_next()}else{window.setTimeout(dgenies.run.ask_for_upload,15000)}}else{dgenies.notify("message"in data?data["message"]:"An error has occurred. Please contact the support","danger",3000)}},undefined,false)};/**
* Ping server: we still upload or wait for upload
*/dgenies.run.ping_upload=function(){dgenies.post("/ping-upload",{"s_id":dgenies.run.s_id},function(data,status){})};/**
* Check if an URL is valid
......
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