mirror of
https://github.com/konvajs/konva.git
synced 2026-01-08 18:54:40 +08:00
fix some docs and tests
This commit is contained in:
@@ -21,27 +21,29 @@ export const Factory = {
|
||||
return val === undefined ? def : val;
|
||||
};
|
||||
},
|
||||
|
||||
addSetter(constructor, attr, validator?, after?) {
|
||||
// if (!validator && validator !== null) {
|
||||
// console.error(constructor, attr, 'has no validator.');
|
||||
// }
|
||||
var method = SET + Util._capitalize(attr);
|
||||
|
||||
constructor.prototype[method] =
|
||||
constructor.prototype[method] ||
|
||||
function(val) {
|
||||
if (validator && val !== undefined && val !== null) {
|
||||
val = validator.call(this, val, attr);
|
||||
}
|
||||
if (!constructor.prototype[method]) {
|
||||
Factory.overWriteSetter(constructor, attr, validator, after);
|
||||
}
|
||||
},
|
||||
overWriteSetter(constructor, attr, validator?, after?) {
|
||||
var method = SET + Util._capitalize(attr);
|
||||
constructor.prototype[method] = function(val) {
|
||||
if (validator && val !== undefined && val !== null) {
|
||||
val = validator.call(this, val, attr);
|
||||
}
|
||||
|
||||
this._setAttr(attr, val);
|
||||
this._setAttr(attr, val);
|
||||
|
||||
if (after) {
|
||||
after.call(this);
|
||||
}
|
||||
if (after) {
|
||||
after.call(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
return this;
|
||||
};
|
||||
},
|
||||
addComponentsGetterSetter(constructor, attr, components, validator?, after?) {
|
||||
var len = components.length,
|
||||
|
||||
11
src/Layer.ts
11
src/Layer.ts
@@ -61,9 +61,9 @@ export class Layer extends BaseLayer {
|
||||
/**
|
||||
* get visible intersection shape. This is the preferred
|
||||
* method for determining if a point intersects a shape or not
|
||||
* also you may pass optional selector parametr to return ancestor of intersected shape
|
||||
* also you may pass optional selector parameter to return ancestor of intersected shape
|
||||
* @method
|
||||
* @memberof Konva.Layer.prototype
|
||||
* @name Konva.Layer#getIntersection
|
||||
* @param {Object} pos
|
||||
* @param {Number} pos.x
|
||||
* @param {Number} pos.y
|
||||
@@ -200,7 +200,6 @@ export class Layer extends BaseLayer {
|
||||
* disable hit graph
|
||||
* @name Konva.Layer#disableHitGraph
|
||||
* @method
|
||||
* @memberof Konva.Layer.prototype
|
||||
* @returns {Layer}
|
||||
*/
|
||||
disableHitGraph() {
|
||||
@@ -208,7 +207,11 @@ export class Layer extends BaseLayer {
|
||||
return this;
|
||||
}
|
||||
|
||||
// document it:
|
||||
/**
|
||||
* Show or hide hit canvas over the stage. May be useful for debugging custom hitFunc
|
||||
* @name Konva.Layer#toggleHitCanvas
|
||||
* @method
|
||||
*/
|
||||
toggleHitCanvas() {
|
||||
if (!this.parent) {
|
||||
return;
|
||||
|
||||
@@ -533,7 +533,6 @@ export class Shape extends Node {
|
||||
cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
||||
|
||||
if (!this.colorKey) {
|
||||
console.log(this);
|
||||
Util.warn(
|
||||
'Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. See the shape in logs above. If you want to reuse shape you should call remove() instead of destroy()'
|
||||
);
|
||||
|
||||
@@ -804,7 +804,6 @@ export class Stage extends Container {
|
||||
|
||||
Stage.prototype.nodeType = STAGE;
|
||||
|
||||
// TODO: test for replacing container
|
||||
/**
|
||||
* get/set container DOM element
|
||||
* @method
|
||||
|
||||
37
src/Tween.ts
37
src/Tween.ts
@@ -394,44 +394,41 @@ export class Tween {
|
||||
}
|
||||
}
|
||||
_addListeners() {
|
||||
var that = this;
|
||||
|
||||
// start listeners
|
||||
this.tween.onPlay = function() {
|
||||
that.anim.start();
|
||||
this.tween.onPlay = () => {
|
||||
this.anim.start();
|
||||
};
|
||||
this.tween.onReverse = function() {
|
||||
that.anim.start();
|
||||
this.tween.onReverse = () => {
|
||||
this.anim.start();
|
||||
};
|
||||
|
||||
// stop listeners
|
||||
this.tween.onPause = function() {
|
||||
that.anim.stop();
|
||||
this.tween.onPause = () => {
|
||||
this.anim.stop();
|
||||
};
|
||||
this.tween.onFinish = function() {
|
||||
// TODO: remove that any
|
||||
var node = that.node as any;
|
||||
this.tween.onFinish = () => {
|
||||
var node = this.node as Node;
|
||||
|
||||
// after tweening points of line we need to set original end
|
||||
var attrs = Tween.attrs[node._id][that._id];
|
||||
var attrs = Tween.attrs[node._id][this._id];
|
||||
if (attrs.points && attrs.points.trueEnd) {
|
||||
node.points(attrs.points.trueEnd);
|
||||
node.setAttr('points', attrs.points.trueEnd);
|
||||
}
|
||||
|
||||
if (that.onFinish) {
|
||||
that.onFinish.call(that);
|
||||
if (this.onFinish) {
|
||||
this.onFinish.call(this);
|
||||
}
|
||||
};
|
||||
this.tween.onReset = function() {
|
||||
var node = that.node as any;
|
||||
this.tween.onReset = () => {
|
||||
var node = this.node as any;
|
||||
// after tweening points of line we need to set original start
|
||||
var attrs = Tween.attrs[node._id][that._id];
|
||||
var attrs = Tween.attrs[node._id][this._id];
|
||||
if (attrs.points && attrs.points.trueStart) {
|
||||
node.points(attrs.points.trueStart);
|
||||
}
|
||||
|
||||
if (that.onReset) {
|
||||
that.onReset();
|
||||
if (this.onReset) {
|
||||
this.onReset();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ Collection.prototype = [] as any;
|
||||
* @param {Function} func
|
||||
* @example
|
||||
* // get all nodes with name foo inside layer, and set x to 10 for each
|
||||
* layer.get('.foo').each(function(shape, n) {
|
||||
* layer.find('.foo').each(function(shape, n) {
|
||||
* shape.setX(10);
|
||||
* });
|
||||
*/
|
||||
@@ -806,6 +806,9 @@ export const Util = {
|
||||
console.error(KONVA_ERROR + str);
|
||||
},
|
||||
warn(str) {
|
||||
if (!getGlobalKonva().showWarnings) {
|
||||
return;
|
||||
}
|
||||
console.warn(KONVA_WARNING + str);
|
||||
},
|
||||
extend(child, parent) {
|
||||
|
||||
@@ -343,7 +343,7 @@ Factory.addGetterSetter(
|
||||
/**
|
||||
* get/set pointer height
|
||||
* @method
|
||||
* @memberof Konva.Tag.prototype
|
||||
* @name Konva.Tag#pointerHeight
|
||||
* @param {Number} pointerHeight
|
||||
* @returns {Number}
|
||||
* @example
|
||||
|
||||
@@ -20,7 +20,8 @@ import { GetSet } from '../types';
|
||||
* y: 40,
|
||||
* data: 'M12.582,9.551C3.251,16.237,0.921,29.021,7.08,38.564l-2.36,1.689l4.893,2.262l4.893,2.262l-0.568-5.36l-0.567-5.359l-2.365,1.694c-4.657-7.375-2.83-17.185,4.352-22.33c7.451-5.338,17.817-3.625,23.156,3.824c5.337,7.449,3.625,17.813-3.821,23.152l2.857,3.988c9.617-6.893,11.827-20.277,4.935-29.896C35.591,4.87,22.204,2.658,12.582,9.551z',
|
||||
* fill: 'green',
|
||||
* scale: 2
|
||||
* scaleX: 2,
|
||||
* scaleY: 2
|
||||
* });
|
||||
*/
|
||||
export class Path extends Shape {
|
||||
|
||||
@@ -524,12 +524,7 @@ Text.prototype._attrsAffectingSize = [
|
||||
* text.width('auto');
|
||||
* text.width() // will return calculated width, and not "auto"
|
||||
*/
|
||||
Factory.addGetterSetter(
|
||||
Text,
|
||||
'width',
|
||||
undefined,
|
||||
Validators.getNumberOrAutoValidator()
|
||||
);
|
||||
Factory.overWriteSetter(Text, 'width', Validators.getNumberOrAutoValidator());
|
||||
|
||||
/**
|
||||
* get/set the height of the text area, which takes into account multi-line text, line heights, and padding.
|
||||
@@ -549,12 +544,7 @@ Factory.addGetterSetter(
|
||||
* text.height() // will return calculated height, and not "auto"
|
||||
*/
|
||||
|
||||
Factory.addGetterSetter(
|
||||
Text,
|
||||
'height',
|
||||
undefined,
|
||||
Validators.getNumberOrAutoValidator()
|
||||
);
|
||||
Factory.overWriteSetter(Text, 'height', Validators.getNumberOrAutoValidator());
|
||||
|
||||
/**
|
||||
* get/set font family
|
||||
|
||||
@@ -175,12 +175,10 @@ export class TextPath extends Shape {
|
||||
getTextWidth() {
|
||||
return this.textWidth;
|
||||
}
|
||||
/**
|
||||
* get text line height in pixels
|
||||
* @method
|
||||
* @name Konva.TextPath#getTextHeight
|
||||
*/
|
||||
getTextHeight() {
|
||||
Util.warn(
|
||||
'text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.'
|
||||
);
|
||||
return this.textHeight;
|
||||
}
|
||||
setText(text) {
|
||||
|
||||
Reference in New Issue
Block a user