line.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Util = require('../../util/common');
  9. var GuideBase = require('./base');
  10. var Line = /*#__PURE__*/function (_GuideBase) {
  11. (0, _inheritsLoose2["default"])(Line, _GuideBase);
  12. var _super = _createSuper(Line);
  13. function Line() {
  14. return _GuideBase.apply(this, arguments) || this;
  15. }
  16. var _proto = Line.prototype;
  17. _proto._initDefaultCfg = function _initDefaultCfg() {
  18. this.type = 'line';
  19. this.start = [];
  20. this.end = [];
  21. this.style = {
  22. stroke: '#000',
  23. lineWidth: 1
  24. };
  25. };
  26. _proto.render = function render(coord, container) {
  27. var points = [];
  28. points[0] = this.parsePoint(coord, this.start);
  29. points[1] = this.parsePoint(coord, this.end);
  30. if (!points[0] || !points[1]) {
  31. return;
  32. }
  33. var shape = container.addShape('Line', {
  34. className: 'guide-line',
  35. attrs: Util.mix({
  36. x1: points[0].x,
  37. y1: points[0].y,
  38. x2: points[1].x,
  39. y2: points[1].y
  40. }, this.style)
  41. });
  42. this.element = shape;
  43. return shape;
  44. };
  45. return Line;
  46. }(GuideBase);
  47. GuideBase.Line = Line;
  48. module.exports = Line;