GraphSeries.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 = /** @class */function (_super) {
  52. __extends(GraphSeriesModel, _super);
  53. function GraphSeriesModel() {
  54. var _this = _super !== null && _super.apply(this, arguments) || this;
  55. _this.type = GraphSeriesModel.type;
  56. _this.hasSymbolVisual = true;
  57. return _this;
  58. }
  59. GraphSeriesModel.prototype.init = function (option) {
  60. _super.prototype.init.apply(this, arguments);
  61. var self = this;
  62. function getCategoriesData() {
  63. return self._categoriesData;
  64. }
  65. // Provide data for legend select
  66. this.legendVisualProvider = new LegendVisualProvider(getCategoriesData, getCategoriesData);
  67. this.fillDataTextStyle(option.edges || option.links);
  68. this._updateCategoriesData();
  69. };
  70. GraphSeriesModel.prototype.mergeOption = function (option) {
  71. _super.prototype.mergeOption.apply(this, arguments);
  72. this.fillDataTextStyle(option.edges || option.links);
  73. this._updateCategoriesData();
  74. };
  75. GraphSeriesModel.prototype.mergeDefaultAndTheme = function (option) {
  76. _super.prototype.mergeDefaultAndTheme.apply(this, arguments);
  77. defaultEmphasis(option, 'edgeLabel', ['show']);
  78. };
  79. GraphSeriesModel.prototype.getInitialData = function (option, ecModel) {
  80. var edges = option.edges || option.links || [];
  81. var nodes = option.data || option.nodes || [];
  82. var self = this;
  83. if (nodes && edges) {
  84. // auto curveness
  85. initCurvenessList(this);
  86. var graph = createGraphFromNodeEdge(nodes, edges, this, true, beforeLink);
  87. zrUtil.each(graph.edges, function (edge) {
  88. createEdgeMapForCurveness(edge.node1, edge.node2, this, edge.dataIndex);
  89. }, this);
  90. return graph.data;
  91. }
  92. function beforeLink(nodeData, edgeData) {
  93. // Overwrite nodeData.getItemModel to
  94. nodeData.wrapMethod('getItemModel', function (model) {
  95. var categoriesModels = self._categoriesModels;
  96. var categoryIdx = model.getShallow('category');
  97. var categoryModel = categoriesModels[categoryIdx];
  98. if (categoryModel) {
  99. categoryModel.parentModel = model.parentModel;
  100. model.parentModel = categoryModel;
  101. }
  102. return model;
  103. });
  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. }
  155. // dataType === 'node' or empty
  156. var nodeMarkup = defaultSeriesFormatTooltip({
  157. series: this,
  158. dataIndex: dataIndex,
  159. multipleSeries: multipleSeries
  160. });
  161. return nodeMarkup;
  162. };
  163. GraphSeriesModel.prototype._updateCategoriesData = function () {
  164. var categories = zrUtil.map(this.option.categories || [], function (category) {
  165. // Data must has value
  166. return category.value != null ? category : zrUtil.extend({
  167. value: 0
  168. }, category);
  169. });
  170. var categoriesData = new SeriesData(['value'], this);
  171. categoriesData.initData(categories);
  172. this._categoriesData = categoriesData;
  173. this._categoriesModels = categoriesData.mapArray(function (idx) {
  174. return categoriesData.getItemModel(idx);
  175. });
  176. };
  177. GraphSeriesModel.prototype.setZoom = function (zoom) {
  178. this.option.zoom = zoom;
  179. };
  180. GraphSeriesModel.prototype.setCenter = function (center) {
  181. this.option.center = center;
  182. };
  183. GraphSeriesModel.prototype.isAnimationEnabled = function () {
  184. return _super.prototype.isAnimationEnabled.call(this)
  185. // Not enable animation when do force layout
  186. && !(this.get('layout') === 'force' && this.get(['force', 'layoutAnimation']));
  187. };
  188. GraphSeriesModel.type = 'series.graph';
  189. GraphSeriesModel.dependencies = ['grid', 'polar', 'geo', 'singleAxis', 'calendar'];
  190. GraphSeriesModel.defaultOption = {
  191. // zlevel: 0,
  192. z: 2,
  193. coordinateSystem: 'view',
  194. // Default option for all coordinate systems
  195. // xAxisIndex: 0,
  196. // yAxisIndex: 0,
  197. // polarIndex: 0,
  198. // geoIndex: 0,
  199. legendHoverLink: true,
  200. layout: null,
  201. // Configuration of circular layout
  202. circular: {
  203. rotateLabel: false
  204. },
  205. // Configuration of force directed layout
  206. force: {
  207. initLayout: null,
  208. // Node repulsion. Can be an array to represent range.
  209. repulsion: [0, 50],
  210. gravity: 0.1,
  211. // Initial friction
  212. friction: 0.6,
  213. // Edge length. Can be an array to represent range.
  214. edgeLength: 30,
  215. layoutAnimation: true
  216. },
  217. left: 'center',
  218. top: 'center',
  219. // right: null,
  220. // bottom: null,
  221. // width: '80%',
  222. // height: '80%',
  223. symbol: 'circle',
  224. symbolSize: 10,
  225. edgeSymbol: ['none', 'none'],
  226. edgeSymbolSize: 10,
  227. edgeLabel: {
  228. position: 'middle',
  229. distance: 5
  230. },
  231. draggable: false,
  232. roam: false,
  233. // Default on center of graph
  234. center: null,
  235. zoom: 1,
  236. // Symbol size scale ratio in roam
  237. nodeScaleRatio: 0.6,
  238. // cursor: null,
  239. // categories: [],
  240. // data: []
  241. // Or
  242. // nodes: []
  243. //
  244. // links: []
  245. // Or
  246. // edges: []
  247. label: {
  248. show: false,
  249. formatter: '{b}'
  250. },
  251. itemStyle: {},
  252. lineStyle: {
  253. color: '#aaa',
  254. width: 1,
  255. opacity: 0.5
  256. },
  257. emphasis: {
  258. scale: true,
  259. label: {
  260. show: true
  261. }
  262. },
  263. select: {
  264. itemStyle: {
  265. borderColor: '#212121'
  266. }
  267. }
  268. };
  269. return GraphSeriesModel;
  270. }(SeriesModel);
  271. export default GraphSeriesModel;