| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.renderTitle = void 0;
- var tslib_1 = require("tslib");
- var animation_1 = require("../../../animation");
- var util_1 = require("../../../util");
- var title_1 = require("../../title");
- var constant_1 = require("../constant");
- function getTitlePosition(mainGroup, titleGroup, attr) {
- var _a = attr.titlePosition, position = _a === void 0 ? 'lb' : _a, spacing = attr.titleSpacing;
- var pos = (0, title_1.parsePosition)(position);
- var _b = mainGroup.node().getLocalBounds(), _c = tslib_1.__read(_b.min, 2), mainX = _c[0], mainY = _c[1], _d = tslib_1.__read(_b.halfExtents, 2), mainHalfWidth = _d[0], mainHalfHeight = _d[1];
- var _e = tslib_1.__read(titleGroup.node().getLocalBounds().halfExtents, 2), titleHalfWidth = _e[0], titleHalfHeight = _e[1];
- var _f = tslib_1.__read([mainX + mainHalfWidth, mainY + mainHalfHeight], 2), x = _f[0], y = _f[1];
- var _g = tslib_1.__read((0, util_1.parseSeriesAttr)(spacing), 4), spacingTop = _g[0], spacingRight = _g[1], spacingBottom = _g[2], spacingLeft = _g[3];
- if (['start', 'end'].includes(position) && attr.type === 'linear') {
- var startPos = attr.startPos, endPos = attr.endPos;
- // todo did not consider the truncate case
- var _h = tslib_1.__read(position === 'start' ? [startPos, endPos] : [endPos, startPos], 2), from = _h[0], to = _h[1];
- var direction = (0, util_1.normalize)([-to[0] + from[0], -to[1] + from[1]]);
- var _j = tslib_1.__read((0, util_1.scale)(direction, spacingTop), 2), dx = _j[0], dy = _j[1];
- return { x: from[0] + dx, y: from[1] + dy };
- }
- if (pos.includes('t'))
- y -= mainHalfHeight + titleHalfHeight + spacingTop;
- if (pos.includes('r'))
- x += mainHalfWidth + titleHalfWidth + spacingRight;
- if (pos.includes('l'))
- x -= mainHalfWidth + titleHalfWidth + spacingLeft;
- if (pos.includes('b'))
- y += mainHalfHeight + titleHalfHeight + spacingBottom;
- return { x: x, y: y };
- }
- function applyTitleStyle(title, group, axis, attr, animate) {
- var style = (0, util_1.subStyleProps)(attr, 'title');
- var _a = tslib_1.__read((0, util_1.splitStyle)(style), 2), titleStyle = _a[0], _b = _a[1], _c = _b.transform, transform = _c === void 0 ? '' : _c, groupStyle = tslib_1.__rest(_b, ["transform"]);
- title.styles(titleStyle);
- group.styles(groupStyle);
- // the transform of g has some limitation, so we need to apply the transform to the title twice
- (0, util_1.percentTransform)(title.node(), transform);
- var _d = getTitlePosition(
- // @ts-ignore
- (0, util_1.select)(axis._offscreen || axis.querySelector(constant_1.CLASS_NAMES.mainGroup.class)), group, attr), x = _d.x, y = _d.y;
- var animation = (0, animation_1.transition)(group.node(), { x: x, y: y }, animate);
- (0, util_1.percentTransform)(title.node(), transform);
- return animation;
- }
- function renderTitle(container, axis, attr, animate) {
- var titleText = attr.titleText;
- return container
- .selectAll(constant_1.CLASS_NAMES.title.class)
- .data([{ title: titleText }].filter(function (d) { return !!d.title; }), function (d, i) { return d.title; })
- .join(function (enter) {
- return enter
- .append(function () { return (0, util_1.renderExtDo)(titleText); })
- .attr('className', constant_1.CLASS_NAMES.title.name)
- .transition(function () {
- return applyTitleStyle((0, util_1.select)(this), container, axis, attr, animate.enter);
- });
- }, function (update) {
- return update.transition(function () {
- return applyTitleStyle((0, util_1.select)(this), container, axis, attr, animate.update);
- });
- }, function (exit) { return exit.remove(); })
- .transitions();
- }
- exports.renderTitle = renderTitle;
- //# sourceMappingURL=title.js.map
|