From 0ae92d1957a63c0be5692d0442b8ba90087d58fb Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 15 Oct 2014 16:26:47 +0900 Subject: [PATCH] History slider now more or less working --- client/html/index.html | 4 ++-- client/scripts/application.js | 22 ++++++++++------------ client/scripts/grapher.js | 17 ++++++++++------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/client/html/index.html b/client/html/index.html index 80ca9c4..f3a12e5 100644 --- a/client/html/index.html +++ b/client/html/index.html @@ -126,8 +126,8 @@
-
- +
diff --git a/client/scripts/application.js b/client/scripts/application.js index 7a69980..f35ecaf 100644 --- a/client/scripts/application.js +++ b/client/scripts/application.js @@ -94,7 +94,6 @@ function onLearn() { $('#learnKeyword').prop('disabled', true); - $('#learnError').slideUp(function() { var query = { keyword: $('#keywordToLearn').val(), @@ -116,7 +115,6 @@ function onForget() { $('#forgetKeyword').prop('disabled', true); - $('#forgetError').slideUp(function() { var query = { keyword: $('#keywordToForget').val() @@ -136,25 +134,25 @@ } function onSelectSnapshot() { - var snapshot = $('#history').slider('getValue'); - outputSnapshot(log[snapshot]); + var index = $('#history').slider('getValue'); + outputSnapshot(log[index]); } function saveSnapshot(results) { log.push(results); + var count = log.length; var history = $('#history').slider(); - history.slider('setAttribute', 'max', log.length - 1); - history.slider('setValue', log.length - 1); + history.slider('setAttribute', 'max', count - 1); + history.slider('setValue', count - 1); + + if (count > 1) { + $('#history').parent().slideDown(); + } } function outputSnapshot(results) { - var hintData = {}; - for (var keyword in results.columns) { - hintData[keyword] = results.columns[keyword].hints; - } - - ctx.grapher.setColumnHints(hintData); + ctx.grapher.updateColumns(results.columns); outputMatches(results.items, results.count); } diff --git a/client/scripts/grapher.js b/client/scripts/grapher.js index 3fadbe4..b5c31d6 100644 --- a/client/scripts/grapher.js +++ b/client/scripts/grapher.js @@ -277,8 +277,10 @@ } }; - this.setHints = function(hints, scale) { - this.hints = hints; + this.updateParams = function(params, scale) { + this.hints = params.hints; + this.value = params.value; + this.steps = params.steps; this.scale = scale; this.updateShapes(true); }; @@ -527,22 +529,23 @@ this.indexMap = {}; }; - this.setColumnHints = function(hintData) { + this.updateColumns = function(data) { var scale = 0; if (!this.useLocalScale) { scale = this.getGlobalScale(hintData); } - var that = this; - _.each(hintData, function(hints, name) { + var that = this; + _.each(data, function(entry, name) { var index = that.getColumnIndex(name); console.assert(index >= 0); if (that.useLocalScale) { - scale = that.getLocalScale(hints); + scale = that.getLocalScale(entry.hints); } - that.columns[index].setHints(hints, scale); + var column = that.columns[index]; + column.updateParams(entry, scale); }); };