From c12e67a35ab55a46e0d529ece2f66dbdd0d8bb71 Mon Sep 17 00:00:00 2001 From: Mokaddem Date: Wed, 17 Aug 2016 10:43:43 +0200 Subject: [PATCH] Added tooltips + slight gauge modification --- bin/packages/Paste.py | 2 +- var/www/static/js/sentiment_plot.js | 1 - var/www/static/js/sentiment_trending.js | 20 +++++++++-- .../sentiment_analysis_trending.html | 33 ++++++++++--------- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/bin/packages/Paste.py b/bin/packages/Paste.py index eb5dd320..d91018bd 100755 --- a/bin/packages/Paste.py +++ b/bin/packages/Paste.py @@ -157,7 +157,7 @@ class Paste(object): self.p_nb_lines = line_id self.p_max_length_line = max_length_line - return (self.p_nb_lines, self.p_max_length_line, array_line_above_threshold) + return (self.p_nb_lines, self.p_max_length_line) def _get_p_encoding(self): """ diff --git a/var/www/static/js/sentiment_plot.js b/var/www/static/js/sentiment_plot.js index 2b1ab230..b8541247 100644 --- a/var/www/static/js/sentiment_plot.js +++ b/var/www/static/js/sentiment_plot.js @@ -65,7 +65,6 @@ function plotData(){ // retreive the data from the server $.getJSON('/sentiment_analysis_plot_tool_getdata/?getProviders=False&query='+query+'&Qdate='+Qdate, function(data){ - console.log(data); var to_plot = []; for (provider in data){ var nltk_data = Object.keys(data[provider]).map(function (key) { return data[provider][key]; }); diff --git a/var/www/static/js/sentiment_trending.js b/var/www/static/js/sentiment_trending.js index be85fbdb..2872c502 100644 --- a/var/www/static/js/sentiment_trending.js +++ b/var/www/static/js/sentiment_trending.js @@ -54,10 +54,13 @@ $.getJSON("/sentiment_analysis_getplotdata/", var all_graph_day_sum = 0.0; var all_graph_hour_sum = 0.0; + var all_graph_hour_maxVal = 0.0; var all_day_avg = 0.0; + var all_day_avg_maxVal = 0.0; for (graphNum=0; graphNum<8; graphNum++) { var max_value = 0.0; + var max_value_day = 0.0; var graph_data = []; var spark_data = []; var curr_provider = array_provider[graphNum]; @@ -102,10 +105,11 @@ $.getJSON("/sentiment_analysis_getplotdata/", max_value = Math.abs(pos-neg) > max_value ? Math.abs(pos-neg) : max_value; if(curr_date >= dateStart+oneWeek-23*oneHour){ + max_value_day = Math.abs(pos-neg) > max_value_day ? Math.abs(pos-neg) : max_value_day; day_sum += (pos-neg); day_sum_elem++; } - if(curr_date >= dateStart+oneWeek-oneHour){ + if(curr_date > dateStart+oneWeek-2*oneHour && curr_date <=dateStart+oneWeek-oneHour){ hour_sum += (pos-neg); } @@ -113,6 +117,7 @@ $.getJSON("/sentiment_analysis_getplotdata/", } all_graph_day_sum += day_sum; all_graph_hour_sum += hour_sum; + all_graph_hour_maxVal = Math.abs(hour_sum) > all_graph_hour_maxVal ? Math.abs(hour_sum) : all_graph_hour_maxVal; var curr_avg = curr_sum / (curr_sum_elem); //var curr_avg = curr_sum / (oneWeek/oneHour); @@ -138,7 +143,11 @@ $.getJSON("/sentiment_analysis_getplotdata/", $(placeholder+'b').sparkline([curr_avg], sparklineOptions); sparklineOptions.tooltipFormat = ' {{offset:names}}, {{value}} ' sparklineOptions.barWidth = 2; + + sparklineOptions.tooltipValueLookups = { names: offset_to_time}; + sparklineOptions.chartRangeMax = max_value_day; + sparklineOptions.chartRangeMin = -max_value_day; // print today var data_length = plot_data[graphNum].length; @@ -155,6 +164,7 @@ $.getJSON("/sentiment_analysis_getplotdata/", var day_avg = isNaN(day_sum/day_sum_elem) ? 0 : day_sum/day_sum_elem; var day_avg_text = isNaN(day_sum/day_sum_elem) ? 'No data' : (day_avg).toFixed(5); all_day_avg += day_avg; + all_day_avg_maxVal = Math.abs(day_avg) > all_day_avg_maxVal ? Math.abs(day_avg) : all_day_avg_maxVal; $(placeholder+'b').sparkline([day_avg], sparklineOptions); sparklineOptions.tooltipFormat = ' {{offset:names}}, {{value}} ' sparklineOptions.barWidth = 2; @@ -194,7 +204,7 @@ $.getJSON("/sentiment_analysis_getplotdata/", gaugeOptions.appendTo = '#gauge_today_last_hour'; gaugeOptions.dialLabel = 'Last hour'; gaugeOptions.elementId = 'gauge1'; - var piePercent = (all_graph_hour_sum / 8) / max_value; + var piePercent = (all_graph_hour_sum / 8) / all_graph_hour_maxVal; gaugeOptions.inc = piePercent; var gauge_today_last_hour = new FlexGauge(gaugeOptions); @@ -202,7 +212,7 @@ $.getJSON("/sentiment_analysis_getplotdata/", gaugeOptions2.dialLabel = 'Today'; gaugeOptions2.elementId = 'gauge2'; //piePercent = (all_graph_day_sum / (8*24)) / max_value; - piePercent = (all_day_avg / 8) / max_value; + piePercent = (all_day_avg / 8) / all_day_avg_maxVal; gaugeOptions2.inc = piePercent; var gauge_today_last_days = new FlexGauge(gaugeOptions2); @@ -268,6 +278,7 @@ $.getJSON("/sentiment_analysis_getplotdata/", }, data: [ { + toolTipContent: "Positive: {y}", type: "bar", color: "green", dataPoints: [ @@ -275,6 +286,7 @@ $.getJSON("/sentiment_analysis_getplotdata/", ] }, { + toolTipContent: "Negative: {y}", type: "bar", color: "red", dataPoints: [ @@ -302,6 +314,7 @@ $.getJSON("/sentiment_analysis_getplotdata/", }, data: [ { + toolTipContent: "Positive: {y}", type: "bar", color: "green", dataPoints: [ @@ -309,6 +322,7 @@ $.getJSON("/sentiment_analysis_getplotdata/", ] }, { + toolTipContent: "Negative: {y}", type: "bar", color: "red", dataPoints: [ diff --git a/var/www/templates/sentiment_analysis_trending.html b/var/www/templates/sentiment_analysis_trending.html index 1f74f4a3..709eb694 100644 --- a/var/www/templates/sentiment_analysis_trending.html +++ b/var/www/templates/sentiment_analysis_trending.html @@ -110,7 +110,7 @@
- Today's mood + Today's mood
@@ -256,15 +256,15 @@
- Mood value + Mood value
- Compound by mood + Compound by mood
- Mood value + Mood value
- Compound by mood + Compound by mood
@@ -432,7 +432,7 @@
- Mood value + Mood value
@@ -445,24 +445,24 @@ - Pastebin - Ideone + worst1 + best1 - Pastebin - Ideone + worst2 + best2 - Pastebin - Ideone + worst3 + best3 - Pastebin - Ideone + worst4 + best4 - Pastebin - Ideone + worst5 + best5 @@ -495,6 +495,7 @@ $(document).ready(function(){ activePage = $('h1.page-header').attr('data-page'); $("#"+activePage).addClass("active"); + $('[data-toggle="tooltip"]').tooltip(); // Reload every 30min setTimeout(function(){ location.reload(); }, 30*60*1000);