base.js 2.2 KB

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