Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Desktop.ini

# Build output and Go artifacts
/build
# `go build` in the root writes the binary here.
/dot

# Scratch / work-in-progress files
# *.local
Expand Down
22 changes: 19 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@ command line interface described in `README.md`.

## [Unreleased]

## [1.2.0] - 2026-10-07
## [1.2.0] - 2026-10-08

### Added

- `-Txdot`: the layout with its drawing operations, as Graphviz's xdot.
`-Tdot` stays the layout with positions only.

### Changed

- The engine is forkcloser/go-graphviz v0.4.0. Text is measured with the
- The engine is forkcloser/go-graphviz v0.5.0. Text is measured with the
fonts it is drawn in, the installed ones, as Graphviz's own `dot` does:
labels fit their nodes, and the same graph can lay out slightly
differently, in every output format, on machines with different fonts.
- PNG and JPEG are drawn the way Graphviz's Cairo renderer draws: lines
meet in mitred corners and end flat, where they were round; dashed lines
are six points on, six off, and dotted lines two on, six off, Graphviz's
lengths. A PNG render of a graph of about 40 nodes allocates 7 MB
instead of 320 MB and takes half the time. The binary no longer carries
`fogleman/gg` or `golang/freetype`.
- Font names resolve as Graphviz resolves them (PostScript names, family
and style words, metric-compatible substitutes), falling back to
embedded Go fonts in regular, bold, italic and monospace.
Expand All @@ -31,9 +42,14 @@ command line interface described in `README.md`.
a blank page.
- Characters the label's font lacks (Japanese, Chinese, Korean in a Latin
font) are drawn from an installed font that has them, not as boxes.
- A node image named by an absolute path is drawn; it was silently left
out. A lossless or extended WebP node image, any WebP with alpha, is
sized as it is instead of failing the render as a page too large.
- An attribute the engine could not store (out of WebAssembly memory)
fails the render instead of being dropped.

Details in go-graphviz's
[CHANGELOG](https://github.com/forkcloser/go-graphviz/blob/v0.4.0/CHANGELOG.md).
[CHANGELOG](https://github.com/forkcloser/go-graphviz/blob/v0.5.0/CHANGELOG.md).

## [1.1.1] - 2026-10-05

Expand Down
13 changes: 8 additions & 5 deletions cmd/dot/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Command dot renders a Graphviz graph to dot, svg, png or jpg without a
// Command dot renders a Graphviz graph to dot, xdot, svg, png or jpg without a
// native graphviz installation: the engine is go-graphviz's WASM build.
//
// Usage:
Expand Down Expand Up @@ -28,7 +28,7 @@ const usage = `usage: dot [-K engine] [-T format] [-o path] [input]

-K engine layout engine: dot (default), neato, fdp, sfdp, circo, twopi,
osage, patchwork
-T format output format: dot (default), svg, png, jpg
-T format output format: dot (default), xdot, svg, png, jpg
-o path output file (default: standard output)
-V print the version
-h print this help
Expand Down Expand Up @@ -77,11 +77,14 @@ func layoutNamed(name string) (graphviz.Layout, bool) {
}
}

// formatNamed is the output format by the name -T takes. "dot" is graphviz's
// xdot: the layout written back as DOT, with the computed positions on it.
// formatNamed is the output format by the name -T takes, as Graphviz names
// them: "dot" is the layout written back as DOT with the computed positions
// on it, "xdot" that plus the drawing operations.
func formatNamed(name string) (graphviz.Format, bool) {
switch name {
case "dot":
return graphviz.GV, true
case "xdot":
return graphviz.XDOT, true
case "svg":
return graphviz.SVG, true
Expand All @@ -97,7 +100,7 @@ func formatNamed(name string) (graphviz.Format, bool) {
// parseArgs accepts graphviz's glued flags (-Tpng) as well as spaced ones,
// which the standard flag package cannot do.
func parseArgs(args []string) (options, error) {
opt := options{layout: graphviz.DOT, format: graphviz.XDOT}
opt := options{layout: graphviz.DOT, format: graphviz.GV}

// A spaced value flag consumes the argument after it, so the loop moves
// the index itself rather than ranging over the slice.
Expand Down
28 changes: 21 additions & 7 deletions cmd/dot/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestParseArgs(t *testing.T) {
want options
err bool
}{
{nil, options{layout: graphviz.DOT, format: graphviz.XDOT}, false},
{nil, options{layout: graphviz.DOT, format: graphviz.GV}, false},
{
[]string{"-Tpng", "-oout.png", "in.dot"},
options{layout: graphviz.DOT, format: graphviz.PNG, output: "out.png", input: "in.dot"},
Expand All @@ -31,8 +31,8 @@ func TestParseArgs(t *testing.T) {
options{layout: graphviz.NEATO, format: graphviz.SVG, output: "out.svg", input: "-"},
false,
},
{[]string{"-h"}, options{layout: graphviz.DOT, format: graphviz.XDOT, help: true}, false},
{[]string{"-V"}, options{layout: graphviz.DOT, format: graphviz.XDOT, version: true}, false},
{[]string{"-h"}, options{layout: graphviz.DOT, format: graphviz.GV, help: true}, false},
{[]string{"-V"}, options{layout: graphviz.DOT, format: graphviz.GV, version: true}, false},
{[]string{"-Tgif"}, options{}, true},
{[]string{"-Kbogus"}, options{}, true},
{[]string{"-o"}, options{}, true},
Expand All @@ -56,10 +56,11 @@ func TestRenderFormats(t *testing.T) {
t.Parallel()

magic := map[string]string{
"dot": "digraph",
"svg": "<?xml",
"png": "\x89PNG",
"jpg": "\xff\xd8\xff",
"dot": "digraph",
"xdot": "digraph",
"svg": "<?xml",
"png": "\x89PNG",
"jpg": "\xff\xd8\xff",
}
for format, want := range magic {
var out, errb bytes.Buffer
Expand All @@ -72,6 +73,19 @@ func TestRenderFormats(t *testing.T) {
if !strings.HasPrefix(out.String(), want) {
t.Errorf("-T%s: output does not start with %q: %q", format, want, out.String()[:min(16, out.Len())])
}

// Both DOT forms carry the layout; only xdot carries the drawing
// operations. The two were the same output before go-graphviz 0.5.0
// named them apart.
if format == "dot" || format == "xdot" {
if !strings.Contains(out.String(), "pos=") {
t.Errorf("-T%s: output has no positions", format)
}

if drawn := strings.Contains(out.String(), "_draw_"); drawn != (format == "xdot") {
t.Errorf("-T%s: _draw_ present = %v", format, drawn)
}
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module github.com/forkcloser/dot

go 1.26.0

require github.com/forkcloser/go-graphviz v0.4.0
require github.com/forkcloser/go-graphviz v0.5.0

require (
github.com/fogleman/gg v1.3.0 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/tetratelabs/wazero v1.12.0 // indirect
golang.org/x/image v0.46.0 // indirect
golang.org/x/sys v0.48.0 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/forkcloser/go-graphviz v0.4.0 h1:NCpzxoQtQB0hL3mm4zSwi3bdO9tgBtPJNyHrFabmsqY=
github.com/forkcloser/go-graphviz v0.4.0/go.mod h1:eAWRQF8m4fwtzgh1U8K+PNiYskteXC6aV4+ft/cinFk=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/forkcloser/go-graphviz v0.5.0 h1:gJeM9OmNFkTIRkZ3u6X6+XHRM9tFRY12Ic/E6LtfkLg=
github.com/forkcloser/go-graphviz v0.5.0/go.mod h1:EbSWnUlAz5sNUrAeWXI45Fiy074kdsvwXuVuD8nO5Eo=
github.com/tetratelabs/wazero v1.12.0 h1:DuWcpNu/FzgEXgGBDp8J1Spc+CWOvvtvVyjKlaZopYU=
github.com/tetratelabs/wazero v1.12.0/go.mod h1:LvKtzl2RqO4gyF27BiXU+nKAjcV8f38U+kP/q2vgxh0=
golang.org/x/image v0.46.0 h1:b1+oYj0Jbp6K5MDT4i4/eZpYlk3V8SJhhDKh6LBHAyQ=
Expand Down
Loading