Animation.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. import Color from "../../Core/Color.js";
  2. import defined from "../../Core/defined.js";
  3. import destroyObject from "../../Core/destroyObject.js";
  4. import DeveloperError from "../../Core/DeveloperError.js";
  5. import getElement from "../getElement.js";
  6. import subscribeAndEvaluate from "../subscribeAndEvaluate.js";
  7. const svgNS = "http://www.w3.org/2000/svg";
  8. const xlinkNS = "http://www.w3.org/1999/xlink";
  9. let widgetForDrag;
  10. const gradientEnabledColor0 = Color.fromCssColorString(
  11. "rgba(247,250,255,0.384)"
  12. );
  13. const gradientEnabledColor1 = Color.fromCssColorString(
  14. "rgba(143,191,255,0.216)"
  15. );
  16. const gradientEnabledColor2 = Color.fromCssColorString(
  17. "rgba(153,197,255,0.098)"
  18. );
  19. const gradientEnabledColor3 = Color.fromCssColorString(
  20. "rgba(255,255,255,0.086)"
  21. );
  22. const gradientDisabledColor0 = Color.fromCssColorString(
  23. "rgba(255,255,255,0.267)"
  24. );
  25. const gradientDisabledColor1 = Color.fromCssColorString("rgba(255,255,255,0)");
  26. const gradientKnobColor = Color.fromCssColorString("rgba(66,67,68,0.3)");
  27. const gradientPointerColor = Color.fromCssColorString("rgba(0,0,0,0.5)");
  28. function getElementColor(element) {
  29. return Color.fromCssColorString(
  30. window.getComputedStyle(element).getPropertyValue("color")
  31. );
  32. }
  33. const svgIconsById = {
  34. animation_pathReset: {
  35. tagName: "path",
  36. transform: "translate(16,16) scale(0.85) translate(-16,-16)",
  37. d:
  38. "M24.316,5.318,9.833,13.682,9.833,5.5,5.5,5.5,5.5,25.5,9.833,25.5,9.833,17.318,24.316,25.682z",
  39. },
  40. animation_pathPause: {
  41. tagName: "path",
  42. transform: "translate(16,16) scale(0.85) translate(-16,-16)",
  43. d: "M13,5.5,7.5,5.5,7.5,25.5,13,25.5zM24.5,5.5,19,5.5,19,25.5,24.5,25.5z",
  44. },
  45. animation_pathPlay: {
  46. tagName: "path",
  47. transform: "translate(16,16) scale(0.85) translate(-16,-16)",
  48. d: "M6.684,25.682L24.316,15.5L6.684,5.318V25.682z",
  49. },
  50. animation_pathPlayReverse: {
  51. tagName: "path",
  52. transform: "translate(16,16) scale(-0.85,0.85) translate(-16,-16)",
  53. d: "M6.684,25.682L24.316,15.5L6.684,5.318V25.682z",
  54. },
  55. animation_pathLoop: {
  56. tagName: "path",
  57. transform: "translate(16,16) scale(0.85) translate(-16,-16)",
  58. d:
  59. "M24.249,15.499c-0.009,4.832-3.918,8.741-8.75,8.75c-2.515,0-4.768-1.064-6.365-2.763l2.068-1.442l-7.901-3.703l0.744,8.694l2.193-1.529c2.244,2.594,5.562,4.242,9.26,4.242c6.767,0,12.249-5.482,12.249-12.249H24.249zM15.499,6.75c2.516,0,4.769,1.065,6.367,2.764l-2.068,1.443l7.901,3.701l-0.746-8.693l-2.192,1.529c-2.245-2.594-5.562-4.245-9.262-4.245C8.734,3.25,3.25,8.734,3.249,15.499H6.75C6.758,10.668,10.668,6.758,15.499,6.75z",
  60. },
  61. animation_pathClock: {
  62. tagName: "path",
  63. transform: "translate(16,16) scale(0.85) translate(-16,-15.5)",
  64. d:
  65. "M15.5,2.374C8.251,2.375,2.376,8.251,2.374,15.5C2.376,22.748,8.251,28.623,15.5,28.627c7.249-0.004,13.124-5.879,13.125-13.127C28.624,8.251,22.749,2.375,15.5,2.374zM15.5,25.623C9.909,25.615,5.385,21.09,5.375,15.5C5.385,9.909,9.909,5.384,15.5,5.374c5.59,0.01,10.115,4.535,10.124,10.125C25.615,21.09,21.091,25.615,15.5,25.623zM8.625,15.5c-0.001-0.552-0.448-0.999-1.001-1c-0.553,0-1,0.448-1,1c0,0.553,0.449,1,1,1C8.176,16.5,8.624,16.053,8.625,15.5zM8.179,18.572c-0.478,0.277-0.642,0.889-0.365,1.367c0.275,0.479,0.889,0.641,1.365,0.365c0.479-0.275,0.643-0.887,0.367-1.367C9.27,18.461,8.658,18.297,8.179,18.572zM9.18,10.696c-0.479-0.276-1.09-0.112-1.366,0.366s-0.111,1.09,0.365,1.366c0.479,0.276,1.09,0.113,1.367-0.366C9.821,11.584,9.657,10.973,9.18,10.696zM22.822,12.428c0.478-0.275,0.643-0.888,0.366-1.366c-0.275-0.478-0.89-0.642-1.366-0.366c-0.479,0.278-0.642,0.89-0.366,1.367C21.732,12.54,22.344,12.705,22.822,12.428zM12.062,21.455c-0.478-0.275-1.089-0.111-1.366,0.367c-0.275,0.479-0.111,1.09,0.366,1.365c0.478,0.277,1.091,0.111,1.365-0.365C12.704,22.344,12.54,21.732,12.062,21.455zM12.062,9.545c0.479-0.276,0.642-0.888,0.366-1.366c-0.276-0.478-0.888-0.642-1.366-0.366s-0.642,0.888-0.366,1.366C10.973,9.658,11.584,9.822,12.062,9.545zM22.823,18.572c-0.48-0.275-1.092-0.111-1.367,0.365c-0.275,0.479-0.112,1.092,0.367,1.367c0.477,0.275,1.089,0.113,1.365-0.365C23.464,19.461,23.3,18.848,22.823,18.572zM19.938,7.813c-0.477-0.276-1.091-0.111-1.365,0.366c-0.275,0.48-0.111,1.091,0.366,1.367s1.089,0.112,1.366-0.366C20.581,8.702,20.418,8.089,19.938,7.813zM23.378,14.5c-0.554,0.002-1.001,0.45-1.001,1c0.001,0.552,0.448,1,1.001,1c0.551,0,1-0.447,1-1C24.378,14.949,23.929,14.5,23.378,14.5zM15.501,6.624c-0.552,0-1,0.448-1,1l-0.466,7.343l-3.004,1.96c-0.478,0.277-0.642,0.889-0.365,1.365c0.275,0.479,0.889,0.643,1.365,0.367l3.305-1.676C15.39,16.99,15.444,17,15.501,17c0.828,0,1.5-0.671,1.5-1.5l-0.5-7.876C16.501,7.072,16.053,6.624,15.501,6.624zM15.501,22.377c-0.552,0-1,0.447-1,1s0.448,1,1,1s1-0.447,1-1S16.053,22.377,15.501,22.377zM18.939,21.455c-0.479,0.277-0.643,0.889-0.366,1.367c0.275,0.477,0.888,0.643,1.366,0.365c0.478-0.275,0.642-0.889,0.366-1.365C20.028,21.344,19.417,21.18,18.939,21.455z",
  66. },
  67. animation_pathWingButton: {
  68. tagName: "path",
  69. d:
  70. "m 4.5,0.5 c -2.216,0 -4,1.784 -4,4 l 0,24 c 0,2.216 1.784,4 4,4 l 13.71875,0 C 22.478584,27.272785 27.273681,22.511272 32.5,18.25 l 0,-13.75 c 0,-2.216 -1.784,-4 -4,-4 l -24,0 z",
  71. },
  72. animation_pathPointer: {
  73. tagName: "path",
  74. d: "M-15,-65,-15,-55,15,-55,15,-65,0,-95z",
  75. },
  76. animation_pathSwooshFX: {
  77. tagName: "path",
  78. d:
  79. "m 85,0 c 0,16.617 -4.813944,35.356 -13.131081,48.4508 h 6.099803 c 8.317138,-13.0948 13.13322,-28.5955 13.13322,-45.2124 0,-46.94483 -38.402714,-85.00262 -85.7743869,-85.00262 -1.0218522,0 -2.0373001,0.0241 -3.0506131,0.0589 45.958443,1.59437 82.723058,35.77285 82.723058,81.70532 z",
  80. },
  81. };
  82. //Dynamically builds an SVG element from a JSON object.
  83. function svgFromObject(obj) {
  84. const ele = document.createElementNS(svgNS, obj.tagName);
  85. for (const field in obj) {
  86. if (obj.hasOwnProperty(field) && field !== "tagName") {
  87. if (field === "children") {
  88. const len = obj.children.length;
  89. for (let i = 0; i < len; ++i) {
  90. ele.appendChild(svgFromObject(obj.children[i]));
  91. }
  92. } else if (field.indexOf("xlink:") === 0) {
  93. ele.setAttributeNS(xlinkNS, field.substring(6), obj[field]);
  94. } else if (field === "textContent") {
  95. ele.textContent = obj[field];
  96. } else {
  97. ele.setAttribute(field, obj[field]);
  98. }
  99. }
  100. }
  101. return ele;
  102. }
  103. function svgText(x, y, msg) {
  104. const text = document.createElementNS(svgNS, "text");
  105. text.setAttribute("x", x);
  106. text.setAttribute("y", y);
  107. text.setAttribute("class", "cesium-animation-svgText");
  108. const tspan = document.createElementNS(svgNS, "tspan");
  109. tspan.textContent = msg;
  110. text.appendChild(tspan);
  111. return text;
  112. }
  113. function setShuttleRingPointer(shuttleRingPointer, knobOuter, angle) {
  114. shuttleRingPointer.setAttribute(
  115. "transform",
  116. `translate(100,100) rotate(${angle})`
  117. );
  118. knobOuter.setAttribute("transform", `rotate(${angle})`);
  119. }
  120. const makeColorStringScratch = new Color();
  121. function makeColorString(background, gradient) {
  122. const gradientAlpha = gradient.alpha;
  123. const backgroundAlpha = 1.0 - gradientAlpha;
  124. makeColorStringScratch.red =
  125. background.red * backgroundAlpha + gradient.red * gradientAlpha;
  126. makeColorStringScratch.green =
  127. background.green * backgroundAlpha + gradient.green * gradientAlpha;
  128. makeColorStringScratch.blue =
  129. background.blue * backgroundAlpha + gradient.blue * gradientAlpha;
  130. return makeColorStringScratch.toCssColorString();
  131. }
  132. function rectButton(x, y, path) {
  133. const iconInfo = svgIconsById[path];
  134. const button = {
  135. tagName: "g",
  136. class: "cesium-animation-rectButton",
  137. transform: `translate(${x},${y})`,
  138. children: [
  139. {
  140. tagName: "rect",
  141. class: "cesium-animation-buttonGlow",
  142. width: 32,
  143. height: 32,
  144. rx: 2,
  145. ry: 2,
  146. },
  147. {
  148. tagName: "rect",
  149. class: "cesium-animation-buttonMain",
  150. width: 32,
  151. height: 32,
  152. rx: 4,
  153. ry: 4,
  154. },
  155. {
  156. class: "cesium-animation-buttonPath",
  157. id: path,
  158. tagName: iconInfo.tagName,
  159. transform: iconInfo.transform,
  160. d: iconInfo.d,
  161. },
  162. {
  163. tagName: "title",
  164. textContent: "",
  165. },
  166. ],
  167. };
  168. return svgFromObject(button);
  169. }
  170. function wingButton(x, y, path) {
  171. const buttonIconInfo = svgIconsById[path];
  172. const wingIconInfo = svgIconsById["animation_pathWingButton"];
  173. const button = {
  174. tagName: "g",
  175. class: "cesium-animation-rectButton",
  176. transform: `translate(${x},${y})`,
  177. children: [
  178. {
  179. class: "cesium-animation-buttonGlow",
  180. id: "animation_pathWingButton",
  181. tagName: wingIconInfo.tagName,
  182. d: wingIconInfo.d,
  183. },
  184. {
  185. class: "cesium-animation-buttonMain",
  186. id: "animation_pathWingButton",
  187. tagName: wingIconInfo.tagName,
  188. d: wingIconInfo.d,
  189. },
  190. {
  191. class: "cesium-animation-buttonPath",
  192. id: path,
  193. tagName: buttonIconInfo.tagName,
  194. transform: buttonIconInfo.transform,
  195. d: buttonIconInfo.d,
  196. },
  197. {
  198. tagName: "title",
  199. textContent: "",
  200. },
  201. ],
  202. };
  203. return svgFromObject(button);
  204. }
  205. function setShuttleRingFromMouseOrTouch(widget, e) {
  206. const viewModel = widget._viewModel;
  207. const shuttleRingDragging = viewModel.shuttleRingDragging;
  208. if (shuttleRingDragging && widgetForDrag !== widget) {
  209. return;
  210. }
  211. if (
  212. e.type === "mousedown" ||
  213. (shuttleRingDragging && e.type === "mousemove") ||
  214. (e.type === "touchstart" && e.touches.length === 1) ||
  215. (shuttleRingDragging && e.type === "touchmove" && e.touches.length === 1)
  216. ) {
  217. const centerX = widget._centerX;
  218. const centerY = widget._centerY;
  219. const svg = widget._svgNode;
  220. const rect = svg.getBoundingClientRect();
  221. let clientX;
  222. let clientY;
  223. if (e.type === "touchstart" || e.type === "touchmove") {
  224. clientX = e.touches[0].clientX;
  225. clientY = e.touches[0].clientY;
  226. } else {
  227. clientX = e.clientX;
  228. clientY = e.clientY;
  229. }
  230. if (
  231. !shuttleRingDragging &&
  232. (clientX > rect.right ||
  233. clientX < rect.left ||
  234. clientY < rect.top ||
  235. clientY > rect.bottom)
  236. ) {
  237. return;
  238. }
  239. const pointerRect = widget._shuttleRingPointer.getBoundingClientRect();
  240. const x = clientX - centerX - rect.left;
  241. const y = clientY - centerY - rect.top;
  242. let angle = (Math.atan2(y, x) * 180) / Math.PI + 90;
  243. if (angle > 180) {
  244. angle -= 360;
  245. }
  246. const shuttleRingAngle = viewModel.shuttleRingAngle;
  247. if (
  248. shuttleRingDragging ||
  249. (clientX < pointerRect.right &&
  250. clientX > pointerRect.left &&
  251. clientY > pointerRect.top &&
  252. clientY < pointerRect.bottom)
  253. ) {
  254. widgetForDrag = widget;
  255. viewModel.shuttleRingDragging = true;
  256. viewModel.shuttleRingAngle = angle;
  257. } else if (angle < shuttleRingAngle) {
  258. viewModel.slower();
  259. } else if (angle > shuttleRingAngle) {
  260. viewModel.faster();
  261. }
  262. e.preventDefault();
  263. } else {
  264. if (widget === widgetForDrag) {
  265. widgetForDrag = undefined;
  266. }
  267. viewModel.shuttleRingDragging = false;
  268. }
  269. }
  270. //This is a private class for treating an SVG element like a button.
  271. //If we ever need a general purpose SVG button, we can make this generic.
  272. function SvgButton(svgElement, viewModel) {
  273. this._viewModel = viewModel;
  274. this.svgElement = svgElement;
  275. this._enabled = undefined;
  276. this._toggled = undefined;
  277. const that = this;
  278. this._clickFunction = function () {
  279. const command = that._viewModel.command;
  280. if (command.canExecute) {
  281. command();
  282. }
  283. };
  284. svgElement.addEventListener("click", this._clickFunction, true);
  285. //TODO: Since the animation widget uses SVG and has no HTML backing,
  286. //we need to wire everything up manually. Knockout can supposedly
  287. //bind to SVG, so we we figure that out we can modify our SVG
  288. //to include the binding information directly.
  289. this._subscriptions = [
  290. //
  291. subscribeAndEvaluate(viewModel, "toggled", this.setToggled, this), //
  292. subscribeAndEvaluate(viewModel, "tooltip", this.setTooltip, this), //
  293. subscribeAndEvaluate(
  294. viewModel.command,
  295. "canExecute",
  296. this.setEnabled,
  297. this
  298. ),
  299. ];
  300. }
  301. SvgButton.prototype.destroy = function () {
  302. this.svgElement.removeEventListener("click", this._clickFunction, true);
  303. const subscriptions = this._subscriptions;
  304. for (let i = 0, len = subscriptions.length; i < len; i++) {
  305. subscriptions[i].dispose();
  306. }
  307. destroyObject(this);
  308. };
  309. SvgButton.prototype.isDestroyed = function () {
  310. return false;
  311. };
  312. SvgButton.prototype.setEnabled = function (enabled) {
  313. if (this._enabled !== enabled) {
  314. this._enabled = enabled;
  315. if (!enabled) {
  316. this.svgElement.setAttribute("class", "cesium-animation-buttonDisabled");
  317. return;
  318. }
  319. if (this._toggled) {
  320. this.svgElement.setAttribute(
  321. "class",
  322. "cesium-animation-rectButton cesium-animation-buttonToggled"
  323. );
  324. return;
  325. }
  326. this.svgElement.setAttribute("class", "cesium-animation-rectButton");
  327. }
  328. };
  329. SvgButton.prototype.setToggled = function (toggled) {
  330. if (this._toggled !== toggled) {
  331. this._toggled = toggled;
  332. if (this._enabled) {
  333. if (toggled) {
  334. this.svgElement.setAttribute(
  335. "class",
  336. "cesium-animation-rectButton cesium-animation-buttonToggled"
  337. );
  338. } else {
  339. this.svgElement.setAttribute("class", "cesium-animation-rectButton");
  340. }
  341. }
  342. }
  343. };
  344. SvgButton.prototype.setTooltip = function (tooltip) {
  345. this.svgElement.getElementsByTagName("title")[0].textContent = tooltip;
  346. };
  347. /**
  348. * <span style="display: block; text-align: center;">
  349. * <img src="Images/AnimationWidget.png" width="211" height="142" alt="" />
  350. * <br />Animation widget
  351. * </span>
  352. * <br /><br />
  353. * The Animation widget provides buttons for play, pause, and reverse, along with the
  354. * current time and date, surrounded by a "shuttle ring" for controlling the speed of animation.
  355. * <br /><br />
  356. * The "shuttle ring" concept is borrowed from video editing, where typically a
  357. * "jog wheel" can be rotated to move past individual animation frames very slowly, and
  358. * a surrounding shuttle ring can be twisted to control direction and speed of fast playback.
  359. * Cesium typically treats time as continuous (not broken into pre-defined animation frames),
  360. * so this widget offers no jog wheel. Instead, the shuttle ring is capable of both fast and
  361. * very slow playback. Click and drag the shuttle ring pointer itself (shown above in green),
  362. * or click in the rest of the ring area to nudge the pointer to the next preset speed in that direction.
  363. * <br /><br />
  364. * The Animation widget also provides a "realtime" button (in the upper-left) that keeps
  365. * animation time in sync with the end user's system clock, typically displaying
  366. * "today" or "right now." This mode is not available in {@link ClockRange.CLAMPED} or
  367. * {@link ClockRange.LOOP_STOP} mode if the current time is outside of {@link Clock}'s startTime and endTime.
  368. *
  369. * @alias Animation
  370. * @constructor
  371. *
  372. * @param {Element|String} container The DOM element or ID that will contain the widget.
  373. * @param {AnimationViewModel} viewModel The view model used by this widget.
  374. *
  375. * @exception {DeveloperError} Element with id "container" does not exist in the document.
  376. *
  377. *
  378. * @example
  379. * // In HTML head, include a link to Animation.css stylesheet,
  380. * // and in the body, include: <div id="animationContainer"></div>
  381. *
  382. * const clock = new Cesium.Clock();
  383. * const clockViewModel = new Cesium.ClockViewModel(clock);
  384. * const viewModel = new Cesium.AnimationViewModel(clockViewModel);
  385. * const widget = new Cesium.Animation('animationContainer', viewModel);
  386. *
  387. * function tick() {
  388. * clock.tick();
  389. * Cesium.requestAnimationFrame(tick);
  390. * }
  391. * Cesium.requestAnimationFrame(tick);
  392. *
  393. * @see AnimationViewModel
  394. * @see Clock
  395. */
  396. function Animation(container, viewModel) {
  397. //>>includeStart('debug', pragmas.debug);
  398. if (!defined(container)) {
  399. throw new DeveloperError("container is required.");
  400. }
  401. if (!defined(viewModel)) {
  402. throw new DeveloperError("viewModel is required.");
  403. }
  404. //>>includeEnd('debug');
  405. container = getElement(container);
  406. this._viewModel = viewModel;
  407. this._container = container;
  408. this._centerX = 0;
  409. this._centerY = 0;
  410. this._defsElement = undefined;
  411. this._svgNode = undefined;
  412. this._topG = undefined;
  413. this._lastHeight = undefined;
  414. this._lastWidth = undefined;
  415. const ownerDocument = container.ownerDocument;
  416. // Firefox requires SVG references to be included directly, not imported from external CSS.
  417. // Also, CSS minifiers get confused by this being in an external CSS file.
  418. const cssStyle = document.createElement("style");
  419. cssStyle.textContent =
  420. ".cesium-animation-rectButton .cesium-animation-buttonGlow { filter: url(#animation_blurred); }\
  421. .cesium-animation-rectButton .cesium-animation-buttonMain { fill: url(#animation_buttonNormal); }\
  422. .cesium-animation-buttonToggled .cesium-animation-buttonMain { fill: url(#animation_buttonToggled); }\
  423. .cesium-animation-rectButton:hover .cesium-animation-buttonMain { fill: url(#animation_buttonHovered); }\
  424. .cesium-animation-buttonDisabled .cesium-animation-buttonMain { fill: url(#animation_buttonDisabled); }\
  425. .cesium-animation-shuttleRingG .cesium-animation-shuttleRingSwoosh { fill: url(#animation_shuttleRingSwooshGradient); }\
  426. .cesium-animation-shuttleRingG:hover .cesium-animation-shuttleRingSwoosh { fill: url(#animation_shuttleRingSwooshHovered); }\
  427. .cesium-animation-shuttleRingPointer { fill: url(#animation_shuttleRingPointerGradient); }\
  428. .cesium-animation-shuttleRingPausePointer { fill: url(#animation_shuttleRingPointerPaused); }\
  429. .cesium-animation-knobOuter { fill: url(#animation_knobOuter); }\
  430. .cesium-animation-knobInner { fill: url(#animation_knobInner); }";
  431. ownerDocument.head.insertBefore(cssStyle, ownerDocument.head.childNodes[0]);
  432. const themeEle = document.createElement("div");
  433. themeEle.className = "cesium-animation-theme";
  434. themeEle.innerHTML =
  435. '<div class="cesium-animation-themeNormal"></div>\
  436. <div class="cesium-animation-themeHover"></div>\
  437. <div class="cesium-animation-themeSelect"></div>\
  438. <div class="cesium-animation-themeDisabled"></div>\
  439. <div class="cesium-animation-themeKnob"></div>\
  440. <div class="cesium-animation-themePointer"></div>\
  441. <div class="cesium-animation-themeSwoosh"></div>\
  442. <div class="cesium-animation-themeSwooshHover"></div>';
  443. this._theme = themeEle;
  444. this._themeNormal = themeEle.childNodes[0];
  445. this._themeHover = themeEle.childNodes[1];
  446. this._themeSelect = themeEle.childNodes[2];
  447. this._themeDisabled = themeEle.childNodes[3];
  448. this._themeKnob = themeEle.childNodes[4];
  449. this._themePointer = themeEle.childNodes[5];
  450. this._themeSwoosh = themeEle.childNodes[6];
  451. this._themeSwooshHover = themeEle.childNodes[7];
  452. const svg = document.createElementNS(svgNS, "svg:svg");
  453. this._svgNode = svg;
  454. // Define the XLink namespace that SVG uses
  455. svg.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", xlinkNS);
  456. const topG = document.createElementNS(svgNS, "g");
  457. this._topG = topG;
  458. this._realtimeSVG = new SvgButton(
  459. wingButton(3, 4, "animation_pathClock"),
  460. viewModel.playRealtimeViewModel
  461. );
  462. this._playReverseSVG = new SvgButton(
  463. rectButton(44, 99, "animation_pathPlayReverse"),
  464. viewModel.playReverseViewModel
  465. );
  466. this._playForwardSVG = new SvgButton(
  467. rectButton(124, 99, "animation_pathPlay"),
  468. viewModel.playForwardViewModel
  469. );
  470. this._pauseSVG = new SvgButton(
  471. rectButton(84, 99, "animation_pathPause"),
  472. viewModel.pauseViewModel
  473. );
  474. const buttonsG = document.createElementNS(svgNS, "g");
  475. buttonsG.appendChild(this._realtimeSVG.svgElement);
  476. buttonsG.appendChild(this._playReverseSVG.svgElement);
  477. buttonsG.appendChild(this._playForwardSVG.svgElement);
  478. buttonsG.appendChild(this._pauseSVG.svgElement);
  479. const shuttleRingBackPanel = svgFromObject({
  480. tagName: "circle",
  481. class: "cesium-animation-shuttleRingBack",
  482. cx: 100,
  483. cy: 100,
  484. r: 99,
  485. });
  486. this._shuttleRingBackPanel = shuttleRingBackPanel;
  487. const swooshIconInfo = svgIconsById["animation_pathSwooshFX"];
  488. const shuttleRingPointerIconInfo = svgIconsById["animation_pathPointer"];
  489. const shuttleRingSwooshG = svgFromObject({
  490. tagName: "g",
  491. class: "cesium-animation-shuttleRingSwoosh",
  492. children: [
  493. {
  494. tagName: swooshIconInfo.tagName,
  495. transform: "translate(100,97) scale(-1,1)",
  496. id: "animation_pathSwooshFX",
  497. d: swooshIconInfo.d,
  498. },
  499. {
  500. tagName: swooshIconInfo.tagName,
  501. transform: "translate(100,97)",
  502. id: "animation_pathSwooshFX",
  503. d: swooshIconInfo.d,
  504. },
  505. {
  506. tagName: "line",
  507. x1: 100,
  508. y1: 8,
  509. x2: 100,
  510. y2: 22,
  511. },
  512. ],
  513. });
  514. this._shuttleRingSwooshG = shuttleRingSwooshG;
  515. this._shuttleRingPointer = svgFromObject({
  516. class: "cesium-animation-shuttleRingPointer",
  517. id: "animation_pathPointer",
  518. tagName: shuttleRingPointerIconInfo.tagName,
  519. d: shuttleRingPointerIconInfo.d,
  520. });
  521. const knobG = svgFromObject({
  522. tagName: "g",
  523. transform: "translate(100,100)",
  524. });
  525. this._knobOuter = svgFromObject({
  526. tagName: "circle",
  527. class: "cesium-animation-knobOuter",
  528. cx: 0,
  529. cy: 0,
  530. r: 71,
  531. });
  532. const knobInnerAndShieldSize = 61;
  533. const knobInner = svgFromObject({
  534. tagName: "circle",
  535. class: "cesium-animation-knobInner",
  536. cx: 0,
  537. cy: 0,
  538. r: knobInnerAndShieldSize,
  539. });
  540. this._knobDate = svgText(0, -24, "");
  541. this._knobTime = svgText(0, -7, "");
  542. this._knobStatus = svgText(0, -41, "");
  543. // widget shield catches clicks on the knob itself (even while DOM elements underneath are changing).
  544. const knobShield = svgFromObject({
  545. tagName: "circle",
  546. class: "cesium-animation-blank",
  547. cx: 0,
  548. cy: 0,
  549. r: knobInnerAndShieldSize,
  550. });
  551. const shuttleRingBackG = document.createElementNS(svgNS, "g");
  552. shuttleRingBackG.setAttribute("class", "cesium-animation-shuttleRingG");
  553. container.appendChild(themeEle);
  554. topG.appendChild(shuttleRingBackG);
  555. topG.appendChild(knobG);
  556. topG.appendChild(buttonsG);
  557. shuttleRingBackG.appendChild(shuttleRingBackPanel);
  558. shuttleRingBackG.appendChild(shuttleRingSwooshG);
  559. shuttleRingBackG.appendChild(this._shuttleRingPointer);
  560. knobG.appendChild(this._knobOuter);
  561. knobG.appendChild(knobInner);
  562. knobG.appendChild(this._knobDate);
  563. knobG.appendChild(this._knobTime);
  564. knobG.appendChild(this._knobStatus);
  565. knobG.appendChild(knobShield);
  566. svg.appendChild(topG);
  567. container.appendChild(svg);
  568. const that = this;
  569. function mouseCallback(e) {
  570. setShuttleRingFromMouseOrTouch(that, e);
  571. }
  572. this._mouseCallback = mouseCallback;
  573. shuttleRingBackPanel.addEventListener("mousedown", mouseCallback, true);
  574. shuttleRingBackPanel.addEventListener("touchstart", mouseCallback, true);
  575. shuttleRingSwooshG.addEventListener("mousedown", mouseCallback, true);
  576. shuttleRingSwooshG.addEventListener("touchstart", mouseCallback, true);
  577. ownerDocument.addEventListener("mousemove", mouseCallback, true);
  578. ownerDocument.addEventListener("touchmove", mouseCallback, true);
  579. ownerDocument.addEventListener("mouseup", mouseCallback, true);
  580. ownerDocument.addEventListener("touchend", mouseCallback, true);
  581. ownerDocument.addEventListener("touchcancel", mouseCallback, true);
  582. this._shuttleRingPointer.addEventListener("mousedown", mouseCallback, true);
  583. this._shuttleRingPointer.addEventListener("touchstart", mouseCallback, true);
  584. this._knobOuter.addEventListener("mousedown", mouseCallback, true);
  585. this._knobOuter.addEventListener("touchstart", mouseCallback, true);
  586. //TODO: Since the animation widget uses SVG and has no HTML backing,
  587. //we need to wire everything up manually. Knockout can supposedly
  588. //bind to SVG, so we we figure that out we can modify our SVG
  589. //to include the binding information directly.
  590. const timeNode = this._knobTime.childNodes[0];
  591. const dateNode = this._knobDate.childNodes[0];
  592. const statusNode = this._knobStatus.childNodes[0];
  593. let isPaused;
  594. this._subscriptions = [
  595. //
  596. subscribeAndEvaluate(viewModel.pauseViewModel, "toggled", function (value) {
  597. if (isPaused !== value) {
  598. isPaused = value;
  599. if (isPaused) {
  600. that._shuttleRingPointer.setAttribute(
  601. "class",
  602. "cesium-animation-shuttleRingPausePointer"
  603. );
  604. } else {
  605. that._shuttleRingPointer.setAttribute(
  606. "class",
  607. "cesium-animation-shuttleRingPointer"
  608. );
  609. }
  610. }
  611. }),
  612. subscribeAndEvaluate(viewModel, "shuttleRingAngle", function (value) {
  613. setShuttleRingPointer(that._shuttleRingPointer, that._knobOuter, value);
  614. }),
  615. subscribeAndEvaluate(viewModel, "dateLabel", function (value) {
  616. if (dateNode.textContent !== value) {
  617. dateNode.textContent = value;
  618. }
  619. }),
  620. subscribeAndEvaluate(viewModel, "timeLabel", function (value) {
  621. if (timeNode.textContent !== value) {
  622. timeNode.textContent = value;
  623. }
  624. }),
  625. subscribeAndEvaluate(viewModel, "multiplierLabel", function (value) {
  626. if (statusNode.textContent !== value) {
  627. statusNode.textContent = value;
  628. }
  629. }),
  630. ];
  631. this.applyThemeChanges();
  632. this.resize();
  633. }
  634. Object.defineProperties(Animation.prototype, {
  635. /**
  636. * Gets the parent container.
  637. *
  638. * @memberof Animation.prototype
  639. * @type {Element}
  640. * @readonly
  641. */
  642. container: {
  643. get: function () {
  644. return this._container;
  645. },
  646. },
  647. /**
  648. * Gets the view model.
  649. *
  650. * @memberof Animation.prototype
  651. * @type {AnimationViewModel}
  652. * @readonly
  653. */
  654. viewModel: {
  655. get: function () {
  656. return this._viewModel;
  657. },
  658. },
  659. });
  660. /**
  661. * @returns {Boolean} true if the object has been destroyed, false otherwise.
  662. */
  663. Animation.prototype.isDestroyed = function () {
  664. return false;
  665. };
  666. /**
  667. * Destroys the animation widget. Should be called if permanently
  668. * removing the widget from layout.
  669. */
  670. Animation.prototype.destroy = function () {
  671. if (defined(this._observer)) {
  672. this._observer.disconnect();
  673. this._observer = undefined;
  674. }
  675. const doc = this._container.ownerDocument;
  676. const mouseCallback = this._mouseCallback;
  677. this._shuttleRingBackPanel.removeEventListener(
  678. "mousedown",
  679. mouseCallback,
  680. true
  681. );
  682. this._shuttleRingBackPanel.removeEventListener(
  683. "touchstart",
  684. mouseCallback,
  685. true
  686. );
  687. this._shuttleRingSwooshG.removeEventListener(
  688. "mousedown",
  689. mouseCallback,
  690. true
  691. );
  692. this._shuttleRingSwooshG.removeEventListener(
  693. "touchstart",
  694. mouseCallback,
  695. true
  696. );
  697. doc.removeEventListener("mousemove", mouseCallback, true);
  698. doc.removeEventListener("touchmove", mouseCallback, true);
  699. doc.removeEventListener("mouseup", mouseCallback, true);
  700. doc.removeEventListener("touchend", mouseCallback, true);
  701. doc.removeEventListener("touchcancel", mouseCallback, true);
  702. this._shuttleRingPointer.removeEventListener(
  703. "mousedown",
  704. mouseCallback,
  705. true
  706. );
  707. this._shuttleRingPointer.removeEventListener(
  708. "touchstart",
  709. mouseCallback,
  710. true
  711. );
  712. this._knobOuter.removeEventListener("mousedown", mouseCallback, true);
  713. this._knobOuter.removeEventListener("touchstart", mouseCallback, true);
  714. this._container.removeChild(this._svgNode);
  715. this._container.removeChild(this._theme);
  716. this._realtimeSVG.destroy();
  717. this._playReverseSVG.destroy();
  718. this._playForwardSVG.destroy();
  719. this._pauseSVG.destroy();
  720. const subscriptions = this._subscriptions;
  721. for (let i = 0, len = subscriptions.length; i < len; i++) {
  722. subscriptions[i].dispose();
  723. }
  724. return destroyObject(this);
  725. };
  726. /**
  727. * Resizes the widget to match the container size.
  728. * This function should be called whenever the container size is changed.
  729. */
  730. Animation.prototype.resize = function () {
  731. const parentWidth = this._container.clientWidth;
  732. const parentHeight = this._container.clientHeight;
  733. if (parentWidth === this._lastWidth && parentHeight === this._lastHeight) {
  734. return;
  735. }
  736. const svg = this._svgNode;
  737. //The width and height as the SVG was originally drawn.
  738. const baseWidth = 200;
  739. const baseHeight = 132;
  740. let width = parentWidth;
  741. let height = parentHeight;
  742. if (parentWidth === 0 && parentHeight === 0) {
  743. width = baseWidth;
  744. height = baseHeight;
  745. } else if (parentWidth === 0) {
  746. height = parentHeight;
  747. width = baseWidth * (parentHeight / baseHeight);
  748. } else if (parentHeight === 0) {
  749. width = parentWidth;
  750. height = baseHeight * (parentWidth / baseWidth);
  751. }
  752. const scaleX = width / baseWidth;
  753. const scaleY = height / baseHeight;
  754. svg.style.cssText = `width: ${width}px; height: ${height}px; position: absolute; bottom: 0; left: 0; overflow: hidden;`;
  755. svg.setAttribute("width", width);
  756. svg.setAttribute("height", height);
  757. svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
  758. this._topG.setAttribute("transform", `scale(${scaleX},${scaleY})`);
  759. this._centerX = Math.max(1, 100.0 * scaleX);
  760. this._centerY = Math.max(1, 100.0 * scaleY);
  761. this._lastHeight = parentWidth;
  762. this._lastWidth = parentHeight;
  763. };
  764. /**
  765. * Updates the widget to reflect any modified CSS rules for theming.
  766. *
  767. * @example
  768. * //Switch to the cesium-lighter theme.
  769. * document.body.className = 'cesium-lighter';
  770. * animation.applyThemeChanges();
  771. */
  772. Animation.prototype.applyThemeChanges = function () {
  773. // Since we rely on computed styles for themeing, we can't actually
  774. // do anything if the container has not yet been added to the DOM.
  775. // Set up an observer to be notified when it is added and apply
  776. // the changes at that time.
  777. const doc = this._container.ownerDocument;
  778. if (!doc.body.contains(this._container)) {
  779. if (defined(this._observer)) {
  780. //Already listening.
  781. return;
  782. }
  783. const that = this;
  784. that._observer = new MutationObserver(function () {
  785. if (doc.body.contains(that._container)) {
  786. that._observer.disconnect();
  787. that._observer = undefined;
  788. that.applyThemeChanges();
  789. }
  790. });
  791. that._observer.observe(doc, { childList: true, subtree: true });
  792. return;
  793. }
  794. const buttonNormalBackColor = getElementColor(this._themeNormal);
  795. const buttonHoverBackColor = getElementColor(this._themeHover);
  796. const buttonToggledBackColor = getElementColor(this._themeSelect);
  797. const buttonDisabledBackColor = getElementColor(this._themeDisabled);
  798. const knobBackColor = getElementColor(this._themeKnob);
  799. const pointerColor = getElementColor(this._themePointer);
  800. const swooshColor = getElementColor(this._themeSwoosh);
  801. const swooshHoverColor = getElementColor(this._themeSwooshHover);
  802. const defsElement = svgFromObject({
  803. tagName: "defs",
  804. children: [
  805. {
  806. id: "animation_buttonNormal",
  807. tagName: "linearGradient",
  808. x1: "50%",
  809. y1: "0%",
  810. x2: "50%",
  811. y2: "100%",
  812. children: [
  813. //add a 'stop-opacity' field to make translucent.
  814. {
  815. tagName: "stop",
  816. offset: "0%",
  817. "stop-color": makeColorString(
  818. buttonNormalBackColor,
  819. gradientEnabledColor0
  820. ),
  821. },
  822. {
  823. tagName: "stop",
  824. offset: "12%",
  825. "stop-color": makeColorString(
  826. buttonNormalBackColor,
  827. gradientEnabledColor1
  828. ),
  829. },
  830. {
  831. tagName: "stop",
  832. offset: "46%",
  833. "stop-color": makeColorString(
  834. buttonNormalBackColor,
  835. gradientEnabledColor2
  836. ),
  837. },
  838. {
  839. tagName: "stop",
  840. offset: "81%",
  841. "stop-color": makeColorString(
  842. buttonNormalBackColor,
  843. gradientEnabledColor3
  844. ),
  845. },
  846. ],
  847. },
  848. {
  849. id: "animation_buttonHovered",
  850. tagName: "linearGradient",
  851. x1: "50%",
  852. y1: "0%",
  853. x2: "50%",
  854. y2: "100%",
  855. children: [
  856. {
  857. tagName: "stop",
  858. offset: "0%",
  859. "stop-color": makeColorString(
  860. buttonHoverBackColor,
  861. gradientEnabledColor0
  862. ),
  863. },
  864. {
  865. tagName: "stop",
  866. offset: "12%",
  867. "stop-color": makeColorString(
  868. buttonHoverBackColor,
  869. gradientEnabledColor1
  870. ),
  871. },
  872. {
  873. tagName: "stop",
  874. offset: "46%",
  875. "stop-color": makeColorString(
  876. buttonHoverBackColor,
  877. gradientEnabledColor2
  878. ),
  879. },
  880. {
  881. tagName: "stop",
  882. offset: "81%",
  883. "stop-color": makeColorString(
  884. buttonHoverBackColor,
  885. gradientEnabledColor3
  886. ),
  887. },
  888. ],
  889. },
  890. {
  891. id: "animation_buttonToggled",
  892. tagName: "linearGradient",
  893. x1: "50%",
  894. y1: "0%",
  895. x2: "50%",
  896. y2: "100%",
  897. children: [
  898. {
  899. tagName: "stop",
  900. offset: "0%",
  901. "stop-color": makeColorString(
  902. buttonToggledBackColor,
  903. gradientEnabledColor0
  904. ),
  905. },
  906. {
  907. tagName: "stop",
  908. offset: "12%",
  909. "stop-color": makeColorString(
  910. buttonToggledBackColor,
  911. gradientEnabledColor1
  912. ),
  913. },
  914. {
  915. tagName: "stop",
  916. offset: "46%",
  917. "stop-color": makeColorString(
  918. buttonToggledBackColor,
  919. gradientEnabledColor2
  920. ),
  921. },
  922. {
  923. tagName: "stop",
  924. offset: "81%",
  925. "stop-color": makeColorString(
  926. buttonToggledBackColor,
  927. gradientEnabledColor3
  928. ),
  929. },
  930. ],
  931. },
  932. {
  933. id: "animation_buttonDisabled",
  934. tagName: "linearGradient",
  935. x1: "50%",
  936. y1: "0%",
  937. x2: "50%",
  938. y2: "100%",
  939. children: [
  940. {
  941. tagName: "stop",
  942. offset: "0%",
  943. "stop-color": makeColorString(
  944. buttonDisabledBackColor,
  945. gradientDisabledColor0
  946. ),
  947. },
  948. {
  949. tagName: "stop",
  950. offset: "75%",
  951. "stop-color": makeColorString(
  952. buttonDisabledBackColor,
  953. gradientDisabledColor1
  954. ),
  955. },
  956. ],
  957. },
  958. {
  959. id: "animation_blurred",
  960. tagName: "filter",
  961. width: "200%",
  962. height: "200%",
  963. x: "-50%",
  964. y: "-50%",
  965. children: [
  966. {
  967. tagName: "feGaussianBlur",
  968. stdDeviation: 4,
  969. in: "SourceGraphic",
  970. },
  971. ],
  972. },
  973. {
  974. id: "animation_shuttleRingSwooshGradient",
  975. tagName: "linearGradient",
  976. x1: "50%",
  977. y1: "0%",
  978. x2: "50%",
  979. y2: "100%",
  980. children: [
  981. {
  982. tagName: "stop",
  983. offset: "0%",
  984. "stop-opacity": 0.2,
  985. "stop-color": swooshColor.toCssColorString(),
  986. },
  987. {
  988. tagName: "stop",
  989. offset: "85%",
  990. "stop-opacity": 0.85,
  991. "stop-color": swooshColor.toCssColorString(),
  992. },
  993. {
  994. tagName: "stop",
  995. offset: "95%",
  996. "stop-opacity": 0.05,
  997. "stop-color": swooshColor.toCssColorString(),
  998. },
  999. ],
  1000. },
  1001. {
  1002. id: "animation_shuttleRingSwooshHovered",
  1003. tagName: "linearGradient",
  1004. x1: "50%",
  1005. y1: "0%",
  1006. x2: "50%",
  1007. y2: "100%",
  1008. children: [
  1009. {
  1010. tagName: "stop",
  1011. offset: "0%",
  1012. "stop-opacity": 0.2,
  1013. "stop-color": swooshHoverColor.toCssColorString(),
  1014. },
  1015. {
  1016. tagName: "stop",
  1017. offset: "85%",
  1018. "stop-opacity": 0.85,
  1019. "stop-color": swooshHoverColor.toCssColorString(),
  1020. },
  1021. {
  1022. tagName: "stop",
  1023. offset: "95%",
  1024. "stop-opacity": 0.05,
  1025. "stop-color": swooshHoverColor.toCssColorString(),
  1026. },
  1027. ],
  1028. },
  1029. {
  1030. id: "animation_shuttleRingPointerGradient",
  1031. tagName: "linearGradient",
  1032. x1: "0%",
  1033. y1: "50%",
  1034. x2: "100%",
  1035. y2: "50%",
  1036. children: [
  1037. {
  1038. tagName: "stop",
  1039. offset: "0%",
  1040. "stop-color": pointerColor.toCssColorString(),
  1041. },
  1042. {
  1043. tagName: "stop",
  1044. offset: "40%",
  1045. "stop-color": pointerColor.toCssColorString(),
  1046. },
  1047. {
  1048. tagName: "stop",
  1049. offset: "60%",
  1050. "stop-color": makeColorString(pointerColor, gradientPointerColor),
  1051. },
  1052. {
  1053. tagName: "stop",
  1054. offset: "100%",
  1055. "stop-color": makeColorString(pointerColor, gradientPointerColor),
  1056. },
  1057. ],
  1058. },
  1059. {
  1060. id: "animation_shuttleRingPointerPaused",
  1061. tagName: "linearGradient",
  1062. x1: "0%",
  1063. y1: "50%",
  1064. x2: "100%",
  1065. y2: "50%",
  1066. children: [
  1067. {
  1068. tagName: "stop",
  1069. offset: "0%",
  1070. "stop-color": "#CCC",
  1071. },
  1072. {
  1073. tagName: "stop",
  1074. offset: "40%",
  1075. "stop-color": "#CCC",
  1076. },
  1077. {
  1078. tagName: "stop",
  1079. offset: "60%",
  1080. "stop-color": "#555",
  1081. },
  1082. {
  1083. tagName: "stop",
  1084. offset: "100%",
  1085. "stop-color": "#555",
  1086. },
  1087. ],
  1088. },
  1089. {
  1090. id: "animation_knobOuter",
  1091. tagName: "linearGradient",
  1092. x1: "20%",
  1093. y1: "0%",
  1094. x2: "90%",
  1095. y2: "100%",
  1096. children: [
  1097. {
  1098. tagName: "stop",
  1099. offset: "5%",
  1100. "stop-color": makeColorString(knobBackColor, gradientEnabledColor0),
  1101. },
  1102. {
  1103. tagName: "stop",
  1104. offset: "60%",
  1105. "stop-color": makeColorString(knobBackColor, gradientKnobColor),
  1106. },
  1107. {
  1108. tagName: "stop",
  1109. offset: "85%",
  1110. "stop-color": makeColorString(knobBackColor, gradientEnabledColor1),
  1111. },
  1112. ],
  1113. },
  1114. {
  1115. id: "animation_knobInner",
  1116. tagName: "linearGradient",
  1117. x1: "20%",
  1118. y1: "0%",
  1119. x2: "90%",
  1120. y2: "100%",
  1121. children: [
  1122. {
  1123. tagName: "stop",
  1124. offset: "5%",
  1125. "stop-color": makeColorString(knobBackColor, gradientKnobColor),
  1126. },
  1127. {
  1128. tagName: "stop",
  1129. offset: "60%",
  1130. "stop-color": makeColorString(knobBackColor, gradientEnabledColor0),
  1131. },
  1132. {
  1133. tagName: "stop",
  1134. offset: "85%",
  1135. "stop-color": makeColorString(knobBackColor, gradientEnabledColor3),
  1136. },
  1137. ],
  1138. },
  1139. ],
  1140. });
  1141. if (!defined(this._defsElement)) {
  1142. this._svgNode.appendChild(defsElement);
  1143. } else {
  1144. this._svgNode.replaceChild(defsElement, this._defsElement);
  1145. }
  1146. this._defsElement = defsElement;
  1147. };
  1148. export default Animation;