graphic.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { __assign } from "tslib";
  2. import { get } from '@antv/util';
  3. import { ellipsisLabel } from './label';
  4. import { applyRotate, applyTranslate } from './matrix';
  5. import { formatPadding } from './util';
  6. export function renderTag(container, tagCfg) {
  7. var x = tagCfg.x, y = tagCfg.y, content = tagCfg.content, style = tagCfg.style, id = tagCfg.id, name = tagCfg.name, rotate = tagCfg.rotate, maxLength = tagCfg.maxLength, autoEllipsis = tagCfg.autoEllipsis, isVertical = tagCfg.isVertical, ellipsisPosition = tagCfg.ellipsisPosition, background = tagCfg.background;
  8. var tagGroup = container.addGroup({
  9. id: id + "-group",
  10. name: name + "-group",
  11. attrs: {
  12. x: x,
  13. y: y,
  14. }
  15. });
  16. // Text shape
  17. var text = tagGroup.addShape({
  18. type: 'text',
  19. id: id,
  20. name: name,
  21. attrs: __assign({ x: 0, y: 0, text: content }, style),
  22. });
  23. // maxLength 应包含 background 中的 padding 值
  24. var padding = formatPadding(get(background, 'padding', 0));
  25. if (maxLength && autoEllipsis) {
  26. var maxTextLength = maxLength - (padding[1] + padding[3]);
  27. // 超出自动省略
  28. ellipsisLabel(!isVertical, text, maxTextLength, ellipsisPosition);
  29. }
  30. if (background) {
  31. // 渲染文本背景
  32. var backgroundStyle = get(background, 'style', {});
  33. var _a = text.getCanvasBBox(), minX = _a.minX, minY = _a.minY, width = _a.width, height = _a.height;
  34. var tagBg = tagGroup.addShape('rect', {
  35. id: id + "-bg",
  36. name: id + "-bg",
  37. attrs: __assign({ x: minX - padding[3], y: minY - padding[0], width: width + padding[1] + padding[3], height: height + padding[0] + padding[2] }, backgroundStyle),
  38. });
  39. tagBg.toBack();
  40. }
  41. applyTranslate(tagGroup, x, y);
  42. applyRotate(tagGroup, rotate, x, y);
  43. }
  44. //# sourceMappingURL=graphic.js.map