SankeySeries.js 7.4 KB

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