]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/pretty-json/node_modules/jsonminify/report/assets/scripts/plato-overview.js
bc40078494cfc4a58e1becb41ef1e64f205e52d4
1 /*global $:false, _:false, Morris:false, __report:false, __history:false, __options: false */
2 /*jshint browser:true*/
8 $('[rel=popover]').popover();
10 // @todo put client side templates into a JST
11 var fileGraphTemplate
= _
.template(
12 '<div class="threshold-<%= threshold %>">' +
13 '<label><%= label %></label>' +
14 '<span class="horizontal-bar" style="width:<%= width %>px"></span>' +
15 '<span class="chart-value"><%= value %></span>' +
19 var horizontalBar = function(orig
, width
, label
, thresholds
){
21 for (var i
= thresholds
.length
- 1; i
> -1; i
--) {
22 if (orig
> thresholds
[i
]) {
27 return fileGraphTemplate({
30 threshold : threshold
,
35 function drawFileCharts() {
36 // @todo make a jQuery plugin to accomodate the horizontalBar function
37 $('.js-file-chart').each(function(){
39 width
= el
.width() - 130; // @todo establish max width of graph in plugin
43 var value
= el
.data('complexity');
44 el
.append(horizontalBar(value
, Math
.min(value
* 2, width
),'complexity', [5,10]));
46 value
= el
.data('sloc');
47 el
.append(horizontalBar(value
, Math
.min(value
, width
), 'sloc', [400,600]));
49 value
= el
.data('bugs');
50 el
.append(horizontalBar(value
, Math
.min(value
* 5, width
), 'est errors', [1,5]));
52 value
= el
.data('lint');
53 el
.append(horizontalBar(value
, Math
.min(value
* 5, width
), 'lint errors', [1,10]));
57 function drawOverviewCharts(reports
) {
59 var maintainability
= {
60 element: 'chart_maintainability',
66 labels: ['Maintainability'],
67 barColors : ['#ff9b40']
70 element: 'chart_sloc',
76 barColors : ['#1f6b75']
79 element: 'chart_bugs',
85 barColors : ['#ff9b40']
88 element: 'chart_lint',
94 barColors : ['#1f6b75']
97 reports
.forEach(function(report
){
99 // @todo shouldn't need this, 'auto [num]' doesn't seem to work : https://github.com/oesmith/morris.js/issues/201
100 sloc
.ymax
= Math
.max(sloc
.ymax
, report
.complexity
.aggregate
.complexity
.sloc
.physical
);
101 bugs
.ymax
= Math
.max(bugs
.ymax
, report
.complexity
.aggregate
.complexity
.halstead
.bugs
.toFixed(2));
105 value : report
.complexity
.aggregate
.complexity
.sloc
.physical
,
106 label : report
.info
.fileShort
109 value : report
.complexity
.aggregate
.complexity
.halstead
.bugs
.toFixed(2),
110 label : report
.info
.fileShort
112 maintainability
.data
.push({
113 value : report
.complexity
.maintainability
? report
.complexity
.maintainability
.toFixed(2) : 0,
114 label : report
.info
.fileShort
117 value : report
.jshint
&& report
.jshint
.messages
,
118 label : report
.info
.fileShort
122 function onGraphClick(i
){
123 document
.location
= __report
.reports
[i
].info
.link
;
129 Morris
.Bar(maintainability
)
132 if (__options
.flags
.jshint
) charts
.push(Morris
.Bar(lint
));
134 charts
.forEach(function(chart
){
135 chart
.on('click', onGraphClick
);
140 function drawHistoricalChart(history
) {
141 var data
= _
.map(history
,function(record
){
142 var date
= new Date(record
.date
);
144 date : date
.getFullYear() + '-' + (date
.getMonth() + 1) + '-' + date
.getDate(),
145 average_maintainability : parseFloat(record
.average
.maintainability
),
146 average_sloc : record
.average
.sloc
150 element: 'chart_historical_sloc',
153 ykeys: ['average_sloc'],
154 labels: ['Average Lines'],
158 element: 'chart_historical_maint',
161 ykeys: ['average_maintainability'],
162 labels: ['Maintainability'],
168 function drawCharts() {
169 $('.js-chart').empty();
170 drawHistoricalChart(__history
);
171 drawOverviewCharts(__report
.reports
);
172 drawFileCharts(__report
.reports
);
177 $(window
).on('resize', _
.debounce(drawCharts
,200));