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(
9 main_div.startsWith("#") ? main_div.slice(1) : main_div
13 main_div.innerHTML = `
14 <div class="container-fluid">
16 <div class="col-sm-12 boxplotter-loading"></div>
17 <div class="form col-sm-12 form-group boxplotter-variable-select-div" style="display:none;">
18 <label for="sort" class="control-label">Variable</label>
19 <select class="form-control boxplotter-variable-select"></select>
23 <div class="row boxplotter-group-list" style="display:none;">
24 <div class="form col-sm-12 form-group">
25 <label for="sort" class="control-label"> Group By </label>
26 <div class="groupBy-div">
27 <select class="form-control groupBy" style="width:auto; display:inline;">
28 <option value="" selected></option>
30 <a class="btn btn-default groupBy-add" style="margin-top:-1px;">+</a>
31 <a class="btn btn-default groupBy-remove" style="margin-top:-1px;">-</a>
37 <div class="col-sm-12 boxplotter-result" style="display:none;">
43 var boxplot = BrAPIBoxPlotter(bp.find(".boxplotter-result").get(0));
45 function loadDatasetObsUnits(ds, ou, auth_token) {
51 ".boxplotter-variable-select-div, .boxplotter-group-list, .boxplotter-result"
53 bp.find(".boxplotter-loading").html("Loading ...");
55 url: document.location.origin + "/ajax/tools/boxplotter/get_constraints",
59 success: function (data) {
62 document.location.origin + "/brapi/v2",
65 ).search_observationunits({
66 germplasmDbIds: data["categories"]["accessions"],
67 observationVariableDbIds: data["categories"]["traits"],
68 studyDbIds: data["categories"]["trials"],
69 locationDbIds: data["categories"]["locations"],
70 programDbIds: data["categories"]["breeding_programs"],
71 observationLevelName: ou,
72 includeObservations: "true",
75 boxplot.setData(obsUnits);
76 obsUnits.all(function (d) {
81 boxplot.getVariables().then((vs) => {
83 bp.find(".boxplotter-result").html(
84 '<strong class="not-enough-data">Not Enough Data with the Given Constraints</strong>'
86 bp.find(".boxplots").hide();
89 bp.find(".boxplotter-result .not-enough-data").remove();
91 ".boxplotter-variable-select-div, .boxplotter-group-list, .brapp-wrapper, .boxplots"
94 bp.find(".boxplotter-loading").html("");
95 bp.find(".boxplotter-result").show();
100 function drawVariableSelect() {
101 boxplot.getVariables().then((vs) => {
104 .select(".boxplotter-variable-select")
107 vars.exit().remove();
112 .attr("value", (d) => d.key)
113 .attr("selected", (d) => (d.key == boxplot.variable ? "" : null))
114 .text((d) => d.value);
117 .select(".boxplotter-variable-select")
118 .on("change", function () {
119 boxplot.setVariable(this.value);
123 function drawGroupBys() {
124 boxplot.getGroupings().then((grps) => {
125 console.log("grps", grps);
128 .select(".boxplotter-group-list")
129 .selectAll(".groupBy")
130 .on("change", function () {
133 .selectAll('option:not([value=""])')
139 .attr("value", (d) => d.key)
140 .text((d) => d.value.name);
141 d3.selectAll(".groupBy-add").on("click", function () {
142 $(this.parentNode).clone(true).appendTo(this.parentNode.parentNode);
146 d3.selectAll(".groupBy-remove").on("click", function () {
147 d3.select(this.parentNode).remove();
152 function readGrouping() {
154 d3.selectAll(".groupBy").each(function () {
155 grouping.push(this.value);
157 boxplot.setGroupings(grouping);
161 loadDatasetObsUnits: loadDatasetObsUnits,