RGraph.common.effects.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  1. // version: 2014-06-26
  2. /**
  3. * o--------------------------------------------------------------------------------o
  4. * | This file is part of the RGraph package. RGraph is Free Software, licensed |
  5. * | under the MIT license - so it's free to use for all purposes. If you want to |
  6. * | donate to help keep the project going then you can do so here: |
  7. * | |
  8. * | http://www.rgraph.net/donate |
  9. * o--------------------------------------------------------------------------------o
  10. */
  11. /**
  12. * This is a library of a few functions that make it easier to do
  13. * effects like fade-ins or eaxpansion.
  14. */
  15. /**
  16. * Initialise the various objects
  17. */
  18. RGraph = window.RGraph || {isRGraph: true};
  19. RGraph.Effects = RGraph.Effects || {};
  20. RGraph.Effects.Common = {};
  21. // Module pattern
  22. (function (win, doc, undefined)
  23. {
  24. var RG = RGraph,
  25. ua = navigator.userAgent,
  26. ma = Math;
  27. /**
  28. * This functions adds the generic effects to thechart object
  29. *
  30. * @param object obj The chart object
  31. */
  32. RG.Effects.decorate = function (obj)
  33. {
  34. for (i in RG.Effects.Common) {
  35. if (typeof RG.Effects.Common[i] === 'function') {
  36. obj[i] = RG.Effects.Common[i];
  37. }
  38. }
  39. };
  40. /**
  41. * A function used to replace the canvas with a DIV, which in turn holds the canvas. This way the page
  42. * layout doesn't shift in the canvas is resized.
  43. *
  44. * @param object canvas The canvas to replace.
  45. */
  46. RG.Effects.replaceCanvasWithDIV =
  47. RG.Effects.ReplaceCanvasWithDIV =
  48. RG.Effects.wrap = function (canvas)
  49. {
  50. if (!canvas.rgraph_wrapper) {
  51. // Create the place holder DIV
  52. var div = $('<div></div>')
  53. .css({
  54. width: canvas.width + 'px',
  55. height: canvas.height + 'px',
  56. cssFloat: canvas.style.cssFloat,
  57. left: canvas.style.left,
  58. top: canvas.style.top,
  59. display: 'inline-block'
  60. })
  61. .get(0);
  62. // Add the new DIV to the DOM
  63. canvas.parentNode.insertBefore(div, canvas);
  64. // Remove the canvas from the document
  65. canvas.parentNode.removeChild(canvas);
  66. // Add it back in as a child of the place holder
  67. div.appendChild(canvas);
  68. // Reset the positioning information on the canvas
  69. canvas.style.position = 'relative';
  70. canvas.style.left = (div.offsetWidth / 2) + 'px';
  71. canvas.style.top = (div.offsetHeight / 2) + 'px';
  72. canvas.style.cssFloat = '';
  73. // Add a reference to the canvas to the DIV so that repeated plays of the anumation
  74. // don't keep replacing the canvas with a new DIV
  75. canvas.rgraph_wrapper = div;
  76. }
  77. var div = canvas.rgraph_wrapper;
  78. return div;
  79. };
  80. /**
  81. * fadeIn
  82. *
  83. * This function simply uses the CSS opacity property - initially set to zero and
  84. * increasing to 1 over the period of 0.5 second
  85. */
  86. RG.Effects.Common.fadeIn = function ()
  87. {
  88. // This function gets added to the chart object - so the this
  89. // variable is the chart object
  90. var obj = this;
  91. var opt = arguments[0] || {};
  92. var frames = opt.frames || 30;
  93. var duration = (frames / 60) * 1000;
  94. var frame = 0;
  95. var callback = arguments[1] || function () {};
  96. // Initially the opacity should be zero
  97. obj.canvas.style.opacity = 0;
  98. // Draw the chart
  99. RG.redrawCanvas(obj.canvas);
  100. // Now fade the chart in
  101. for (var i=1; i<=frames; ++i) {
  102. (function (index)
  103. {
  104. setTimeout(function ()
  105. {
  106. obj.canvas.style.opacity = (index / frames);
  107. }, (index / frames) * duration);
  108. })(i)
  109. }
  110. setTimeout(function () {callback(obj);}, duration);
  111. return obj;
  112. };
  113. /**
  114. * fadeOut
  115. *
  116. * This function is a reversal of the above function - fading out instead of in
  117. */
  118. RG.Effects.Common.fadeOut = function ()
  119. {
  120. // This function gets added to the chart object - so the this
  121. // variable is the chart object
  122. var obj = this;
  123. var opt = arguments[0] || {};
  124. var frames = opt.frames || 30;
  125. var duration = (frames / 60) * 1000;
  126. var frame = 0;
  127. var callback = arguments[1] || function () {};
  128. // Now fade the chart in
  129. for (var i=1; i<=frames; ++i) {
  130. (function (index)
  131. {
  132. setTimeout(function ()
  133. {
  134. obj.canvas.style.opacity = 1 - (index / frames);
  135. }, (index / frames) * duration);
  136. })(i)
  137. }
  138. setTimeout(function () {callback(obj);}, duration);
  139. return this;
  140. /**
  141. * Callback
  142. */
  143. callback(obj);
  144. };
  145. /**
  146. * fadeSlideIn
  147. *
  148. * This function fades the canvas in in a sliding motion
  149. */
  150. RG.Effects.Common.fadeSlideIn = function ()
  151. {
  152. // This function gets added to the chart object - so the this
  153. // variable is the chart object
  154. var obj = this;
  155. var opt = arguments[0] || {};
  156. var frames = opt.frames || 30;
  157. var frame = 0;
  158. var pc = -20;
  159. var step = (120 - pc) / frames;
  160. var canvasXY = RG.getCanvasXY(obj.canvas);
  161. var color = opt.color || 'white';
  162. var callback = arguments[1] || function () {};
  163. // Draw the chart
  164. RG.redrawCanvas(obj.canvas);
  165. // Create the cover
  166. $('<div id="rgraph_fadeslide_cover_' + obj.id + '"></div>').css({
  167. background: 'linear-gradient(135deg, rgba(255,255,255,0) ' + pc + '%, ' + color + ' ' + (pc + 20) + '%)',
  168. width:obj.canvas.width + 'px',
  169. height: obj.canvas.height + 'px',
  170. top: canvasXY[1] + 'px',
  171. left: canvasXY[0] + 'px',
  172. position: 'absolute'
  173. })
  174. .appendTo($(obj.canvas.parentNode));
  175. function iterator ()
  176. {
  177. if (pc < 120) {
  178. $('div#rgraph_fadeslide_cover_' + obj.id).css({
  179. background: 'linear-gradient(135deg, rgba(255,255,255,0) ' + pc + '%, ' + color + ' ' + (pc + 20) + '%)'
  180. });
  181. pc += step;
  182. RG.Effects.updateCanvas(iterator);
  183. } else {
  184. $('div#rgraph_fadeslide_cover_' + obj.id).remove();
  185. callback(obj);
  186. }
  187. }
  188. iterator();
  189. };
  190. /**
  191. * fadeSlideOut
  192. *
  193. Fades the canvas out in a sliding motion
  194. */
  195. RG.Effects.Common.fadeSlideOut = function ()
  196. {
  197. // This function gets added to the chart object - so the this
  198. // variable is the chart object
  199. var obj = this;
  200. var opt = arguments[0] || {};
  201. var frames = opt.frames || 30;
  202. var frame = 0;
  203. var pc = -20;
  204. var step = (120 - pc) / frames;
  205. var canvasXY = RG.getCanvasXY(obj.canvas);
  206. var color = opt.color || 'white';
  207. var callback = arguments[1] || function () {};
  208. // Draw the chart
  209. RG.redrawCanvas(obj.canvas);
  210. // Create the cover
  211. $('<div id="rgraph_fadeslide_cover_' + obj.id + '"></div>').css({
  212. background: 'linear-gradient(135deg, ' + color + ' ' + pc + '%, rgba(255,255,255,0) ' + (pc + 20) + '%)',
  213. width:obj.canvas.width + 'px',
  214. height: obj.canvas.height + 'px',
  215. top: canvasXY[1] + 'px',
  216. left: canvasXY[0] + 'px',
  217. position: 'absolute'
  218. })
  219. .appendTo($(obj.canvas.parentNode));
  220. function iterator ()
  221. {
  222. if (pc < 120) {
  223. $('div#rgraph_fadeslide_cover_' + obj.id).css({
  224. background: 'linear-gradient(135deg, ' + color + ' ' + pc + '%, rgba(255,255,255,0) ' + (pc + 20) + '%)'
  225. });
  226. pc += step;
  227. RG.Effects.updateCanvas(iterator);
  228. } else {
  229. RG.clear(obj.canvas, color)
  230. $('div#rgraph_fadeslide_cover_' + obj.id).remove();
  231. callback(obj);
  232. }
  233. }
  234. iterator();
  235. };
  236. /**
  237. * fadeCircularIn
  238. *
  239. * This function uses radial CSS gradients to cover the canvas with a radial fade in effect
  240. * (from the center outwards)
  241. */
  242. RG.Effects.Common.fadeCircularInOutwards = function ()
  243. {
  244. // This function gets added to the chart object - so the this
  245. // variable is the chart object
  246. var obj = this;
  247. var opt = arguments[0] || {};
  248. var frames = opt.frames || 120;
  249. var frame = 0;
  250. var radius = 0;
  251. var canvasXY = RG.getCanvasXY(obj.canvas);
  252. var color = opt.color || 'white';
  253. var callback = arguments[1] || function () {};
  254. // Draw the chart
  255. RG.redrawCanvas(obj.canvas);
  256. // Create the cover
  257. $('<div id="rgraph_fadeslide_cover_' + obj.id + '"></div>').css({
  258. background: 'radial-gradient(rgba(255,255,255,0) 0%, white ' + radius + '%)',
  259. width:obj.canvas.width + 'px',
  260. height: obj.canvas.height + 'px',
  261. top: canvasXY[1] + 'px',
  262. left: canvasXY[0] + 'px',
  263. position: 'absolute'
  264. })
  265. .appendTo($(obj.canvas.parentNode));
  266. function iterator ()
  267. {
  268. if (frame < frames) {
  269. $('div#rgraph_fadeslide_cover_' + obj.id).css({
  270. background: 'radial-gradient(rgba(255,255,255,0) ' + ((frame++ / frames) * 100) + '%, ' + color + ' ' + ((frame++ / frames) * 150) + '%)'
  271. });
  272. RG.Effects.updateCanvas(iterator);
  273. } else {
  274. $('div#rgraph_fadeslide_cover_' + obj.id).remove();
  275. callback(obj);
  276. }
  277. }
  278. iterator();
  279. };
  280. /**
  281. * fadeCircularOut
  282. *
  283. * This function uses radial CSS gradients to cover the canvas with a radial fade out effect
  284. * (from the center outwards)
  285. */
  286. RG.Effects.Common.fadeCircularOutOutwards = function ()
  287. {
  288. // This function gets added to the chart object - so the this
  289. // variable is the chart object
  290. var obj = this;
  291. var opt = arguments[0] || {};
  292. var frames = opt.frames || 120;
  293. var frame = 0;
  294. var canvasXY = RG.getCanvasXY(obj.canvas);
  295. var color = opt.color || 'white';
  296. var callback = arguments[1] || function () {};
  297. // Draw the chart
  298. RG.redrawCanvas(obj.canvas);
  299. // Create the cover
  300. $('<div id="rgraph_fadeslide_cover_' + obj.id + '"></div>').css({
  301. background: 'radial-gradient(rgba(255,255,255,0) 0%, white 0%)',
  302. width:obj.canvas.width + 'px',
  303. height: obj.canvas.height + 'px',
  304. top: canvasXY[1] + 'px',
  305. left: canvasXY[0] + 'px',
  306. position: 'absolute'
  307. })
  308. .appendTo($(obj.canvas.parentNode));
  309. function iterator ()
  310. {
  311. if (frame < frames) {
  312. $('div#rgraph_fadeslide_cover_' + obj.id).css({
  313. background: 'radial-gradient(' + color + ' ' + ((frame++ / frames) * 100) + '%, rgba(255,255,255,0) ' + ((frame++ / frames) * 150) + '%)'
  314. });
  315. RG.Effects.updateCanvas(iterator);
  316. } else {
  317. RG.clear(obj.canvas, color);
  318. $('div#rgraph_fadeslide_cover_' + obj.id).remove();
  319. callback(obj);
  320. }
  321. }
  322. iterator();
  323. };
  324. /**
  325. * fadeCircularInInwards
  326. */
  327. RG.Effects.Common.fadeCircularInInwards = function ()
  328. {
  329. // This function gets added to the chart object - so the this
  330. // variable is the chart object
  331. var obj = this;
  332. var opt = arguments[0] || {};
  333. var frames = opt.frames || 120;
  334. var frame = 0;
  335. var radius = ma.max(obj.canvas.width, obj.canvas.height);
  336. var canvasXY = RG.getCanvasXY(obj.canvas);
  337. var color = opt.color || 'white';
  338. var callback = arguments[1] || function () {};
  339. // Draw the chart
  340. RG.redrawCanvas(obj.canvas);
  341. // Create the cover
  342. $('<div id="rgraph_fadeslide_cover_' + obj.id + '"></div>').css({
  343. background: 'radial-gradient(rgba(255,255,255,0) 100%, rgba(255,255,255,0) 0%)',
  344. width:obj.canvas.width + 'px',
  345. height: obj.canvas.height + 'px',
  346. top: canvasXY[1] + 'px',
  347. left: canvasXY[0] + 'px',
  348. position: 'absolute'
  349. })
  350. .appendTo($(obj.canvas.parentNode));
  351. function iterator ()
  352. {
  353. if (frame < frames) {
  354. $('div#rgraph_fadeslide_cover_' + obj.id).css({
  355. background: 'radial-gradient(' + color + ' ' + (( (frames - frame++) / frames) * 100) + '%, rgba(255,255,255,0) ' + (( (frames - frame++) / frames) * 120) + '%)'
  356. });
  357. RG.Effects.updateCanvas(iterator);
  358. } else {
  359. $('div#rgraph_fadeslide_cover_' + obj.id).remove();
  360. callback(obj);
  361. }
  362. }
  363. iterator();
  364. };
  365. /**
  366. * fadeCircularOutReverse
  367. */
  368. RG.Effects.Common.fadeCircularOutInwards = function ()
  369. {
  370. // This function gets added to the chart object - so the this
  371. // variable is the chart object
  372. var obj = this;
  373. var opt = arguments[0] || {};
  374. var frames = opt.frames || 120;
  375. var frame = 0;
  376. var radius = ma.max(obj.canvas.width, obj.canvas.height);
  377. var canvasXY = RG.getCanvasXY(obj.canvas);
  378. var color = opt.color || 'white';
  379. var callback = arguments[1] || function () {};
  380. // Draw the chart
  381. RG.redrawCanvas(obj.canvas);
  382. // Create the cover
  383. $('<div id="rgraph_fadeslide_cover_' + obj.id + '"></div>').css({
  384. background: 'radial-gradient(rgba(255,255,255,0) 0%, rgba(255,255,255,0) 0%)',
  385. width:obj.canvas.width + 'px',
  386. height: obj.canvas.height + 'px',
  387. top: canvasXY[1] + 'px',
  388. left: canvasXY[0] + 'px',
  389. position: 'absolute'
  390. })
  391. .appendTo($(obj.canvas.parentNode));
  392. function iterator ()
  393. {
  394. if (frame < frames) {
  395. $('div#rgraph_fadeslide_cover_' + obj.id).css({
  396. background: 'radial-gradient(rgba(255,255,255,0) ' + (( (frames - frame++) / frames) * 100) + '%, ' + color + ' ' + (( (frames - frame++) / frames) * 120) + '%)'
  397. });
  398. RG.Effects.updateCanvas(iterator);
  399. } else {
  400. RG.clear(obj.canvas);
  401. $('div#rgraph_fadeslide_cover_' + obj.id).remove();
  402. callback(obj);
  403. }
  404. }
  405. iterator();
  406. };
  407. /**
  408. * Expand
  409. *
  410. * This effect is like the tooltip effect of the same name. I starts in the middle
  411. * and expands out to full size.
  412. *
  413. * @param object obj The graph object
  414. */
  415. RG.Effects.Common.expand = function ()
  416. {
  417. // This function gets added to the chart object - so the this
  418. // variable is the chart object
  419. var obj = this;
  420. var opt = arguments[0] || {};
  421. var bounce = typeof opt.bounce === 'boolean' ? opt.bounce : true;
  422. var frames = opt.frames || 60;
  423. var duration = (frames / 60) * 1000;
  424. var callback = arguments[1] || function () {};
  425. if (!this.canvas.rgraph_wrapper) {
  426. var div = RG.Effects.wrap(this.canvas);
  427. this.canvas.rgraph_wrapper = div;
  428. } else {
  429. div = this.canvas.rgraph_wrapper;
  430. }
  431. div.style.position = 'relative';
  432. //this.canvas.style.position = 'relative'; // absolute should work here too - but doesn't in Chrome
  433. this.canvas.style.top = (this.canvas.height / 2) + 'px';
  434. this.canvas.style.left = (this.canvas.width / 2) + 'px';
  435. this.canvas.style.width = 0;
  436. this.canvas.style.height = 0;
  437. this.canvas.style.opacity = 0;
  438. RG.clear(this.canvas);
  439. RG.redrawCanvas(this.canvas);
  440. if (bounce) {
  441. jQuery('#' + obj.id).animate({opacity: 1, width: (obj.canvas.width * 1.2) + 'px', height: (obj.canvas.height * 1.2) + 'px', left: (obj.canvas.width * -0.1) + 'px', top: (obj.canvas.height * -0.1) + 'px'}, duration * 0.5, function ()
  442. {
  443. jQuery('#' + obj.id).animate({width: (obj.canvas.width * 0.9) + 'px', height: (obj.canvas.height * 0.9) + 'px', top: (obj.canvas.height * 0.05) + 'px', left: (obj.canvas.width * 0.05) + 'px'}, duration * 0.25, function ()
  444. {
  445. jQuery('#' + obj.id).animate({width: obj.canvas.width + 'px', height: obj.canvas.height + 'px', top: 0, left: 0}, duration * 0.25, function () {callback(obj);});
  446. });
  447. });
  448. } else {
  449. jQuery(obj.canvas).animate({
  450. opacity: 1,
  451. width: obj.canvas.width + 'px',
  452. height: obj.canvas.height + 'px',
  453. left: 0,
  454. top: 0
  455. }, duration, function () {callback(obj);})
  456. }
  457. return this;
  458. };
  459. /**
  460. * Contract
  461. *
  462. * This effect is a good one to use with the Expand effect to make a transition
  463. *
  464. * @param object You can specify frames here: {frames: 120}
  465. * @param function Optional callback to run when the effect is done.
  466. */
  467. RG.Effects.Common.contract = function ()
  468. {
  469. // This function gets added to the chart object - so the this
  470. // variable is the chart object
  471. var obj = this;
  472. var opt = arguments[0] || {};
  473. var frames = opt.frames || 60;
  474. var duration = (frames / 60) * 1000;
  475. var callback = arguments[1] || function () {};
  476. if (!obj.canvas.rgraph_wrapper) {
  477. var div = RG.Effects.wrap(obj.canvas);
  478. obj.canvas.rgraph_wrapper = div;
  479. } else {
  480. div = obj.canvas.rgraph_wrapper;
  481. }
  482. div.style.position = 'relative';
  483. //canvas.style.position = 'absolute'; // Chrome bug...?
  484. obj.canvas.style.top = 0;
  485. obj.canvas.style.left = 0;
  486. jQuery('#' + obj.id).animate({
  487. width: (obj.canvas.width * 1.2) + 'px',
  488. height: (obj.canvas.height * 1.2) + 'px',
  489. left: (obj.canvas.width * -0.1) + 'px',
  490. top: (obj.canvas.height * -0.1) + 'px'
  491. }, duration * 0.25, function ()
  492. {
  493. jQuery('#' + obj.id).animate({
  494. opacity: 0,
  495. width: 0,
  496. height: 0,
  497. left: (obj.canvas.width * 0.5) + 'px',
  498. top: (obj.canvas.height * 0.5) + 'px'
  499. }, duration * 0.75, function () {callback(obj);});
  500. });
  501. return this;
  502. };
  503. /**
  504. * Reveal
  505. *
  506. * This effect issmilar to the Expand effect - the canvas is slowly revealed from
  507. * the centre outwards
  508. *
  509. * @param object Options for the effect. You can give frames here
  510. * @param function An optional callback function
  511. */
  512. RG.Effects.Common.reveal = function ()
  513. {
  514. // This function gets added to the chart object - so the this
  515. // variable is the chart object
  516. var obj = this;
  517. var opt = arguments[0] || {};
  518. var frames = opt.frames || 60;
  519. var duration = (frames / 60) * 1000;
  520. var callback = arguments[1] || function () {};
  521. var xy = RG.getCanvasXY(obj.canvas);
  522. var divs = [
  523. ['rgraph_reveal_left_' + obj.id, xy[0], xy[1], obj.canvas.width / 2, obj.canvas.height],
  524. ['rgraph_reveal_right_' + obj.id,(xy[0] + (obj.canvas.width / 2)),xy[1],(obj.canvas.width / 2),obj.canvas.height],
  525. ['rgraph_reveal_top_' + obj.id,xy[0],xy[1],obj.canvas.width,(obj.canvas.height / 2)],
  526. ['rgraph_reveal_bottom_' + obj.id,xy[0],(xy[1] + (obj.canvas.height / 2)),obj.canvas.width,(obj.canvas.height / 2)]
  527. ];
  528. for (var i=0,len=divs.length; i<len; ++i) {
  529. var div = document.createElement('DIV');
  530. div.id = divs[i][0];
  531. div.style.width = divs[i][3]+ 'px';
  532. div.style.height = divs[i][4] + 'px';
  533. div.style.left = divs[i][1] + 'px';
  534. div.style.top = divs[i][2] + 'px';
  535. div.style.position = 'absolute';
  536. div.style.backgroundColor = opt && typeof opt.color === 'string' ? opt.color : 'white';
  537. document.body.appendChild(div);
  538. }
  539. // Clear the canvas and redraw it
  540. RG.clear(obj.canvas);
  541. RG.redrawCanvas(obj.canvas);
  542. // Animate the shrinking of the DIVs
  543. jQuery('#rgraph_reveal_left_' + obj.id).animate({width: 0}, duration);
  544. jQuery('#rgraph_reveal_right_' + obj.id).animate({left: '+=' + (obj.canvas.width / 2),width: 0}, duration);
  545. jQuery('#rgraph_reveal_top_' + obj.id).animate({height: 0}, duration);
  546. jQuery('#rgraph_reveal_bottom_' + obj.id).animate({top: '+=' + (obj.canvas.height / 2),height: 0}, duration);
  547. // Remove the DIVs from the DOM 100ms after the animation ends
  548. setTimeout(function ()
  549. {
  550. doc.body.removeChild(doc.getElementById("rgraph_reveal_top_" + obj.id));
  551. doc.body.removeChild(doc.getElementById("rgraph_reveal_bottom_" + obj.id));
  552. doc.body.removeChild(doc.getElementById("rgraph_reveal_left_" + obj.id));
  553. doc.body.removeChild(doc.getElementById("rgraph_reveal_right_" + obj.id));
  554. callback(obj);
  555. }, duration);
  556. return this;
  557. };
  558. /**
  559. * RevealCircular
  560. *
  561. * This effect is smilar to the Reveal effect - the canvas is slowly revealed from
  562. * the centre outwards using a circular shape
  563. *
  564. * @param object An object of options - eg {frames: 30}
  565. * @param function An optional callback function that runs when the effect is finished
  566. */
  567. RG.Effects.Common.revealCircular =
  568. RG.Effects.Common.revealcircular = function ()
  569. {
  570. // This function gets added to the chart object - so the this
  571. // variable is the chart object
  572. var obj = this;
  573. var opt = arguments[0] || {};
  574. var frames = opt.frames || 30;
  575. var frame = 0;
  576. var callback = arguments[1] || function () {};
  577. var currentRadius = 0
  578. var centerx = obj.canvas.width / 2;
  579. var centery = obj.canvas.height / 2;
  580. var targetRadius = ma.max(obj.canvas.height, obj.canvas.width);
  581. var step = targetRadius / frames;
  582. var color = opt.background || opt.color || opt.backgroundColor || 'transparent';
  583. /**
  584. * This is the iterator function which gradually increases the radius of the clip circle
  585. */
  586. function iterator ()
  587. {
  588. // Begin by clearing the canvas
  589. RG.clear(obj.canvas, color);
  590. obj.context.save();
  591. // First draw the circle and clip to it
  592. obj.context.beginPath();
  593. obj.context.arc(centerx, centery, currentRadius, 0, RG.TWOPI, false);
  594. obj.context.clip();
  595. // Clear the canvas to a white color
  596. if (opt.background) {
  597. RG.clear(obj.canvas, opt.background);
  598. }
  599. // Now draw the chart
  600. obj.Draw();
  601. obj.context.restore();
  602. // Increment the radius
  603. if (currentRadius < targetRadius) {
  604. currentRadius += step;
  605. RG.Effects.updateCanvas(iterator);
  606. } else {
  607. callback(obj);
  608. }
  609. }
  610. iterator();
  611. return this;
  612. };
  613. /**
  614. * Conceal
  615. *
  616. * This effect is the reverse of the Reveal effect - instead of revealing the canvas it
  617. * conceals it. Combined with the reveal effect would make for a nice wipe effect.
  618. *
  619. * @param object obj The chart object
  620. */
  621. RG.Effects.Common.conceal = function ()
  622. {
  623. // This function gets added to the chart object - so the this
  624. // variable is the chart object
  625. var obj = this;
  626. var opt = arguments[0] || {};
  627. var frames = opt.frames || 60;
  628. var duration = (frames / 60) * 1000;
  629. var frame = 0;
  630. var callback = arguments[1] || function () {};
  631. var xy = RG.getCanvasXY(obj.canvas);
  632. var color = opt.background || opt.color || opt.backgroundColor || 'white';
  633. var divs = [
  634. ['rgraph_conceal_left_' + obj.id, xy[0], xy[1], 0, obj.canvas.height],
  635. ['rgraph_conceal_right_' + obj.id,(xy[0] + obj.canvas.width),xy[1],0,obj.canvas.height],
  636. ['rgraph_conceal_top_' + obj.id,xy[0],xy[1],obj.canvas.width,0],
  637. ['rgraph_conceal_bottom_' + obj.id,xy[0],(xy[1] + obj.canvas.height),obj.canvas.width,0]
  638. ];
  639. for (var i=0,len=divs.length; i<len; ++i) {
  640. var div = doc.createElement('DIV');
  641. div.id = divs[i][0];
  642. div.style.width = divs[i][3]+ 'px';
  643. div.style.height = divs[i][4] + 'px';
  644. div.style.left = divs[i][1] + 'px';
  645. div.style.top = divs[i][2] + 'px';
  646. div.style.position = 'absolute';
  647. div.style.backgroundColor = color;
  648. doc.body.appendChild(div);
  649. }
  650. jQuery('#rgraph_conceal_left_' + obj.id).animate({width: '+=' + (obj.canvas.width / 2)}, duration);
  651. jQuery('#rgraph_conceal_right_' + obj.id).animate({left: '-=' + (obj.canvas.width / 2),width: (obj.canvas.width / 2)}, duration);
  652. jQuery('#rgraph_conceal_top_' + obj.id).animate({height: '+=' + (obj.canvas.height / 2)}, duration);
  653. jQuery('#rgraph_conceal_bottom_' + obj.id).animate({top: '-=' + (obj.canvas.height / 2),height: (obj.canvas.height / 2)}, duration);
  654. // Remove the DIVs from the DOM 100ms after the animation ends
  655. setTimeout(
  656. function ()
  657. {
  658. doc.body.removeChild(doc.getElementById("rgraph_conceal_top_" + obj.id));
  659. doc.body.removeChild(doc.getElementById("rgraph_conceal_bottom_" + obj.id));
  660. doc.body.removeChild(doc.getElementById("rgraph_conceal_left_" + obj.id));
  661. doc.body.removeChild(doc.getElementById("rgraph_conceal_right_" + obj.id));
  662. RG.clear(obj.canvas, color);
  663. callback(obj);
  664. }, duration);
  665. return this;
  666. };
  667. /**
  668. * Horizontal Blinds (open)
  669. *
  670. * @params object obj The graph object
  671. */
  672. RG.Effects.Common.hBlindsOpen =
  673. RG.Effects.Common.hblindsOpen = function ()
  674. {
  675. // This function gets added to the chart object - so the this
  676. // variable is the chart object
  677. var obj = this;
  678. var opt = arguments[0] || {};
  679. var frames = opt.frames || 60;
  680. var duration = (frames / 60) * 1000;
  681. var frame = 0;
  682. var callback = arguments[1] || function () {};
  683. var xy = RG.getCanvasXY(obj.canvas);
  684. var color = opt.background || opt.color || opt.backgroundColor || 'white';
  685. var xy = RG.getCanvasXY(this.canvas);
  686. var height = this.canvas.height / 5;
  687. /**
  688. * First draw the chart
  689. */
  690. RG.clear(this.canvas);
  691. RG.redrawCanvas(this.canvas);
  692. for (var i=0; i<5; ++i) {
  693. var div = doc.createElement('DIV');
  694. div.id = 'rgraph_hblinds_' + i + '_' + obj.id;
  695. div.style.width = this.canvas.width + 'px';
  696. div.style.height = height + 'px';
  697. div.style.left = xy[0] + 'px';
  698. div.style.top = (xy[1] + (this.canvas.height * (i / 5))) + 'px';
  699. div.style.position = 'absolute';
  700. div.style.backgroundColor = color;
  701. document.body.appendChild(div);
  702. jQuery('#rgraph_hblinds_' + i + '_' + obj.id).animate({height: 0}, duration);
  703. }
  704. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_hblinds_0_' + obj.id));}, duration);
  705. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_hblinds_1_' + obj.id));}, duration);
  706. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_hblinds_2_' + obj.id));}, duration);
  707. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_hblinds_3_' + obj.id));}, duration);
  708. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_hblinds_4_' + obj.id));}, duration);
  709. setTimeout(function () {callback(obj);}, duration);
  710. return this;
  711. };
  712. /**
  713. * Horizontal Blinds (close)
  714. *
  715. * @params object obj The graph object
  716. */
  717. RG.Effects.Common.hBlindsClose =
  718. RG.Effects.Common.hblindsclose = function ()
  719. {
  720. // This function gets added to the chart object - so the this
  721. // variable is the chart object
  722. var obj = this;
  723. var opt = arguments[0] || {};
  724. var frames = opt.frames || 60;
  725. var duration = (frames / 60) * 1000;
  726. var frame = 0;
  727. var callback = arguments[1] || function () {};
  728. var xy = RG.getCanvasXY(obj.canvas);
  729. var color = opt.background || opt.color || opt.backgroundColor || 'white';
  730. var xy = RG.getCanvasXY(this.canvas);
  731. var height = this.canvas.height / 5;
  732. for (var i=0; i<5; ++i) {
  733. var div = doc.createElement('DIV');
  734. div.id = 'rgraph_hblinds_' + i + '_' + obj.id;
  735. div.style.width = this.canvas.width + 'px';
  736. div.style.height = 0;
  737. div.style.left = xy[0] + 'px';
  738. div.style.top = (xy[1] + (this.canvas.height * (i / 5))) + 'px';
  739. div.style.position = 'absolute';
  740. div.style.backgroundColor = color;
  741. doc.body.appendChild(div);
  742. jQuery('#rgraph_hblinds_' + i + '_' + obj.id).animate({height: height + 'px'}, duration);
  743. }
  744. setTimeout(function () {RG.clear(obj.canvas);}, duration + 100);
  745. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_hblinds_0_' + obj.id));}, duration + 100);
  746. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_hblinds_1_' + obj.id));}, duration + 100);
  747. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_hblinds_2_' + obj.id));}, duration + 100);
  748. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_hblinds_3_' + obj.id));}, duration + 100);
  749. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_hblinds_4_' + obj.id));}, duration + 100);
  750. setTimeout(function () {callback(obj);}, duration + 100);
  751. };
  752. /**
  753. * Vertical Blinds (open)
  754. *
  755. * @params object obj The graph object
  756. */
  757. RG.Effects.Common.vBlindsOpen =
  758. RG.Effects.Common.vblindsopen = function ()
  759. {
  760. // This function gets added to the chart object - so the this
  761. // variable is the chart object
  762. var obj = this;
  763. var opt = arguments[0] || {};
  764. var frames = opt.frames || 60;
  765. var duration = (frames / 60) * 1000;
  766. var frame = 0;
  767. var callback = arguments[1] || function () {};
  768. var xy = RG.getCanvasXY(obj.canvas);
  769. var color = opt.background || opt.color || opt.backgroundColor || 'white';
  770. var xy = RG.getCanvasXY(this.canvas);
  771. var width = this.canvas.width / 10;
  772. /**
  773. * First draw the chart
  774. */
  775. //RG.clear(obj.canvas);
  776. RG.redrawCanvas(obj.canvas);
  777. for (var i=0; i<10; ++i) {
  778. var div = doc.createElement('DIV');
  779. div.id = 'rgraph_vblinds_' + i + '_' + obj.id;
  780. div.style.width = width + 'px';
  781. div.style.height = this.canvas.height + 'px';
  782. div.style.left = (xy[0] + (this.canvas.width * (i / 10))) + 'px';
  783. div.style.top = (xy[1]) + 'px';
  784. div.style.position = 'absolute';
  785. div.style.backgroundColor = color;
  786. doc.body.appendChild(div);
  787. jQuery('#rgraph_vblinds_' + i + '_' + obj.id).animate({width: 0}, duration);
  788. }
  789. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_0_' + obj.id));}, duration + 100);
  790. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_1_' + obj.id));}, duration + 100);
  791. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_2_' + obj.id));}, duration + 100);
  792. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_3_' + obj.id));}, duration + 100);
  793. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_4_' + obj.id));}, duration + 100);
  794. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_5_' + obj.id));}, duration + 100);
  795. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_6_' + obj.id));}, duration + 100);
  796. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_7_' + obj.id));}, duration + 100);
  797. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_8_' + obj.id));}, duration + 100);
  798. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_9_' + obj.id));}, duration + 100);
  799. setTimeout(function () {callback(obj);}, duration + 100);
  800. return this;
  801. };
  802. /**
  803. * Vertical Blinds (close)
  804. *
  805. * @params object obj The graph object
  806. */
  807. RG.Effects.Common.vblindsclose =
  808. RG.Effects.Common.vBlindsClose = function ()
  809. {
  810. // This function gets added to the chart object - so the this
  811. // variable is the chart object
  812. var obj = this;
  813. var opt = arguments[0] || {};
  814. var frames = opt.frames || 60;
  815. var duration = (frames / 60) * 1000;
  816. var frame = 0;
  817. var callback = arguments[1] || function () {};
  818. var xy = RG.getCanvasXY(obj.canvas);
  819. var color = opt.background || opt.color || opt.backgroundColor || 'white';
  820. var xy = RG.getCanvasXY(this.canvas);
  821. var width = this.canvas.width / 10;
  822. // Don't draw the chart
  823. // Create the blinds
  824. for (var i=0; i<10; ++i) {
  825. var div = doc.createElement('DIV');
  826. div.id = 'rgraph_vblinds_' + i + '_' + obj.id;
  827. div.style.width = 0;
  828. div.style.height = this.canvas.height + 'px';
  829. div.style.left = (xy[0] + (this.canvas.width * (i / 10))) + 'px';
  830. div.style.top = (xy[1]) + 'px';
  831. div.style.position = 'absolute';
  832. div.style.backgroundColor = color;
  833. doc.body.appendChild(div);
  834. jQuery('#rgraph_vblinds_' + i + '_' + obj.id).animate({width: width}, duration);
  835. }
  836. setTimeout(function () {RG.clear(obj.canvas);}, duration + 100);
  837. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_0_' + obj.id));}, duration + 100);
  838. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_1_' + obj.id));}, duration + 100);
  839. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_2_' + obj.id));}, duration + 100);
  840. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_3_' + obj.id));}, duration + 100);
  841. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_4_' + obj.id));}, duration + 100);
  842. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_5_' + obj.id));}, duration + 100);
  843. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_6_' + obj.id));}, duration + 100);
  844. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_7_' + obj.id));}, duration + 100);
  845. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_8_' + obj.id));}, duration + 100);
  846. setTimeout(function () {doc.body.removeChild(doc.getElementById('rgraph_vblinds_9_' + obj.id));}, duration + 100);
  847. setTimeout(function () {callback(obj);}, duration + 100);
  848. return this;
  849. };
  850. /**
  851. * Slide in
  852. *
  853. * This function is a wipe that can be used when switching the canvas to a new graph
  854. *
  855. * @param object obj The graph object
  856. */
  857. RG.Effects.Common.slideIn = function ()
  858. {
  859. // This function gets added to the chart object - so the this
  860. // variable is the chart object
  861. var obj = this;
  862. var opt = arguments[0] || {};
  863. var frames = opt.frames || 60;
  864. var duration = (frames / 60) * 1000;
  865. var frame = 0;
  866. var callback = arguments[1] || function () {};
  867. var xy = RG.getCanvasXY(obj.canvas);
  868. var color = opt.background || opt.color || opt.backgroundColor || 'white';
  869. var xy = RG.getCanvasXY(this.canvas);
  870. var width = this.canvas.width / 10;
  871. var div = RG.Effects.wrap(obj.canvas);
  872. var from = opt.from || 'left';
  873. div.style.overflow = 'hidden';
  874. RG.clear(obj.canvas);
  875. RG.redrawCanvas(obj.canvas);
  876. canvas.style.position = 'relative';
  877. if (from == 'left') {
  878. obj.canvas.style.left = (0 - div.offsetWidth) + 'px';
  879. obj.canvas.style.top = 0;
  880. } else if (from == 'top') {
  881. obj.canvas.style.left = 0;
  882. obj.canvas.style.top = (0 - div.offsetHeight) + 'px';
  883. } else if (from == 'bottom') {
  884. obj.canvas.style.left = 0;
  885. obj.canvas.style.top = div.offsetHeight + 'px';
  886. } else {
  887. obj.canvas.style.left = div.offsetWidth + 'px';
  888. obj.canvas.style.top = 0;
  889. }
  890. jQuery('#' + obj.id).animate({left:0,top:0}, duration, function ()
  891. {
  892. callback(obj);
  893. });
  894. return this;
  895. };
  896. /**
  897. * Slide out
  898. *
  899. * This function is a wipe that can be used when switching the canvas to a new graph
  900. *
  901. * @param object Optional object containing configuration.
  902. * @param function Optional callback function
  903. */
  904. RG.Effects.Common.slideOut = function ()
  905. {
  906. // This function gets added to the chart object - so the this
  907. // variable is the chart object
  908. var obj = this;
  909. var opt = arguments[0] || {};
  910. var frames = opt.frames || 60;
  911. var duration = (frames / 60) * 1000;
  912. var frame = 0;
  913. var callback = arguments[1] || function () {};
  914. var xy = RG.getCanvasXY(obj.canvas);
  915. var color = opt.background || opt.color || opt.backgroundColor || 'white';
  916. var xy = RG.getCanvasXY(this.canvas);
  917. var width = this.canvas.width / 10;
  918. var div = RG.Effects.wrap(obj.canvas);
  919. var to = opt.to || 'left';
  920. div.style.overflow= 'hidden';
  921. obj.canvas.style.position = 'relative';
  922. obj.canvas.style.left = 0;
  923. obj.canvas.style.top = 0;
  924. if (to == 'left') {
  925. jQuery('#' + obj.id).animate({left: (0 - obj.canvas.width) + 'px'}, duration, function () {callback(obj);});
  926. } else if (to == 'top') {
  927. jQuery('#' + obj.id).animate({left: 0, top: (0 - div.offsetHeight) + 'px'}, duration, function () {callback(obj);});
  928. } else if (to == 'bottom') {
  929. jQuery('#' + obj.id).animate({top: (0 + div.offsetHeight) + 'px'}, duration, function () {callback(obj);});
  930. } else {
  931. jQuery('#' + obj.id).animate({left: (0 + obj.canvas.width) + 'px'}, duration, function () {callback(obj);});
  932. }
  933. return this;
  934. };
  935. /**
  936. * Horizontal Scissors (open)
  937. *
  938. * @param @object Optional array of options
  939. * @param function Optional callback function
  940. *
  941. */
  942. RG.Effects.Common.hscissorsopen =
  943. RG.Effects.Common.hScissorsOpen = function ()
  944. {
  945. // This function gets added to the chart object - so the this
  946. // variable is the chart object
  947. var obj = this;
  948. var opt = arguments[0] || {};
  949. var frames = opt.frames || 60;
  950. var duration = (frames / 60) * 1000;
  951. var frame = 0;
  952. var callback = arguments[1] || function () {};
  953. var xy = RG.getCanvasXY(obj.canvas);
  954. var color = opt.background || opt.color || opt.backgroundColor || 'white';
  955. var xy = RG.getCanvasXY(obj.canvas);
  956. var width = this.canvas.width / 10;
  957. var to = opt.to || 'left';
  958. var height = obj.canvas.height / 5;
  959. /**
  960. * First draw the chart
  961. */
  962. RG.clear(obj.canvas);
  963. RG.redrawCanvas(obj.canvas);
  964. for (var i=0; i<5; ++i) {
  965. var div = doc.getElementById("rgraph_hscissors_" + i + '_' + obj.id)
  966. if (!div) {
  967. var div = doc.createElement('DIV');
  968. div.id = 'rgraph_hscissors_' + i + '_' + obj.id;
  969. div.style.width = obj.canvas.width + 'px';
  970. div.style.height = height + 'px';
  971. div.style.left = xy[0] + 'px';
  972. div.style.top = (xy[1] + (obj.canvas.height * (i / 5))) + 'px';
  973. div.style.position = 'absolute';
  974. div.style.backgroundColor = color;
  975. doc.body.appendChild(div);
  976. }
  977. if (i % 2 == 0) {
  978. jQuery('#' + 'rgraph_hscissors_' + i + '_' + obj.id).animate({left: xy[0] + obj.canvas.width + 'px', width: 0}, duration);
  979. } else {
  980. jQuery('#' + 'rgraph_hscissors_' + i + '_' + obj.id).animate({width: 0}, duration);
  981. }
  982. }
  983. setTimeout(function ()
  984. {
  985. doc.body.removeChild(doc.getElementById('rgraph_hscissors_0_' + obj.id));
  986. doc.body.removeChild(doc.getElementById('rgraph_hscissors_1_' + obj.id));
  987. doc.body.removeChild(doc.getElementById('rgraph_hscissors_2_' + obj.id));
  988. doc.body.removeChild(doc.getElementById('rgraph_hscissors_3_' + obj.id));
  989. doc.body.removeChild(doc.getElementById('rgraph_hscissors_4_' + obj.id));
  990. callback(obj);
  991. }, duration);
  992. return this;
  993. };
  994. /**
  995. * Horizontal Scissors (Close)
  996. *
  997. * @param @object Optional object of options
  998. * @param function Optional callback function
  999. *
  1000. */
  1001. RG.Effects.Common.hScissorsClose =
  1002. RG.Effects.Common.hscissorsclose = function ()
  1003. {
  1004. // This function gets added to the chart object - so the this
  1005. // variable is the chart object
  1006. var obj = this;
  1007. var opt = arguments[0] || {};
  1008. var frames = opt.frames || 60;
  1009. var duration = (frames / 60) * 1000;
  1010. var frame = 0;
  1011. var callback = arguments[1] || function () {};
  1012. var xy = RG.getCanvasXY(obj.canvas);
  1013. var color = opt.background || opt.color || opt.backgroundColor || 'white';
  1014. var xy = RG.getCanvasXY(this.canvas);
  1015. var height = obj.canvas.height / 5;
  1016. /**
  1017. * First draw the chart
  1018. */
  1019. //RG.clear(obj.canvas);
  1020. RG.redrawCanvas(obj.canvas);
  1021. for (var i=0; i<5; ++i) {
  1022. var div = doc.createElement('DIV');
  1023. div.id = 'rgraph_hscissors_' + i + '_' + obj.id;
  1024. div.style.width = 0;
  1025. div.style.height = height + 'px';
  1026. div.style.left = (i % 2 == 0 ? xy[0] + obj.canvas.width : xy[0]) + 'px';
  1027. div.style.top = (xy[1] + (obj.canvas.height * (i / 5))) + 'px';
  1028. div.style.position = 'absolute';
  1029. div.style.backgroundColor = color;
  1030. doc.body.appendChild(div);
  1031. if (i % 2 == 0) {
  1032. jQuery('#' + 'rgraph_hscissors_' + i + '_' + obj.id).animate({left: xy[0] + 'px', width: obj.canvas.width + 'px'}, duration);
  1033. } else {
  1034. jQuery('#' + 'rgraph_hscissors_' + i + '_' + obj.id).animate({width: obj.canvas.width + 'px'}, duration);
  1035. }
  1036. }
  1037. setTimeout(function () {callback(obj);}, duration);
  1038. return this;
  1039. };
  1040. /**
  1041. * Vertical Scissors (open)
  1042. *
  1043. * @param @object Optional object of options
  1044. * @param function Optional callback function
  1045. *
  1046. */
  1047. RG.Effects.Common.vScissorsOpen =
  1048. RG.Effects.Common.vscissorsopen = function ()
  1049. {
  1050. // This function gets added to the chart object - so the this
  1051. // variable is the chart object
  1052. var obj = this;
  1053. var opt = arguments[0] || {};
  1054. var frames = opt.frames || 60;
  1055. var duration = (frames / 60) * 1000;
  1056. var frame = 0;
  1057. var callback = arguments[1] || function () {};
  1058. var xy = RG.getCanvasXY(obj.canvas);
  1059. var color = opt.background || opt.color || opt.backgroundColor || 'white';
  1060. var xy = RG.getCanvasXY(this.canvas);
  1061. var width = this.canvas.width / 10;
  1062. /**
  1063. * First draw the chart
  1064. */
  1065. //RG.clear(obj.canvas);
  1066. RG.redrawCanvas(obj.canvas);
  1067. for (var i=0; i<10; ++i) {
  1068. var div = doc.getElementById("rgraph_vscissors_" + i + '_' + obj.id);
  1069. if (!div) {
  1070. var div = doc.createElement('DIV');
  1071. div.id = 'rgraph_vscissors_' + i + '_' + obj.id;
  1072. div.style.width = width + 'px';
  1073. div.style.height = obj.canvas.height + 'px';
  1074. div.style.left = xy[0] + (obj.canvas.width * (i / 10)) + 'px';
  1075. div.style.top = xy[1] + 'px';
  1076. div.style.position = 'absolute';
  1077. div.style.backgroundColor = color;
  1078. doc.body.appendChild(div);
  1079. }
  1080. if (i % 2 == 0) {
  1081. jQuery('#' + 'rgraph_vscissors_' + i + '_' + obj.id).animate({top: xy[1] + obj.canvas.height + 'px', height: 0}, duration);
  1082. } else {
  1083. jQuery('#' + 'rgraph_vscissors_' + i + '_' + obj.id).animate({height: 0}, duration);
  1084. }
  1085. }
  1086. setTimeout(function ()
  1087. {
  1088. doc.body.removeChild(doc.getElementById('rgraph_vscissors_0' + '_' + obj.id));
  1089. doc.body.removeChild(doc.getElementById('rgraph_vscissors_1' + '_' + obj.id));
  1090. doc.body.removeChild(doc.getElementById('rgraph_vscissors_2' + '_' + obj.id));
  1091. doc.body.removeChild(doc.getElementById('rgraph_vscissors_3' + '_' + obj.id));
  1092. doc.body.removeChild(doc.getElementById('rgraph_vscissors_4' + '_' + obj.id));
  1093. callback(obj);
  1094. }, duration);
  1095. return this;
  1096. };
  1097. /**
  1098. * Vertical Scissors (close)
  1099. *
  1100. * @param object obj The graph object
  1101. * @param @object An array of options
  1102. * @param function Optional callback function
  1103. *
  1104. */
  1105. RG.Effects.Common.vscissorsclose =
  1106. RG.Effects.Common.vScissorsClose = function ()
  1107. {
  1108. // This function gets added to the chart object - so the this
  1109. // variable is the chart object
  1110. var obj = this;
  1111. var opt = arguments[0] || {};
  1112. var frames = opt.frames || 60;
  1113. var duration = (frames / 60) * 1000;
  1114. var frame = 0;
  1115. var callback = arguments[1] || function () {};
  1116. var xy = RG.getCanvasXY(obj.canvas);
  1117. var color = opt.background || opt.color || opt.backgroundColor || 'white';
  1118. var xy = RG.getCanvasXY(this.canvas);
  1119. var width = this.canvas.width / 10;
  1120. /**
  1121. * First draw the chart
  1122. */
  1123. //RG.clear(obj.canvas);
  1124. RG.redrawCanvas(obj.canvas);
  1125. for (var i=0; i<10; ++i) {
  1126. var div = doc.getElementById("rgraph_vscissors_" + i + '_' + obj.id)
  1127. if (!div) {
  1128. var div = doc.createElement('DIV');
  1129. div.id = 'rgraph_vscissors_' + i + '_' + obj.id;
  1130. div.style.width = width + 'px';
  1131. div.style.height = 0;
  1132. div.style.left = xy[0] + (width * i) + 'px';
  1133. div.style.top = (i % 2 == 0 ? xy[1] + obj.canvas.height : xy[1]) + 'px';
  1134. div.style.position = 'absolute';
  1135. div.style.backgroundColor = color;
  1136. doc.body.appendChild(div);
  1137. }
  1138. if (i % 2 == 0) {
  1139. jQuery('#' + 'rgraph_vscissors_' + i + '_' + obj.id).animate({top: xy[1] + 'px', height: obj.canvas.height + 'px'}, duration);
  1140. } else {
  1141. jQuery('#' + 'rgraph_vscissors_' + i + '_' + obj.id).animate({height: obj.canvas.height + 'px'}, duration);
  1142. }
  1143. }
  1144. setTimeout(function () {callback(obj);}, duration);
  1145. return this;
  1146. };
  1147. // End Module pattern
  1148. })(window, document);