Skip to content

Commit

Permalink
Merge pull request #1882 from alixander/fill-pattern-none
Browse files Browse the repository at this point in the history
fill-pattern: none
  • Loading branch information
alixander committed Mar 26, 2024
2 parents c7d5d3e + b0d27a1 commit 60475cd
Show file tree
Hide file tree
Showing 15 changed files with 2,619 additions and 925 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#### Features 🚀

- `style.underline` works on connections [#1836](https://github.com/terrastruct/d2/pull/1836)
- `none` is added as an accepted value for `fill-pattern`. Previously there was no way to cancel the `fill-pattern` on select objects set by a theme that applies it (Origami) [#1882](https://github.com/terrastruct/d2/pull/1882)

#### Improvements 🧹

Expand Down
2 changes: 1 addition & 1 deletion d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ containers: {
}
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/invalid-fill-pattern.d2:3:19: expected "fill-pattern" to be one of: dots, lines, grain, paper`,
expErr: `d2/testdata/d2compiler/TestCompile/invalid-fill-pattern.d2:3:19: expected "fill-pattern" to be one of: none, dots, lines, grain, paper`,
},
{
name: "shape_unquoted_hex",
Expand Down
1 change: 1 addition & 0 deletions d2graph/d2graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,7 @@ var LabelPositionsMapping = map[string]label.Position{
}

var FillPatterns = []string{
"none",
"dots",
"lines",
"grain",
Expand Down
18 changes: 3 additions & 15 deletions d2oracle/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"oss.terrastruct.com/d2/d2ir"
"oss.terrastruct.com/d2/d2parser"
"oss.terrastruct.com/d2/d2target"
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
)

type OutsideScopeError struct{}
Expand Down Expand Up @@ -1297,20 +1296,9 @@ func deleteReserved(g *d2graph.Graph, boardPath []string, baseAST *d2ast.Map, mk
if err != nil {
return nil, err
}
if !deleted {
if imported {
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
appendMapKey(baseAST, mk)
} else {
switch id {
// Special cases where a value is set by theme, so is not found as a field
case "fill-pattern":
if g.Theme != nil && g.Theme.ID == d2themescatalog.Origami.ID {
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
appendMapKey(baseAST, mk)
}
}
}
if !deleted && imported {
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
appendMapKey(baseAST, mk)
}
continue
}
Expand Down
49 changes: 0 additions & 49 deletions d2oracle/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"oss.terrastruct.com/d2/d2graph"
"oss.terrastruct.com/d2/d2oracle"
"oss.terrastruct.com/d2/d2target"
"oss.terrastruct.com/d2/d2themes"
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
)

// TODO: make assertions less specific
Expand Down Expand Up @@ -5697,7 +5695,6 @@ func TestDelete(t *testing.T) {
testCases := []struct {
name string
boardPath []string
theme *d2themes.Theme

text string
fsTexts map[string]string
Expand Down Expand Up @@ -7691,52 +7688,13 @@ layers: {
}
}
`,
theme: &d2themescatalog.Origami,
boardPath: []string{"x"},
key: `a.style.fill`,
exp: `layers: {
x: {
a
}
}
`,
},
{
name: "delete-theme-set/1",

text: `layers: {
x: {
a
}
}
`,
theme: &d2themescatalog.Origami,
boardPath: []string{"x"},
key: `a.style.fill-pattern`,
exp: `layers: {
x: {
a
a.style.fill-pattern: null
}
}
`,
},
{
name: "delete-theme-set/2",

text: `layers: {
x: {
a
}
}
`,
boardPath: []string{"x"},
key: `a.style.fill-pattern`,
exp: `layers: {
x: {
a
}
}
`,
},
}
Expand All @@ -7749,7 +7707,6 @@ layers: {
et := editTest{
text: tc.text,
fsTexts: tc.fsTexts,
theme: tc.theme,
testFunc: func(g *d2graph.Graph) (*d2graph.Graph, error) {
return d2oracle.Delete(g, tc.boardPath, tc.key)
},
Expand All @@ -7765,7 +7722,6 @@ layers: {

type editTest struct {
text string
theme *d2themes.Theme
fsTexts map[string]string
testFunc func(*d2graph.Graph) (*d2graph.Graph, error)

Expand Down Expand Up @@ -7793,11 +7749,6 @@ func (tc editTest) run(t *testing.T) {
})
assert.Success(t, err)

if tc.theme != nil {
err := g.ApplyTheme(tc.theme.ID)
assert.Success(t, err)
}

g, err = tc.testFunc(g)
if tc.expErr != "" {
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion d2themes/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (el *ThemableElement) Render() string {
}

out += " />"
if el.FillPattern != "" {
if el.FillPattern != "" && el.FillPattern != "none" {
patternEl := el.Copy()
patternEl.Fill = ""
patternEl.Stroke = ""
Expand Down
11 changes: 11 additions & 0 deletions e2etests/testdata/txtar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,14 @@ costumes.monster -> monsters.id
a -> b: hi {
style.underline: true
}

-- none-fill --

vars: {
d2-config: {
# Origami theme code
theme-id: 302
}
}
a.style.fill-pattern: none
b
140 changes: 140 additions & 0 deletions e2etests/testdata/txtar/none-fill/dagre/board.exp.json

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

0 comments on commit 60475cd

Please sign in to comment.