mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 12:06:18 +08:00
optional parent argument for getAbsolutePosition
This commit is contained in:
parent
dd52f0202a
commit
eda967c07e
@ -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]
|
||||
|
||||
|
8
konva.js
8
konva.js
@ -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
4
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -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",
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user