1
This commit is contained in:
Alex Yatskov 2014-07-28 16:38:03 +09:00
parent 7401359144
commit 696049aa76

View File

@ -1,5 +1,7 @@
'use strict';
var app = { };
function outputResults(results, maxResults) {
$('#results').empty();
$('#count').text(results.length);
@ -11,18 +13,15 @@ function outputResults(results, maxResults) {
}
function onAdjust(name, value) {
var wa = window.adjuster;
var wg = window.grapher;
wa.searchParams[name] = value;
console.log(wa.searchParams);
app.searchParams[name] = value;
console.log(app.searchParams);
var params = {
searchParams: wa.searchParams,
searchRange: wa.searchRange,
minScore: wa.minScore,
hintSteps: wa.hintSteps,
maxResults: wa.maxResults
searchParams: app.searchParams,
searchRange: app.searchRange,
minScore: app.minScore,
hintSteps: app.hintSteps,
maxResults: app.maxResults
};
$.getJSON('/node/search', params, function(results) {
@ -31,48 +30,44 @@ function onAdjust(name, value) {
hintData[feature] = results.columns[feature].hints;
}
wg.setColumnHints(hintData);
app.grapher.setColumnHints(hintData);
outputResults(results.items, params.maxResults);
});
}
function onSearch() {
var params = {
keyword: $('#keyword').val(),
searchRange: { min: -1.0, max: 1.0 },
minScore: parseInt($('#minScore').val()),
hintSteps: parseInt($('#hintSteps').val()),
maxResults: parseInt($('#maxResults').val()),
useLocalScale: true,
useRelativeScale: true
keyword: $('#keyword').val(),
searchRange: { min: -1.0, max: 1.0 },
minScore: parseInt($('#minScore').val()),
hintSteps: parseInt($('#hintSteps').val()),
maxResults: parseInt($('#maxResults').val())
};
$.getJSON('/node/search', params, function(results) {
window.adjuster = {
searchParams: results.params,
searchRange: params.searchRange,
minScore: params.minScore,
hintSteps: params.hintSteps,
maxResults: params.maxResults
};
app.searchParams = results.params;
app.searchRange = params.searchRange;
app.minScore = params.minScore;
app.hintSteps = params.hintSteps;
app.maxResults = params.maxResults;
window.grapher = new Grapher('grapher', new goog.math.Range(-1.0, 1.0), params.useLocalScale, params.useRelativeScale);
window.grapher.setColumns(results.columns);
window.grapher.setValueChangedListener(onAdjust);
app.grapher = new Grapher('grapher', new goog.math.Range(-1.0, 1.0), true, true);
app.grapher.setColumns(results.columns);
app.grapher.setValueChangedListener(onAdjust);
outputResults(results.items, params.maxResults);
$('#query').text(params.keyword);
$('#useLocalScale').prop('checked', useLocalScale);
$('#useRelativeScale').prop('checked', useRelativeScale);
$('#useLocalScale').click(function() {
var useLocalScale = $('#useLocalScale').is(':checked');
window.grapher.setUseLocalScale(useLocalScale);
app.grapher.setUseLocalScale(useLocalScale);
});
$('#useRelativeScale').click(function() {
var useRelativeScale = $('#useRelativeScale').is(':checked');
window.grapher.setUseRelativeScale(useRelativeScale);
app.grapher.setUseRelativeScale(useRelativeScale);
});
$('#input').fadeOut(function() {
$('#output').fadeIn();
});
@ -82,10 +77,8 @@ function onSearch() {
$(document).ready(function() {
$.getJSON('/node/keywords', function(keywords) {
for (var i = 0; i < keywords.length; ++i) {
$('#keyword').append($('<option></option>', {
'value': keywords[i],
'text': keywords[i]
}));
var properties = { value: keywords[i], text: keywords[i] };
$('#keyword').append($('<option></option>', properties));
}
$('#search').prop('disabled', false);