edgeVisual.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * Licensed to the Apache Software Foundation (ASF) under one
  21. * or more contributor license agreements. See the NOTICE file
  22. * distributed with this work for additional information
  23. * regarding copyright ownership. The ASF licenses this file
  24. * to you under the Apache License, Version 2.0 (the
  25. * "License"); you may not use this file except in compliance
  26. * with the License. You may obtain a copy of the License at
  27. *
  28. * http://www.apache.org/licenses/LICENSE-2.0
  29. *
  30. * Unless required by applicable law or agreed to in writing,
  31. * software distributed under the License is distributed on an
  32. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33. * KIND, either express or implied. See the License for the
  34. * specific language governing permissions and limitations
  35. * under the License.
  36. */
  37. function normalize(a) {
  38. if (!(a instanceof Array)) {
  39. a = [a, a];
  40. }
  41. return a;
  42. }
  43. function _default(ecModel) {
  44. ecModel.eachSeriesByType('graph', function (seriesModel) {
  45. var graph = seriesModel.getGraph();
  46. var edgeData = seriesModel.getEdgeData();
  47. var symbolType = normalize(seriesModel.get('edgeSymbol'));
  48. var symbolSize = normalize(seriesModel.get('edgeSymbolSize'));
  49. var colorQuery = 'lineStyle.color'.split('.');
  50. var opacityQuery = 'lineStyle.opacity'.split('.');
  51. edgeData.setVisual('fromSymbol', symbolType && symbolType[0]);
  52. edgeData.setVisual('toSymbol', symbolType && symbolType[1]);
  53. edgeData.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  54. edgeData.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  55. edgeData.setVisual('color', seriesModel.get(colorQuery));
  56. edgeData.setVisual('opacity', seriesModel.get(opacityQuery));
  57. edgeData.each(function (idx) {
  58. var itemModel = edgeData.getItemModel(idx);
  59. var edge = graph.getEdgeByIndex(idx);
  60. var symbolType = normalize(itemModel.getShallow('symbol', true));
  61. var symbolSize = normalize(itemModel.getShallow('symbolSize', true)); // Edge visual must after node visual
  62. var color = itemModel.get(colorQuery);
  63. var opacity = itemModel.get(opacityQuery);
  64. switch (color) {
  65. case 'source':
  66. color = edge.node1.getVisual('color');
  67. break;
  68. case 'target':
  69. color = edge.node2.getVisual('color');
  70. break;
  71. }
  72. symbolType[0] && edge.setVisual('fromSymbol', symbolType[0]);
  73. symbolType[1] && edge.setVisual('toSymbol', symbolType[1]);
  74. symbolSize[0] && edge.setVisual('fromSymbolSize', symbolSize[0]);
  75. symbolSize[1] && edge.setVisual('toSymbolSize', symbolSize[1]);
  76. edge.setVisual('color', color);
  77. edge.setVisual('opacity', opacity);
  78. });
  79. });
  80. }
  81. module.exports = _default;