var Util = require('../util/index'); var Shape = require('../core/shape'); var ArcMath = require('./math/arc'); var Fan = function Fan(cfg) { Fan.superclass.constructor.call(this, cfg); }; Fan.ATTRS = { x: 0, y: 0, rs: 0, re: 0, startAngle: 0, endAngle: 0, clockwise: false, lineWidth: 1 }; Util.extend(Fan, Shape); Util.augment(Fan, { canFill: true, canStroke: true, type: 'fan', getDefaultAttrs: function getDefaultAttrs() { return { clockwise: false, lineWidth: 1, rs: 0, re: 0 }; }, calculateBox: function calculateBox() { var self = this; var attrs = self._attrs; var cx = attrs.x; var cy = attrs.y; var rs = attrs.rs; var re = attrs.re; var startAngle = attrs.startAngle; var endAngle = attrs.endAngle; var clockwise = attrs.clockwise; var lineWidth = this.getHitLineWidth(); var boxs = ArcMath.box(cx, cy, rs, startAngle, endAngle, clockwise); var boxe = ArcMath.box(cx, cy, re, startAngle, endAngle, clockwise); var minX = Math.min(boxs.minX, boxe.minX); var minY = Math.min(boxs.minY, boxe.minY); var maxX = Math.max(boxs.maxX, boxe.maxX); var maxY = Math.max(boxs.maxY, boxe.maxY); var halfWidth = lineWidth / 2; return { minX: minX - halfWidth, minY: minY - halfWidth, maxX: maxX + halfWidth, maxY: maxY + halfWidth }; }, createPath: function createPath(context) { var attrs = this._attrs; var cx = attrs.x; var cy = attrs.y; var rs = attrs.rs; var re = attrs.re; var startAngle = attrs.startAngle; var endAngle = attrs.endAngle; var clockwise = attrs.clockwise; var ssp = { x: Math.cos(startAngle) * rs + cx, y: Math.sin(startAngle) * rs + cy }; var sep = { x: Math.cos(startAngle) * re + cx, y: Math.sin(startAngle) * re + cy }; var esp = { x: Math.cos(endAngle) * rs + cx, y: Math.sin(endAngle) * rs + cy }; context = context || self.get('context'); context.beginPath(); context.moveTo(ssp.x, ssp.y); context.lineTo(sep.x, sep.y); context.arc(cx, cy, re, startAngle, endAngle, clockwise); context.lineTo(esp.x, esp.y); context.arc(cx, cy, rs, endAngle, startAngle, !clockwise); context.closePath(); } }); module.exports = Fan;