helper.js 1.1 KB

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