Better calculations for container.getClientRect()

This commit is contained in:
Anton Lavrenov
2019-10-21 10:12:10 -05:00
parent 0669b24cf9
commit d82c11ea95
7 changed files with 98 additions and 9 deletions

View File

@@ -928,7 +928,11 @@ suite('Container', function() {
assert.equal(layer.find('Shape').length, 2, 'layer should have 2 shapes');
assert.equal(layer.find('Layer').length, 0, 'layer should have 0 layers');
assert.equal(layer.find('Group, Rect').length, 3, 'layer should have 3 [group or rects]');
assert.equal(
layer.find('Group, Rect').length,
3,
'layer should have 3 [group or rects]'
);
assert.equal(
fooLayer.find('Group').length,
@@ -2333,6 +2337,49 @@ suite('Container', function() {
});
});
test('getClientRect - test group with visible child inside invisible parent', function() {
var stage = addStage();
var layer = new Konva.Layer({
visible: false
});
stage.add(layer);
var group = new Konva.Group({
x: 10,
y: 10
});
layer.add(group);
var subGroup = new Konva.Group({
visible: false
});
group.add(subGroup);
subGroup.add(
new Konva.Rect({
x: 0,
y: 0,
width: 50,
height: 50,
visible: true
})
);
subGroup.add(
new Konva.Rect({
x: 400,
y: 400,
width: 50,
height: 50,
visible: true
})
);
layer.draw();
assert.deepEqual(group.getClientRect(), {
x: 10,
y: 10,
width: 0,
height: 0
});
});
test('get client rect with deep nested hidden shape 2', function() {
var layer = new Konva.Layer();
var group = new Konva.Group({

View File

@@ -1684,7 +1684,7 @@ suite('Transformer', function() {
},
expectedWidth: 50,
expectedHeight: 50
},
}
// {
// name: 'top-left-reverse',
// startPos: {
@@ -1970,6 +1970,38 @@ suite('Transformer', function() {
assert.equal(rect.height(), 100);
});
test('check calculations when the size = 0', function() {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
var rect = new Konva.Rect({
x: 50,
y: 50,
draggable: true,
// can we fit from empty width?
width: 0,
height: 100,
fill: 'yellow'
});
layer.add(rect);
var tr = new Konva.Transformer({
node: rect
});
layer.add(tr);
layer.draw();
tr._fitNodeInto({
x: 50,
y: 50,
width: 100,
height: 100
});
layer.draw();
assert.equal(rect.scaleX(), 1, '');
});
test('attrs change - arc', function() {
var stage = addStage();
var layer = new Konva.Layer();