SankeySeries.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { __extends } from "tslib";
  41. import SeriesModel from '../../model/Series.js';
  42. import createGraphFromNodeEdge from '../helper/createGraphFromNodeEdge.js';
  43. import Model from '../../model/Model.js';
  44. import { createTooltipMarkup } from '../../component/tooltip/tooltipMarkup.js';
  45. var SankeySeriesModel =
  46. /** @class */
  47. function (_super) {
  48. __extends(SankeySeriesModel, _super);
  49. function SankeySeriesModel() {
  50. var _this = _super !== null && _super.apply(this, arguments) || this;
  51. _this.type = SankeySeriesModel.type;
  52. return _this;
  53. }
  54. /**
  55. * Init a graph data structure from data in option series
  56. */
  57. SankeySeriesModel.prototype.getInitialData = function (option, ecModel) {
  58. var links = option.edges || option.links;
  59. var nodes = option.data || option.nodes;
  60. var levels = option.levels;
  61. this.levelModels = [];
  62. var levelModels = this.levelModels;
  63. for (var i = 0; i < levels.length; i++) {
  64. if (levels[i].depth != null && levels[i].depth >= 0) {
  65. levelModels[levels[i].depth] = new Model(levels[i], this, ecModel);
  66. } else {
  67. if (process.env.NODE_ENV !== 'production') {
  68. throw new Error('levels[i].depth is mandatory and should be natural number');
  69. }
  70. }
  71. }
  72. if (nodes && links) {
  73. var graph = createGraphFromNodeEdge(nodes, links, this, true, beforeLink);
  74. return graph.data;
  75. }
  76. function beforeLink(nodeData, edgeData) {
  77. nodeData.wrapMethod('getItemModel', function (model, idx) {
  78. var seriesModel = model.parentModel;
  79. var layout = seriesModel.getData().getItemLayout(idx);
  80. if (layout) {
  81. var nodeDepth = layout.depth;
  82. var levelModel = seriesModel.levelModels[nodeDepth];
  83. if (levelModel) {
  84. model.parentModel = levelModel;
  85. }
  86. }
  87. return model;
  88. });
  89. edgeData.wrapMethod('getItemModel', function (model, idx) {
  90. var seriesModel = model.parentModel;
  91. var edge = seriesModel.getGraph().getEdgeByIndex(idx);
  92. var layout = edge.node1.getLayout();
  93. if (layout) {
  94. var depth = layout.depth;
  95. var levelModel = seriesModel.levelModels[depth];
  96. if (levelModel) {
  97. model.parentModel = levelModel;
  98. }
  99. }
  100. return model;
  101. });
  102. }
  103. };
  104. SankeySeriesModel.prototype.setNodePosition = function (dataIndex, localPosition) {
  105. var nodes = this.option.data || this.option.nodes;
  106. var dataItem = nodes[dataIndex];
  107. dataItem.localX = localPosition[0];
  108. dataItem.localY = localPosition[1];
  109. };
  110. /**
  111. * Return the graphic data structure
  112. *
  113. * @return graphic data structure
  114. */
  115. SankeySeriesModel.prototype.getGraph = function () {
  116. return this.getData().graph;
  117. };
  118. /**
  119. * Get edge data of graphic data structure
  120. *
  121. * @return data structure of list
  122. */
  123. SankeySeriesModel.prototype.getEdgeData = function () {
  124. return this.getGraph().edgeData;
  125. };
  126. SankeySeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  127. function noValue(val) {
  128. return isNaN(val) || val == null;
  129. } // dataType === 'node' or empty do not show tooltip by default
  130. if (dataType === 'edge') {
  131. var params = this.getDataParams(dataIndex, dataType);
  132. var rawDataOpt = params.data;
  133. var edgeValue = params.value;
  134. var edgeName = rawDataOpt.source + ' -- ' + rawDataOpt.target;
  135. return createTooltipMarkup('nameValue', {
  136. name: edgeName,
  137. value: edgeValue,
  138. noValue: noValue(edgeValue)
  139. });
  140. } // dataType === 'node'
  141. else {
  142. var node = this.getGraph().getNodeByIndex(dataIndex);
  143. var value = node.getLayout().value;
  144. var name_1 = this.getDataParams(dataIndex, dataType).data.name;
  145. return createTooltipMarkup('nameValue', {
  146. name: name_1 != null ? name_1 + '' : null,
  147. value: value,
  148. noValue: noValue(value)
  149. });
  150. }
  151. };
  152. SankeySeriesModel.prototype.optionUpdated = function () {}; // Override Series.getDataParams()
  153. SankeySeriesModel.prototype.getDataParams = function (dataIndex, dataType) {
  154. var params = _super.prototype.getDataParams.call(this, dataIndex, dataType);
  155. if (params.value == null && dataType === 'node') {
  156. var node = this.getGraph().getNodeByIndex(dataIndex);
  157. var nodeValue = node.getLayout().value;
  158. params.value = nodeValue;
  159. }
  160. return params;
  161. };
  162. SankeySeriesModel.type = 'series.sankey';
  163. SankeySeriesModel.defaultOption = {
  164. // zlevel: 0,
  165. z: 2,
  166. coordinateSystem: 'view',
  167. left: '5%',
  168. top: '5%',
  169. right: '20%',
  170. bottom: '5%',
  171. orient: 'horizontal',
  172. nodeWidth: 20,
  173. nodeGap: 8,
  174. draggable: true,
  175. layoutIterations: 32,
  176. label: {
  177. show: true,
  178. position: 'right',
  179. fontSize: 12
  180. },
  181. levels: [],
  182. nodeAlign: 'justify',
  183. lineStyle: {
  184. color: '#314656',
  185. opacity: 0.2,
  186. curveness: 0.5
  187. },
  188. emphasis: {
  189. label: {
  190. show: true
  191. },
  192. lineStyle: {
  193. opacity: 0.5
  194. }
  195. },
  196. select: {
  197. itemStyle: {
  198. borderColor: '#212121'
  199. }
  200. },
  201. animationEasing: 'linear',
  202. animationDuration: 1000
  203. };
  204. return SankeySeriesModel;
  205. }(SeriesModel);
  206. export default SankeySeriesModel;