GraphSeries.js 9.6 KB

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