view.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.addViewAnimation = exports.getSiblingViews = exports.getViews = exports.findViewById = void 0;
  4. var util_1 = require("@antv/util");
  5. /**
  6. * 在 Chart 中查找特定 id 的子 View
  7. * @param chart
  8. * @param id
  9. */
  10. function findViewById(chart, id) {
  11. return chart.views.find(function (view) { return view.id === id; });
  12. }
  13. exports.findViewById = findViewById;
  14. /**
  15. * 获取同 view 同一级的所有 views
  16. * @param view 当前 view
  17. * @returns 同一级的 views
  18. * @ignore
  19. */
  20. function getViews(view) {
  21. var parent = view.parent;
  22. return parent ? parent.views : [];
  23. }
  24. exports.getViews = getViews;
  25. /**
  26. * 获取同 view 同一级的 views,不包括自身
  27. * @param view 当前 view
  28. * @returns 同一级的 views
  29. * @ignore
  30. */
  31. function getSiblingViews(view) {
  32. return getViews(view).filter(function (sub) { return sub !== view; });
  33. }
  34. exports.getSiblingViews = getSiblingViews;
  35. /**
  36. * 所有的 Geometries 都使用同一动画(各个图形如有区别,自行覆盖)并添加处理动画回调
  37. * @param view View
  38. * @param animation 动画配置
  39. */
  40. function addViewAnimation(view, animation, geometries) {
  41. if (geometries === void 0) { geometries = view.geometries; }
  42. // 同时设置整个 view 动画选项
  43. if (typeof animation === 'boolean') {
  44. view.animate(animation);
  45. }
  46. else {
  47. view.animate(true);
  48. }
  49. // 所有的 Geometry 都使用同一动画(各个图形如有区别,自行覆盖)
  50. (0, util_1.each)(geometries, function (g) {
  51. var animationCfg;
  52. if ((0, util_1.isFunction)(animation)) {
  53. animationCfg = animation(g.type || g.shapeType, g) || true;
  54. }
  55. else {
  56. animationCfg = animation;
  57. }
  58. g.animate(animationCfg);
  59. });
  60. }
  61. exports.addViewAnimation = addViewAnimation;
  62. //# sourceMappingURL=view.js.map