Commit 9911b0e6 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Merge branch 'master' into multitools

parents ec33e669 af6e0e23
......@@ -94,4 +94,7 @@ max_concurrent_dl = 5
[example]
query =
target =
target =
[analytics]
enable_logging_runs = False
......@@ -388,3 +388,9 @@ class AppConfigReader:
return self.reader.get("example", "target")
except (NoOptionError, NoSectionError):
return ""
def _get_analytics_enabled(self):
try:
return self.reader.get("analytics", "enable_logging_runs").lower() == "true"
except (NoOptionError, NoSectionError):
return False
......@@ -125,7 +125,17 @@ if MODE == "webserver":
self.save()
if config.analytics_enabled:
class Analytics(BaseModel):
date_created = DateTimeField()
target_size = IntegerField()
query_size = IntegerField(null=True)
mail_client = CharField()
batch_type = CharField(max_length=20)
if not Analytics.table_exists():
Analytics.create_table()
if not Job.table_exists():
Job.create_table()
......
......@@ -926,6 +926,22 @@ class JobManager:
if MODE == "webserver" and self.config.send_mail_status:
self.send_mail_post()
def _save_analytics_data(self):
from dgenies.database import Analytics
with Job.connect():
job = Job.get(Job.id_job == self.id_job)
target_size = os.path.getsize(self.target.get_path())
query_size = None
if self.query is not None:
query_size = os.path.getsize(self.query.get_path())
log = Analytics.create(
date_created=datetime.now(),
target_size=target_size,
query_size=query_size,
mail_client=job.email,
batch_type=job.batch_type)
log.save()
def _after_start(self, success, error_set):
with Job.connect():
if success:
......@@ -934,6 +950,8 @@ class JobManager:
job = Job.get(Job.id_job == self.id_job)
job.status = status
job.save()
if self.config.analytics_enabled:
self._save_analytics_data()
else:
self.set_status_standalone("waiting")
self.prepare_data_in_thread()
......
......@@ -262,8 +262,6 @@ d3.boxplot.draw_left_axis = function (y_max, y_min = 0) {
.attr("preserveAspectRatio", "none");
let container_left = svg_left.append("g")
.attr("width", axis_length)
.attr("height", 20)
.attr("transform", "translate(0," + axis_length + ")rotate(-90)");
let y_size = y_max - y_min;
......@@ -491,8 +489,6 @@ d3.boxplot.draw_right_axis = function (y_zones=d3.boxplot.y_zones) {
.attr("preserveAspectRatio", "none");
let container_right = svg_right.append("g")
.attr("width", axis_length)
.attr("height", 20)
.attr("transform", "translate(20)rotate(90)");
container_right.append("text")
......
......@@ -4,8 +4,8 @@ if (!dgenies || !dgenies.result) {
dgenies.result.export = {};
dgenies.result.export.get_svg = function () {
return "<svg width='5000px' height='5000px' viewBox='0 0 100 100'>" + $("#draw-in").find(">svg").html() + "</svg>";
dgenies.result.export.get_svg = function (width="5000px") {
return `<svg version='1.1' xmlns='http://www.w3.org/2000/svg' width='${width}' height='${width}' viewBox='0 0 100 100'>${$("#draw-in").find(">svg").html()}</svg>`;
};
dgenies.result.export.save_file = function(blob, format) {
......@@ -32,7 +32,10 @@ dgenies.result.export.export_svg = function () {
window.setTimeout(() => {
let transform = d3.boxplot.container.attr("transform");
let after = function () {
let blob = new Blob([dgenies.result.export.get_svg()], {type: "image/svg+xml"});
let svg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" " +
"\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">";
svg += dgenies.result.export.get_svg("1000px");
let blob = new Blob([svg], {type: "image/svg+xml"});
d3.boxplot.zoom.restore_scale(transform);
dgenies.result.export.save_file(blob, "svg");
};
......
if(!dgenies){throw"dgenies wasn't included!"}dgenies.result={};// GLOBAL VARIABLES:
dgenies.result.id_res=null;dgenies.result.init=function(id_res){dgenies.result.id_res=id_res;dgenies.result.add_to_list();d3.boxplot.init()};dgenies.result.add_to_list=function(){let cookies=$.cookie("results");cookies=cookies!==undefined?cookies.split("|"):[];if(cookies.indexOf(dgenies.result.id_res)===-1){cookies.splice(0,0,dgenies.result.id_res);dgenies.save_cookies(cookies);dgenies.update_results(cookies)}};dgenies.result.remove_job_from_cookie=function(job){let cookies=$.cookie("results");cookies=cookies!==undefined?cookies.split("|"):[];let index=cookies.indexOf(job);let need_update=false;if(index>-1){need_update=true;cookies.splice(index,1)}$.cookie("results",cookies.join("|"),{path:"/"});if(need_update){dgenies.update_results(cookies)}};
if(!dgenies||!dgenies.result){throw"dgenies.result wasn't included!"}dgenies.result.controls={};dgenies.result.controls.init=function(){$("#sort-contigs").click(dgenies.result.controls.launch_sort_contigs);$("#hide-noise").click(dgenies.result.controls.launch_hide_noise);$("#summary").click(dgenies.result.controls.summary);$("#delete-job").click(dgenies.result.controls.delete_job);$("form#select-zone input.submit").click(dgenies.result.controls.select_zone);$("form#export select").change(dgenies.result.export.export)};dgenies.result.controls.summary=function(){dgenies.show_loading("Building...");window.setTimeout(()=>{dgenies.post(`/summary/${dgenies.result.id_res}`,{},function(data){dgenies.hide_loading();if(data["success"]){if(data["status"]==="done"){dgenies.result.summary.show(data["percents"])}else if(data["status"]==="waiting"){dgenies.result.controls.summary()}}else{dgenies.notify(data["message"]||"An error occurred! Please contact us to report the bug","danger")}})},0)};dgenies.result.controls.launch_sort_contigs=function(){d3.boxplot.zoom.reset_scale();window.setTimeout(()=>{dgenies.show_loading("Building...");window.setTimeout(()=>{dgenies.post(`/sort/${dgenies.result.id_res}`,{},function(data){if(data["success"]){dgenies.reset_loading_message();window.setTimeout(()=>{d3.boxplot.launch(data,true)},0)}else{dgenies.hide_loading();dgenies.notify(data["message"]||"An error occurred! Please contact us to report the bug","danger")}})},0)},0)};dgenies.result.controls.launch_reverse_contig=function(){if(d3.boxplot.query_selected!==null){d3.boxplot.zoom.reset_scale();window.setTimeout(()=>{dgenies.show_loading("Building...");window.setTimeout(()=>{dgenies.post(`/reverse-contig/${dgenies.result.id_res}`,{"contig":d3.boxplot.query_selected},function(data){if(data["success"]){dgenies.reset_loading_message();window.setTimeout(()=>{d3.boxplot.launch(data,true)},0)}else{dgenies.hide_loading();dgenies.notify(data["message"]||"An error occurred! Please contact us to report the bug","danger")}})},0)},0)}else{dgenies.notify("Error: no query selected. Please contact us to report the bug","danger")}};dgenies.result.controls.launch_hide_noise=function(){d3.boxplot.zoom.reset_scale();window.setTimeout(()=>{dgenies.show_loading("Building...");window.setTimeout(()=>{dgenies.post(`/freenoise/${dgenies.result.id_res}`,{noise:dgenies.noise?0:1},function(data){if(data["success"]){dgenies.noise=!dgenies.noise;dgenies.reset_loading_message();window.setTimeout(()=>{d3.boxplot.launch(data,true,true)},0)}else{dgenies.hide_loading();dgenies.notify(data["message"]||"An error occurred! Please contact us to report the bug","danger")}})},0)},0)};dgenies.result.controls.select_zone=function(){let contig_select=$("#select-contig").find(":selected");let target_select=$("#select-target").find(":selected");if(contig_select.val()!=="###NONE###"&&target_select.val()!=="###NONE###"){d3.boxplot.select_zone(null,null,target_select.val(),contig_select.val(),true)}else{dgenies.notify("Please select zones into zoom!","danger",2000)}};dgenies.result.controls.do_delete_job=function(){dgenies.post(`/delete/${dgenies.result.id_res}`,{},function(data){if(data["success"]){dgenies.notify("Your job has been deleted!","success",1500);window.setTimeout(()=>{dgenies.result.remove_job_from_cookie(dgenies.result.id_res);window.location="/"},1500)}else{dgenies.notify("error"in data?data["error"]:"An error has occurred. Please contact the support","danger")}})};dgenies.result.controls.delete_job=function(){let dialog=$("<div>").attr("id","dialog-confirm").attr("title","Delete job?");let icon=$("<span>").attr("class","ui-icon ui-icon-help").css("float","left").css("margin","12px 12px 20px 0");let body=$("<p>");body.append(icon);body.append("Confirm deletion of this job? This operation is definitive.");dialog.append(body);dialog.dialog({resizable:false,height:"auto",width:500,modal:true,buttons:{"Yes":function(){$(this).dialog("close");dgenies.result.controls.do_delete_job()},"No":function(){$(this).dialog("close")}}})};
if(!dgenies||!dgenies.result){throw"dgenies.result wasn't included!"}dgenies.result.export={};dgenies.result.export.get_svg=function(){return"<svg width='5000px' height='5000px' viewBox='0 0 100 100'>"+$("#draw-in").find(">svg").html()+"</svg>"};dgenies.result.export.save_file=function(blob,format){dgenies.hide_loading();saveAs(blob,`map_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.${format}`)};dgenies.result.export.export_png=function(){dgenies.show_loading("Building picture...",210);window.setTimeout(()=>{let export_div=$("div#export-pict");export_div.html("").append($("<canvas>"));canvg(export_div.find("canvas")[0],dgenies.result.export.get_svg());let canvas=export_div.find("canvas")[0];canvas.toBlob(function(blob){dgenies.result.export.save_file(blob,"png");export_div.html("")},"image/png")},0)};dgenies.result.export.export_svg=function(){dgenies.show_loading("Building picture...",180);window.setTimeout(()=>{let transform=d3.boxplot.container.attr("transform");let after=function(){let blob=new Blob([dgenies.result.export.get_svg()],{type:"image/svg+xml"});d3.boxplot.zoom.restore_scale(transform);dgenies.result.export.save_file(blob,"svg")};d3.boxplot.zoom.reset_scale(true,after)},0)};dgenies.result.export.export_paf=function(){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/paf/${dgenies.result.id_res}`).attr("download",`map_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.paf`).attr("id","my-download").text("download"));dgenies.hide_loading();document.getElementById("my-download").click()};dgenies.result.export.dl_fasta=function(gzip=false){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/fasta-query/${dgenies.result.id_res}`).attr("download",d3.boxplot.name_y+(gzip?".fasta.gz":".fasta")).attr("id","my-download").text("download"));dgenies.hide_loading();document.getElementById("my-download").click()};dgenies.result.export.export_fasta=function(compress=false){dgenies.show_loading("Building file...",180);dgenies.post("/get-fasta-query/"+dgenies.result.id_res,{gzip:compress},function(data,success){if(data["status"]===0){window.setTimeout(()=>{dgenies.result.export.export_fasta()},10000)}else if(data["status"]===2){dgenies.result.export.dl_fasta(data["gzip"])}else if(data["status"]===1){dgenies.hide_loading();dgenies.notify("We are building your Fasta file. You will receive by mail a link to download it soon!","info")}else{dgenies.hide_loading();dgenies.notify("An error has occurred. Please contact us to report the bug","danger")}})};dgenies.result.export.ask_export_fasta=function(){if(dgenies.mode==="webserver"){let dialog=$("<div>").attr("id","dialog-confirm").attr("title","Gzip?");let icon=$("<span>").attr("class","ui-icon ui-icon-help").css("float","left").css("margin","12px 12px 20px 0");let body=$("<p>");body.append(icon);body.append("Compression is recommanded on slow connections. Download Gzip file?");dialog.append(body);dialog.dialog({resizable:false,height:"auto",width:500,modal:true,buttons:{"Use default":function(){$(this).dialog("close");dgenies.result.export.export_fasta(false)},"Use Gzip":function(){$(this).dialog("close");dgenies.result.export.export_fasta(true)},Cancel:function(){$(this).dialog("close")}}})}else{dgenies.result.export.export_fasta(false)}};dgenies.result.export.export_association_table=function(){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/qt-assoc/${dgenies.result.id_res}`).attr("download",d3.boxplot.name_y+"_"+d3.boxplot.name_x+"_assoc.tsv").attr("id","my-download").text("download"));dgenies.hide_loading();document.getElementById("my-download").click()};dgenies.result.export.export_no_association_file=function(to){window.setTimeout(()=>{dgenies.show_loading("Building file...",180);let on=to==="query"?"target":"query";dgenies.post("/no-assoc/"+dgenies.result.id_res,{"to":to},function(data,success){dgenies.hide_loading();if(!data["empty"]){let blob=new Blob([data["file_content"]],{type:"text/plain"});saveAs(blob,`no_${to}_matches_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.txt`)}else{dgenies.notify(`No contigs in ${to} have None match with any ${on}!`,"success")}})},0)};dgenies.result.export.export_query_as_reference_fasta_webserver=function(){dgenies.post(`/build-query-as-reference/${dgenies.result.id_res}`,{},function(data,success){if(data["success"]){dgenies.notify("You will receive a mail soon with the link to download your Fasta file","success")}else{dgenies.notify(`An error has occurred. Please contact the support`,"danger")}})};dgenies.result.export.export_query_as_reference_fasta_standalone=function(){dgenies.show_loading("Building file...",180);window.setTimeout(()=>{dgenies.post(`/build-query-as-reference/${dgenies.result.id_res}`,{},function(data,success){if(data["success"]){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/get-query-as-reference/${dgenies.result.id_res}`).attr("download",`as_reference_${d3.boxplot.name_y}.fasta`).attr("id","my-download").text("download"));document.getElementById("my-download").click();dgenies.hide_loading()}else{dgenies.notify(`An error has occurred. Please contact the support`,"danger")}})},0)};dgenies.result.export.export=function(){let select=$("form#export select");let selection=parseInt(select.val());window.setTimeout(()=>{if(selection>0){let async=false;if(selection===1){dgenies.result.export.export_svg();async=true}else if(selection===2){dgenies.result.export.export_png();async=true}else if(selection===3)dgenies.result.export.export_paf();else if(selection===4){dgenies.result.export.ask_export_fasta();async=true}else if(selection===5){dgenies.result.export.export_association_table()}else if(selection===6){dgenies.result.export.export_no_association_file("query");async=true}else if(selection===7){dgenies.result.export.export_no_association_file("target");async=true}else if(selection===8){if(dgenies.mode==="webserver"){dgenies.result.export.export_query_as_reference_fasta_webserver()}else{dgenies.result.export.export_query_as_reference_fasta_standalone();async=true}}else dgenies.notify("Not supported yet!","danger",2000);if(!async)dgenies.hide_loading();select.val("0")}},0)};
if(!dgenies||!dgenies.result){throw"dgenies.result wasn't included!"}dgenies.result.export={};dgenies.result.export.get_svg=function(){return"<svg width='5000px' height='5000px' viewBox='0 0 100 100'>"+$("#draw-in").find(">svg").html()+"</svg>"};dgenies.result.export.save_file=function(blob,format){dgenies.hide_loading();saveAs(blob,`map_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.${format}`)};dgenies.result.export.export_png=function(){dgenies.show_loading("Building picture...",210);window.setTimeout(()=>{let export_div=$("div#export-pict");export_div.html("").append($("<canvas>"));canvg(export_div.find("canvas")[0],dgenies.result.export.get_svg());let canvas=export_div.find("canvas")[0];canvas.toBlob(function(blob){dgenies.result.export.save_file(blob,"png");export_div.html("")},"image/png")},0)};dgenies.result.export.export_svg=function(){dgenies.show_loading("Building picture...",180);window.setTimeout(()=>{let transform=d3.boxplot.container.attr("transform");let after=function(){let svg="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "+"\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">";svg+=dgenies.result.export.get_svg();let blob=new Blob([svg],{type:"image/svg+xml"});d3.boxplot.zoom.restore_scale(transform);dgenies.result.export.save_file(blob,"svg")};d3.boxplot.zoom.reset_scale(true,after)},0)};dgenies.result.export.export_paf=function(){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/paf/${dgenies.result.id_res}`).attr("download",`map_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.paf`).attr("id","my-download").text("download"));dgenies.hide_loading();document.getElementById("my-download").click()};dgenies.result.export.dl_fasta=function(gzip=false){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/fasta-query/${dgenies.result.id_res}`).attr("download",d3.boxplot.name_y+(gzip?".fasta.gz":".fasta")).attr("id","my-download").text("download"));dgenies.hide_loading();document.getElementById("my-download").click()};dgenies.result.export.export_fasta=function(compress=false){dgenies.show_loading("Building file...",180);dgenies.post("/get-fasta-query/"+dgenies.result.id_res,{gzip:compress},function(data,success){if(data["status"]===0){window.setTimeout(()=>{dgenies.result.export.export_fasta()},10000)}else if(data["status"]===2){dgenies.result.export.dl_fasta(data["gzip"])}else if(data["status"]===1){dgenies.hide_loading();dgenies.notify("We are building your Fasta file. You will receive by mail a link to download it soon!","info")}else{dgenies.hide_loading();dgenies.notify("An error has occurred. Please contact us to report the bug","danger")}})};dgenies.result.export.ask_export_fasta=function(){if(dgenies.mode==="webserver"){let dialog=$("<div>").attr("id","dialog-confirm").attr("title","Gzip?");let icon=$("<span>").attr("class","ui-icon ui-icon-help").css("float","left").css("margin","12px 12px 20px 0");let body=$("<p>");body.append(icon);body.append("Compression is recommanded on slow connections. Download Gzip file?");dialog.append(body);dialog.dialog({resizable:false,height:"auto",width:500,modal:true,buttons:{"Use default":function(){$(this).dialog("close");dgenies.result.export.export_fasta(false)},"Use Gzip":function(){$(this).dialog("close");dgenies.result.export.export_fasta(true)},Cancel:function(){$(this).dialog("close")}}})}else{dgenies.result.export.export_fasta(false)}};dgenies.result.export.export_association_table=function(){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/qt-assoc/${dgenies.result.id_res}`).attr("download",d3.boxplot.name_y+"_"+d3.boxplot.name_x+"_assoc.tsv").attr("id","my-download").text("download"));dgenies.hide_loading();document.getElementById("my-download").click()};dgenies.result.export.export_no_association_file=function(to){window.setTimeout(()=>{dgenies.show_loading("Building file...",180);let on=to==="query"?"target":"query";dgenies.post("/no-assoc/"+dgenies.result.id_res,{"to":to},function(data,success){dgenies.hide_loading();if(!data["empty"]){let blob=new Blob([data["file_content"]],{type:"text/plain"});saveAs(blob,`no_${to}_matches_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.txt`)}else{dgenies.notify(`No contigs in ${to} have None match with any ${on}!`,"success")}})},0)};dgenies.result.export.export_query_as_reference_fasta_webserver=function(){dgenies.post(`/build-query-as-reference/${dgenies.result.id_res}`,{},function(data,success){if(data["success"]){dgenies.notify("You will receive a mail soon with the link to download your Fasta file","success")}else{dgenies.notify(`An error has occurred. Please contact the support`,"danger")}})};dgenies.result.export.export_query_as_reference_fasta_standalone=function(){dgenies.show_loading("Building file...",180);window.setTimeout(()=>{dgenies.post(`/build-query-as-reference/${dgenies.result.id_res}`,{},function(data,success){if(data["success"]){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/get-query-as-reference/${dgenies.result.id_res}`).attr("download",`as_reference_${d3.boxplot.name_y}.fasta`).attr("id","my-download").text("download"));document.getElementById("my-download").click();dgenies.hide_loading()}else{dgenies.notify(`An error has occurred. Please contact the support`,"danger")}})},0)};dgenies.result.export.export=function(){let select=$("form#export select");let selection=parseInt(select.val());window.setTimeout(()=>{if(selection>0){let async=false;if(selection===1){dgenies.result.export.export_svg();async=true}else if(selection===2){dgenies.result.export.export_png();async=true}else if(selection===3)dgenies.result.export.export_paf();else if(selection===4){dgenies.result.export.ask_export_fasta();async=true}else if(selection===5){dgenies.result.export.export_association_table()}else if(selection===6){dgenies.result.export.export_no_association_file("query");async=true}else if(selection===7){dgenies.result.export.export_no_association_file("target");async=true}else if(selection===8){if(dgenies.mode==="webserver"){dgenies.result.export.export_query_as_reference_fasta_webserver()}else{dgenies.result.export.export_query_as_reference_fasta_standalone();async=true}}else dgenies.notify("Not supported yet!","danger",2000);if(!async)dgenies.hide_loading();select.val("0")}},0)};
if(!dgenies||!dgenies.result){throw"dgenies.result wasn't included!"}dgenies.result.summary={};dgenies.result.summary.percents={};dgenies.result.summary.show=function(percents){dgenies.result.summary.percents=percents;let svgcontainer=d3.select("#draw-stats").html("").append("svg:svg").attr("width","500px").attr("height","220px");let container=svgcontainer.append("svg:g");let percents_order=["-1","0","1","2","3"];let x=0;let percent_value=0;for(let i in percents_order){let percent=percents_order[i];let label=dgenies.result.summary._get_label(percent);x+=percent_value;percent_value=percent in percents?percents[percent]:0;container.append("rect").attr("x",x+"%").attr("y",0).attr("width",percent_value+"%").attr("height","50px").attr("stroke","none").attr("fill",d3.boxplot.color_idy[d3.boxplot.color_idy_theme][percent]);container.append("rect").attr("x",5).attr("y",70+i*30).attr("width","10px").attr("height","10px").attr("fill",d3.boxplot.color_idy[d3.boxplot.color_idy_theme][percent]).style("stroke","#000").style("stroke-width","1px");container.append("text").attr("x",30).attr("y",82+i*30).attr("font-family","sans-serif").attr("font-size","12pt").text(label+":");container.append("text").attr("x",110).attr("y",82+i*30).attr("font-family","sans-serif").attr("font-size","12pt").text(percent_value.toFixed(2)+" %")}container.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","50px").style("stroke","#000").style("fill","none").style("stroke-width","1px");$("#modal-stats").dialog({title:"Summary of identity",width:"560px",buttons:[{text:"Export TSV",click:dgenies.result.summary.export_tsv},{text:"Export PNG",click:dgenies.result.summary.export_png},{text:"Export SVG",click:dgenies.result.summary.export_svg},{text:"Close",click:function(){$(this).dialog("close")},default:true}],open:function(){$(this).parents().find(".ui-dialog-buttonpane button")[3].focus()}})};dgenies.result.summary._get_label=function(percent_class){switch(percent_class){case"-1":return"No match";case"0":return"< 25 %";case"1":return"< 50 %";case"2":return"< 75 %";case"3":return"> 75 %";}};dgenies.result.summary.get_svg=function(){return $("#draw-stats").html()};dgenies.result.summary.save_file=function(blob,format){saveAs(blob,`summary_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.${format}`)};dgenies.result.summary.export_tsv=function(){let content="category\tpercent\n";for(let percent in dgenies.result.summary.percents){content+=`${dgenies.result.summary._get_label(percent)}\t${dgenies.result.summary.percents[percent]}\n`}dgenies.result.summary.save_file(new Blob([content],{type:"plain/text"}),"tsv")};dgenies.result.summary.export_svg=function(){let blob=new Blob([dgenies.result.summary.get_svg()],{type:"image/svg+xml"});dgenies.result.summary.save_file(blob,"svg")};dgenies.result.summary.export_png=function(){let export_div=$("div#export-pict");export_div.html("").append($("<canvas>"));canvg(export_div.find("canvas")[0],dgenies.result.summary.get_svg());let canvas=export_div.find("canvas")[0];canvas.toBlob(function(blob){dgenies.result.summary.save_file(blob,"png");export_div.html("")},"image/png")};
if(!d3){throw"d3 wasn't included!"}d3.boxplot={};//GLOBAL VARIABLES:
d3.boxplot.svgcontainer=null;d3.boxplot.container=null;d3.boxplot.svgsupercontainer=null;d3.boxplot.name_x=null;d3.boxplot.name_y=null;d3.boxplot.lines=null;d3.boxplot.x_len=null;d3.boxplot.y_len=null;d3.boxplot.x_zones=null;d3.boxplot.y_zones=null;d3.boxplot.zoom_enabled=true;d3.boxplot.all_disabled=false;d3.boxplot.min_idy=0;d3.boxplot.max_idy=0;d3.boxplot.zone_selected=false;d3.boxplot.query_selected=null;//For translations:
......@@ -41,12 +41,12 @@ d3.boxplot.container.attr("transform","scale("+scale_x+","+scale_y+")"+"translat
d3.selectAll(".content-lines").attr("stroke-width",d3.boxplot.content_lines_width/Math.min(scale_x,scale_y));d3.boxplot.zoom_scale_lines=Math.min(scale_x,scale_y);d3.selectAll("line.break-lines").style("visibility","hidden");//Update left and bottom axis:
let y_max=d3.boxplot.y_zones[y_zone][1]/d3.boxplot.scale*d3.boxplot.y_len;let y_min=d3.boxplot.y_zones[y_zone][0]/d3.boxplot.scale*d3.boxplot.y_len;d3.boxplot.draw_left_axis(y_max-y_min,0);let x_max=d3.boxplot.x_zones[x_zone][1]/d3.boxplot.scale*d3.boxplot.x_len;let x_min=d3.boxplot.x_zones[x_zone][0]/d3.boxplot.scale*d3.boxplot.x_len;d3.boxplot.draw_bottom_axis(x_max-x_min,0);//Update top and right axis:
let pseudo_x_zones={};pseudo_x_zones[x_zone]=[0,d3.boxplot.x_len];d3.boxplot.draw_top_axis(pseudo_x_zones);let pseudo_y_zones={};pseudo_y_zones[y_zone]=[0,d3.boxplot.y_len];d3.boxplot.draw_right_axis(pseudo_y_zones);d3.boxplot.zoom_enabled=false}$("#restore-all").show();dgenies.hide_loading()},0)};d3.boxplot.draw_left_axis=function(y_max,y_min=0){let axis_length=500;$("svg.left-axis").remove();//Remove previous axis (if any)
let svg_left=d3.boxplot.svgsupercontainer.append("svg:svg").attr("class","axis left-axis").attr("width",5).attr("height",90).attr("x",0).attr("y",5).attr("viewBox","0 0 20 "+axis_length).attr("preserveAspectRatio","none");let container_left=svg_left.append("g").attr("width",axis_length).attr("height",20).attr("transform","translate(0,"+axis_length+")rotate(-90)");let y_size=y_max-y_min;for(let i=1;i<10;i++){let y=axis_length/10*i;let y_t=y_min+y_size/10*i;if(y_t>=0&&y_t<=d3.boxplot.y_len){let y_lab="";if(y_t>1000000){y_lab=(Math.round(y_t/100000)/10).toString()+" M"}else if(y_t>1000){y_lab=(Math.round(y_t/100)/10).toString()+" K"}else{y_lab=Math.round(y_t).toString()}container_left.append("line").attr("x1",y).attr("y1",15).attr("x2",y).attr("y2",20).attr("stroke-width",d3.boxplot.tick_width).attr("stroke","black");container_left.append("text").attr("x",y).attr("y",12).attr("text-anchor","middle").attr("font-family","sans-serif").attr("font-size","6.5pt").text(y_lab)}}};d3.boxplot.draw_bottom_axis=function(x_max,x_min=0){let axis_length=500;$("svg.bottom-axis").remove();//Remove previous axis (if any)
let svg_left=d3.boxplot.svgsupercontainer.append("svg:svg").attr("class","axis left-axis").attr("width",5).attr("height",90).attr("x",0).attr("y",5).attr("viewBox","0 0 20 "+axis_length).attr("preserveAspectRatio","none");let container_left=svg_left.append("g").attr("transform","translate(0,"+axis_length+")rotate(-90)");let y_size=y_max-y_min;for(let i=1;i<10;i++){let y=axis_length/10*i;let y_t=y_min+y_size/10*i;if(y_t>=0&&y_t<=d3.boxplot.y_len){let y_lab="";if(y_t>1000000){y_lab=(Math.round(y_t/100000)/10).toString()+" M"}else if(y_t>1000){y_lab=(Math.round(y_t/100)/10).toString()+" K"}else{y_lab=Math.round(y_t).toString()}container_left.append("line").attr("x1",y).attr("y1",15).attr("x2",y).attr("y2",20).attr("stroke-width",d3.boxplot.tick_width).attr("stroke","black");container_left.append("text").attr("x",y).attr("y",12).attr("text-anchor","middle").attr("font-family","sans-serif").attr("font-size","6.5pt").text(y_lab)}}};d3.boxplot.draw_bottom_axis=function(x_max,x_min=0){let axis_length=500;$("svg.bottom-axis").remove();//Remove previous axis (if any)
let svg_bottom=d3.boxplot.svgsupercontainer.append("svg:svg").attr("class","axis bottom-axis").attr("width",90).attr("height",5).attr("x",5).attr("y",95).attr("viewBox","0 0 "+axis_length+" 20").attr("preserveAspectRatio","none");let x_size=x_max-x_min;for(let i=1;i<10;i++){let x=axis_length/10*i;let x_t=x_min+x_size/10*i;if(x_t>=0&&x_t<=d3.boxplot.x_len){let x_lab="";if(x_t>=1000000){x_lab=(Math.round(x_t/100000)/10).toString()+" M"}else if(x_t>=1000){x_lab=(Math.round(x_t/100)/10).toString()+" K"}else{x_lab=Math.round(x_t).toString()}svg_bottom.append("line").attr("x1",x).attr("y1",0).attr("x2",x).attr("y2",5).attr("stroke-width",d3.boxplot.tick_width).attr("stroke","black");svg_bottom.append("text").attr("x",x).attr("y",15).attr("text-anchor","middle").attr("font-family","sans-serif").attr("font-size","6.5pt").text(x_lab)}}};d3.boxplot.zoom_left_axis=function(){let transform=d3.boxplot.container.attr("transform");if(transform===null){transform="translate(0,0)scale(1)"}let tr_regex=/translate\(([^,]+),([^)]+)\)/;let translate=parseFloat(transform.match(tr_regex)[2]);let sc_regex=/scale\(([^,)]+)(,([^)]+))?\)/;let scale=parseFloat(transform.match(sc_regex)[3]!==undefined?transform.match(sc_regex)[3]:transform.match(sc_regex)[1]);let max_y=d3.boxplot.y_len+translate/d3.boxplot.scale*d3.boxplot.y_len/scale;let min_y=max_y-d3.boxplot.y_len/scale;d3.boxplot.draw_left_axis(max_y,min_y)};d3.boxplot.zoom_bottom_axis=function(){let transform=d3.boxplot.container.attr("transform");if(transform===null){transform="translate(0,0)scale(1)"}let tr_regex=/translate\(([^,]+),([^)]+)\)/;let translate=parseFloat(transform.match(tr_regex)[1]);let sc_regex=/scale\(([^,)]+)(,([^)]+))?\)/;let scale=parseFloat(transform.match(sc_regex)[1]);let min_x=-translate/d3.boxplot.scale*d3.boxplot.x_len/scale;let max_x=(d3.boxplot.x_len-translate/d3.boxplot.scale*d3.boxplot.x_len)/scale;d3.boxplot.draw_bottom_axis(max_x,min_x)};d3.boxplot.draw_top_axis=function(x_zones=d3.boxplot.x_zones){$("svg.top-axis").remove();//Remove previous axis (if any)
let transform=d3.boxplot.container.attr("transform");if(transform===null){transform="translate(0,0)scale(1)"}let tr_regex=/translate\(([^,]+),([^)]+)\)/;let translate=parseFloat(transform.match(tr_regex)[1]);let sc_regex=/scale\(([^,)]+)(,([^)]+))?\)/;let scale=parseFloat(transform.match(sc_regex)[1]);let axis_length=500;let svg_top=d3.boxplot.svgsupercontainer.append("svg:svg").attr("class","top-axis axis").attr("width",90).attr("height",5).attr("x",5).attr("y",0).attr("viewBox","0 0 "+axis_length+" 20").attr("preserveAspectRatio","none");svg_top.append("text").attr("x",axis_length/2).attr("y",7.5).attr("font-size","6pt").attr("font-family","sans-serif").attr("font-style","italic").attr("text-anchor","middle").text(d3.boxplot.name_x);let nb_zone=0;for(let zone in x_zones){let x_pos_1=Math.min(Math.max(x_zones[zone][0]*scale+translate,0),d3.boxplot.scale);let x_pos_2=Math.min(Math.max(x_zones[zone][1]*scale+translate,0),d3.boxplot.scale);let z_len=x_pos_2/d3.boxplot.scale*axis_length-x_pos_1/d3.boxplot.scale*axis_length;if(!zone.startsWith("###MIX###")){//z_middle = (x_zones[zone][1] + x_zones[zone][0]) / 2
let text_container=svg_top.append("svg:svg").attr("x",x_pos_1/d3.boxplot.scale*axis_length).attr("y",0).attr("width",z_len).attr("height","100%");let text=text_container.append("text").attr("x",z_len/2).attr("y",17).attr("text-anchor","middle").attr("font-family","sans-serif").attr("font-size","6pt").text(zone);let zone_txt=zone;let i=4;while(text.node().getComputedTextLength()>z_len&&zone_txt.length>=5){text.remove();zone_txt=zone.slice(0,-i)+"...";text=text_container.append("text").attr("x",z_len/2).attr("y",17).attr("text-anchor","middle").attr("font-family","sans-serif").attr("font-size","6pt").text(zone_txt);i++}if(text.node().getComputedTextLength()>z_len){text.remove()}}if(zone.startsWith("###MIX###")){svg_top.append("rect").attr("x",x_pos_1/d3.boxplot.scale*axis_length).attr("y",12).attr("width",z_len).attr("height",8).attr("fill",d3.boxplot.color_mixes).attr("stroke",d3.boxplot.color_mixes)}else if(nb_zone>0){//Draw zone separator at left of zone (except for first zone)
svg_top.append("line").attr("x1",x_pos_1/d3.boxplot.scale*axis_length).attr("x2",x_pos_1/d3.boxplot.scale*axis_length).attr("y1",12).attr("y2",20).attr("stroke","black").attr("stroke-width",d3.boxplot.tick_width)}nb_zone++}};d3.boxplot.draw_right_axis=function(y_zones=d3.boxplot.y_zones){$("svg.right-axis").remove();//Remove previous axis (if any)
let transform=d3.boxplot.container.attr("transform");if(transform===null){transform="translate(0,0)scale(1)"}let tr_regex=/translate\(([^,]+),([^)]+)\)/;let translate=parseFloat(transform.match(tr_regex)[2]);let sc_regex=/scale\(([^,)]+)(,([^)]+))?\)/;let scale=parseFloat(transform.match(sc_regex)[3]!==undefined?transform.match(sc_regex)[3]:transform.match(sc_regex)[1]);let axis_length=500;let svg_right=d3.boxplot.svgsupercontainer.append("svg:svg").attr("class","right-axis").attr("width",5).attr("height",90).attr("x",95).attr("y",5).attr("viewBox","0 0 20 "+axis_length).attr("preserveAspectRatio","none");let container_right=svg_right.append("g").attr("width",axis_length).attr("height",20).attr("transform","translate(20)rotate(90)");container_right.append("text").attr("x",axis_length/2).attr("y",7.5).attr("font-size","6pt").attr("font-family","sans-serif").attr("font-style","italic").attr("text-anchor","middle").text(d3.boxplot.name_y);let nb_zone=Object.keys(y_zones).length-1;for(let zone in y_zones){let y_pos_2=Math.min(Math.max((d3.boxplot.scale-y_zones[zone][0])*scale+translate,0),d3.boxplot.scale);let y_pos_1=Math.min(Math.max((d3.boxplot.scale-y_zones[zone][1])*scale+translate,0),d3.boxplot.scale);let z_len=y_pos_2/d3.boxplot.scale*axis_length-y_pos_1/d3.boxplot.scale*axis_length;if(!zone.startsWith("###MIX###")){//z_middle = (x_zones[zone][1] + x_zones[zone][0]) / 2
let transform=d3.boxplot.container.attr("transform");if(transform===null){transform="translate(0,0)scale(1)"}let tr_regex=/translate\(([^,]+),([^)]+)\)/;let translate=parseFloat(transform.match(tr_regex)[2]);let sc_regex=/scale\(([^,)]+)(,([^)]+))?\)/;let scale=parseFloat(transform.match(sc_regex)[3]!==undefined?transform.match(sc_regex)[3]:transform.match(sc_regex)[1]);let axis_length=500;let svg_right=d3.boxplot.svgsupercontainer.append("svg:svg").attr("class","right-axis").attr("width",5).attr("height",90).attr("x",95).attr("y",5).attr("viewBox","0 0 20 "+axis_length).attr("preserveAspectRatio","none");let container_right=svg_right.append("g").attr("transform","translate(20)rotate(90)");container_right.append("text").attr("x",axis_length/2).attr("y",7.5).attr("font-size","6pt").attr("font-family","sans-serif").attr("font-style","italic").attr("text-anchor","middle").text(d3.boxplot.name_y);let nb_zone=Object.keys(y_zones).length-1;for(let zone in y_zones){let y_pos_2=Math.min(Math.max((d3.boxplot.scale-y_zones[zone][0])*scale+translate,0),d3.boxplot.scale);let y_pos_1=Math.min(Math.max((d3.boxplot.scale-y_zones[zone][1])*scale+translate,0),d3.boxplot.scale);let z_len=y_pos_2/d3.boxplot.scale*axis_length-y_pos_1/d3.boxplot.scale*axis_length;if(!zone.startsWith("###MIX###")){//z_middle = (x_zones[zone][1] + x_zones[zone][0]) / 2
let text_container=container_right.append("svg:svg").attr("x",y_pos_1/d3.boxplot.scale*axis_length).attr("y",0).attr("width",z_len).attr("height","100%");let text=text_container.append("text").attr("x",z_len/2).attr("y",17).attr("text-anchor","middle").attr("font-family","sans-serif").attr("font-size","6pt").text(zone);let zone_txt=zone;let i=4;while(text.node().getComputedTextLength()>z_len&&zone_txt.length>=5){text.remove();zone_txt=zone.slice(0,-i)+"...";text=text_container.append("text").attr("x",z_len/2).attr("y",17).attr("text-anchor","middle").attr("font-family","sans-serif").attr("font-size","6pt").text(zone_txt);i++}if(text.node().getComputedTextLength()>z_len){text.remove()}}if(zone.startsWith("###MIX###")){container_right.append("rect").attr("x",y_pos_1/d3.boxplot.scale*axis_length).attr("y",12).attr("width",z_len).attr("height",8).attr("fill",d3.boxplot.color_mixes).attr("stroke","None")}else if(nb_zone>0){//Draw zone separator at left of zone (except for first zone)
container_right.append("line").attr("x1",y_pos_1/d3.boxplot.scale*axis_length).attr("x2",y_pos_1/d3.boxplot.scale*axis_length).attr("y1",12).attr("y2",20).attr("stroke","black").attr("stroke-width",d3.boxplot.tick_width).attr("class","whereis")}nb_zone--}};d3.boxplot.draw_axis_bckgd=function(){// Top:
let svg_top=d3.boxplot.svgsupercontainer.append("svg:svg").attr("width",100).attr("height",5).attr("x",0).attr("y",0).attr("viewBox","0 0 100 5").attr("preserveAspectRatio","none");svg_top.append("polygon").attr("points","5,0 95,0 100,5 0,5").attr("stroke","none").style("fill",d3.boxplot.background_axis);// Right:
......
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