8 background-color: #4CAF50; /* Green */
13 text-decoration: none;
14 display: inline-block;
18 -webkit-transition-duration: 0.4s; /* Safari */
19 transition-duration: 0.4s;
21 .button1 {border-radius: 8px;}
24 box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
33 <script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
34 <script src="https://rawgit.com/tpreusse/radar-chart-d3/master/src/radar-chart.js"></script>
35 <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
36 <& /page/page_title.mas, title => "Radar Graph" &>
38 <& /util/import_javascript.mas, classes => [ 'CXGN.BreedersToolbox.HTMLSelect' ] &>
40 <div id="dataset_select_div">[loading...]</div>
43 <div class="text-center">
44 <button class="button button1" id="load_data">Render Graph</button>
48 <div id="current_selected_traits"></div>
50 <canvas id="radar_chart" width="400" height="400"></canvas>
54 var ctx = document.getElementById('radar_chart').getContext('2d');
55 var radar_data = { labels: [], datasets: [] };
58 var radar_chart = new Chart(ctx, {
98 jQuery(window).ready(function () {
99 get_select_box("datasets", "dataset_select_div", { "checkbox_name": "dataset_select_checkbox" });
102 jQuery('#load_data').click(function () {
104 var dataset_ids = get_dataset_id();
105 radar_chart.data.datasets = [];
106 radar_chart.data.labels = [];
108 for (var i = 0; i < dataset_ids.length; i++) {
110 url: '/ajax/radargraph?dataset_id=' + dataset_ids[i],
111 success: function (r) {
113 format_data(r.data, r.name);
120 * Pushes the input into the dataset as an array of values
121 * @param {*} input Data from the AJAX request
123 function format_data(input, dataset_name) {
125 var trait_indices = input[0].indexOf("availableGermplasmSeedlotUniquenames") + 1;
127 for (var i = trait_indices; i < trait_indices + (input[0].length - trait_indices - 1); i++) {
129 for (var j = 1; j < input.length; j++) {
130 temp.push(input[j][i] / 1.0);
132 data.push(Math.round((get_avg(temp)) * 10) / 10);
135 var rgb_col = colors[Math.floor(Math.random() * colors.length)]
136 var rgba_col = colors_alpha[colors.indexOf(rgb_col)]
143 backgroundColor: rgba_col,
144 borderColor: rgb_col,
145 pointHoverRadius: 13,
146 pointBackgroundColor: rgb_col,
147 pointBorderColor: '#fff',
148 pointHoverBackgroundColor: '#fff',
149 pointHoverBorderColor: rgb_col
152 radar_chart.data.datasets.push(set);
153 radar_chart.update();
157 * Returns the average of an array
158 * @param {*} data Array of numbers
159 * @returns Average value
161 function get_avg(data) {
162 const total = data.reduce((acc, c) => acc + c, 0);
163 return total * 1.0 / data.length * 1.0;
167 * Returns the selected dataset ids
168 * @returns Dataset ids
171 function get_dataset_id() {
172 var selected_ids = [];
173 jQuery('input[name="dataset_select_checkbox"]:checked').each(function () {
174 selected_ids.push(jQuery(this).val());
176 if (selected_ids.length < 1) {
177 alert('Please select at least one dataset!');
184 * If the labels have not been set for the chart,
185 * this function will push all labels to the chart
186 * @param {*} input The data returned from the ajax request
188 function get_labels(input) {
190 var trait_indices = input[0].indexOf("availableGermplasmSeedlotUniquenames") + 1;
192 for (var i = trait_indices; i < trait_indices + (input[0].length - trait_indices - 1); i++) {
193 radar_chart.data.labels.push(input[0][i]);
195 radar_chart.update();
200 var colors = ['rgb(0,0,0)','rgb(255, 99, 132)','rgb(34,139,34)','rgb(30,144,255)'];
201 var colors_alpha = ['rgba(0,0,0,0.2)','rgba(255, 99, 132,0.2)','rgba(34,139,34,0.2)','rgba(30,144,255,0.2)'];