From 542c3f954c9fd62f245e16859bb20b0f5ea98643 Mon Sep 17 00:00:00 2001 From: stackdump Date: Sun, 31 Dec 2023 02:12:24 -0600 Subject: [PATCH] calculate viewport --- metamodel/image/svg_test.go | 4 +--- metamodel/metamodel.go | 9 +++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/metamodel/image/svg_test.go b/metamodel/image/svg_test.go index baa31cc..426b08c 100644 --- a/metamodel/image/svg_test.go +++ b/metamodel/image/svg_test.go @@ -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) diff --git a/metamodel/metamodel.go b/metamodel/metamodel.go index 31115b9..5bb5dd2 100644 --- a/metamodel/metamodel.go +++ b/metamodel/metamodel.go @@ -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 @@ -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) {