refactor, fix tests, next
This commit is contained in:
parent
d2cfa5eb1d
commit
2c13a97cdd
3 changed files with 66 additions and 54 deletions
|
|
@ -4,12 +4,6 @@
|
||||||
|
|
||||||
#### Improvements 🧹
|
#### Improvements 🧹
|
||||||
|
|
||||||
- Use shape specific sizing for grid containers [#1294](https://github.com/terrastruct/d2/pull/1294)
|
|
||||||
- Grid diagrams now support nested shapes or grid diagrams [#1309](https://github.com/terrastruct/d2/pull/1309)
|
|
||||||
- Grid diagrams will now also use `grid-gap`, `vertical-gap`, and `horizontal-gap` for padding [#1309](https://github.com/terrastruct/d2/pull/1309)
|
|
||||||
- Watch mode browser uses an error favicon to easily indicate compiler errors. Thanks @sinyo-matu ! [#1240](https://github.com/terrastruct/d2/pull/1240)
|
|
||||||
- Improves grid layout performance when there are many similarly sized shapes. [#1315](https://github.com/terrastruct/d2/pull/1315)
|
|
||||||
- Connections and labels now are adjusted for shapes with `3d` or `multiple`. [#1340](https://github.com/terrastruct/d2/pull/1340)
|
|
||||||
- Display version on CLI help invocation [#1400](https://github.com/terrastruct/d2/pull/1400)
|
- Display version on CLI help invocation [#1400](https://github.com/terrastruct/d2/pull/1400)
|
||||||
- Improved readability of connection labels when they overlap another connection. [#447](https://github.com/terrastruct/d2/pull/447)
|
- Improved readability of connection labels when they overlap another connection. [#447](https://github.com/terrastruct/d2/pull/447)
|
||||||
- Error message when `shape` is given a composite [#1415](https://github.com/terrastruct/d2/pull/1415)
|
- Error message when `shape` is given a composite [#1415](https://github.com/terrastruct/d2/pull/1415)
|
||||||
|
|
|
||||||
|
|
@ -275,36 +275,15 @@ func (p *printer) _map(m *d2ast.Map) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes := []d2ast.MapNodeBox{}
|
|
||||||
// extract out layer, scenario, and step nodes
|
|
||||||
layerNodes := []d2ast.MapNodeBox{}
|
|
||||||
scenarioNodes := []d2ast.MapNodeBox{}
|
|
||||||
stepNodes := []d2ast.MapNodeBox{}
|
|
||||||
for i := 0; i < len(m.Nodes); i++ {
|
|
||||||
node := m.Nodes[i]
|
|
||||||
if node.IsBoardNode() {
|
|
||||||
switch node.MapKey.Key.Path[0].Unbox().ScalarString() {
|
|
||||||
case "layers":
|
|
||||||
layerNodes = append(layerNodes, node)
|
|
||||||
case "scenarios":
|
|
||||||
scenarioNodes = append(scenarioNodes, node)
|
|
||||||
case "steps":
|
|
||||||
stepNodes = append(stepNodes, node)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
nodes = append(nodes, node)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// append layers, scenarios, and steps at the end
|
|
||||||
nodes = append(nodes, layerNodes...)
|
|
||||||
nodes = append(nodes, scenarioNodes...)
|
|
||||||
nodes = append(nodes, stepNodes...)
|
|
||||||
|
|
||||||
prev := d2ast.Node(m)
|
prev := d2ast.Node(m)
|
||||||
for i := 0; i < len(nodes); i++ {
|
for i := 0; i < len(m.Nodes); i++ {
|
||||||
nb := nodes[i]
|
nb := m.Nodes[i]
|
||||||
n := nb.Unbox()
|
n := nb.Unbox()
|
||||||
|
// skip board nodes as we'll write them at the end
|
||||||
|
if nb.IsBoardNode() {
|
||||||
|
prev = n
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Handle inline comments.
|
// Handle inline comments.
|
||||||
if i > 0 && (nb.Comment != nil || nb.BlockComment != nil) {
|
if i > 0 && (nb.Comment != nil || nb.BlockComment != nil) {
|
||||||
|
|
@ -328,12 +307,43 @@ func (p *printer) _map(m *d2ast.Map) {
|
||||||
p.sb.WriteString("; ")
|
p.sb.WriteString("; ")
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.IsFileMap() && nb.IsBoardNode() {
|
p.node(n)
|
||||||
currString := p.sb.String()
|
prev = n
|
||||||
// if the two characters before the board node is not a double newline, we add one
|
}
|
||||||
if currString[len(currString)-2:] != "\n\n" {
|
|
||||||
p.newline()
|
// extract out layer, scenario, and step nodes
|
||||||
}
|
layerNodes := []d2ast.MapNodeBox{}
|
||||||
|
scenarioNodes := []d2ast.MapNodeBox{}
|
||||||
|
stepNodes := []d2ast.MapNodeBox{}
|
||||||
|
for i := 0; i < len(m.Nodes); i++ {
|
||||||
|
node := m.Nodes[i]
|
||||||
|
if !node.IsBoardNode() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch node.MapKey.Key.Path[0].Unbox().ScalarString() {
|
||||||
|
case "layers":
|
||||||
|
layerNodes = append(layerNodes, node)
|
||||||
|
case "scenarios":
|
||||||
|
scenarioNodes = append(scenarioNodes, node)
|
||||||
|
case "steps":
|
||||||
|
stepNodes = append(stepNodes, node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boards := []d2ast.MapNodeBox{}
|
||||||
|
boards = append(boards, layerNodes...)
|
||||||
|
boards = append(boards, scenarioNodes...)
|
||||||
|
boards = append(boards, stepNodes...)
|
||||||
|
|
||||||
|
// draw board nodes
|
||||||
|
for i := 0; i < len(boards); i++ {
|
||||||
|
n := boards[i].Unbox()
|
||||||
|
// if this board is the very first line of the file, don't add an extra indent
|
||||||
|
if n.GetRange().Start.Line != 0 {
|
||||||
|
p.newline()
|
||||||
|
}
|
||||||
|
if len(m.Nodes) > len(boards) {
|
||||||
|
p.newline()
|
||||||
}
|
}
|
||||||
p.node(n)
|
p.node(n)
|
||||||
prev = n
|
prev = n
|
||||||
|
|
|
||||||
|
|
@ -152,8 +152,8 @@ meow
|
||||||
representation: {type: jsonb}
|
representation: {type: jsonb}
|
||||||
diagram: int {constraint: foreign_key}
|
diagram: int {constraint: foreign_key}
|
||||||
}
|
}
|
||||||
|
|
||||||
meow <- diagrams.id
|
meow <- diagrams.id
|
||||||
|
|
||||||
steps: {
|
steps: {
|
||||||
shape: sql_table
|
shape: sql_table
|
||||||
id: {type: int; constraint: primary_key}
|
id: {type: int; constraint: primary_key}
|
||||||
|
|
@ -661,28 +661,21 @@ x: @"x/../file"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "layers_scenarios_steps_bottom_simple",
|
name: "layers_scenarios_steps_bottom_simple",
|
||||||
in: `a
|
in: `layers: {
|
||||||
|
|
||||||
layers: {
|
|
||||||
b: {
|
b: {
|
||||||
|
e
|
||||||
scenarios: {
|
scenarios: {
|
||||||
p: {
|
p: {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g
|
|
||||||
`,
|
`,
|
||||||
exp: `a
|
exp: `layers: {
|
||||||
|
|
||||||
g
|
|
||||||
|
|
||||||
layers: {
|
|
||||||
b: {
|
b: {
|
||||||
e
|
e
|
||||||
|
|
||||||
scenarios: {
|
scenarios: {
|
||||||
p: {
|
p: {
|
||||||
x
|
x
|
||||||
|
|
@ -741,21 +734,35 @@ scenarios: {
|
||||||
|
|
||||||
c
|
c
|
||||||
d
|
d
|
||||||
|
|
||||||
|
only-layers: {
|
||||||
|
layers: {
|
||||||
|
X
|
||||||
|
Y
|
||||||
|
}
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
exp: `a
|
exp: `a
|
||||||
|
|
||||||
b
|
b
|
||||||
|
|
||||||
c
|
c
|
||||||
d
|
d
|
||||||
|
|
||||||
|
only-layers: {
|
||||||
|
layers: {
|
||||||
|
X
|
||||||
|
Y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
layers: {
|
layers: {
|
||||||
Test super nested: {
|
Test super nested: {
|
||||||
base-layer
|
base-layer
|
||||||
|
|
||||||
last-layer
|
last-layer
|
||||||
|
|
||||||
layers: {
|
layers: {
|
||||||
layer-board
|
layer-board
|
||||||
|
|
||||||
layers: {
|
layers: {
|
||||||
grand-child-layer: {
|
grand-child-layer: {
|
||||||
grand-child-board
|
grand-child-board
|
||||||
|
|
@ -768,6 +775,7 @@ layers: {
|
||||||
scenarios: {
|
scenarios: {
|
||||||
scenario-1: {
|
scenario-1: {
|
||||||
non-step
|
non-step
|
||||||
|
|
||||||
steps: {
|
steps: {
|
||||||
step-1: {
|
step-1: {
|
||||||
Test
|
Test
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue