1

History slider now more or less working

This commit is contained in:
Alex Yatskov 2014-10-15 16:26:47 +09:00
parent 3cfe23f795
commit 0ae92d1957
3 changed files with 22 additions and 21 deletions

View File

@ -126,8 +126,8 @@
</div>
<div style="padding: 10px;">
<canvas id="grapher" width="800" height="550"></canvas>
<div class="text-center">
<input id="history" style="width: 90%" type="text" data-slider-max="0">
<div class="text-center" style="display: none;">
<input id="history" style="width: 90%;" type="text" data-slider-reversed="true" data-slider-max="0">
</div>
</div>
</div>

View File

@ -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);
}

View File

@ -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) {
_.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);
});
};