-
Notifications
You must be signed in to change notification settings - Fork 510
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
Hash not unique #2309
Comments
It shouldn't be nil after d2lib.Compile?: https://github.com/alixander/d2/blob/4c74a05705a16a613bb11fb00a1b0b460d82b074/d2lib/d2.go#L80 I can also inspect the hash of the resulting diagram on playground (using DOM inspector) with and without some config, and see that it's different. |
I just tested this again with 4c74a05. Please run this example: package main
import (
"context"
"fmt"
"os"
"path/filepath"
"oss.terrastruct.com/d2/d2graph"
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
"oss.terrastruct.com/d2/d2lib"
"oss.terrastruct.com/d2/d2renderers/d2svg"
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
"oss.terrastruct.com/d2/lib/log"
"oss.terrastruct.com/d2/lib/textmeasure"
"oss.terrastruct.com/util-go/go2"
)
// Remember to add if err != nil checks in production.
func main() {
ruler, _ := textmeasure.NewRuler()
layoutResolver := func(engine string) (d2graph.LayoutGraph, error) {
return d2dagrelayout.DefaultLayout, nil
}
renderOpts := &d2svg.RenderOpts{
Pad: go2.Pointer(int64(5)),
ThemeID: &d2themescatalog.GrapeSoda.ID,
}
compileOpts := &d2lib.CompileOptions{
LayoutResolver: layoutResolver,
Ruler: ruler,
}
ctx := log.WithDefault(context.Background())
diagram, _, _ := d2lib.Compile(ctx, "x -> y", compileOpts, renderOpts)
fmt.Printf("%+v\n", diagram.Config) // prints <nil>
out, _ := d2svg.Render(diagram, renderOpts)
_ = os.WriteFile(filepath.Join("grape_soda.svg"), out, 0o600)
renderOpts.ThemeID = &d2themescatalog.EarthTones.ID
diagram, _, _ = d2lib.Compile(ctx, "x -> y", compileOpts, renderOpts)
fmt.Printf("%+v\n", diagram.Config) // prints <nil>
out, _ = d2svg.Render(diagram, renderOpts)
_ = os.WriteFile(filepath.Join("earth_tones.svg"), out, 0o600)
} Both the resulting SVG files have class Also note that in the above, If I manually set diagram, _, _ := d2lib.Compile(ctx, "x -> y", compileOpts, renderOpts)
fmt.Printf("%+v\n", diagram.Config) // prints <nil>
diagram.Config = &d2target.Config{
ThemeID: &d2themescatalog.GrapeSoda.ID,
}
out, _ := d2svg.Render(diagram, renderOpts)
_ = os.WriteFile(filepath.Join("grape_soda.svg"), out, 0o600)
renderOpts.ThemeID = &d2themescatalog.EarthTones.ID
diagram, _, _ = d2lib.Compile(ctx, "x -> y", compileOpts, renderOpts)
fmt.Printf("%+v\n", diagram.Config) // prints <nil>
diagram.Config = &d2target.Config{
ThemeID: &d2themescatalog.EarthTones.ID,
}
out, _ = d2svg.Render(diagram, renderOpts)
_ = os.WriteFile(filepath.Join("earth_tones.svg"), out, 0o600) ...the classes in the two files are different, as they should be. |
Oh I see now. That But changing the render opts should've resulted in a different diagram hash. Fixed here: #2314 Thank you for reporting! |
With the exception of my comment, below is a verbatim copy of https://github.com/terrastruct/d2/blob/master/docs/examples/lib/1-d2lib/d2lib.go:
d2lib.go
I suppose we could manually populate
diagram.Config
at this point, but it seems like that should have happened already.The text was updated successfully, but these errors were encountered: