performance update

This commit is contained in:
Anton Lavrenov 2019-11-20 13:39:02 -05:00
parent 47870c9c68
commit ca1ccdaf82
4 changed files with 119 additions and 1358 deletions

1409
konva.js

File diff suppressed because it is too large Load Diff

View File

@ -40,16 +40,15 @@
"gulp-typescript": "^5.0.1", "gulp-typescript": "^5.0.1",
"gulp-uglify": "^3.0.2", "gulp-uglify": "^3.0.2",
"gulp-util": "^3.0.8", "gulp-util": "^3.0.8",
"mocha": "6.2.1", "mocha": "6.2.2",
"mocha-headless-chrome": "^2.0.3", "mocha-headless-chrome": "^2.0.3",
"parcel-bundler": "^1.12.3", "prettier": "^1.19.1",
"prettier": "^1.18.2", "rollup": "^1.27.0",
"rollup": "^1.23.0",
"rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-sourcemaps": "^0.4.2", "rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript2": "^0.24.3", "rollup-plugin-typescript2": "^0.25.2",
"typescript": "^3.6.3" "typescript": "^3.7.2"
}, },
"keywords": [ "keywords": [
"canvas", "canvas",

View File

@ -1675,22 +1675,44 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
} }
} }
_getAbsoluteTransform(top?: Node) { _getAbsoluteTransform(top?: Node) {
var at = new Transform();
var at;
// we we need position relative to an ancestor, we will iterate for all
if (top) {
at = new Transform();
// start with stage and traverse downwards to self // start with stage and traverse downwards to self
this._eachAncestorReverse(function(node) { this._eachAncestorReverse(function(node: Node) {
var transformsEnabled = node.getTransformsEnabled(); var transformsEnabled = node.transformsEnabled();
if (transformsEnabled === 'all') { if (transformsEnabled === 'all') {
at.multiply(node.getTransform()); at.multiply(node.getTransform());
} else if (transformsEnabled === 'position') { } else if (transformsEnabled === 'position') {
at.translate( at.translate(
node.getX() - node.getOffsetX(), node.x() - node.offsetX(),
node.getY() - node.getOffsetY() node.y() - node.offsetY()
); );
} }
}, top); }, top);
return at; return at;
} else {
// try to use a cached value
if (this.parent) {
// transform will be cached
at = this.parent.getAbsoluteTransform().copy();
} else {
at = new Transform();
}
var transformsEnabled = this.transformsEnabled();
if (transformsEnabled === 'all') {
at.multiply(this.getTransform());
} else if (transformsEnabled === 'position') {
at.translate(
this.x() - this.offsetX(),
this.y() - this.offsetY()
);
}
return at;
}
} }
/** /**
* get absolute scale of the node which takes into * get absolute scale of the node which takes into

View File

@ -28,7 +28,7 @@
var maxY = height - 10; var maxY = height - 10;
var minY = 0; var minY = 0;
var startBunnyCount = 10; var startBunnyCount = 1000;
var isAdding = false; var isAdding = false;
var count = 0; var count = 0;
var container; var container;
@ -98,8 +98,9 @@
bunnys.push(bunny); bunnys.push(bunny);
layer.add(bunny); layer.add(bunny);
layer.draw();
} }
layer.draw();
} }
function onTouchStart(event) { function onTouchStart(event) {