2022-11-12 10:29:21AM
This commit is contained in:
parent
9b44b84154
commit
4037bce13c
4 changed files with 30 additions and 26 deletions
|
|
@ -97,8 +97,8 @@ func visibilityToken(visibility string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawClass(writer io.Writer, targetShape d2target.Shape) {
|
func drawClass(writer io.Writer, targetShape d2target.Shape) {
|
||||||
fmt.Fprintf(writer, `<rect class="shape" x="%d" y="%d" width="%d" height="%d" />`,
|
fmt.Fprintf(writer, `<rect class="shape" x="%d" y="%d" width="%d" height="%d" style="%s"/>`,
|
||||||
targetShape.Pos.X, targetShape.Pos.Y, targetShape.Width, targetShape.Height)
|
targetShape.Pos.X, targetShape.Pos.Y, targetShape.Width, targetShape.Height, shapeStyle(targetShape))
|
||||||
|
|
||||||
box := geo.NewBox(
|
box := geo.NewBox(
|
||||||
geo.NewPoint(float64(targetShape.Pos.X), float64(targetShape.Pos.Y)),
|
geo.NewPoint(float64(targetShape.Pos.X), float64(targetShape.Pos.Y)),
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,9 @@ const (
|
||||||
|
|
||||||
var multipleOffset = geo.NewVector(10, -10)
|
var multipleOffset = geo.NewVector(10, -10)
|
||||||
|
|
||||||
|
//go:embed style.css
|
||||||
|
var styleCSS string
|
||||||
|
|
||||||
//go:embed github-markdown.css
|
//go:embed github-markdown.css
|
||||||
var mdCSS string
|
var mdCSS string
|
||||||
|
|
||||||
|
|
@ -446,12 +449,12 @@ func drawConnection(writer io.Writer, connection d2target.Connection, markers ma
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderOval(tl *geo.Point, width, height float64) string {
|
func renderOval(tl *geo.Point, width, height float64, style string) string {
|
||||||
rx := width / 2
|
rx := width / 2
|
||||||
ry := height / 2
|
ry := height / 2
|
||||||
cx := tl.X + rx
|
cx := tl.X + rx
|
||||||
cy := tl.Y + ry
|
cy := tl.Y + ry
|
||||||
return fmt.Sprintf(`<ellipse class="shape" cx="%f" cy="%f" rx="%f" ry="%f" />`, cx, cy, rx, ry)
|
return fmt.Sprintf(`<ellipse class="shape" cx="%f" cy="%f" rx="%f" ry="%f" style="%s" />`, cx, cy, rx, ry, style)
|
||||||
}
|
}
|
||||||
|
|
||||||
func defineShadowFilter(writer io.Writer) {
|
func defineShadowFilter(writer io.Writer) {
|
||||||
|
|
@ -487,7 +490,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(writer, `<g class="shape" style="%s" %s>`, style, shadowAttr)
|
fmt.Fprintf(writer, `<g class="shape" %s>`, shadowAttr)
|
||||||
|
|
||||||
var multipleTL *geo.Point
|
var multipleTL *geo.Point
|
||||||
if targetShape.Multiple {
|
if targetShape.Multiple {
|
||||||
|
|
@ -503,14 +506,14 @@ func drawShape(writer io.Writer, targetShape d2target.Shape) error {
|
||||||
return nil
|
return nil
|
||||||
case d2target.ShapeOval:
|
case d2target.ShapeOval:
|
||||||
if targetShape.Multiple {
|
if targetShape.Multiple {
|
||||||
fmt.Fprint(writer, renderOval(multipleTL, width, height))
|
fmt.Fprint(writer, renderOval(multipleTL, width, height, style))
|
||||||
}
|
}
|
||||||
fmt.Fprint(writer, renderOval(tl, width, height))
|
fmt.Fprint(writer, renderOval(tl, width, height, style))
|
||||||
|
|
||||||
case d2target.ShapeImage:
|
case d2target.ShapeImage:
|
||||||
fmt.Fprintf(writer, `<image href="%s" x="%d" y="%d" width="%d" height="%d"/>`,
|
fmt.Fprintf(writer, `<image href="%s" x="%d" y="%d" width="%d" height="%d" style="%s" />`,
|
||||||
targetShape.Icon.String(),
|
targetShape.Icon.String(),
|
||||||
targetShape.Pos.X, targetShape.Pos.Y, targetShape.Width, targetShape.Height)
|
targetShape.Pos.X, targetShape.Pos.Y, targetShape.Width, targetShape.Height, style)
|
||||||
|
|
||||||
// TODO should standardize "" to rectangle
|
// TODO should standardize "" to rectangle
|
||||||
case d2target.ShapeRectangle, "":
|
case d2target.ShapeRectangle, "":
|
||||||
|
|
@ -550,11 +553,11 @@ func drawShape(writer io.Writer, targetShape d2target.Shape) error {
|
||||||
strings.Join(rightPolygonPoints, ""), darkerColor)
|
strings.Join(rightPolygonPoints, ""), darkerColor)
|
||||||
}
|
}
|
||||||
if targetShape.Multiple {
|
if targetShape.Multiple {
|
||||||
fmt.Fprintf(writer, `<rect x="%d" y="%d" width="%d" height="%d"/>`,
|
fmt.Fprintf(writer, `<rect x="%d" y="%d" width="%d" height="%d" style="%s" />`,
|
||||||
targetShape.Pos.X+10, targetShape.Pos.Y-10, targetShape.Width, targetShape.Height)
|
targetShape.Pos.X+10, targetShape.Pos.Y-10, targetShape.Width, targetShape.Height, style)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(writer, `<rect x="%d" y="%d" width="%d" height="%d"/>`,
|
fmt.Fprintf(writer, `<rect x="%d" y="%d" width="%d" height="%d" style="%s" />`,
|
||||||
targetShape.Pos.X, targetShape.Pos.Y, targetShape.Width, targetShape.Height)
|
targetShape.Pos.X, targetShape.Pos.Y, targetShape.Width, targetShape.Height, style)
|
||||||
|
|
||||||
case d2target.ShapeText, d2target.ShapeCode:
|
case d2target.ShapeText, d2target.ShapeCode:
|
||||||
default:
|
default:
|
||||||
|
|
@ -566,7 +569,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pathData := range s.GetSVGPathData() {
|
for _, pathData := range s.GetSVGPathData() {
|
||||||
fmt.Fprintf(writer, `<path d="%s"/>`, pathData)
|
fmt.Fprintf(writer, `<path d="%s" style="%s"/>`, pathData, style)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -837,18 +840,11 @@ func Render(diagram *d2target.Diagram) ([]byte, error) {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
_, _ = setViewbox(buf, diagram)
|
_, _ = setViewbox(buf, diagram)
|
||||||
|
|
||||||
buf.WriteString(`<style type="text/css">
|
buf.WriteString(fmt.Sprintf(`<style type="text/css">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
.shape {
|
%s
|
||||||
shape-rendering: geometricPrecision;
|
|
||||||
stroke-linejoin: round;
|
|
||||||
}
|
|
||||||
.connection {
|
|
||||||
stroke-linecap: round;
|
|
||||||
stroke-linejoin: round;
|
|
||||||
}
|
|
||||||
]]>
|
]]>
|
||||||
</style>`)
|
</style>`, styleCSS))
|
||||||
|
|
||||||
hasMarkdown := false
|
hasMarkdown := false
|
||||||
for _, s := range diagram.Shapes {
|
for _, s := range diagram.Shapes {
|
||||||
|
|
|
||||||
8
d2renderers/d2svg/style.css
Normal file
8
d2renderers/d2svg/style.css
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
.shape {
|
||||||
|
shape-rendering: geometricPrecision;
|
||||||
|
stroke-linejoin: round;
|
||||||
|
}
|
||||||
|
.connection {
|
||||||
|
stroke-linecap: round;
|
||||||
|
stroke-linejoin: round;
|
||||||
|
}
|
||||||
|
|
@ -98,8 +98,8 @@ func constraintAbbr(constraint string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawTable(writer io.Writer, targetShape d2target.Shape) {
|
func drawTable(writer io.Writer, targetShape d2target.Shape) {
|
||||||
fmt.Fprintf(writer, `<rect class="shape" x="%d" y="%d" width="%d" height="%d" />`,
|
fmt.Fprintf(writer, `<rect class="shape" x="%d" y="%d" width="%d" height="%d" style="%s"/>`,
|
||||||
targetShape.Pos.X, targetShape.Pos.Y, targetShape.Width, targetShape.Height)
|
targetShape.Pos.X, targetShape.Pos.Y, targetShape.Width, targetShape.Height, shapeStyle(targetShape))
|
||||||
|
|
||||||
box := geo.NewBox(
|
box := geo.NewBox(
|
||||||
geo.NewPoint(float64(targetShape.Pos.X), float64(targetShape.Pos.Y)),
|
geo.NewPoint(float64(targetShape.Pos.X), float64(targetShape.Pos.Y)),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue