1 import BrAPIBoxPlotter from 'BrAPI-BoxPlotter';
2 import '../legacy/d3/d3v4Min.js';
3 import '../legacy/jquery.js';
4 import '../legacy/brapi/BrAPI.js';
6 export function init(main_div){
7 if (!(main_div instanceof HTMLElement)){
8 main_div = document.getElementById(main_div.startsWith("#") ? main_div.slice(1) : main_div);
11 main_div.innerHTML = `
12 <div class="container-fluid">
14 <div class="form col-sm-12 form-group boxplotter-variable-select-div" style="display:none;">
15 <label for="sort" class="control-label">Variable</label>
16 <select class="form-control boxplotter-variable-select"></select>
20 <div class="row boxplotter-group-list" style="display:none;">
21 <div class="form col-sm-12 form-group">
22 <label for="sort" class="control-label"> Group By </label>
23 <div class="groupBy-div">
24 <select class="form-control groupBy" style="width:auto; display:inline;">
25 <option value="" selected></option>
27 <a class="btn btn-default groupBy-add" style="margin-top:-1px;">+</a>
28 <a class="btn btn-default groupBy-remove" style="margin-top:-1px;">-</a>
34 <div class="col-sm-12 boxplotter-result" style="display:none;">
40 var boxplot = BrAPIBoxPlotter(bp.find(".boxplotter-result").get(0));
43 function loadDatasetObsUnits(ds,ou){
48 bp.find(".boxplotter-variable-select-div, .boxplotter-group-list, .boxplotter-result").hide();
50 url : document.location.origin+'/ajax/tools/boxplotter/get_constraints',
54 success : function(data) {
56 var obsUnits = BrAPI(document.location.origin+"/brapi/v1").phenotypes_search({
57 "germplasmDbIds" : data["categories"]["accessions"],
58 "observationVariableDbIds" : data["categories"]["traits"],
59 "studyDbIds" : data["categories"]["trials"],
60 "locationDbIds" : data["categories"]["locations"],
61 "programDbIds" : data["categories"]["breeding_programs"],
62 "observationLevel" : ou,
65 boxplot.setData(obsUnits);
66 obsUnits.all(function(d){
71 boxplot.getVariables().then(vs=>{
73 bp.find('.boxplotter-result').html('<strong class="not-enough-data">Not Enough Data with the Given Constraints</strong>');
74 bp.find(".boxplots").hide();
78 bp.find('.boxplotter-result .not-enough-data').remove();
79 bp.find(".boxplotter-variable-select-div, .boxplotter-group-list, .brapp-wrapper, .boxplots").show();
81 bp.find(".boxplotter-result").show();
86 function drawVariableSelect(){
87 boxplot.getVariables().then(vs=>{
88 var vars = d3.select(main_div).select(".boxplotter-variable-select").selectAll("option").data(vs);
90 var allVars = vars.enter().append("option")
92 .attr("value",d=>d.key)
93 .attr("selected",d=>d.key==boxplot.variable?"":null)
96 d3.select(main_div).select(".boxplotter-variable-select").on("change",function(){
97 boxplot.setVariable(this.value);
101 function drawGroupBys(){
102 boxplot.getGroupings().then(grps=>{
103 console.log("grps",grps);
104 var optSelects = d3.select(main_div).select(".boxplotter-group-list")
105 .selectAll(".groupBy")
106 .on("change",function(){
109 .selectAll('option:not([value=""])')
111 optSelects.enter().append("option")
113 .attr("value",d=>d.key)
114 .text(d=>d.value.name);
115 d3.selectAll(".groupBy-add").on("click",function(){
116 $(this.parentNode).clone(true).appendTo(this.parentNode.parentNode);
120 d3.selectAll(".groupBy-remove").on("click",function(){
121 d3.select(this.parentNode).remove();
126 function readGrouping(){
128 d3.selectAll(".groupBy")
129 .each(function(){grouping.push(this.value)})
130 boxplot.setGroupings(grouping)
134 'loadDatasetObsUnits':loadDatasetObsUnits,