edgeVisual.js 3.7 KB

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