utils.js 2.6 KB

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