UNPKG

@antv/g2plot

Version:

G2 Plot, a market of plots built with the Grammar of Graphics'

52 lines 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var g2_1 = require("@antv/g2"); var clone_1 = tslib_1.__importDefault(require("@antv/util/lib/clone")); var each_1 = tslib_1.__importDefault(require("@antv/util/lib/each")); // import verticalShatter from '../../../../util/layout/verticalShatter'; var MARGIN = 10; var LineElementLabels = /** @class */ (function (_super) { tslib_1.__extends(LineElementLabels, _super); function LineElementLabels() { return _super !== null && _super.apply(this, arguments) || this; } LineElementLabels.prototype.showLabels = function (points, shapes) { var _this = this; var labelPoints = []; each_1.default(shapes, function (shape) { var originData = shape.get('origin'); var lastPoint = clone_1.default(originData[originData.length - 1]); var bbox = shape.getBBox(); lastPoint.x = bbox.maxX + MARGIN; labelPoints.push(lastPoint); }); _super.prototype.showLabels.call(this, labelPoints, shapes); var renderer = this.get('labelsRenderer'); var field = this.get('labelOptions').fields[0]; var labels = renderer.get('group').get('children'); var view = this.get('element').get('view'); each_1.default(labels, function (label) { label.attr('textAlign', 'left'); label.attr('textBaseline', 'middle'); var origin = label.get('origin'); var shapeId = _this.get('element').getShapeId(origin); var color = _this._adjustColor(shapeId, shapes); label.attr('fill', color); }); view.get('canvas').draw(); }; LineElementLabels.prototype._adjustColor = function (shapeId, shapes) { var color; each_1.default(shapes, function (shape) { var id = shape.id; if (id === shapeId) { color = shape.attr('stroke'); } }); return color; }; return LineElementLabels; }(g2_1.ElementLabels)); g2_1.registerElementLabels('line', LineElementLabels); //# sourceMappingURL=line-label.js.map