Skip to content

Commit

Permalink
feat: elk border-radius
Browse files Browse the repository at this point in the history
  • Loading branch information
ShupingHe committed Feb 28, 2023
1 parent 5ac8b6f commit 85d8e75
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions d2exporter/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ func toConnection(edge *d2graph.Edge) d2target.Connection {
}
}

if edge.Attributes.Style.BorderRadius != nil {
connection.BorderRadius, _ = strconv.ParseFloat(edge.Attributes.Style.BorderRadius.Value, 64)
}

if edge.Attributes.Style.Opacity != nil {
connection.Opacity, _ = strconv.ParseFloat(edge.Attributes.Style.Opacity.Value, 64)
}
Expand Down
9 changes: 7 additions & 2 deletions d2renderers/d2svg/d2svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,12 @@ func pathData(connection d2target.Connection, srcAdj, dstAdj *geo.Point) string
currVector := prevTarget.VectorTo(currTarget)

dist := geo.EuclideanDistance(prevTarget.X, prevTarget.Y, currTarget.X, currTarget.Y)
units := math.Min(10, dist/2)

connectionBorderRadius := connection.BorderRadius
if connectionBorderRadius == 0 {
connectionBorderRadius = 10
}
units := math.Min(connectionBorderRadius, dist/2)

prevTranslations := prevVector.Unit().Multiply(units).ToPoint()
currTranslations := currVector.Unit().Multiply(units).ToPoint()
Expand All @@ -428,7 +433,7 @@ func pathData(connection d2target.Connection, srcAdj, dstAdj *geo.Point) string
))

// If the segment length is too small, instead of drawing 2 arcs, just skip this segment and bezier curve to the next one
if units < 10 && i < len(route)-2 {
if units < connectionBorderRadius && i < len(route)-2 {
nextTarget := route[i+2]
nextVector := geo.NewVector(nextTarget.X-currTarget.X, nextTarget.Y-currTarget.Y)
i++
Expand Down
11 changes: 6 additions & 5 deletions d2target/d2target.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,12 @@ type Connection struct {
DstArrow Arrowhead `json:"dstArrow"`
DstLabel string `json:"dstLabel"`

Opacity float64 `json:"opacity"`
StrokeDash float64 `json:"strokeDash"`
StrokeWidth int `json:"strokeWidth"`
Stroke string `json:"stroke"`
Fill string `json:"fill,omitempty"`
Opacity float64 `json:"opacity"`
StrokeDash float64 `json:"strokeDash"`
StrokeWidth int `json:"strokeWidth"`
Stroke string `json:"stroke"`
Fill string `json:"fill,omitempty"`
BorderRadius float64 `json:"borderRadius,omitempty"`

Text
LabelPosition string `json:"labelPosition"`
Expand Down

0 comments on commit 85d8e75

Please sign in to comment.