]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/pretty-json/node_modules/jsonminify/report/assets/scripts/plato-file.js
5603e22f98866cb26bcb9c36acccc7ab2e6167b7
1 /*global $:false, _:false, Morris:false, CodeMirror:false, __report:false, __history:false */
2 /*jshint browser:true*/
8 $('[rel=popover]').popover();
10 _
.templateSettings
= {
11 interpolate : /\{\{(.+?)\}\}/g
14 function focusFragment() {
15 $('.plato-mark').removeClass('focus');
16 var markId
= window
.location
.hash
.substr(1);
17 if (markId
) $('.' + markId
).addClass('focus');
21 window
.onhashchange
= focusFragment();
23 var srcEl
= document
.getElementById('file-source');
27 gutters : ['plato-gutter-jshint','plato-gutter-complexity'],
31 var cm
= CodeMirror
.fromTextArea(srcEl
, options
);
33 var byComplexity
= [], bySloc
= [];
35 var popoverTemplate
= _
.template($('#complexity-popover-template').text());
36 var gutterIcon
= $('<a><i class="plato-gutter-icon icon-cog"></i></a>');
38 var popovers
= cm
.operation(function(){
39 var queuedPopovers
= [];
40 __report
.complexity
.functions
.forEach(function(fn
,i
){
43 value : fn
.complexity
.cyclomatic
47 value : fn
.complexity
.sloc
.physical
,
48 formatter: function (x
) { return x
+ " lines"; }
51 var name
= fn
.name
=== '<anonymous>' ? 'function\\s*\\([^)]*\\)' : fn
.name
;
52 var line
= fn
.line
- 1;
53 var className
= 'plato-mark-fn-' + i
;
55 gutterId : 'plato-gutter-complexity',
56 el : gutterIcon
.clone().attr('name',className
)[0]
60 title : fn
.name
=== '<anonymous>' ? '<anonymous>' : 'function ' + fn
.name
+ '',
61 content : popoverTemplate(fn
)
63 queuedPopovers
.push(cm
.markPopoverText({line : line
, ch:0}, name
, className
, gutter
, popover
));
65 return queuedPopovers
;
68 popovers
.forEach(function(fn
){fn();});
70 var scrollToLine = function(i
) {
71 var origScroll
= [window
.pageXOffset
,window
.pageYOffset
];
72 window
.location
.hash
= '#plato-mark-fn-' + i
;
73 window
.scrollTo(origScroll
[0],origScroll
[1]);
74 var line
= __report
.complexity
.functions
[i
].line
;
75 var coords
= cm
.charCoords({line : line
, ch : 0});
76 $('body,html').animate({scrollTop : coords
.top
-50},250);
79 // yield to the browser
80 setTimeout(function(){
82 { element: 'fn-by-complexity', data: byComplexity
},
83 { element: 'fn-by-sloc', data: bySloc
}
85 drawHistoricalCharts(__history
);
88 cm
.operation(function(){
89 addLintMessages(__report
);
93 function drawFunctionCharts(charts
) {
94 charts
.forEach(function(chart
){
95 Morris
.Donut(chart
).on('click',scrollToLine
);
99 function drawHistoricalCharts(history
) {
100 $('.historical.chart').empty();
101 var data
= _
.map(history
,function(record
){
102 var date
= new Date(record
.date
);
104 date : date
.getFullYear() + '-' + (date
.getMonth() + 1) + '-' + date
.getDate(),
105 maintainability : parseFloat(record
.maintainability
).toFixed(2),
110 element: 'chart_historical_sloc',
114 labels: ['Lines of Code'],
118 element: 'chart_historical_maint',
121 ykeys: ['maintainability'],
122 labels: ['Maintainability'],
128 function addLintMessages(report
) {
130 report
.jshint
.messages
.forEach(function (message
) {
131 var text
= 'Column: ' + message
.column
+ ' "' + message
.message
+ '"';
132 if (_
.isArray(message
.line
)) {
133 message
.line
.forEach(function(line
){
134 if (!lines
[line
]) lines
[line
] = '';
135 lines
[line
] += '<div class="plato-jshint-message text-'+message
.severity
+'">' + text
+ '</div>';
138 if (!lines
[message
.line
]) lines
[message
.line
] = '';
139 lines
[message
.line
] += '<div class="plato-jshint-message text-'+message
.severity
+'">' + text
+ '</div>';
142 var marker
= document
.createElement('a');
143 marker
.innerHTML
= '<i class="plato-gutter-icon icon-eye-open"></i>';
144 Object
.keys(lines
).forEach(function(line
){
145 var lineWidget
= document
.createElement('div');
146 lineWidget
.innerHTML
= lines
[line
];
147 cm
.setGutterMarker(line
- 1, 'plato-gutter-jshint', marker
.cloneNode(true));
148 cm
.addLineWidget(line
- 1, lineWidget
);