mirror of
https://github.com/konvajs/konva.git
synced 2025-09-22 20:14:01 +08:00
docs and types
This commit is contained in:
19
konva.js
19
konva.js
@@ -731,7 +731,9 @@
|
||||
},
|
||||
_sign: function (number) {
|
||||
if (number === 0) {
|
||||
return 0;
|
||||
// that is not what sign usually returns
|
||||
// but that is what we need
|
||||
return 1;
|
||||
}
|
||||
if (number > 0) {
|
||||
return 1;
|
||||
@@ -3504,6 +3506,21 @@
|
||||
y: this.y(),
|
||||
};
|
||||
};
|
||||
/**
|
||||
* get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor
|
||||
* @method
|
||||
* @name Konva.Node#getAbsolutePosition
|
||||
* @param {Object} Ancestor optional ancestor node
|
||||
* @returns {Konva.Node}
|
||||
* @example
|
||||
*
|
||||
* // returns absolute position relative to top-left corner of canvas
|
||||
* node.getAbsolutePosition();
|
||||
*
|
||||
* // calculate absolute position of node, inside stage
|
||||
* // so stage transforms are ignored
|
||||
* node.getAbsolutePosition(stage)
|
||||
*/
|
||||
Node.prototype.getAbsolutePosition = function (top) {
|
||||
var haveCachedParent = false;
|
||||
var parent = this.parent;
|
||||
|
15
src/Node.ts
15
src/Node.ts
@@ -1183,6 +1183,21 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
y: this.y(),
|
||||
};
|
||||
}
|
||||
/**
|
||||
* get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor
|
||||
* @method
|
||||
* @name Konva.Node#getAbsolutePosition
|
||||
* @param {Object} Ancestor optional ancestor node
|
||||
* @returns {Konva.Node}
|
||||
* @example
|
||||
*
|
||||
* // returns absolute position relative to top-left corner of canvas
|
||||
* node.getAbsolutePosition();
|
||||
*
|
||||
* // calculate absolute position of node, inside stage
|
||||
* // so stage transforms are ignored
|
||||
* node.getAbsolutePosition(stage)
|
||||
*/
|
||||
getAbsolutePosition(top?) {
|
||||
let haveCachedParent = false;
|
||||
let parent = this.parent;
|
||||
|
@@ -599,7 +599,9 @@ export const Util = {
|
||||
},
|
||||
_sign(number: number) {
|
||||
if (number === 0) {
|
||||
return 0;
|
||||
// that is not what sign usually returns
|
||||
// but that is what we need
|
||||
return 1;
|
||||
}
|
||||
if (number > 0) {
|
||||
return 1;
|
||||
|
@@ -31,6 +31,7 @@ export interface TextConfig extends ShapeConfig {
|
||||
verticalAlign?: string;
|
||||
padding?: number;
|
||||
lineHeight?: number;
|
||||
letterSpacing?: number;
|
||||
wrap?: string;
|
||||
ellipsis?: boolean;
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ export interface TransformerConfig extends ContainerConfig {
|
||||
anchorStroke?: string;
|
||||
anchorStrokeWidth?: number;
|
||||
anchorSize?: number;
|
||||
anchorCornerRadius?: number;
|
||||
keepRatio?: boolean;
|
||||
centeredScaling?: boolean;
|
||||
enabledAnchors?: Array<string>;
|
||||
|
@@ -4496,4 +4496,42 @@ suite('Transformer', function () {
|
||||
layer.add(tr);
|
||||
layer.draw();
|
||||
});
|
||||
|
||||
// we don't support height = 0
|
||||
test.skip('try to tranform zero size shape', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
|
||||
var shape = new Konva.Line({
|
||||
x: stage.getWidth() / 4,
|
||||
y: stage.getHeight() / 4,
|
||||
points: [0, 0, 200, 0],
|
||||
fill: 'black',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
draggable: true,
|
||||
});
|
||||
layer.add(shape);
|
||||
|
||||
var tr = new Konva.Transformer({
|
||||
nodes: [shape],
|
||||
enabledAnchors: ['middle-left', 'middle-right'],
|
||||
ignoreStroke: true,
|
||||
});
|
||||
layer.add(tr);
|
||||
|
||||
layer.draw();
|
||||
|
||||
tr.simulateMouseDown({
|
||||
x: stage.width() / 2,
|
||||
y: stage.height() / 2,
|
||||
});
|
||||
tr.simulateMouseDown({
|
||||
x: stage.width() / 2 + 100,
|
||||
y: stage.height() / 2,
|
||||
});
|
||||
tr.simulateMouseUp();
|
||||
assert.equal(shape.scaleX(), 0.5);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user