ChordView.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 { __extends } from "tslib";
  41. import * as graphic from '../../util/graphic.js';
  42. import ChartView from '../../view/Chart.js';
  43. import ChordPiece from './ChordPiece.js';
  44. import { ChordEdge } from './ChordEdge.js';
  45. import { parsePercent } from '../../util/number.js';
  46. import { getECData } from '../../util/innerStore.js';
  47. var RADIAN = Math.PI / 180;
  48. var ChordView = /** @class */function (_super) {
  49. __extends(ChordView, _super);
  50. function ChordView() {
  51. var _this = _super !== null && _super.apply(this, arguments) || this;
  52. _this.type = ChordView.type;
  53. return _this;
  54. }
  55. ChordView.prototype.init = function (ecModel, api) {};
  56. ChordView.prototype.render = function (seriesModel, ecModel, api) {
  57. var data = seriesModel.getData();
  58. var oldData = this._data;
  59. var group = this.group;
  60. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  61. data.diff(oldData).add(function (newIdx) {
  62. /* Consider the case when there are only two nodes A and B,
  63. * and there is a link between A and B.
  64. * At first, they are both disselected from legend. And then
  65. * when A is selected, A will go into `add` method. But since
  66. * there are no edges to be displayed, A should not be added.
  67. * So we should only add A when layout is defined.
  68. */
  69. var layout = data.getItemLayout(newIdx);
  70. if (layout) {
  71. var el = new ChordPiece(data, newIdx, startAngle);
  72. getECData(el).dataIndex = newIdx;
  73. group.add(el);
  74. }
  75. }).update(function (newIdx, oldIdx) {
  76. var el = oldData.getItemGraphicEl(oldIdx);
  77. var layout = data.getItemLayout(newIdx);
  78. /* Consider the case when there are only two nodes A and B,
  79. * and there is a link between A and B.
  80. * and when A is disselected from legend, there should be
  81. * nothing to display. But in the `data.diff` method, B will go
  82. * into `update` method and having no layout.
  83. * In this case, we need to remove B.
  84. */
  85. if (!layout) {
  86. el && graphic.removeElementWithFadeOut(el, seriesModel, oldIdx);
  87. return;
  88. }
  89. if (!el) {
  90. el = new ChordPiece(data, newIdx, startAngle);
  91. } else {
  92. el.updateData(data, newIdx, startAngle);
  93. }
  94. group.add(el);
  95. }).remove(function (oldIdx) {
  96. var el = oldData.getItemGraphicEl(oldIdx);
  97. el && graphic.removeElementWithFadeOut(el, seriesModel, oldIdx);
  98. }).execute();
  99. if (!oldData) {
  100. var center = seriesModel.get('center');
  101. this.group.scaleX = 0.01;
  102. this.group.scaleY = 0.01;
  103. this.group.originX = parsePercent(center[0], api.getWidth());
  104. this.group.originY = parsePercent(center[1], api.getHeight());
  105. graphic.initProps(this.group, {
  106. scaleX: 1,
  107. scaleY: 1
  108. }, seriesModel);
  109. }
  110. this._data = data;
  111. this.renderEdges(seriesModel, startAngle);
  112. };
  113. ChordView.prototype.renderEdges = function (seriesModel, startAngle) {
  114. var nodeData = seriesModel.getData();
  115. var edgeData = seriesModel.getEdgeData();
  116. var oldData = this._edgeData;
  117. var group = this.group;
  118. edgeData.diff(oldData).add(function (newIdx) {
  119. var el = new ChordEdge(nodeData, edgeData, newIdx, startAngle);
  120. getECData(el).dataIndex = newIdx;
  121. group.add(el);
  122. }).update(function (newIdx, oldIdx) {
  123. var el = oldData.getItemGraphicEl(oldIdx);
  124. el.updateData(nodeData, edgeData, newIdx, startAngle);
  125. group.add(el);
  126. }).remove(function (oldIdx) {
  127. var el = oldData.getItemGraphicEl(oldIdx);
  128. el && graphic.removeElementWithFadeOut(el, seriesModel, oldIdx);
  129. }).execute();
  130. this._edgeData = edgeData;
  131. };
  132. ChordView.prototype.dispose = function () {};
  133. ChordView.type = 'chord';
  134. return ChordView;
  135. }(ChartView);
  136. export default ChordView;