Sector.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var Path = require("../Path");
  2. var fixClipWithShadow = require("../helper/fixClipWithShadow");
  3. /**
  4. * 扇形
  5. * @module zrender/graphic/shape/Sector
  6. */
  7. var _default = Path.extend({
  8. type: 'sector',
  9. shape: {
  10. cx: 0,
  11. cy: 0,
  12. r0: 0,
  13. r: 0,
  14. startAngle: 0,
  15. endAngle: Math.PI * 2,
  16. clockwise: true
  17. },
  18. brush: fixClipWithShadow(Path.prototype.brush),
  19. buildPath: function (ctx, shape) {
  20. var x = shape.cx;
  21. var y = shape.cy;
  22. var r0 = Math.max(shape.r0 || 0, 0);
  23. var r = Math.max(shape.r, 0);
  24. var startAngle = shape.startAngle;
  25. var endAngle = shape.endAngle;
  26. var clockwise = shape.clockwise;
  27. var unitX = Math.cos(startAngle);
  28. var unitY = Math.sin(startAngle);
  29. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  30. ctx.lineTo(unitX * r + x, unitY * r + y);
  31. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  32. ctx.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
  33. if (r0 !== 0) {
  34. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  35. }
  36. ctx.closePath();
  37. }
  38. });
  39. module.exports = _default;