1(function($) { 2 Drupal.behaviors.exploreCommitments = { 3 attach: function(context, settings) { 4 5 var url = window.location.protocol + '//' + window.location.host, 6 searchData, 7 graphWrap, 8 graphSelector; 9 10 if($("#cr-search-in").length) { 11 searchData = url + '/visualization/get_donut_data'; 12 graphWrap = $("#cr-search-in"); 13 graphSelector = "#cr-search-in"; 14 createDonut(searchData, graphWrap, graphSelector); 15 } 16 17 if($("#cr-search-core-commt").length) { 18 searchData = url + '/visualization/get_ca_donut_data'; 19 graphWrap = $("#cr-search-core-commt"); 20 graphSelector = "#cr-search-core-commt"; 21 createDonut(searchData, graphWrap, graphSelector); 22 } 23 24 if($("#cr-search-ar").length) { 25 searchData = url + '/visualization/get_reports_donut_data'; 26 graphWrap = $("#cr-search-ar"); 27 graphSelector = "#cr-search-ar"; 28 createDonut(searchData, graphWrap, graphSelector); 29 } 30 31 function createDonut(dataURL, elementWrap, elementSelector) { 32 $.getJSON(dataURL, function(data) { 33 34 //Hide loader 35 elementWrap.siblings(".loader-img").hide(); 36 var container = elementWrap, 37 width, 38 height, 39 twoPi = 2 * Math.PI, 40 innerRadius = 43, 41 outerRadius = 50, 42 image_width = 42, 43 image_height = 42, 44 arc = d3.svg.arc(), 45 i = 1; 46 47 if(container) { 48 width = 225; 49 height = 250; 50 } 51 52 arc.innerRadius(innerRadius) 53 .outerRadius(outerRadius) 54 .startAngle(0); 55 56 var svg = d3.select("body " + elementSelector).selectAll("svg") 57 .data(data) 58 .enter().append("svg") 59 .attr("width", width) 60 .attr("height", height) 61 .attr("viewBox", "0, 0, 220, 230") 62 .attr("preserveAspectRatio", "xMinYMin") 63 .attr("id", function() { 64 return "chart-" + i++; 65 }); 66 67 var ring = svg.append("g") 68 .attr("class", "donut-ring") 69 .attr("transform", "translate(115, 70)"); 70 71 // Background arc 72 var background = ring.append("path") 73 .datum({ endAngle: twoPi }) 74 .style("fill", "#e6e6e6") 75 .attr("class", "back-arc") 76 .attr("d", arc); 77 78 // Foreground arc 79 var foreground = ring.append("path") 80 .attr("class", "front-arc") 81 .attr("d", arc.endAngle(function(d) { 82 return (twoPi * (1 - ((d.capacity - d.filled) / d.capacity))); 83 })) 84 .style("fill", function(d) { 85 return d.color; 86 }) 87 .transition() 88 .delay(100) 89 .duration(1700) 90 .attrTween("transform", function(d, i) { 91 var angle = 360; 92 var i = d3.interpolate(0, angle); 93 return function(t) { 94 return "rotate(" + i(t) + ")"; 95 }; 96 }); 97 98 //Center icon 99 ring.append("svg:image") 100 .attr("x", -20) 101 .attr("y", -20) 102 .attr("xlink:href", function(d) { 103 return d.icon; 104 }) 105 .attr("width", image_width) 106 .attr("height", image_height); 107 108 //Label text 109 var textLabel = svg.append("g") 110 .attr("class", "donut-label") 111 .attr("transform", "translate(110, 70)"); 112 113 textLabel.append("text") 114 .attr("class", "cr-text") 115 .attr("y", 70) 116 .attr("text-anchor", "middle") 117 .text(function(d, i) { 118 return d.name; 119 }) 120 .call(wrap, 180); 121 122 textLabel.append("text") 123 .attr("class", "cr-count") 124 .attr("x", -10) 125 .attr("y", 150) 126 .style("fill", function(d) { 127 return d.color; 128 }) 129 .text("0 %") 130 .transition() 131 .delay(100) 132 .duration(1700) 133 .tween(".cr-count", function(d) {
134 return displayCount(this, d.percentage); 135 }); 136 137 textLabel.append("text") 138 .attr("class", "cr-tot-count") 139 .attr("x", 0) 140 .attr("y", 172) 141 .attr("text-anchor", "middle") 142 .style("fill", function(d) { 143 return d.color; 144 }) 145 .text("0") 146 .transition() 147 .delay(100) 148 .duration(1700) 149 .tween(".cr-count", function(d) { 150 return displayCount(this, d.filled); 151 }); 152 153 // textLabel.append("text") 154 // .attr("class", "cr-tot-count") 155 // .attr("x", 3) 156 // .attr("y", 172) 157 // .style("fill", function(d) { 158 // return d.color; 159 // }) 160 // .text(function(d) { 161 // return " / " + d.capacity; 162 // }); 163 164 resize(elementWrap, elementSelector); 165 }); 166 } 167 168 //Wrap long text 169 function wrap(text, width) { 170 text.each(function() { 171 var text = d3.select(this), 172 words = text.text().split(/\s+/).reverse(), 173 word, 174 line = [], 175 lineNumber = 0, 176 lineHeight = 1.1, // ems 177 y = text.attr("y"), 178 dy = 0.35, 179 tspan = text.text(null).append("tspan").attr("x", 0).attr("y", y).attr("dy", dy + "em"); 180 while (word = words.pop()) { 181 line.push(word); 182 tspan.text(line.join(" ")); 183 if (tspan.node().getComputedTextLength() > width) { 184 line.pop(); 185 tspan.text(line.join(" ")); 186 line = [word]; 187 tspan = text.append("tspan").attr("x", 0).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word); 188 } 189 } 190 }); 191 } 192 193 function displayCount(text, value) { 194 var i = d3.interpolate(0, value), 195 prec = (value + "").split("."), 196 round = (prec.length > 1) ? Math.pow(10, prec[1].length) : 1; 197 if (d3.select(text).classed('cr-count')) { 198 return function(t) { 199 text.textContent = Math.round(i(t) * round) / round + "%"; 200 }; 201 } else { 202 return function(t) { 203 text.textContent = Math.round(i(t) * round) / round; 204 }; 205 } 206 } 207 208 // Call the resize function whenever a resize event occurs 209 d3.select(window).on('resize', resize(graphWrap, graphSelector)); 210 211 // Call the resize function 212 resize(graphWrap, graphSelector); 213 214 function resize(fieldWrap, fieldSelector) { 215 216 var general_width = parseFloat(d3.select("html").style("width")), 217 donut = d3.select(fieldSelector); 218 if (fieldWrap) { 219 if (general_width <= 445) { 220 donut.selectAll('svg .cr-count') 221 .attr("y", "140"); 222 // donut.selectAll('svg .cr-tot-count') 223 // .attr("y", "190"); 224 } 225 else { 226 donut.selectAll('svg .cr-count') 227 .attr("y", "150"); 228 } 229 } 230 } 231 } 232 }; 233})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.