line.js 791 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { mix } from '../../util/common';
  2. import GuideBase from './base';
  3. class Line extends GuideBase {
  4. _initDefaultCfg() {
  5. this.type = 'line';
  6. this.start = [];
  7. this.end = [];
  8. this.style = {
  9. stroke: '#000',
  10. lineWidth: 1
  11. };
  12. }
  13. render(coord, container) {
  14. var points = [];
  15. points[0] = this.parsePoint(coord, this.start);
  16. points[1] = this.parsePoint(coord, this.end);
  17. if (!points[0] || !points[1]) {
  18. return;
  19. }
  20. var shape = container.addShape('Line', {
  21. className: 'guide-line',
  22. attrs: mix({
  23. x1: points[0].x,
  24. y1: points[0].y,
  25. x2: points[1].x,
  26. y2: points[1].y
  27. }, this.style)
  28. });
  29. this.element = shape;
  30. return shape;
  31. }
  32. }
  33. GuideBase.Line = Line;
  34. export default Line;