1

Renaming things

This commit is contained in:
Alex Yatskov 2015-06-28 13:30:22 +09:00
parent 201c2e49ce
commit cfaded9896
4 changed files with 53 additions and 28 deletions

View File

@ -59,6 +59,7 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
response := jsonQueryResponse{ response := jsonQueryResponse{
Count: len(foundEntries), Count: len(foundEntries),
Columns: make(map[string]jsonColumn), Columns: make(map[string]jsonColumn),
MinScore: request.MinScore,
Records: make([]jsonRecord, 0)} Records: make([]jsonRecord, 0)}
for name, value := range features { for name, value := range features {

View File

@ -99,7 +99,7 @@
var _name = params.name; var _name = params.name;
var _valueTrans = params.data.value; var _valueTrans = params.data.value;
var _bracketTrans = params.data.bracket; var _bracketTrans = params.data.bracket;
var _onValueChanged = params.onValueChanged; var _onStateChanged = params.onStateChanged;
var _range = params.range; var _range = params.range;
var _scale = params.scale; var _scale = params.scale;
var _elements = {}; var _elements = {};
@ -324,13 +324,25 @@
return colorStops; return colorStops;
} }
function updateValue(value, bracket) { function updateState(value, bracket) {
_data.value = _range.clamp(value); var updateBracket = bracket !== null;
var updateValue = value !== null;
if (updateBracket) {
_data.bracket.max = _range.clamp(bracket.max); _data.bracket.max = _range.clamp(bracket.max);
_data.bracket.min = _range.clamp(bracket.min); _data.bracket.min = _range.clamp(bracket.min);
}
if (_onValueChanged) { if (updateValue) {
_onValueChanged(_name, _data.value, _data.bracket); _data.value = _range.clamp(value);
}
if (_onStateChanged) {
_onStateChanged(
_name,
updateValue ? _data.value : null,
updateBracket ? _data.bracket : null
);
} }
animateIndicator(_valueTrans, _data.value); animateIndicator(_valueTrans, _data.value);
@ -431,7 +443,7 @@
function indicatorClick(event, x, y) { function indicatorClick(event, x, y) {
var rect = _canvas.node.getBoundingClientRect(); var rect = _canvas.node.getBoundingClientRect();
updateValue(indicatorToValue(y - rect.top), _data.bracket); updateState(indicatorToValue(y - rect.top), null);
} }
function bracketClick(event, x, y) { function bracketClick(event, x, y) {
@ -442,7 +454,7 @@
dist = Math.min(dist, Math.abs(_range.max - mid)); dist = Math.min(dist, Math.abs(_range.max - mid));
dist = Math.min(dist, Math.abs(_range.min - mid)); dist = Math.min(dist, Math.abs(_range.min - mid));
updateValue(_data.value, {max: mid + dist, min: mid - dist}); updateState(_data.value, {max: mid + dist, min: mid - dist});
} }
this.update = function(data, scale) { this.update = function(data, scale) {
@ -477,7 +489,7 @@
var _range = new Range(-1.0, 1.0); var _range = new Range(-1.0, 1.0);
var _useLocalScale = params.useLocalScale || false; var _useLocalScale = params.useLocalScale || false;
var _displayType = params.displayType || 'density'; var _displayType = params.displayType || 'density';
var _onValueChanged = params.onValueChanged; var _onStateChanged = params.onStateChanged;
function processHintParameters(columns) { function processHintParameters(columns) {
var displayTypes = {compatibility: 'compatibility', density: 'count'}; var displayTypes = {compatibility: 'compatibility', density: 'count'};
@ -535,7 +547,7 @@
} }
else { else {
_columns[name] = new Column({ _columns[name] = new Column({
onValueChanged: _onValueChanged, onStateChanged: _onStateChanged,
range: _range, range: _range,
canvas: _canvas, canvas: _canvas,
data: columnData, data: columnData,

View File

@ -25,8 +25,9 @@
var _ctx = {}; var _ctx = {};
function onAdjust(name, value, bracket) { function onStateChanged(name, value, bracket) {
_ctx.query.features[name] = value; _ctx.query.features[name] = value;
_ctx.query.bracket = bracket === null ? null : {name: name, bracket: bracket};
$.post('/query', JSON.stringify(_ctx.query), function(results) { $.post('/query', JSON.stringify(_ctx.query), function(results) {
saveSnapshot(results); saveSnapshot(results);
@ -77,6 +78,7 @@
function onSearch() { function onSearch() {
_ctx.query = { _ctx.query = {
features: _ctx.query.features || {}, features: _ctx.query.features || {},
bracket: null,
sortKey: _ctx.sortKey, sortKey: _ctx.sortKey,
sortAsc: _ctx.sortAsc, sortAsc: _ctx.sortAsc,
profile: getProfile(), profile: getProfile(),
@ -97,7 +99,7 @@
if (!_.has(_ctx, 'grapher')) { if (!_.has(_ctx, 'grapher')) {
_ctx.grapher = new grapher.Grapher({ _ctx.grapher = new grapher.Grapher({
canvas: new Snap('#svg'), canvas: new Snap('#svg'),
onValueChanged: onAdjust, onStateChanged: onStateChanged,
displayType: $('#displayType').val(), displayType: $('#displayType').val(),
useLocalScale: $('#useLocalScale').is(':checked') useLocalScale: $('#useLocalScale').is(':checked')
}); });
@ -138,6 +140,9 @@
} }
function outputSnapshot(results, omitValues) { function outputSnapshot(results, omitValues) {
_ctx.query.minScore = results.minScore;
$('#minScore').val(results.minScore);
var columns = {}; var columns = {};
for (var name in results.columns) { for (var name in results.columns) {
var column = results.columns[name]; var column = results.columns[name];

View File

@ -37,6 +37,7 @@ type jsonGeoData struct {
} }
type jsonQueryRequest struct { type jsonQueryRequest struct {
Bracket *jsonNamedBracket `json:"bracket"`
Features featureMap `json:"features"` Features featureMap `json:"features"`
Geo *jsonGeoData `json:"geo"` Geo *jsonGeoData `json:"geo"`
MaxResults int `json:"maxResults"` MaxResults int `json:"maxResults"`
@ -78,9 +79,15 @@ type jsonBracket struct {
Max float64 `json:"max"` Max float64 `json:"max"`
} }
type jsonNamedBracket struct {
Bracket string `json:"bracket"`
Name string `json:"name"`
}
type jsonQueryResponse struct { type jsonQueryResponse struct {
Columns map[string]jsonColumn `json:"columns"` Columns map[string]jsonColumn `json:"columns"`
Count int `json:"count"` Count int `json:"count"`
MinScore float64 `json:"minScore"`
Records []jsonRecord `json:"records"` Records []jsonRecord `json:"records"`
} }