line.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 Abstract = require('./abstract');
  10. var Line = /*#__PURE__*/function (_Abstract) {
  11. (0, _inheritsLoose2["default"])(Line, _Abstract);
  12. var _super = _createSuper(Line);
  13. function Line() {
  14. return _Abstract.apply(this, arguments) || this;
  15. }
  16. var _proto = Line.prototype;
  17. _proto._initDefaultCfg = function _initDefaultCfg() {
  18. _Abstract.prototype._initDefaultCfg.call(this);
  19. this.start = null;
  20. this.end = null;
  21. };
  22. _proto.getOffsetPoint = function getOffsetPoint(value) {
  23. var start = this.start,
  24. end = this.end;
  25. return {
  26. x: start.x + (end.x - start.x) * value,
  27. y: start.y + (end.y - start.y) * value
  28. };
  29. };
  30. _proto.getAxisVector = function getAxisVector() {
  31. var start = this.start,
  32. end = this.end;
  33. return [end.x - start.x, end.y - start.y];
  34. };
  35. _proto.drawLine = function drawLine(lineCfg) {
  36. var container = this.getContainer(lineCfg.top);
  37. var start = this.start,
  38. end = this.end;
  39. container.addShape('line', {
  40. className: 'axis-line',
  41. attrs: Util.mix({
  42. x1: start.x,
  43. y1: start.y,
  44. x2: end.x,
  45. y2: end.y
  46. }, lineCfg)
  47. });
  48. };
  49. return Line;
  50. }(Abstract);
  51. Abstract.Line = Line;
  52. module.exports = Line;