utils.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { __assign } from "tslib";
  2. import { each } from '@antv/util';
  3. import { geometry as geometryAdaptor } from '../../adaptor/geometries/base';
  4. import { AXIS_META_CONFIG_KEYS } from '../../constant';
  5. import { addViewAnimation, deepAssign, pick } from '../../utils';
  6. /**
  7. *
  8. * @param params 分面图 参数
  9. * @returns facet eachView 的回调设置每个 view 的展示
  10. */
  11. export function execViewAdaptor(viewOfG2, options) {
  12. var data = options.data, coordinate = options.coordinate, interactions = options.interactions, annotations = options.annotations, animation = options.animation, tooltip = options.tooltip, axes = options.axes, meta = options.meta, geometries = options.geometries;
  13. // 1. data, optional
  14. if (data) {
  15. viewOfG2.data(data);
  16. }
  17. // 2. meta 配置
  18. var scales = {};
  19. if (axes) {
  20. each(axes, function (axis, field) {
  21. scales[field] = pick(axis, AXIS_META_CONFIG_KEYS);
  22. });
  23. }
  24. scales = deepAssign({}, meta, scales);
  25. viewOfG2.scale(scales);
  26. // 3. coordinate 配置 (默认由顶层决定)
  27. if (coordinate) {
  28. viewOfG2.coordinate(coordinate);
  29. }
  30. // 4. axis 轴配置 (默认由顶层决定,但可以通过 false 强制关闭)
  31. if (axes === false) {
  32. viewOfG2.axis(false);
  33. }
  34. else {
  35. each(axes, function (axis, field) {
  36. viewOfG2.axis(field, axis);
  37. });
  38. }
  39. each(geometries, function (geometry) {
  40. // Geometry
  41. var ext = geometryAdaptor({
  42. chart: viewOfG2,
  43. options: geometry,
  44. }).ext;
  45. // Geometry adjust
  46. var adjust = geometry.adjust;
  47. if (adjust) {
  48. ext.geometry.adjust(adjust);
  49. }
  50. });
  51. // 5. interactions
  52. each(interactions, function (interaction) {
  53. if (interaction.enable === false) {
  54. viewOfG2.removeInteraction(interaction.type);
  55. }
  56. else {
  57. viewOfG2.interaction(interaction.type, interaction.cfg);
  58. }
  59. });
  60. // 6. annotations
  61. each(annotations, function (annotation) {
  62. viewOfG2.annotation()[annotation.type](__assign({}, annotation));
  63. });
  64. // 7. animation (先做动画)
  65. addViewAnimation(viewOfG2, animation);
  66. if (tooltip) {
  67. // 8. tooltip
  68. viewOfG2.interaction('tooltip');
  69. viewOfG2.tooltip(tooltip);
  70. }
  71. else if (tooltip === false) {
  72. viewOfG2.removeInteraction('tooltip');
  73. }
  74. }
  75. //# sourceMappingURL=utils.js.map