skip throw on bad caching

This commit is contained in:
Anton Lavrenov
2017-09-05 13:30:08 +02:00
parent f46ce6e885
commit 356c778b7b
5 changed files with 125 additions and 54 deletions

View File

@@ -181,7 +181,13 @@
drawBorder = conf.drawBorder || false;
if (!width || !height) {
throw new Error('Width or height of caching configuration equals 0.');
// make throw async, because we don't need to stop funcion
setTimeout(function() {
Konva.Util.throw(
'Width or height of caching configuration equals 0. Caching is ignored.'
);
});
return;
}
width += offset * 2;
@@ -191,10 +197,10 @@
y -= offset;
var cachedSceneCanvas = new Konva.SceneCanvas({
pixelRatio: pixelRatio,
width: width,
height: height
}),
pixelRatio: pixelRatio,
width: width,
height: height
}),
cachedFilterCanvas = new Konva.SceneCanvas({
pixelRatio: pixelRatio,
width: width,
@@ -338,7 +344,8 @@
context.restore();
},
_drawCachedHitCanvas: function(context) {
var cachedCanvas = this._cache.canvas, hitCanvas = cachedCanvas.hit;
var cachedCanvas = this._cache.canvas,
hitCanvas = cachedCanvas.hit;
context.save();
context.translate(this._cache.canvas.x, this._cache.canvas.y);
context.drawImage(hitCanvas._canvas, 0, 0);
@@ -666,7 +673,8 @@
* })
*/
getAncestors: function() {
var parent = this.getParent(), ancestors = new Konva.Collection();
var parent = this.getParent(),
ancestors = new Konva.Collection();
while (parent) {
ancestors.push(parent);
@@ -740,7 +748,8 @@
return this._getCache(LISTENING, this._isListening);
},
_isListening: function() {
var listening = this.getListening(), parent = this.getParent();
var listening = this.getListening(),
parent = this.getParent();
// the following conditions are a simplification of the truth table above.
// please modify carefully
@@ -777,7 +786,8 @@
return this._getCache(VISIBLE, this._isVisible);
},
_isVisible: function() {
var visible = this.getVisible(), parent = this.getParent();
var visible = this.getVisible(),
parent = this.getParent();
// the following conditions are a simplification of the truth table above.
// please modify carefully
@@ -845,7 +855,13 @@
* @returns {Integer}
*/
getAbsoluteZIndex: function() {
var depth = this.getDepth(), that = this, index = 0, nodes, len, n, child;
var depth = this.getDepth(),
that = this,
index = 0,
nodes,
len,
n,
child;
function addChildren(children) {
nodes = [];
@@ -882,7 +898,8 @@
* @returns {Integer}
*/
getDepth: function() {
var depth = 0, parent = this.parent;
var depth = 0,
parent = this.parent;
while (parent) {
depth++;
@@ -930,7 +947,8 @@
* @returns {Konva.Node}
*/
setAbsolutePosition: function(pos) {
var origTrans = this._clearTransform(), it;
var origTrans = this._clearTransform(),
it;
// don't clear translation
this.attrs.x = origTrans.x;
@@ -1025,7 +1043,10 @@
return this;
},
_eachAncestorReverse: function(func, top) {
var family = [], parent = this.getParent(), len, n;
var family = [],
parent = this.getParent(),
len,
n;
// if top node is defined, and this node is top node,
// there's no need to build a family tree. just execute
@@ -1086,7 +1107,8 @@
Konva.Util.warn('Node has no parent. moveUp function is ignored.');
return false;
}
var index = this.index, len = this.parent.getChildren().length;
var index = this.index,
len = this.parent.getChildren().length;
if (index < len - 1) {
this.parent.children.splice(index, 1);
this.parent.children.splice(index + 1, 0, this);
@@ -1199,7 +1221,12 @@
* @returns {Object}
*/
toObject: function() {
var obj = {}, attrs = this.getAttrs(), key, val, getter, defaultValue;
var obj = {},
attrs = this.getAttrs(),
key,
val,
getter,
defaultValue;
obj.attrs = {};
@@ -1401,7 +1428,9 @@
}
},
_getAbsoluteTransform: function(top) {
var at = new Konva.Transform(), transformsEnabled, trans;
var at = new Konva.Transform(),
transformsEnabled,
trans;
// start with stage and traverse downwards to self
this._eachAncestorReverse(function(node) {
@@ -1442,7 +1471,8 @@
parent = parent.getParent();
}
var scaleX = 1, scaleY = 1;
var scaleX = 1,
scaleY = 1;
// start with stage and traverse downwards to self
this._eachAncestorReverse(function(node) {
@@ -1558,10 +1588,10 @@
y = config.y || 0,
pixelRatio = config.pixelRatio || 1,
canvas = new Konva.SceneCanvas({
width: config.width ||
this.getWidth() ||
(stage ? stage.getWidth() : 0),
height: config.height ||
width:
config.width || this.getWidth() || (stage ? stage.getWidth() : 0),
height:
config.height ||
this.getHeight() ||
(stage ? stage.getHeight() : 0),
pixelRatio: pixelRatio
@@ -1617,7 +1647,8 @@
*/
toDataURL: function(config) {
config = config || {};
var mimeType = config.mimeType || null, quality = config.quality || null;
var mimeType = config.mimeType || null,
quality = config.quality || null;
return this._toKonvaCanvas(config).toDataURL(mimeType, quality);
},
/**
@@ -1704,7 +1735,9 @@
: [];
},
_off: function(type, name) {
var evtListeners = this.eventListeners[type], i, evtName;
var evtListeners = this.eventListeners[type],
i,
evtName;
for (i = 0; i < evtListeners.length; i++) {
evtName = evtListeners[i].name;
@@ -1829,7 +1862,8 @@
* node.setAttr('x', 5);
*/
setAttr: function(attr, val) {
var method = SET + Konva.Util._capitalize(attr), func = this[method];
var method = SET + Konva.Util._capitalize(attr),
func = this[method];
if (Konva.Util._isFunction(func)) {
func.call(this, val);
@@ -1918,7 +1952,8 @@
}
},
_fire: function(eventType, evt) {
var events = this.eventListeners[eventType], i;
var events = this.eventListeners[eventType],
i;
evt = evt || {};
evt.currentTarget = this;