1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | 1× 1× 1× 84× 84× 43× 41× 1× 1× 1× 1× 1× 1× 20× 20× 20× 20× 20× 20× 20× 20× 5× 15× 5× 20× 74× 74× 32× 3× 32× 1× 32× 18× 74× 32× 2× 32× 1× 32× 16× 20× 78× 20× 36× 36× 14× 36× 10× 36× 14× 36× 10× 20× | import { is } from '../../../../util/ModelUtil'; import { asTRBL } from 'diagram-js/lib/layout/LayoutUtil'; import { collectLanes, getLanesRoot } from '../../../modeling/util/LaneUtil'; var abs = Math.abs, min = Math.min, max = Math.max; function addToTrbl(trbl, attr, value, choice) { var current = trbl[attr]; // make sure to set the value if it does not exist // or apply the correct value by comparing against // choice(value, currentValue) trbl[attr] = current === undefined ? value : choice(value, current); } function addMin(trbl, attr, value) { return addToTrbl(trbl, attr, value, min); } function addMax(trbl, attr, value) { return addToTrbl(trbl, attr, value, max); } var LANE_MIN_HEIGHT = 60, LANE_MIN_WIDTH = 300, LANE_RIGHT_PADDING = 20, LANE_LEFT_PADDING = 50, LANE_TOP_PADDING = 20, LANE_BOTTOM_PADDING = 20; export function getParticipantResizeConstraints(laneShape, resizeDirection, balanced) { var lanesRoot = getLanesRoot(laneShape); var isFirst = true, isLast = true; // max top/bottom size for lanes var allLanes = collectLanes(lanesRoot, [ lanesRoot ]); var laneTrbl = asTRBL(laneShape); var maxTrbl = {}, minTrbl = {}; if (/e/.test(resizeDirection)) { minTrbl.right = laneTrbl.left + LANE_MIN_WIDTH; } else if (/w/.test(resizeDirection)) { minTrbl.left = laneTrbl.right - LANE_MIN_WIDTH; } allLanes.forEach(function(other) { var otherTrbl = asTRBL(other); if (/n/.test(resizeDirection)) { if (otherTrbl.top < (laneTrbl.top - 10)) { isFirst = false; } // max top size (based on next element) if (balanced && abs(laneTrbl.top - otherTrbl.bottom) < 10) { addMax(maxTrbl, 'top', otherTrbl.top + LANE_MIN_HEIGHT); } // min top size (based on self or nested element) if (abs(laneTrbl.top - otherTrbl.top) < 5) { addMin(minTrbl, 'top', otherTrbl.bottom - LANE_MIN_HEIGHT); } } if (/s/.test(resizeDirection)) { if (otherTrbl.bottom > (laneTrbl.bottom + 10)) { isLast = false; } // max bottom size (based on previous element) if (balanced && abs(laneTrbl.bottom - otherTrbl.top) < 10) { addMin(maxTrbl, 'bottom', otherTrbl.bottom - LANE_MIN_HEIGHT); } // min bottom size (based on self or nested element) if (abs(laneTrbl.bottom - otherTrbl.bottom) < 5) { addMax(minTrbl, 'bottom', otherTrbl.top + LANE_MIN_HEIGHT); } } }); // max top/bottom/left/right size based on flow nodes var flowElements = lanesRoot.children.filter(function(s) { return !s.hidden && !s.waypoints && (is(s, 'bpmn:FlowElement') || is(s, 'bpmn:Artifact')); }); flowElements.forEach(function(flowElement) { var flowElementTrbl = asTRBL(flowElement); if (isFirst && /n/.test(resizeDirection)) { addMin(minTrbl, 'top', flowElementTrbl.top - LANE_TOP_PADDING); } if (/e/.test(resizeDirection)) { addMax(minTrbl, 'right', flowElementTrbl.right + LANE_RIGHT_PADDING); } if (isLast && /s/.test(resizeDirection)) { addMax(minTrbl, 'bottom', flowElementTrbl.bottom + LANE_BOTTOM_PADDING); } if (/w/.test(resizeDirection)) { addMin(minTrbl, 'left', flowElementTrbl.left - LANE_LEFT_PADDING); } }); return { min: minTrbl, max: maxTrbl }; } |