Skip to content

Commit

Permalink
Show percentage in tooltips for histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
tadassce committed Jul 20, 2012
1 parent 72f3acd commit 2e7ec7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions web/haml/distribution_gauge.haml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%ul.ui_numbers(style="float:right;") %ul.ui_numbers(style="float:right;")
%li %li
.val .val
%span.ui_value(data-value="#{@samples}") %span.ui_value.samples(data-value="#{@samples}")
.title Number of Samples .title Number of Samples
%li %li
.val .val
Expand Down Expand Up @@ -96,23 +96,23 @@
no_headbar: true, no_headbar: true,
default_style: 'line', default_style: 'line',
series_resolutions: #{@zooms.to_json}, series_resolutions: #{@zooms.to_json},
series: [ series: [
{ {
name: 'Max', name: 'Max',
color: "#{FnordMetric::COLORS[-1]}", color: "#{FnordMetric::COLORS[-1]}",
data: #{@mmm_timeseries_arr.map{|t,v| {:x=>t.to_i,:y=>v[:max]} }.to_json} data: #{@mmm_timeseries_arr.map{|t,v| {:x=>t.to_i,:y=>v[:max]} }.to_json}
}, },
{ {
name: 'Min', name: 'Min',
color: "#{FnordMetric::COLORS[-1]}", color: "#{FnordMetric::COLORS[-1]}",
data: #{@mmm_timeseries_arr.map{|t,v| {:x=>t.to_i,:y=>v[:min]} }.to_json} data: #{@mmm_timeseries_arr.map{|t,v| {:x=>t.to_i,:y=>v[:min]} }.to_json}
}, },
{ {
name: 'Mean', name: 'Mean',
color: "#{FnordMetric::COLORS[-2]}", color: "#{FnordMetric::COLORS[-2]}",
data: #{@mmm_timeseries_arr.map{|t,v| {:x=>t.to_i,:y=>v[:avg].average} }.to_json} data: #{@mmm_timeseries_arr.map{|t,v| {:x=>t.to_i,:y=>v[:avg].average} }.to_json}
} }
] ]
}); });



4 changes: 3 additions & 1 deletion web/vendor/rickshaw.fnordmetric.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2183,13 +2183,15 @@ Rickshaw.Graph.Renderer.Bar = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
} ); } );




var total = $('.ui_numbers .samples').data('value');
$('.widget_histogram_bars .tooltip').remove(); $('.widget_histogram_bars .tooltip').remove();
$('.widget_histogram_bars rect').each(function(hist_i) { $('.widget_histogram_bars rect').each(function(hist_i) {
var percentage = Math.round(sdata[hist_i].y * 1000 / total) / 10;
var left = parseInt($(this).offset().left); var left = parseInt($(this).offset().left);
var top = parseInt($(this).offset().top) - 23; var top = parseInt($(this).offset().top) - 23;
var tooltip = '<div class="tooltip" data-hist-id="' + hist_i var tooltip = '<div class="tooltip" data-hist-id="' + hist_i
+ '" style="left:' + left + 'px; top: ' + top + 'px">' + '" style="left:' + left + 'px; top: ' + top + 'px">'
+ sdata[hist_i].y + '</div>'; + sdata[hist_i].y + ' (' + percentage + '%)' + '</div>';
$(this).parents('.widget_histogram_bars:first').append(tooltip); $(this).parents('.widget_histogram_bars:first').append(tooltip);
$(this).attr('data-id', hist_i); $(this).attr('data-id', hist_i);
}); });
Expand Down

0 comments on commit 2e7ec7d

Please sign in to comment.