fix sql_table width measurement
This commit is contained in:
parent
212b7a9448
commit
75a21435ca
1 changed files with 16 additions and 9 deletions
|
|
@ -995,23 +995,30 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
|
||||||
obj.Width = float64(maxWidth + 100)
|
obj.Width = float64(maxWidth + 100)
|
||||||
|
|
||||||
case d2target.ShapeSQLTable:
|
case d2target.ShapeSQLTable:
|
||||||
maxWidth := dims.Width
|
maxNameWidth := 0.
|
||||||
|
maxTypeWidth := 0.
|
||||||
|
constraintWidth := 0.
|
||||||
|
|
||||||
|
font := d2fonts.SourceSansPro.Font(d2fonts.FONT_SIZE_L, d2fonts.FONT_STYLE_REGULAR)
|
||||||
for _, c := range obj.SQLTable.Columns {
|
for _, c := range obj.SQLTable.Columns {
|
||||||
cdims := getTextDimensions(mtexts, ruler, c.Text())
|
nameWidth, _ := ruler.MeasurePrecise(font, c.Name)
|
||||||
if cdims == nil {
|
if maxNameWidth < nameWidth {
|
||||||
return fmt.Errorf("dimensions for column %#v not found", c.Text())
|
maxNameWidth = nameWidth
|
||||||
}
|
}
|
||||||
lineWidth := cdims.Width
|
typeWidth, _ := ruler.MeasurePrecise(font, c.Type)
|
||||||
if maxWidth < lineWidth {
|
if maxTypeWidth < typeWidth {
|
||||||
maxWidth = lineWidth
|
maxTypeWidth = typeWidth
|
||||||
|
}
|
||||||
|
if c.Constraint != "" {
|
||||||
|
// covers UNQ constraint with padding
|
||||||
|
constraintWidth = 70.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The rows get padded a little due to header font being larger than row font
|
// The rows get padded a little due to header font being larger than row font
|
||||||
obj.Height = float64(dims.Height * (len(obj.SQLTable.Columns) + 1))
|
obj.Height = float64(dims.Height * (len(obj.SQLTable.Columns) + 1))
|
||||||
// Leave room for padding
|
// Leave room for padding (20 on each side)
|
||||||
obj.Width = float64(maxWidth + 100)
|
obj.Width = float64(maxNameWidth + maxTypeWidth + constraintWidth + 40)
|
||||||
|
|
||||||
case d2target.ShapeText, d2target.ShapeCode:
|
case d2target.ShapeText, d2target.ShapeCode:
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue