line.js 874 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { mix } from '../../util/common';
  2. import Abstract from './abstract';
  3. class Line extends Abstract {
  4. _initDefaultCfg() {
  5. super._initDefaultCfg();
  6. this.start = null;
  7. this.end = null;
  8. }
  9. getOffsetPoint(value) {
  10. var {
  11. start,
  12. end
  13. } = this;
  14. return {
  15. x: start.x + (end.x - start.x) * value,
  16. y: start.y + (end.y - start.y) * value
  17. };
  18. }
  19. getAxisVector() {
  20. var {
  21. start,
  22. end
  23. } = this;
  24. return [end.x - start.x, end.y - start.y];
  25. }
  26. drawLine(lineCfg) {
  27. var container = this.getContainer(lineCfg.top);
  28. var {
  29. start,
  30. end
  31. } = this;
  32. container.addShape('line', {
  33. className: 'axis-line',
  34. attrs: mix({
  35. x1: start.x,
  36. y1: start.y,
  37. x2: end.x,
  38. y2: end.y
  39. }, lineCfg)
  40. });
  41. }
  42. }
  43. Abstract.Line = Line;
  44. export default Line;