line.js 1.4 KB

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