This commit is contained in:
lavrton
2015-06-19 23:18:41 +07:00
parent abe749b102
commit 5c6f654cb3
2 changed files with 39 additions and 31 deletions

View File

@@ -3,7 +3,7 @@
* Konva JavaScript Framework v0.9.9 * Konva JavaScript Framework v0.9.9
* http://konvajs.github.io/ * http://konvajs.github.io/
* Licensed under the MIT or GPL Version 2 licenses. * Licensed under the MIT or GPL Version 2 licenses.
* Date: Tue Jun 02 2015 * Date: Fri Jun 19 2015
* *
* 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 - 2015 by Anton Lavrenov (Konva) * Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
@@ -6616,6 +6616,12 @@ var Konva = {};
}, },
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
@@ -6632,12 +6638,15 @@ var Konva = {};
}); });
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);
} }
@@ -12889,7 +12898,7 @@ var Konva = {};
Konva.Collection.mapMethods(Konva.Text); Konva.Collection.mapMethods(Konva.Text);
})(); })();
(function() { (function () {
/** /**
* Line constructor.  Lines are defined by an array of points and * Line constructor.  Lines are defined by an array of points and
* a tension * a tension
@@ -12981,23 +12990,23 @@ var Konva = {};
* tension: 1 * tension: 1
* }); * });
*/ */
Konva.Line = function(config) { Konva.Line = function (config) {
this.___init(config); this.___init(config);
}; };
Konva.Line.prototype = { Konva.Line.prototype = {
___init: function(config) { ___init: function (config) {
// call super constructor // call super constructor
Konva.Shape.call(this, config); Konva.Shape.call(this, config);
this.className = 'Line'; this.className = 'Line';
this.on('pointsChange.konva tensionChange.konva closedChange.konva', function() { this.on('pointsChange.konva tensionChange.konva closedChange.konva', function () {
this._clearCache('tensionPoints'); this._clearCache('tensionPoints');
}); });
this.sceneFunc(this._sceneFunc); this.sceneFunc(this._sceneFunc);
}, },
_sceneFunc: function(context) { _sceneFunc: function (context) {
var points = this.getPoints(), var points = this.getPoints(),
length = points.length, length = points.length,
tension = this.getTension(), tension = this.getTension(),
@@ -13012,7 +13021,7 @@ var Konva = {};
context.moveTo(points[0], points[1]); context.moveTo(points[0], points[1]);
// tension // tension
if(tension !== 0 && length > 4) { if (tension !== 0 && length > 4) {
tp = this.getTensionPoints(); tp = this.getTensionPoints();
len = tp.length; len = tp.length;
n = closed ? 0 : 4; n = closed ? 0 : 4;
@@ -13021,7 +13030,7 @@ var Konva = {};
context.quadraticCurveTo(tp[0], tp[1], tp[2], tp[3]); context.quadraticCurveTo(tp[0], tp[1], tp[2], tp[3]);
} }
while(n < len - 2) { while (n < len - 2) {
context.bezierCurveTo(tp[n++], tp[n++], tp[n++], tp[n++], tp[n++], tp[n++]); context.bezierCurveTo(tp[n++], tp[n++], tp[n++], tp[n++], tp[n++], tp[n++]);
} }
@@ -13031,7 +13040,7 @@ var Konva = {};
} }
// no tension // no tension
else { else {
for(n = 2; n < length; n += 2) { for (n = 2; n < length; n += 2) {
context.lineTo(points[n], points[n + 1]); context.lineTo(points[n], points[n + 1]);
} }
} }
@@ -13046,18 +13055,17 @@ var Konva = {};
context.strokeShape(this); context.strokeShape(this);
} }
}, },
getTensionPoints: function() { getTensionPoints: function () {
return this._getCache('tensionPoints', this._getTensionPoints); return this._getCache('tensionPoints', this._getTensionPoints);
}, },
_getTensionPoints: function() { _getTensionPoints: function () {
if (this.getClosed()) { if (this.getClosed()) {
return this._getTensionPointsClosed(); return this._getTensionPointsClosed();
} } else {
else {
return Konva.Util._expandPoints(this.getPoints(), this.getTension()); return Konva.Util._expandPoints(this.getPoints(), this.getTension());
} }
}, },
_getTensionPointsClosed: function() { _getTensionPointsClosed: function () {
var p = this.getPoints(), var p = this.getPoints(),
len = p.length, len = p.length,
tension = this.getTension(), tension = this.getTension(),
@@ -13101,14 +13109,14 @@ var Konva = {};
return tp; return tp;
}, },
getWidth: function() { getWidth: function () {
return this.getSelfRect().width; return this.getSelfRect().width;
}, },
getHeight: function() { getHeight: function () {
return this.getSelfRect().height; return this.getSelfRect().height;
}, },
// overload size detection // overload size detection
getSelfRect: function() { getSelfRect: function () {
var points; var points;
if (this.getTension() !== 0) { if (this.getTension() !== 0) {
points = this._getTensionPoints(); points = this._getTensionPoints();
@@ -13117,11 +13125,12 @@ var Konva = {};
} }
var minX = points[0]; var minX = points[0];
var maxX = points[0]; var maxX = points[0];
var minY = points[0]; var minY = points[1];
var maxY = points[0]; var maxY = points[1];
var x, y; var x, y;
for (var i = 0; i < points.length / 2; i++) { for (var i = 0; i < points.length / 2; i++) {
x = points[i * 2]; y = points[i * 2 + 1]; x = points[i * 2];
y = points[i * 2 + 1];
minX = Math.min(minX, x); minX = Math.min(minX, x);
maxX = Math.max(maxX, x); maxX = Math.max(maxX, x);
minY = Math.min(minY, y); minY = Math.min(minY, y);

9
konva.min.js vendored

File diff suppressed because one or more lines are too long