ChordView.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. var echarts = require("../../echarts");
  20. var RibbonPath = require("./Ribbon");
  21. var graphic = require("../../util/graphic");
  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. var _default = echarts.extendChartView({
  41. type: 'chord',
  42. init: function (option) {},
  43. render: function (seriesModel, ecModel, api) {
  44. var data = seriesModel.getData();
  45. var graph = seriesModel.getGraph();
  46. var edgeData = seriesModel.getEdgeData();
  47. var group = this.group;
  48. group.removeAll();
  49. data.each(function (idx) {
  50. var layout = data.getItemLayout(idx);
  51. var sector = new graphic.Sector({
  52. shape: {
  53. cx: layout.cx,
  54. cy: layout.cy,
  55. clockwise: layout.clockwise,
  56. r0: layout.r0,
  57. r: layout.r,
  58. startAngle: layout.startAngle,
  59. endAngle: layout.endAngle
  60. }
  61. });
  62. sector.setStyle({
  63. fill: data.getItemVisual(idx, 'color')
  64. });
  65. data.setItemLayout(idx);
  66. group.add(sector);
  67. });
  68. var edgeRendered = {};
  69. edgeData.each(function (idx) {
  70. if (edgeRendered[idx]) {
  71. return;
  72. }
  73. var layout = edgeData.getItemLayout(idx);
  74. var edge = graph.getEdgeByIndex(idx);
  75. var otherEdge = graph.getEdge(edge.node2, edge.node1);
  76. var otherEdgeLayout = otherEdge.getLayout();
  77. edgeRendered[idx] = edgeRendered[otherEdge.dataIndex] = true;
  78. var ribbon = new RibbonPath({
  79. shape: {
  80. cx: layout.cx,
  81. cy: layout.cy,
  82. r: layout.r,
  83. s0: layout.startAngle,
  84. s1: layout.endAngle,
  85. t0: otherEdgeLayout.startAngle,
  86. t1: otherEdgeLayout.endAngle,
  87. clockwise: layout.clockwise
  88. }
  89. });
  90. ribbon.setStyle({
  91. // Use color of source
  92. fill: edge.node1.getVisual('color'),
  93. opacity: 0.5
  94. });
  95. group.add(ribbon);
  96. });
  97. },
  98. dispose: function () {}
  99. });
  100. module.exports = _default;