base.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { __assign } from "tslib";
  2. import { Text } from '../../shapes';
  3. import { maybeAppend, select } from '../../util';
  4. export function getTitleShapeBBox(titleShape) {
  5. var box = { left: 0, top: 0, width: 0, height: 0 };
  6. if ((titleShape === null || titleShape === void 0 ? void 0 : titleShape.tagName) === 'html') {
  7. var _a = titleShape.style, width = _a.width, height = _a.height;
  8. box = { left: 0, top: 0, width: width, height: height };
  9. }
  10. else if (titleShape) {
  11. var _b = titleShape.getLocalBounds(), min = _b.min, halfExtents = _b.halfExtents;
  12. box = {
  13. left: min[0],
  14. top: min[1],
  15. width: halfExtents[0] * 2,
  16. height: halfExtents[1] * 2,
  17. };
  18. }
  19. return { left: 0, top: 0, right: box.width, bottom: box.height };
  20. }
  21. export function renderTitle(container, cfg) {
  22. if (!cfg) {
  23. var shape = container.querySelector('.legend-title');
  24. if (shape)
  25. shape.remove();
  26. return null;
  27. }
  28. var style = cfg.style;
  29. var className = "legend-title";
  30. return maybeAppend(container, ".".concat(className), function () { return new Text({ className: className, style: style }); })
  31. .call(function (selection) {
  32. selection.styles({
  33. fontSize: 12,
  34. textBaseline: 'top',
  35. text: cfg.content,
  36. });
  37. })
  38. .styles(style)
  39. .node();
  40. }
  41. export function renderGroup(container, className, x, y) {
  42. return maybeAppend(container, ".".concat(className), 'g').styles({ className: className, x: x, y: y }).node();
  43. }
  44. export function renderRect(container, className, width, height, style) {
  45. if (style === void 0) { style = {}; }
  46. return select(container)
  47. .maybeAppendByClassName(className, 'rect')
  48. .styles(__assign({ zIndex: -1, width: width, height: height }, style))
  49. .node();
  50. }
  51. //# sourceMappingURL=base.js.map