Skip to content

Commit

Permalink
Remove properties.go and replace functionality with "util/json" and "…
Browse files Browse the repository at this point in the history
…reflect" packages.
  • Loading branch information
kbirk committed Jun 8, 2017
1 parent e0c24fc commit 1caffcb
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 503 deletions.
23 changes: 7 additions & 16 deletions generation/salt/count_tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,15 @@ func (c *CountTile) getTileConfig() (map[string]interface{}, error) {
if err != nil {
return nil, err
}

result := make(map[string]interface{})

setProperty("type", "heatmap", result)
setProperty("xField", c.XField, result)
setProperty("yField", c.YField, result)
if 0 < len(c.valueField) {
setProperty("valueField", c.valueField, result)
}
setProperty("resolution", 1, result)
// Bounds are ignored - salt needs the dataset bounds, not the tile bounds
// in visualization space
// setProperty("bounds.left", c.Left, result)
// setProperty("bounds.right", c.Right, result)
// setProperty("bounds.top", c.Top, result)
// setProperty("bounds.bottom", c.Bottom, result)

return result, nil
return map[string]interface{}{
"type": "heatmap",
"xField": c.XField,
"yField": c.YField,
"valueField": c.valueField,
"resolution": 1,
}, nil
}

func (c *CountTile) convertTile(coord *binning.TileCoord, input []byte) ([]byte, error) {
Expand Down
23 changes: 7 additions & 16 deletions generation/salt/heatmap_tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,15 @@ func (h *HeatmapTile) getTileConfig() (map[string]interface{}, error) {
if err != nil {
return nil, err
}

result := make(map[string]interface{})

setProperty("type", "heatmap", result)
setProperty("xField", h.XField, result)
setProperty("yField", h.YField, result)
if 0 < len(h.valueField) {
setProperty("valueField", h.valueField, result)
}
setProperty("resolution", h.Resolution, result)
// Bounds are ignored - salt needs the dataset bounds, not the tile bounds
// in visualization space
// setProperty("bounds.left", h.Left, result)
// setProperty("bounds.right", h.Right, result)
// setProperty("bounds.top", h.Top, result)
// setProperty("bounds.bottom", h.Bottom, result)

return result, nil
return map[string]interface{}{
"type": "heatmap",
"xField": h.XField,
"yField": h.YField,
"valueField": h.valueField,
"resolution": h.Resolution,
}, nil
}

func (h *HeatmapTile) convertTile(coord *binning.TileCoord, input []byte) ([]byte, error) {
Expand Down
22 changes: 10 additions & 12 deletions generation/salt/macro_edge_tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,16 @@ func (m *MacroEdgeTile) getTileConfig() (map[string]interface{}, error) {
if err != nil {
return nil, err
}

result := make(map[string]interface{})
setProperty("type", "macro-edge", result)
setProperty("srcXField", m.SrcXField, result)
setProperty("srcYField", m.SrcYField, result)
setProperty("dstXField", m.DstXField, result)
setProperty("dstYField", m.DstYField, result)
setProperty("weightField", m.WeightField, result)
setProperty("hitsCount", m.HitsCount, result)
setProperty("lengthSorted", true, result)

return result, nil
return map[string]interface{}{
"type": "macro-edge",
"srcXField": m.SrcXField,
"srcYField": m.SrcYField,
"dstXField": m.DstXField,
"dstYField": m.DstYField,
"weightField": m.WeightField,
"hitsCount": m.HitsCount,
"lengthSorted": true,
}, nil
}

func (m *MacroEdgeTile) convertTile(coord *binning.TileCoord, input []byte) ([]byte, error) {
Expand Down
23 changes: 6 additions & 17 deletions generation/salt/macro_tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,14 @@ func (m *MacroTile) getTileConfig() (map[string]interface{}, error) {
if err != nil {
return nil, err
}

result := make(map[string]interface{})

setProperty("type", "macro", result)

// Bivariate properties
setProperty("xField", m.XField, result)
setProperty("yField", m.YField, result)
setProperty("resolution", m.Resolution, result)
// Bounds are ignored - salt needs the dataset bounds, not the tile bounds
// in visualization space
// setProperty("bounds.left", m.Left, result)
// setProperty("bounds.right", m.Right, result)
// setProperty("bounds.top", m.Top, result)
// setProperty("bounds.bottom", m.Bottom, result)

// Macro properties

return result, nil
return map[string]interface{}{
"type": "macro",
"xField": m.XField,
"yField": m.YField,
"resolution": m.Resolution,
}, nil
}

func (m *MacroTile) convertTile(coord *binning.TileCoord, input []byte) ([]byte, error) {
Expand Down
58 changes: 20 additions & 38 deletions generation/salt/micro_tile.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package salt

import (
"encoding/json"
"fmt"

"github.com/unchartedsoftware/veldt"
"github.com/unchartedsoftware/veldt/binning"
"github.com/unchartedsoftware/veldt/generation/batch"
"github.com/unchartedsoftware/veldt/tile"
"github.com/unchartedsoftware/veldt/util/json"
)

// MicroTile represents a Salt implementation of the micro tile
Expand Down Expand Up @@ -86,30 +86,17 @@ func (m *MicroTile) getTileConfig() (map[string]interface{}, error) {
if err != nil {
return nil, err
}

result := make(map[string]interface{})

setProperty("type", "micro", result)

// Bivariate properties
setProperty("xField", m.XField, result)
setProperty("yField", m.YField, result)
// Resolution is ignored for micro, as it is irrelevant
// setProperty("resolution", m.Resolution, result)
// Bounds are ignored - salt needs the dataset bounds, not the tile bounds
// in visualization space
// setProperty("bounds.left", m.Left, result)
// setProperty("bounds.right", m.Right, result)
// setProperty("bounds.top", m.Top, result)
// setProperty("bounds.bottom", m.Bottom, result)

// TopHits properties
setProperty("sortField", m.SortField, result)
setProperty("sortOrder", m.SortOrder, result)
setProperty("hitsCount", m.HitsCount, result)
setProperty("includeFields", m.IncludeFields, result)

return result, nil
return map[string]interface{}{
"type": "micro",
"xField": m.XField,
"yField": m.YField,
"sortField": m.SortField,
"sortOrder": m.SortOrder,
"hitsCount": m.HitsCount,
"includeFields": m.IncludeFields,
}, nil
}

func (m *MicroTile) convertTile(coord *binning.TileCoord, input []byte) ([]byte, error) {
Expand All @@ -119,8 +106,7 @@ func (m *MicroTile) convertTile(coord *binning.TileCoord, input []byte) ([]byte,
return nil, err
}

var rawHits []map[string]interface{}
err = json.Unmarshal(input, &rawHits)
rawHits, err := json.UnmarshalArray(input)
if nil != err {
return nil, err
}
Expand All @@ -130,22 +116,18 @@ func (m *MicroTile) convertTile(coord *binning.TileCoord, input []byte) ([]byte,
hits := make([]map[string]interface{}, numHits)

for i, hit := range rawHits {
x, err := getFloat32Property("x", hit)
if err != nil {
return nil, err
x, ok := json.GetFloat(hit, "x")
if !ok {
return nil, fmt.Errorf("could not parse x from hit: %v", hit)
}
y, err := getFloat32Property("y", hit)
if err != nil {
return nil, err
y, ok := json.GetFloat(hit, "y")
if !ok {
return nil, fmt.Errorf("could not parse x from hit: %v", hit)
}
points[2*i+0] = x
points[2*i+1] = 256 - y
points[2*i+0] = float32(x)
points[2*i+1] = 256 - float32(y)

hitMapRaw, err := getProperty("values", hit)
if err != nil {
return nil, err
}
hitMap, ok := hitMapRaw.(map[string]interface{})
hitMap, ok := json.GetChild(hit, "values")
if !ok {
return nil, fmt.Errorf("values didn't form a map: %v", hit)
}
Expand Down
Loading

0 comments on commit 1caffcb

Please sign in to comment.