optional parent argument for getAbsolutePosition

This commit is contained in:
Anton Lavrenov 2015-12-23 09:18:36 +07:00
parent dd52f0202a
commit eda967c07e
6 changed files with 49 additions and 9 deletions

View File

@ -12,7 +12,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- event delegation. You can use it in this way: `layer.on('click', 'Circle', handler);`
### Changed
- `moveTo` and some other methods will return `this`
- `moveTo` and some other methods return `this`
- `getAbsolutePosition` support optional relative parent argument (useful to find absolute position inside of some of parent nodes)
## [0.10.0][2015-10-27]

View File

@ -3,7 +3,7 @@
* Konva JavaScript Framework v0.11.0
* http://konvajs.github.io/
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Tue Dec 22 2015
* Date: Wed Dec 23 2015
*
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
@ -3103,12 +3103,14 @@ var Konva = {};
},
/**
* get absolute position relative to the top left corner of the stage container div
* or relative to passed node
* @method
* @param {Object} [top] optional parent node
* @memberof Konva.Node.prototype
* @returns {Object}
*/
getAbsolutePosition: function() {
var absoluteMatrix = this.getAbsoluteTransform().getMatrix(),
getAbsolutePosition: function(top) {
var absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(),
absoluteTransform = new Konva.Transform(),
offset = this.offset();

4
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,8 @@
"version": "0.11.0",
"author": "Anton Lavrenov",
"scripts": {
"start": "gulp"
"start": "gulp",
"full-build": "gulp lint test build"
},
"devDependencies": {
"chai": "3.2.0",

View File

@ -855,12 +855,14 @@
},
/**
* get absolute position relative to the top left corner of the stage container div
* or relative to passed node
* @method
* @param {Object} [top] optional parent node
* @memberof Konva.Node.prototype
* @returns {Object}
*/
getAbsolutePosition: function() {
var absoluteMatrix = this.getAbsoluteTransform().getMatrix(),
getAbsolutePosition: function(top) {
var absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(),
absoluteTransform = new Konva.Transform(),
offset = this.offset();

View File

@ -1555,6 +1555,40 @@ suite('Node', function() {
assert.equal(Math.round(marker.getAbsolutePosition().y), Math.round(diagonal / 2), 'marker absolute position y should be about ' + Math.round(diagonal / 2) + ' but is about ' + Math.round(marker.getAbsolutePosition().y));
});
// ======================================================
test('test relative getAbsolutePosition for transformed parent ', function() {
var stage = addStage();
var layer = new Konva.Layer({
name: 'layerName',
id: 'layerId',
x: 100,
y: 100
});
var group = new Konva.Group({
name: 'groupName',
id: 'groupId',
x: 100,
y: 100
});
var rect = new Konva.Rect({
x: 50,
y: 60,
width: 50,
height: 50,
fill: 'red',
name: 'rectName',
id: 'rectId'
});
group.add(rect);
layer.add(group);
stage.add(layer);
assert.equal(rect.getAbsolutePosition(layer).x, 150);
assert.equal(rect.getAbsolutePosition(layer).y, 160);
});
// ======================================================
test('test dragDistance', function() {
var stage = addStage();