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
@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
: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
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