line.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _global = _interopRequireDefault(require("../../global"));
  5. var _shape = _interopRequireDefault(require("./shape"));
  6. var _common = require("../../util/common");
  7. var _util = require("./util");
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  9. // register line geom
  10. var Line = _shape["default"].registerFactory('line', {
  11. defaultShapeType: 'line'
  12. });
  13. function getStyle(cfg) {
  14. var style = {
  15. strokeStyle: cfg.color
  16. };
  17. if (cfg.size >= 0) {
  18. style.lineWidth = cfg.size;
  19. }
  20. (0, _common.mix)(style, cfg.style);
  21. return (0, _common.mix)({}, _global["default"].shape.line, style);
  22. }
  23. function drawLines(cfg, container, style, smooth) {
  24. var points = cfg.points;
  25. if (points.length && (0, _common.isArray)(points[0].y)) {
  26. var topPoints = [];
  27. var bottomPoints = [];
  28. for (var i = 0, len = points.length; i < len; i++) {
  29. var point = points[i];
  30. var tmp = (0, _util.splitPoints)(point);
  31. bottomPoints.push(tmp[0]);
  32. topPoints.push(tmp[1]);
  33. }
  34. if (cfg.isInCircle) {
  35. topPoints.push(topPoints[0]);
  36. bottomPoints.push(bottomPoints[0]);
  37. }
  38. if (cfg.isStack) {
  39. return container.addShape('Polyline', {
  40. className: 'line',
  41. attrs: (0, _common.mix)({
  42. points: topPoints,
  43. smooth: smooth
  44. }, style)
  45. });
  46. }
  47. var topShape = container.addShape('Polyline', {
  48. className: 'line',
  49. attrs: (0, _common.mix)({
  50. points: topPoints,
  51. smooth: smooth
  52. }, style)
  53. });
  54. var bottomShape = container.addShape('Polyline', {
  55. className: 'line',
  56. attrs: (0, _common.mix)({
  57. points: bottomPoints,
  58. smooth: smooth
  59. }, style)
  60. });
  61. return [topShape, bottomShape];
  62. }
  63. if (cfg.isInCircle) {
  64. points.push(points[0]);
  65. }
  66. return container.addShape('Polyline', {
  67. className: 'line',
  68. attrs: (0, _common.mix)({
  69. points: points,
  70. smooth: smooth
  71. }, style)
  72. });
  73. }
  74. var SHAPES = ['line', 'smooth', 'dash'];
  75. (0, _common.each)(SHAPES, function (shapeType) {
  76. _shape["default"].registerShape('line', shapeType, {
  77. draw: function draw(cfg, container) {
  78. var smooth = shapeType === 'smooth';
  79. var style = getStyle(cfg);
  80. if (shapeType === 'dash') {
  81. style.lineDash = _global["default"].lineDash;
  82. }
  83. return drawLines(cfg, container, style, smooth);
  84. }
  85. });
  86. });
  87. var _default = Line;
  88. exports["default"] = _default;