Rename rows to columns and omit empty indices
This commit is contained in:
parent
a943bea111
commit
07bd4cca50
3 changed files with 49 additions and 8 deletions
|
|
@ -680,11 +680,12 @@ func (c *compiler) compileSQLTable(obj *d2graph.Object) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if srcID == absID {
|
if srcID == absID {
|
||||||
// Frontend isn't aware of container IDs.
|
|
||||||
d2Col.Reference = strings.TrimPrefix(dstID, parentID+".")
|
d2Col.Reference = strings.TrimPrefix(dstID, parentID+".")
|
||||||
e.FromTableRowIndex = len(obj.SQLTable.Columns)
|
e.FromTableColumnIndex = new(int)
|
||||||
} else {
|
*e.FromTableColumnIndex = len(obj.SQLTable.Columns)
|
||||||
e.ToTableRowIndex = len(obj.SQLTable.Columns)
|
} else if dstID == absID {
|
||||||
|
e.ToTableColumnIndex = new(int)
|
||||||
|
*e.ToTableColumnIndex = len(obj.SQLTable.Columns)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -745,8 +746,10 @@ func flattenContainer(g *d2graph.Graph, obj *d2graph.Object) {
|
||||||
newEdge, _ = g.Root.Connect(e.Src.AbsIDArray(), obj.AbsIDArray(), e.SrcArrow, e.DstArrow, e.Attributes.Label.Value)
|
newEdge, _ = g.Root.Connect(e.Src.AbsIDArray(), obj.AbsIDArray(), e.SrcArrow, e.DstArrow, e.Attributes.Label.Value)
|
||||||
}
|
}
|
||||||
// TODO more attributes
|
// TODO more attributes
|
||||||
newEdge.FromTableRowIndex = e.FromTableRowIndex
|
newEdge.FromTableColumnIndex = new(int)
|
||||||
newEdge.ToTableRowIndex = e.ToTableRowIndex
|
*newEdge.FromTableColumnIndex = *e.FromTableColumnIndex
|
||||||
|
newEdge.ToTableColumnIndex = new(int)
|
||||||
|
*newEdge.ToTableColumnIndex = *e.ToTableColumnIndex
|
||||||
newEdge.Attributes.Label = e.Attributes.Label
|
newEdge.Attributes.Label = e.Attributes.Label
|
||||||
newEdge.References = e.References
|
newEdge.References = e.References
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -607,8 +607,8 @@ type Edge struct {
|
||||||
MinWidth int `json:"minWidth"`
|
MinWidth int `json:"minWidth"`
|
||||||
MinHeight int `json:"minHeight"`
|
MinHeight int `json:"minHeight"`
|
||||||
|
|
||||||
FromTableRowIndex int `json:"fromTableRowIndex"`
|
FromTableColumnIndex *int `json:"fromTableColumnIndex,omitempty"`
|
||||||
ToTableRowIndex int `json:"toTableRowIndex"`
|
ToTableColumnIndex *int `json:"toTableColumnIndex,omitempty"`
|
||||||
|
|
||||||
LabelDimensions d2target.TextDimensions `json:"label_dimensions"`
|
LabelDimensions d2target.TextDimensions `json:"label_dimensions"`
|
||||||
LabelPosition *string `json:"labelPosition,omitempty"`
|
LabelPosition *string `json:"labelPosition,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -831,6 +831,44 @@ a -> md -> b
|
||||||
+setTimeout(seconds int)
|
+setTimeout(seconds int)
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
}, {
|
||||||
|
name: "sql_tables",
|
||||||
|
script: `
|
||||||
|
users: {
|
||||||
|
shape: sql_table
|
||||||
|
id: int
|
||||||
|
name: string
|
||||||
|
email: string
|
||||||
|
password: string
|
||||||
|
last_login: datetime
|
||||||
|
}
|
||||||
|
|
||||||
|
products: {
|
||||||
|
shape: sql_table
|
||||||
|
id: int
|
||||||
|
price: decimal
|
||||||
|
sku: string
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
orders: {
|
||||||
|
shape: sql_table
|
||||||
|
id: int
|
||||||
|
user_id: int
|
||||||
|
product_id: int
|
||||||
|
}
|
||||||
|
|
||||||
|
shipments: {
|
||||||
|
shape: sql_table
|
||||||
|
id: int
|
||||||
|
order_id: int
|
||||||
|
tracking_number: string
|
||||||
|
status: string
|
||||||
|
}
|
||||||
|
|
||||||
|
users.id <-> orders.user_id
|
||||||
|
products.id <-> orders.product_id
|
||||||
|
shipments.order_id <-> orders.id`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue