SankeySeries.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. var graph = createGraphFromNodeEdge(nodes, links, this, true, beforeLink);
  71. return graph.data;
  72. function beforeLink(nodeData, edgeData) {
  73. nodeData.wrapMethod('getItemModel', function (model, idx) {
  74. var seriesModel = model.parentModel;
  75. var layout = seriesModel.getData().getItemLayout(idx);
  76. if (layout) {
  77. var nodeDepth = layout.depth;
  78. var levelModel = seriesModel.levelModels[nodeDepth];
  79. if (levelModel) {
  80. model.parentModel = levelModel;
  81. }
  82. }
  83. return model;
  84. });
  85. edgeData.wrapMethod('getItemModel', function (model, idx) {
  86. var seriesModel = model.parentModel;
  87. var edge = seriesModel.getGraph().getEdgeByIndex(idx);
  88. var layout = edge.node1.getLayout();
  89. if (layout) {
  90. var depth = layout.depth;
  91. var levelModel = seriesModel.levelModels[depth];
  92. if (levelModel) {
  93. model.parentModel = levelModel;
  94. }
  95. }
  96. return model;
  97. });
  98. }
  99. };
  100. SankeySeriesModel.prototype.setNodePosition = function (dataIndex, localPosition) {
  101. var nodes = this.option.data || this.option.nodes;
  102. var dataItem = nodes[dataIndex];
  103. dataItem.localX = localPosition[0];
  104. dataItem.localY = localPosition[1];
  105. };
  106. /**
  107. * Return the graphic data structure
  108. *
  109. * @return graphic data structure
  110. */
  111. SankeySeriesModel.prototype.getGraph = function () {
  112. return this.getData().graph;
  113. };
  114. /**
  115. * Get edge data of graphic data structure
  116. *
  117. * @return data structure of list
  118. */
  119. SankeySeriesModel.prototype.getEdgeData = function () {
  120. return this.getGraph().edgeData;
  121. };
  122. SankeySeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  123. function noValue(val) {
  124. return isNaN(val) || val == null;
  125. }
  126. // dataType === 'node' or empty do not show tooltip by default
  127. if (dataType === 'edge') {
  128. var params = this.getDataParams(dataIndex, dataType);
  129. var rawDataOpt = params.data;
  130. var edgeValue = params.value;
  131. var edgeName = rawDataOpt.source + ' -- ' + rawDataOpt.target;
  132. return createTooltipMarkup('nameValue', {
  133. name: edgeName,
  134. value: edgeValue,
  135. noValue: noValue(edgeValue)
  136. });
  137. }
  138. // dataType === 'node'
  139. else {
  140. var node = this.getGraph().getNodeByIndex(dataIndex);
  141. var value = node.getLayout().value;
  142. var name_1 = this.getDataParams(dataIndex, dataType).data.name;
  143. return createTooltipMarkup('nameValue', {
  144. name: name_1 != null ? name_1 + '' : null,
  145. value: value,
  146. noValue: noValue(value)
  147. });
  148. }
  149. };
  150. SankeySeriesModel.prototype.optionUpdated = function () {};
  151. // Override Series.getDataParams()
  152. SankeySeriesModel.prototype.getDataParams = function (dataIndex, dataType) {
  153. var params = _super.prototype.getDataParams.call(this, dataIndex, dataType);
  154. if (params.value == null && dataType === 'node') {
  155. var node = this.getGraph().getNodeByIndex(dataIndex);
  156. var nodeValue = node.getLayout().value;
  157. params.value = nodeValue;
  158. }
  159. return params;
  160. };
  161. SankeySeriesModel.type = 'series.sankey';
  162. SankeySeriesModel.defaultOption = {
  163. // zlevel: 0,
  164. z: 2,
  165. coordinateSystem: 'view',
  166. left: '5%',
  167. top: '5%',
  168. right: '20%',
  169. bottom: '5%',
  170. orient: 'horizontal',
  171. nodeWidth: 20,
  172. nodeGap: 8,
  173. draggable: true,
  174. layoutIterations: 32,
  175. label: {
  176. show: true,
  177. position: 'right',
  178. fontSize: 12
  179. },
  180. edgeLabel: {
  181. show: false,
  182. fontSize: 12
  183. },
  184. levels: [],
  185. nodeAlign: 'justify',
  186. lineStyle: {
  187. color: '#314656',
  188. opacity: 0.2,
  189. curveness: 0.5
  190. },
  191. emphasis: {
  192. label: {
  193. show: true
  194. },
  195. lineStyle: {
  196. opacity: 0.5
  197. }
  198. },
  199. select: {
  200. itemStyle: {
  201. borderColor: '#212121'
  202. }
  203. },
  204. animationEasing: 'linear',
  205. animationDuration: 1000
  206. };
  207. return SankeySeriesModel;
  208. }(SeriesModel);
  209. export default SankeySeriesModel;