From b9c467830241d2a9b147c214271e270e5d1cfdd0 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 13 Jan 2023 08:16:18 -0800 Subject: [PATCH 1/4] tooltip --- d2renderers/d2svg/d2svg.go | 42 +++++----- e2etests/stable_test.go | 10 +++ .../dagre/board.exp.json | 78 +++++++++++++++++++ .../dagre/sketch.exp.svg | 70 +++++++++++++++++ .../elk/board.exp.json | 78 +++++++++++++++++++ .../elk/sketch.exp.svg | 70 +++++++++++++++++ 6 files changed, 330 insertions(+), 18 deletions(-) create mode 100644 e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json create mode 100644 e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/stable/sql_table_tooltip_animated/elk/board.exp.json create mode 100644 e2etests/testdata/stable/sql_table_tooltip_animated/elk/sketch.exp.svg diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 87bfff9a2..b57b483e8 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -687,6 +687,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske } else { drawClass(writer, targetShape) } + addAppendixItems(writer, targetShape) fmt.Fprintf(writer, ``) fmt.Fprintf(writer, closingTag) return labelMask, nil @@ -700,6 +701,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske } else { drawTable(writer, targetShape) } + addAppendixItems(writer, targetShape) fmt.Fprintf(writer, ``) fmt.Fprintf(writer, closingTag) return labelMask, nil @@ -899,29 +901,33 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske } } - rightPadForTooltip := 0 - if targetShape.Tooltip != "" { - rightPadForTooltip = 2 * appendixIconRadius - fmt.Fprintf(writer, `%s`, - targetShape.Pos.X+targetShape.Width-appendixIconRadius, - targetShape.Pos.Y-appendixIconRadius, - TooltipIcon, - ) - fmt.Fprintf(writer, `%s`, targetShape.Tooltip) - } - - if targetShape.Link != "" { - fmt.Fprintf(writer, `%s`, - targetShape.Pos.X+targetShape.Width-appendixIconRadius-rightPadForTooltip, - targetShape.Pos.Y-appendixIconRadius, - LinkIcon, - ) - } + addAppendixItems(writer, targetShape) fmt.Fprintf(writer, closingTag) return labelMask, nil } +func addAppendixItems(writer io.Writer, shape d2target.Shape) { + rightPadForTooltip := 0 + if shape.Tooltip != "" { + rightPadForTooltip = 2 * appendixIconRadius + fmt.Fprintf(writer, `%s`, + shape.Pos.X+shape.Width-appendixIconRadius, + shape.Pos.Y-appendixIconRadius, + TooltipIcon, + ) + fmt.Fprintf(writer, `%s`, shape.Tooltip) + } + + if shape.Link != "" { + fmt.Fprintf(writer, `%s`, + shape.Pos.X+shape.Width-appendixIconRadius-rightPadForTooltip, + shape.Pos.Y-appendixIconRadius, + LinkIcon, + ) + } +} + func RenderText(text string, x, height float64) string { if !strings.Contains(text, "\n") { return svg.EscapeText(text) diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index 18af2f0b8..c65582e72 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1795,6 +1795,16 @@ Listen <-> Talk: { target-arrowhead.shape: diamond label: hear } +`, + }, + { + name: "sql_table_tooltip_animated", + script: ` +x: { + shape: sql_table + y + tooltip: I like turtles +} `, }, } diff --git a/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json new file mode 100644 index 000000000..5cacce054 --- /dev/null +++ b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json @@ -0,0 +1,78 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "x", + "type": "sql_table", + "pos": { + "x": 0, + "y": 0 + }, + "width": 60, + "height": 72, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#0A0F25", + "stroke": "#FFFFFF", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "I like turtles", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": [ + { + "name": { + "label": "y", + "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": "x", + "fontSize": 20, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 17, + "labelHeight": 36, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" + } + ], + "connections": [] +} diff --git a/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg new file mode 100644 index 000000000..45bf8f483 --- /dev/null +++ b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg @@ -0,0 +1,70 @@ + +xy + + + + + + + + + + + + + + +I like turtles + + + \ No newline at end of file diff --git a/e2etests/testdata/stable/sql_table_tooltip_animated/elk/board.exp.json b/e2etests/testdata/stable/sql_table_tooltip_animated/elk/board.exp.json new file mode 100644 index 000000000..d54413e03 --- /dev/null +++ b/e2etests/testdata/stable/sql_table_tooltip_animated/elk/board.exp.json @@ -0,0 +1,78 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "x", + "type": "sql_table", + "pos": { + "x": 12, + "y": 12 + }, + "width": 60, + "height": 72, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#0A0F25", + "stroke": "#FFFFFF", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "I like turtles", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": [ + { + "name": { + "label": "y", + "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": "x", + "fontSize": 20, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 17, + "labelHeight": 36, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" + } + ], + "connections": [] +} diff --git a/e2etests/testdata/stable/sql_table_tooltip_animated/elk/sketch.exp.svg b/e2etests/testdata/stable/sql_table_tooltip_animated/elk/sketch.exp.svg new file mode 100644 index 000000000..2517048ed --- /dev/null +++ b/e2etests/testdata/stable/sql_table_tooltip_animated/elk/sketch.exp.svg @@ -0,0 +1,70 @@ + +xy + + + + + + + + + + + + + + +I like turtles + + + \ No newline at end of file From adee356d81b8b5c6cdc1502674975d1df269ea33 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 13 Jan 2023 08:21:32 -0800 Subject: [PATCH 2/4] fix sql attributes --- d2compiler/compile.go | 2 +- d2compiler/compile_test.go | 19 + e2etests/stable_test.go | 9 + .../dagre/board.exp.json | 124 +++- .../dagre/sketch.exp.svg | 14 +- .../elk/board.exp.json | 115 +++- .../elk/sketch.exp.svg | 14 +- .../table_connection_attr.exp.json | 570 ++++++++++++++++++ 8 files changed, 856 insertions(+), 11 deletions(-) create mode 100644 testdata/d2compiler/TestCompile/table_connection_attr.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 48498a767..38c1f68d6 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -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{} diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 81db413f2..a432f078e 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -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", diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index c65582e72..24981d9fe 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1805,6 +1805,15 @@ x: { y tooltip: I like turtles } + +a: { + shape: sql_table + b +} + +x.y -> a.b: { + style.animated: true +} `, }, } diff --git a/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json index 5cacce054..93aba66a4 100644 --- a/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json +++ b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json @@ -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 + } + ] } diff --git a/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg index 45bf8f483..4c942441c 100644 --- a/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg @@ -3,7 +3,7 @@ id="d2-svg" style="background: white;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" -width="280" height="292" viewBox="-102 -118 280 292"> \ No newline at end of file diff --git a/e2etests/testdata/stable/sql_table_tooltip_animated/elk/board.exp.json b/e2etests/testdata/stable/sql_table_tooltip_animated/elk/board.exp.json index d54413e03..315f66a6c 100644 --- a/e2etests/testdata/stable/sql_table_tooltip_animated/elk/board.exp.json +++ b/e2etests/testdata/stable/sql_table_tooltip_animated/elk/board.exp.json @@ -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 + } + ] } diff --git a/e2etests/testdata/stable/sql_table_tooltip_animated/elk/sketch.exp.svg b/e2etests/testdata/stable/sql_table_tooltip_animated/elk/sketch.exp.svg index 2517048ed..0efc20882 100644 --- a/e2etests/testdata/stable/sql_table_tooltip_animated/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/sql_table_tooltip_animated/elk/sketch.exp.svg @@ -3,7 +3,7 @@ id="d2-svg" style="background: white;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" -width="280" height="292" viewBox="-90 -106 280 292"> \ No newline at end of file diff --git a/testdata/d2compiler/TestCompile/table_connection_attr.exp.json b/testdata/d2compiler/TestCompile/table_connection_attr.exp.json new file mode 100644 index 000000000..2dc6c143d --- /dev/null +++ b/testdata/d2compiler/TestCompile/table_connection_attr.exp.json @@ -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 +} From 1420dab5a92ef4e638e9d2be7fbad7744e13feb9 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 13 Jan 2023 08:26:38 -0800 Subject: [PATCH 3/4] also transfer arrowheads --- d2compiler/compile.go | 2 ++ e2etests/stable_test.go | 1 + .../stable/sql_table_tooltip_animated/dagre/board.exp.json | 2 +- .../stable/sql_table_tooltip_animated/dagre/sketch.exp.svg | 2 +- .../stable/sql_table_tooltip_animated/elk/board.exp.json | 2 +- .../stable/sql_table_tooltip_animated/elk/sketch.exp.svg | 2 +- 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 38c1f68d6..c89a4853e 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -757,10 +757,12 @@ func flattenContainer(g *d2graph.Graph, obj *d2graph.Object) { // TODO more attributes if e.SrcTableColumnIndex != nil { newEdge.SrcTableColumnIndex = new(int) + newEdge.SrcArrowhead = e.SrcArrowhead *newEdge.SrcTableColumnIndex = *e.SrcTableColumnIndex } if e.DstTableColumnIndex != nil { newEdge.DstTableColumnIndex = new(int) + newEdge.DstArrowhead = e.DstArrowhead *newEdge.DstTableColumnIndex = *e.DstTableColumnIndex } newEdge.Attributes = e.Attributes diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index 24981d9fe..fb9f7399a 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1813,6 +1813,7 @@ a: { x.y -> a.b: { style.animated: true + target-arrowhead.shape: cf-many } `, }, diff --git a/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json index 93aba66a4..08265e940 100644 --- a/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json +++ b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/board.exp.json @@ -152,7 +152,7 @@ "srcArrow": "none", "srcLabel": "", "dst": "a", - "dstArrow": "triangle", + "dstArrow": "cf-many", "dstLabel": "", "opacity": 1, "strokeDash": 0, diff --git a/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg index 4c942441c..12c3e8317 100644 --- a/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sql_table_tooltip_animated/dagre/sketch.exp.svg @@ -56,7 +56,7 @@ width="280" height="464" viewBox="-102 -118 280 464">