diff --git a/d2renderers/d2sketch/sketch.go b/d2renderers/d2sketch/sketch.go index e95a6fe5a..bf89e7aec 100644 --- a/d2renderers/d2sketch/sketch.go +++ b/d2renderers/d2sketch/sketch.go @@ -132,6 +132,47 @@ func DoubleRect(r *Runner, shape d2target.Shape) (string, error) { return output, nil } +func DoubleRect(r *Runner, shape d2target.Shape) (string, error) { + jsBigRect := fmt.Sprintf(`node = rc.rectangle(0, 0, %d, %d, { + fill: "%s", + stroke: "%s", + strokeWidth: %d, + %s + });`, shape.Width, shape.Height, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps) + pathsBigRect, err := computeRoughPaths(r, jsBigRect) + if err != nil { + return "", err + } + jsSmallRect := fmt.Sprintf(`node = rc.rectangle(0, 0, %d, %d, { + fill: "%s", + stroke: "%s", + strokeWidth: %d, + %s + });`, shape.Width-d2target.INNER_BORDER_OFFSET*2, shape.Height-d2target.INNER_BORDER_OFFSET*2, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps) + pathsSmallRect, err := computeRoughPaths(r, jsSmallRect) + if err != nil { + return "", err + } + output := "" + for _, p := range pathsBigRect { + output += fmt.Sprintf( + ``, + shape.Pos.X, shape.Pos.Y, p, shapeStyle(shape), + ) + } + for _, p := range pathsSmallRect { + output += fmt.Sprintf( + ``, + shape.Pos.X+d2target.INNER_BORDER_OFFSET, shape.Pos.Y+d2target.INNER_BORDER_OFFSET, p, shapeStyle(shape), + ) + } + output += fmt.Sprintf( + ``, + shape.Pos.X, shape.Pos.Y, shape.Width, shape.Height, + ) + return output, nil +} + func Oval(r *Runner, shape d2target.Shape) (string, error) { js := fmt.Sprintf(`node = rc.ellipse(%d, %d, %d, %d, { fill: "%s", @@ -198,6 +239,47 @@ func DoubleOval(r *Runner, shape d2target.Shape) (string, error) { return output, nil } +func DoubleOval(r *Runner, shape d2target.Shape) (string, error) { + jsBigCircle := fmt.Sprintf(`node = rc.ellipse(%d, %d, %d, %d, { + fill: "%s", + stroke: "%s", + strokeWidth: %d, + %s + });`, shape.Width/2, shape.Height/2, shape.Width, shape.Height, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps) + jsSmallCircle := fmt.Sprintf(`node = rc.ellipse(%d, %d, %d, %d, { + fill: "%s", + stroke: "%s", + strokeWidth: %d, + %s + });`, shape.Width/2, shape.Height/2, shape.Width-d2target.INNER_BORDER_OFFSET*2, shape.Height-d2target.INNER_BORDER_OFFSET*2, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps) + pathsBigCircle, err := computeRoughPaths(r, jsBigCircle) + if err != nil { + return "", err + } + pathsSmallCircle, err := computeRoughPaths(r, jsSmallCircle) + if err != nil { + return "", err + } + output := "" + for _, p := range pathsBigCircle { + output += fmt.Sprintf( + ``, + shape.Pos.X, shape.Pos.Y, p, shapeStyle(shape), + ) + } + for _, p := range pathsSmallCircle { + output += fmt.Sprintf( + ``, + shape.Pos.X, shape.Pos.Y, p, shapeStyle(shape), + ) + } + output += fmt.Sprintf( + ``, + shape.Pos.X+shape.Width/2, shape.Pos.Y+shape.Height/2, shape.Width/2, shape.Height/2, + ) + return output, nil +} + // TODO need to personalize this per shape like we do in Terrastruct app func Paths(r *Runner, shape d2target.Shape, paths []string) (string, error) { output := "" diff --git a/d2renderers/d2sketch/testdata/all_shapes/sketch.exp.svg b/d2renderers/d2sketch/testdata/all_shapes/sketch.exp.svg index 07980441b..830b30433 100644 --- a/d2renderers/d2sketch/testdata/all_shapes/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/all_shapes/sketch.exp.svg @@ -1,9 +1,8 @@ -rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud - +rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud + + -ab - +ab + + -wintersummersnowsun - +wintersummersnowsun + + -BatchManager- +BatchManager- num int- timeout int- pid -+ ++ getStatus() Enum+ getJobs() Job[]+ setTimeout(seconds int) -void - +void + + -ab hello - - +ab hello + + + -usersid +usersid int -name +name string -email +email string -password +password string -last_login +last_login datetime -productsid +productsid int -price +price decimal -sku +sku string -name +name string -ordersid +ordersid int -user_id +user_id int -product_id +product_id int -shipmentsid +shipmentsid int -order_id +order_id int -tracking_number +tracking_number string -PKstatus +PKstatus string - - + +

Another item in the same list.

-ab - +ab + x +x @@ -51,7 +30,7 @@ width="334" height="572" viewBox="-102 -118 334 572"> -y +y @@ -77,8 +56,8 @@ knowing I can't make my satellite dish PAYMENTS! - + + x +x @@ -51,7 +30,7 @@ width="334" height="572" viewBox="-90 -106 334 572"> -y +y @@ -77,8 +56,8 @@ knowing I can't make my satellite dish PAYMENTS! - + +

Markdown: Syntax

+
ab +

Markdown: Syntax

+
ab +