From d4b2892c13e263a4e6991cdde10d7d9bf0c68ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B0=D0=B2=D1=80=D1=91=D0=BD=D0=BE=D0=B2=20=D0=90?= =?UTF-8?q?=D0=BD=D1=82=D0=BE=D0=BD?= Date: Tue, 12 Nov 2013 18:57:58 +0800 Subject: [PATCH 1/2] toImage improvement --- src/Node.js | 4 ++-- test/unit/Node-test.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Node.js b/src/Node.js index 12df7475..8eed690a 100644 --- a/src/Node.js +++ b/src/Node.js @@ -1005,8 +1005,8 @@ x = config.x || 0, y = config.y || 0, canvas = new Kinetic.SceneCanvas({ - width: config.width || stage.getWidth(), - height: config.height || stage.getHeight(), + width: this.getWidth() || config.width || (stage ? stage.getWidth() : 0), + height: this.getHeight() || config.height || (stage ? stage.getHeight() : 0), pixelRatio: 1 }), context = canvas.getContext(); diff --git a/test/unit/Node-test.js b/test/unit/Node-test.js index 93ed1036..6c1a1520 100644 --- a/test/unit/Node-test.js +++ b/test/unit/Node-test.js @@ -933,6 +933,39 @@ suite('Node', function() { showHit(layer); }); + // ====================================================== + test('node caching width minimal configuration', function(done) { + var stage = addStage(); + var layer = new Kinetic.Layer(); + stage.add(layer); + + var rect = new Kinetic.Rect({ + width : 50, + height : 50, + fill: 'green', + stroke: 'blue', + strokeWidth: 5, + draggable: true + }); + + rect.toImage({ + callback: function(imageObj) { + assert.equal(Kinetic.Util._isElement(imageObj), true); + var cachedShape = new Kinetic.Image({ + image: imageObj, + draggable: true, + stroke: 'red', + strokeWidth: 5 + }); + + layer.add(cachedShape); + layer.draw(); + done(); + } + }); + + showHit(layer); + }); // ====================================================== test('hide group', function() { var stage = addStage(); From 6de66f18af994fa2e4f792a13413fa831406ae41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B0=D0=B2=D1=80=D1=91=D0=BD=D0=BE=D0=B2=20=D0=90?= =?UTF-8?q?=D0=BD=D1=82=D0=BE=D0=BD?= Date: Tue, 12 Nov 2013 19:03:15 +0800 Subject: [PATCH 2/2] config first --- src/Node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Node.js b/src/Node.js index 8eed690a..8725f6f9 100644 --- a/src/Node.js +++ b/src/Node.js @@ -1005,8 +1005,8 @@ x = config.x || 0, y = config.y || 0, canvas = new Kinetic.SceneCanvas({ - width: this.getWidth() || config.width || (stage ? stage.getWidth() : 0), - height: this.getHeight() || config.height || (stage ? stage.getHeight() : 0), + width: config.width || this.getWidth() || (stage ? stage.getWidth() : 0), + height: config.height || this.getHeight() || (stage ? stage.getHeight() : 0), pixelRatio: 1 }), context = canvas.getContext();