diff --git a/app/views/_pie.html.erb b/app/views/_pie.html.erb
index c19e634..5138924 100644
--- a/app/views/_pie.html.erb
+++ b/app/views/_pie.html.erb
@@ -5,13 +5,17 @@
<%- arc_y = 150 %>
<%- cumulative_percent = 0 %>
<%- cumulative_angle = -180 %>
+
<%# Calculate arc coordinates to draw each slice %>
<%- data.each_with_index do |object, index| %>
<%- cumulative_percent += object[:percent_value] %>
-
<%- cumulative_angle += 360 * object[:percent_value] %>
<% end %>
+
+ <%# This generates the svg tooltips on top of the pie slices %>
+ <%- data.each_with_index do |object, index| %>
+ <%- cumulative_percent += object[:percent_value] %>
+ <%- arc_x = 150 - 125 * Math.cos(2 * Math::PI * cumulative_percent) %>
+ <%- arc_y = 150 - 125 * Math.sin(2 * Math::PI * cumulative_percent) %>
+
+ <%# Background rectangle for the tooltip %>
+ <%# x - 5 is padding before the text, y - 15 is half the height, width + 1 is padding, *8px per char, +5 is for the x padding %>
+
+
+ <%# Tooltip for each pie slice %>
+
+ <%= object[:name] %>:
+ <%= object[:value] %>
+
+
+ <%- cumulative_angle += 360 * object[:percent_value] %>
+ <% end %>
<%# Pie chart key %>
@@ -42,43 +80,70 @@
diff --git a/app/views/_styles.html.erb b/app/views/_styles.html.erb
index 51abe6c..f81b704 100644
--- a/app/views/_styles.html.erb
+++ b/app/views/_styles.html.erb
@@ -156,6 +156,21 @@ h4.purechart {
min-height: 15px;
}
+.pie-slice-tooltip {
+ position: absolute;
+ top: 50%;
+ left: 50%;
+
+ padding: 8px;
+
+ background-color: #fff;
+ border-radius: 8px;
+ box-shadow: rgba(0, 0, 0, 0.25) 0px 10px 36px 0px, rgba(0, 0, 0, 0.15) 0px 0px 0px 1px;
+
+ opacity: 0;
+}
+
+
.bar-chart-bar {
height: 16px;
}