Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
Issue #344
  • Loading branch information
rsoika committed May 24, 2024
1 parent c493eab commit 46a89dd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,26 +572,28 @@ export class MultiLineTextNodeView extends ShapeView {
* This method splits a text into an array of separate lines.
* Beside the new-line character also the length of a line is considered.
* This is needed to display a long text in multiple SVG tspan elements.
* The CHARACTER_SPACE defines the average with of a single character.
* However, this value is only an approximation.
*
* @param text - The text to be split.
* @returns an array of text lines
*/
function textLineSplitter(text: any, nodeWidth: number): string[] {
const CHARACTER_SPACE = 6.5;
const result: string[] = [];
// first split only by newlines
const lines = text.split('\n');
// Next we iterate of each line and verify if the words
// in this line fit into the given nodesWidth
for (let i = 0; i < lines.length; i++) {
// split line into words....
// const words = lines[i].split(/\s+/);
const words = lines[i].split(' ');
// now lets add word by word and verify if we need to add a newline...
let line = '';
for (let j = 0; j < words.length; j++) {
const word = words[j];
line += word + ' ';
if (line.length > (nodeWidth / 5)) {
if (line.length > (nodeWidth / CHARACTER_SPACE)) {
line = line.substring(0, line.length - word.length - 2);
result.push(line);
line = word + ' ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class BPMNEdgeView extends PolylineEdgeViewWithGapsOnIntersections {
additionals.push(arrow);
}

// Add the edge padding (added by the )BPMNGModelFactory
// Add the edge padding (added by the BPMNGModelFactory)
const edgePadding = EdgePadding.from(edge);
if (edgePadding) {
additionals.push(this.renderEdgePadding(edge, segments, edgePadding));
Expand Down

0 comments on commit 46a89dd

Please sign in to comment.