Skip to content

Commit

Permalink
fix: Remove overflowing background when text parent is a line (#38)
Browse files Browse the repository at this point in the history
* fix: Set overflow to 'both' when text parent is a line

* chore: Update test fixture
  • Loading branch information
sindrel authored Feb 14, 2024
1 parent f017c49 commit 9cef259
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 49 deletions.
33 changes: 21 additions & 12 deletions internal/conversion/gliffy.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ func AddElements(addChildren bool, input datastr.ExcalidrawScene, scene datastr.
continue
}

var hasParent bool = false
var parent int = 999999
if len(element.ContainerId) > 0 {
for obj_k, obj := range objects {
if obj.ID == objectIDs[element.ContainerId] {
parent = obj_k
}
}

if parent == 999999 {
return nil, scene, nil, errors.New("unable to find object parent")
}

hasParent = true
}

var object datastr.GliffyObject
var shape datastr.GliffyShape
var text datastr.GliffyText
Expand Down Expand Up @@ -253,6 +269,10 @@ func AddElements(addChildren bool, input datastr.ExcalidrawScene, scene datastr.
text.Vposition = "none"
text.Hposition = "none"

if hasParent && objects[parent].Graphic.Line != nil {
text.Overflow = "both"
}

object.Graphic.Text = &text
}
}
Expand Down Expand Up @@ -306,18 +326,7 @@ func AddElements(addChildren bool, input datastr.ExcalidrawScene, scene datastr.

fmt.Printf(" Adding object: %s (%s,%d,%d)\n", object.UID, element.ID, object.ID, object.Order)

if len(element.ContainerId) > 0 {
var parent int = 999999
for obj_k, obj := range objects {
if obj.ID == objectIDs[element.ContainerId] {
parent = obj_k
}
}

if parent == 999999 {
return nil, scene, nil, errors.New("unable to find object parent")
}

if hasParent {
object.X = 2
object.Y = 0
object.Rotation = 0
Expand Down
151 changes: 115 additions & 36 deletions test/data/test_input.excalidraw
Original file line number Diff line number Diff line change
Expand Up @@ -3075,28 +3075,28 @@
"pressures": []
},
{
"id": "7kzobgIeRwxMvnCGFNJR1",
"type": "freedraw",
"x": 618.8225763349608,
"y": 1080.5,
"width": 4,
"height": 186,
"angle": 0,
"strokeColor": "#1e1e1e",
"backgroundColor": "transparent",
"version": 36,
"versionNonce": 1095203009,
"isDeleted": false,
"id": "7kzobgIeRwxMvnCGFNJR1",
"fillStyle": "solid",
"strokeWidth": 4,
"strokeStyle": "solid",
"roughness": 0,
"opacity": 100,
"angle": 0,
"x": 618.8225763349608,
"y": 1080.5,
"strokeColor": "#1e1e1e",
"backgroundColor": "transparent",
"width": 4,
"height": 186,
"seed": 389253487,
"groupIds": [],
"frameId": null,
"roundness": null,
"seed": 389253487,
"version": 36,
"versionNonce": 1095203009,
"isDeleted": false,
"boundElements": null,
"boundElements": [],
"updated": 1700924304587,
"link": null,
"locked": false,
Expand Down Expand Up @@ -3242,36 +3242,33 @@
186
]
],
"pressures": [],
"lastCommittedPoint": null,
"simulatePressure": true,
"lastCommittedPoint": [
-1,
186
]
"pressures": []
},
{
"id": "MCte_QtWHKVQuqiS0iiRS",
"type": "freedraw",
"x": 551.8225763349608,
"y": 1269.5,
"width": 132,
"height": 4,
"angle": 0,
"strokeColor": "#1e1e1e",
"backgroundColor": "transparent",
"version": 21,
"versionNonce": 990510625,
"isDeleted": false,
"id": "MCte_QtWHKVQuqiS0iiRS",
"fillStyle": "solid",
"strokeWidth": 4,
"strokeStyle": "solid",
"roughness": 0,
"opacity": 100,
"angle": 0,
"x": 551.8225763349608,
"y": 1269.5,
"strokeColor": "#1e1e1e",
"backgroundColor": "transparent",
"width": 132,
"height": 4,
"seed": 1266769391,
"groupIds": [],
"frameId": null,
"roundness": null,
"seed": 1266769391,
"version": 21,
"versionNonce": 990510625,
"isDeleted": false,
"boundElements": null,
"boundElements": [],
"updated": 1700924306275,
"link": null,
"locked": false,
Expand Down Expand Up @@ -3357,12 +3354,94 @@
-4
]
],
"pressures": [],
"lastCommittedPoint": null,
"simulatePressure": true,
"lastCommittedPoint": [
132,
-4
]
"pressures": []
},
{
"id": "1ygCn6fQ7jY1QWrmS8deF",
"type": "arrow",
"x": 1472.7540955,
"y": 738.25,
"width": 138,
"height": 217,
"angle": 0,
"strokeColor": "#1e1e1e",
"backgroundColor": "transparent",
"fillStyle": "solid",
"strokeWidth": 2,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"roundness": {
"type": 2
},
"seed": 1082467352,
"version": 144,
"versionNonce": 355526680,
"isDeleted": false,
"boundElements": [
{
"type": "text",
"id": "dizyaS2XKg5AJ8_6z_zQB"
}
],
"updated": 1707931011007,
"link": null,
"locked": false,
"points": [
[
0,
0
],
[
138,
217
]
],
"lastCommittedPoint": null,
"startBinding": null,
"endBinding": null,
"startArrowhead": null,
"endArrowhead": null
},
{
"id": "dizyaS2XKg5AJ8_6z_zQB",
"type": "text",
"x": 1465.7457642011718,
"y": 960.25,
"width": 170.01666259765625,
"height": 23,
"angle": 0,
"strokeColor": "#1e1e1e",
"backgroundColor": "transparent",
"fillStyle": "solid",
"strokeWidth": 2,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"roundness": null,
"seed": 612416280,
"version": 55,
"versionNonce": 1090058088,
"isDeleted": false,
"boundElements": null,
"updated": 1707930976305,
"link": null,
"locked": false,
"text": "this text is on a line",
"fontSize": 20,
"fontFamily": 2,
"textAlign": "center",
"verticalAlign": "middle",
"baseline": 17,
"containerId": "1ygCn6fQ7jY1QWrmS8deF",
"originalText": "this text is on a line",
"lineHeight": 1.15
}
],
"appState": {
Expand Down
84 changes: 83 additions & 1 deletion test/data/test_output.gliffy
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"autosaveDisabled": false,
"editorVersion": null,
"exportBorder": false,
"lastSerialized": 1700924363482,
"lastSerialized": 1707931162256,
"libraries": [
"com.gliffy.libraries.basic.basic_v1.default",
"com.gliffy.libraries.flowchart.flowchart_v1.default"
Expand Down Expand Up @@ -1228,6 +1228,88 @@
"width": 132,
"x": 63.04257633496081,
"y": 1113.5
},
{
"children": [
{
"children": null,
"graphic": {
"Text": {
"calculatedHeight": 0,
"calculatedWidth": 0,
"hposition": "none",
"html": "<p style=\"text-align: center;\"><span style=\"font-family: Arial; font-size: 20px;\"><span style=\"\"><span style=\"color: #1e1e1e; font-size: 20px; line-height: 16.5px;\">this text is on a line</span><br></span></span></p>",
"outerPaddingBottom": 0,
"outerPaddingLeft": 0,
"outerPaddingRight": 0,
"outerPaddingTop": 0,
"overflow": "both",
"paddingBottom": 0,
"paddingLeft": 0,
"paddingRight": 0,
"paddingTop": 0,
"tid": null,
"valign": "middle",
"vposition": "none"
},
"type": "Text"
},
"height": 213,
"hidden": false,
"id": 35,
"layerId": "dR5PnMr9lIuu",
"linkMap": null,
"lockAspectRatio": false,
"lockShape": false,
"order": 35,
"rotation": 0,
"uid": "",
"width": 134,
"x": 2,
"y": 0
}
],
"graphic": {
"Line": {
"controlPath": [
[
0,
0
],
[
138,
217
]
],
"cornerRadius": 10,
"dashStyle": "",
"endArrow": 0,
"endArrowRotation": "auto",
"fillColor": "none",
"hopType": null,
"interpolationType": "linear",
"lockSegments": {},
"ortho": true,
"startArrow": 0,
"startArrowRotation": "auto",
"strokeColor": "#1e1e1e",
"strokeWidth": 2
},
"type": "Line"
},
"height": 217,
"hidden": false,
"id": 34,
"layerId": "dR5PnMr9lIuu",
"linkMap": null,
"lockAspectRatio": false,
"lockShape": false,
"order": 34,
"rotation": 0,
"uid": "com.gliffy.shape.basic.basic_v1.default.line",
"width": 138,
"x": 983.9740955,
"y": 586.25
}
],
"printModel": {
Expand Down

0 comments on commit 9cef259

Please sign in to comment.