Merge pull request #511 from alixander/fix-sql-using-ruler
fix sql table measurements
This commit is contained in:
commit
17f4e05cce
3 changed files with 56 additions and 48 deletions
|
|
@ -1002,23 +1002,29 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
|
||||||
maxTypeWidth := 0
|
maxTypeWidth := 0
|
||||||
constraintWidth := 0
|
constraintWidth := 0
|
||||||
|
|
||||||
font := d2fonts.SourceSansPro.Font(d2fonts.FONT_SIZE_L, d2fonts.FONT_STYLE_REGULAR)
|
|
||||||
for i := range obj.SQLTable.Columns {
|
for i := range obj.SQLTable.Columns {
|
||||||
// Note: we want to set dimensions of actual column not the for loop copy of the struct
|
// Note: we want to set dimensions of actual column not the for loop copy of the struct
|
||||||
c := &obj.SQLTable.Columns[i]
|
c := &obj.SQLTable.Columns[i]
|
||||||
|
ctexts := c.Texts()
|
||||||
|
|
||||||
nameWidth, nameHeight := ruler.Measure(font, c.Name.Label)
|
nameDims := getTextDimensions(mtexts, ruler, ctexts[0], fontFamily)
|
||||||
c.Name.LabelWidth = nameWidth
|
if nameDims == nil {
|
||||||
c.Name.LabelHeight = nameHeight
|
return fmt.Errorf("dimensions for sql_table name %#v not found", ctexts[0].Text)
|
||||||
if maxNameWidth < nameWidth {
|
}
|
||||||
maxNameWidth = nameWidth
|
c.Name.LabelWidth = nameDims.Width
|
||||||
|
c.Name.LabelHeight = nameDims.Height
|
||||||
|
if maxNameWidth < nameDims.Width {
|
||||||
|
maxNameWidth = nameDims.Width
|
||||||
}
|
}
|
||||||
|
|
||||||
typeWidth, typeHeight := ruler.Measure(font, c.Type.Label)
|
typeDims := getTextDimensions(mtexts, ruler, ctexts[1], fontFamily)
|
||||||
c.Type.LabelWidth = typeWidth
|
if typeDims == nil {
|
||||||
c.Type.LabelHeight = typeHeight
|
return fmt.Errorf("dimensions for sql_table type %#v not found", ctexts[1].Text)
|
||||||
if maxTypeWidth < typeWidth {
|
}
|
||||||
maxTypeWidth = typeWidth
|
c.Type.LabelWidth = typeDims.Width
|
||||||
|
c.Type.LabelHeight = typeDims.Height
|
||||||
|
if maxTypeWidth < typeDims.Width {
|
||||||
|
maxTypeWidth = typeDims.Width
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Constraint != "" {
|
if c.Constraint != "" {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
|
|
@ -1,5 +1,7 @@
|
||||||
package d2target
|
package d2target
|
||||||
|
|
||||||
|
import "oss.terrastruct.com/d2/d2renderers/d2fonts"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NamePadding = 10
|
NamePadding = 10
|
||||||
TypePadding = 20
|
TypePadding = 20
|
||||||
|
|
@ -20,14 +22,14 @@ func (c SQLColumn) Texts() []*MText {
|
||||||
return []*MText{
|
return []*MText{
|
||||||
{
|
{
|
||||||
Text: c.Name.Label,
|
Text: c.Name.Label,
|
||||||
FontSize: c.Name.FontSize,
|
FontSize: d2fonts.FONT_SIZE_L,
|
||||||
IsBold: false,
|
IsBold: false,
|
||||||
IsItalic: false,
|
IsItalic: false,
|
||||||
Shape: "sql_table",
|
Shape: "sql_table",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Text: c.Type.Label,
|
Text: c.Type.Label,
|
||||||
FontSize: c.Type.FontSize,
|
FontSize: d2fonts.FONT_SIZE_L,
|
||||||
IsBold: false,
|
IsBold: false,
|
||||||
IsItalic: false,
|
IsItalic: false,
|
||||||
Shape: "sql_table",
|
Shape: "sql_table",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue