Skip to content

Commit

Permalink
cytoscapejs: fix optional field marshaling and helper type naming
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Oct 26, 2018
1 parent f098207 commit be44418
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions graph/formats/cytoscapejs/cytoscapejs.go
Expand Up @@ -24,8 +24,8 @@ type GraphElem struct {
type Element struct {
Group string `json:"group,omitempty"`
Data ElemData `json:"data"`
Position Position `json:"position,omitempty"`
RenderedPosition Position `json:"renderedPosition,omitempty"`
Position *Position `json:"position,omitempty"`
RenderedPosition *Position `json:"renderedPosition,omitempty"`
Selected bool `json:"selected,omitempty"`
Selectable bool `json:"selectable,omitempty"`
Locked bool `json:"locked,omitempty"`
Expand Down Expand Up @@ -85,13 +85,13 @@ var (
// MarshalJSON implements the json.Marshaler interface.
func (e *ElemData) MarshalJSON() ([]byte, error) {
if e.Attributes == nil {
type edge struct {
type elem struct {
ID string `json:"id"`
Source string `json:"source"`
Target string `json:"target"`
Source string `json:"source,omitempty"`
Target string `json:"target,omitempty"`
Parent string `json:"parent,omitempty"`
}
return json.Marshal(edge{ID: e.ID, Source: e.Source, Target: e.Target, Parent: e.Parent})
return json.Marshal(elem{ID: e.ID, Source: e.Source, Target: e.Target, Parent: e.Parent})
}
e.Attributes["id"] = e.ID
if e.Source != "" {
Expand Down Expand Up @@ -167,8 +167,8 @@ type Elements struct {
// Node is a Cytoscape.js node.
type Node struct {
Data NodeData `json:"data"`
Position Position `json:"position,omitempty"`
RenderedPosition Position `json:"renderedPosition,omitempty"`
Position *Position `json:"position,omitempty"`
RenderedPosition *Position `json:"renderedPosition,omitempty"`
Selected bool `json:"selected,omitempty"`
Selectable bool `json:"selectable,omitempty"`
Locked bool `json:"locked,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion graph/formats/cytoscapejs/cytoscapejs_test.go
Expand Up @@ -181,7 +181,7 @@ var cytoscapejsNodeEdgeTests = []struct {
"y": -357509.32,
},
},
Position: Position{
Position: &Position{
X: 1398668.75,
Y: -357509.32,
},
Expand Down

0 comments on commit be44418

Please sign in to comment.