base.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CompositionNode = void 0;
  4. const style_1 = require("../../utils/style");
  5. const node_1 = require("../node");
  6. class CompositionNode extends node_1.Node {
  7. /**
  8. * Change current node data and its children data.
  9. */
  10. changeData(data) {
  11. var _a;
  12. const chart = this.getRoot();
  13. if (!chart)
  14. return;
  15. this.attr('data', data);
  16. if ((_a = this.children) === null || _a === void 0 ? void 0 : _a.length) {
  17. this.children.forEach((child) => {
  18. child.attr('data', data);
  19. });
  20. }
  21. return chart === null || chart === void 0 ? void 0 : chart.render();
  22. }
  23. /**
  24. * Get view instance by key.
  25. */
  26. getView() {
  27. const chart = this.getRoot();
  28. const { views } = chart.getContext();
  29. if (!(views === null || views === void 0 ? void 0 : views.length))
  30. return undefined;
  31. return views.find((view) => view.key === this._key);
  32. }
  33. getScale() {
  34. var _a;
  35. return (_a = this.getView()) === null || _a === void 0 ? void 0 : _a.scale;
  36. }
  37. getScaleByChannel(channel) {
  38. const scale = this.getScale();
  39. if (scale)
  40. return scale[channel];
  41. return;
  42. }
  43. getCoordinate() {
  44. var _a;
  45. return (_a = this.getView()) === null || _a === void 0 ? void 0 : _a.coordinate;
  46. }
  47. getTheme() {
  48. var _a;
  49. return (_a = this.getView()) === null || _a === void 0 ? void 0 : _a.theme;
  50. }
  51. getGroup() {
  52. const key = this._key;
  53. if (!key)
  54. return undefined;
  55. const chart = this.getRoot();
  56. const chartGroup = chart.getContext().canvas.getRoot();
  57. return chartGroup.getElementById(key);
  58. }
  59. /**
  60. * Show the view.
  61. */
  62. show() {
  63. const group = this.getGroup();
  64. if (!group)
  65. return;
  66. !group.isVisible() && (0, style_1.show)(group);
  67. }
  68. /**
  69. * Hide the view.
  70. */
  71. hide() {
  72. const group = this.getGroup();
  73. if (!group)
  74. return;
  75. group.isVisible() && (0, style_1.hide)(group);
  76. }
  77. }
  78. exports.CompositionNode = CompositionNode;
  79. //# sourceMappingURL=base.js.map