GraphSeries.js 9.4 KB

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