createClipPathFromCoordSys.js 4.4 KB

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