SankeySeries.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. var SeriesModel = require("../../model/Series");
  2. var createGraphFromNodeEdge = require("../helper/createGraphFromNodeEdge");
  3. var _format = require("../../util/format");
  4. var encodeHTML = _format.encodeHTML;
  5. /**
  6. * @file Get initial data and define sankey view's series model
  7. * @author Deqing Li(annong035@gmail.com)
  8. */
  9. var SankeySeries = SeriesModel.extend({
  10. type: 'series.sankey',
  11. layoutInfo: null,
  12. /**
  13. * Init a graph data structure from data in option series
  14. *
  15. * @param {Object} option the object used to config echarts view
  16. * @return {module:echarts/data/List} storage initial data
  17. */
  18. getInitialData: function (option) {
  19. var links = option.edges || option.links;
  20. var nodes = option.data || option.nodes;
  21. if (nodes && links) {
  22. var graph = createGraphFromNodeEdge(nodes, links, this, true);
  23. return graph.data;
  24. }
  25. },
  26. /**
  27. * Return the graphic data structure
  28. *
  29. * @return {module:echarts/data/Graph} graphic data structure
  30. */
  31. getGraph: function () {
  32. return this.getData().graph;
  33. },
  34. /**
  35. * Get edge data of graphic data structure
  36. *
  37. * @return {module:echarts/data/List} data structure of list
  38. */
  39. getEdgeData: function () {
  40. return this.getGraph().edgeData;
  41. },
  42. /**
  43. * @override
  44. */
  45. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  46. // dataType === 'node' or empty do not show tooltip by default
  47. if (dataType === 'edge') {
  48. var params = this.getDataParams(dataIndex, dataType);
  49. var rawDataOpt = params.data;
  50. var html = rawDataOpt.source + ' -- ' + rawDataOpt.target;
  51. if (params.value) {
  52. html += ' : ' + params.value;
  53. }
  54. return encodeHTML(html);
  55. }
  56. return SankeySeries.superCall(this, 'formatTooltip', dataIndex, multipleSeries);
  57. },
  58. defaultOption: {
  59. zlevel: 0,
  60. z: 2,
  61. coordinateSystem: 'view',
  62. layout: null,
  63. // the position of the whole view
  64. left: '5%',
  65. top: '5%',
  66. right: '20%',
  67. bottom: '5%',
  68. // the dx of the node
  69. nodeWidth: 20,
  70. // the vertical distance between two nodes
  71. nodeGap: 8,
  72. // the number of iterations to change the position of the node
  73. layoutIterations: 32,
  74. label: {
  75. normal: {
  76. show: true,
  77. position: 'right',
  78. color: '#000',
  79. fontSize: 12
  80. },
  81. emphasis: {
  82. show: true
  83. }
  84. },
  85. itemStyle: {
  86. normal: {
  87. borderWidth: 1,
  88. borderColor: '#333'
  89. }
  90. },
  91. lineStyle: {
  92. normal: {
  93. color: '#314656',
  94. opacity: 0.2,
  95. curveness: 0.5
  96. },
  97. emphasis: {
  98. opacity: 0.6
  99. }
  100. },
  101. animationEasing: 'linear',
  102. animationDuration: 1000
  103. }
  104. });
  105. var _default = SankeySeries;
  106. module.exports = _default;