GraphSeries.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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 SeriesData from '../../data/SeriesData.js';
  42. import * as zrUtil from 'zrender/lib/core/util.js';
  43. import { defaultEmphasis } from '../../util/model.js';
  44. import Model from '../../model/Model.js';
  45. import createGraphFromNodeEdge from '../helper/createGraphFromNodeEdge.js';
  46. import LegendVisualProvider from '../../visual/LegendVisualProvider.js';
  47. import SeriesModel from '../../model/Series.js';
  48. import { createTooltipMarkup } from '../../component/tooltip/tooltipMarkup.js';
  49. import { defaultSeriesFormatTooltip } from '../../component/tooltip/seriesFormatTooltip.js';
  50. import { initCurvenessList, createEdgeMapForCurveness } from '../helper/multipleGraphEdgeHelper.js';
  51. var GraphSeriesModel =
  52. /** @class */
  53. function (_super) {
  54. __extends(GraphSeriesModel, _super);
  55. function GraphSeriesModel() {
  56. var _this = _super !== null && _super.apply(this, arguments) || this;
  57. _this.type = GraphSeriesModel.type;
  58. _this.hasSymbolVisual = true;
  59. return _this;
  60. }
  61. GraphSeriesModel.prototype.init = function (option) {
  62. _super.prototype.init.apply(this, arguments);
  63. var self = this;
  64. function getCategoriesData() {
  65. return self._categoriesData;
  66. } // Provide data for legend select
  67. this.legendVisualProvider = new LegendVisualProvider(getCategoriesData, getCategoriesData);
  68. this.fillDataTextStyle(option.edges || option.links);
  69. this._updateCategoriesData();
  70. };
  71. GraphSeriesModel.prototype.mergeOption = function (option) {
  72. _super.prototype.mergeOption.apply(this, arguments);
  73. this.fillDataTextStyle(option.edges || option.links);
  74. this._updateCategoriesData();
  75. };
  76. GraphSeriesModel.prototype.mergeDefaultAndTheme = function (option) {
  77. _super.prototype.mergeDefaultAndTheme.apply(this, arguments);
  78. defaultEmphasis(option, 'edgeLabel', ['show']);
  79. };
  80. GraphSeriesModel.prototype.getInitialData = function (option, ecModel) {
  81. var edges = option.edges || option.links || [];
  82. var nodes = option.data || option.nodes || [];
  83. var self = this;
  84. if (nodes && edges) {
  85. // auto curveness
  86. initCurvenessList(this);
  87. var graph = createGraphFromNodeEdge(nodes, edges, this, true, beforeLink);
  88. zrUtil.each(graph.edges, function (edge) {
  89. createEdgeMapForCurveness(edge.node1, edge.node2, this, edge.dataIndex);
  90. }, this);
  91. return graph.data;
  92. }
  93. function beforeLink(nodeData, edgeData) {
  94. // Overwrite nodeData.getItemModel to
  95. nodeData.wrapMethod('getItemModel', function (model) {
  96. var categoriesModels = self._categoriesModels;
  97. var categoryIdx = model.getShallow('category');
  98. var categoryModel = categoriesModels[categoryIdx];
  99. if (categoryModel) {
  100. categoryModel.parentModel = model.parentModel;
  101. model.parentModel = categoryModel;
  102. }
  103. return model;
  104. }); // TODO Inherit resolveParentPath by default in Model#getModel?
  105. var oldGetModel = Model.prototype.getModel;
  106. function newGetModel(path, parentModel) {
  107. var model = oldGetModel.call(this, path, parentModel);
  108. model.resolveParentPath = resolveParentPath;
  109. return model;
  110. }
  111. edgeData.wrapMethod('getItemModel', function (model) {
  112. model.resolveParentPath = resolveParentPath;
  113. model.getModel = newGetModel;
  114. return model;
  115. });
  116. function resolveParentPath(pathArr) {
  117. if (pathArr && (pathArr[0] === 'label' || pathArr[1] === 'label')) {
  118. var newPathArr = pathArr.slice();
  119. if (pathArr[0] === 'label') {
  120. newPathArr[0] = 'edgeLabel';
  121. } else if (pathArr[1] === 'label') {
  122. newPathArr[1] = 'edgeLabel';
  123. }
  124. return newPathArr;
  125. }
  126. return pathArr;
  127. }
  128. }
  129. };
  130. GraphSeriesModel.prototype.getGraph = function () {
  131. return this.getData().graph;
  132. };
  133. GraphSeriesModel.prototype.getEdgeData = function () {
  134. return this.getGraph().edgeData;
  135. };
  136. GraphSeriesModel.prototype.getCategoriesData = function () {
  137. return this._categoriesData;
  138. };
  139. GraphSeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  140. if (dataType === 'edge') {
  141. var nodeData = this.getData();
  142. var params = this.getDataParams(dataIndex, dataType);
  143. var edge = nodeData.graph.getEdgeByIndex(dataIndex);
  144. var sourceName = nodeData.getName(edge.node1.dataIndex);
  145. var targetName = nodeData.getName(edge.node2.dataIndex);
  146. var nameArr = [];
  147. sourceName != null && nameArr.push(sourceName);
  148. targetName != null && nameArr.push(targetName);
  149. return createTooltipMarkup('nameValue', {
  150. name: nameArr.join(' > '),
  151. value: params.value,
  152. noValue: params.value == null
  153. });
  154. } // dataType === 'node' or empty
  155. var nodeMarkup = defaultSeriesFormatTooltip({
  156. series: this,
  157. dataIndex: dataIndex,
  158. multipleSeries: multipleSeries
  159. });
  160. return nodeMarkup;
  161. };
  162. GraphSeriesModel.prototype._updateCategoriesData = function () {
  163. var categories = zrUtil.map(this.option.categories || [], function (category) {
  164. // Data must has value
  165. return category.value != null ? category : zrUtil.extend({
  166. value: 0
  167. }, category);
  168. });
  169. var categoriesData = new SeriesData(['value'], this);
  170. categoriesData.initData(categories);
  171. this._categoriesData = categoriesData;
  172. this._categoriesModels = categoriesData.mapArray(function (idx) {
  173. return categoriesData.getItemModel(idx);
  174. });
  175. };
  176. GraphSeriesModel.prototype.setZoom = function (zoom) {
  177. this.option.zoom = zoom;
  178. };
  179. GraphSeriesModel.prototype.setCenter = function (center) {
  180. this.option.center = center;
  181. };
  182. GraphSeriesModel.prototype.isAnimationEnabled = function () {
  183. return _super.prototype.isAnimationEnabled.call(this) // Not enable animation when do force layout
  184. && !(this.get('layout') === 'force' && this.get(['force', 'layoutAnimation']));
  185. };
  186. GraphSeriesModel.type = 'series.graph';
  187. GraphSeriesModel.dependencies = ['grid', 'polar', 'geo', 'singleAxis', 'calendar'];
  188. GraphSeriesModel.defaultOption = {
  189. // zlevel: 0,
  190. z: 2,
  191. coordinateSystem: 'view',
  192. // Default option for all coordinate systems
  193. // xAxisIndex: 0,
  194. // yAxisIndex: 0,
  195. // polarIndex: 0,
  196. // geoIndex: 0,
  197. legendHoverLink: true,
  198. layout: null,
  199. // Configuration of circular layout
  200. circular: {
  201. rotateLabel: false
  202. },
  203. // Configuration of force directed layout
  204. force: {
  205. initLayout: null,
  206. // Node repulsion. Can be an array to represent range.
  207. repulsion: [0, 50],
  208. gravity: 0.1,
  209. // Initial friction
  210. friction: 0.6,
  211. // Edge length. Can be an array to represent range.
  212. edgeLength: 30,
  213. layoutAnimation: true
  214. },
  215. left: 'center',
  216. top: 'center',
  217. // right: null,
  218. // bottom: null,
  219. // width: '80%',
  220. // height: '80%',
  221. symbol: 'circle',
  222. symbolSize: 10,
  223. edgeSymbol: ['none', 'none'],
  224. edgeSymbolSize: 10,
  225. edgeLabel: {
  226. position: 'middle',
  227. distance: 5
  228. },
  229. draggable: false,
  230. roam: false,
  231. // Default on center of graph
  232. center: null,
  233. zoom: 1,
  234. // Symbol size scale ratio in roam
  235. nodeScaleRatio: 0.6,
  236. // cursor: null,
  237. // categories: [],
  238. // data: []
  239. // Or
  240. // nodes: []
  241. //
  242. // links: []
  243. // Or
  244. // edges: []
  245. label: {
  246. show: false,
  247. formatter: '{b}'
  248. },
  249. itemStyle: {},
  250. lineStyle: {
  251. color: '#aaa',
  252. width: 1,
  253. opacity: 0.5
  254. },
  255. emphasis: {
  256. scale: true,
  257. label: {
  258. show: true
  259. }
  260. },
  261. select: {
  262. itemStyle: {
  263. borderColor: '#212121'
  264. }
  265. }
  266. };
  267. return GraphSeriesModel;
  268. }(SeriesModel);
  269. export default GraphSeriesModel;