Rect.js 871 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var Path = require("../Path");
  2. var roundRectHelper = require("../helper/roundRect");
  3. /**
  4. * 矩形
  5. * @module zrender/graphic/shape/Rect
  6. */
  7. var _default = Path.extend({
  8. type: 'rect',
  9. shape: {
  10. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  11. // r缩写为1 相当于 [1, 1, 1, 1]
  12. // r缩写为[1] 相当于 [1, 1, 1, 1]
  13. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  14. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  15. r: 0,
  16. x: 0,
  17. y: 0,
  18. width: 0,
  19. height: 0
  20. },
  21. buildPath: function (ctx, shape) {
  22. var x = shape.x;
  23. var y = shape.y;
  24. var width = shape.width;
  25. var height = shape.height;
  26. if (!shape.r) {
  27. ctx.rect(x, y, width, height);
  28. } else {
  29. roundRectHelper.buildPath(ctx, shape);
  30. }
  31. ctx.closePath();
  32. return;
  33. }
  34. });
  35. module.exports = _default;