createClipPathFromCoordSys.js 4.5 KB

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