fix sql attributes

This commit is contained in:
Alexander Wang 2023-01-13 08:21:32 -08:00
parent b9c4678302
commit adee356d81
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
8 changed files with 856 additions and 11 deletions

View file

@ -763,7 +763,7 @@ func flattenContainer(g *d2graph.Graph, obj *d2graph.Object) {
newEdge.DstTableColumnIndex = new(int)
*newEdge.DstTableColumnIndex = *e.DstTableColumnIndex
}
newEdge.Attributes.Label = e.Attributes.Label
newEdge.Attributes = e.Attributes
newEdge.References = e.References
}
updatedEdges := []*d2graph.Edge{}

View file

@ -1597,6 +1597,25 @@ b`, g.Objects[0].Attributes.Label.Value)
}
},
},
{
name: "table_connection_attr",
text: `x: {
shape: sql_table
y
}
a: {
shape: sql_table
b
}
x.y -> a.b: {
style.animated: true
}
`,
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, "true", g.Edges[0].Attributes.Style.Animated.Value)
},
},
{
name: "class_paren",

View file

@ -1805,6 +1805,15 @@ x: {
y
tooltip: I like turtles
}
a: {
shape: sql_table
b
}
x.y -> a.b: {
style.animated: true
}
`,
},
}

View file

@ -54,7 +54,7 @@
"labelHeight": 0
},
"constraint": "",
"reference": ""
"reference": "a.b"
}
],
"label": "x",
@ -72,7 +72,127 @@
"primaryAccentColor": "#0D32B2",
"secondaryAccentColor": "#4A6FF3",
"neutralAccentColor": "#676C7E"
},
{
"id": "a",
"type": "sql_table",
"pos": {
"x": 0,
"y": 172
},
"width": 60,
"height": 72,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#0A0F25",
"stroke": "#FFFFFF",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": [
{
"name": {
"label": "b",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 10,
"labelHeight": 26
},
"type": {
"label": "",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0
},
"constraint": "",
"reference": ""
}
],
"label": "a",
"fontSize": 20,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 16,
"labelHeight": 36,
"zIndex": 0,
"level": 1,
"primaryAccentColor": "#0D32B2",
"secondaryAccentColor": "#4A6FF3",
"neutralAccentColor": "#676C7E"
}
],
"connections": []
"connections": [
{
"id": "(x -> a)[0]",
"src": "x",
"srcArrow": "none",
"srcLabel": "",
"dst": "a",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "#0D32B2",
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#676C7E",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 30,
"y": 72
},
{
"x": 30,
"y": 112
},
{
"x": 30,
"y": 132
},
{
"x": 30,
"y": 172
}
],
"isCurve": true,
"animated": true,
"tooltip": "",
"icon": null,
"zIndex": 0
}
]
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 327 KiB

After

Width:  |  Height:  |  Size: 328 KiB

View file

@ -54,7 +54,7 @@
"labelHeight": 0
},
"constraint": "",
"reference": ""
"reference": "a.b"
}
],
"label": "x",
@ -72,7 +72,118 @@
"primaryAccentColor": "#0D32B2",
"secondaryAccentColor": "#4A6FF3",
"neutralAccentColor": "#676C7E"
},
{
"id": "a",
"type": "sql_table",
"pos": {
"x": 12,
"y": 184
},
"width": 60,
"height": 72,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#0A0F25",
"stroke": "#FFFFFF",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": [
{
"name": {
"label": "b",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 10,
"labelHeight": 26
},
"type": {
"label": "",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0
},
"constraint": "",
"reference": ""
}
],
"label": "a",
"fontSize": 20,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 16,
"labelHeight": 36,
"zIndex": 0,
"level": 1,
"primaryAccentColor": "#0D32B2",
"secondaryAccentColor": "#4A6FF3",
"neutralAccentColor": "#676C7E"
}
],
"connections": []
"connections": [
{
"id": "(x -> a)[0]",
"src": "x",
"srcArrow": "none",
"srcLabel": "",
"dst": "a",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "#0D32B2",
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#676C7E",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 42,
"y": 84
},
{
"x": 42,
"y": 184
}
],
"animated": true,
"tooltip": "",
"icon": null,
"zIndex": 0
}
]
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 327 KiB

After

Width:  |  Height:  |  Size: 328 KiB

View file

@ -0,0 +1,570 @@
{
"graph": {
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,0:0:0-11:0:99",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,0:0:0-3:1:29",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,0:3:3-3:0:28",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,1:2:7-1:18:23",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,1:2:7-1:7:12",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,1:2:7-1:7:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,1:9:14-1:18:23",
"value": [
{
"string": "sql_table",
"raw_string": "sql_table"
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,2:2:26-2:3:27",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,2:2:26-2:3:27",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,2:2:26-2:3:27",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,4:0:30-7:1:59",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,4:0:30-4:1:31",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,4:0:30-4:1:31",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,4:3:33-7:0:58",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,5:2:37-5:18:53",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,5:2:37-5:7:42",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,5:2:37-5:7:42",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,5:9:44-5:18:53",
"value": [
{
"string": "sql_table",
"raw_string": "sql_table"
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,6:2:56-6:3:57",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,6:2:56-6:3:57",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,6:2:56-6:3:57",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:0:60-10:1:98",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:0:60-8:10:70",
"src": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:0:60-8:4:64",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:0:60-8:1:61",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:2:62-8:3:63",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:6:66-8:10:70",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:7:67-8:8:68",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:9:69-8:10:70",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:12:72-10:0:97",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,9:2:76-9:22:96",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,9:2:76-9:16:90",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,9:2:76-9:7:81",
"value": [
{
"string": "style",
"raw_string": "style"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,9:8:82-9:16:90",
"value": [
{
"string": "animated",
"raw_string": "animated"
}
]
}
}
]
},
"primary": {},
"value": {
"boolean": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,9:18:92-9:22:96",
"value": true
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
}
},
"zIndex": 0
},
"edges": [
{
"index": 0,
"minWidth": 0,
"minHeight": 0,
"srcTableColumnIndex": 0,
"dstTableColumnIndex": 0,
"label_dimensions": {
"width": 0,
"height": 0
},
"isCurve": false,
"src_arrow": false,
"dst_arrow": true,
"references": [
{
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": ""
},
"style": {
"animated": {
"value": "true"
}
},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
}
},
"zIndex": 0
}
],
"objects": [
{
"id": "x",
"id_val": "x",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:0:60-8:4:64",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:0:60-8:1:61",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:2:62-8:3:63",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
}
],
"sql_table": {
"columns": [
{
"name": {
"label": "y",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0
},
"type": {
"label": "",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0
},
"constraint": "",
"reference": "a.b"
}
]
},
"attributes": {
"label": {
"value": "x"
},
"style": {},
"near_key": null,
"shape": {
"value": "sql_table"
},
"direction": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "a",
"id_val": "a",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,4:0:30-4:1:31",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,4:0:30-4:1:31",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
},
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:6:66-8:10:70",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:7:67-8:8:68",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,8:9:69-8:10:70",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
}
],
"sql_table": {
"columns": [
{
"name": {
"label": "b",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0
},
"type": {
"label": "",
"fontSize": 0,
"fontFamily": "",
"language": "",
"color": "",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0
},
"constraint": "",
"reference": ""
}
]
},
"attributes": {
"label": {
"value": "a"
},
"style": {},
"near_key": null,
"shape": {
"value": "sql_table"
},
"direction": {
"value": ""
}
},
"zIndex": 0
}
]
},
"err": null
}