mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
prettier
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
suite('Shape', function() {
|
||||
suite('Shape', function () {
|
||||
// ======================================================
|
||||
test('test intersects()', function() {
|
||||
test('test intersects()', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
var rect = new Konva.Rect({
|
||||
@@ -10,7 +10,7 @@ suite('Shape', function() {
|
||||
height: 50,
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4
|
||||
strokeWidth: 4,
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -19,7 +19,7 @@ suite('Shape', function() {
|
||||
assert.equal(
|
||||
rect.intersects({
|
||||
x: 201,
|
||||
y: 101
|
||||
y: 101,
|
||||
}),
|
||||
true,
|
||||
'(201,101) should intersect the shape'
|
||||
@@ -28,7 +28,7 @@ suite('Shape', function() {
|
||||
assert.equal(
|
||||
rect.intersects({
|
||||
x: 197,
|
||||
y: 97
|
||||
y: 97,
|
||||
}),
|
||||
false,
|
||||
'(197, 97) should not intersect the shape'
|
||||
@@ -37,7 +37,7 @@ suite('Shape', function() {
|
||||
assert.equal(
|
||||
rect.intersects({
|
||||
x: 250,
|
||||
y: 125
|
||||
y: 125,
|
||||
}),
|
||||
true,
|
||||
'(250, 125) should intersect the shape'
|
||||
@@ -46,7 +46,7 @@ suite('Shape', function() {
|
||||
assert.equal(
|
||||
rect.intersects({
|
||||
x: 300,
|
||||
y: 150
|
||||
y: 150,
|
||||
}),
|
||||
true,
|
||||
'(300, 150) should intersect the shape'
|
||||
@@ -55,7 +55,7 @@ suite('Shape', function() {
|
||||
assert.equal(
|
||||
rect.intersects({
|
||||
x: 303,
|
||||
y: 153
|
||||
y: 153,
|
||||
}),
|
||||
false,
|
||||
'(303, 153) should not intersect the shape'
|
||||
@@ -63,11 +63,11 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('test hasShadow() method', function() {
|
||||
test('test hasShadow() method', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
var shape = new Konva.Shape({
|
||||
sceneFunc: function(context) {
|
||||
sceneFunc: function (context) {
|
||||
context.beginPath();
|
||||
context.moveTo(0, 0);
|
||||
context.lineTo(100, 0);
|
||||
@@ -82,7 +82,7 @@ suite('Shape', function() {
|
||||
strokeWidth: 5,
|
||||
shadowColor: 'black',
|
||||
shadowOffsetX: 10,
|
||||
shadowOpacity: 0
|
||||
shadowOpacity: 0,
|
||||
});
|
||||
|
||||
layer.add(shape);
|
||||
@@ -112,11 +112,11 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('custom shape with fill, stroke, and strokeWidth', function() {
|
||||
test('custom shape with fill, stroke, and strokeWidth', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
var shape = new Konva.Shape({
|
||||
sceneFunc: function(context) {
|
||||
sceneFunc: function (context) {
|
||||
context.beginPath();
|
||||
context.moveTo(0, 0);
|
||||
context.lineTo(100, 0);
|
||||
@@ -128,7 +128,7 @@ suite('Shape', function() {
|
||||
y: 100,
|
||||
fill: 'green',
|
||||
stroke: 'blue',
|
||||
strokeWidth: 5
|
||||
strokeWidth: 5,
|
||||
});
|
||||
|
||||
layer.add(shape);
|
||||
@@ -136,9 +136,9 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('add star with translated, scaled, rotated fill', function(done) {
|
||||
test('add star with translated, scaled, rotated fill', function (done) {
|
||||
var imageObj = new Image();
|
||||
imageObj.onload = function() {
|
||||
imageObj.onload = function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -159,7 +159,7 @@ suite('Shape', function() {
|
||||
|
||||
stroke: 'blue',
|
||||
strokeWidth: 5,
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
layer.add(star);
|
||||
@@ -240,7 +240,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('test size setters and getters', function() {
|
||||
test('test size setters and getters', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -248,14 +248,14 @@ suite('Shape', function() {
|
||||
x: stage.getWidth() / 2,
|
||||
y: stage.getHeight() / 2,
|
||||
radius: 50,
|
||||
fill: 'red'
|
||||
fill: 'red',
|
||||
});
|
||||
|
||||
var ellipse = new Konva.Circle({
|
||||
x: stage.getWidth() / 2,
|
||||
y: stage.getHeight() / 2,
|
||||
radius: 50,
|
||||
fill: 'yellow'
|
||||
fill: 'yellow',
|
||||
});
|
||||
|
||||
layer.add(ellipse);
|
||||
@@ -279,16 +279,16 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('set image fill to color then image then linear gradient then back to image', function(done) {
|
||||
test('set image fill to color then image then linear gradient then back to image', function (done) {
|
||||
var imageObj = new Image();
|
||||
imageObj.onload = function() {
|
||||
imageObj.onload = function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
var circle = new Konva.Circle({
|
||||
x: 200,
|
||||
y: 60,
|
||||
radius: 50,
|
||||
fill: 'blue'
|
||||
fill: 'blue',
|
||||
});
|
||||
|
||||
layer.add(circle);
|
||||
@@ -339,10 +339,10 @@ suite('Shape', function() {
|
||||
imageObj.src = 'assets/darth-vader.jpg';
|
||||
});
|
||||
|
||||
test('stroke gradient', function() {
|
||||
test('stroke gradient', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer({
|
||||
scaleY: 1.5
|
||||
scaleY: 1.5,
|
||||
});
|
||||
|
||||
var shape = new Konva.Rect({
|
||||
@@ -353,22 +353,22 @@ suite('Shape', function() {
|
||||
fillLinearGradientColorStops: [0, 'yellow', 0.5, 'red', 1, 'white'],
|
||||
fillLinearGradientStartPoint: {
|
||||
x: 0,
|
||||
y: 0
|
||||
y: 0,
|
||||
},
|
||||
scaleX: 3,
|
||||
fillLinearGradientEndPoint: {
|
||||
x: 100,
|
||||
y: 100
|
||||
y: 100,
|
||||
},
|
||||
strokeLinearGradientColorStops: [0, 'red', 0.5, 'blue', 1, 'green'],
|
||||
strokeLinearGradientStartPoint: {
|
||||
x: 0,
|
||||
y: 0
|
||||
y: 0,
|
||||
},
|
||||
strokeLinearGradientEndPoint: {
|
||||
x: 100,
|
||||
y: 100
|
||||
}
|
||||
y: 100,
|
||||
},
|
||||
});
|
||||
layer.add(shape);
|
||||
stage.add(layer);
|
||||
@@ -382,7 +382,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('test enablers and disablers', function() {
|
||||
test('test enablers and disablers', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
var circle = new Konva.Circle({
|
||||
@@ -396,7 +396,7 @@ suite('Shape', function() {
|
||||
shadowBlur: 10,
|
||||
shadowOffset: { x: 10, y: 10 },
|
||||
dash: [10, 10],
|
||||
scaleX: 3
|
||||
scaleX: 3,
|
||||
});
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
@@ -465,7 +465,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('fill with shadow and opacity', function() {
|
||||
test('fill with shadow and opacity', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -480,7 +480,7 @@ suite('Shape', function() {
|
||||
shadowColor: 'black',
|
||||
shadowBlur: 10,
|
||||
shadowOffset: { x: 10, y: 10 },
|
||||
shadowOpacity: 0.5
|
||||
shadowOpacity: 0.5,
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -515,7 +515,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('test strokeWidth = 0', function() {
|
||||
test('test strokeWidth = 0', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -527,7 +527,7 @@ suite('Shape', function() {
|
||||
height: 50,
|
||||
fill: 'green',
|
||||
strokeWidth: 0,
|
||||
stroke: 'black'
|
||||
stroke: 'black',
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -552,7 +552,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('stroke with shadow and opacity', function() {
|
||||
test('stroke with shadow and opacity', function () {
|
||||
Konva.pixelRatio = 1;
|
||||
var stage = addStage();
|
||||
|
||||
@@ -569,7 +569,7 @@ suite('Shape', function() {
|
||||
shadowColor: 'black',
|
||||
shadowBlur: 10,
|
||||
shadowOffset: { x: 10, y: 10 },
|
||||
shadowOpacity: 0.5
|
||||
shadowOpacity: 0.5,
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -606,7 +606,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('fill and stroke with opacity', function() {
|
||||
test('fill and stroke with opacity', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -619,7 +619,7 @@ suite('Shape', function() {
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 10,
|
||||
opacity: 0.5
|
||||
opacity: 0.5,
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -648,7 +648,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('fill and stroke with shadow', function() {
|
||||
test('fill and stroke with shadow', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -665,8 +665,8 @@ suite('Shape', function() {
|
||||
shadowBlur: 10,
|
||||
shadowOffset: {
|
||||
x: 20,
|
||||
y: 20
|
||||
}
|
||||
y: 20,
|
||||
},
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -707,7 +707,7 @@ suite('Shape', function() {
|
||||
|
||||
// ======================================================
|
||||
// hard to emulate the same drawing
|
||||
test('fill and stroke with shadow and opacity', function() {
|
||||
test('fill and stroke with shadow and opacity', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -724,8 +724,8 @@ suite('Shape', function() {
|
||||
shadowBlur: 5,
|
||||
shadowOffset: {
|
||||
x: 20,
|
||||
y: 20
|
||||
}
|
||||
y: 20,
|
||||
},
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -783,7 +783,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('text with fill and stroke with shadow', function() {
|
||||
test('text with fill and stroke with shadow', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -800,8 +800,8 @@ suite('Shape', function() {
|
||||
shadowBlur: 2,
|
||||
shadowOffset: {
|
||||
x: 20,
|
||||
y: 20
|
||||
}
|
||||
y: 20,
|
||||
},
|
||||
});
|
||||
|
||||
layer.add(text);
|
||||
@@ -844,7 +844,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('shape intersect with shadow', function() {
|
||||
test('shape intersect with shadow', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -856,7 +856,7 @@ suite('Shape', function() {
|
||||
width: 200,
|
||||
height: 200,
|
||||
draggable: true,
|
||||
shadowColor: '#000' // if all shadow properties removed, works fine
|
||||
shadowColor: '#000', // if all shadow properties removed, works fine
|
||||
});
|
||||
layer.add(rect);
|
||||
stage.add(layer);
|
||||
@@ -867,7 +867,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('overloaded getters and setters', function() {
|
||||
test('overloaded getters and setters', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -880,7 +880,7 @@ suite('Shape', function() {
|
||||
fill: 'green',
|
||||
stroke: 'red',
|
||||
strokeWidth: 20,
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -912,13 +912,13 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('create image hit region', function(done) {
|
||||
test('create image hit region', function (done) {
|
||||
var imageObj = new Image();
|
||||
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
imageObj.onload = function() {
|
||||
imageObj.onload = function () {
|
||||
var lion = new Konva.Image({
|
||||
x: 200,
|
||||
y: 40,
|
||||
@@ -927,7 +927,7 @@ suite('Shape', function() {
|
||||
shadowColor: 'black',
|
||||
shadowBlur: 10,
|
||||
shadowOffsetX: 20,
|
||||
shadowOpacity: 0.2
|
||||
shadowOpacity: 0.2,
|
||||
});
|
||||
|
||||
// override color key with black
|
||||
@@ -955,7 +955,7 @@ suite('Shape', function() {
|
||||
layer.hitCanvas._canvas.style.border = '2px solid black';
|
||||
});
|
||||
|
||||
test('test defaults', function() {
|
||||
test('test defaults', function () {
|
||||
var shape = new Konva.Shape();
|
||||
|
||||
assert.equal(shape.strokeWidth(), 2);
|
||||
@@ -989,7 +989,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('hit graph when shape cached before adding to Layer', function() {
|
||||
test('hit graph when shape cached before adding to Layer', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
var rect = new Konva.Rect({
|
||||
@@ -997,13 +997,13 @@ suite('Shape', function() {
|
||||
y: 111,
|
||||
width: 50,
|
||||
height: 50,
|
||||
fill: 'black'
|
||||
fill: 'black',
|
||||
});
|
||||
rect.cache();
|
||||
|
||||
var click = false;
|
||||
|
||||
rect.on('click', function() {
|
||||
rect.on('click', function () {
|
||||
click = true;
|
||||
});
|
||||
|
||||
@@ -1016,12 +1016,12 @@ suite('Shape', function() {
|
||||
|
||||
stage.simulateMouseDown({
|
||||
x: 300,
|
||||
y: 120
|
||||
y: 120,
|
||||
});
|
||||
|
||||
stage.simulateMouseUp({
|
||||
x: 300,
|
||||
y: 120
|
||||
y: 120,
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
@@ -1031,14 +1031,14 @@ suite('Shape', function() {
|
||||
);
|
||||
});
|
||||
|
||||
test('class inherence', function() {
|
||||
test('class inherence', function () {
|
||||
var rect = new Konva.Rect();
|
||||
assert.equal(rect instanceof Konva.Rect, true);
|
||||
assert.equal(rect instanceof Konva.Shape, true);
|
||||
assert.equal(rect instanceof Konva.Node, true);
|
||||
});
|
||||
|
||||
test('disable stroke for hit', function() {
|
||||
test('disable stroke for hit', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -1050,7 +1050,7 @@ suite('Shape', function() {
|
||||
height: 50,
|
||||
stroke: 'red',
|
||||
strokeWidth: 20,
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
// default value
|
||||
assert.equal(rect.strokeHitEnabled(), true);
|
||||
@@ -1063,17 +1063,14 @@ suite('Shape', function() {
|
||||
|
||||
assert.equal(rect.getY(), 50);
|
||||
|
||||
var trace = layer
|
||||
.getHitCanvas()
|
||||
.getContext()
|
||||
.getTrace(true);
|
||||
var trace = layer.getHitCanvas().getContext().getTrace(true);
|
||||
assert.equal(
|
||||
trace,
|
||||
'clearRect();save();transform();beginPath();rect();closePath();save();fillStyle;fill();restore();restore();'
|
||||
);
|
||||
});
|
||||
|
||||
test('hitStrokeWidth', function() {
|
||||
test('hitStrokeWidth', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -1084,7 +1081,7 @@ suite('Shape', function() {
|
||||
width: 100,
|
||||
height: 100,
|
||||
stroke: 'red',
|
||||
strokeWidth: 2
|
||||
strokeWidth: 2,
|
||||
});
|
||||
// default value
|
||||
layer.add(rect);
|
||||
@@ -1123,7 +1120,7 @@ suite('Shape', function() {
|
||||
// );
|
||||
});
|
||||
|
||||
test('enable hitStrokeWidth even if we have no stroke on scene', function() {
|
||||
test('enable hitStrokeWidth even if we have no stroke on scene', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -1132,7 +1129,7 @@ suite('Shape', function() {
|
||||
x: 10,
|
||||
y: 10,
|
||||
width: 100,
|
||||
height: 100
|
||||
height: 100,
|
||||
});
|
||||
// default value
|
||||
layer.add(rect);
|
||||
@@ -1147,10 +1144,10 @@ suite('Shape', function() {
|
||||
assert.equal(stage.getIntersection({ x: 5, y: 5 }), rect);
|
||||
});
|
||||
|
||||
test('cache shadow color rgba', function() {
|
||||
test('cache shadow color rgba', function () {
|
||||
var circle = new Konva.Circle({
|
||||
fill: 'green',
|
||||
radius: 50
|
||||
radius: 50,
|
||||
});
|
||||
// no shadow on start
|
||||
assert.equal(circle.hasShadow(), false);
|
||||
@@ -1173,7 +1170,7 @@ suite('Shape', function() {
|
||||
assert.equal(circle.getShadowRGBA(), undefined);
|
||||
});
|
||||
|
||||
test('scale should also effect shadow offset', function() {
|
||||
test('scale should also effect shadow offset', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -1188,7 +1185,7 @@ suite('Shape', function() {
|
||||
fill: 'green',
|
||||
shadowColor: 'black',
|
||||
shadowBlur: 0,
|
||||
shadowOffset: { x: 10, y: 10 }
|
||||
shadowOffset: { x: 10, y: 10 },
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -1219,7 +1216,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// TODO: restore it!
|
||||
test.skip('scale should also effect shadow offset - negative scale', function() {
|
||||
test.skip('scale should also effect shadow offset - negative scale', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -1234,7 +1231,7 @@ suite('Shape', function() {
|
||||
fill: 'green',
|
||||
shadowColor: 'black',
|
||||
shadowBlur: 10,
|
||||
shadowOffset: { x: 10, y: 10 }
|
||||
shadowOffset: { x: 10, y: 10 },
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -1264,7 +1261,7 @@ suite('Shape', function() {
|
||||
// );
|
||||
});
|
||||
|
||||
test('scale of parent container should also effect shadow offset', function() {
|
||||
test('scale of parent container should also effect shadow offset', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -1272,7 +1269,7 @@ suite('Shape', function() {
|
||||
x: 100,
|
||||
y: 100,
|
||||
scaleX: 0.5,
|
||||
scaleY: 0.5
|
||||
scaleY: 0.5,
|
||||
});
|
||||
var rect = new Konva.Rect({
|
||||
width: 200,
|
||||
@@ -1282,7 +1279,7 @@ suite('Shape', function() {
|
||||
fill: 'green',
|
||||
shadowColor: 'black',
|
||||
shadowBlur: 0,
|
||||
shadowOffset: { x: 20, y: 20 }
|
||||
shadowOffset: { x: 20, y: 20 },
|
||||
});
|
||||
|
||||
group.add(rect);
|
||||
@@ -1313,7 +1310,7 @@ suite('Shape', function() {
|
||||
);
|
||||
});
|
||||
|
||||
test('optional disable buffer canvas', function() {
|
||||
test('optional disable buffer canvas', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -1327,7 +1324,7 @@ suite('Shape', function() {
|
||||
stroke: 'black',
|
||||
strokeWidth: 10,
|
||||
opacity: 0.5,
|
||||
perfectDrawEnabled: false
|
||||
perfectDrawEnabled: false,
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -1358,7 +1355,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('optional disable shadow for stroke', function() {
|
||||
test('optional disable shadow for stroke', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
@@ -1375,9 +1372,9 @@ suite('Shape', function() {
|
||||
shadowBlur: 10,
|
||||
shadowOffset: {
|
||||
x: 20,
|
||||
y: 20
|
||||
y: 20,
|
||||
},
|
||||
shadowForStrokeEnabled: false
|
||||
shadowForStrokeEnabled: false,
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -1408,19 +1405,19 @@ suite('Shape', function() {
|
||||
);
|
||||
});
|
||||
|
||||
test('clone custom shape', function() {
|
||||
test('clone custom shape', function () {
|
||||
var className = 'myCustomName';
|
||||
var CustomShape = function() {
|
||||
var CustomShape = function () {
|
||||
CustomShape.super.apply(this, arguments);
|
||||
this.className = className;
|
||||
};
|
||||
|
||||
CustomShape.prototype.foo = function() {};
|
||||
CustomShape.prototype.foo = function () {};
|
||||
|
||||
Konva.Util.extend(CustomShape, Konva.Shape);
|
||||
|
||||
var myShape = new CustomShape({
|
||||
fill: 'grey'
|
||||
fill: 'grey',
|
||||
});
|
||||
|
||||
var clone = myShape.clone();
|
||||
@@ -1431,7 +1428,7 @@ suite('Shape', function() {
|
||||
assert.equal(clone.foo, CustomShape.prototype.foo);
|
||||
});
|
||||
|
||||
test('getClientRect should skip disabled attributes', function() {
|
||||
test('getClientRect should skip disabled attributes', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
var shape = new Konva.Rect({
|
||||
@@ -1444,7 +1441,7 @@ suite('Shape', function() {
|
||||
strokeWidth: 4,
|
||||
strokeEnabled: false,
|
||||
shadowOffsetX: 10,
|
||||
shadowEnabled: false
|
||||
shadowEnabled: false,
|
||||
});
|
||||
|
||||
layer.add(shape);
|
||||
@@ -1456,7 +1453,7 @@ suite('Shape', function() {
|
||||
assert.equal(rect.height, 100, 'should not effect width');
|
||||
});
|
||||
|
||||
test('getClientRect for shape in transformed parent', function() {
|
||||
test('getClientRect for shape in transformed parent', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
@@ -1464,7 +1461,7 @@ suite('Shape', function() {
|
||||
var group = new Konva.Group({
|
||||
x: 110,
|
||||
y: 0,
|
||||
rotation: 90
|
||||
rotation: 90,
|
||||
});
|
||||
layer.add(group);
|
||||
|
||||
@@ -1473,7 +1470,7 @@ suite('Shape', function() {
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100,
|
||||
fill: 'green'
|
||||
fill: 'green',
|
||||
});
|
||||
group.add(shape);
|
||||
|
||||
@@ -1492,7 +1489,7 @@ suite('Shape', function() {
|
||||
assert.equal(absRect.height, 100);
|
||||
});
|
||||
|
||||
test('getClientRect with skew', function() {
|
||||
test('getClientRect with skew', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
@@ -1504,12 +1501,12 @@ suite('Shape', function() {
|
||||
height: 100,
|
||||
skewX: 0.5,
|
||||
scaleX: 2,
|
||||
fill: 'green'
|
||||
fill: 'green',
|
||||
});
|
||||
layer.add(shape);
|
||||
|
||||
var back = new Konva.Rect({
|
||||
stroke: 'red'
|
||||
stroke: 'red',
|
||||
});
|
||||
back.setAttrs(shape.getClientRect());
|
||||
layer.add(back);
|
||||
@@ -1523,7 +1520,7 @@ suite('Shape', function() {
|
||||
assert.equal(absRect.height, 100);
|
||||
});
|
||||
|
||||
test('decompose transform', function() {
|
||||
test('decompose transform', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
@@ -1536,7 +1533,7 @@ suite('Shape', function() {
|
||||
skewX: 0.5,
|
||||
scaleX: 2,
|
||||
scaleY: 2,
|
||||
fill: 'green'
|
||||
fill: 'green',
|
||||
});
|
||||
layer.add(shape);
|
||||
layer.draw();
|
||||
@@ -1553,7 +1550,7 @@ suite('Shape', function() {
|
||||
assert.equal(shape.getTransform().decompose().scaleY, 2);
|
||||
});
|
||||
|
||||
test('shadow should respect pixel ratio', function() {
|
||||
test('shadow should respect pixel ratio', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
layer.getCanvas().setPixelRatio(2);
|
||||
@@ -1564,7 +1561,7 @@ suite('Shape', function() {
|
||||
shadowColor: 'green',
|
||||
shadowOffsetX: 20,
|
||||
shadowOffsetY: 20,
|
||||
shadowBlur: 0
|
||||
shadowBlur: 0,
|
||||
});
|
||||
|
||||
layer.add(shape);
|
||||
@@ -1573,7 +1570,7 @@ suite('Shape', function() {
|
||||
assert.equal(data.data[3], 0, 'pixel should be empty, no shadow here');
|
||||
});
|
||||
|
||||
test('text shadow blur should take scale into account', function() {
|
||||
test('text shadow blur should take scale into account', function () {
|
||||
var stage = addStage();
|
||||
var layer1 = new Konva.Layer();
|
||||
stage.add(layer1);
|
||||
@@ -1589,7 +1586,7 @@ suite('Shape', function() {
|
||||
shadowColor: 'black',
|
||||
shadowOffsetX: 0,
|
||||
shadowOffsetY: 50,
|
||||
shadowBlur: 10
|
||||
shadowBlur: 10,
|
||||
});
|
||||
layer1.add(rect1);
|
||||
stage.add(layer1);
|
||||
@@ -1606,7 +1603,7 @@ suite('Shape', function() {
|
||||
shadowColor: 'black',
|
||||
shadowOffsetX: 0,
|
||||
shadowOffsetY: 25,
|
||||
shadowBlur: 5
|
||||
shadowBlur: 5,
|
||||
});
|
||||
layer2.add(rect2);
|
||||
stage.add(layer2);
|
||||
@@ -1615,11 +1612,11 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('sceneFunc and hitFunc should have shape as second argument', function() {
|
||||
test('sceneFunc and hitFunc should have shape as second argument', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
var shape = new Konva.Shape({
|
||||
sceneFunc: function(context, shape) {
|
||||
sceneFunc: function (context, shape) {
|
||||
assert.equal(this, shape);
|
||||
context.beginPath();
|
||||
context.moveTo(0, 0);
|
||||
@@ -1632,23 +1629,23 @@ suite('Shape', function() {
|
||||
y: 100,
|
||||
fill: 'green',
|
||||
stroke: 'blue',
|
||||
strokeWidth: 5
|
||||
strokeWidth: 5,
|
||||
});
|
||||
layer.add(shape);
|
||||
|
||||
var rect = new Konva.Rect({
|
||||
hitFunc: function(ctx, shape) {
|
||||
hitFunc: function (ctx, shape) {
|
||||
assert.equal(this, shape);
|
||||
}
|
||||
},
|
||||
});
|
||||
layer.add(rect);
|
||||
stage.add(layer);
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('cache fill pattern', function(done) {
|
||||
test('cache fill pattern', function (done) {
|
||||
var imageObj = new Image();
|
||||
imageObj.onload = function() {
|
||||
imageObj.onload = function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -1669,7 +1666,7 @@ suite('Shape', function() {
|
||||
|
||||
stroke: 'blue',
|
||||
strokeWidth: 5,
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
layer.add(star);
|
||||
@@ -1679,7 +1676,7 @@ suite('Shape', function() {
|
||||
var oldCreate = ctx.createPattern;
|
||||
|
||||
var callCount = 0;
|
||||
ctx.createPattern = function() {
|
||||
ctx.createPattern = function () {
|
||||
callCount += 1;
|
||||
return oldCreate.apply(this, arguments);
|
||||
};
|
||||
@@ -1692,9 +1689,9 @@ suite('Shape', function() {
|
||||
imageObj.src = 'assets/darth-vader.jpg';
|
||||
});
|
||||
|
||||
test('recache fill pattern on changes', function(done) {
|
||||
test('recache fill pattern on changes', function (done) {
|
||||
var imageObj = new Image();
|
||||
imageObj.onload = function() {
|
||||
imageObj.onload = function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -1715,7 +1712,7 @@ suite('Shape', function() {
|
||||
|
||||
stroke: 'blue',
|
||||
strokeWidth: 5,
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
layer.add(star);
|
||||
@@ -1741,7 +1738,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('cache linear gradient', function() {
|
||||
test('cache linear gradient', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -1758,7 +1755,7 @@ suite('Shape', function() {
|
||||
|
||||
stroke: 'blue',
|
||||
strokeWidth: 5,
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
layer.add(star);
|
||||
@@ -1768,7 +1765,7 @@ suite('Shape', function() {
|
||||
var oldCreate = ctx.createLinearGradient;
|
||||
|
||||
var callCount = 0;
|
||||
ctx.createLinearGradient = function() {
|
||||
ctx.createLinearGradient = function () {
|
||||
callCount += 1;
|
||||
return oldCreate.apply(this, arguments);
|
||||
};
|
||||
@@ -1778,7 +1775,7 @@ suite('Shape', function() {
|
||||
assert.equal(callCount, 0);
|
||||
});
|
||||
|
||||
test('recache linear gradient on changes', function() {
|
||||
test('recache linear gradient on changes', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -1795,7 +1792,7 @@ suite('Shape', function() {
|
||||
|
||||
stroke: 'blue',
|
||||
strokeWidth: 5,
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
layer.add(star);
|
||||
@@ -1837,7 +1834,7 @@ suite('Shape', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('cache radial gradient', function() {
|
||||
test('cache radial gradient', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -1856,7 +1853,7 @@ suite('Shape', function() {
|
||||
|
||||
stroke: 'blue',
|
||||
strokeWidth: 5,
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
layer.add(star);
|
||||
@@ -1866,7 +1863,7 @@ suite('Shape', function() {
|
||||
var oldCreate = ctx.createRadialGradient;
|
||||
|
||||
var callCount = 0;
|
||||
ctx.createRadialGradient = function() {
|
||||
ctx.createRadialGradient = function () {
|
||||
callCount += 1;
|
||||
return oldCreate.apply(this, arguments);
|
||||
};
|
||||
@@ -1876,7 +1873,7 @@ suite('Shape', function() {
|
||||
assert.equal(callCount, 0);
|
||||
});
|
||||
|
||||
test('recache linear gradient on changes', function() {
|
||||
test('recache linear gradient on changes', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -1895,7 +1892,7 @@ suite('Shape', function() {
|
||||
|
||||
stroke: 'blue',
|
||||
strokeWidth: 5,
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
layer.add(star);
|
||||
@@ -1948,7 +1945,7 @@ suite('Shape', function() {
|
||||
layer.draw();
|
||||
});
|
||||
|
||||
test('try to add destroyed shape', function() {
|
||||
test('try to add destroyed shape', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
@@ -1962,14 +1959,14 @@ suite('Shape', function() {
|
||||
|
||||
stroke: 'blue',
|
||||
strokeWidth: 5,
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
star.destroy();
|
||||
|
||||
var callCount = 0;
|
||||
var oldWarn = Konva.Util.warn;
|
||||
Konva.Util.warn = function() {
|
||||
Konva.Util.warn = function () {
|
||||
callCount += 1;
|
||||
};
|
||||
|
||||
@@ -1981,7 +1978,7 @@ suite('Shape', function() {
|
||||
Konva.Util.warn = oldWarn;
|
||||
});
|
||||
|
||||
test('hasFill getter', function() {
|
||||
test('hasFill getter', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
@@ -1989,33 +1986,33 @@ suite('Shape', function() {
|
||||
var shape = new Konva.Shape({
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
sceneFunc: function(context) {
|
||||
sceneFunc: function (context) {
|
||||
context.beginPath();
|
||||
context.moveTo(20, 50);
|
||||
context.quadraticCurveTo(550, 0, 500, 500);
|
||||
context.fillStrokeShape(shape);
|
||||
},
|
||||
fill: 'red',
|
||||
fillEnabled: false
|
||||
fillEnabled: false,
|
||||
});
|
||||
|
||||
layer.add(shape);
|
||||
assert.equal(shape.hasFill(), false);
|
||||
});
|
||||
|
||||
test('test hit of non filled shape', function() {
|
||||
test('test hit of non filled shape', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
|
||||
var line = new Konva.Shape({
|
||||
sceneFunc: function(context) {
|
||||
sceneFunc: function (context) {
|
||||
context.beginPath();
|
||||
context.moveTo(20, 50);
|
||||
context.quadraticCurveTo(550, 0, 500, 500);
|
||||
|
||||
context.fillStrokeShape(line);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
layer.add(line);
|
||||
|
Reference in New Issue
Block a user