render sketch arrowheads separately
This commit is contained in:
parent
033a005eea
commit
af2a032a9e
1 changed files with 20 additions and 9 deletions
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"html"
|
"html"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
@ -60,6 +61,8 @@ var sketchStyleCSS string
|
||||||
//go:embed github-markdown.css
|
//go:embed github-markdown.css
|
||||||
var mdCSS string
|
var mdCSS string
|
||||||
|
|
||||||
|
var strokeWidthRE = regexp.MustCompile(`(.*stroke-width):(.+?);(.*)`)
|
||||||
|
|
||||||
type RenderOpts struct {
|
type RenderOpts struct {
|
||||||
Pad int
|
Pad int
|
||||||
Sketch bool
|
Sketch bool
|
||||||
|
|
@ -449,24 +452,32 @@ func drawConnection(writer io.Writer, labelMaskID string, connection d2target.Co
|
||||||
}
|
}
|
||||||
|
|
||||||
path := pathData(connection, idToShape)
|
path := pathData(connection, idToShape)
|
||||||
attrs := fmt.Sprintf(`%s%smask="url(#%s)"`,
|
mask := fmt.Sprintf(`mask="url(#%s)"`, labelMaskID)
|
||||||
markerStart,
|
|
||||||
markerEnd,
|
|
||||||
labelMaskID,
|
|
||||||
)
|
|
||||||
if sketchRunner != nil {
|
if sketchRunner != nil {
|
||||||
out, err := d2sketch.Connection(sketchRunner, connection, path, attrs)
|
out, err := d2sketch.Connection(sketchRunner, connection, path, mask)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(writer, out)
|
fmt.Fprint(writer, out)
|
||||||
|
|
||||||
|
// render sketch arrowheads separately
|
||||||
|
// TODO add sketch specific arrowheads
|
||||||
|
if markerStart != "" || markerEnd != "" {
|
||||||
|
// set stroke width to 0
|
||||||
|
style := strokeWidthRE.ReplaceAllString(connection.CSSStyle(), `$1:0;$3`)
|
||||||
|
fmt.Fprintf(writer, `<path d="%s" class="connection" style="fill:none;%s" %s%s/>`,
|
||||||
|
path, style,
|
||||||
|
markerStart,
|
||||||
|
markerEnd,
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
animatedClass := ""
|
animatedClass := ""
|
||||||
if connection.Animated {
|
if connection.Animated {
|
||||||
animatedClass = " animated-connection"
|
animatedClass = " animated-connection"
|
||||||
}
|
}
|
||||||
fmt.Fprintf(writer, `<path d="%s" class="connection%s" style="fill:none;%s" %s/>`,
|
fmt.Fprintf(writer, `<path d="%s" class="connection%s" style="fill:none;%s" %s%s%s/>`,
|
||||||
path, animatedClass, connection.CSSStyle(), attrs)
|
path, animatedClass, connection.CSSStyle(), markerStart, markerEnd, mask)
|
||||||
}
|
}
|
||||||
|
|
||||||
if connection.Label != "" {
|
if connection.Label != "" {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue