bugs fixes

This commit is contained in:
Anton Lavrenov 2018-09-22 14:08:22 +03:00
parent 0001c1de0d
commit 27f00b1aad
6 changed files with 58 additions and 10 deletions

View File

@ -2,7 +2,7 @@
* Konva JavaScript Framework v2.4.0 * Konva JavaScript Framework v2.4.0
* http://konvajs.github.io/ * http://konvajs.github.io/
* Licensed under the MIT * Licensed under the MIT
* Date: Wed Sep 19 2018 * Date: Sat Sep 22 2018
* *
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@ -3304,15 +3304,20 @@
isVisible: function() { isVisible: function() {
return this._getCache(VISIBLE, this._isVisible); return this._getCache(VISIBLE, this._isVisible);
}, },
_isVisible: function() { _isVisible: function(relativeTo) {
var visible = this.getVisible(), var visible = this.getVisible(),
parent = this.getParent(); parent = this.getParent();
if (relativeTo === parent && visible === 'inherit') {
return true;
} else if (relativeTo === parent) {
return visible;
}
// the following conditions are a simplification of the truth table above. // the following conditions are a simplification of the truth table above.
// please modify carefully // please modify carefully
if (visible === 'inherit') { if (visible === 'inherit') {
if (parent) { if (parent) {
return parent.isVisible(); return parent._isVisible(relativeTo);
} else { } else {
return true; return true;
} }
@ -8419,7 +8424,7 @@
var hasVisible = false; var hasVisible = false;
for (var i = 0; i < shapes.length; i++) { for (var i = 0; i < shapes.length; i++) {
var shape = shapes[i]; var shape = shapes[i];
if (shape.getVisible()) { if (shape._isVisible(this)) {
hasVisible = true; hasVisible = true;
break; break;
} }
@ -19856,6 +19861,8 @@
var keepProportion = this.keepRatio() || e.shiftKey; var keepProportion = this.keepRatio() || e.shiftKey;
// console.log(keepProportion);
if (this.movingResizer === 'top-left') { if (this.movingResizer === 'top-left') {
if (keepProportion) { if (keepProportion) {
newHypotenuse = Math.sqrt( newHypotenuse = Math.sqrt(
@ -20013,6 +20020,8 @@
var bottomOffsetX = this.getWidth() - bottomRight.x(); var bottomOffsetX = this.getWidth() - bottomRight.x();
var bottomOffsetY = this.getHeight() - bottomRight.y(); var bottomOffsetY = this.getHeight() - bottomRight.y();
console.log(topOffsetX, topOffsetY, bottomOffsetX, bottomOffsetY);
bottomRight.move({ bottomRight.move({
x: -topOffsetX, x: -topOffsetX,
y: -topOffsetY y: -topOffsetY
@ -20034,6 +20043,8 @@
var height = var height =
this.findOne('.bottom-right').y() - this.findOne('.top-left').y(); this.findOne('.bottom-right').y() - this.findOne('.top-left').y();
// console.log(x, y, width, height);
this._fitNodeInto( this._fitNodeInto(
{ {
x: x + this.offsetX(), x: x + this.offsetX(),

6
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -533,7 +533,7 @@
var hasVisible = false; var hasVisible = false;
for (var i = 0; i < shapes.length; i++) { for (var i = 0; i < shapes.length; i++) {
var shape = shapes[i]; var shape = shapes[i];
if (shape.getVisible()) { if (shape._isVisible(this)) {
hasVisible = true; hasVisible = true;
break; break;
} }

View File

@ -781,15 +781,20 @@
isVisible: function() { isVisible: function() {
return this._getCache(VISIBLE, this._isVisible); return this._getCache(VISIBLE, this._isVisible);
}, },
_isVisible: function() { _isVisible: function(relativeTo) {
var visible = this.getVisible(), var visible = this.getVisible(),
parent = this.getParent(); parent = this.getParent();
if (relativeTo === parent && visible === 'inherit') {
return true;
} else if (relativeTo === parent) {
return visible;
}
// the following conditions are a simplification of the truth table above. // the following conditions are a simplification of the truth table above.
// please modify carefully // please modify carefully
if (visible === 'inherit') { if (visible === 'inherit') {
if (parent) { if (parent) {
return parent.isVisible(); return parent._isVisible(relativeTo);
} else { } else {
return true; return true;
} }

View File

@ -429,6 +429,8 @@
var keepProportion = this.keepRatio() || e.shiftKey; var keepProportion = this.keepRatio() || e.shiftKey;
// console.log(keepProportion);
if (this.movingResizer === 'top-left') { if (this.movingResizer === 'top-left') {
if (keepProportion) { if (keepProportion) {
newHypotenuse = Math.sqrt( newHypotenuse = Math.sqrt(
@ -586,6 +588,8 @@
var bottomOffsetX = this.getWidth() - bottomRight.x(); var bottomOffsetX = this.getWidth() - bottomRight.x();
var bottomOffsetY = this.getHeight() - bottomRight.y(); var bottomOffsetY = this.getHeight() - bottomRight.y();
console.log(topOffsetX, topOffsetY, bottomOffsetX, bottomOffsetY);
bottomRight.move({ bottomRight.move({
x: -topOffsetX, x: -topOffsetX,
y: -topOffsetY y: -topOffsetY
@ -607,6 +611,8 @@
var height = var height =
this.findOne('.bottom-right').y() - this.findOne('.top-left').y(); this.findOne('.bottom-right').y() - this.findOne('.top-left').y();
// console.log(x, y, width, height);
this._fitNodeInto( this._fitNodeInto(
{ {
x: x + this.offsetX(), x: x + this.offsetX(),

View File

@ -2295,6 +2295,32 @@ suite('Container', function() {
}); });
}); });
test('get client rect with deep nested hidden shape 2', function() {
var layer = new Konva.Layer();
var group = new Konva.Group({
visible: false,
x: 100,
y: 40
});
var rect = new Konva.Rect({
height: 100,
width: 100,
fill: 'red'
});
group.add(rect);
layer.add(group);
var clientRect = layer.getClientRect();
assert.deepEqual(clientRect, {
x: 0,
y: 0,
width: 0,
height: 0
});
});
test('getClientRect - test layer', function() { test('getClientRect - test layer', function() {
var stage = addStage(); var stage = addStage();
var layer = new Konva.Layer(); var layer = new Konva.Layer();