Animation.js 39 KB

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