Skip to content

Commit

Permalink
fix(overlays): add multi-root modeling behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
marstamm committed Dec 17, 2021
1 parent e1a88be commit 26cfc93
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/features/overlays/Overlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ Overlays.prototype._updateOverlay = function(overlay) {
}

setPosition(htmlContainer, left || 0, top || 0);
this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
};


Expand Down Expand Up @@ -459,8 +460,6 @@ Overlays.prototype._addOverlay = function(overlay) {
var elementRoot = this._canvas.findRoot(element);
var activeRoot = this._canvas.getRootElement();

overlay.rootElement = elementRoot;

setVisible(htmlContainer, elementRoot === activeRoot);

overlay.htmlContainer = htmlContainer;
Expand All @@ -477,7 +476,7 @@ Overlays.prototype._addOverlay = function(overlay) {

Overlays.prototype._updateOverlayVisibilty = function(overlay, viewbox) {
var show = overlay.show,
rootElement = overlay.rootElement,
rootElement = this._canvas.findRoot(overlay.element),
minZoom = show && show.minZoom,
maxZoom = show && show.maxZoom,
htmlContainer = overlay.htmlContainer,
Expand Down Expand Up @@ -620,10 +619,8 @@ Overlays.prototype._init = function() {
});


eventBus.on('root.set', function(event) {
forEach(self._overlays, function(el) {
setVisible(el.htmlContainer, el.rootElement === event.element);
});
eventBus.on('root.set', function() {
self._updateOverlaysVisibilty();
});

// clear overlays with diagram
Expand Down
72 changes: 72 additions & 0 deletions test/spec/features/overlays/OverlaysIntegrationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {

import {
classes as domClasses,
domify,
query as domQuery
} from 'min-dom';

Expand Down Expand Up @@ -173,6 +174,72 @@ describe('features/overlay - integration', function() {
expect(parseInt(html.style.left)).to.equal(50);
}));


describe('changing root elements', function() {

it('should hide on move to hidden root', inject(function(modeling, canvas, overlays) {

// given
var root1 = canvas.setRootElement({ id: '1', children: [] });
var root2 = canvas.addRootElement({ id: '2', children: [] });
var shape = canvas.addShape({
id: 'test',
x: 50,
y: 50,
width: 100,
height: 100
}, root1);

// add overlay to a single shape (or connection)
var overlayId = overlays.add(shape, {
html: domify('<div style="width: 40px; height: 40px">TEST<br/>TEST</div>'),
position: {
top: 0,
left: 0
}
});

// when
modeling.moveShape(shape, { x: 0, y: 0 }, root2);

// then
var html = overlays.get(overlayId).html;
expect(isVisible(html)).to.be.false;
}));


it('should show on move to active root', inject(function(modeling, canvas, overlays) {

// given
var root1 = canvas.setRootElement({ id: '1', children: [] });
var root2 = canvas.addRootElement({ id: '2', children: [] });
var shape = canvas.addShape({
id: 'test',
x: 50,
y: 50,
width: 100,
height: 100
}, root2);

// add overlay to a single shape (or connection)
var overlayId = overlays.add(shape, {
html: domify('<div style="width: 40px; height: 40px">TEST<br/>TEST</div>'),
position: {
top: 0,
left: 0
}
});

// when
modeling.moveShape(shape, { x: 0, y: 0 }, root1);

// then
var html = overlays.get(overlayId).html;
expect(isVisible(html)).to.be.true;
}));

});

});


Expand Down Expand Up @@ -328,3 +395,8 @@ describe('features/overlay - integration', function() {
});

});


function isVisible(element) {
return element.parentNode.style.display !== 'none';
}

0 comments on commit 26cfc93

Please sign in to comment.