index.js 3.8 KB

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