From b9d84db7a2c8b52604da03db8777bf4857146df6 Mon Sep 17 00:00:00 2001 From: Aliaxander Date: Sat, 20 Feb 2016 01:25:43 +0300 Subject: [PATCH] Create loc2.js --- public/assets/js/loc2.js | 106 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 public/assets/js/loc2.js diff --git a/public/assets/js/loc2.js b/public/assets/js/loc2.js new file mode 100644 index 00000000..12c07c01 --- /dev/null +++ b/public/assets/js/loc2.js @@ -0,0 +1,106 @@ +var locPlugin2 = ActiveBuild.UiPlugin.extend({ + id: 'build-lines-chart-structure', + css: 'col-xs-6', + title: Lang.get('structure'), + lastData: null, + displayOnUpdate: false, + rendered: false, + chartData: null, + + register: function() { + var self = this; + var query = ActiveBuild.registerQuery('phploc-structure', -1, {num_builds: 10, key: 'phploc-structure'}) + + $(window).on('phploc-structure', function(data) { + self.onUpdate(data); + }); + + $(window).on('build-updated', function(data) { + if (data.queryData.status > 1 && !self.rendered) { + query(); + } + }); + }, + + render: function() { + var self = this; + var container = $('
'); + container.append(''); + + $(document).on('shown.bs.tab', function () { + $('#build-lines-chart-structure').hide(); + self.drawChart(); + }); + + return container; + }, + + onUpdate: function(e) { + this.lastData = e.queryData; + this.displayChart(); + }, + + displayChart: function() { + var self = this; + var builds = this.lastData; + self.rendered = true; + + self.chartData = { + labels: [], + datasets: [ + { + label: "Namespaces", + strokeColor: "rgba(60,141,188,1)", + pointColor: "rgba(60,141,188,1)", + data: [] + }, + { + label: "Interfaces", + strokeColor: "rgba(245,105,84,1)", + pointColor: "rgba(245,105,84,1)", + data: [] + }, + { + label: "Classes", + strokeColor: "rgba(0,166,90,1)", + pointColor: "rgba(0,166,90,1)", + data: [] + }, + { + label: "Methods", + strokeColor: "rgba(0,192,239,1)", + pointColor: "rgba(0,192,239,1)", + data: [] + } + ] + }; + + for (var i in builds) { + self.chartData.labels.push('Build ' + builds[i].build_id); + self.chartData.datasets[0].data.push(builds[i].meta_value.Namespaces); + self.chartData.datasets[1].data.push(builds[i].meta_value.Interfaces); + self.chartData.datasets[2].data.push(builds[i].meta_value.Classes); + self.chartData.datasets[3].data.push(builds[i].meta_value.Methods); + } + + self.drawChart(); + }, + + drawChart: function () { + var self = this; + + if ($('#information').hasClass('active') && self.chartData && self.lastData) { + $('#build-lines-chart-structure').show(); + + var ctx = $("#phploc-structure-chart").get(0).getContext("2d"); + var phpLocChart = new Chart(ctx); + + phpLocChart.Line(self.chartData, { + datasetFill: false, + multiTooltipTemplate: "<%=datasetLabel%>: <%= value %>" + }); + } + } +}); + +ActiveBuild.registerPlugin(new locPlugin2());