mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
Add new method getClientRect()
. rethink caching.
This commit is contained in:
@@ -26,4 +26,92 @@ suite('Arc', function() {
|
||||
assert.equal(trace, 'clearRect(0,0,578,200);save();transform(1,0,0,1,100,100);beginPath();arc(0,0,80,0,1.571,false);arc(0,0,50,1.571,0,true);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();');
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('attrs sync', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
var arc = new Konva.Arc({
|
||||
x: 100,
|
||||
y: 100,
|
||||
innerRadius: 50,
|
||||
outerRadius: 80,
|
||||
angle: 90,
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
name: 'myArc',
|
||||
draggable: true
|
||||
});
|
||||
|
||||
layer.add(arc);
|
||||
stage.add(layer);
|
||||
assert.equal(arc.getWidth(), 160);
|
||||
assert.equal(arc.getHeight(), 160);
|
||||
|
||||
arc.setWidth(100);
|
||||
assert.equal(arc.outerRadius(), 50);
|
||||
assert.equal(arc.getHeight(), 100);
|
||||
|
||||
arc.setHeight(120);
|
||||
assert.equal(arc.outerRadius(), 60);
|
||||
assert.equal(arc.getHeight(), 120);
|
||||
});
|
||||
|
||||
test('getSelfRect', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
var arc = new Konva.Arc({
|
||||
x: 100,
|
||||
y: 100,
|
||||
innerRadius: 50,
|
||||
outerRadius: 80,
|
||||
angle: 90,
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
name: 'myArc',
|
||||
draggable: true
|
||||
});
|
||||
|
||||
layer.add(arc);
|
||||
stage.add(layer);
|
||||
|
||||
assert.deepEqual(arc.getSelfRect(), {
|
||||
x : -80,
|
||||
y : -80,
|
||||
width : 160,
|
||||
height : 160
|
||||
});
|
||||
});
|
||||
|
||||
test('cache', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
var arc = new Konva.Arc({
|
||||
x: 100,
|
||||
y: 100,
|
||||
innerRadius: 50,
|
||||
outerRadius: 80,
|
||||
angle: 90,
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
});
|
||||
|
||||
layer.add(arc);
|
||||
stage.add(layer);
|
||||
|
||||
var canvas = createCanvas();
|
||||
var context = canvas.getContext('2d');
|
||||
context.beginPath();
|
||||
context.arc(100, 100, 80, 0, Math.PI / 2, false);
|
||||
context.arc(100, 100, 50, Math.PI / 2, 0, true);
|
||||
context.closePath();
|
||||
context.fillStyle = 'green';
|
||||
context.fill();
|
||||
context.lineWidth = 4;
|
||||
context.stroke();
|
||||
compareLayerAndCanvas(layer, canvas, 10);
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user