lines.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Lines = void 0;
  4. var tslib_1 = require("tslib");
  5. var util_1 = require("@antv/util");
  6. var shapes_1 = require("../../shapes");
  7. var util_2 = require("../../util");
  8. var Lines = /** @class */ (function (_super) {
  9. tslib_1.__extends(Lines, _super);
  10. function Lines(_a) {
  11. var _this = this;
  12. var style = _a.style, rest = tslib_1.__rest(_a, ["style"]);
  13. _this = _super.call(this, (0, util_1.deepMix)({}, { type: 'lines' }, tslib_1.__assign({ style: style }, rest))) || this;
  14. _this.linesGroup = _this.appendChild(new shapes_1.Group());
  15. _this.areasGroup = _this.appendChild(new shapes_1.Group());
  16. _this.render();
  17. return _this;
  18. }
  19. Lines.prototype.render = function () {
  20. var _a = this.attributes, lines = _a.lines, areas = _a.areas;
  21. if (lines)
  22. this.renderLines(lines);
  23. if (areas)
  24. this.renderAreas(areas);
  25. };
  26. Lines.prototype.clear = function () {
  27. this.linesGroup.removeChildren();
  28. this.areasGroup.removeChildren();
  29. };
  30. Lines.prototype.update = function (attr) {
  31. this.attr((0, util_2.deepAssign)({}, this.attributes, attr));
  32. this.render();
  33. };
  34. Lines.prototype.renderLines = function (lines) {
  35. (0, util_2.select)(this.linesGroup)
  36. .selectAll('.line')
  37. .data(lines)
  38. .join(function (enter) {
  39. return enter
  40. .append('path')
  41. .attr('className', 'line')
  42. .each(function (style) {
  43. this.attr(style);
  44. });
  45. }, function (update) {
  46. return update.each(function (style) {
  47. this.attr(style);
  48. });
  49. }, function (exit) { return exit.remove(); });
  50. };
  51. Lines.prototype.renderAreas = function (areas) {
  52. (0, util_2.select)(this.linesGroup)
  53. .selectAll('.area')
  54. .data(areas)
  55. .join(function (enter) {
  56. return enter
  57. .append('path')
  58. .attr('className', 'area')
  59. .each(function (style) {
  60. this.attr(style);
  61. });
  62. }, function (update) {
  63. return update.each(function (style) {
  64. this.style(style);
  65. });
  66. }, function (exit) { return exit.remove(); });
  67. };
  68. return Lines;
  69. }(shapes_1.DisplayObject));
  70. exports.Lines = Lines;
  71. //# sourceMappingURL=lines.js.map