Merge pull request #1869 from alixander/shape-hierarchy
add shape hierarchy
This commit is contained in:
commit
55b8bc89ab
4 changed files with 324 additions and 1 deletions
|
|
@ -2848,6 +2848,14 @@ y.source-arrowhead.shape: cf-one
|
|||
expErr: `d2/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.d2:1:3: "target-arrowhead" can only be used on connections
|
||||
d2/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.d2:2:3: "source-arrowhead" can only be used on connections`,
|
||||
},
|
||||
{
|
||||
name: "shape-hierarchy",
|
||||
text: `x: {
|
||||
shape: hierarchy
|
||||
a -> b
|
||||
}
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
|||
|
|
@ -1036,7 +1036,7 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
|
|||
fmt.Fprint(writer, el.Render())
|
||||
|
||||
// TODO should standardize "" to rectangle
|
||||
case d2target.ShapeRectangle, d2target.ShapeSequenceDiagram, "":
|
||||
case d2target.ShapeRectangle, d2target.ShapeSequenceDiagram, d2target.ShapeHierarchy, "":
|
||||
borderRadius := math.MaxFloat64
|
||||
if targetShape.BorderRadius != 0 {
|
||||
borderRadius = float64(targetShape.BorderRadius)
|
||||
|
|
|
|||
|
|
@ -881,6 +881,7 @@ const (
|
|||
ShapeSQLTable = "sql_table"
|
||||
ShapeImage = "image"
|
||||
ShapeSequenceDiagram = "sequence_diagram"
|
||||
ShapeHierarchy = "hierarchy"
|
||||
)
|
||||
|
||||
var Shapes = []string{
|
||||
|
|
@ -907,6 +908,7 @@ var Shapes = []string{
|
|||
ShapeSQLTable,
|
||||
ShapeImage,
|
||||
ShapeSequenceDiagram,
|
||||
ShapeHierarchy,
|
||||
}
|
||||
|
||||
func IsShape(s string) bool {
|
||||
|
|
@ -974,6 +976,7 @@ var DSL_SHAPE_TO_SHAPE_TYPE = map[string]string{
|
|||
ShapeSQLTable: shape.TABLE_TYPE,
|
||||
ShapeImage: shape.IMAGE_TYPE,
|
||||
ShapeSequenceDiagram: shape.SQUARE_TYPE,
|
||||
ShapeHierarchy: shape.SQUARE_TYPE,
|
||||
}
|
||||
|
||||
var SHAPE_TYPE_TO_DSL_SHAPE map[string]string
|
||||
|
|
|
|||
312
testdata/d2compiler/TestCompile/shape-hierarchy.exp.json
generated
vendored
Normal file
312
testdata/d2compiler/TestCompile/shape-hierarchy.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
{
|
||||
"graph": {
|
||||
"name": "",
|
||||
"isFolderOnly": false,
|
||||
"ast": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,0:0:0-4:0:35",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,0:0:0-3:1:34",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,0:0:0-0:1:1",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,0:0:0-0:1:1",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"map": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,0:3:3-3:1:34",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,1:2:7-1:18:23",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,1:2:7-1:7:12",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,1:2:7-1:7:12",
|
||||
"value": [
|
||||
{
|
||||
"string": "shape",
|
||||
"raw_string": "shape"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,1:9:14-1:18:23",
|
||||
"value": [
|
||||
{
|
||||
"string": "hierarchy",
|
||||
"raw_string": "hierarchy"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,2:2:26-2:8:32",
|
||||
"edges": [
|
||||
{
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,2:2:26-2:8:32",
|
||||
"src": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,2:2:26-2:3:27",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,2:2:26-2:3:27",
|
||||
"value": [
|
||||
{
|
||||
"string": "a",
|
||||
"raw_string": "a"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"src_arrow": "",
|
||||
"dst": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,2:7:31-2:8:32",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,2:7:31-2:8:32",
|
||||
"value": [
|
||||
{
|
||||
"string": "b",
|
||||
"raw_string": "b"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"dst_arrow": ">"
|
||||
}
|
||||
],
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"root": {
|
||||
"id": "",
|
||||
"id_val": "",
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
"edges": [
|
||||
{
|
||||
"index": 0,
|
||||
"isCurve": false,
|
||||
"src_arrow": false,
|
||||
"dst_arrow": true,
|
||||
"references": [
|
||||
{
|
||||
"map_key_edge_index": 0
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
}
|
||||
],
|
||||
"objects": [
|
||||
{
|
||||
"id": "x",
|
||||
"id_val": "x",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,0:0:0-0:1:1",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,0:0:0-0:1:1",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "x"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "hierarchy"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "a",
|
||||
"id_val": "a",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,2:2:26-2:3:27",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,2:2:26-2:3:27",
|
||||
"value": [
|
||||
{
|
||||
"string": "a",
|
||||
"raw_string": "a"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": 0
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "a"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "b",
|
||||
"id_val": "b",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,2:7:31-2:8:32",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/shape-hierarchy.d2,2:7:31-2:8:32",
|
||||
"value": [
|
||||
{
|
||||
"string": "b",
|
||||
"raw_string": "b"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": 0
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "b"
|
||||
},
|
||||
"labelDimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": null
|
||||
},
|
||||
"zIndex": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"err": null
|
||||
}
|
||||
Loading…
Reference in a new issue