shape.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var g2_1 = require("@antv/g2");
  5. var util_1 = require("@antv/util");
  6. var utils_1 = require("../../utils");
  7. /**
  8. * 获取柱子 path
  9. * @param points
  10. */
  11. function getRectPath(points) {
  12. var path = [];
  13. for (var i = 0; i < points.length; i++) {
  14. var point = points[i];
  15. if (point) {
  16. var action = i === 0 ? 'M' : 'L';
  17. path.push([action, point.x, point.y]);
  18. }
  19. }
  20. var first = points[0];
  21. path.push(['L', first.x, first.y]);
  22. path.push(['z']);
  23. return path;
  24. }
  25. /**
  26. * 获取填充属性
  27. * @param cfg 图形绘制数据
  28. */
  29. function getFillAttrs(cfg) {
  30. return (0, utils_1.deepAssign)({}, cfg.defaultStyle, cfg.style, { fill: cfg.color });
  31. }
  32. (0, g2_1.registerShape)('interval', 'waterfall', {
  33. draw: function (cfg, container) {
  34. var customInfo = cfg.customInfo, points = cfg.points, nextPoints = cfg.nextPoints;
  35. var group = container.addGroup();
  36. // ① 绘制柱体
  37. var rectPath = this.parsePath(getRectPath(points));
  38. var fillAttrs = getFillAttrs(cfg);
  39. group.addShape('path', {
  40. attrs: tslib_1.__assign(tslib_1.__assign({}, fillAttrs), { path: rectPath }),
  41. });
  42. // ② 绘制连接线
  43. var leaderLineCfg = (0, util_1.get)(customInfo, 'leaderLine');
  44. if (leaderLineCfg && nextPoints) {
  45. var linkPath = [
  46. ['M', points[2].x, points[2].y],
  47. ['L', nextPoints[0].x, nextPoints[0].y],
  48. ];
  49. if (points[2].y === nextPoints[1].y) {
  50. linkPath[1] = ['L', nextPoints[1].x, nextPoints[1].y];
  51. }
  52. linkPath = this.parsePath(linkPath);
  53. group.addShape('path', {
  54. attrs: tslib_1.__assign({ path: linkPath }, (leaderLineCfg.style || {})),
  55. });
  56. }
  57. return group;
  58. },
  59. });
  60. //# sourceMappingURL=shape.js.map