Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad rendering #106

Open
pebbe opened this issue Oct 30, 2024 · 8 comments
Open

Bad rendering #106

pebbe opened this issue Oct 30, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@pebbe
Copy link

pebbe commented Oct 30, 2024

Rendering of this graph is all wrong:

strict graph gr {
 
    ranksep=".4"
    nodesep=.05
 
    margin=.05;
    outputMode="edgesfirst";
    node [shape=box, height=0, width=0, style=filled, fontsize=12, color="#ffc0c0", fontname="Helvetica"];
 
    n0 [label="top"];
    n1 [label="smain", style=bold, color="#ff0000"];
    n3 [label="np", style=bold, color="#ff0000"];
    n6 [label="ppart", style=bold, color="#ff0000"];
 
    node [fontname="Helvetica-Oblique", color="#c0c0ff"];
 
    n2 [label="werd"];
    n4 [label="groot", style=bold, color="#0000ff"];
    n5 [label="alarm", style=bold, color="#0000ff"];
    n7 [label="Wel"];
    n8 [label="meteen"];
    n10 [label="geslagen"];
 
    {rank=same; edge[style=invis]; n7 -- n2 -- n8 -- n4 -- n5 -- n10}
 
    edge [sametail=true, samehead=true, color="#d3d3d3", fontname="Helvetica", fontsize=10];
 
    n0 -- n1 [label=" --  "];
    n1 -- n2 [label=" hd  "];
    n1 -- n3 [label=" su  ", color="#000000"];
    n1 -- n6 [label=" vc  "];
    n3 -- n4 [label=" mod  ", color="#000000"];
    n3 -- n5 [label=" hd  ", color="#000000"];
    n6 -- n7 [label=" mod  "];
    n6 -- n8 [label=" mod  "];
    n6 -- n3 [label=" svp  ", color="#000000"];
    n6 -- n10 [label=" hd  "];
 
}

How it should look (rendered with the dot program):

ok

How it looks:

wrong

@marcelom97
Copy link
Contributor

Looks to be working fine in this example in all 4 formats.

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/goccy/go-graphviz"
)

func main() {
	ctx := context.Background()
	gv, err := graphviz.ParseBytes([]byte(`
 strict graph gr {

     ranksep=".4"
     nodesep=.05

     margin=.05;
     outputMode="edgesfirst";
     node [shape=box, height=0, width=0, style=filled, fontsize=12, color="#ffc0c0", fontname="Helvetica"];

     n0 [label="top"];
     n1 [label="smain", style=bold, color="#ff0000"];
     n3 [label="np", style=bold, color="#ff0000"];
     n6 [label="ppart", style=bold, color="#ff0000"];

     node [fontname="Helvetica-Oblique", color="#c0c0ff"];

     n2 [label="werd"];
     n4 [label="groot", style=bold, color="#0000ff"];
     n5 [label="alarm", style=bold, color="#0000ff"];
     n7 [label="Wel"];
     n8 [label="meteen"];
     n10 [label="geslagen"];

     {rank=same; edge[style=invis]; n7 -- n2 -- n8 -- n4 -- n5 -- n10}

     edge [sametail=true, samehead=true, color="#d3d3d3", fontname="Helvetica", fontsize=10];

     n0 -- n1 [label=" --  "];
     n1 -- n2 [label=" hd  "];
     n1 -- n3 [label=" su  ", color="#000000"];
     n1 -- n6 [label=" vc  "];
     n3 -- n4 [label=" mod  ", color="#000000"];
     n3 -- n5 [label=" hd  ", color="#000000"];
     n6 -- n7 [label=" mod  "];
     n6 -- n8 [label=" mod  "];
     n6 -- n3 [label=" svp  ", color="#000000"];
     n6 -- n10 [label=" hd  "];
 }`))
	if err != nil {
		log.Fatal("failed to parse graphviz: ", err)
	}

	g, err := graphviz.New(ctx)
	if err != nil {
		log.Fatal("failed to create graphviz: ", err)
	}

	formats := []graphviz.Format{graphviz.PNG, graphviz.SVG, graphviz.JPG, graphviz.XDOT}
	for _, format := range formats {
		f, err := os.Create(fmt.Sprintf("example.%s", format))
		if err != nil {
			log.Fatal("failed to create file: ", err)
		}
		defer f.Close()

		if err := g.Render(ctx, gv, format, f); err != nil {
			// don't exit here, just log the error
			fmt.Printf("failed to render graph to %s: %v\n", format, err)
		}
	}
}

@pebbe
Copy link
Author

pebbe commented Nov 1, 2024

Running this code I get what you see below. Only the svg version (top right) looks identical to the original (top left).
Is it something platform dependant? I am using Go version go1.23.2 on linux/amd64.

screen1

@pebbe
Copy link
Author

pebbe commented Nov 1, 2024

Or is it a library version thing? This is my go.mod for this program:

require github.com/goccy/go-graphviz v0.2.9
 
require (
        github.com/disintegration/imaging v1.6.2 // indirect
        github.com/flopp/go-findfont v0.1.0 // indirect
        github.com/fogleman/gg v1.3.0 // indirect
        github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
        github.com/tetratelabs/wazero v1.8.1 // indirect
        golang.org/x/image v0.21.0 // indirect
        golang.org/x/text v0.19.0 // indirect
)

@marcelom97
Copy link
Contributor

I ran it on go1.23.2 darwin/arm64

Maybe try to run it in docker on a different platform

@WolvenSpirit
Copy link

WolvenSpirit commented Nov 14, 2024

Same bug with rendering edges happens on my platform also (which is actually Github codespace)

$ uname -ai
Linux codespaces-51c77b 6.5.0-1025-azure #26~22.04.1-Ubuntu SMP Thu Jul 11 22:33:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
go version go1.23.1 linux/amd64

From go.mod

require github.com/goccy/go-graphviz v0.2.9

require (
	github.com/disintegration/imaging v1.6.2 // indirect
	github.com/flopp/go-findfont v0.1.0 // indirect
	github.com/fogleman/gg v1.3.0 // indirect
	github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
	github.com/tetratelabs/wazero v1.8.1 // indirect
	golang.org/x/image v0.22.0 // indirect
	golang.org/x/text v0.20.0 // indirect
)

image
Reproducing it in codespace would be trivial as it happens out of the box.

@goccy
Copy link
Owner

goccy commented Nov 14, 2024

It’s likely an issue with the feature you are using. Does the rendering break with a simpler example as well ? If not, please provide a minimal sample.

@goccy goccy added the bug Something isn't working label Nov 14, 2024
@WolvenSpirit
Copy link

WolvenSpirit commented Nov 14, 2024

An example, I skipped a lot of things to get a really slim code sample.
Note: The codespace dev env is as provided by Github nothing was installed besides this library via go get ....

package main

import (
	"context"

	gv "github.com/goccy/go-graphviz"
)

func main() {
	ctx := context.Background()
	g, _ := gv.New(ctx)
	graph, _ := g.Graph()
	a, _ := graph.CreateNodeByName("a")
	b, _ := graph.CreateNodeByName("b")
	c, _ := graph.CreateNodeByName("c")
	d, _ := graph.CreateNodeByName("d")
	e, _ := graph.CreateNodeByName("e")
	f, _ := graph.CreateNodeByName("f")
	a.Root().CreateEdgeByName("a-b", a, b)
	a.Root().CreateEdgeByName("a-c", a, c)
	b.Root().CreateEdgeByName("b-c", b, c)
	a.Root().CreateEdgeByName("a-d", a, d)
	d.Root().CreateEdgeByName("d-e", d, e)
	e.Root().CreateEdgeByName("e-f", e, f)
	g.RenderFilename(ctx, graph, "png", "sample.png")
}

Output
image
While the svg code would seem to render properly when doing

// instead of RenderFilename
buff := new(bytes.Buffer)
g.Render(ctx, graph, "svg", buff)
ioutil.WriteFile("sample.svg", buff.Bytes(), fs.ModePerm)

Output
image

So probably this is either specific to RenderFilename or rendering png/jpg specifically.

@lubronzhan
Copy link

lubronzhan commented Dec 6, 2024

I'm also creating a PNG image. Running on mac, golang 1.22.9.
I have much more components so the rendering effect is much much worst. For example, small piece of it
image

I tried several go-graphvzi versions, it happens starting on v0.2.1, the graph is correct with v0.2.0, so it's highly likely due to this PR #92 according to v0.2.0...v0.2.1
Snipped of image using 0.2.0:
image

This PR just fixes #24, the images wasn't render correctly previously before 0.2.1, this PR fixes it. So by default looks like the edge use that chubby style. But if I tried set the edge style it doesn't work

edge.SetStyle(cgraph.SolidEdgeStyle)

Not sure where does the filled value is set, we do set Node's style as filled. Maybe the node's fill will also impact the Edge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants