mirror of
https://github.com/konvajs/konva.git
synced 2026-01-05 09:04:40 +08:00
stage setSize() method now converts inputs to integers. added a lot of setSize unit tests
This commit is contained in:
19
dist/kinetic-core.js
vendored
19
dist/kinetic-core.js
vendored
@@ -1574,17 +1574,22 @@ Kinetic.Stage.prototype = {
|
|||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* set stage size
|
* set stage size
|
||||||
* @param {int} width
|
|
||||||
* @param {int} height
|
|
||||||
*/
|
*/
|
||||||
setSize: function(width, height) {
|
setSize: function() {
|
||||||
// set stage dimensions
|
// set stage dimensions
|
||||||
this.attrs.width = width;
|
var size = Kinetic.GlobalObject._getSize(arguments);
|
||||||
this.attrs.height = height;
|
this.setAttrs(size);
|
||||||
|
|
||||||
|
// convert to integers
|
||||||
|
this.attrs.width = Math.round(this.attrs.width);
|
||||||
|
this.attrs.height = Math.round(this.attrs.height);
|
||||||
|
|
||||||
|
var width = this.attrs.width;
|
||||||
|
var height = this.attrs.height;
|
||||||
|
|
||||||
// set content dimensions
|
// set content dimensions
|
||||||
this.content.style.width = this.attrs.width + 'px';
|
this.content.style.width = width + 'px';
|
||||||
this.content.style.height = this.attrs.height + 'px';
|
this.content.style.height = height + 'px';
|
||||||
|
|
||||||
// set buffer layer and path layer sizes
|
// set buffer layer and path layer sizes
|
||||||
this.bufferLayer.getCanvas().width = width;
|
this.bufferLayer.getCanvas().width = width;
|
||||||
|
|||||||
4
dist/kinetic-core.min.js
vendored
4
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
19
src/Stage.js
19
src/Stage.js
@@ -91,17 +91,22 @@ Kinetic.Stage.prototype = {
|
|||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* set stage size
|
* set stage size
|
||||||
* @param {int} width
|
|
||||||
* @param {int} height
|
|
||||||
*/
|
*/
|
||||||
setSize: function(width, height) {
|
setSize: function() {
|
||||||
// set stage dimensions
|
// set stage dimensions
|
||||||
this.attrs.width = width;
|
var size = Kinetic.GlobalObject._getSize(arguments);
|
||||||
this.attrs.height = height;
|
this.setAttrs(size);
|
||||||
|
|
||||||
|
// convert to integers
|
||||||
|
this.attrs.width = Math.round(this.attrs.width);
|
||||||
|
this.attrs.height = Math.round(this.attrs.height);
|
||||||
|
|
||||||
|
var width = this.attrs.width;
|
||||||
|
var height = this.attrs.height;
|
||||||
|
|
||||||
// set content dimensions
|
// set content dimensions
|
||||||
this.content.style.width = this.attrs.width + 'px';
|
this.content.style.width = width + 'px';
|
||||||
this.content.style.height = this.attrs.height + 'px';
|
this.content.style.height = height + 'px';
|
||||||
|
|
||||||
// set buffer layer and path layer sizes
|
// set buffer layer and path layer sizes
|
||||||
this.bufferLayer.getCanvas().width = width;
|
this.bufferLayer.getCanvas().width = width;
|
||||||
|
|||||||
@@ -734,8 +734,7 @@ Test.prototype.tests = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
layer.add(star);
|
layer.add(star);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
star.saveData();
|
star.saveData();
|
||||||
},
|
},
|
||||||
'EVENTS - drag events click': function(containerId) {
|
'EVENTS - drag events click': function(containerId) {
|
||||||
|
|||||||
@@ -18,6 +18,54 @@ Test.prototype.tests = {
|
|||||||
height: 200
|
height: 200
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
'STAGE - test setSize': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
|
||||||
|
var circle = new Kinetic.Circle({
|
||||||
|
x: stage.getWidth() / 2,
|
||||||
|
y: stage.getHeight() / 2,
|
||||||
|
radius: 70,
|
||||||
|
fill: 'green',
|
||||||
|
stroke: 'black',
|
||||||
|
strokeWidth: 4,
|
||||||
|
name: 'myCircle'
|
||||||
|
});
|
||||||
|
|
||||||
|
test(stage.getSize().width === 578 && stage.getSize().height === 200, 'stage size should be 1 x 2');
|
||||||
|
stage.setSize(1, 2);
|
||||||
|
test(stage.getSize().width === 1 && stage.getSize().height === 2, 'stage size should be 1 x 2');
|
||||||
|
stage.setSize(3);
|
||||||
|
test(stage.getSize().width === 3 && stage.getSize().height === 3, 'stage size should be 3 x 3');
|
||||||
|
stage.setSize({
|
||||||
|
width: 4,
|
||||||
|
height: 5
|
||||||
|
});
|
||||||
|
test(stage.getSize().width === 4 && stage.getSize().height === 5, 'stage size should be 4 x 5');
|
||||||
|
stage.setSize({
|
||||||
|
width: 6
|
||||||
|
});
|
||||||
|
test(stage.getSize().width === 6 && stage.getSize().height === 5, 'stage size should be 6 x 5');
|
||||||
|
stage.setSize({
|
||||||
|
height: 7
|
||||||
|
});
|
||||||
|
test(stage.getSize().width === 6 && stage.getSize().height === 7, 'stage size should be 6 x 7');
|
||||||
|
stage.setSize([8, 9]);
|
||||||
|
test(stage.getSize().width === 8 && stage.getSize().height === 9, 'stage size should be 8 x 9');
|
||||||
|
stage.setSize([1, 1, 10, 11]);
|
||||||
|
test(stage.getSize().width === 10 && stage.getSize().height === 11, 'stage size should be 10 x 11');
|
||||||
|
|
||||||
|
// test integer conversion
|
||||||
|
stage.setSize(300.2, 200.2);
|
||||||
|
test(stage.getSize().width === 300 && stage.getSize().height === 200, 'stage size should be 300 x 200');
|
||||||
|
|
||||||
|
layer.add(circle);
|
||||||
|
stage.add(layer);
|
||||||
|
},
|
||||||
'STAGE - add shape then stage then layer': function(containerId) {
|
'STAGE - add shape then stage then layer': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
|
|||||||
Reference in New Issue
Block a user