1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#
# SonarQube, open source software quality management tool.
# Copyright (C) 2008-2014 SonarSource
# mailto:contact AT sonarsource DOT com
#
# SonarQube is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# SonarQube is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
window.SonarWidgets ?= {}
class BaseWidget
lineHeight: 20
colors4: ['#ee0000', '#f77700', '#80cc00', '#00aa00']
colors4r: ['#00aa00', '#80cc00', '#f77700', '#ee0000']
colors5: ['#ee0000', '#f77700', '#ffee00', '#80cc00', '#00aa00']
colors5r: ['#00aa00', '#80cc00', '#ffee00', '#f77700', '#ee0000']
colorsLevel: ['#d4333f', '#ff9900', '#85bb43', '##b4b4b4']
colorUnknown: '#777'
constructor: ->
@addField 'components', []
@addField 'metrics', []
@addField 'metricsPriority', []
@addField 'options', []
@
addField: (name, defaultValue) ->
privateName = "_#{name}"
@[privateName] = defaultValue
@[name] = (d) -> @param.call @, privateName, d
@
param: (name, value) ->
return @[name] unless value?
@[name] = value
@
addMetric: (property, index) ->
key = @metricsPriority()[index]
@[property] = _.extend @metrics()[key],
key: key
value: (d) ->
if d.measures[key]?
if d.measures[key].text? then d.measures[key].text else d.measures[key].val
formattedValue: (d) ->
if d.measures[key]?
if d.measures[key].text? then d.measures[key].text else d.measures[key].fval
@
trans: (left, top) ->
"translate(#{left},#{top})"
render: (container) ->
@update container
@
update: ->
@
tooltip: (d) ->
title = d.longName
title += "\n#{@colorMetric.name}: #{@colorMetric.formattedValue d}" if @colorMetric and @colorMetric.value(d)?
title += "\n#{@sizeMetric.name}: #{@sizeMetric.formattedValue d}" if @sizeMetric and @sizeMetric.value(d)?
title
window.SonarWidgets.BaseWidget = BaseWidget
|