brush.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.brushInteraction = void 0;
  4. var util_1 = require("@antv/util");
  5. /** 先引入brush 交互 */
  6. require("../interactions/brush");
  7. var brush_1 = require("../interactions/brush");
  8. var utils_1 = require("../utils");
  9. var BRUSH_TYPES = ['brush', 'brush-x', 'brush-y', 'brush-highlight', 'brush-x-highlight', 'brush-y-highlight'];
  10. /**
  11. * brush 交互
  12. */
  13. function brushInteraction(params) {
  14. var options = params.options;
  15. var brush = options.brush;
  16. // 先过滤掉 brush 等交互
  17. var interactions = (0, util_1.filter)(options.interactions || [], function (i) { return BRUSH_TYPES.indexOf(i.type) === -1; });
  18. // 设置 brush 交互
  19. if (brush === null || brush === void 0 ? void 0 : brush.enabled) {
  20. BRUSH_TYPES.forEach(function (type) {
  21. var enable = false;
  22. switch (brush.type) {
  23. case 'x-rect':
  24. enable = type === (brush.action === 'highlight' ? 'brush-x-highlight' : 'brush-x');
  25. break;
  26. case 'y-rect':
  27. enable = type === (brush.action === 'highlight' ? 'brush-y-highlight' : 'brush-y');
  28. break;
  29. default:
  30. enable = type === (brush.action === 'highlight' ? 'brush-highlight' : 'brush');
  31. break;
  32. }
  33. var obj = { type: type, enable: enable };
  34. if (brush) {
  35. obj.cfg = (0, brush_1.getInteractionCfg)(type, brush.type, brush);
  36. }
  37. interactions.push(obj);
  38. });
  39. // 塞入 button 配置 (G2Plot 的封装)
  40. if ((brush === null || brush === void 0 ? void 0 : brush.action) !== 'highlight') {
  41. interactions.push({
  42. type: 'filter-action',
  43. cfg: {
  44. buttonConfig: brush.button,
  45. },
  46. });
  47. }
  48. }
  49. return (0, utils_1.deepAssign)({}, params, { options: { interactions: interactions } });
  50. }
  51. exports.brushInteraction = brushInteraction;
  52. //# sourceMappingURL=brush.js.map