base.js 2.1 KB

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