also limit person AR with width/height attributes unless both are entered
This commit is contained in:
parent
92629a6c3b
commit
57fa903fe6
8 changed files with 457 additions and 21 deletions
|
|
@ -1187,6 +1187,10 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
|
|||
sideLength := math.Max(obj.Width, obj.Height)
|
||||
obj.Width = sideLength
|
||||
obj.Height = sideLength
|
||||
} else if desiredHeight == 0 || desiredWidth == 0 {
|
||||
if s.GetType() == shape.PERSON_TYPE {
|
||||
obj.Width, obj.Height = shape.LimitAR(obj.Width, obj.Height, shape.PERSON_AR_LIMIT)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, edge := range g.Edges {
|
||||
|
|
|
|||
|
|
@ -1895,6 +1895,21 @@ d: --------
|
|||
e: ----------------
|
||||
f: --------------------------------
|
||||
g: ----------------------------------------------------------------
|
||||
|
||||
1.shape: person
|
||||
2.shape: person
|
||||
3.shape: person
|
||||
4.shape: person
|
||||
5.shape: person
|
||||
|
||||
1.width: 16
|
||||
2.width: 64
|
||||
3.width: 128
|
||||
4.width: 512
|
||||
|
||||
# entering both width and height overrides aspect ratio limit
|
||||
5.height: 256
|
||||
5.width: 32
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
223
e2etests/testdata/stable/people/dagre/board.exp.json
generated
vendored
223
e2etests/testdata/stable/people/dagre/board.exp.json
generated
vendored
|
|
@ -6,7 +6,7 @@
|
|||
"id": "a",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 0,
|
||||
"x": 1054,
|
||||
"y": 257
|
||||
},
|
||||
"width": 49,
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
"id": "b",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 109,
|
||||
"x": 1163,
|
||||
"y": 257
|
||||
},
|
||||
"width": 64,
|
||||
|
|
@ -88,7 +88,7 @@
|
|||
"id": "c",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 233,
|
||||
"x": 1287,
|
||||
"y": 257
|
||||
},
|
||||
"width": 89,
|
||||
|
|
@ -129,7 +129,7 @@
|
|||
"id": "d",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 382,
|
||||
"x": 1436,
|
||||
"y": 243
|
||||
},
|
||||
"width": 142,
|
||||
|
|
@ -170,11 +170,11 @@
|
|||
"id": "e",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 584,
|
||||
"y": 208
|
||||
"x": 1638,
|
||||
"y": 209
|
||||
},
|
||||
"width": 245,
|
||||
"height": 164,
|
||||
"height": 163,
|
||||
"opacity": 1,
|
||||
"strokeDash": 0,
|
||||
"strokeWidth": 2,
|
||||
|
|
@ -211,7 +211,7 @@
|
|||
"id": "f",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 889,
|
||||
"x": 1943,
|
||||
"y": 139
|
||||
},
|
||||
"width": 453,
|
||||
|
|
@ -252,7 +252,7 @@
|
|||
"id": "g",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 1402,
|
||||
"x": 2456,
|
||||
"y": 0
|
||||
},
|
||||
"width": 870,
|
||||
|
|
@ -288,6 +288,211 @@
|
|||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
},
|
||||
{
|
||||
"id": "1",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 0,
|
||||
"y": 280
|
||||
},
|
||||
"width": 18,
|
||||
"height": 21,
|
||||
"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": "1",
|
||||
"fontSize": 16,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "#0A0F25",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 12,
|
||||
"labelHeight": 26,
|
||||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 78,
|
||||
"y": 269
|
||||
},
|
||||
"width": 64,
|
||||
"height": 43,
|
||||
"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": "2",
|
||||
"fontSize": 16,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "#0A0F25",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 13,
|
||||
"labelHeight": 26,
|
||||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 202,
|
||||
"y": 248
|
||||
},
|
||||
"width": 128,
|
||||
"height": 85,
|
||||
"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": "3",
|
||||
"fontSize": 16,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "#0A0F25",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 13,
|
||||
"labelHeight": 26,
|
||||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
},
|
||||
{
|
||||
"id": "4",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 390,
|
||||
"y": 120
|
||||
},
|
||||
"width": 512,
|
||||
"height": 341,
|
||||
"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": "4",
|
||||
"fontSize": 16,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "#0A0F25",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 14,
|
||||
"labelHeight": 26,
|
||||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
},
|
||||
{
|
||||
"id": "5",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 962,
|
||||
"y": 162
|
||||
},
|
||||
"width": 32,
|
||||
"height": 256,
|
||||
"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": "5",
|
||||
"fontSize": 16,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "#0A0F25",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 13,
|
||||
"labelHeight": 26,
|
||||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
}
|
||||
],
|
||||
"connections": []
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 327 KiB After Width: | Height: | Size: 329 KiB |
207
e2etests/testdata/stable/people/elk/board.exp.json
generated
vendored
207
e2etests/testdata/stable/people/elk/board.exp.json
generated
vendored
|
|
@ -174,7 +174,7 @@
|
|||
"y": 220
|
||||
},
|
||||
"width": 245,
|
||||
"height": 164,
|
||||
"height": 163,
|
||||
"opacity": 1,
|
||||
"strokeDash": 0,
|
||||
"strokeWidth": 2,
|
||||
|
|
@ -288,6 +288,211 @@
|
|||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
},
|
||||
{
|
||||
"id": "1",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 2064,
|
||||
"y": 291
|
||||
},
|
||||
"width": 18,
|
||||
"height": 21,
|
||||
"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": "1",
|
||||
"fontSize": 16,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "#0A0F25",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 12,
|
||||
"labelHeight": 26,
|
||||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 2102,
|
||||
"y": 280
|
||||
},
|
||||
"width": 64,
|
||||
"height": 43,
|
||||
"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": "2",
|
||||
"fontSize": 16,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "#0A0F25",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 13,
|
||||
"labelHeight": 26,
|
||||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 2186,
|
||||
"y": 259
|
||||
},
|
||||
"width": 128,
|
||||
"height": 85,
|
||||
"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": "3",
|
||||
"fontSize": 16,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "#0A0F25",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 13,
|
||||
"labelHeight": 26,
|
||||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
},
|
||||
{
|
||||
"id": "4",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 2334,
|
||||
"y": 131
|
||||
},
|
||||
"width": 512,
|
||||
"height": 341,
|
||||
"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": "4",
|
||||
"fontSize": 16,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "#0A0F25",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 14,
|
||||
"labelHeight": 26,
|
||||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
},
|
||||
{
|
||||
"id": "5",
|
||||
"type": "person",
|
||||
"pos": {
|
||||
"x": 2866,
|
||||
"y": 174
|
||||
},
|
||||
"width": 32,
|
||||
"height": 256,
|
||||
"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": "5",
|
||||
"fontSize": 16,
|
||||
"fontFamily": "DEFAULT",
|
||||
"language": "",
|
||||
"color": "#0A0F25",
|
||||
"italic": false,
|
||||
"bold": true,
|
||||
"underline": false,
|
||||
"labelWidth": 13,
|
||||
"labelHeight": 26,
|
||||
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||
"zIndex": 0,
|
||||
"level": 1
|
||||
}
|
||||
],
|
||||
"connections": []
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 327 KiB After Width: | Height: | Size: 329 KiB |
|
|
@ -225,3 +225,12 @@ func boxPath(box *geo.Box) *svg.SvgPathContext {
|
|||
pc.Z()
|
||||
return pc
|
||||
}
|
||||
|
||||
func LimitAR(width, height, aspectRatio float64) (float64, float64) {
|
||||
if width > aspectRatio*height {
|
||||
height = math.Round(width / aspectRatio)
|
||||
} else if height > aspectRatio*width {
|
||||
width = math.Round(height / aspectRatio)
|
||||
}
|
||||
return width, height
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ func NewPerson(box *geo.Box) Shape {
|
|||
}
|
||||
|
||||
const (
|
||||
PERSON_AR_LIMIT = 1.5
|
||||
|
||||
personShoulderWidthFactor = 20.2 / 68.3
|
||||
)
|
||||
|
||||
|
|
@ -76,11 +78,7 @@ func (s shapePerson) GetDimensionsToFit(width, height, paddingX, paddingY float6
|
|||
totalHeight := height + paddingY
|
||||
|
||||
// prevent the shape's aspect ratio from becoming too extreme
|
||||
if totalWidth > 1.5*totalHeight {
|
||||
totalHeight = totalWidth / 1.5
|
||||
} else if totalHeight > 1.5*totalWidth {
|
||||
totalWidth = totalHeight / 1.5
|
||||
}
|
||||
totalWidth, totalHeight = LimitAR(totalWidth, totalHeight, PERSON_AR_LIMIT)
|
||||
return math.Ceil(totalWidth), math.Ceil(totalHeight)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue