fabric.js/benchmarks/raphael_vs_fabric/complex_shape_2.html

105 lines
No EOL
3 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Complex shape 2</title>
<style>
svg {
border: 1px solid #000;
}
.canvas_container {
border: 1px solid #000;
position: relative;
}
#holder {
height: 760px;
width: 380px;
left: 500px;
position: absolute;
}
</style>
<script src="raphael-min.js"></script>
<script src="../../dist/all.js"></script>
<script src="dragon.js"></script>
<script>
window.onload = function() {
var width = 380,
height = 760;
var logEl = document.getElementById('log');
(function testFabric() {
var canvas = window.__canvas = new fabric.Element('canvas', {
renderOnAddition: false,
stateful: false
});
//console.profile('parsing');
fabric.loadSVGFromURL('dragon.svg', function(objects) {
//console.profileEnd('parsing');
var startTime = new Date();
var group = new fabric.PathGroup(objects, {
left: 185,
top: 380,
width: 371,
height: 760
});
canvas.add(group);
canvas.renderAll();
var renderingTime = new Date() - startTime;
logEl.innerHTML += 'fabric: <b>' + (fabric.documentParsingTime + renderingTime) +
'</b>ms (parsing: ' + fabric.documentParsingTime + ', rendering: ' + renderingTime + ')';
document.getElementById('description').appendChild(document.createTextNode(' (' + group.complexity() + ' paths)'))
});
canvas.calcOffset();
})();
(function testRaphael() {
var start = function () {
// storing original coordinates
this.ox = this.attr("cx");
this.oy = this.attr("cy");
this.attr({opacity: .5});
},
move = function (dx, dy) {
// move will be called with dx and dy
this.attr({cx: this.ox + dx, cy: this.oy + dy});
},
up = function () {
// restoring state
this.attr({opacity: 1});
};
var startTime = new Date();
var r = Raphael("holder", width, height);
r.dragon();
// r.drag(start, move, up);
logEl.innerHTML = 'Raphael: <b>' + (new Date() - startTime) + '</b>ms<br>';
})();
};
</script>
</head>
<body>
<!-- preload svg -->
<iframe src="dragon.svg" style="position:absolute;top:-999px;left:-999px"></iframe>
<p id="description">Rendering a complex shape</p>
<div id="holder"></div>
<canvas id="canvas" width="380" height="760"></canvas>
<p id="log"></p>
</body>
</html>