From 20461a245fa99e3b9049ed2dd3f4a78b396222b4 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Thu, 29 Aug 2024 15:05:37 +0530 Subject: [PATCH] assign correct position during conversion Signed-off-by: MUzairS15 --- models/v1beta1/component/component.go | 4 ++-- models/v1beta1/pattern/design_conversion.go | 24 ++++++++++++--------- schemas/constructs/core.json | 6 ++++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/models/v1beta1/component/component.go b/models/v1beta1/component/component.go index 2cd1315908..1f5ebff59d 100644 --- a/models/v1beta1/component/component.go +++ b/models/v1beta1/component/component.go @@ -243,10 +243,10 @@ type Styles struct { // Position The position of the node. If the position is set, the node is drawn at that position in the given dimensions. If the position is not set, the node is drawn at a random position. Position *struct { // X The x-coordinate of the node. - X float32 `json:"x" yaml:"x"` + X float64 `json:"x" yaml:"x"` // Y The y-coordinate of the node. - Y float32 `json:"y" yaml:"y"` + Y float64 `json:"y" yaml:"y"` } `json:"position,omitempty" yaml:"position,omitempty"` // PrimaryColor Primary color of the component used for UI representation. diff --git a/models/v1beta1/pattern/design_conversion.go b/models/v1beta1/pattern/design_conversion.go index 3cd562ccd1..f7f20b31f7 100644 --- a/models/v1beta1/pattern/design_conversion.go +++ b/models/v1beta1/pattern/design_conversion.go @@ -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. @@ -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) @@ -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 { diff --git a/schemas/constructs/core.json b/schemas/constructs/core.json index 0b09be6cc6..58a918f07a 100644 --- a/schemas/constructs/core.json +++ b/schemas/constructs/core.json @@ -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" } } },