index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { isInOffscreenGroup } from '../../../util';
  2. import ellipsis from './autoEllipsis';
  3. import hide from './autoHide';
  4. import rotate from './autoRotate';
  5. import wrap from './autoWrap';
  6. export var OverlapUtils = new Map([
  7. ['hide', hide],
  8. ['rotate', rotate],
  9. ['ellipsis', ellipsis],
  10. ['wrap', wrap],
  11. ]);
  12. export function canProcessOverlap(labels, attr, type) {
  13. if (attr.labelOverlap.length < 1)
  14. return false;
  15. if (type === 'hide')
  16. return !isInOffscreenGroup(labels[0]);
  17. if (type === 'rotate')
  18. return !labels.some(function (label) { var _a; return !!((_a = label.attr('transform')) === null || _a === void 0 ? void 0 : _a.includes('rotate')); });
  19. if (type === 'ellipsis' || type === 'wrap')
  20. return labels.filter(function (item) { return item.querySelector('text'); }).length > 1;
  21. return true;
  22. }
  23. export function processOverlap(labels, attr, utils) {
  24. var _a = attr.labelOverlap, labelOverlap = _a === void 0 ? [] : _a;
  25. if (!labelOverlap.length)
  26. return;
  27. labelOverlap.forEach(function (overlapCfg) {
  28. var type = overlapCfg.type;
  29. var util = OverlapUtils.get(type);
  30. if (canProcessOverlap(labels, attr, type))
  31. util === null || util === void 0 ? void 0 : util(labels, overlapCfg, attr, utils);
  32. });
  33. }
  34. //# sourceMappingURL=index.js.map