Skip to content

Commit

Permalink
fix cursor on anchors for rotated parent. fix#837
Browse files Browse the repository at this point in the history
  • Loading branch information
lavrton committed Jan 30, 2020
1 parent e112c14 commit 1c85a7e
Show file tree
Hide file tree
Showing 7 changed files with 1,407 additions and 53 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## Not released:

* Fix line with tension calculations
* Add `node.getAbsoluteRotation()` method

## 4.1.2 - 2020-01-08

Expand Down
1,398 changes: 1,350 additions & 48 deletions konva.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions konva.min.js

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import { Stage } from './Stage';
import { Context } from './Context';
import { Shape } from './Shape';
import { Layer } from './Layer';
import { BaseLayer } from './BaseLayer';

export const ids: any = {};
Expand Down Expand Up @@ -1756,6 +1755,26 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
y: scaleY
};
}
/**
* get absolute rotation of the node which takes into
* account its ancestor rotations
* @method
* @name Konva.Node#getAbsoluteRotation
* @returns {Number}
* @example
* // get absolute scale x
* var rotation = node.getAbsoluteRotation();
*/
getAbsoluteRotation() {
var parent: Node = this;
var rotation = 0;

while (parent) {
rotation += parent.rotation();
parent = parent.getParent();
}
return rotation;
}
/**
* get transform of the node
* @method
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/Transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class Transformer extends Group {

// add hover styling
anchor.on('mouseenter', () => {
var rad = Konva.getAngle(this.rotation());
var rad = Konva.getAngle(this.getAbsoluteRotation());

var scale = this.getNode().getAbsoluteScale();
// If scale.y < 0 xor scale.x < 0 we need to flip (not rotate).
Expand Down
2 changes: 1 addition & 1 deletion test/unit/shapes/Line-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ suite('Line', function() {
y: 0,
points: [75, 75, 100, 200, 300, 140],
tension: 0.5,
stroke: '#0f0',
stroke: '#0f0'
});
layer.add(line);

Expand Down
32 changes: 32 additions & 0 deletions test/unit/shapes/Transformer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,38 @@ suite('Transformer', function() {
assert.equal(stage.content.style.cursor, 'nwse-resize');
});

test('check correct cursor on rotated parent', function() {
var stage = addStage();
var layer = new Konva.Layer({
x: 100,
y: -50,
rotation: 90
});
stage.add(layer);

var rect = new Konva.Rect({
x: 50,
y: 0,
draggable: true,
width: 100,
height: 100,
fill: 'yellow'
});
layer.add(rect);

var tr = new Konva.Transformer({
node: rect
});
layer.add(tr);
layer.draw();

stage.simulateMouseMove({
x: 50,
y: 1
});
assert.equal(stage.content.style.cursor, 'ns-resize');
});

test('stopTransform method', function() {
var stage = addStage();
var layer = new Konva.Layer();
Expand Down

0 comments on commit 1c85a7e

Please sign in to comment.