From cfaded989685d0c4d9643dbaf616e3de46b2a8a7 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 28 Jun 2015 13:30:22 +0900 Subject: [PATCH] Renaming things --- server.go | 7 ++++--- static/scripts/grapher.js | 34 +++++++++++++++++++++++----------- static/scripts/search.js | 9 +++++++-- types.go | 31 +++++++++++++++++++------------ 4 files changed, 53 insertions(+), 28 deletions(-) diff --git a/server.go b/server.go index 12803d1..f5ed98d 100644 --- a/server.go +++ b/server.go @@ -57,9 +57,10 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) { sorter.sort() response := jsonQueryResponse{ - Count: len(foundEntries), - Columns: make(map[string]jsonColumn), - Records: make([]jsonRecord, 0)} + Count: len(foundEntries), + Columns: make(map[string]jsonColumn), + MinScore: request.MinScore, + Records: make([]jsonRecord, 0)} for name, value := range features { column := jsonColumn{ diff --git a/static/scripts/grapher.js b/static/scripts/grapher.js index 4a2c609..ccca765 100644 --- a/static/scripts/grapher.js +++ b/static/scripts/grapher.js @@ -99,7 +99,7 @@ var _name = params.name; var _valueTrans = params.data.value; var _bracketTrans = params.data.bracket; - var _onValueChanged = params.onValueChanged; + var _onStateChanged = params.onStateChanged; var _range = params.range; var _scale = params.scale; var _elements = {}; @@ -324,13 +324,25 @@ return colorStops; } - function updateValue(value, bracket) { - _data.value = _range.clamp(value); - _data.bracket.max = _range.clamp(bracket.max); - _data.bracket.min = _range.clamp(bracket.min); + function updateState(value, bracket) { + var updateBracket = bracket !== null; + var updateValue = value !== null; - if (_onValueChanged) { - _onValueChanged(_name, _data.value, _data.bracket); + if (updateBracket) { + _data.bracket.max = _range.clamp(bracket.max); + _data.bracket.min = _range.clamp(bracket.min); + } + + if (updateValue) { + _data.value = _range.clamp(value); + } + + if (_onStateChanged) { + _onStateChanged( + _name, + updateValue ? _data.value : null, + updateBracket ? _data.bracket : null + ); } animateIndicator(_valueTrans, _data.value); @@ -431,7 +443,7 @@ function indicatorClick(event, x, y) { var rect = _canvas.node.getBoundingClientRect(); - updateValue(indicatorToValue(y - rect.top), _data.bracket); + updateState(indicatorToValue(y - rect.top), null); } 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.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) { @@ -477,7 +489,7 @@ var _range = new Range(-1.0, 1.0); var _useLocalScale = params.useLocalScale || false; var _displayType = params.displayType || 'density'; - var _onValueChanged = params.onValueChanged; + var _onStateChanged = params.onStateChanged; function processHintParameters(columns) { var displayTypes = {compatibility: 'compatibility', density: 'count'}; @@ -535,7 +547,7 @@ } else { _columns[name] = new Column({ - onValueChanged: _onValueChanged, + onStateChanged: _onStateChanged, range: _range, canvas: _canvas, data: columnData, diff --git a/static/scripts/search.js b/static/scripts/search.js index 4856286..6242b68 100644 --- a/static/scripts/search.js +++ b/static/scripts/search.js @@ -25,8 +25,9 @@ var _ctx = {}; - function onAdjust(name, value, bracket) { + function onStateChanged(name, value, bracket) { _ctx.query.features[name] = value; + _ctx.query.bracket = bracket === null ? null : {name: name, bracket: bracket}; $.post('/query', JSON.stringify(_ctx.query), function(results) { saveSnapshot(results); @@ -77,6 +78,7 @@ function onSearch() { _ctx.query = { features: _ctx.query.features || {}, + bracket: null, sortKey: _ctx.sortKey, sortAsc: _ctx.sortAsc, profile: getProfile(), @@ -97,7 +99,7 @@ if (!_.has(_ctx, 'grapher')) { _ctx.grapher = new grapher.Grapher({ canvas: new Snap('#svg'), - onValueChanged: onAdjust, + onStateChanged: onStateChanged, displayType: $('#displayType').val(), useLocalScale: $('#useLocalScale').is(':checked') }); @@ -138,6 +140,9 @@ } function outputSnapshot(results, omitValues) { + _ctx.query.minScore = results.minScore; + $('#minScore').val(results.minScore); + var columns = {}; for (var name in results.columns) { var column = results.columns[name]; diff --git a/types.go b/types.go index f11e225..725c40c 100644 --- a/types.go +++ b/types.go @@ -37,15 +37,16 @@ type jsonGeoData struct { } type jsonQueryRequest struct { - Features featureMap `json:"features"` - Geo *jsonGeoData `json:"geo"` - MaxResults int `json:"maxResults"` - MinScore float64 `json:"minScore"` - Profile featureMap `json:"profile"` - Resolution int `json:"resolution"` - SortAsc bool `json:"sortAsc"` - SortKey string `json:"sortKey"` - WalkingDist float64 `json:"walkingDist"` + Bracket *jsonNamedBracket `json:"bracket"` + Features featureMap `json:"features"` + Geo *jsonGeoData `json:"geo"` + MaxResults int `json:"maxResults"` + MinScore float64 `json:"minScore"` + Profile featureMap `json:"profile"` + Resolution int `json:"resolution"` + SortAsc bool `json:"sortAsc"` + SortKey string `json:"sortKey"` + WalkingDist float64 `json:"walkingDist"` } type jsonColumn struct { @@ -78,10 +79,16 @@ type jsonBracket struct { Max float64 `json:"max"` } +type jsonNamedBracket struct { + Bracket string `json:"bracket"` + Name string `json:"name"` +} + type jsonQueryResponse struct { - Columns map[string]jsonColumn `json:"columns"` - Count int `json:"count"` - Records []jsonRecord `json:"records"` + Columns map[string]jsonColumn `json:"columns"` + Count int `json:"count"` + MinScore float64 `json:"minScore"` + Records []jsonRecord `json:"records"` } type jsonCategory struct {