rect.js 818 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { mix } from '../../util/common';
  2. import GuideBase from './base';
  3. class Rect extends GuideBase {
  4. _initDefaultCfg() {
  5. this.type = 'rect';
  6. this.start = [];
  7. this.end = [];
  8. this.style = {
  9. fill: '#CCD7EB',
  10. opacity: 0.4
  11. };
  12. }
  13. render(coord, container) {
  14. var start = this.parsePoint(coord, this.start);
  15. var end = this.parsePoint(coord, this.end);
  16. if (!start || !end) {
  17. return;
  18. }
  19. var shape = container.addShape('rect', {
  20. className: 'guide-rect',
  21. attrs: mix({
  22. x: Math.min(start.x, end.x),
  23. y: Math.min(start.y, end.y),
  24. width: Math.abs(end.x - start.x),
  25. height: Math.abs(start.y - end.y)
  26. }, this.style)
  27. });
  28. this.element = shape;
  29. return shape;
  30. }
  31. }
  32. GuideBase.Rect = Rect;
  33. export default Rect;