summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-10-20 14:16:28 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-10-20 14:16:28 +0000
commit83e37e5cb8006c90a5cf20c7c368cb248086fd8b (patch)
tree7b3106f2e84ad91d227e59f143c874c2e46959bf /sonar-server
parent650127b2fab45be5907f8de45aad0d2a6497991f (diff)
downloadsonarqube-83e37e5cb8006c90a5cf20c7c368cb248086fd8b.tar.gz
sonarqube-83e37e5cb8006c90a5cf20c7c368cb248086fd8b.zip
SONAR-1830 extract the html color of a measure from the class Treemap to Measure + support rating type
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb37
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/sonar/treemap.rb56
2 files changed, 40 insertions, 53 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb
index ffbea749e58..2cda15f22e0 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb
@@ -124,6 +124,43 @@ class ProjectMeasure < ActiveRecord::Base
end
end
+
+ MIN_COLOR=Color::RGB.from_html("FF0000") # red
+ MEAN_COLOR=Color::RGB.from_html("FFB000") # orange
+ MAX_COLOR=Color::RGB.from_html("00FF00") # green
+
+ def color
+ @color ||=
+ begin
+ percent=-1.0
+ if !alert_status.blank?
+ case(alert_status)
+ when Metric::TYPE_LEVEL_OK : percent=100.0
+ when Metric::TYPE_LEVEL_ERROR : percent=0.0
+ when Metric::TYPE_LEVEL_WARN : percent=50.0
+ end
+ elsif metric.value_type==Metric::VALUE_TYPE_LEVEL
+ case(text_value)
+ when Metric::TYPE_LEVEL_OK : percent=100.0
+ when Metric::TYPE_LEVEL_WARN : percent=50.0
+ when Metric::TYPE_LEVEL_ERROR : percent=0.0
+ end
+ elsif value && metric.worst_value && metric.best_value
+ percent = 100.0 * (value.to_f - metric.worst_value.to_f) / (metric.best_value.to_f - metric.worst_value.to_f)
+ percent=100.0 if percent>100.0
+ percent=0.0 if percent<0.0
+ end
+
+ if percent<0.0
+ nil
+ elsif (percent > 50.0)
+ MAX_COLOR.mix_with(MEAN_COLOR, percent - 50.0)
+ else
+ MIN_COLOR.mix_with(MEAN_COLOR, 50.0 - percent)
+ end
+ end
+ end
+
def leading_zero( value )
if ( value < 10 )
return "0" + value.to_s
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/sonar/treemap.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/sonar/treemap.rb
index cbae7b317cf..7d4f93860b4 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/sonar/treemap.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/sonar/treemap.rb
@@ -28,12 +28,6 @@ class Sonar::Treemap
@color_metric = color_metric
@width = width
@height = height
-
- @min = 0
- @max = 100
- @min_color = Color::RGB.from_html("FF0000") # red
- @mean_color = Color::RGB.from_html("FFB000") # orange
- @max_color = Color::RGB.from_html("00FF00") # green
end
def generate_html
@@ -65,7 +59,7 @@ class Sonar::Treemap
:label => resource.name(false),
:title => escape_javascript(resource.name(true)),
:tooltip => get_html_tooltip(snapshot, size_measure, color_measure),
- :color => get_hex_color(color_measure),
+ :color => html_color(color_measure),
:url => get_url(snapshot,color_measure))
node.add_child(child)
end
@@ -89,54 +83,10 @@ class Sonar::Treemap
html
end
- def get_color(color_measure)
- value=percentage_value(color_measure)
- if value<0
- return Color::RGB.from_html("DDDDDD")
- end
-
- interval = (@max - @min)/2
- mean = (@min + @max) / 2.0
- if (value > mean)
- value_percent = ((value - mean) / interval) * 100.0
- color = @max_color.mix_with(@mean_color, value_percent)
- else
- value_percent = ((mean - value) / interval) * 100.0
- color = @min_color.mix_with(@mean_color, value_percent)
- end
- color
- end
-
- def percentage_value(color_measure)
- return -1 if color_measure.nil?
-
- metric=color_measure.metric
- value=-1
- if !color_measure.alert_status.blank?
- case(color_measure.alert_status)
- when Metric::TYPE_LEVEL_OK : value=100
- when Metric::TYPE_LEVEL_ERROR : value=0
- when Metric::TYPE_LEVEL_WARN : value=50
- end
-
- elsif metric.value_type==Metric::VALUE_TYPE_LEVEL
- case(color_measure.text_value)
- when Metric::TYPE_LEVEL_OK : value=100
- when Metric::TYPE_LEVEL_WARN : value=50
- when Metric::TYPE_LEVEL_ERROR : value=0
- end
- elsif metric.worst_value && metric.best_value
- range=metric.best_value.to_f - metric.worst_value.to_f
- value = (color_measure.value.to_f - metric.worst_value.to_f) * (100.0 / range)
- value=100 if value>100.0
- value=0 if value<0.0
- end
- value
+ def html_color(measure)
+ measure ? measure.color.html : '#DDDDDD'
end
- def get_hex_color(color_measure)
- get_color(color_measure).html
- end
end
class Sonar::HtmlOutput < Treemap::HtmlOutput