EffectPolyline.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 Polyline from './Polyline.js';
  42. import EffectLine from './EffectLine.js';
  43. import * as vec2 from 'zrender/lib/core/vector.js';
  44. var EffectPolyline = /** @class */function (_super) {
  45. __extends(EffectPolyline, _super);
  46. function EffectPolyline() {
  47. var _this = _super !== null && _super.apply(this, arguments) || this;
  48. _this._lastFrame = 0;
  49. _this._lastFramePercent = 0;
  50. return _this;
  51. }
  52. // Override
  53. EffectPolyline.prototype.createLine = function (lineData, idx, seriesScope) {
  54. return new Polyline(lineData, idx, seriesScope);
  55. };
  56. ;
  57. // Override
  58. EffectPolyline.prototype._updateAnimationPoints = function (symbol, points) {
  59. this._points = points;
  60. var accLenArr = [0];
  61. var len = 0;
  62. for (var i = 1; i < points.length; i++) {
  63. var p1 = points[i - 1];
  64. var p2 = points[i];
  65. len += vec2.dist(p1, p2);
  66. accLenArr.push(len);
  67. }
  68. if (len === 0) {
  69. this._length = 0;
  70. return;
  71. }
  72. for (var i = 0; i < accLenArr.length; i++) {
  73. accLenArr[i] /= len;
  74. }
  75. this._offsets = accLenArr;
  76. this._length = len;
  77. };
  78. ;
  79. // Override
  80. EffectPolyline.prototype._getLineLength = function () {
  81. return this._length;
  82. };
  83. ;
  84. // Override
  85. EffectPolyline.prototype._updateSymbolPosition = function (symbol) {
  86. var t = symbol.__t < 1 ? symbol.__t : 2 - symbol.__t;
  87. var points = this._points;
  88. var offsets = this._offsets;
  89. var len = points.length;
  90. if (!offsets) {
  91. // Has length 0
  92. return;
  93. }
  94. var lastFrame = this._lastFrame;
  95. var frame;
  96. if (t < this._lastFramePercent) {
  97. // Start from the next frame
  98. // PENDING start from lastFrame ?
  99. var start = Math.min(lastFrame + 1, len - 1);
  100. for (frame = start; frame >= 0; frame--) {
  101. if (offsets[frame] <= t) {
  102. break;
  103. }
  104. }
  105. // PENDING really need to do this ?
  106. frame = Math.min(frame, len - 2);
  107. } else {
  108. for (frame = lastFrame; frame < len; frame++) {
  109. if (offsets[frame] > t) {
  110. break;
  111. }
  112. }
  113. frame = Math.min(frame - 1, len - 2);
  114. }
  115. var p = (t - offsets[frame]) / (offsets[frame + 1] - offsets[frame]);
  116. var p0 = points[frame];
  117. var p1 = points[frame + 1];
  118. symbol.x = p0[0] * (1 - p) + p * p1[0];
  119. symbol.y = p0[1] * (1 - p) + p * p1[1];
  120. var tx = symbol.__t < 1 ? p1[0] - p0[0] : p0[0] - p1[0];
  121. var ty = symbol.__t < 1 ? p1[1] - p0[1] : p0[1] - p1[1];
  122. symbol.rotation = -Math.atan2(ty, tx) - Math.PI / 2;
  123. this._lastFrame = frame;
  124. this._lastFramePercent = t;
  125. symbol.ignore = false;
  126. };
  127. ;
  128. return EffectPolyline;
  129. }(EffectLine);
  130. export default EffectPolyline;