adaptor.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.adaptor = void 0;
  4. var tslib_1 = require("tslib");
  5. var util_1 = require("@antv/util");
  6. var common_1 = require("../../adaptor/common");
  7. var constant_1 = require("../../constant");
  8. var utils_1 = require("../../utils");
  9. var utils_2 = require("../mix/utils");
  10. var utils_3 = require("./utils");
  11. function facetAdaptor(params) {
  12. var chart = params.chart, options = params.options;
  13. var facetType = options.type, data = options.data, fields = options.fields, eachView = options.eachView;
  14. var restFacetCfg = (0, util_1.omit)(options, [
  15. 'type',
  16. 'data',
  17. 'fields',
  18. 'eachView',
  19. 'axes',
  20. 'meta',
  21. 'tooltip',
  22. 'coordinate',
  23. 'theme',
  24. 'legend',
  25. 'interactions',
  26. 'annotations',
  27. ]);
  28. // 1. data
  29. chart.data(data);
  30. // 2. facet
  31. chart.facet(facetType, tslib_1.__assign(tslib_1.__assign({}, restFacetCfg), { fields: fields, eachView: function (viewOfG2, facet) {
  32. var viewOptions = eachView(viewOfG2, facet);
  33. if (viewOptions.geometries) {
  34. (0, utils_3.execViewAdaptor)(viewOfG2, viewOptions);
  35. }
  36. else {
  37. var plot = viewOptions;
  38. var plotOptions = plot.options;
  39. // @ts-ignore 仪表盘没 tooltip
  40. if (plotOptions.tooltip) {
  41. // 配置 tooltip 交互
  42. viewOfG2.interaction('tooltip');
  43. }
  44. (0, utils_2.execPlotAdaptor)(plot.type, viewOfG2, plotOptions);
  45. }
  46. } }));
  47. return params;
  48. }
  49. function component(params) {
  50. var chart = params.chart, options = params.options;
  51. var axes = options.axes, meta = options.meta, tooltip = options.tooltip, coordinate = options.coordinate, theme = options.theme, legend = options.legend, interactions = options.interactions, annotations = options.annotations;
  52. // 3. meta 配置
  53. var scales = {};
  54. if (axes) {
  55. (0, util_1.each)(axes, function (axis, field) {
  56. scales[field] = (0, utils_1.pick)(axis, constant_1.AXIS_META_CONFIG_KEYS);
  57. });
  58. }
  59. scales = (0, utils_1.deepAssign)({}, meta, scales);
  60. chart.scale(scales);
  61. // 4. coordinate 配置
  62. chart.coordinate(coordinate);
  63. // 5. axis 轴配置 (默认不展示)
  64. if (!axes) {
  65. chart.axis(false);
  66. }
  67. else {
  68. (0, util_1.each)(axes, function (axis, field) {
  69. chart.axis(field, axis);
  70. });
  71. }
  72. // 6. tooltip 配置
  73. if (tooltip) {
  74. chart.interaction('tooltip');
  75. chart.tooltip(tooltip);
  76. }
  77. else if (tooltip === false) {
  78. chart.removeInteraction('tooltip');
  79. }
  80. // 7. legend 配置(默认展示)
  81. chart.legend(legend);
  82. // theme 配置
  83. if (theme) {
  84. chart.theme(theme);
  85. }
  86. // 8. interactions
  87. (0, util_1.each)(interactions, function (interaction) {
  88. if (interaction.enable === false) {
  89. chart.removeInteraction(interaction.type);
  90. }
  91. else {
  92. chart.interaction(interaction.type, interaction.cfg);
  93. }
  94. });
  95. // 9. annotations
  96. (0, util_1.each)(annotations, function (annotation) {
  97. chart.annotation()[annotation.type](tslib_1.__assign({}, annotation));
  98. });
  99. return params;
  100. }
  101. /**
  102. * 分面图适配器
  103. * @param chart
  104. * @param options
  105. */
  106. function adaptor(params) {
  107. // flow 的方式处理所有的配置到 G2 API
  108. return (0, utils_1.flow)(common_1.theme, facetAdaptor, component)(params);
  109. }
  110. exports.adaptor = adaptor;
  111. //# sourceMappingURL=adaptor.js.map