diff --git a/d2compiler/compile.go b/d2compiler/compile.go index df5efd7cd..96bb44847 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -592,14 +592,6 @@ func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) { keyword := strings.ToLower(f.Name) _, isReserved := d2graph.ReservedKeywords[keyword] if isReserved { - switch obj.Attributes.Shape.Value { - case d2target.ShapeSQLTable, d2target.ShapeClass: - default: - if len(obj.Children) > 0 && (f.Name == "width" || f.Name == "height") { - c.errorf(f.LastPrimaryKey(), fmt.Sprintf("%s cannot be used on container: %s", f.Name, obj.AbsID())) - } - } - switch obj.Attributes.Shape.Value { case d2target.ShapeCircle, d2target.ShapeSquare: checkEqual := (keyword == "width" && obj.Attributes.Height != nil) || (keyword == "height" && obj.Attributes.Width != nil) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 537cec457..bedd03206 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -163,8 +163,7 @@ d2/testdata/d2compiler/TestCompile/equal_dimensions_on_circle.d2:4:2: width and }, }, { - name: "no_dimensions_on_containers", - + name: "dimensions_on_containers", text: ` containers: { circle container: { @@ -211,13 +210,6 @@ containers: { } } `, - expErr: `d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:5:3: width cannot be used on container: containers.circle container -d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:15:3: width cannot be used on container: containers.diamond container -d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:16:3: height cannot be used on container: containers.diamond container -d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:25:3: width cannot be used on container: containers.oval container -d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:26:3: height cannot be used on container: containers.oval container -d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:36:3: width cannot be used on container: containers.hexagon container -d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:37:3: height cannot be used on container: containers.hexagon container`, }, { name: "dimension_with_style", diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go index 7e1703b05..a413923c3 100644 --- a/d2layouts/d2elklayout/layout.go +++ b/d2layouts/d2elklayout/layout.go @@ -9,6 +9,7 @@ import ( _ "embed" "encoding/json" "fmt" + "math" "strings" "github.com/dop251/goja" @@ -102,6 +103,9 @@ type elkOpts struct { ForceNodeModelOrder bool `json:"elk.layered.crossingMinimization.forceNodeModelOrder,omitempty"` ConsiderModelOrder string `json:"elk.layered.considerModelOrder.strategy,omitempty"` + NodeSizeConstraints string `json:"elk.nodeSize.constraints,omitempty"` + NodeSizeMinimum string `json:"elk.nodeSize.minimum,omitempty"` + ConfigurableOpts } @@ -173,15 +177,17 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err walk(g.Root, nil, func(obj, parent *d2graph.Object) { height := obj.Height + width := obj.Width if obj.LabelWidth != nil && obj.LabelHeight != nil { if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil { height += float64(*obj.LabelHeight) + label.PADDING } + width = go2.Max(width, float64(*obj.LabelWidth)) } n := &ELKNode{ ID: obj.AbsID(), - Width: obj.Width, + Width: width, Height: height, } @@ -192,6 +198,8 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err EdgeEdgeBetweenLayersSpacing: 50, HierarchyHandling: "INCLUDE_CHILDREN", ConsiderModelOrder: "NODES_AND_EDGES", + // Why is it (height, width)? I have no clue, but it works. + NodeSizeMinimum: fmt.Sprintf("(%d, %d)", int(math.Ceil(height)), int(math.Ceil(width))), ConfigurableOpts: ConfigurableOpts{ NodeSpacing: opts.NodeSpacing, EdgeNodeSpacing: opts.EdgeNodeSpacing, @@ -199,6 +207,12 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err Padding: opts.Padding, }, } + // Only set if specified. + // There's a bug where if it's the node label dimensions that set the NodeSizeMinimum, + // then suddenly it's reversed back to (width, height). I must be missing something + if obj.Attributes.Width != nil || obj.Attributes.Height != nil { + n.LayoutOptions.NodeSizeConstraints = "MINIMUM_SIZE" + } if n.LayoutOptions.Padding == DefaultOpts.Padding { // Default diff --git a/d2layouts/d2layoutfeatures/d2layoutfeatures.go b/d2layouts/d2layoutfeatures/d2layoutfeatures.go new file mode 100644 index 000000000..40771b229 --- /dev/null +++ b/d2layouts/d2layoutfeatures/d2layoutfeatures.go @@ -0,0 +1,11 @@ +package d2layoutfeatures + +// When this is true, objects can set ther `near` key to another object +// When this is false, objects can only set `near` to constants +const NEAR_OBJECT = "near_object" + +// When this is true, containers can have dimensions set +const CONTAINER_DIMENSIONS = "container_dimensions" + +// When this is true, objects can specify their `top` and `left` keywords +const TOP_LEFT = "top_left" diff --git a/d2plugin/plugin.go b/d2plugin/plugin.go index 7a30fad87..456c3cbad 100644 --- a/d2plugin/plugin.go +++ b/d2plugin/plugin.go @@ -77,6 +77,8 @@ type PluginInfo struct { Type string `json:"type"` // If Type == binary then this contains the absolute path to the binary. Path string `json:"path"` + + Features map[PluginFeature]struct{} `json:"features"` } const binaryPrefix = "d2plugin-" diff --git a/d2plugin/plugin_dagre.go b/d2plugin/plugin_dagre.go index 6c0237060..478aca5bf 100644 --- a/d2plugin/plugin_dagre.go +++ b/d2plugin/plugin_dagre.go @@ -67,6 +67,7 @@ func (p dagrePlugin) Info(ctx context.Context) (*PluginInfo, error) { return &PluginInfo{ Name: "dagre", Type: "bundled", + Features: make(map[PluginFeature]struct{}), ShortHelp: "The directed graph layout library Dagre", LongHelp: fmt.Sprintf(`dagre is a directed graph layout library for JavaScript. See https://d2lang.com/tour/dagre for more. diff --git a/d2plugin/plugin_elk.go b/d2plugin/plugin_elk.go index aa49c909d..f67af65ab 100644 --- a/d2plugin/plugin_elk.go +++ b/d2plugin/plugin_elk.go @@ -85,8 +85,11 @@ func (p elkPlugin) Info(ctx context.Context) (*PluginInfo, error) { f.AddToOpts(opts) } return &PluginInfo{ - Name: "elk", - Type: "bundled", + Name: "elk", + Type: "bundled", + Features: map[PluginFeature]struct{}{ + CONTAINER_DIMENSIONS: {}, + }, ShortHelp: "Eclipse Layout Kernel (ELK) with the Layered algorithm.", LongHelp: fmt.Sprintf(`ELK is a layout engine offered by Eclipse. Originally written in Java, it has been ported to Javascript and cross-compiled into D2. diff --git a/d2plugin/plugin_features.go b/d2plugin/plugin_features.go new file mode 100644 index 000000000..5ea4518b0 --- /dev/null +++ b/d2plugin/plugin_features.go @@ -0,0 +1,49 @@ +package d2plugin + +import ( + "fmt" + + "oss.terrastruct.com/d2/d2graph" +) + +type PluginFeature string + +// When this is true, objects can set ther `near` key to another object +// When this is false, objects can only set `near` to constants +const NEAR_OBJECT PluginFeature = "near_object" + +// When this is true, containers can have dimensions set +const CONTAINER_DIMENSIONS PluginFeature = "container_dimensions" + +// When this is true, objects can specify their `top` and `left` keywords +const TOP_LEFT PluginFeature = "top_left" + +func FeatureSupportCheck(info *PluginInfo, g *d2graph.Graph) error { + // Older version of plugin. Skip checking. + if info.Features == nil { + return nil + } + + for _, obj := range g.Objects { + if obj.Attributes.Top != nil || obj.Attributes.Left != nil { + if _, ok := info.Features[TOP_LEFT]; !ok { + return fmt.Errorf(`Object "%s" has attribute "top" and/or "left" set, but layout engine "%s" does not support locked positions.`, obj.AbsID(), info.Name) + } + } + if (obj.Attributes.Width != nil || obj.Attributes.Height != nil) && len(obj.ChildrenArray) > 0 { + if _, ok := info.Features[CONTAINER_DIMENSIONS]; !ok { + return fmt.Errorf(`Object "%s" has attribute "width" and/or "height" set, but layout engine "%s" does not support dimensions set on containers.`, obj.AbsID(), info.Name) + } + } + + if obj.Attributes.NearKey != nil { + _, isKey := g.Root.HasChild(d2graph.Key(obj.Attributes.NearKey)) + if isKey { + if _, ok := info.Features[NEAR_OBJECT]; !ok { + return fmt.Errorf(`Object "%s" has "near" set to another object, but layout engine "%s" only supports constant values for "near".`, obj.AbsID(), info.Name) + } + } + } + } + return nil +} diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index a2d38b57f..169d1ad1e 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1767,6 +1767,30 @@ class.height: 512 users.height: 512 code.height: 512 package.height: 512 +`, + }, + { + name: "container_dimensions", + script: `a: { + width: 500 + b -> c + b.width: 400 + c.width: 600 +} + +b: { + width: 700 + b -> c + e: { + height: 300 + } +} + +c: { + width: 200 + height: 300 + a +} `, }, { diff --git a/e2etests/testdata/stable/container_dimensions/dagre/board.exp.json b/e2etests/testdata/stable/container_dimensions/dagre/board.exp.json new file mode 100644 index 000000000..317bd2d40 --- /dev/null +++ b/e2etests/testdata/stable/container_dimensions/dagre/board.exp.json @@ -0,0 +1,473 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "a", + "type": "rectangle", + "pos": { + "x": 0, + "y": 41 + }, + "width": 680, + "height": 575, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "a", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 12, + "labelHeight": 36, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "a.b", + "type": "rectangle", + "pos": { + "x": 140, + "y": 73 + }, + "width": 400, + "height": 61, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "a.c", + "type": "rectangle", + "pos": { + "x": 40, + "y": 406 + }, + "width": 600, + "height": 61, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "b", + "type": "rectangle", + "pos": { + "x": 853, + "y": 41 + }, + "width": 241, + "height": 575, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 13, + "labelHeight": 36, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "b.b", + "type": "rectangle", + "pos": { + "x": 893, + "y": 70 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "b.c", + "type": "rectangle", + "pos": { + "x": 893, + "y": 403 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "b.e", + "type": "rectangle", + "pos": { + "x": 1006, + "y": 286 + }, + "width": 48, + "height": 300, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "e", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "c", + "type": "rectangle", + "pos": { + "x": 700, + "y": 41 + }, + "width": 133, + "height": 125, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "c", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 12, + "labelHeight": 36, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "c.a", + "type": "rectangle", + "pos": { + "x": 740, + "y": 70 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + } + ], + "connections": [ + { + "id": "a.(b -> c)[0]", + "src": "a.b", + "srcArrow": "none", + "srcLabel": "", + "dst": "a.c", + "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": 340, + "y": 135 + }, + { + "x": 340, + "y": 176.2 + }, + { + "x": 340, + "y": 270.4 + }, + { + "x": 340, + "y": 406 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "b.(b -> c)[0]", + "src": "b.b", + "srcArrow": "none", + "srcLabel": "", + "dst": "b.c", + "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": 919.5, + "y": 136.5 + }, + { + "x": 919.5, + "y": 176.5 + }, + { + "x": 919.5, + "y": 269.9 + }, + { + "x": 919.5, + "y": 403.5 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ] +} diff --git a/e2etests/testdata/stable/container_dimensions/dagre/sketch.exp.svg b/e2etests/testdata/stable/container_dimensions/dagre/sketch.exp.svg new file mode 100644 index 000000000..eb78ff58d --- /dev/null +++ b/e2etests/testdata/stable/container_dimensions/dagre/sketch.exp.svg @@ -0,0 +1,59 @@ + +abcbcbcea + + + \ No newline at end of file diff --git a/e2etests/testdata/stable/container_dimensions/elk/board.exp.json b/e2etests/testdata/stable/container_dimensions/elk/board.exp.json new file mode 100644 index 000000000..96eb760eb --- /dev/null +++ b/e2etests/testdata/stable/container_dimensions/elk/board.exp.json @@ -0,0 +1,455 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "a", + "type": "rectangle", + "pos": { + "x": 12, + "y": 134 + }, + "width": 700, + "height": 292, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "a", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 12, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "a.b", + "type": "rectangle", + "pos": { + "x": 162, + "y": 184 + }, + "width": 400, + "height": 61, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "a.c", + "type": "rectangle", + "pos": { + "x": 62, + "y": 315 + }, + "width": 600, + "height": 61, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "b", + "type": "rectangle", + "pos": { + "x": 732, + "y": 12 + }, + "width": 700, + "height": 536, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 13, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "b.b", + "type": "rectangle", + "pos": { + "x": 782, + "y": 296 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "b.c", + "type": "rectangle", + "pos": { + "x": 782, + "y": 432 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "b.e", + "type": "rectangle", + "pos": { + "x": 855, + "y": 62 + }, + "width": 48, + "height": 300, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "e", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "c", + "type": "rectangle", + "pos": { + "x": 1452, + "y": 130 + }, + "width": 200, + "height": 300, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "c", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 12, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "c.a", + "type": "rectangle", + "pos": { + "x": 1502, + "y": 180 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + } + ], + "connections": [ + { + "id": "a.(b -> c)[0]", + "src": "a.b", + "srcArrow": "none", + "srcLabel": "", + "dst": "a.c", + "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": 362, + "y": 245 + }, + { + "x": 362, + "y": 315 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "b.(b -> c)[0]", + "src": "b.b", + "srcArrow": "none", + "srcLabel": "", + "dst": "b.c", + "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": 808.5, + "y": 362 + }, + { + "x": 808.5, + "y": 432 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ] +} diff --git a/e2etests/testdata/stable/container_dimensions/elk/sketch.exp.svg b/e2etests/testdata/stable/container_dimensions/elk/sketch.exp.svg new file mode 100644 index 000000000..3a1b99b89 --- /dev/null +++ b/e2etests/testdata/stable/container_dimensions/elk/sketch.exp.svg @@ -0,0 +1,59 @@ + +abcbcbcea + + + \ No newline at end of file diff --git a/main.go b/main.go index 6634e25a8..9b7da5cba 100644 --- a/main.go +++ b/main.go @@ -251,7 +251,17 @@ func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketc if sketch { opts.FontFamily = go2.Pointer(d2fonts.HandDrawn) } - diagram, _, err := d2lib.Compile(ctx, string(input), opts) + diagram, g, err := d2lib.Compile(ctx, string(input), opts) + if err != nil { + return nil, false, err + } + + pluginInfo, err := plugin.Info(ctx) + if err != nil { + return nil, false, err + } + + err = d2plugin.FeatureSupportCheck(pluginInfo, g) if err != nil { return nil, false, err } diff --git a/testdata/d2compiler/TestCompile/dimensions_on_containers.exp.json b/testdata/d2compiler/TestCompile/dimensions_on_containers.exp.json new file mode 100644 index 000000000..a5b45a2b1 --- /dev/null +++ b/testdata/d2compiler/TestCompile/dimensions_on_containers.exp.json @@ -0,0 +1,1435 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,0:0:0-45:0:505", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,1:0:1-44:1:504", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,1:0:1-1:10:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,1:0:1-1:10:11", + "value": [ + { + "string": "containers", + "raw_string": "containers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,1:12:13-44:0:503", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,2:1:16-11:2:131", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,2:1:16-2:17:32", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,2:1:16-2:17:32", + "value": [ + { + "string": "circle container", + "raw_string": "circle container" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,2:19:34-11:1:130", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,3:2:38-3:15:51", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,3:2:38-3:7:43", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,3:2:38-3:7:43", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,3:9:45-3:15:51", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,4:2:54-4:12:64", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,4:2:54-4:7:59", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,4:2:54-4:7:59", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,4:9:61-4:12:64", + "raw": "512", + "value": "512" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,6:2:68-10:3:128", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,6:2:68-6:9:75", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,6:2:68-6:9:75", + "value": [ + { + "string": "diamond", + "raw_string": "diamond" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,6:11:77-10:2:127", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,7:3:82-7:17:96", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,7:3:82-7:8:87", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,7:3:82-7:8:87", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,7:10:89-7:17:96", + "value": [ + { + "string": "diamond", + "raw_string": "diamond" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,8:3:100-8:13:110", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,8:3:100-8:8:105", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,8:3:100-8:8:105", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,8:10:107-8:13:110", + "raw": "128", + "value": "128" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,9:3:114-9:13:124", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,9:3:114-9:9:120", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,9:3:114-9:9:120", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,9:11:122-9:13:124", + "raw": "64", + "value": "64" + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,12:1:133-21:2:248", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,12:1:133-12:18:150", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,12:1:133-12:18:150", + "value": [ + { + "string": "diamond container", + "raw_string": "diamond container" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,12:20:152-21:1:247", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,13:2:156-13:16:170", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,13:2:156-13:7:161", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,13:2:156-13:7:161", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,13:9:163-13:16:170", + "value": [ + { + "string": "diamond", + "raw_string": "diamond" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,14:2:173-14:12:183", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,14:2:173-14:7:178", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,14:2:173-14:7:178", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,14:9:180-14:12:183", + "raw": "512", + "value": "512" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,15:2:186-15:13:197", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,15:2:186-15:8:192", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,15:2:186-15:8:192", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,15:10:194-15:13:197", + "raw": "256", + "value": "256" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,17:2:201-20:3:245", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,17:2:201-17:8:207", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,17:2:201-17:8:207", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,17:10:209-20:2:244", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,18:3:214-18:16:227", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,18:3:214-18:8:219", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,18:3:214-18:8:219", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,18:10:221-18:16:227", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,19:3:231-19:13:241", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,19:3:231-19:8:236", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,19:3:231-19:8:236", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,19:10:238-19:13:241", + "raw": "128", + "value": "128" + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,22:1:250-32:2:375", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,22:1:250-22:15:264", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,22:1:250-22:15:264", + "value": [ + { + "string": "oval container", + "raw_string": "oval container" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,22:17:266-32:1:374", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,23:2:270-23:13:281", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,23:2:270-23:7:275", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,23:2:270-23:7:275", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,23:9:277-23:13:281", + "value": [ + { + "string": "oval", + "raw_string": "oval" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,24:2:284-24:12:294", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,24:2:284-24:7:289", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,24:2:284-24:7:289", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,24:9:291-24:12:294", + "raw": "512", + "value": "512" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,25:2:297-25:13:308", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,25:2:297-25:8:303", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,25:2:297-25:8:303", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,25:10:305-25:13:308", + "raw": "256", + "value": "256" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,27:2:312-31:3:372", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,27:2:312-27:9:319", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,27:2:312-27:9:319", + "value": [ + { + "string": "hexagon", + "raw_string": "hexagon" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,27:11:321-31:2:371", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,28:3:326-28:17:340", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,28:3:326-28:8:331", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,28:3:326-28:8:331", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,28:10:333-28:17:340", + "value": [ + { + "string": "hexagon", + "raw_string": "hexagon" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,29:3:344-29:13:354", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,29:3:344-29:8:349", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,29:3:344-29:8:349", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,29:10:351-29:13:354", + "raw": "128", + "value": "128" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,30:3:358-30:13:368", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,30:3:358-30:9:364", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,30:3:358-30:9:364", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,30:11:366-30:13:368", + "raw": "64", + "value": "64" + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,33:1:377-43:2:502", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,33:1:377-33:18:394", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,33:1:377-33:18:394", + "value": [ + { + "string": "hexagon container", + "raw_string": "hexagon container" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,33:20:396-43:1:501", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,34:2:400-34:16:414", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,34:2:400-34:7:405", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,34:2:400-34:7:405", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,34:9:407-34:16:414", + "value": [ + { + "string": "hexagon", + "raw_string": "hexagon" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,35:2:417-35:12:427", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,35:2:417-35:7:422", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,35:2:417-35:7:422", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,35:9:424-35:12:427", + "raw": "512", + "value": "512" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,36:2:430-36:13:441", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,36:2:430-36:8:436", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,36:2:430-36:8:436", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,36:10:438-36:13:441", + "raw": "256", + "value": "256" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,38:2:445-42:3:499", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,38:2:445-38:6:449", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,38:2:445-38:6:449", + "value": [ + { + "string": "oval", + "raw_string": "oval" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,38:8:451-42:2:498", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,39:3:456-39:14:467", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,39:3:456-39:8:461", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,39:3:456-39:8:461", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,39:10:463-39:14:467", + "value": [ + { + "string": "oval", + "raw_string": "oval" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,40:3:471-40:13:481", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,40:3:471-40:8:476", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,40:3:471-40:8:476", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,40:10:478-40:13:481", + "raw": "128", + "value": "128" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,41:3:485-41:13:495", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,41:3:485-41:9:491", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,41:3:485-41:9:491", + "value": [ + { + "string": "height", + "raw_string": "height" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,41:11:493-41:13:495", + "raw": "64", + "value": "64" + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "containers", + "id_val": "containers", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,1:0:1-1:10:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,1:0:1-1:10:11", + "value": [ + { + "string": "containers", + "raw_string": "containers" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "containers" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "circle container", + "id_val": "circle container", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,2:1:16-2:17:32", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,2:1:16-2:17:32", + "value": [ + { + "string": "circle container", + "raw_string": "circle container" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "circle container" + }, + "style": {}, + "width": { + "value": "512" + }, + "near_key": null, + "shape": { + "value": "circle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "diamond", + "id_val": "diamond", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,6:2:68-6:9:75", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,6:2:68-6:9:75", + "value": [ + { + "string": "diamond", + "raw_string": "diamond" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "diamond" + }, + "style": {}, + "width": { + "value": "128" + }, + "height": { + "value": "64" + }, + "near_key": null, + "shape": { + "value": "diamond" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "diamond container", + "id_val": "diamond container", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,12:1:133-12:18:150", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,12:1:133-12:18:150", + "value": [ + { + "string": "diamond container", + "raw_string": "diamond container" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "diamond container" + }, + "style": {}, + "width": { + "value": "512" + }, + "height": { + "value": "256" + }, + "near_key": null, + "shape": { + "value": "diamond" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "circle", + "id_val": "circle", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,17:2:201-17:8:207", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,17:2:201-17:8:207", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "circle" + }, + "style": {}, + "width": { + "value": "128" + }, + "near_key": null, + "shape": { + "value": "circle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "oval container", + "id_val": "oval container", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,22:1:250-22:15:264", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,22:1:250-22:15:264", + "value": [ + { + "string": "oval container", + "raw_string": "oval container" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "oval container" + }, + "style": {}, + "width": { + "value": "512" + }, + "height": { + "value": "256" + }, + "near_key": null, + "shape": { + "value": "oval" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "hexagon", + "id_val": "hexagon", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,27:2:312-27:9:319", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,27:2:312-27:9:319", + "value": [ + { + "string": "hexagon", + "raw_string": "hexagon" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hexagon" + }, + "style": {}, + "width": { + "value": "128" + }, + "height": { + "value": "64" + }, + "near_key": null, + "shape": { + "value": "hexagon" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "hexagon container", + "id_val": "hexagon container", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,33:1:377-33:18:394", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,33:1:377-33:18:394", + "value": [ + { + "string": "hexagon container", + "raw_string": "hexagon container" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hexagon container" + }, + "style": {}, + "width": { + "value": "512" + }, + "height": { + "value": "256" + }, + "near_key": null, + "shape": { + "value": "hexagon" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "oval", + "id_val": "oval", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,38:2:445-38:6:449", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,38:2:445-38:6:449", + "value": [ + { + "string": "oval", + "raw_string": "oval" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "oval" + }, + "style": {}, + "width": { + "value": "128" + }, + "height": { + "value": "64" + }, + "near_key": null, + "shape": { + "value": "oval" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/no_dimensions_on_containers.exp.json b/testdata/d2compiler/TestCompile/no_dimensions_on_containers.exp.json deleted file mode 100644 index ec21bacd7..000000000 --- a/testdata/d2compiler/TestCompile/no_dimensions_on_containers.exp.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "graph": null, - "err": { - "ioerr": null, - "errs": [ - { - "range": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2,4:2:54-4:12:64", - "errmsg": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:5:3: width cannot be used on container: containers.circle container" - }, - { - "range": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2,14:2:173-14:12:183", - "errmsg": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:15:3: width cannot be used on container: containers.diamond container" - }, - { - "range": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2,15:2:186-15:13:197", - "errmsg": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:16:3: height cannot be used on container: containers.diamond container" - }, - { - "range": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2,24:2:284-24:12:294", - "errmsg": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:25:3: width cannot be used on container: containers.oval container" - }, - { - "range": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2,25:2:297-25:13:308", - "errmsg": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:26:3: height cannot be used on container: containers.oval container" - }, - { - "range": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2,35:2:417-35:12:427", - "errmsg": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:36:3: width cannot be used on container: containers.hexagon container" - }, - { - "range": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2,36:2:430-36:13:441", - "errmsg": "d2/testdata/d2compiler/TestCompile/no_dimensions_on_containers.d2:37:3: height cannot be used on container: containers.hexagon container" - } - ] - } -}