polygon.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
  4. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
  5. var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
  6. function _createSuper(Derived) { return function () { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
  7. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  8. var Shape = require('../shape');
  9. var bbox = require('../util/bbox');
  10. var Polygon = /*#__PURE__*/function (_Shape) {
  11. (0, _inheritsLoose2["default"])(Polygon, _Shape);
  12. var _super = _createSuper(Polygon);
  13. function Polygon() {
  14. return _Shape.apply(this, arguments) || this;
  15. }
  16. var _proto = Polygon.prototype;
  17. _proto._initProperties = function _initProperties() {
  18. _Shape.prototype._initProperties.call(this);
  19. this._attrs.canFill = true;
  20. this._attrs.canStroke = true;
  21. this._attrs.type = 'polygon';
  22. };
  23. _proto.getDefaultAttrs = function getDefaultAttrs() {
  24. return {
  25. points: null,
  26. lineWidth: 0
  27. };
  28. };
  29. _proto.createPath = function createPath(context) {
  30. var self = this;
  31. var attrs = self.get('attrs');
  32. var points = attrs.points;
  33. context.beginPath();
  34. for (var i = 0, len = points.length; i < len; i++) {
  35. var point = points[i];
  36. if (i === 0) {
  37. context.moveTo(point.x, point.y);
  38. } else {
  39. context.lineTo(point.x, point.y);
  40. }
  41. }
  42. context.closePath();
  43. };
  44. _proto.calculateBox = function calculateBox() {
  45. var attrs = this.get('attrs');
  46. var points = attrs.points;
  47. return bbox.getBBoxFromPoints(points);
  48. };
  49. return Polygon;
  50. }(Shape);
  51. Shape.Polygon = Polygon;
  52. module.exports = Polygon;