pie.js 877 B

12345678910111213141516171819202122232425
  1. define(function(require, exports, module){
  2. var Path = require('graphic/path');
  3. var Point = require('graphic/point');
  4. return require('core/class').createClass({
  5. base: Path,
  6. constructor: function(r, R, a1, a2) {
  7. this.callBase();
  8. this.draw(r, R, a1, a2);
  9. this.center = Point.fromPolar( (R + r) / 2, (a1 + a2) / 2 );
  10. },
  11. draw: function(r, R, a1, a2) {
  12. var d = this.getDrawer();
  13. var p1 = Point.fromPolar(r, a1),
  14. p2 = Point.fromPolar(R, a1),
  15. p3 = Point.fromPolar(R, a2),
  16. p4 = Point.fromPolar(r, a2);
  17. d.moveTo(p1.x, p1.y);
  18. d.lineTo(p2.x, p2.y);
  19. d.carcTo(R, 0, 1, p3.x, p3.y);
  20. d.lineTo(p4.x, p4.y);
  21. d.carcTo(r, 0, 0, p1.x, p1.y);
  22. d.close();
  23. }
  24. });
  25. });