Skip to content

Commit

Permalink
calculate viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
stackdump committed Dec 31, 2023
1 parent 0334d6a commit 542c3f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 1 addition & 3 deletions metamodel/image/svg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ func TestNewSvg(t *testing.T) {
// Load a model from a URL
mm := metamodel.New("test")
mm.UnzipUrl(sampleUrl)
x1, y1, x2, y2 := mm.GetViewPort()
width := x2 - x1
height := y2 - y1
x1, y1, width, height := mm.GetViewPort()
i := image.NewSvgFile("/tmp/test.svg", width, height, x1, y1, width, height)
i.Rect(x1, y1, width, height, "fill: #fff; stroke: #000; stroke-width: 1px;")
i.Render(mm)
Expand Down
9 changes: 7 additions & 2 deletions metamodel/metamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ type Model struct {
*PetriNet
}

func (m *Model) GetViewPort() (x1 int, x2 int, y1 int, y2 int) {
func (m *Model) GetViewPort() (x1 int, y1 int, width int, height int) {
var minX int64 = 0
var minY int64 = 0
var limitX int64 = 0
Expand Down Expand Up @@ -433,7 +433,12 @@ func (m *Model) GetViewPort() (x1 int, x2 int, y1 int, y2 int) {
}
}
const margin = 60
return int(minX) - margin, int(minY) - margin, int(limitX) + margin, int(limitY) + margin
x1 = int(minX) - margin
y1 = int(minY) - margin
x2 := int(limitX) + margin
y2 := int(limitY) + margin

return x1, y1, x2 - x1, y2 - y1
}

func (m *Model) exportObjectJsonDefinition() (obj []byte, ok bool) {
Expand Down

0 comments on commit 542c3f9

Please sign in to comment.