ZRender
View on GitHub
Home
Example
Demo
Animation
Chart
Color Series
Artist
slice
API & Doc
Download
ZIP (2.0.7)
ZIP (Latest)
Link
Ecom-FE
Data Visualization
ECharts
code
/* * zr has been init like this, just use it! * * var zrender = require('zrender'); * var zr = zrender.init(document.getElementById('main')); */ zr.clear(); var Base = require('zrender/shape/Base'); function Cross(options) { Base.call(this, options); } Cross.prototype = { type : 'cross', brush : function(ctx, isHighlight) { var style = this.style || {}; if (isHighlight) { // 根据style扩展默认高亮样式 style = this.highlightStyle || {}; for (var k in this.style) { style[k] = this.style[k]; } } ctx.save(); ctx.beginPath(); ctx.strokeStyle = style.strokeColor || style.color; ctx.moveTo(style.x - style.width / 2, style.y); ctx.lineTo(style.x + style.width / 2, style.y); ctx.moveTo(style.x, style.y - style.height / 2); ctx.lineTo(style.x, style.y + style.height / 2); ctx.closePath(); ctx.stroke(); ctx.restore(); return; }, drift : function(dx, dy) { this.style.x += dx; this.style.y += dy; }, isCover : function(x, y) { var originPos = this.getTansform(x, y); x = originPos[0]; y = originPos[1]; if (x >= (this.style.x - this.style.width / 2) && x <= (this.style.x + this.style.width / 2) && y >= this.style.y - this.style.height / 2 && y <= (this.style.y + this.style.height / 2) ) { return true; } return false; } } require('zrender/tool/util').inherits(Cross, Base); zr.addShape(new Cross({ style : { x : 100, y : 100, width : 50, height : 50, color : 'red' }, draggable : true })); function Audi(options) { this.brushTypeOnly = 'stroke'; Base.call(this, options); } Audi.prototype = { type : 'auid', buildPath : function(ctx, style) { var x = style.x; var y = style.y; var r = style.r; for (var i = 0; i < 4; i++) { ctx.arc(x, y, r, 0, Math.PI * 2, true); ctx.moveTo(x + 5 * r / 2, y); x += r * 3 / 2; } return; }, /** * 返回矩形区域,用于局部刷新和文字定位 * @param {Object} style */ getRect : function(style) { return { x : Math.round(style.x - style.r), y : Math.round(style.y - style.r), width : style.r * 6.5, height : style.r * 2 }; } } require('zrender/tool/util').inherits(Audi, Base); zr.addShape(new Audi({ style : { x : 200, y : 100, r : 50, color : '#1e90ff', lineWidth : 1, text : 'Audi' }, draggable : true })); zr.render();
Refresh ~