Animation.js 39 KB

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