shape.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  2. var Util = require('../util/common');
  3. var Element = require('./element');
  4. var Shape =
  5. /*#__PURE__*/
  6. function (_Element) {
  7. _inheritsLoose(Shape, _Element);
  8. function Shape() {
  9. return _Element.apply(this, arguments) || this;
  10. }
  11. var _proto = Shape.prototype;
  12. _proto._initProperties = function _initProperties() {
  13. this._attrs = {
  14. zIndex: 0,
  15. visible: true,
  16. destroyed: false,
  17. isShape: true,
  18. attrs: {}
  19. };
  20. };
  21. _proto.getType = function getType() {
  22. return this._attrs.type;
  23. };
  24. _proto.drawInner = function drawInner(context) {
  25. var self = this;
  26. var attrs = self.get('attrs');
  27. self.createPath(context);
  28. var originOpacity = context.globalAlpha;
  29. if (self.hasFill()) {
  30. var fillOpacity = attrs.fillOpacity;
  31. if (!Util.isNil(fillOpacity) && fillOpacity !== 1) {
  32. context.globalAlpha = fillOpacity;
  33. context.fill();
  34. context.globalAlpha = originOpacity;
  35. } else {
  36. context.fill();
  37. }
  38. }
  39. if (self.hasStroke()) {
  40. var lineWidth = attrs.lineWidth;
  41. if (lineWidth > 0) {
  42. var strokeOpacity = attrs.strokeOpacity;
  43. if (!Util.isNil(strokeOpacity) && strokeOpacity !== 1) {
  44. context.globalAlpha = strokeOpacity;
  45. }
  46. context.stroke();
  47. }
  48. }
  49. };
  50. _proto.getBBox = function getBBox() {
  51. var bbox = this._attrs.bbox;
  52. if (!bbox) {
  53. bbox = this.calculateBox();
  54. if (bbox) {
  55. bbox.x = bbox.minX;
  56. bbox.y = bbox.minY;
  57. bbox.width = bbox.maxX - bbox.minX;
  58. bbox.height = bbox.maxY - bbox.minY;
  59. }
  60. this._attrs.bbox = bbox;
  61. }
  62. return bbox;
  63. };
  64. _proto.calculateBox = function calculateBox() {
  65. return null;
  66. };
  67. _proto.createPath = function createPath() {};
  68. return Shape;
  69. }(Element);
  70. module.exports = Shape;