helper.js 943 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { Shape } from '../graphic/index';
  2. function getClip(coord) {
  3. var start = coord.start;
  4. var end = coord.end;
  5. var width = end.x - start.x;
  6. var height = Math.abs(end.y - start.y);
  7. var margin = 10;
  8. var clip;
  9. if (coord.isPolar) {
  10. var {
  11. circleRadius,
  12. center,
  13. startAngle,
  14. endAngle
  15. } = coord;
  16. clip = new Shape.Sector({
  17. attrs: {
  18. x: center.x,
  19. y: center.y,
  20. r: circleRadius,
  21. r0: 0,
  22. startAngle,
  23. endAngle
  24. }
  25. });
  26. } else {
  27. clip = new Shape.Rect({
  28. attrs: {
  29. x: start.x,
  30. y: end.y - margin,
  31. width,
  32. height: height + 2 * margin
  33. }
  34. });
  35. }
  36. clip.isClip = true;
  37. return clip;
  38. }
  39. function isPointInPlot(point, plot) {
  40. var {
  41. x,
  42. y
  43. } = point;
  44. var {
  45. tl,
  46. tr,
  47. br
  48. } = plot;
  49. return x >= tl.x && x <= tr.x && y >= tl.y && y <= br.y;
  50. }
  51. export { getClip, isPointInPlot };