d3-ease.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // https://d3js.org/d3-ease/ v1.0.6 Copyright 2019 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = global || self, factory(global.d3 = global.d3 || {}));
  6. }(this, function (exports) { 'use strict';
  7. function linear(t) {
  8. return +t;
  9. }
  10. function quadIn(t) {
  11. return t * t;
  12. }
  13. function quadOut(t) {
  14. return t * (2 - t);
  15. }
  16. function quadInOut(t) {
  17. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  18. }
  19. function cubicIn(t) {
  20. return t * t * t;
  21. }
  22. function cubicOut(t) {
  23. return --t * t * t + 1;
  24. }
  25. function cubicInOut(t) {
  26. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  27. }
  28. var exponent = 3;
  29. var polyIn = (function custom(e) {
  30. e = +e;
  31. function polyIn(t) {
  32. return Math.pow(t, e);
  33. }
  34. polyIn.exponent = custom;
  35. return polyIn;
  36. })(exponent);
  37. var polyOut = (function custom(e) {
  38. e = +e;
  39. function polyOut(t) {
  40. return 1 - Math.pow(1 - t, e);
  41. }
  42. polyOut.exponent = custom;
  43. return polyOut;
  44. })(exponent);
  45. var polyInOut = (function custom(e) {
  46. e = +e;
  47. function polyInOut(t) {
  48. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  49. }
  50. polyInOut.exponent = custom;
  51. return polyInOut;
  52. })(exponent);
  53. var pi = Math.PI,
  54. halfPi = pi / 2;
  55. function sinIn(t) {
  56. return 1 - Math.cos(t * halfPi);
  57. }
  58. function sinOut(t) {
  59. return Math.sin(t * halfPi);
  60. }
  61. function sinInOut(t) {
  62. return (1 - Math.cos(pi * t)) / 2;
  63. }
  64. function expIn(t) {
  65. return Math.pow(2, 10 * t - 10);
  66. }
  67. function expOut(t) {
  68. return 1 - Math.pow(2, -10 * t);
  69. }
  70. function expInOut(t) {
  71. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  72. }
  73. function circleIn(t) {
  74. return 1 - Math.sqrt(1 - t * t);
  75. }
  76. function circleOut(t) {
  77. return Math.sqrt(1 - --t * t);
  78. }
  79. function circleInOut(t) {
  80. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  81. }
  82. var b1 = 4 / 11,
  83. b2 = 6 / 11,
  84. b3 = 8 / 11,
  85. b4 = 3 / 4,
  86. b5 = 9 / 11,
  87. b6 = 10 / 11,
  88. b7 = 15 / 16,
  89. b8 = 21 / 22,
  90. b9 = 63 / 64,
  91. b0 = 1 / b1 / b1;
  92. function bounceIn(t) {
  93. return 1 - bounceOut(1 - t);
  94. }
  95. function bounceOut(t) {
  96. return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
  97. }
  98. function bounceInOut(t) {
  99. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  100. }
  101. var overshoot = 1.70158;
  102. var backIn = (function custom(s) {
  103. s = +s;
  104. function backIn(t) {
  105. return t * t * ((s + 1) * t - s);
  106. }
  107. backIn.overshoot = custom;
  108. return backIn;
  109. })(overshoot);
  110. var backOut = (function custom(s) {
  111. s = +s;
  112. function backOut(t) {
  113. return --t * t * ((s + 1) * t + s) + 1;
  114. }
  115. backOut.overshoot = custom;
  116. return backOut;
  117. })(overshoot);
  118. var backInOut = (function custom(s) {
  119. s = +s;
  120. function backInOut(t) {
  121. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  122. }
  123. backInOut.overshoot = custom;
  124. return backInOut;
  125. })(overshoot);
  126. var tau = 2 * Math.PI,
  127. amplitude = 1,
  128. period = 0.3;
  129. var elasticIn = (function custom(a, p) {
  130. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  131. function elasticIn(t) {
  132. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  133. }
  134. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  135. elasticIn.period = function(p) { return custom(a, p); };
  136. return elasticIn;
  137. })(amplitude, period);
  138. var elasticOut = (function custom(a, p) {
  139. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  140. function elasticOut(t) {
  141. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  142. }
  143. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  144. elasticOut.period = function(p) { return custom(a, p); };
  145. return elasticOut;
  146. })(amplitude, period);
  147. var elasticInOut = (function custom(a, p) {
  148. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  149. function elasticInOut(t) {
  150. return ((t = t * 2 - 1) < 0
  151. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  152. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  153. }
  154. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  155. elasticInOut.period = function(p) { return custom(a, p); };
  156. return elasticInOut;
  157. })(amplitude, period);
  158. exports.easeBack = backInOut;
  159. exports.easeBackIn = backIn;
  160. exports.easeBackInOut = backInOut;
  161. exports.easeBackOut = backOut;
  162. exports.easeBounce = bounceOut;
  163. exports.easeBounceIn = bounceIn;
  164. exports.easeBounceInOut = bounceInOut;
  165. exports.easeBounceOut = bounceOut;
  166. exports.easeCircle = circleInOut;
  167. exports.easeCircleIn = circleIn;
  168. exports.easeCircleInOut = circleInOut;
  169. exports.easeCircleOut = circleOut;
  170. exports.easeCubic = cubicInOut;
  171. exports.easeCubicIn = cubicIn;
  172. exports.easeCubicInOut = cubicInOut;
  173. exports.easeCubicOut = cubicOut;
  174. exports.easeElastic = elasticOut;
  175. exports.easeElasticIn = elasticIn;
  176. exports.easeElasticInOut = elasticInOut;
  177. exports.easeElasticOut = elasticOut;
  178. exports.easeExp = expInOut;
  179. exports.easeExpIn = expIn;
  180. exports.easeExpInOut = expInOut;
  181. exports.easeExpOut = expOut;
  182. exports.easeLinear = linear;
  183. exports.easePoly = polyInOut;
  184. exports.easePolyIn = polyIn;
  185. exports.easePolyInOut = polyInOut;
  186. exports.easePolyOut = polyOut;
  187. exports.easeQuad = quadInOut;
  188. exports.easeQuadIn = quadIn;
  189. exports.easeQuadInOut = quadInOut;
  190. exports.easeQuadOut = quadOut;
  191. exports.easeSin = sinInOut;
  192. exports.easeSinIn = sinIn;
  193. exports.easeSinInOut = sinInOut;
  194. exports.easeSinOut = sinOut;
  195. Object.defineProperty(exports, '__esModule', { value: true });
  196. }));