UNPKG

@antv/g2plot

Version:

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

70 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var g2_1 = require("@antv/g2"); var _ = tslib_1.__importStar(require("@antv/util")); function getRectPath(points) { var path = []; for (var i = 0; i < points.length; i++) { var point = points[i]; if (point) { var action = i === 0 ? 'M' : 'L'; path.push([action, point.x, point.y]); } } var first = points[0]; path.push(['L', first.x, first.y]); path.push(['Z']); return path; } var ShapeUtil = { addFillAttrs: function (attrs, cfg) { if (cfg.color) { attrs.fill = cfg.color; } if (_.isNumber(cfg.opacity)) { attrs.opacity = attrs.fillOpacity = cfg.opacity; } }, }; function getFillAttrs(cfg) { var defaultAttrs = g2_1.Global.theme.shape.interval; var attrs = _.mix({}, defaultAttrs, cfg.style); ShapeUtil.addFillAttrs(attrs, cfg); if (cfg.color) { attrs.stroke = attrs.stroke || cfg.color; } return attrs; } // @ts-ignore g2_1.registerShape('interval', 'waterfall', { draw: function (cfg, container) { var fillAttrs = getFillAttrs(cfg); var rectPath = getRectPath(cfg.points); rectPath = this.parsePath(rectPath); // 1. 区域 var interval = container.addShape('path', { attrs: _.mix(fillAttrs, { path: rectPath, }), }); var leaderLine = _.get(cfg.style, 'leaderLine'); if (leaderLine && leaderLine.visible) { var lineStyle = leaderLine.style || {}; // 2. 虚线连线 if (cfg.nextPoints) { var linkPath = [ ['M', cfg.points[2].x, cfg.points[2].y], ['L', cfg.nextPoints[0].x, cfg.nextPoints[0].y], ]; linkPath = this.parsePath(linkPath); var path = container.addShape('path', { attrs: tslib_1.__assign({ path: linkPath, stroke: '#d3d3d3', lineDash: [4, 2], lineWidth: 1 }, lineStyle), }); path.name = 'leader-line'; } } return interval; }, }); //# sourceMappingURL=waterfall.js.map