docs and types

This commit is contained in:
Anton Lavrenov
2021-01-26 11:43:52 -05:00
parent 76476a5d77
commit febf3251eb
6 changed files with 76 additions and 2 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -31,6 +31,7 @@ export interface TextConfig extends ShapeConfig {
verticalAlign?: string;
padding?: number;
lineHeight?: number;
letterSpacing?: number;
wrap?: string;
ellipsis?: boolean;
}

View File

@@ -29,6 +29,7 @@ export interface TransformerConfig extends ContainerConfig {
anchorStroke?: string;
anchorStrokeWidth?: number;
anchorSize?: number;
anchorCornerRadius?: number;
keepRatio?: boolean;
centeredScaling?: boolean;
enabledAnchors?: Array<string>;

View File

@@ -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);
});
});