Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC] architecture doc about label bounds with mxgraph #325

Merged
53 changes: 53 additions & 0 deletions docs/architecture/mxgraph-integration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,56 @@ waypoints of BPMNEdge are always relative to that plane’s origin point and are
[quote]
The bounds of BPMNLabel are always relative to the containing plane’s origin point. Note that the bounds’ x and y
coordinates are the position of the upper left corner of the label (relative to the upper left corner of the plane).


==== Label Font and Bounds

The `mxGraph` integration renders labels based on the definition taken from the BPMN source. When the label style is not
or only partially defined in BPMN, the following fallback takes place:

* for labels without a font, the rendering may not be accurate: the default font used by the original modeler may differ
from the one the lib uses. As a result, the bounds set in the BPMN file may be too small or large for the lib font. So the
resulting text wrapping cannot be the same as with the original modeler.
* for labels without bounds, the lib uses an arbitrary position which depends on the type of the BPMN element (for instance, middle
centred for tasks or on the bottom for start events). As for fonts, this does not cover all use cases, but works most of
the time.

===== Shape

The `mxGraph` integration uses the following to set the label bounds

* the `vertex mxCell` geometry offset, see https://github.com/jgraph/mxgraph2/blob/mxgraph-4_1_1/javascript/src/js/model/mxGeometry.js#L60[mxGeometry]
for more details
** x and y position relative to the shape `vertex` itself
** as for the shape `vertex` position, a coordinate transformation layer is required.
* styling for the label width (for word wrapping)

===== Edge

====== Overview

The mxGraph integration uses the `edge mxCell` geometry to set the label bounds

* absolute geometry
* offset x and y: position related to the center of the edge and as for the Shape Position, a coordinate transformation layer is required.
** the center depends on the 2 terminal waypoints
** if the waypoints are not available, no position is set and the label is placed on the edge center
* width and height: for word wrapping.

see https://github.com/jgraph/mxgraph2/blob/mxgraph-4_1_1/javascript/src/js/model/mxGeometry.js#L60[mxGeometry]

====== mxGraph Details

The label position is related to the 'center' of the edge, see https://github.com/jgraph/mxgraph2/blob/mxgraph-4_1_1/javascript/src/js/model/mxGeometry.js#L35[mxGeometry]
for more details. The definition of 'center' differs whether the `mxGeometry` is `relative` or not:

* if relative, it is the center along the line
* if absolute, it is derived from the terminal points

This is explained in https://github.com/jgraph/mxgraph2/blob/mxgraph-4_1_1/javascript/src/js/view/mxGraphView.js#L2187[mxGraphView.updateEdgeLabelOffset]

* center between the two endpoints if the geometry is absolute
* the relative distance between the center along the line, and the absolute orthogonal distance if the geometry is relative.

Check the https://github.com/process-analytics/bpmn-visualization-js/pull/291#issuecomment-642024601[GitHub Pull Request #291]
to see various positioning methods in action.