shape.js 1.8 KB

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