1

Work in progress

This commit is contained in:
Alex Yatskov 2015-06-27 13:53:26 +09:00
parent db7ad681ff
commit af91fbc5ae
4 changed files with 56 additions and 33 deletions

View File

@ -58,12 +58,14 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
response := jsonQueryResponse{
Count: len(foundEntries),
Ranges: make(map[string]jsonRange),
Columns: make(map[string]jsonColumn),
Records: make([]jsonRecord, 0)}
for name, value := range features {
column := jsonColumn{Value: value, Steps: request.Resolution}
column := jsonColumn{
Bracket: jsonBracket{Max: -1, Min: 1},
Value: value,
Steps: request.Resolution}
hints := project(
entries,
@ -77,23 +79,17 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
column.Hints = append(column.Hints, jsonHint)
}
for _, record := range foundEntries {
if feature, ok := record.features[name]; ok {
column.Bracket.Max = math.Max(column.Bracket.Max, feature)
column.Bracket.Min = math.Min(column.Bracket.Min, feature)
}
}
response.Columns[name] = column
}
for index, record := range foundEntries {
for feature, value := range record.features {
rng, ok := response.Ranges[feature]
if ok {
rng.Max = math.Max(rng.Max, value)
rng.Min = math.Min(rng.Min, value)
} else {
rng.Max = value
rng.Min = value
}
response.Ranges[feature] = rng
}
if index >= request.MaxResults {
break
}

View File

@ -96,6 +96,7 @@
var _onValueChanged = params.onValueChanged;
var _range = params.range;
var _scale = params.scale;
var _bracket = params.bracket;
var _elements = {};
function createShapes() {
@ -121,16 +122,6 @@
stroke: _borderColor
});
// bracket
_elements.bracket = _canvas.rect(
_width - _bracketSize,
0,
_bracketSize,
_height - _panelSize
).attr({
fill: '#ff0000'
});
// panel
_elements.panel = _canvas.rect(
_tickSize,
@ -163,6 +154,26 @@
fill: computeIndicatorColor(_data.value)
}).click(clicked);
console.log(_data);
// bracketMin
_elements.bracketMin = _canvas.circle(
_width - _bracketSize / 2,
valueToIndicator(_data.bracket.min),
5
).attr({
fill: '#0000ff'
});
// bracketMax
_elements.bracketMax = _canvas.circle(
_width - _bracketSize / 2,
valueToIndicator(_data.bracket.max),
5
).attr({
fill: '#ff0000'
});
// tick
if (_range.contains(0.0)) {
var origin = valueToIndicator(0.0);
@ -180,7 +191,8 @@
_elements.backdrop,
_elements.indicator,
_elements.density,
_elements.bracket,
_elements.bracketMin,
_elements.bracketMax,
_elements.panel,
_elements.tick,
_elements.label
@ -204,6 +216,16 @@
_valueAnimated = value;
}
function updateBracket() {
_elements.bracketMin.attr({
y: _data.bracket.min
});
_elements.bracketMax.attr({
y: _data.bracket.max
});
}
function updateDensity() {
var fill = _backdropColor;
if (_data.hints.length > 0) {
@ -313,6 +335,10 @@
_data.hints = data.hints;
updateDensity();
}
if (_.has(data, 'bracket')) {
_data.bracket = data.bracket;
updateBracket();
}
};
createShapes();

View File

@ -119,8 +119,9 @@
var column = results.columns[feature];
_ctx.query.features[feature] = column.value;
columns[feature] = {
value: column.value,
hints: column.hints
value: column.value,
hints: column.hints,
bracket: column.bracket
};
}

View File

@ -49,9 +49,10 @@ type jsonQueryRequest struct {
}
type jsonColumn struct {
Hints []jsonProjection `json:"hints"`
Steps int `json:"steps"`
Value float64 `json:"value"`
Bracket jsonBracket `json:"bracket"`
Hints []jsonProjection `json:"hints"`
Steps int `json:"steps"`
Value float64 `json:"value"`
}
type jsonProjection struct {
@ -72,7 +73,7 @@ type jsonRecord struct {
Url string `json:"url"`
}
type jsonRange struct {
type jsonBracket struct {
Min float64 `json:"min"`
Max float64 `json:"max"`
}
@ -80,7 +81,6 @@ type jsonRange struct {
type jsonQueryResponse struct {
Columns map[string]jsonColumn `json:"columns"`
Count int `json:"count"`
Ranges map[string]jsonRange `json:"ranges"`
Records []jsonRecord `json:"records"`
}