index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { __extends } from "tslib";
  2. import { get } from '@antv/util';
  3. import { Plot } from '../../core/plot';
  4. import { findViewById } from '../../utils';
  5. import { adaptor } from './adaptor';
  6. import { EDGES_VIEW_ID, NODES_VIEW_ID } from './constant';
  7. import { transformToViewsData } from './helper';
  8. // 桑基图内置交互
  9. import './interactions';
  10. /**
  11. * 桑基图 Sankey
  12. */
  13. var Sankey = /** @class */ (function (_super) {
  14. __extends(Sankey, _super);
  15. function Sankey() {
  16. var _this = _super !== null && _super.apply(this, arguments) || this;
  17. /** 图表类型 */
  18. _this.type = 'sankey';
  19. return _this;
  20. }
  21. Sankey.getDefaultOptions = function () {
  22. return {
  23. appendPadding: 8,
  24. syncViewPadding: true,
  25. nodeStyle: {
  26. opacity: 1,
  27. fillOpacity: 1,
  28. lineWidth: 1,
  29. },
  30. edgeStyle: {
  31. opacity: 0.3,
  32. lineWidth: 0,
  33. },
  34. edgeState: {
  35. active: {
  36. style: {
  37. opacity: 0.8,
  38. lineWidth: 0,
  39. },
  40. },
  41. },
  42. label: {
  43. formatter: function (_a) {
  44. var name = _a.name;
  45. return name;
  46. },
  47. callback: function (x) {
  48. var isLast = x[1] === 1; // 最后一列靠边的节点
  49. return {
  50. style: {
  51. fill: '#545454',
  52. textAlign: isLast ? 'end' : 'start',
  53. },
  54. offsetX: isLast ? -8 : 8,
  55. };
  56. },
  57. layout: [
  58. {
  59. type: 'hide-overlap',
  60. },
  61. ],
  62. },
  63. tooltip: {
  64. showTitle: false,
  65. showMarkers: false,
  66. shared: false,
  67. // 内置:node 不显示 tooltip,edge 显示 tooltip
  68. showContent: function (items) {
  69. return !get(items, [0, 'data', 'isNode']);
  70. },
  71. formatter: function (datum) {
  72. var source = datum.source, target = datum.target, value = datum.value;
  73. return {
  74. name: source + ' -> ' + target,
  75. value: value,
  76. };
  77. },
  78. },
  79. nodeWidthRatio: 0.008,
  80. nodePaddingRatio: 0.01,
  81. animation: {
  82. appear: {
  83. animation: 'wave-in',
  84. },
  85. enter: {
  86. animation: 'wave-in',
  87. },
  88. },
  89. };
  90. };
  91. /**
  92. * @override
  93. * @param data
  94. */
  95. Sankey.prototype.changeData = function (data) {
  96. this.updateOption({ data: data });
  97. var _a = transformToViewsData(this.options, this.chart.width, this.chart.height), nodes = _a.nodes, edges = _a.edges;
  98. var nodesView = findViewById(this.chart, NODES_VIEW_ID);
  99. var edgesView = findViewById(this.chart, EDGES_VIEW_ID);
  100. nodesView.changeData(nodes);
  101. edgesView.changeData(edges);
  102. };
  103. /**
  104. * 获取适配器
  105. */
  106. Sankey.prototype.getSchemaAdaptor = function () {
  107. return adaptor;
  108. };
  109. /**
  110. * 获取 条形图 默认配置
  111. */
  112. Sankey.prototype.getDefaultOptions = function () {
  113. return Sankey.getDefaultOptions();
  114. };
  115. return Sankey;
  116. }(Plot));
  117. export { Sankey };
  118. //# sourceMappingURL=index.js.map