Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bolding #358

Merged
merged 3 commits into from
Dec 5, 2022
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 ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
So you can run `go install oss.terrastruct.com/d2@latest` to install from source
now.
[#290](https://github.com/terrastruct/d2/pull/290)
- Container default font styling is no longer bold. Everything used to look too bold.
[#358](https://github.com/terrastruct/d2/pull/358)
- `BROWSER=0` now works to disable opening a browser on `--watch`.
[#311](https://github.com/terrastruct/d2/pull/311)

Expand Down
2 changes: 2 additions & 0 deletions d2exporter/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func toShape(obj *d2graph.Object, theme *d2themes.Theme) d2target.Shape {
shape.Height = int(obj.Height)

text := obj.Text()
shape.Bold = text.IsBold
shape.Italic = text.IsItalic
shape.FontSize = text.FontSize

applyStyles(shape, obj)
Expand Down
16 changes: 10 additions & 6 deletions d2graph/d2graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (obj *Object) GetFill(theme *d2themes.Theme) string {
} else if obj.IsSequenceDiagramNote() {
return theme.Colors.Neutrals.N7
} else if obj.IsSequenceDiagramGroup() {
sd := obj.outerSequenceDiagram()
sd := obj.OuterSequenceDiagram()
// Alternate
if (level-int(sd.Level()))%2 == 0 {
return theme.Colors.Neutrals.N7
Expand Down Expand Up @@ -428,10 +428,14 @@ func (obj *Object) AbsIDArray() []string {
}

func (obj *Object) Text() *d2target.MText {
isBold := !obj.IsContainer()
fontSize := d2fonts.FONT_SIZE_M
if obj.IsContainer() && !obj.Parent.IsSequenceDiagram() {
// sequence diagram children (aka, actors) shouldn't have the container font size
fontSize = obj.Level().LabelSize()
if obj.OuterSequenceDiagram() == nil {
if obj.IsContainer() {
fontSize = obj.Level().LabelSize()
}
} else {
isBold = false
}
if obj.Attributes.Style.FontSize != nil {
fontSize, _ = strconv.Atoi(obj.Attributes.Style.FontSize.Value)
Expand All @@ -443,7 +447,7 @@ func (obj *Object) Text() *d2target.MText {
return &d2target.MText{
Text: obj.Attributes.Label.Value,
FontSize: fontSize,
IsBold: !obj.IsContainer(),
IsBold: isBold,
IsItalic: false,
Language: obj.Attributes.Language,
Shape: obj.Attributes.Shape.Value,
Expand Down Expand Up @@ -742,7 +746,7 @@ func (obj *Object) Connect(srcID, dstID []string, srcArrow, dstArrow bool, label
src := srcObj.EnsureChild(srcID)
dst := dstObj.EnsureChild(dstID)

if src.outerSequenceDiagram() != dst.outerSequenceDiagram() {
if src.OuterSequenceDiagram() != dst.OuterSequenceDiagram() {
return nil, errors.New("connections within sequence diagrams can connect only to other objects within the same sequence diagram")
}

Expand Down
6 changes: 3 additions & 3 deletions d2graph/seqdiagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func (obj *Object) IsSequenceDiagram() bool {
return obj != nil && obj.Attributes.Shape.Value == d2target.ShapeSequenceDiagram
}

func (obj *Object) outerSequenceDiagram() *Object {
func (obj *Object) OuterSequenceDiagram() *Object {
for obj != nil {
obj = obj.Parent
if obj.IsSequenceDiagram() {
Expand All @@ -19,7 +19,7 @@ func (obj *Object) outerSequenceDiagram() *Object {
// groups are objects in sequence diagrams that have no messages connected
// and does not have a note as a child (a note can appear within a group, but it's a child of an actor)
func (obj *Object) IsSequenceDiagramGroup() bool {
if obj.outerSequenceDiagram() == nil {
if obj.OuterSequenceDiagram() == nil {
return false
}
for _, e := range obj.Graph.Edges {
Expand All @@ -38,7 +38,7 @@ func (obj *Object) IsSequenceDiagramGroup() bool {

// notes are descendant of actors with no edges and no children
func (obj *Object) IsSequenceDiagramNote() bool {
if obj.outerSequenceDiagram() == nil {
if obj.OuterSequenceDiagram() == nil {
return false
}
return !obj.hasEdgeRef() && !obj.ContainsAnyEdge(obj.Graph.Edges) && len(obj.ChildrenArray) == 0
Expand Down
1 change: 1 addition & 0 deletions d2layouts/d2sequence/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"oss.terrastruct.com/d2/d2compiler"
"oss.terrastruct.com/d2/d2graph"
"oss.terrastruct.com/d2/d2layouts/d2sequence"
Expand Down
4 changes: 2 additions & 2 deletions e2etests/testdata/sanity/child_to_child/dagre/board.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion e2etests/testdata/sanity/child_to_child/dagre/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions e2etests/testdata/sanity/child_to_child/elk/board.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion e2etests/testdata/sanity/child_to_child/elk/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion e2etests/testdata/stable/chaos1/dagre/board.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion e2etests/testdata/stable/chaos1/dagre/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion e2etests/testdata/stable/chaos1/elk/board.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion e2etests/testdata/stable/chaos1/elk/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions e2etests/testdata/stable/chaos2/dagre/board.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions e2etests/testdata/stable/chaos2/dagre/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading