base.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { Node } from '../node';
  2. export class MarkNode extends Node {
  3. changeData(data) {
  4. const chart = this.getRoot();
  5. if (!chart)
  6. return;
  7. this.attr('data', data);
  8. return chart === null || chart === void 0 ? void 0 : chart.render();
  9. }
  10. /**
  11. * Get mark from chart views.
  12. */
  13. getMark() {
  14. var _a;
  15. const chartView = (_a = this.getRoot()) === null || _a === void 0 ? void 0 : _a.getView();
  16. if (!chartView)
  17. return undefined;
  18. const { markState } = chartView;
  19. const markKey = Array.from(markState.keys()).find((item) => item.key === this.attr('key'));
  20. return markState.get(markKey);
  21. }
  22. /**
  23. * Get all scales instance.
  24. */
  25. getScale() {
  26. var _a;
  27. const chartView = (_a = this.getRoot()) === null || _a === void 0 ? void 0 : _a.getView();
  28. if (!chartView)
  29. return undefined;
  30. return chartView === null || chartView === void 0 ? void 0 : chartView.scale;
  31. }
  32. /**
  33. * Get the scale instance by channel.
  34. */
  35. getScaleByChannel(channel) {
  36. var _a, _b;
  37. const chartView = (_a = this.getRoot()) === null || _a === void 0 ? void 0 : _a.getView();
  38. if (!chartView)
  39. return undefined;
  40. return (_b = chartView === null || chartView === void 0 ? void 0 : chartView.scale) === null || _b === void 0 ? void 0 : _b[channel];
  41. }
  42. /**
  43. * Get canvas group.
  44. */
  45. getGroup() {
  46. const key = this.attr('key');
  47. if (!key)
  48. return undefined;
  49. const chart = this.getRoot();
  50. const chartGroup = chart.getContext().canvas.getRoot();
  51. return chartGroup.getElementById(key);
  52. }
  53. }
  54. //# sourceMappingURL=base.js.map