fix sql table font-size
This commit is contained in:
parent
0da4e150cd
commit
301e692a24
7 changed files with 578 additions and 9 deletions
|
|
@ -477,7 +477,7 @@ func (obj *Object) Text() *d2target.MText {
|
|||
}
|
||||
// Class and Table objects have Label set to header
|
||||
if obj.Class != nil || obj.SQLTable != nil {
|
||||
fontSize = d2fonts.FONT_SIZE_XL
|
||||
fontSize += d2target.HeaderFontAdd
|
||||
}
|
||||
if obj.Class != nil {
|
||||
isBold = false
|
||||
|
|
@ -836,10 +836,16 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R
|
|||
maxTypeWidth := 0
|
||||
constraintWidth := 0
|
||||
|
||||
colFontSize := d2fonts.FONT_SIZE_L
|
||||
if obj.Attributes.Style.FontSize != nil {
|
||||
colFontSize, _ = strconv.Atoi(obj.Attributes.Style.FontSize.Value)
|
||||
}
|
||||
|
||||
for i := range obj.SQLTable.Columns {
|
||||
// Note: we want to set dimensions of actual column not the for loop copy of the struct
|
||||
c := &obj.SQLTable.Columns[i]
|
||||
ctexts := c.Texts()
|
||||
|
||||
ctexts := c.Texts(colFontSize)
|
||||
|
||||
nameDims := GetTextDimensions(mtexts, ruler, ctexts[0], fontFamily)
|
||||
if nameDims == nil {
|
||||
|
|
@ -1334,8 +1340,12 @@ func (g *Graph) Texts() []*d2target.MText {
|
|||
texts = appendTextDedup(texts, method.Text())
|
||||
}
|
||||
} else if obj.SQLTable != nil {
|
||||
colFontSize := d2fonts.FONT_SIZE_L
|
||||
if obj.Attributes.Style.FontSize != nil {
|
||||
colFontSize, _ = strconv.Atoi(obj.Attributes.Style.FontSize.Value)
|
||||
}
|
||||
for _, column := range obj.SQLTable.Columns {
|
||||
for _, t := range column.Texts() {
|
||||
for _, t := range column.Texts(colFontSize) {
|
||||
texts = appendTextDedup(texts, t)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package d2target
|
||||
|
||||
import "oss.terrastruct.com/d2/d2renderers/d2fonts"
|
||||
|
||||
const (
|
||||
NamePadding = 10
|
||||
TypePadding = 20
|
||||
HeaderPadding = 20
|
||||
HeaderPadding = 10
|
||||
|
||||
// Setting table font size sets it for columns
|
||||
// The header needs to be a little larger for visual hierarchy
|
||||
HeaderFontAdd = 4
|
||||
)
|
||||
|
||||
type SQLTable struct {
|
||||
|
|
@ -19,18 +21,18 @@ type SQLColumn struct {
|
|||
Reference string `json:"reference"`
|
||||
}
|
||||
|
||||
func (c SQLColumn) Texts() []*MText {
|
||||
func (c SQLColumn) Texts(fontSize int) []*MText {
|
||||
return []*MText{
|
||||
{
|
||||
Text: c.Name.Label,
|
||||
FontSize: d2fonts.FONT_SIZE_L,
|
||||
FontSize: fontSize,
|
||||
IsBold: false,
|
||||
IsItalic: false,
|
||||
Shape: "sql_table",
|
||||
},
|
||||
{
|
||||
Text: c.Type.Label,
|
||||
FontSize: d2fonts.FONT_SIZE_L,
|
||||
FontSize: fontSize,
|
||||
IsBold: false,
|
||||
IsItalic: false,
|
||||
Shape: "sql_table",
|
||||
|
|
|
|||
|
|
@ -1838,6 +1838,29 @@ x.y -> a.b: {
|
|||
style.animated: true
|
||||
target-arrowhead.shape: cf-many
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "sql_table_column_styles",
|
||||
script: `Humor in the Court: {
|
||||
shape: sql_table
|
||||
Could you see him from where you were standing?: "I could see his head."
|
||||
And where was his head?: Just above his shoulders.
|
||||
style.fill: red
|
||||
style.stroke: lightgray
|
||||
style.font-color: orange
|
||||
style.font-size: 20
|
||||
}
|
||||
|
||||
Humor in the Court2: {
|
||||
shape: sql_table
|
||||
Could you see him from where you were standing?: "I could see his head."
|
||||
And where was his head?: Just above his shoulders.
|
||||
style.fill: red
|
||||
style.stroke: lightgray
|
||||
style.font-color: orange
|
||||
style.font-size: 30
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
|
|
|
|||
207
e2etests/testdata/stable/sql_table_column_styles/dagre/board.exp.json
generated
vendored
Normal file
207
e2etests/testdata/stable/sql_table_column_styles/dagre/board.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
{
|
||||
"name": "",
|
||||
"fontFamily": "SourceSansPro",
|
||||
"shapes": [
|
||||
{
|
||||
"id": "Humor in the Court",
|
||||
"type": "sql_table",
|
||||
"pos": {
|
||||
"x": 0,
|
||||
"y": 18
|
||||
},
|
||||
"width": 678,
|
||||
"height": 108,
|
||||
"opacity": 1,
|
||||
"strokeDash": 0,
|
||||
"strokeWidth": 2,
|
||||
"borderRadius": 0,
|
||||
"fill": "red",
|
||||
"stroke": "lightgray",
|
||||
"shadow": false,
|
||||
"3d": false,
|
||||
"multiple": false,
|
||||
"double-border": false,
|
||||
"tooltip": "",
|
||||
"link": "",
|
||||
"icon": null,
|
||||
"iconPosition": "",
|
||||
"blend": false,
|
||||
"fields": null,
|
||||
"methods": null,
|
||||
"columns": [
|
||||
{
|
||||
"name": {
|
||||
"label": "Could you see him from where you were standing?",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 418,
|
||||
"labelHeight": 26
|
||||
},
|
||||
"type": {
|
||||
"label": "I could see his head.",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 166,
|
||||
"labelHeight": 26
|
||||
},
|
||||
"constraint": "",
|
||||
"reference": ""
|
||||
},
|
||||
{
|
||||
"name": {
|
||||
"label": "And where was his head?",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 208,
|
||||
"labelHeight": 26
|
||||
},
|
||||
"type": {
|
||||
"label": "Just above his shoulders.",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 210,
|
||||
"labelHeight": 26
|
||||
},
|
||||
"constraint": "",
|
||||
"reference": ""
|
||||
}
|
||||
],
|
||||
"label": "Humor in the Court",
|
||||
"fontSize": 20,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "orange",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 202,
|
||||
"labelHeight": 31,
|
||||
"zIndex": 0,
|
||||
"level": 1,
|
||||
"primaryAccentColor": "#0D32B2",
|
||||
"secondaryAccentColor": "#4A6FF3",
|
||||
"neutralAccentColor": "#676C7E"
|
||||
},
|
||||
{
|
||||
"id": "Humor in the Court2",
|
||||
"type": "sql_table",
|
||||
"pos": {
|
||||
"x": 738,
|
||||
"y": 0
|
||||
},
|
||||
"width": 992,
|
||||
"height": 144,
|
||||
"opacity": 1,
|
||||
"strokeDash": 0,
|
||||
"strokeWidth": 2,
|
||||
"borderRadius": 0,
|
||||
"fill": "red",
|
||||
"stroke": "lightgray",
|
||||
"shadow": false,
|
||||
"3d": false,
|
||||
"multiple": false,
|
||||
"double-border": false,
|
||||
"tooltip": "",
|
||||
"link": "",
|
||||
"icon": null,
|
||||
"iconPosition": "",
|
||||
"blend": false,
|
||||
"fields": null,
|
||||
"methods": null,
|
||||
"columns": [
|
||||
{
|
||||
"name": {
|
||||
"label": "Could you see him from where you were standing?",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 627,
|
||||
"labelHeight": 38
|
||||
},
|
||||
"type": {
|
||||
"label": "I could see his head.",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 248,
|
||||
"labelHeight": 38
|
||||
},
|
||||
"constraint": "",
|
||||
"reference": ""
|
||||
},
|
||||
{
|
||||
"name": {
|
||||
"label": "And where was his head?",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 312,
|
||||
"labelHeight": 38
|
||||
},
|
||||
"type": {
|
||||
"label": "Just above his shoulders.",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 315,
|
||||
"labelHeight": 38
|
||||
},
|
||||
"constraint": "",
|
||||
"reference": ""
|
||||
}
|
||||
],
|
||||
"label": "Humor in the Court2",
|
||||
"fontSize": 30,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "orange",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 303,
|
||||
"labelHeight": 43,
|
||||
"zIndex": 0,
|
||||
"level": 1,
|
||||
"primaryAccentColor": "#0D32B2",
|
||||
"secondaryAccentColor": "#4A6FF3",
|
||||
"neutralAccentColor": "#676C7E"
|
||||
}
|
||||
],
|
||||
"connections": []
|
||||
}
|
||||
60
e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg
vendored
Normal file
60
e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 328 KiB |
207
e2etests/testdata/stable/sql_table_column_styles/elk/board.exp.json
generated
vendored
Normal file
207
e2etests/testdata/stable/sql_table_column_styles/elk/board.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
{
|
||||
"name": "",
|
||||
"fontFamily": "SourceSansPro",
|
||||
"shapes": [
|
||||
{
|
||||
"id": "Humor in the Court",
|
||||
"type": "sql_table",
|
||||
"pos": {
|
||||
"x": 12,
|
||||
"y": 30
|
||||
},
|
||||
"width": 678,
|
||||
"height": 108,
|
||||
"opacity": 1,
|
||||
"strokeDash": 0,
|
||||
"strokeWidth": 2,
|
||||
"borderRadius": 0,
|
||||
"fill": "red",
|
||||
"stroke": "lightgray",
|
||||
"shadow": false,
|
||||
"3d": false,
|
||||
"multiple": false,
|
||||
"double-border": false,
|
||||
"tooltip": "",
|
||||
"link": "",
|
||||
"icon": null,
|
||||
"iconPosition": "",
|
||||
"blend": false,
|
||||
"fields": null,
|
||||
"methods": null,
|
||||
"columns": [
|
||||
{
|
||||
"name": {
|
||||
"label": "Could you see him from where you were standing?",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 418,
|
||||
"labelHeight": 26
|
||||
},
|
||||
"type": {
|
||||
"label": "I could see his head.",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 166,
|
||||
"labelHeight": 26
|
||||
},
|
||||
"constraint": "",
|
||||
"reference": ""
|
||||
},
|
||||
{
|
||||
"name": {
|
||||
"label": "And where was his head?",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 208,
|
||||
"labelHeight": 26
|
||||
},
|
||||
"type": {
|
||||
"label": "Just above his shoulders.",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 210,
|
||||
"labelHeight": 26
|
||||
},
|
||||
"constraint": "",
|
||||
"reference": ""
|
||||
}
|
||||
],
|
||||
"label": "Humor in the Court",
|
||||
"fontSize": 20,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "orange",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 202,
|
||||
"labelHeight": 31,
|
||||
"zIndex": 0,
|
||||
"level": 1,
|
||||
"primaryAccentColor": "#0D32B2",
|
||||
"secondaryAccentColor": "#4A6FF3",
|
||||
"neutralAccentColor": "#676C7E"
|
||||
},
|
||||
{
|
||||
"id": "Humor in the Court2",
|
||||
"type": "sql_table",
|
||||
"pos": {
|
||||
"x": 710,
|
||||
"y": 12
|
||||
},
|
||||
"width": 992,
|
||||
"height": 144,
|
||||
"opacity": 1,
|
||||
"strokeDash": 0,
|
||||
"strokeWidth": 2,
|
||||
"borderRadius": 0,
|
||||
"fill": "red",
|
||||
"stroke": "lightgray",
|
||||
"shadow": false,
|
||||
"3d": false,
|
||||
"multiple": false,
|
||||
"double-border": false,
|
||||
"tooltip": "",
|
||||
"link": "",
|
||||
"icon": null,
|
||||
"iconPosition": "",
|
||||
"blend": false,
|
||||
"fields": null,
|
||||
"methods": null,
|
||||
"columns": [
|
||||
{
|
||||
"name": {
|
||||
"label": "Could you see him from where you were standing?",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 627,
|
||||
"labelHeight": 38
|
||||
},
|
||||
"type": {
|
||||
"label": "I could see his head.",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 248,
|
||||
"labelHeight": 38
|
||||
},
|
||||
"constraint": "",
|
||||
"reference": ""
|
||||
},
|
||||
{
|
||||
"name": {
|
||||
"label": "And where was his head?",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 312,
|
||||
"labelHeight": 38
|
||||
},
|
||||
"type": {
|
||||
"label": "Just above his shoulders.",
|
||||
"fontSize": 0,
|
||||
"fontFamily": "",
|
||||
"language": "",
|
||||
"color": "",
|
||||
"italic": false,
|
||||
"bold": false,
|
||||
"underline": false,
|
||||
"labelWidth": 315,
|
||||
"labelHeight": 38
|
||||
},
|
||||
"constraint": "",
|
||||
"reference": ""
|
||||
}
|
||||
],
|
||||
"label": "Humor in the Court2",
|
||||
"fontSize": 30,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "orange",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 303,
|
||||
"labelHeight": 43,
|
||||
"zIndex": 0,
|
||||
"level": 1,
|
||||
"primaryAccentColor": "#0D32B2",
|
||||
"secondaryAccentColor": "#4A6FF3",
|
||||
"neutralAccentColor": "#676C7E"
|
||||
}
|
||||
],
|
||||
"connections": []
|
||||
}
|
||||
60
e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg
vendored
Normal file
60
e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 328 KiB |
Loading…
Reference in a new issue