brush.js 1.9 KB

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