From 123d7bb2f427035b37887818102ef966ee52f740 Mon Sep 17 00:00:00 2001 From: Brandon Hilkert Date: Wed, 21 May 2014 16:37:49 -0400 Subject: [PATCH] Update history graph with new hover legend --- web/assets/javascripts/dashboard.js | 39 ++++++++++++++++++++++++-- web/assets/stylesheets/application.css | 22 +++++++++++---- web/views/dashboard.erb | 1 + 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/web/assets/javascripts/dashboard.js b/web/assets/javascripts/dashboard.js index e5ddc8a0..8a2a1bfd 100644 --- a/web/assets/javascripts/dashboard.js +++ b/web/assets/javascripts/dashboard.js @@ -139,10 +139,43 @@ var historyGraph = function() { graph.render(); - var hoverDetail = new Rickshaw.Graph.HoverDetail({ - graph: graph, - yFormatter: function(y) { return Math.floor(y).numberWithDelimiter() }, + var legend = document.querySelector('#history-legend'); + var Hover = Rickshaw.Class.create(Rickshaw.Graph.HoverDetail, { + render: function(args) { + legend.innerHTML = args.formattedXValue; + + args.detail.sort(function(a, b) { return a.order - b.order }).forEach( function(d) { + var line = document.createElement('div'); + line.className = 'line'; + + var swatch = document.createElement('div'); + swatch.className = 'swatch'; + swatch.style.backgroundColor = d.series.color; + + var label = document.createElement('div'); + label.className = 'tag'; + label.innerHTML = d.name + ": " + Math.floor(d.formattedYValue); + + line.appendChild(swatch); + line.appendChild(label); + + legend.appendChild(line); + + var dot = document.createElement('div'); + dot.className = 'dot'; + dot.style.top = graph.y(d.value.y0 + d.value.y) + 'px'; + dot.style.borderColor = d.series.color; + + this.element.appendChild(dot); + + dot.className = 'dot active'; + + this.show(); + + }, this ); + } }); + var hover = new Hover( { graph: graph } ); } var createSeries = function(obj) { diff --git a/web/assets/stylesheets/application.css b/web/assets/stylesheets/application.css index 45586ebe..50e68f54 100755 --- a/web/assets/stylesheets/application.css +++ b/web/assets/stylesheets/application.css @@ -394,33 +394,45 @@ div.interval-slider input { width: 160px; } -#realtime-legend { +#realtime-legend, +#history-legend { width: 490px; text-align: left; margin-top: 5px; float: right; } -#realtime-legend .line { +#realtime-legend .line, +#history-legend .line { display: inline-block; margin: 0 0 0 20px; } -#realtime-legend .swatch { +#realtime-legend .swatch, +#history-legend .swatch { display: inline-block; width: 10px; height: 10px; margin: 0 8px 0 0; } -#realtime-legend .tag { +#realtime-legend .tag, +#history-legend .tag { display: inline-block; } @media (max-width: 790px) { - #realtime-legend { + #realtime-legend, + #history-legend { float: none; width: 100%; margin-bottom: 20px; } } + +@media (max-width: 500px) { + #realtime-legend, + #history-legend { + text-align: center; + } +} /* Beacon ********************************** */ diff --git a/web/views/dashboard.erb b/web/views/dashboard.erb index f1fb3203..b123fd47 100644 --- a/web/views/dashboard.erb +++ b/web/views/dashboard.erb @@ -26,6 +26,7 @@ "><%= t('SixMonths') %>
+

Redis