createClipPathFromCoordSys.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 * as graphic from '../../util/graphic';
  41. import { round } from '../../util/number';
  42. function createGridClipPath(cartesian, hasAnimation, seriesModel, done, during) {
  43. var rect = cartesian.getArea();
  44. var x = rect.x;
  45. var y = rect.y;
  46. var width = rect.width;
  47. var height = rect.height;
  48. var lineWidth = seriesModel.get(['lineStyle', 'width']) || 2; // Expand the clip path a bit to avoid the border is clipped and looks thinner
  49. x -= lineWidth / 2;
  50. y -= lineWidth / 2;
  51. width += lineWidth;
  52. height += lineWidth; // fix: https://github.com/apache/incubator-echarts/issues/11369
  53. x = Math.floor(x);
  54. width = Math.round(width);
  55. var clipPath = new graphic.Rect({
  56. shape: {
  57. x: x,
  58. y: y,
  59. width: width,
  60. height: height
  61. }
  62. });
  63. if (hasAnimation) {
  64. var baseAxis = cartesian.getBaseAxis();
  65. var isHorizontal = baseAxis.isHorizontal();
  66. var isAxisInversed = baseAxis.inverse;
  67. if (isHorizontal) {
  68. if (isAxisInversed) {
  69. clipPath.shape.x += width;
  70. }
  71. clipPath.shape.width = 0;
  72. } else {
  73. if (!isAxisInversed) {
  74. clipPath.shape.y += height;
  75. }
  76. clipPath.shape.height = 0;
  77. }
  78. var duringCb = typeof during === 'function' ? function (percent) {
  79. during(percent, clipPath);
  80. } : null;
  81. graphic.initProps(clipPath, {
  82. shape: {
  83. width: width,
  84. height: height,
  85. x: x,
  86. y: y
  87. }
  88. }, seriesModel, null, done, duringCb);
  89. }
  90. return clipPath;
  91. }
  92. function createPolarClipPath(polar, hasAnimation, seriesModel) {
  93. var sectorArea = polar.getArea(); // Avoid float number rounding error for symbol on the edge of axis extent.
  94. var r0 = round(sectorArea.r0, 1);
  95. var r = round(sectorArea.r, 1);
  96. var clipPath = new graphic.Sector({
  97. shape: {
  98. cx: round(polar.cx, 1),
  99. cy: round(polar.cy, 1),
  100. r0: r0,
  101. r: r,
  102. startAngle: sectorArea.startAngle,
  103. endAngle: sectorArea.endAngle,
  104. clockwise: sectorArea.clockwise
  105. }
  106. });
  107. if (hasAnimation) {
  108. var isRadial = polar.getBaseAxis().dim === 'angle';
  109. if (isRadial) {
  110. clipPath.shape.endAngle = sectorArea.startAngle;
  111. } else {
  112. clipPath.shape.r = r0;
  113. }
  114. graphic.initProps(clipPath, {
  115. shape: {
  116. endAngle: sectorArea.endAngle,
  117. r: r
  118. }
  119. }, seriesModel);
  120. }
  121. return clipPath;
  122. }
  123. function createClipPath(coordSys, hasAnimation, seriesModel, done, during) {
  124. if (!coordSys) {
  125. return null;
  126. } else if (coordSys.type === 'polar') {
  127. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  128. } else if (coordSys.type === 'cartesian2d') {
  129. return createGridClipPath(coordSys, hasAnimation, seriesModel, done, during);
  130. }
  131. return null;
  132. }
  133. export { createGridClipPath, createPolarClipPath, createClipPath };