edgeVisual.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 { createSimpleOverallStageHandler } from '../../util/model.js';
  41. import { SERIES_TYPE_GRAPH } from './GraphSeries.js';
  42. import { extend } from 'zrender/lib/core/util.js';
  43. function normalize(a) {
  44. if (!(a instanceof Array)) {
  45. a = [a, a];
  46. }
  47. return a;
  48. }
  49. export var graphEdgeVisualStageHandler = createSimpleOverallStageHandler(SERIES_TYPE_GRAPH, graphEdgeVisual);
  50. function graphEdgeVisual(ecModel) {
  51. ecModel.eachSeriesByType(SERIES_TYPE_GRAPH, function (seriesModel) {
  52. var graph = seriesModel.getGraph();
  53. var edgeData = seriesModel.getEdgeData();
  54. var symbolType = normalize(seriesModel.get('edgeSymbol'));
  55. var symbolSize = normalize(seriesModel.get('edgeSymbolSize'));
  56. // const colorQuery = ['lineStyle', 'color'] as const;
  57. // const opacityQuery = ['lineStyle', 'opacity'] as const;
  58. edgeData.setVisual('fromSymbol', symbolType && symbolType[0]);
  59. edgeData.setVisual('toSymbol', symbolType && symbolType[1]);
  60. edgeData.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  61. edgeData.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  62. edgeData.setVisual('style', seriesModel.getModel('lineStyle').getLineStyle());
  63. edgeData.each(function (idx) {
  64. var itemModel = edgeData.getItemModel(idx);
  65. var edge = graph.getEdgeByIndex(idx);
  66. var symbolType = normalize(itemModel.getShallow('symbol', true));
  67. var symbolSize = normalize(itemModel.getShallow('symbolSize', true));
  68. // Edge visual must after node visual
  69. var style = itemModel.getModel('lineStyle').getLineStyle();
  70. var existsStyle = edgeData.ensureUniqueItemVisual(idx, 'style');
  71. extend(existsStyle, style);
  72. switch (existsStyle.stroke) {
  73. case 'source':
  74. {
  75. var nodeStyle = edge.node1.getVisual('style');
  76. existsStyle.stroke = nodeStyle && nodeStyle.fill;
  77. break;
  78. }
  79. case 'target':
  80. {
  81. var nodeStyle = edge.node2.getVisual('style');
  82. existsStyle.stroke = nodeStyle && nodeStyle.fill;
  83. break;
  84. }
  85. }
  86. symbolType[0] && edge.setVisual('fromSymbol', symbolType[0]);
  87. symbolType[1] && edge.setVisual('toSymbol', symbolType[1]);
  88. symbolSize[0] && edge.setVisual('fromSymbolSize', symbolSize[0]);
  89. symbolSize[1] && edge.setVisual('toSymbolSize', symbolSize[1]);
  90. });
  91. });
  92. }