SankeySeries.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 = /** @class */function (_super) {
  46. __extends(SankeySeriesModel, _super);
  47. function SankeySeriesModel() {
  48. var _this = _super !== null && _super.apply(this, arguments) || this;
  49. _this.type = SankeySeriesModel.type;
  50. return _this;
  51. }
  52. /**
  53. * Init a graph data structure from data in option series
  54. */
  55. SankeySeriesModel.prototype.getInitialData = function (option, ecModel) {
  56. var links = option.edges || option.links;
  57. var nodes = option.data || option.nodes;
  58. var levels = option.levels;
  59. this.levelModels = [];
  60. var levelModels = this.levelModels;
  61. for (var i = 0; i < levels.length; i++) {
  62. if (levels[i].depth != null && levels[i].depth >= 0) {
  63. levelModels[levels[i].depth] = new Model(levels[i], this, ecModel);
  64. } else {
  65. if (process.env.NODE_ENV !== 'production') {
  66. throw new Error('levels[i].depth is mandatory and should be natural number');
  67. }
  68. }
  69. }
  70. if (nodes && links) {
  71. var graph = createGraphFromNodeEdge(nodes, links, this, true, beforeLink);
  72. return graph.data;
  73. }
  74. function beforeLink(nodeData, edgeData) {
  75. nodeData.wrapMethod('getItemModel', function (model, idx) {
  76. var seriesModel = model.parentModel;
  77. var layout = seriesModel.getData().getItemLayout(idx);
  78. if (layout) {
  79. var nodeDepth = layout.depth;
  80. var levelModel = seriesModel.levelModels[nodeDepth];
  81. if (levelModel) {
  82. model.parentModel = levelModel;
  83. }
  84. }
  85. return model;
  86. });
  87. edgeData.wrapMethod('getItemModel', function (model, idx) {
  88. var seriesModel = model.parentModel;
  89. var edge = seriesModel.getGraph().getEdgeByIndex(idx);
  90. var layout = edge.node1.getLayout();
  91. if (layout) {
  92. var depth = layout.depth;
  93. var levelModel = seriesModel.levelModels[depth];
  94. if (levelModel) {
  95. model.parentModel = levelModel;
  96. }
  97. }
  98. return model;
  99. });
  100. }
  101. };
  102. SankeySeriesModel.prototype.setNodePosition = function (dataIndex, localPosition) {
  103. var nodes = this.option.data || this.option.nodes;
  104. var dataItem = nodes[dataIndex];
  105. dataItem.localX = localPosition[0];
  106. dataItem.localY = localPosition[1];
  107. };
  108. /**
  109. * Return the graphic data structure
  110. *
  111. * @return graphic data structure
  112. */
  113. SankeySeriesModel.prototype.getGraph = function () {
  114. return this.getData().graph;
  115. };
  116. /**
  117. * Get edge data of graphic data structure
  118. *
  119. * @return data structure of list
  120. */
  121. SankeySeriesModel.prototype.getEdgeData = function () {
  122. return this.getGraph().edgeData;
  123. };
  124. SankeySeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  125. function noValue(val) {
  126. return isNaN(val) || val == null;
  127. }
  128. // dataType === 'node' or empty do not show tooltip by default
  129. if (dataType === 'edge') {
  130. var params = this.getDataParams(dataIndex, dataType);
  131. var rawDataOpt = params.data;
  132. var edgeValue = params.value;
  133. var edgeName = rawDataOpt.source + ' -- ' + rawDataOpt.target;
  134. return createTooltipMarkup('nameValue', {
  135. name: edgeName,
  136. value: edgeValue,
  137. noValue: noValue(edgeValue)
  138. });
  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 () {};
  153. // Override Series.getDataParams()
  154. SankeySeriesModel.prototype.getDataParams = function (dataIndex, dataType) {
  155. var params = _super.prototype.getDataParams.call(this, dataIndex, dataType);
  156. if (params.value == null && dataType === 'node') {
  157. var node = this.getGraph().getNodeByIndex(dataIndex);
  158. var nodeValue = node.getLayout().value;
  159. params.value = nodeValue;
  160. }
  161. return params;
  162. };
  163. SankeySeriesModel.type = 'series.sankey';
  164. SankeySeriesModel.defaultOption = {
  165. // zlevel: 0,
  166. z: 2,
  167. coordinateSystem: 'view',
  168. left: '5%',
  169. top: '5%',
  170. right: '20%',
  171. bottom: '5%',
  172. orient: 'horizontal',
  173. nodeWidth: 20,
  174. nodeGap: 8,
  175. draggable: true,
  176. layoutIterations: 32,
  177. label: {
  178. show: true,
  179. position: 'right',
  180. fontSize: 12
  181. },
  182. edgeLabel: {
  183. show: false,
  184. fontSize: 12
  185. },
  186. levels: [],
  187. nodeAlign: 'justify',
  188. lineStyle: {
  189. color: '#314656',
  190. opacity: 0.2,
  191. curveness: 0.5
  192. },
  193. emphasis: {
  194. label: {
  195. show: true
  196. },
  197. lineStyle: {
  198. opacity: 0.5
  199. }
  200. },
  201. select: {
  202. itemStyle: {
  203. borderColor: '#212121'
  204. }
  205. },
  206. animationEasing: 'linear',
  207. animationDuration: 1000
  208. };
  209. return SankeySeriesModel;
  210. }(SeriesModel);
  211. export default SankeySeriesModel;