EffectPolyline.js 4.3 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 { __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 =
  45. /** @class */
  46. function (_super) {
  47. __extends(EffectPolyline, _super);
  48. function EffectPolyline() {
  49. var _this = _super !== null && _super.apply(this, arguments) || this;
  50. _this._lastFrame = 0;
  51. _this._lastFramePercent = 0;
  52. return _this;
  53. } // Override
  54. EffectPolyline.prototype.createLine = function (lineData, idx, seriesScope) {
  55. return new Polyline(lineData, idx, seriesScope);
  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. ; // Override
  79. EffectPolyline.prototype._getLineLength = function () {
  80. return this._length;
  81. };
  82. ; // Override
  83. EffectPolyline.prototype._updateSymbolPosition = function (symbol) {
  84. var t = symbol.__t < 1 ? symbol.__t : 2 - symbol.__t;
  85. var points = this._points;
  86. var offsets = this._offsets;
  87. var len = points.length;
  88. if (!offsets) {
  89. // Has length 0
  90. return;
  91. }
  92. var lastFrame = this._lastFrame;
  93. var frame;
  94. if (t < this._lastFramePercent) {
  95. // Start from the next frame
  96. // PENDING start from lastFrame ?
  97. var start = Math.min(lastFrame + 1, len - 1);
  98. for (frame = start; frame >= 0; frame--) {
  99. if (offsets[frame] <= t) {
  100. break;
  101. }
  102. } // PENDING really need to do this ?
  103. frame = Math.min(frame, len - 2);
  104. } else {
  105. for (frame = lastFrame; frame < len; frame++) {
  106. if (offsets[frame] > t) {
  107. break;
  108. }
  109. }
  110. frame = Math.min(frame - 1, len - 2);
  111. }
  112. var p = (t - offsets[frame]) / (offsets[frame + 1] - offsets[frame]);
  113. var p0 = points[frame];
  114. var p1 = points[frame + 1];
  115. symbol.x = p0[0] * (1 - p) + p * p1[0];
  116. symbol.y = p0[1] * (1 - p) + p * p1[1];
  117. var tx = symbol.__t < 1 ? p1[0] - p0[0] : p0[0] - p1[0];
  118. var ty = symbol.__t < 1 ? p1[1] - p0[1] : p0[1] - p1[1];
  119. symbol.rotation = -Math.atan2(ty, tx) - Math.PI / 2;
  120. this._lastFrame = frame;
  121. this._lastFramePercent = t;
  122. symbol.ignore = false;
  123. };
  124. ;
  125. return EffectPolyline;
  126. }(EffectLine);
  127. export default EffectPolyline;