lines.js 2.3 KB

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