UNPKG

@antv/g2plot

Version:

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

68 lines 2.2 kB
import { __assign } from "tslib"; import { Global, registerShape } from '@antv/g2'; import * as _ from '@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 = 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 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: __assign({ path: linkPath, stroke: '#d3d3d3', lineDash: [4, 2], lineWidth: 1 }, lineStyle), }); path.name = 'leader-line'; } } return interval; }, }); //# sourceMappingURL=waterfall.js.map