getClientRect calculation fix for groups

This commit is contained in:
Anton Lavrenov 2018-09-24 14:40:07 +03:00
parent 04222bfe93
commit c0911572e7
5 changed files with 52 additions and 9 deletions

View File

@ -9,6 +9,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
* Added some text trim logic to wrap in better
### Fixed
* `getClientRect` calculation fix for groups
## [2.4.0][2018-09-19]
### Added

View File

@ -8400,10 +8400,9 @@
var rect = child.getClientRect({ relativeTo: that });
// skip invisible children (like empty groups)
// or don't skip... hmmm...
// if (rect.width === 0 && rect.height === 0) {
// return;
// }
if (rect.width === 0 && rect.height === 0) {
return;
}
if (minX === undefined) {
// initial value for first child

2
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -509,10 +509,9 @@
var rect = child.getClientRect({ relativeTo: that });
// skip invisible children (like empty groups)
// or don't skip... hmmm...
// if (rect.width === 0 && rect.height === 0) {
// return;
// }
if (rect.width === 0 && rect.height === 0) {
return;
}
if (minX === undefined) {
// initial value for first child

View File

@ -2346,6 +2346,47 @@ suite('Container', function() {
});
});
test.only('getClientRect - nested group with a hidden shapes', function() {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
var group1 = new Konva.Group();
layer.add(group1);
var rect = new Konva.Rect({
x: 50,
y: 100,
width: 200,
height: 75,
fill: 'red'
});
group1.add(rect);
var group2 = new Konva.Group();
layer.add(group2);
var rect2 = new Konva.Rect({
x: 0,
y: 0,
width: 200,
height: 75,
fill: 'red',
visible: false
});
group1.add(rect2);
assert.deepEqual(layer.getClientRect(), {
x: 50,
y: 100,
width: 200,
height: 75
});
});
test('clip-cache', function() {
var stage = addStage();
var layer = new Konva.Layer();