Skip to content

Commit

Permalink
Merge pull request #161 from MUzairS15/assign-correct-position
Browse files Browse the repository at this point in the history
assign correct position during conversion
  • Loading branch information
MUzairS15 authored Aug 29, 2024
2 parents 411ef8e + 20461a2 commit 7f04bfc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions models/v1beta1/component/component.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions models/v1beta1/pattern/design_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ import (
"github.com/meshery/schemas/models/v1beta1/component"
"github.com/meshery/schemas/models/v1beta1/model"
"github.com/pkg/errors"
"gonum.org/v1/gonum/graph/formats/cytoscapejs"
)

type position struct {
X float64 `json:"posX" yaml:"posX"`
Y float64 `json:"posY" yaml:"posY"`
}

// The pattern file indicated by "p", is converted to the version pointed by "pattern", the version of the patternFile which implements the Hub interface indicates the version the conversion will happen.
// Only one version of the resource (patternfile in this case) should implement the Hub interface.
// "pattern" parameter acts as the destination and "p" the source.
Expand Down Expand Up @@ -165,23 +169,23 @@ func (p *PatternFile) convertFromTraits(cmp *component.ComponentDefinition, serv

randY, _ := rand.Int(rand.Reader, big.NewInt(100))

positionX, _ := big.NewFloat(0).SetInt(randX).Float32()
positionY, _ := big.NewFloat(0).SetInt(randY).Float32()
positionX, _ := big.NewFloat(0).SetInt(randX).Float64()
positionY, _ := big.NewFloat(0).SetInt(randY).Float64()

cmp.Styles = &component.Styles{
Position: &struct {
X float32 "json:\"x\" yaml:\"x\""
Y float32 "json:\"y\" yaml:\"y\""
X float64 "json:\"x\" yaml:\"x\""
Y float64 "json:\"y\" yaml:\"y\""
}{
X: positionX,
Y: positionY,
},
}

pos, ok := extensionsMetadata["position"].(cytoscapejs.Position)
if ok {
cmp.Styles.Position.X, _ = big.NewFloat(pos.X).Float32()
cmp.Styles.Position.Y, _ = big.NewFloat(pos.Y).Float32()
pos, err := utils.MarshalAndUnmarshal[interface{}, position](extensionsMetadata["position"])
if err == nil {
cmp.Styles.Position.X, _ = big.NewFloat(pos.X).Float64()
cmp.Styles.Position.Y, _ = big.NewFloat(pos.Y).Float64()
}

cmp.Metadata.AdditionalProperties = make(map[string]interface{}, 0)
Expand Down Expand Up @@ -221,7 +225,7 @@ func (p *PatternFile) convertToTraits(service *v1alpha2.Service, component *comp
}

func (p *PatternFile) convertFromSettings(component *component.ComponentDefinition, service *v1alpha2.Service) error {

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

if service.Labels != nil {
Expand Down
6 changes: 4 additions & 2 deletions schemas/constructs/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@
"properties": {
"x": {
"type": "number",
"description": "The x-coordinate of the node."
"description": "The x-coordinate of the node.",
"x-go-type": "float64"
},
"y": {
"type": "number",
"description": "The y-coordinate of the node."
"description": "The y-coordinate of the node.",
"x-go-type": "float64"
}
}
},
Expand Down

0 comments on commit 7f04bfc

Please sign in to comment.