edgeVisual.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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')); // const colorQuery = ['lineStyle', 'color'] as const;
  53. // const opacityQuery = ['lineStyle', 'opacity'] as const;
  54. edgeData.setVisual('fromSymbol', symbolType && symbolType[0]);
  55. edgeData.setVisual('toSymbol', symbolType && symbolType[1]);
  56. edgeData.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  57. edgeData.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  58. edgeData.setVisual('style', seriesModel.getModel('lineStyle').getLineStyle());
  59. edgeData.each(function (idx) {
  60. var itemModel = edgeData.getItemModel(idx);
  61. var edge = graph.getEdgeByIndex(idx);
  62. var symbolType = normalize(itemModel.getShallow('symbol', true));
  63. var symbolSize = normalize(itemModel.getShallow('symbolSize', true)); // Edge visual must after node visual
  64. var style = itemModel.getModel('lineStyle').getLineStyle();
  65. var existsStyle = edgeData.ensureUniqueItemVisual(idx, 'style');
  66. extend(existsStyle, style);
  67. switch (existsStyle.stroke) {
  68. case 'source':
  69. {
  70. var nodeStyle = edge.node1.getVisual('style');
  71. existsStyle.stroke = nodeStyle && nodeStyle.fill;
  72. break;
  73. }
  74. case 'target':
  75. {
  76. var nodeStyle = edge.node2.getVisual('style');
  77. existsStyle.stroke = nodeStyle && nodeStyle.fill;
  78. break;
  79. }
  80. }
  81. symbolType[0] && edge.setVisual('fromSymbol', symbolType[0]);
  82. symbolType[1] && edge.setVisual('toSymbol', symbolType[1]);
  83. symbolSize[0] && edge.setVisual('fromSymbolSize', symbolSize[0]);
  84. symbolSize[1] && edge.setVisual('toSymbolSize', symbolSize[1]);
  85. });
  86. });
  87. }