mirror of
https://github.com/konvajs/konva.git
synced 2025-12-21 19:27:08 +08:00
fix getClientRect for container. close #85
This commit is contained in:
@@ -5,7 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
## [Not released][Not released]
|
## [Not released][Not released]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Correct calculation in `getClientRect` method of `Konva.Line.
|
- Correct calculation in `getClientRect` method of `Konva.Line` and `Konva.Container`.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Dragging now works much better. If your pointer is out of stage content dragging will still continue.
|
- Dragging now works much better. If your pointer is out of stage content dragging will still continue.
|
||||||
|
|||||||
@@ -410,6 +410,12 @@
|
|||||||
},
|
},
|
||||||
getClientRect: function(skipTransform) {
|
getClientRect: function(skipTransform) {
|
||||||
var minX, minY, maxX, maxY;
|
var minX, minY, maxX, maxY;
|
||||||
|
var selfRect = {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: 0,
|
||||||
|
height: 0
|
||||||
|
};
|
||||||
this.children.each(function(child) {
|
this.children.each(function(child) {
|
||||||
var rect = child.getClientRect();
|
var rect = child.getClientRect();
|
||||||
if (minX === undefined) { // initial value for first child
|
if (minX === undefined) { // initial value for first child
|
||||||
@@ -426,12 +432,15 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var selfRect = {
|
if (this.children.length !== 0) {
|
||||||
x: minX,
|
selfRect = {
|
||||||
y: minY,
|
x: minX,
|
||||||
width: maxX - minX,
|
y: minY,
|
||||||
height: maxY - minY
|
width: maxX - minX,
|
||||||
};
|
height: maxY - minY
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (!skipTransform) {
|
if (!skipTransform) {
|
||||||
return this._transformedRect(selfRect);
|
return this._transformedRect(selfRect);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1616,4 +1616,17 @@ suite('Container', function() {
|
|||||||
layer.add(circle1, circle2, circle3);
|
layer.add(circle1, circle2, circle3);
|
||||||
assert.equal(layer.getChildren().length, 3, 'layer has exactly three children');
|
assert.equal(layer.getChildren().length, 3, 'layer has exactly three children');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getClientRect - test empty case', function() {
|
||||||
|
var stage = addStage();
|
||||||
|
var layer = new Konva.Layer();
|
||||||
|
stage.add(layer);
|
||||||
|
var group = new Konva.Group({
|
||||||
|
x : 10,
|
||||||
|
y : 10
|
||||||
|
});
|
||||||
|
group.add(new Konva.Group());
|
||||||
|
assert.deepEqual(group.getClientRect(), {x:10, y:10, width: 0, height:0});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user