mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
fix some docs, partial cache fixes
This commit is contained in:
@@ -134,7 +134,7 @@ export class Canvas {
|
||||
try {
|
||||
return this._canvas.toDataURL();
|
||||
} catch (err) {
|
||||
Util.warn('Unable to get data URL. ' + err.message);
|
||||
Util.error('Unable to get data URL. ' + err.message);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@@ -433,7 +433,7 @@ export abstract class Container extends Node {
|
||||
this._drawCachedHitCanvas(context);
|
||||
context.restore();
|
||||
} else {
|
||||
this._drawChildren(canvas, 'drawHit', top);
|
||||
this._drawChildren(canvas, 'drawHit', top, false, caching);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
@@ -470,11 +470,21 @@ export abstract class Container extends Node {
|
||||
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
}
|
||||
|
||||
var hasComposition =
|
||||
this.globalCompositeOperation() !== 'source-over' && !caching;
|
||||
if (hasComposition && layer) {
|
||||
context.save();
|
||||
context._applyGlobalCompositeOperation(this);
|
||||
}
|
||||
|
||||
this.children.each(function(child) {
|
||||
child[drawMethod](canvas, top, caching, skipBuffer);
|
||||
});
|
||||
if (hasComposition && layer) {
|
||||
context.restore();
|
||||
}
|
||||
|
||||
if (hasClip) {
|
||||
if (hasClip && layer) {
|
||||
context.restore();
|
||||
}
|
||||
}
|
||||
|
@@ -452,6 +452,12 @@ export class Context {
|
||||
});
|
||||
};
|
||||
}
|
||||
_applyGlobalCompositeOperation(node) {
|
||||
var globalCompositeOperation = node.getGlobalCompositeOperation();
|
||||
if (globalCompositeOperation !== 'source-over') {
|
||||
this.setAttr('globalCompositeOperation', globalCompositeOperation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CONTEXT_PROPERTIES.forEach(function(prop) {
|
||||
@@ -628,12 +634,6 @@ export class SceneContext extends Context {
|
||||
this.setAttr('shadowOffsetX', offset.x * scaleX);
|
||||
this.setAttr('shadowOffsetY', offset.y * scaleY);
|
||||
}
|
||||
_applyGlobalCompositeOperation(shape) {
|
||||
var globalCompositeOperation = shape.getGlobalCompositeOperation();
|
||||
if (globalCompositeOperation !== 'source-over') {
|
||||
this.setAttr('globalCompositeOperation', globalCompositeOperation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class HitContext extends Context {
|
||||
|
14
src/Layer.ts
14
src/Layer.ts
@@ -207,6 +207,20 @@ export class Layer extends BaseLayer {
|
||||
this.hitGraphEnabled(false);
|
||||
return this;
|
||||
}
|
||||
|
||||
// document it:
|
||||
toggleHitCanvas() {
|
||||
if (!this.parent) {
|
||||
return;
|
||||
}
|
||||
var parent = this.parent as any;
|
||||
var added = !!this.hitCanvas._canvas.parentNode;
|
||||
if (added) {
|
||||
parent.content.removeChild(this.hitCanvas._canvas);
|
||||
} else {
|
||||
parent.content.appendChild(this.hitCanvas._canvas);
|
||||
}
|
||||
}
|
||||
setSize({ width, height }) {
|
||||
super.setSize({ width, height });
|
||||
this.hitCanvas.setSize(width, height);
|
||||
|
@@ -203,7 +203,7 @@ export abstract class Node {
|
||||
clearCache() {
|
||||
delete this._cache.canvas;
|
||||
this._filterUpToDate = false;
|
||||
this._clearSelfAndDescendantCache();
|
||||
this._clearSelfAndDescendantCache(undefined);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
@@ -306,7 +306,7 @@ export abstract class Node {
|
||||
|
||||
cachedHitCanvas.isCache = true;
|
||||
|
||||
this.clearCache();
|
||||
// this.clearCache();
|
||||
|
||||
sceneContext.save();
|
||||
hitContext.save();
|
||||
@@ -448,6 +448,7 @@ export abstract class Node {
|
||||
var cachedCanvas = this._cache.canvas,
|
||||
hitCanvas = cachedCanvas.hit;
|
||||
context.save();
|
||||
context._applyGlobalCompositeOperation(this);
|
||||
context.translate(this._cache.canvas.x, this._cache.canvas.y);
|
||||
context.drawImage(hitCanvas._canvas, 0, 0);
|
||||
context.restore();
|
||||
|
@@ -855,7 +855,8 @@ Factory.addGetterSetter(Shape, 'lineCap');
|
||||
Factory.addGetterSetter(Shape, 'sceneFunc');
|
||||
|
||||
/**
|
||||
* get/set scene draw function
|
||||
* get/set scene draw function. That function is used to draw the shape on a canvas.
|
||||
* Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.
|
||||
* @name Konva.Shape#sceneFunc
|
||||
* @method
|
||||
* @param {Function} drawFunc drawing function
|
||||
@@ -870,6 +871,7 @@ Factory.addGetterSetter(Shape, 'sceneFunc');
|
||||
* context.rect(0, 0, shape.width(), shape.height());
|
||||
* context.closePath();
|
||||
* // important Konva method that fill and stroke shape from its properties
|
||||
* // like stroke and fill
|
||||
* context.fillStrokeShape(shape);
|
||||
* });
|
||||
*/
|
||||
@@ -877,7 +879,7 @@ Factory.addGetterSetter(Shape, 'sceneFunc');
|
||||
Factory.addGetterSetter(Shape, 'hitFunc');
|
||||
|
||||
/**
|
||||
* get/set hit draw function
|
||||
* get/set hit draw function. That function is used to draw custom hit area of a shape.
|
||||
* @name Konva.Shape#hitFunc
|
||||
* @method
|
||||
* @param {Function} drawFunc drawing function
|
||||
|
@@ -773,8 +773,6 @@ export class Stage extends Container {
|
||||
Stage.prototype.nodeType = STAGE;
|
||||
|
||||
// TODO: test for replacing container
|
||||
Factory.addGetterSetter(Stage, 'container');
|
||||
|
||||
/**
|
||||
* get/set container DOM element
|
||||
* @method
|
||||
@@ -788,3 +786,6 @@ Factory.addGetterSetter(Stage, 'container');
|
||||
* body.appendChild(container);
|
||||
* stage.container(container);
|
||||
*/
|
||||
Factory.addGetterSetter(Stage, 'container');
|
||||
|
||||
|
||||
|
@@ -8,6 +8,7 @@ import { GetSet, Vector2d } from '../types';
|
||||
/**
|
||||
* Ellipse constructor
|
||||
* @constructor
|
||||
* @memberof Konva
|
||||
* @augments Konva.Shape
|
||||
* @param {Object} config
|
||||
* @param {Object} config.radius defines x and y radius
|
||||
|
@@ -8,6 +8,7 @@ var PIx2 = Math.PI * 2;
|
||||
* Ring constructor
|
||||
* @constructor
|
||||
* @augments Konva.Shape
|
||||
* @memberof Konva
|
||||
* @param {Object} config
|
||||
* @param {Number} config.innerRadius
|
||||
* @param {Number} config.outerRadius
|
||||
|
@@ -292,7 +292,7 @@ export class Text extends Shape {
|
||||
* That method can't handle multiline text.
|
||||
* @method
|
||||
* @name Konva.Text#measureSize
|
||||
* @param {Number} [text] text to measure
|
||||
* @param {String} [text] text to measure
|
||||
* @returns {Object} { width , height} of measured text
|
||||
*/
|
||||
measureSize(text) {
|
||||
|
@@ -9,6 +9,7 @@ import { GetSet } from '../types';
|
||||
/**
|
||||
* Wedge constructor
|
||||
* @constructor
|
||||
* @memberof Konva
|
||||
* @augments Konva.Shape
|
||||
* @param {Object} config
|
||||
* @param {Number} config.angle in degrees
|
||||
|
Reference in New Issue
Block a user