RGraph.common.effects.js 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897
  1. /**
  2. * o------------------------------------------------------------------------------o
  3. * | This file is part of the RGraph package - you can learn more at: |
  4. * | |
  5. * | http://www.rgraph.net |
  6. * | |
  7. * | This package is licensed under the RGraph license. For all kinds of business |
  8. * | purposes there is a small one-time licensing fee to pay and for non |
  9. * | commercial purposes it is free to use. You can read the full license here: |
  10. * | |
  11. * | http://www.rgraph.net/license |
  12. * o------------------------------------------------------------------------------o
  13. */
  14. /**
  15. * This is a library of a few functions that make it easier to do
  16. * effects like fade-ins or eaxpansion.
  17. */
  18. /**
  19. * Initialise the various objects
  20. */
  21. if (typeof(RGraph) == 'undefined') RGraph = {isRGraph:true,type:'common'};
  22. RGraph.Effects = {};
  23. RGraph.Effects.Fade = {}; RGraph.Effects.jQuery = {}
  24. RGraph.Effects.jQuery.HBlinds = {}; RGraph.Effects.jQuery.VBlinds = {}
  25. RGraph.Effects.jQuery.Slide = {}; RGraph.Effects.Pie = {}
  26. RGraph.Effects.Bar = {}; RGraph.Effects.Line = {}
  27. RGraph.Effects.Line.jQuery = {}; RGraph.Effects.Fuel = {}
  28. RGraph.Effects.Rose = {}; RGraph.Effects.Odo = {}
  29. RGraph.Effects.Gauge = {}; RGraph.Effects.Meter = {}
  30. RGraph.Effects.HBar = {}; RGraph.Effects.HProgress = {}
  31. RGraph.Effects.VProgress = {}; RGraph.Effects.Radar = {}
  32. RGraph.Effects.Waterfall = {}; RGraph.Effects.Gantt = {}
  33. RGraph.Effects.Thermometer = {}; RGraph.Effects.Scatter = {}
  34. RGraph.Effects.Scatter.jQuery = {}; RGraph.Effects.CornerGauge = {}
  35. RGraph.Effects.jQuery.HScissors = {}; RGraph.Effects.jQuery.VScissors = {}
  36. /**
  37. * Fadein
  38. *
  39. * This function simply uses the CSS opacity property - initially set to zero and
  40. * increasing to 1 over the period of 0.5 second
  41. *
  42. * @param object obj The graph object
  43. */
  44. RGraph.Effects.Fade.In = function (obj)
  45. {
  46. var canvas = obj.canvas;
  47. var duration = (arguments[1] && arguments[1].duration ? arguments[1].duration : 250);
  48. var frames = (arguments[1] && arguments[1].frames ? arguments[1].frames : 5);
  49. // Initially the opacity should be zero
  50. canvas.style.opacity = 0;
  51. // Draw the chart
  52. RGraph.Clear(obj.canvas);
  53. RGraph.RedrawCanvas(obj.canvas);
  54. // Now fade the chart in
  55. for (var i=1; i<=frames; ++i) {
  56. setTimeout('document.getElementById("' + canvas.id + '").style.opacity = ' + (i * (1 / frames)), i * (duration / frames));
  57. }
  58. /**
  59. * Callback
  60. */
  61. if (typeof(arguments[2]) == 'function') {
  62. setTimeout(arguments[2], duration);
  63. }
  64. }
  65. /**
  66. * Fadeout
  67. *
  68. * This function is a reversal of the above function - fading out instead of in
  69. *
  70. * @param object obj The graph object
  71. */
  72. RGraph.Effects.Fade.Out = function (obj)
  73. {
  74. var canvas = obj.canvas;
  75. var duration = (arguments[1] && arguments[1].duration ? arguments[1].duration : 250);
  76. var frames = (arguments[1] && arguments[1].frames ? arguments[1].frames : 5);
  77. // Draw the chart
  78. RGraph.Clear(obj.canvas);
  79. RGraph.RedrawCanvas(obj.canvas);
  80. // Now fade the chart in
  81. for (var i=frames; i>=0; --i) {
  82. setTimeout('document.getElementById("' + canvas.id + '").style.opacity = ' + (i * (1 / frames)), (frames - i) * (duration / frames));
  83. }
  84. /**
  85. * Callback
  86. */
  87. if (typeof(arguments[2]) == 'function') {
  88. setTimeout(arguments[2], duration);
  89. }
  90. }
  91. /**
  92. * Expand
  93. *
  94. * This effect is like the tooltip effect of the same name. I starts in the middle
  95. * and expands out to full size.
  96. *
  97. * @param object obj The graph object
  98. */
  99. RGraph.Effects.jQuery.Expand = function (obj)
  100. {
  101. // Check for jQuery
  102. if (typeof(jQuery) == 'undefined') {
  103. alert('[ERROR] Could not find jQuery object - have you included the jQuery file?');
  104. }
  105. var bounce = (!arguments[1] || (arguments[1] && (arguments[1].bounce || typeof(arguments[1].bounce) == 'undefined'))) ? true : false;
  106. var canvas = obj.canvas;
  107. if (!canvas.__rgraph_div_placeholder__) {
  108. var div = RGraph.Effects.ReplaceCanvasWithDIV(canvas);
  109. canvas.__rgraph_div_placeholder__ = div;
  110. } else {
  111. div = canvas.__rgraph_div_placeholder__;
  112. }
  113. div.style.position = 'relative';
  114. canvas.style.position = 'absolute';
  115. canvas.style.top = (canvas.height / 2) + 'px';
  116. canvas.style.left = (canvas.width / 2) + 'px';
  117. canvas.style.width = 0;
  118. canvas.style.height = 0;
  119. canvas.style.opacity = 0;
  120. RGraph.Clear(obj.canvas);
  121. RGraph.RedrawCanvas(obj.canvas);
  122. if (bounce) {
  123. jQuery('#' + obj.id).animate({
  124. opacity: 1,
  125. width: '120%',
  126. height: '120%',
  127. left: (canvas.width * -0.1) + 'px',
  128. top: (canvas.height * -0.1) + 'px'
  129. }, 500, function (){
  130. jQuery('#' + obj.id).animate({width: '90%', height: '90%', top: (canvas.height * 0.05) + 'px', left: (canvas.width * 0.05) + 'px'}, 250, function ()
  131. {
  132. jQuery('#' + obj.id).animate({width: '101%', height: '101%', top: (canvas.height * -0.005) + 'px', left: (canvas.width * -0.005) + 'px'}, 250, function ()
  133. {
  134. jQuery('#' + obj.id).animate({width: '100%', height: '100%', top: 0, left: 0}, 250);
  135. });
  136. });
  137. });
  138. } else {
  139. jQuery('#' + obj.id).animate({
  140. opacity: 1,
  141. width: '100%',
  142. height: '100%',
  143. left: 0,
  144. top: 0
  145. }, 1000)
  146. }
  147. /**
  148. * Callback
  149. */
  150. if (typeof(arguments[2]) == 'function') {
  151. setTimeout(arguments[2], 1000);
  152. }
  153. }
  154. /**
  155. * Contract
  156. *
  157. * This effect is a good one to use with the Expand effect to make a transition
  158. *
  159. * @param object obj The graph object
  160. * @param null Not used
  161. * @param Optional callback to run when the effect iss done.
  162. */
  163. RGraph.Effects.jQuery.Contract = function (obj)
  164. {
  165. // Check for jQuery
  166. if (typeof(jQuery) == 'undefined') {
  167. alert('[ERROR] Could not find jQuery object - have you included the jQuery file?');
  168. }
  169. var canvas = obj.canvas;
  170. if (!canvas.__rgraph_div_placeholder__) {
  171. var div = RGraph.Effects.ReplaceCanvasWithDIV(canvas);
  172. canvas.__rgraph_div_placeholder__ = div;
  173. } else {
  174. div = canvas.__rgraph_div_placeholder__;
  175. }
  176. div.style.position = 'relative';
  177. canvas.style.position = 'absolute';
  178. canvas.style.top = 0;
  179. canvas.style.left = 0;
  180. jQuery('#' + obj.id).animate({
  181. width: (canvas.width * 1.2) + 'px',
  182. height: (canvas.height * 1.2) + 'px',
  183. left: (canvas.width * -0.1) + 'px',
  184. top: (canvas.height * -0.1) + 'px'
  185. }, 250, function ()
  186. {
  187. jQuery('#' + obj.id).animate({
  188. opacity: 0,
  189. width: 0,
  190. height: 0,
  191. left: (canvas.width * 0.5) + 'px',
  192. top: (canvas.height * 0.5) + 'px'
  193. }, 750)
  194. });
  195. /**
  196. * Callback
  197. */
  198. if (typeof(arguments[2]) == 'function') {
  199. setTimeout(arguments[2], 1000);
  200. }
  201. }
  202. /**
  203. * A function used to replace the canvas witha Div, which inturn holds the canvas. This way the page
  204. * layout doesn't shift in the canvas is resized.
  205. *
  206. * @param object canvas The canvas to replace.
  207. */
  208. RGraph.Effects.ReplaceCanvasWithDIV = function (canvas)
  209. {
  210. if (!canvas.replacementDIV) {
  211. // Create the place holder DIV
  212. var div = document.createElement('DIV');
  213. div.style.width = canvas.width + 'px';
  214. div.style.height = canvas.height + 'px';
  215. div.style.cssFloat = canvas.style.cssFloat;
  216. div.style.left = canvas.style.left;
  217. div.style.top = canvas.style.top;
  218. //div.style.position = canvas.style.position;
  219. div.style.display = 'inline-block';
  220. canvas.parentNode.insertBefore(div, canvas);
  221. // Remove the canvas from the document
  222. canvas.parentNode.removeChild(canvas);
  223. // Add it back in as a child of the place holder
  224. div.appendChild(canvas);
  225. // Reset the positioning information on the canvas
  226. canvas.style.position = 'relative';
  227. canvas.style.left = (div.offsetWidth / 2) + 'px';
  228. canvas.style.top = (div.offsetHeight / 2) + 'px';
  229. canvas.style.cssFloat = '';
  230. // Add a reference to the canvas to the DIV so that repeated plays of the anumation
  231. // don't keep replacing the canvas with a new DIV
  232. canvas.replacementDIV = div;
  233. } else {
  234. var div = canvas.replacementDIV;
  235. }
  236. return div;
  237. }
  238. /**
  239. * Snap
  240. *
  241. * Similar to the tooltip effect of the same name, this moves the canvas in from the top left corner
  242. *
  243. * @param object obj The graph object
  244. */
  245. RGraph.Effects.jQuery.Snap = function (obj)
  246. {
  247. var delay = 500;
  248. var div = RGraph.Effects.ReplaceCanvasWithDIV(obj.canvas);
  249. obj.canvas.style.position = 'absolute';
  250. obj.canvas.style.top = 0;
  251. obj.canvas.style.left = 0;
  252. obj.canvas.style.width = 0;
  253. obj.canvas.style.height = 0;
  254. obj.canvas.style.opacity = 0;
  255. var targetLeft = div.offsetLeft;
  256. var targetTop = div.offsetTop;
  257. var targetWidth = div.offsetWidth;
  258. var targetHeight = div.offsetHeight;
  259. RGraph.Clear(obj.canvas);
  260. RGraph.RedrawCanvas(obj.canvas);
  261. jQuery('#' + obj.id).animate({
  262. opacity: 1,
  263. width: targetWidth + 'px',
  264. height: targetHeight + 'px',
  265. left: targetLeft + 'px',
  266. top: targetTop + 'px'
  267. }, delay);
  268. /**
  269. * Callback
  270. */
  271. if (typeof(arguments[2]) == 'function') {
  272. setTimeout(arguments[2], delay + 50);
  273. }
  274. }
  275. /**
  276. * Reveal
  277. *
  278. * This effect issmilat to the Expand effect - the canvas is slowly revealed from
  279. * the centre outwards
  280. *
  281. * @param object obj The chart object
  282. */
  283. RGraph.Effects.jQuery.Reveal = function (obj)
  284. {
  285. var opts = arguments[1] ? arguments[1] : null;
  286. var delay = 1000;
  287. var canvas = obj.canvas;
  288. var xy = RGraph.getCanvasXY(obj.canvas);
  289. /**
  290. * Hide the canvas and draw it
  291. */
  292. obj.canvas.style.visibility = 'hidden';
  293. RGraph.Clear(obj.canvas);
  294. RGraph.RedrawCanvas(obj.canvas);
  295. var divs = [
  296. ['reveal_left', xy[0], xy[1], obj.canvas.width / 2, obj.canvas.height],
  297. ['reveal_right',(xy[0] + (obj.canvas.width / 2)),xy[1],(obj.canvas.width / 2),obj.canvas.height],
  298. ['reveal_top',xy[0],xy[1],obj.canvas.width,(obj.canvas.height / 2)],
  299. ['reveal_bottom',xy[0],(xy[1] + (obj.canvas.height / 2)),obj.canvas.width,(obj.canvas.height / 2)]
  300. ];
  301. for (var i=0; i<divs.length; ++i) {
  302. var div = document.createElement('DIV');
  303. div.id = divs[i][0];
  304. div.style.width = divs[i][3]+ 'px';
  305. div.style.height = divs[i][4] + 'px';
  306. div.style.left = divs[i][1] + 'px';
  307. div.style.top = divs[i][2] + 'px';
  308. div.style.position = 'absolute';
  309. div.style.backgroundColor = opts && typeof(opts['color']) == 'string' ? opts['color'] : 'white';
  310. document.body.appendChild(div);
  311. }
  312. /**
  313. * Now the covering DIVs are in place show the canvas again
  314. */
  315. obj.canvas.style.visibility = 'visible';
  316. jQuery('#reveal_left').animate({width: 0}, delay);
  317. jQuery('#reveal_right').animate({left: '+=' + (obj.canvas.width / 2),width: 0}, delay);
  318. jQuery('#reveal_top').animate({height: 0}, delay);
  319. jQuery('#reveal_bottom').animate({top: '+=' + (obj.canvas.height / 2),height: 0}, delay);
  320. // Remove the DIVs from the DOM 100ms after the animation ends
  321. setTimeout(
  322. function ()
  323. {
  324. document.body.removeChild(document.getElementById("reveal_top"))
  325. document.body.removeChild(document.getElementById("reveal_bottom"))
  326. document.body.removeChild(document.getElementById("reveal_left"))
  327. document.body.removeChild(document.getElementById("reveal_right"))
  328. }
  329. , delay);
  330. /**
  331. * Callback
  332. */
  333. if (typeof(arguments[2]) == 'function') {
  334. setTimeout(arguments[2], delay);
  335. }
  336. }
  337. /**
  338. * RevealCircular
  339. *
  340. * This effect is smilar to the Reveal effect - the canvas is slowly revealed from
  341. * the centre outwards using a circular shape
  342. *
  343. * @param object obj The chart object
  344. * @param object An object of options
  345. * @param function An optional callback function that runs when the effect is finished
  346. */
  347. RGraph.Effects.RevealCircular = function (obj)
  348. {
  349. var opts = arguments[1] ? arguments[1] : null;
  350. var callback = arguments[2] ? arguments[2] : null;
  351. var frames = 30;
  352. var RG = RGraph;
  353. var ca = obj.canvas;
  354. var co = obj.context;
  355. var ra = 0; // The initial radius of the circle that is clipped to
  356. var cx = ca.width / 2;
  357. var cy = ca.height / 2;
  358. var target_ra = Math.max(ca.height, ca.width);
  359. // This is the iterator function which gradually increases the radius of the clip circle
  360. function Grow ()
  361. {
  362. // Begin by clearing the canvas
  363. RG.Clear(ca);
  364. co.save();
  365. // First draw the circle and clip to it
  366. co.beginPath();
  367. co.arc(cx, cy, ra, 0, TWOPI, false);
  368. co.clip();
  369. // Now draw the chart
  370. obj.Draw();
  371. co.restore();
  372. // Increment the radius
  373. if (ra < target_ra) {
  374. ra += target_ra / 30;
  375. RG.Effects.UpdateCanvas(Grow);
  376. } else if (typeof(callback) == 'function') {
  377. callback(obj);
  378. }
  379. }
  380. Grow();
  381. }
  382. /**
  383. * Conceal
  384. *
  385. * This effect is the reverse of the Reveal effect - instead of revealing the canvas it
  386. * conceals it. Combined with the reveal effect would make for a nice wipe effect.
  387. *
  388. * @param object obj The chart object
  389. */
  390. RGraph.Effects.jQuery.Conceal = function (obj)
  391. {
  392. var opts = arguments[1] ? arguments[1] : null;
  393. var delay = 1000;
  394. var canvas = obj.canvas;
  395. var xy = RGraph.getCanvasXY(obj.canvas);
  396. var divs = [
  397. ['conceal_left', xy[0], xy[1], 0, obj.canvas.height],
  398. ['conceal_right',(xy[0] + obj.canvas.width),xy[1],0,obj.canvas.height],
  399. ['conceal_top',xy[0],xy[1],obj.canvas.width,0],
  400. ['conceal_bottom',xy[0],(xy[1] + obj.canvas.height),obj.canvas.width,0]
  401. ];
  402. for (var i=0; i<divs.length; ++i) {
  403. var div = document.createElement('DIV');
  404. div.id = divs[i][0];
  405. div.style.width = divs[i][3]+ 'px';
  406. div.style.height = divs[i][4] + 'px';
  407. div.style.left = divs[i][1] + 'px';
  408. div.style.top = divs[i][2] + 'px';
  409. div.style.position = 'absolute';
  410. div.style.backgroundColor = opts && typeof(opts['color']) == 'string' ? opts['color'] : 'white';
  411. document.body.appendChild(div);
  412. }
  413. jQuery('#conceal_left').animate({width: '+=' + (obj.canvas.width / 2)}, delay);
  414. jQuery('#conceal_right').animate({left: '-=' + (obj.canvas.width / 2),width: (obj.canvas.width / 2)}, delay);
  415. jQuery('#conceal_top').animate({height: '+=' + (obj.canvas.height / 2)}, delay);
  416. jQuery('#conceal_bottom').animate({top: '-=' + (obj.canvas.height / 2),height: (obj.canvas.height / 2)}, delay);
  417. // Remove the DIVs from the DOM 100ms after the animation ends
  418. setTimeout(
  419. function ()
  420. {
  421. document.body.removeChild(document.getElementById("conceal_top"))
  422. document.body.removeChild(document.getElementById("conceal_bottom"))
  423. document.body.removeChild(document.getElementById("conceal_left"))
  424. document.body.removeChild(document.getElementById("conceal_right"))
  425. }
  426. , delay);
  427. setTimeout(function () {RGraph.Clear(obj.canvas);}, delay);
  428. /**
  429. * Callback
  430. */
  431. if (typeof(arguments[2]) == 'function') {
  432. setTimeout(arguments[2], delay);
  433. }
  434. }
  435. /**
  436. * Horizontal Blinds (open)
  437. *
  438. * @params object obj The graph object
  439. */
  440. RGraph.Effects.jQuery.HBlinds.Open = function (obj)
  441. {
  442. var canvas = obj.canvas;
  443. var opts = arguments[1] ? arguments[1] : [];
  444. var delay = 1000;
  445. var color = opts['color'] ? opts['color'] : 'white';
  446. var xy = RGraph.getCanvasXY(canvas);
  447. var height = canvas.height / 5;
  448. /**
  449. * First draw the chart
  450. */
  451. RGraph.Clear(obj.canvas);
  452. RGraph.RedrawCanvas(obj.canvas);
  453. for (var i=0; i<5; ++i) {
  454. var div = document.createElement('DIV');
  455. div.id = 'blinds_' + i;
  456. div.style.width = canvas.width + 'px';
  457. div.style.height = height + 'px';
  458. div.style.left = xy[0] + 'px';
  459. div.style.top = (xy[1] + (canvas.height * (i / 5))) + 'px';
  460. div.style.position = 'absolute';
  461. div.style.backgroundColor = color;
  462. document.body.appendChild(div);
  463. jQuery('#blinds_' + i).animate({height: 0}, delay);
  464. }
  465. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_0'));}, delay);
  466. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_1'));}, delay);
  467. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_2'));}, delay);
  468. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_3'));}, delay);
  469. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_4'));}, delay);
  470. /**
  471. * Callback
  472. */
  473. if (typeof(arguments[2]) == 'function') {
  474. setTimeout(arguments[2], delay);
  475. }
  476. }
  477. /**
  478. * Horizontal Blinds (close)
  479. *
  480. * @params object obj The graph object
  481. */
  482. RGraph.Effects.jQuery.HBlinds.Close = function (obj)
  483. {
  484. var canvas = obj.canvas;
  485. var opts = arguments[1] ? arguments[1] : [];
  486. var delay = 1000;
  487. var color = opts['color'] ? opts['color'] : 'white';
  488. var xy = RGraph.getCanvasXY(canvas);
  489. var height = canvas.height / 5;
  490. for (var i=0; i<5; ++i) {
  491. var div = document.createElement('DIV');
  492. div.id = 'blinds_' + i;
  493. div.style.width = canvas.width + 'px';
  494. div.style.height = 0;
  495. div.style.left = xy[0] + 'px';
  496. div.style.top = (xy[1] + (canvas.height * (i / 5))) + 'px';
  497. div.style.position = 'absolute';
  498. div.style.backgroundColor = color;
  499. document.body.appendChild(div);
  500. jQuery('#blinds_' + i).animate({height: height + 'px'}, delay);
  501. }
  502. setTimeout(function () {RGraph.Clear(obj.canvas);}, delay + 100);
  503. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_0'));}, delay + 100);
  504. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_1'));}, delay + 100);
  505. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_2'));}, delay + 100);
  506. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_3'));}, delay + 100);
  507. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_4'));}, delay + 100);
  508. /**
  509. * Callback
  510. */
  511. if (typeof(arguments[2]) == 'function') {
  512. setTimeout(arguments[2], delay);
  513. }
  514. }
  515. /**
  516. * Vertical Blinds (open)
  517. *
  518. * @params object obj The graph object
  519. */
  520. RGraph.Effects.jQuery.VBlinds.Open = function (obj)
  521. {
  522. var canvas = obj.canvas;
  523. var opts = arguments[1] ? arguments[1] : [];
  524. var delay = 1000;
  525. var color = opts['color'] ? opts['color'] : 'white';
  526. var xy = RGraph.getCanvasXY(canvas);
  527. var width = canvas.width / 10;
  528. /**
  529. * First draw the chart
  530. */
  531. RGraph.Clear(obj.canvas);
  532. RGraph.RedrawCanvas(obj.canvas);
  533. for (var i=0; i<10; ++i) {
  534. var div = document.createElement('DIV');
  535. div.id = 'blinds_' + i;
  536. div.style.width = width + 'px';
  537. div.style.height = canvas.height + 'px';
  538. div.style.left = (xy[0] + (canvas.width * (i / 10))) + 'px';
  539. div.style.top = (xy[1]) + 'px';
  540. div.style.position = 'absolute';
  541. div.style.backgroundColor = color;
  542. document.body.appendChild(div);
  543. jQuery('#blinds_' + i).animate({width: 0}, delay);
  544. }
  545. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_0'));}, delay + 100);
  546. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_1'));}, delay + 100);
  547. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_2'));}, delay + 100);
  548. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_3'));}, delay + 100);
  549. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_4'));}, delay + 100);
  550. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_5'));}, delay + 100);
  551. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_6'));}, delay + 100);
  552. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_7'));}, delay + 100);
  553. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_8'));}, delay + 100);
  554. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_9'));}, delay + 100);
  555. /**
  556. * Callback
  557. */
  558. if (typeof(arguments[2]) == 'function') {
  559. setTimeout(arguments[2], delay);
  560. }
  561. }
  562. /**
  563. * Vertical Blinds (close)
  564. *
  565. * @params object obj The graph object
  566. */
  567. RGraph.Effects.jQuery.VBlinds.Close = function (obj)
  568. {
  569. var canvas = obj.canvas;
  570. var opts = arguments[1] ? arguments[1] : [];
  571. var delay = 1000;
  572. var color = opts['color'] ? opts['color'] : 'white';
  573. var xy = RGraph.getCanvasXY(canvas);
  574. var width = canvas.width / 10;
  575. // Don't draw the chart
  576. for (var i=0; i<10; ++i) {
  577. var div = document.createElement('DIV');
  578. div.id = 'blinds_' + i;
  579. div.style.width = 0;
  580. div.style.height = canvas.height + 'px';
  581. div.style.left = (xy[0] + (canvas.width * (i / 10))) + 'px';
  582. div.style.top = (xy[1]) + 'px';
  583. div.style.position = 'absolute';
  584. div.style.backgroundColor = color;
  585. document.body.appendChild(div);
  586. jQuery('#blinds_' + i).animate({width: width}, delay);
  587. }
  588. setTimeout(function () {RGraph.Clear(obj.canvas, color);}, delay + 100);
  589. if (opts['remove']) {
  590. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_0'));}, delay + 100);
  591. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_1'));}, delay + 100);
  592. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_2'));}, delay + 100);
  593. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_3'));}, delay + 100);
  594. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_4'));}, delay + 100);
  595. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_5'));}, delay + 100);
  596. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_6'));}, delay + 100);
  597. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_7'));}, delay + 100);
  598. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_8'));}, delay + 100);
  599. setTimeout(function () {document.body.removeChild(document.getElementById('blinds_9'));}, delay + 100);
  600. }
  601. /**
  602. * Callback
  603. */
  604. if (typeof(arguments[2]) == 'function') {
  605. setTimeout(arguments[2], delay);
  606. }
  607. }
  608. /**
  609. * Pie chart grow
  610. *
  611. * Gradually increases the pie chart radius
  612. *
  613. * @params object obj The graph object
  614. */
  615. RGraph.Effects.Pie.Grow = function (obj)
  616. {
  617. var canvas = obj.canvas;
  618. var opts = arguments[1] ? arguments[1] : [];
  619. var color = opts['color'] ? opts['color'] : 'white';
  620. var xy = RGraph.getCanvasXY(canvas);
  621. canvas.style.visibility = 'hidden';
  622. RGraph.RedrawCanvas(canvas);
  623. var radius = obj.getRadius();
  624. if (typeof(obj.Get('chart.radius')) == 'number') {
  625. radius = obj.Get('chart.radius');
  626. }
  627. //RGraph.Clear(obj.canvas);
  628. canvas.style.visibility = 'visible';
  629. obj.Set('chart.radius', 0);
  630. RGraph.Effects.Animate(obj, {'chart.radius': radius}, arguments[2]);
  631. }
  632. /**
  633. * Grow
  634. *
  635. * The Bar chart Grow effect gradually increases the values of the bars
  636. *
  637. * @param object obj The graph object
  638. * @param object An array of options
  639. * @param function A function to call when the effect is complete
  640. */
  641. RGraph.Effects.Bar.Grow = function (obj)
  642. {
  643. // Callback
  644. var callback = arguments[2];
  645. // Save the data
  646. obj.original_data = RGraph.array_clone(obj.data);
  647. // Zero the data
  648. obj.__animation_frame__ = 0;
  649. // Stop the scale from changing by setting chart.ymax (if it's not already set)
  650. if (obj.Get('chart.ymax') == null) {
  651. var ymax = 0;
  652. for (var i=0; i<obj.data.length; ++i) {
  653. if (RGraph.is_array(obj.data[i]) && obj.Get('chart.grouping') == 'stacked') {
  654. ymax = Math.max(ymax, Math.abs(RGraph.array_sum(obj.data[i])));
  655. } else if (RGraph.is_array(obj.data[i]) && obj.Get('chart.grouping') == 'grouped') {
  656. ymax = Math.max(ymax, Math.abs(RGraph.array_max(obj.data[i])));
  657. } else {
  658. ymax = Math.max(ymax, Math.abs(obj.data[i]));
  659. }
  660. }
  661. var scale = RGraph.getScale2(obj, {'max':ymax});
  662. obj.Set('chart.ymax', scale.max);
  663. }
  664. function Grow ()
  665. {
  666. var numFrames = 30;
  667. if (!obj.__animation_frame__) {
  668. obj.__animation_frame__ = 0;
  669. obj.__original_hmargin__ = obj.Get('chart.hmargin');
  670. obj.__hmargin__ = ((obj.canvas.width - obj.Get('chart.gutter.left') - obj.Get('chart.gutter.right')) / obj.data.length) / 2;
  671. obj.Set('chart.hmargin', obj.__hmargin__);
  672. }
  673. // Alter the Bar chart data depending on the frame
  674. for (var j=0; j<obj.original_data.length; ++j) {
  675. if (typeof(obj.data[j]) == 'object') {
  676. for (var k=0; k<obj.data[j].length; ++k) {
  677. obj.data[j][k] = (obj.__animation_frame__ / numFrames) * obj.original_data[j][k];
  678. }
  679. } else {
  680. obj.data[j] = (obj.__animation_frame__ / numFrames) * obj.original_data[j];
  681. }
  682. }
  683. /**
  684. * Increment the hmargin to the target
  685. */
  686. obj.Set('chart.hmargin', ((1 - (obj.__animation_frame__ / numFrames)) * (obj.__hmargin__ - obj.__original_hmargin__)) + obj.__original_hmargin__);
  687. RGraph.Clear(obj.canvas);
  688. RGraph.RedrawCanvas(obj.canvas);
  689. if (obj.__animation_frame__ < numFrames) {
  690. obj.__animation_frame__ += 1;
  691. RGraph.Effects.UpdateCanvas(Grow);
  692. // Call the callback function if it's defined
  693. } else {
  694. if (callback) {
  695. callback(obj);
  696. }
  697. }
  698. }
  699. RGraph.Effects.UpdateCanvas(Grow);
  700. }
  701. /**
  702. * A wrapper function that encapsulate requestAnimationFrame
  703. *
  704. * @param function func The animation function
  705. */
  706. RGraph.Effects.UpdateCanvas = function (func)
  707. {
  708. window.requestAnimationFrame = window.requestAnimationFrame
  709. || window.webkitRequestAnimationFrame
  710. || window.msRequestAnimationFrame
  711. || window.amozRequestAnimationFrame
  712. || (function (func){setTimeout(func, 16.666);});
  713. window.requestAnimationFrame(func);
  714. }
  715. /**
  716. * Grow
  717. *
  718. * The Fuel chart Grow effect gradually increases the values of the Fuel chart
  719. *
  720. * @param object obj The graph object
  721. */
  722. RGraph.Effects.Fuel.Grow = function (obj)
  723. {
  724. var callback = arguments[2];
  725. var numFrames = 30;
  726. var frame = 0;
  727. var origValue = Number(obj.currentValue);
  728. if (obj.currentValue == null) {
  729. obj.currentValue = obj.min;
  730. origValue = obj.min;
  731. }
  732. var newValue = obj.value;
  733. var diff = newValue - origValue;
  734. var step = (diff / numFrames);
  735. var frame = 0;
  736. function Grow ()
  737. {
  738. frame++;
  739. obj.value = ((frame / numFrames) * diff) + origValue
  740. if (obj.value > obj.max) obj.value = obj.max;
  741. if (obj.value < obj.min) obj.value = obj.min;
  742. RGraph.Clear(obj.canvas);
  743. RGraph.RedrawCanvas(obj.canvas);
  744. if (frame < numFrames) {
  745. RGraph.Effects.UpdateCanvas(Grow);
  746. } else if (typeof(callback) == 'function') {
  747. callback(obj);
  748. }
  749. }
  750. Grow();
  751. }
  752. /**
  753. * The Animate function. Similar to the jQuery Animate() function - simply pass it a
  754. * map of the properties and their target values, and this function will animate
  755. * them to get to those values.
  756. *
  757. * @param object obj The chart object
  758. * @param object map A map (an associative array) of the properties and their target values.
  759. * @param An optional function which will be called when the animation is complete
  760. */
  761. RGraph.Effects.Animate = function (obj, map)
  762. {
  763. RGraph.RedrawCanvas(obj.canvas);
  764. RGraph.Effects.__total_frames__ = (map && map['frames']) ? map['frames'] : 30;
  765. function Animate_Iterator (func)
  766. {
  767. var id = [obj.id + '_' + obj.type];
  768. // Very first time in - initialise the arrays
  769. if (typeof(RGraph.Effects.__current_frame__ ) == 'undefined') {
  770. RGraph.Effects.__current_frame__ = new Array();
  771. RGraph.Effects.__original_values__ = new Array();
  772. RGraph.Effects.__diffs__ = new Array();
  773. RGraph.Effects.__steps__ = new Array();
  774. RGraph.Effects.__callback__ = new Array();
  775. }
  776. // Initialise the arrays for THIS animation (not necessrily the first in the page)
  777. if (!RGraph.Effects.__current_frame__[id]) {
  778. RGraph.Effects.__current_frame__[id] = RGraph.Effects.__total_frames__;
  779. RGraph.Effects.__original_values__[id] = {};
  780. RGraph.Effects.__diffs__[id] = {};
  781. RGraph.Effects.__steps__[id] = {};
  782. RGraph.Effects.__callback__[id] = func;
  783. }
  784. for (var i in map) {
  785. if (typeof(map[i]) == 'string' || typeof(map[i]) == 'number') {
  786. // If this the first frame, record the proginal value
  787. if (RGraph.Effects.__current_frame__[id] == RGraph.Effects.__total_frames__) {
  788. RGraph.Effects.__original_values__[id][i] = obj.Get(i);
  789. RGraph.Effects.__diffs__[id][i] = map[i] - RGraph.Effects.__original_values__[id][i];
  790. RGraph.Effects.__steps__[id][i] = RGraph.Effects.__diffs__[id][i] / RGraph.Effects.__total_frames__;
  791. }
  792. obj.Set(i, obj.Get(i) + RGraph.Effects.__steps__[id][i]);
  793. RGraph.RedrawCanvas(obj.canvas);
  794. }
  795. }
  796. // If the current frame number is above zero, run the animation iterator again
  797. if (--RGraph.Effects.__current_frame__[id] > 0) {
  798. //setTimeout(Animate_Iterator, 100)
  799. RGraph.Effects.UpdateCanvas(Animate_Iterator);
  800. // Optional callback
  801. } else {
  802. if (typeof(RGraph.Effects.__callback__[id]) == 'function') {
  803. (RGraph.Effects.__callback__[id])(obj);
  804. }
  805. // Get rid of the arrays
  806. RGraph.Effects.__current_frame__[id] = null;
  807. RGraph.Effects.__original_values__[id] = null;
  808. RGraph.Effects.__diffs__[id] = null;
  809. RGraph.Effects.__steps__[id] = null;
  810. RGraph.Effects.__callback__[id] = null;
  811. }
  812. }
  813. Animate_Iterator(arguments[2]);
  814. }
  815. /**
  816. * Slide in
  817. *
  818. * This function is a wipe that can be used when switching the canvas to a new graph
  819. *
  820. * @param object obj The graph object
  821. */
  822. RGraph.Effects.jQuery.Slide.In = function (obj)
  823. {
  824. RGraph.Clear(obj.canvas);
  825. RGraph.RedrawCanvas(obj.canvas);
  826. var canvas = obj.canvas;
  827. var div = RGraph.Effects.ReplaceCanvasWithDIV(obj.canvas);
  828. var delay = 1000;
  829. div.style.overflow= 'hidden';
  830. var from = typeof(arguments[1]) == 'object' && typeof(arguments[1]['from']) == 'string' ? arguments[1]['from'] : 'left';
  831. canvas.style.position = 'relative';
  832. if (from == 'left') {
  833. canvas.style.left = (0 - div.offsetWidth) + 'px';
  834. canvas.style.top = 0;
  835. } else if (from == 'top') {
  836. canvas.style.left = 0;
  837. canvas.style.top = (0 - div.offsetHeight) + 'px';
  838. } else if (from == 'bottom') {
  839. canvas.style.left = 0;
  840. canvas.style.top = div.offsetHeight + 'px';
  841. } else {
  842. canvas.style.left = div.offsetWidth + 'px';
  843. canvas.style.top = 0;
  844. }
  845. jQuery('#' + obj.id).animate({left:0,top:0}, delay);
  846. /**
  847. * Callback
  848. */
  849. if (typeof(arguments[2]) == 'function') {
  850. setTimeout(arguments[2], delay);
  851. }
  852. }
  853. /**
  854. * Slide out
  855. *
  856. * This function is a wipe that can be used when switching the canvas to a new graph
  857. *
  858. * @param object obj The graph object
  859. */
  860. RGraph.Effects.jQuery.Slide.Out = function (obj)
  861. {
  862. var canvas = obj.canvas;
  863. var div = RGraph.Effects.ReplaceCanvasWithDIV(obj.canvas);
  864. var delay = 1000;
  865. div.style.overflow= 'hidden';
  866. var to = typeof(arguments[1]) == 'object' && arguments[1] && typeof(arguments[1]['to']) == 'string' ? arguments[1]['to'] : 'left';
  867. canvas.style.position = 'relative';
  868. canvas.style.left = 0;
  869. canvas.style.top = 0;
  870. if (to == 'left') {
  871. jQuery('#' + obj.id).animate({left: (0 - canvas.width) + 'px'}, delay);
  872. } else if (to == 'top') {
  873. jQuery('#' + obj.id).animate({left: 0, top: (0 - div.offsetHeight) + 'px'}, delay);
  874. } else if (to == 'bottom') {
  875. jQuery('#' + obj.id).animate({top: (0 + div.offsetHeight) + 'px'}, delay);
  876. } else {
  877. jQuery('#' + obj.id).animate({left: (0 + canvas.width) + 'px'}, delay);
  878. }
  879. /**
  880. * Callback
  881. */
  882. if (typeof(arguments[2]) == 'function') {
  883. setTimeout(arguments[2], delay);
  884. }
  885. }
  886. /**
  887. * Unfold
  888. *
  889. * This effect gradually increases the X/Y coordinatesfrom 0
  890. *
  891. * @param object obj The chart object
  892. */
  893. RGraph.Effects.Line.Unfold = function (obj)
  894. {
  895. obj.Set('chart.animation.factor', obj.Get('chart.animation.unfold.initial'));
  896. RGraph.Effects.Animate(obj, {'chart.animation.factor': 1}, arguments[2]);
  897. }
  898. /**
  899. * RoundRobin
  900. *
  901. * This effect is similar to the Pie chart RoundRobin effect
  902. *
  903. * @param object obj The chart object
  904. * @param Not used - pass null
  905. * @param function An optional callback function
  906. */
  907. RGraph.Effects.Rose.RoundRobin = function (obj)
  908. {
  909. var numFrames = 60;
  910. var currentFrame = 0;
  911. var original_margin = obj.Get('chart.margin');
  912. var margin = (360 / obj.data.length) / 2;
  913. var callback = arguments[2];
  914. obj.Set('chart.margin', margin);
  915. obj.Set('chart.animation.roundrobin.factor', 0);
  916. //RGraph.Effects.Animate(obj, {'chart.margin': original_margin, 'chart.animation.grow.factor': 1, 'frames': 45}, arguments[2]);
  917. function RoundRobin_inner ()
  918. {
  919. if (currentFrame++ < numFrames) {
  920. obj.Set('chart.animation.roundrobin.factor', currentFrame / numFrames);
  921. obj.Set('chart.margin', (currentFrame / numFrames) * original_margin);
  922. RGraph.Clear(obj.canvas);
  923. RGraph.RedrawCanvas(obj.canvas);
  924. RGraph.Effects.UpdateCanvas(RoundRobin_inner);
  925. } else {
  926. obj.Set('chart.animation.roundrobin.factor', 1);
  927. obj.Set('chart.margin', original_margin);
  928. RGraph.Clear(obj.canvas);
  929. RGraph.RedrawCanvas(obj.canvas);
  930. if (typeof(callback) == 'function') {
  931. callback(obj);
  932. }
  933. }
  934. }
  935. RGraph.Effects.UpdateCanvas(RoundRobin_inner);
  936. }
  937. /**
  938. * UnfoldFromCenter
  939. *
  940. * Line chart unfold from center
  941. */
  942. RGraph.Effects.Line.UnfoldFromCenter = function (obj)
  943. {
  944. var numFrames = 30;
  945. var original_opacity = obj.canvas.style.opacity;
  946. obj.canvas.style.opacity = 0;
  947. obj.Draw();
  948. RGraph.RedrawCanvas(obj.canvas);
  949. var center_value = obj.Get('chart.xaxispos') == 'center' ? obj.Get('chart.ymin') : ((obj.max - obj.min) / 2) + obj.min;
  950. obj.Set('chart.ymax', obj.scale2.max);
  951. RGraph.Clear(obj.canvas);
  952. obj.canvas.style.opacity = original_opacity;
  953. var original_data = RGraph.array_clone(obj.original_data);
  954. var callback = arguments[2];
  955. if (!obj.__increments__) {
  956. obj.__increments__ = new Array();
  957. for (var dataset=0; dataset<original_data.length; ++dataset) {
  958. obj.__increments__[dataset] = new Array();
  959. for (var i=0; i<original_data[dataset].length; ++i) {
  960. if (obj.Get('chart.filled') && obj.Get('chart.filled.accumulative') && dataset > 0) {
  961. obj.__increments__[dataset][i] = original_data[dataset][i] / numFrames;
  962. obj.original_data[dataset][i] = 0;
  963. } else {
  964. obj.__increments__[dataset][i] = (original_data[dataset][i] - center_value) / numFrames;
  965. obj.original_data[dataset][i] = center_value;
  966. }
  967. }
  968. }
  969. }
  970. function UnfoldFromCenter ()
  971. {
  972. RGraph.Clear(obj.canvas);
  973. RGraph.RedrawCanvas(obj.canvas);
  974. for (var dataset=0; dataset<original_data.length; ++dataset) {
  975. for (var i=0; i<original_data[dataset].length; ++i) {
  976. obj.original_data[dataset][i] += obj.__increments__[dataset][i];
  977. }
  978. }
  979. if (--numFrames > 0) {
  980. RGraph.Effects.UpdateCanvas(UnfoldFromCenter);
  981. } else {
  982. obj.original_data = RGraph.array_clone(original_data);
  983. obj.__increments__ = null;
  984. RGraph.Clear(obj.canvas);
  985. RGraph.RedrawCanvas(obj.canvas);
  986. if (typeof(callback) == 'function') {
  987. callback(obj);
  988. }
  989. }
  990. }
  991. UnfoldFromCenter();
  992. }
  993. /**
  994. * UnfoldFromCenterTrace
  995. */
  996. RGraph.Effects.Line.jQuery.UnfoldFromCenterTrace = function (obj)
  997. {
  998. // Hide the canvas first
  999. obj.canvas.style.visibility = 'hidden';
  1000. setTimeout(function () {obj.canvas.style.visibility = 'visible';}, 10);
  1001. /**
  1002. * First draw the chart so we can get the max
  1003. */
  1004. obj.Draw();
  1005. RGraph.Clear(obj.canvas);
  1006. var data = RGraph.array_clone(obj.original_data);
  1007. var callback = arguments[2];
  1008. /**
  1009. * When the Trace function finishes it calls this function
  1010. */
  1011. function Unfold_callback ()
  1012. {
  1013. obj.original_data = data;
  1014. RGraph.Effects.Line.UnfoldFromCenter(obj, null, callback);
  1015. }
  1016. /**
  1017. * Determine the mid-point
  1018. */
  1019. var half = obj.Get('chart.xaxispos') == 'center' ? obj.min : ((obj.max - obj.min) / 2) + obj.min;
  1020. obj.Set('chart.ymax', obj.max);
  1021. for (var i=0; i<obj.original_data.length; ++i) {
  1022. for (var j=0; j<obj.original_data[i].length; ++j) {
  1023. obj.original_data[i][j] = (obj.Get('chart.filled') && obj.Get('chart.filled.accumulative') && i > 0) ? 0 : half;
  1024. }
  1025. }
  1026. //RGraph.Clear(obj.canvas);
  1027. RGraph.Effects.Line.jQuery.Trace(obj, {'duration':1000}, Unfold_callback);
  1028. }
  1029. /**
  1030. * FoldToCenter
  1031. *
  1032. * Line chart FoldTocenter
  1033. */
  1034. RGraph.Effects.Line.FoldToCenter = function (obj)
  1035. {
  1036. var totalFrames = 30;
  1037. var numFrame = totalFrames;
  1038. RGraph.RedrawCanvas(obj.canvas);
  1039. var center_value = obj.scale2.max / 2;
  1040. obj.Set('chart.ymax', obj.scale2.max);
  1041. RGraph.Clear(obj.canvas);
  1042. var original_data = RGraph.array_clone(obj.original_data);
  1043. obj.Set('chart.shadow.blur', 0);
  1044. var callback = arguments[2];
  1045. function FoldToCenter ()
  1046. {
  1047. for (var i=0; i<obj.data.length; ++i) {
  1048. if (obj.data[i].length) {
  1049. for (var j=0; j<obj.data[i].length; ++j) {
  1050. if (obj.original_data[i][j] > center_value) {
  1051. obj.original_data[i][j] = ((original_data[i][j] - center_value) * (numFrame/totalFrames)) + center_value;
  1052. } else {
  1053. obj.original_data[i][j] = center_value - ((center_value - original_data[i][j]) * (numFrame/totalFrames));
  1054. }
  1055. }
  1056. }
  1057. }
  1058. RGraph.Clear(obj.canvas);
  1059. RGraph.RedrawCanvas(obj.canvas)
  1060. if (numFrame-- > 0) {
  1061. RGraph.Effects.UpdateCanvas(FoldToCenter);
  1062. } else if (typeof(callback) == 'function') {
  1063. callback(obj);
  1064. }
  1065. }
  1066. RGraph.Effects.UpdateCanvas(FoldToCenter);
  1067. }
  1068. /**
  1069. * Odo Grow
  1070. *
  1071. * This effect gradually increases the represented value
  1072. *
  1073. * @param object obj The chart object
  1074. * @param Not used - pass null
  1075. * @param function An optional callback function
  1076. */
  1077. RGraph.Effects.Odo.Grow = function (obj)
  1078. {
  1079. var numFrames = 30;
  1080. var curFrame = 0;
  1081. var origValue = Number(obj.currentValue);
  1082. var newValue = obj.value;
  1083. var diff = newValue - origValue;
  1084. var step = (diff / numFrames);
  1085. var callback = arguments[2];
  1086. function Grow_inner ()
  1087. {
  1088. obj.value = origValue + (curFrame * step);
  1089. RGraph.Clear(obj.canvas);
  1090. RGraph.RedrawCanvas(obj.canvas);
  1091. if (++curFrame <= numFrames) {
  1092. RGraph.Effects.UpdateCanvas(Grow_inner);
  1093. } else if (callback) {
  1094. callback(obj);
  1095. }
  1096. }
  1097. //setTimeout(Grow, 100);
  1098. Grow_inner();
  1099. }
  1100. /**
  1101. * Meter Grow
  1102. *
  1103. * This effect gradually increases the represented value
  1104. *
  1105. * @param object obj The chart object
  1106. * @param Not used - pass null
  1107. * @param function An optional callback function
  1108. */
  1109. RGraph.Effects.Meter.Grow = function (obj)
  1110. {
  1111. if (!obj.currentValue) {
  1112. obj.currentValue = obj.min;
  1113. }
  1114. var totalFrames = 60;
  1115. var numFrame = 0;
  1116. var diff = obj.value - obj.currentValue;
  1117. var step = diff / totalFrames
  1118. var callback = arguments[2];
  1119. var initial = obj.currentValue;
  1120. function Grow_meter_inner ()
  1121. {
  1122. obj.value = initial + (numFrame++ * step);
  1123. RGraph.Clear(obj.canvas);
  1124. RGraph.RedrawCanvas(obj.canvas);
  1125. if (numFrame++ <= totalFrames) {
  1126. RGraph.Effects.UpdateCanvas(Grow_meter_inner);
  1127. } else if (typeof(callback) == 'function') {
  1128. callback(obj);
  1129. }
  1130. }
  1131. Grow_meter_inner();
  1132. }
  1133. /**
  1134. * Grow
  1135. *
  1136. * The HBar chart Grow effect gradually increases the values of the bars
  1137. *
  1138. * @param object obj The graph object
  1139. */
  1140. RGraph.Effects.HBar.Grow = function (obj)
  1141. {
  1142. // Save the data
  1143. obj.original_data = RGraph.array_clone(obj.data);
  1144. // Zero the data
  1145. obj.__animation_frame__ = 0;
  1146. // Stop the scale from changing by setting chart.ymax (if it's not already set)
  1147. if (obj.Get('chart.xmax') == 0) {
  1148. var xmax = 0;
  1149. for (var i=0; i<obj.data.length; ++i) {
  1150. if (RGraph.is_array(obj.data[i]) && obj.Get('chart.grouping') == 'stacked') {
  1151. xmax = Math.max(xmax, RGraph.array_sum(obj.data[i]));
  1152. } else if (RGraph.is_array(obj.data[i]) && obj.Get('chart.grouping') == 'grouped') {
  1153. xmax = Math.max(xmax, RGraph.array_max(obj.data[i]));
  1154. } else {
  1155. xmax = Math.max(xmax, RGraph.array_max(obj.data[i]));
  1156. }
  1157. }
  1158. var scale2 = RGraph.getScale2(obj, {'max':xmax});
  1159. obj.Set('chart.xmax', scale2.max);
  1160. }
  1161. /**
  1162. * Turn off shadow blur for the duration of the animation
  1163. */
  1164. if (obj.Get('chart.shadow.blur') > 0) {
  1165. var __original_shadow_blur__ = obj.Get('chart.shadow.blur');
  1166. obj.Set('chart.shadow.blur', 0);
  1167. }
  1168. function Grow ()
  1169. {
  1170. var numFrames = 30;
  1171. if (!obj.__animation_frame__) {
  1172. obj.__animation_frame__ = 0;
  1173. obj.__original_vmargin__ = obj.Get('chart.vmargin');
  1174. obj.__vmargin__ = ((obj.canvas.height - obj.Get('chart.gutter.top') - obj.Get('chart.gutter.bottom')) / obj.data.length) / 2;
  1175. obj.Set('chart.vmargin', obj.__vmargin__);
  1176. }
  1177. // Alter the Bar chart data depending on the frame
  1178. for (var j=0; j<obj.original_data.length; ++j) {
  1179. // This stops the animatioon from being completely linear
  1180. var easing = Math.pow(Math.sin((obj.__animation_frame__ * (90 / numFrames)) / (180 / PI)), 4);
  1181. if (typeof(obj.data[j]) == 'object') {
  1182. for (var k=0; k<obj.data[j].length; ++k) {
  1183. obj.data[j][k] = (obj.__animation_frame__ / numFrames) * obj.original_data[j][k] * easing;
  1184. }
  1185. } else {
  1186. obj.data[j] = (obj.__animation_frame__ / numFrames) * obj.original_data[j] * easing;
  1187. }
  1188. }
  1189. /**
  1190. * Increment the vmargin to the target
  1191. */
  1192. obj.Set('chart.vmargin', ((1 - (obj.__animation_frame__ / numFrames)) * (obj.__vmargin__ - obj.__original_vmargin__)) + obj.__original_vmargin__);
  1193. RGraph.Clear(obj.canvas);
  1194. RGraph.RedrawCanvas(obj.canvas);
  1195. if (obj.__animation_frame__ < numFrames) {
  1196. obj.__animation_frame__ += 1;
  1197. RGraph.Effects.UpdateCanvas(Grow);
  1198. // Turn any shadow blur back on
  1199. } else {
  1200. if (typeof(__original_shadow_blur__) == 'number' && __original_shadow_blur__ > 0) {
  1201. obj.Set('chart.shadow.blur', __original_shadow_blur__);
  1202. RGraph.Clear(obj.canvas);
  1203. RGraph.RedrawCanvas(obj.canvas);
  1204. }
  1205. }
  1206. }
  1207. RGraph.Effects.UpdateCanvas(Grow);
  1208. }
  1209. /**
  1210. * Trace
  1211. *
  1212. * This effect is for the Line chart, uses the jQuery library and slowly
  1213. * uncovers the Line , but you can see the background of the chart. This effect
  1214. * is quite new (1/10/2011) and as such should be used with caution.
  1215. *
  1216. * @param object obj The graph object
  1217. * @param object Not used
  1218. * @param int A number denoting how long (in millseconds) the animation should last for. Defauld
  1219. * is 1500
  1220. */
  1221. RGraph.Effects.Line.jQuery.Trace = function (obj)
  1222. {
  1223. var callback = typeof(arguments[2]) == 'function' ? arguments[2] : function () {};
  1224. var opt = arguments[1] || [];
  1225. if (!opt['duration']) {
  1226. opt['duration'] = 1000;
  1227. }
  1228. RGraph.Clear(obj.canvas);
  1229. //obj.Draw();
  1230. RGraph.RedrawCanvas(obj.canvas);
  1231. /**
  1232. * Create the DIV that the second canvas will sit in
  1233. */
  1234. var div = document.createElement('DIV');
  1235. var xy = RGraph.getCanvasXY(obj.canvas);
  1236. div.id = '__rgraph_trace_animation_' + RGraph.random(0, 4351623) + '__';
  1237. div.style.left = xy[0] + 'px';
  1238. div.style.top = xy[1] + 'px';
  1239. div.style.width = obj.Get('chart.gutter.left');
  1240. div.style.height = obj.canvas.height + 'px';
  1241. div.style.position = 'absolute';
  1242. div.style.overflow = 'hidden';
  1243. document.body.appendChild(div);
  1244. obj.canvas.__rgraph_trace_div__ = div;
  1245. /**
  1246. * Make the second canvas
  1247. */
  1248. var id = '__rgraph_line_trace_animation_' + RGraph.random(0, 99999999) + '__';
  1249. var canvas2 = document.createElement('CANVAS');
  1250. // Copy the 3D CSS transformation properties across from the original canvas
  1251. var properties = ['WebkitTransform','MozTransform','OTransform','MSTransform','transform'];
  1252. for (i in properties) {
  1253. var name = properties[i];
  1254. if (typeof(obj.canvas.style[name]) == 'string' && obj.canvas.style[name]) {
  1255. canvas2.style[name] = obj.canvas.style[name];
  1256. }
  1257. }
  1258. obj.canvas.__rgraph_line_canvas2__ = canvas2;
  1259. canvas2.width = obj.canvas.width;
  1260. canvas2.height = obj.canvas.height;
  1261. canvas2.style.position = 'absolute';
  1262. canvas2.style.left = 0;
  1263. canvas2.style.top = 0;
  1264. // This stops the clear effect clearing the canvas - which can happen if you have multiple canvas tags on the page all with
  1265. // dynamic effects that do redrawing
  1266. canvas2.noclear = true;
  1267. canvas2.id = id;
  1268. div.appendChild(canvas2);
  1269. var reposition_canvas2 = function (e)
  1270. {
  1271. var xy = RGraph.getCanvasXY(obj.canvas);
  1272. div.style.left = xy[0] + 'px';
  1273. div.style.top = xy[1] + 'px';
  1274. }
  1275. window.addEventListener('resize', reposition_canvas2, false)
  1276. /**
  1277. * Make a copy of the original Line object
  1278. */
  1279. var obj2 = new RGraph.Line(id, RGraph.array_clone(obj.original_data));
  1280. // Remove the new line from the ObjectRegistry so that it isn't redawn
  1281. RGraph.ObjectRegistry.Remove(obj2);
  1282. for (i in obj.properties) {
  1283. if (typeof(i) == 'string') {
  1284. obj2.Set(i, obj.properties[i]);
  1285. }
  1286. }
  1287. //obj2.Set('chart.tooltips', null);
  1288. obj2.Set('chart.labels', []);
  1289. obj2.Set('chart.background.grid', false);
  1290. obj2.Set('chart.background.barcolor1', 'rgba(0,0,0,0)');
  1291. obj2.Set('chart.background.barcolor2', 'rgba(0,0,0,0)');
  1292. obj2.Set('chart.ylabels', false);
  1293. obj2.Set('chart.noaxes', true);
  1294. obj2.Set('chart.title', '');
  1295. obj2.Set('chart.title.xaxis', '');
  1296. obj2.Set('chart.title.yaxis', '');
  1297. obj2.Set('chart.filled.accumulative', obj.Get('chart.filled.accumulative'));
  1298. obj.Set('chart.key', []);
  1299. obj2.Draw();
  1300. obj.canvas.__rgraph_trace_obj2__ = obj2;
  1301. /**
  1302. * This effectively hides the line
  1303. */
  1304. obj.Set('chart.line.visible', false);
  1305. obj.Set('chart.colors', ['rgba(0,0,0,0)']);
  1306. if (obj.Get('chart.filled')) {
  1307. var original_fillstyle = obj.Get('chart.fillstyle');
  1308. obj.Set('chart.fillstyle', 'rgba(0,0,0,0)');
  1309. obj.Set('chart.animation.trace.original.fillstyle', original_fillstyle);
  1310. }
  1311. RGraph.Clear(obj.canvas);
  1312. //obj.Draw();
  1313. RGraph.RedrawCanvas(obj.canvas);
  1314. /**
  1315. * Place a DIV over the canvas to stop interaction with it
  1316. */
  1317. if (!obj.canvas.__rgraph_trace_cover__) {
  1318. var div2 = document.createElement('DIV');
  1319. div2.id = '__rgraph_trace_animation_' + RGraph.random(0, 4351623) + '__';
  1320. div2.style.left = xy[0] + 'px';
  1321. div2.style.top = xy[1] + 'px';
  1322. div2.style.width = obj.canvas.width + 'px';
  1323. div2.style.height = obj.canvas.height + 'px';
  1324. div2.style.position = 'absolute';
  1325. div2.style.overflow = 'hidden';
  1326. div2.style.backgroundColor = 'rgba(0,0,0,0)';
  1327. div.div2 = div2;
  1328. obj.canvas.__rgraph_trace_cover__ = div2;
  1329. document.body.appendChild(div2);
  1330. } else {
  1331. div2 = obj.canvas.__rgraph_trace_cover__;
  1332. }
  1333. /**
  1334. * Animate the DIV that contains the canvas
  1335. */
  1336. jQuery('#' + div.id).animate({
  1337. width: obj.canvas.width + 'px'
  1338. }, opt['duration'], function () {RGraph.Effects.Line.Trace_callback(obj)});
  1339. /**
  1340. * Get rid of the second canvas and turn the line back on
  1341. * on the original.
  1342. */
  1343. RGraph.Effects.Line.Trace_callback = function (obj)
  1344. {
  1345. var obj2 = obj.canvas.__rgraph_trace_obj2__;
  1346. // Remove the window resize listener
  1347. window.removeEventListener('resize', reposition_canvas2, false);
  1348. div.style.display = 'none';
  1349. div2.style.display = 'none';
  1350. //div.removeChild(canvas2);
  1351. obj.Set('chart.line.visible', true);
  1352. // Revert the filled status back to as it was
  1353. obj.Set('chart.filled', RGraph.array_clone(obj2.Get('chart.filled')));
  1354. obj.Set('chart.fillstyle', obj.Get('chart.animation.trace.original.fillstyle'));
  1355. obj.Set('chart.colors', RGraph.array_clone(obj2.Get('chart.colors')));
  1356. obj.Set('chart.key', RGraph.array_clone(obj2.Get('chart.key')));
  1357. RGraph.RedrawCanvas(obj.canvas);
  1358. obj.canvas.__rgraph_trace_div__.style.display = 'none';
  1359. obj.canvas.__rgraph_trace_div__ = null;
  1360. obj.canvas.__rgraph_line_canvas2__.style.display = 'none';
  1361. obj.canvas.__rgraph_line_canvas2__ = null;
  1362. obj.canvas.__rgraph_trace_cover__.style.display = 'none';
  1363. obj.canvas.__rgraph_trace_cover__ = null;
  1364. callback(obj);
  1365. }
  1366. }
  1367. /**
  1368. * Trace2
  1369. *
  1370. * This is a new version of the Trace effect which no longer requires jQuery and is more compatible
  1371. * with other effects (eg Expand). This new effect is considerably simpler and less code.
  1372. *
  1373. * @param object obj The graph object
  1374. * @param object Options for the effect. Currently only "frames" is available.
  1375. * @param int A function that is called when the ffect is complete
  1376. */
  1377. RGraph.Effects.Line.Trace2 = function (obj)
  1378. {
  1379. var callback = arguments[2];
  1380. var numFrames = (arguments[1] && arguments[1].frames) ? arguments[1].frames : 15;
  1381. var frame = 0;
  1382. obj.Set('animation.trace.clip', 0);
  1383. function Grow ()
  1384. {
  1385. if (frame > numFrames) {
  1386. if (callback) {
  1387. callback(obj);
  1388. }
  1389. return;
  1390. }
  1391. obj.Set('animation.trace.clip', frame / numFrames );
  1392. RGraph.RedrawCanvas(obj.canvas);
  1393. frame++;
  1394. RGraph.Effects.UpdateCanvas(Grow);
  1395. }
  1396. Grow();
  1397. }
  1398. /**
  1399. * Trace (Radar chart)
  1400. *
  1401. * This is a Trace effect for the Radar chart
  1402. *
  1403. * @param object obj The graph object
  1404. * @param object Options for the effect. Currently only "frames" is available.
  1405. * @param function A function that is called when the ffect is complete
  1406. */
  1407. RGraph.Effects.Radar.Trace = function (obj)
  1408. {
  1409. var callback = arguments[2];
  1410. var numFrames = (arguments[1] && arguments[1].frames) ? arguments[1].frames : 60;
  1411. var frame = 0;
  1412. obj.Set('animation.trace.clip', 0);
  1413. function Grow ()
  1414. {
  1415. if (frame > numFrames) {
  1416. if (callback) {
  1417. callback(obj);
  1418. }
  1419. return;
  1420. }
  1421. obj.Set('animation.trace.clip', frame / numFrames );
  1422. RGraph.RedrawCanvas(obj.canvas);
  1423. frame++;
  1424. RGraph.Effects.UpdateCanvas(Grow);
  1425. }
  1426. Grow();
  1427. }
  1428. /**
  1429. * RoundRobin
  1430. *
  1431. * This effect does two things:
  1432. * 1. Gradually increases the size of each segment
  1433. * 2. Gradually increases the size of the radius from 0
  1434. *
  1435. * @param object obj The graph object
  1436. */
  1437. RGraph.Effects.Pie.RoundRobin = function (obj)
  1438. {
  1439. var callback = arguments[2] ? arguments[2] : null;
  1440. var opt = arguments[1];
  1441. var currentFrame = 0;
  1442. var numFrames = (opt && opt['frames']) ? opt['frames'] : 90;
  1443. var targetRadius = obj.getRadius();
  1444. obj.Set('chart.events', false);
  1445. // Fix for donuts
  1446. if (obj.properties['chart.variant'] == 'donut' && typeof(obj.properties['chart.variant.donut.width']) == 'number') {
  1447. if (RGraph.is_null(opt)) {
  1448. var opt = {radius: null}
  1449. } else {
  1450. opt.radius = null;
  1451. }
  1452. }
  1453. function RoundRobin_inner ()
  1454. {
  1455. obj.Set('chart.effect.roundrobin.multiplier', Math.pow(Math.sin((currentFrame * (90 / numFrames)) / (180 / PI)), 2) * (currentFrame / numFrames) );
  1456. if (!opt || typeof(opt['radius']) == 'undefined' || opt['radius'] == true) {
  1457. obj.Set('chart.radius', targetRadius * obj.Get('chart.effect.roundrobin.multiplier'));
  1458. }
  1459. RGraph.RedrawCanvas(obj.canvas);
  1460. if (currentFrame++ < numFrames) {
  1461. RGraph.Effects.UpdateCanvas(RoundRobin_inner);
  1462. } else {
  1463. // Re-enable the events and redraw the chart.
  1464. obj.Set('chart.events', true);
  1465. RGraph.RedrawCanvas(obj.canvas);
  1466. if (callback) {
  1467. callback(obj);
  1468. }
  1469. }
  1470. }
  1471. RGraph.Effects.UpdateCanvas(RoundRobin_inner);
  1472. }
  1473. /**
  1474. * Implode (pie chart)
  1475. *
  1476. * Here the segments are initially exploded - and gradually
  1477. * contract inwards to create the Pie chart
  1478. *
  1479. * @param object obj The Pie chart object
  1480. */
  1481. RGraph.Effects.Pie.Implode = function (obj)
  1482. {
  1483. var numFrames = 90;
  1484. var distance = Math.min(obj.canvas.width, obj.canvas.height);
  1485. var exploded = obj.Get('chart.exploded');
  1486. var callback = arguments[2];
  1487. function Implode_inner ()
  1488. {
  1489. obj.Set('chart.exploded', Math.sin(numFrames / (180 / PI)) * distance);
  1490. RGraph.Clear(obj.canvas)
  1491. //obj.Draw();
  1492. RGraph.RedrawCanvas(obj.canvas);
  1493. if (numFrames > 0) {
  1494. numFrames--;
  1495. RGraph.Effects.UpdateCanvas(Implode_inner);
  1496. } else {
  1497. // Finish off the animation
  1498. obj.Set('chart.exploded', exploded);
  1499. RGraph.Clear(obj.canvas);
  1500. RGraph.RedrawCanvas(obj.canvas);
  1501. if (typeof(callback) == 'function') {
  1502. callback(obj);
  1503. }
  1504. }
  1505. }
  1506. RGraph.Effects.UpdateCanvas(Implode_inner);
  1507. }
  1508. /**
  1509. * Pie chart explode
  1510. *
  1511. * Explodes the Pie chart - gradually incrementing the size of the chart.explode property
  1512. *
  1513. * @params object obj The graph object
  1514. */
  1515. RGraph.Effects.Pie.Explode = function (obj)
  1516. {
  1517. var canvas = obj.canvas;
  1518. var opts = arguments[1] ? arguments[1] : [];
  1519. var callback = arguments[2] ? arguments[2] : null;
  1520. var frames = opts['frames'] ? opts['frames'] : 60;
  1521. obj.Set('chart.exploded', 0);
  1522. RGraph.Effects.Animate(obj, {'frames': frames, 'chart.exploded': Math.max(canvas.width, canvas.height)}, callback);
  1523. }
  1524. /**
  1525. * Gauge Grow
  1526. *
  1527. * This effect gradually increases the represented value
  1528. *
  1529. * @param object obj The chart object
  1530. * @param Not used - pass null
  1531. * @param function An optional callback function
  1532. */
  1533. RGraph.Effects.Gauge.Grow = function (obj)
  1534. {
  1535. var callback = arguments[2];
  1536. var numFrames = 30;
  1537. var frame = 0;
  1538. // Single pointer
  1539. if (typeof(obj.value) == 'number') {
  1540. var origValue = Number(obj.currentValue);
  1541. if (obj.currentValue == null) {
  1542. obj.currentValue = obj.min;
  1543. origValue = obj.min;
  1544. }
  1545. var newValue = obj.value;
  1546. var diff = newValue - origValue;
  1547. var step = (diff / numFrames);
  1548. var frame = 0;
  1549. function Grow_single ()
  1550. {
  1551. frame++;
  1552. obj.value = ((frame / numFrames) * diff) + origValue;
  1553. if (obj.value > obj.max) obj.value = obj.max;
  1554. if (obj.value < obj.min) obj.value = obj.min;
  1555. RGraph.Clear(obj.canvas);
  1556. RGraph.RedrawCanvas(obj.canvas);
  1557. if (frame < 30) {
  1558. RGraph.Effects.UpdateCanvas(Grow_single);
  1559. } else if (typeof(callback) == 'function') {
  1560. callback(obj);
  1561. }
  1562. }
  1563. Grow_single();
  1564. // Multiple pointers
  1565. } else {
  1566. if (obj.currentValue == null) {
  1567. obj.currentValue = [];
  1568. for (var i=0; i<obj.value.length; ++i) {
  1569. obj.currentValue[i] = obj.min;
  1570. }
  1571. origValue = RGraph.array_clone(obj.currentValue);
  1572. }
  1573. var origValue = RGraph.array_clone(obj.currentValue);
  1574. var newValue = RGraph.array_clone(obj.value);
  1575. var diff = [];
  1576. var step = [];
  1577. for (var i=0; i<newValue.length; ++i) {
  1578. diff[i] = newValue[i] - Number(obj.currentValue[i]);
  1579. step[i] = (diff[i] / numFrames);
  1580. }
  1581. function Grow_multiple ()
  1582. {
  1583. frame++;
  1584. for (var i=0; i<obj.value.length; ++i) {
  1585. obj.value[i] = ((frame / numFrames) * diff[i]) + origValue[i];
  1586. if (obj.value[i] > obj.max) obj.value[i] = obj.max;
  1587. if (obj.value[i] < obj.min) obj.value[i] = obj.min;
  1588. RGraph.Clear(obj.canvas);
  1589. RGraph.RedrawCanvas(obj.canvas);
  1590. }
  1591. if (frame < 30) {
  1592. RGraph.Effects.UpdateCanvas(Grow_multiple);
  1593. } else if (typeof(callback) == 'function') {
  1594. callback(obj);
  1595. }
  1596. }
  1597. Grow_multiple();
  1598. }
  1599. }
  1600. /**
  1601. * Radar chart grow
  1602. *
  1603. * This effect gradually increases the magnitude of the points on the radar chart
  1604. *
  1605. * @param object obj The chart object
  1606. * @param null Not used
  1607. * @param function An optional callback that is run when the effect is finished
  1608. */
  1609. RGraph.Effects.Radar.Grow = function (obj)
  1610. {
  1611. var totalframes = 30;
  1612. var framenum = totalframes;
  1613. var data = RGraph.array_clone(obj.data);
  1614. var callback = arguments[2];
  1615. obj.original_data = RGraph.array_clone(obj.original_data);
  1616. function Grow_inner ()
  1617. {
  1618. for (var i=0; i<data.length; ++i) {
  1619. if (obj.original_data[i] == null) {
  1620. obj.original_data[i] = [];
  1621. }
  1622. for (var j=0; j<data[i].length; ++j) {
  1623. obj.original_data[i][j] = ((totalframes - framenum)/totalframes) * data[i][j];
  1624. }
  1625. }
  1626. RGraph.Clear(obj.canvas);
  1627. RGraph.RedrawCanvas(obj.canvas);
  1628. if (framenum > 0) {
  1629. framenum--;
  1630. RGraph.Effects.UpdateCanvas(Grow_inner);
  1631. } else if (typeof(callback) == 'function') {
  1632. callback(obj);
  1633. }
  1634. }
  1635. RGraph.Effects.UpdateCanvas(Grow_inner);
  1636. }
  1637. /**
  1638. * Waterfall Grow
  1639. *
  1640. * @param object obj The chart object
  1641. * @param null Not used
  1642. * @param function An optional function which is called when the animation is finished
  1643. */
  1644. RGraph.Effects.Waterfall.Grow = function (obj)
  1645. {
  1646. var totalFrames = 45;
  1647. var numFrame = 0;
  1648. var data = RGraph.array_clone(obj.data);
  1649. var callback = arguments[2];
  1650. //Reset The data to zeros
  1651. for (var i=0; i<obj.data.length; ++i) {
  1652. obj.data[i] /= totalFrames;
  1653. }
  1654. /**
  1655. * Fix the scale
  1656. */
  1657. if (obj.Get('chart.ymax') == null) {
  1658. var max = obj.getMax(data);
  1659. var scale2 = RGraph.getScale2(obj, {'max':max});
  1660. obj.Set('chart.ymax', scale2.max);
  1661. }
  1662. //obj.Set('chart.multiplier.x', 0);
  1663. //obj.Set('chart.multiplier.w', 0);
  1664. function Grow_inner ()
  1665. {
  1666. for (var i=0; i<obj.data.length; ++i) {
  1667. obj.data[i] = data[i] * (numFrame/totalFrames);
  1668. }
  1669. var multiplier = Math.pow(Math.sin(((numFrame / totalFrames) * 90) / (180 / PI)), 20);
  1670. //obj.Set('chart.multiplier.x', (numFrame / totalFrames) * multiplier);
  1671. //obj.Set('chart.multiplier.w', (numFrame / totalFrames) * multiplier);
  1672. RGraph.Clear(obj.canvas);
  1673. RGraph.RedrawCanvas(obj.canvas);
  1674. if (numFrame++ < totalFrames) {
  1675. RGraph.Effects.UpdateCanvas(Grow_inner);
  1676. } else if (typeof(callback) == 'function') {
  1677. callback(obj);
  1678. }
  1679. }
  1680. RGraph.Effects.UpdateCanvas(Grow_inner)
  1681. }
  1682. /**
  1683. * Bar chart Wave effect This effect defaults to 30 frames - which is
  1684. * approximately half a second
  1685. *
  1686. * @param object obj The chart object
  1687. */
  1688. RGraph.Effects.Bar.Wave2 =
  1689. RGraph.Effects.Bar.Wave = function (obj)
  1690. {
  1691. var totalframes = (arguments[1] && arguments[1].frames) ? arguments[1].frames : 15;
  1692. var original_data = [];
  1693. obj.Draw();
  1694. //var scale = RGraph.getScale2(obj, {'max':obj.max});
  1695. obj.Set('chart.ymax', obj.scale2.max);
  1696. RGraph.Clear(obj.canvas);
  1697. for (var i=0; i<obj.data.length; ++i) {
  1698. (function (idx)
  1699. {
  1700. original_data[i] = obj.data[i];
  1701. obj.data[i] = typeof(obj.data[i]) == 'object' ? [] : 0;
  1702. setTimeout(function () {Iterator(idx, totalframes);}, 100 * i)
  1703. })(i);
  1704. }
  1705. function Iterator(idx, frames)
  1706. {
  1707. if (frames-- > 0) {
  1708. // Update the data point
  1709. if (typeof(obj.data[idx]) == 'number') {
  1710. obj.data[idx] = ((totalframes - frames) / totalframes) * original_data[idx]
  1711. } else if (typeof(obj.data[idx]) == 'object') {
  1712. for (var k=0; k<original_data[idx].length; ++k) {
  1713. obj.data[idx][k] = ((totalframes - frames) / totalframes) * original_data[idx][k];
  1714. }
  1715. }
  1716. RGraph.Clear(obj.canvas);
  1717. RGraph.RedrawCanvas(obj.canvas);
  1718. RGraph.Effects.UpdateCanvas(function () {Iterator(idx, frames);});
  1719. }
  1720. }
  1721. }
  1722. /**
  1723. * HProgress Grow effect (which is also the VPogress Grow effect)
  1724. *
  1725. * @param object obj The chart object
  1726. */
  1727. RGraph.Effects.VProgress.Grow =
  1728. RGraph.Effects.HProgress.Grow = function (obj)
  1729. {
  1730. var canvas = obj.canvas;
  1731. var context = obj.context;
  1732. var initial_value = obj.currentValue;
  1733. var numFrames = 30;
  1734. var currentFrame = 0
  1735. if (typeof(obj.value) == 'object') {
  1736. if (RGraph.is_null(obj.currentValue)) {
  1737. obj.currentValue = [];
  1738. for (var i=0; i<obj.value.length; ++i) {
  1739. obj.currentValue[i] = 0;
  1740. }
  1741. }
  1742. var diff = [];
  1743. var increment = [];
  1744. for (var i=0; i<obj.value.length; ++i) {
  1745. diff[i] = obj.value[i] - Number(obj.currentValue[i]);
  1746. increment[i] = diff[i] / numFrames;
  1747. }
  1748. if (initial_value == null) {
  1749. initial_value = [];
  1750. for (var i=0; i< obj.value.length; ++i) {
  1751. initial_value[i] = 0;
  1752. }
  1753. }
  1754. } else {
  1755. var diff = obj.value - Number(obj.currentValue);
  1756. var increment = diff / numFrames;
  1757. }
  1758. var callback = arguments[2] ? arguments[2] : null;
  1759. function Grow ()
  1760. {
  1761. currentFrame++;
  1762. if (currentFrame <= numFrames) {
  1763. if (typeof(obj.value) == 'object') {
  1764. obj.value = [];
  1765. for (var i=0; i<initial_value.length; ++i) {
  1766. obj.value[i] = initial_value[i] + (increment[i] * currentFrame);
  1767. }
  1768. } else {
  1769. obj.value = initial_value + (increment * currentFrame);
  1770. }
  1771. RGraph.Clear(obj.canvas);
  1772. RGraph.RedrawCanvas(obj.canvas);
  1773. RGraph.Effects.UpdateCanvas(Grow);
  1774. } else if (callback) {
  1775. callback(obj);
  1776. }
  1777. }
  1778. RGraph.Effects.UpdateCanvas(Grow);
  1779. }
  1780. /**
  1781. * Gantt chart Grow effect
  1782. *
  1783. * @param object obj The chart object
  1784. */
  1785. RGraph.Effects.Gantt.Grow = function (obj)
  1786. {
  1787. var canvas = obj.canvas;
  1788. var context = obj.context;
  1789. var numFrames = 30;
  1790. var currentFrame = 0;
  1791. var callback = arguments[2] ? arguments[2] : null;
  1792. var events = obj.data;
  1793. var original_events = RGraph.array_clone(events);
  1794. function Grow_gantt_inner ()
  1795. {
  1796. if (currentFrame <= numFrames) {
  1797. // Update the events
  1798. for (var i=0; i<events.length; ++i) {
  1799. if (typeof(events[i][0]) == 'object') {
  1800. for (var j=0; j<events[i].length; ++j) {
  1801. events[i][j][1] = (currentFrame / numFrames) * original_events[i][j][1];
  1802. }
  1803. } else {
  1804. events[i][1] = (currentFrame / numFrames) * original_events[i][1];
  1805. }
  1806. }
  1807. obj.data = events;
  1808. RGraph.Clear(obj.canvas);
  1809. RGraph.RedrawCanvas(obj.canvas);
  1810. currentFrame++;
  1811. RGraph.Effects.UpdateCanvas(Grow_gantt_inner);
  1812. } else if (callback) {
  1813. callback(obj);
  1814. }
  1815. }
  1816. RGraph.Effects.UpdateCanvas(Grow_gantt_inner);
  1817. }
  1818. /**
  1819. * This is a compatibility hack provided for Opera and Safari which
  1820. * don't support ther Javascript 1.8.5 function.bind()
  1821. */
  1822. if (!Function.prototype.bind) {
  1823. Function.prototype.bind = function (oThis) {
  1824. if (typeof this !== "function") {
  1825. // closest thing possible to the ECMAScript 5 internal IsCallable function
  1826. if (console && console.log) {
  1827. console.log('Function.prototype.bind - what is trying to be bound is not callable');
  1828. }
  1829. }
  1830. var aArgs = Array.prototype.slice.call(arguments, 1),
  1831. fToBind = this,
  1832. fNOP = function () {},
  1833. fBound = function () {
  1834. return fToBind.apply(this instanceof fNOP
  1835. ? this
  1836. : oThis || window,
  1837. aArgs.concat(Array.prototype.slice.call(arguments)));
  1838. };
  1839. fNOP.prototype = this.prototype;
  1840. fBound.prototype = new fNOP();
  1841. return fBound;
  1842. };
  1843. }
  1844. /**
  1845. * Rose chart explode
  1846. *
  1847. * Explodes the Rose chart - gradually incrementing the size of the chart.explode property
  1848. *
  1849. * @params object obj The graph object
  1850. */
  1851. RGraph.Effects.Rose.Explode = function (obj)
  1852. {
  1853. var canvas = obj.canvas;
  1854. var opts = arguments[1] ? arguments[1] : [];
  1855. var callback = arguments[2] ? arguments[2] : null;
  1856. var frames = opts['frames'] ? opts['frames'] : 60;
  1857. obj.Set('chart.exploded', 0);
  1858. RGraph.Effects.Animate(obj, {'frames': frames, 'chart.exploded': Math.min(canvas.width, canvas.height)}, callback);
  1859. }
  1860. /**
  1861. * Rose chart implode
  1862. *
  1863. * Implodes the Rose chart - gradually decreasing the size of the chart.explode property. It starts at the largest of
  1864. * the canvas width./height
  1865. *
  1866. * @params object obj The graph object
  1867. */
  1868. RGraph.Effects.Rose.Implode = function (obj)
  1869. {
  1870. var canvas = obj.canvas;
  1871. var opts = arguments[1] ? arguments[1] : [];
  1872. var callback = arguments[2] ? arguments[2] : null;
  1873. var frames = opts['frames'] ? opts['frames'] : 60;
  1874. obj.Set('chart.exploded', Math.min(canvas.width, canvas.height));
  1875. RGraph.Effects.Animate(obj, {'frames': frames, 'chart.exploded': 0}, callback);
  1876. }
  1877. /**
  1878. * Gauge Grow
  1879. *
  1880. * This effect gradually increases the represented value
  1881. *
  1882. * @param object obj The chart object
  1883. * @param Not used - pass null
  1884. * @param function An optional callback function
  1885. */
  1886. RGraph.Effects.Thermometer.Grow = function (obj)
  1887. {
  1888. var callback = arguments[2];
  1889. var numFrames = 30;
  1890. var origValue = Number(obj.currentValue);
  1891. if (obj.currentValue == null) {
  1892. obj.currentValue = 0
  1893. origValue = 0;
  1894. }
  1895. var newValue = obj.value;
  1896. var diff = newValue - origValue;
  1897. var step = (diff / numFrames);
  1898. var frame = 0;
  1899. function Grow ()
  1900. {
  1901. frame++
  1902. // Set the new value
  1903. obj.value = v = ((frame / numFrames) * diff) + origValue
  1904. RGraph.Clear(obj.canvas);
  1905. RGraph.RedrawCanvas(obj.canvas);
  1906. if (frame < 30) {
  1907. RGraph.Effects.UpdateCanvas(Grow);
  1908. } else if (typeof(callback) == 'function') {
  1909. callback(obj);
  1910. }
  1911. }
  1912. RGraph.Effects.UpdateCanvas(Grow);
  1913. }
  1914. /**
  1915. * Trace
  1916. *
  1917. * This effect is for the Scatter chart, uses the jQuery library and slowly
  1918. * uncovers the Line/marks, but you can see the background of the chart.
  1919. *
  1920. * @param object obj The graph object
  1921. * @param object Options - you can specify duration to set how long the effect lasts for
  1922. */
  1923. RGraph.Effects.Scatter.jQuery.Trace = function (obj)
  1924. {
  1925. var callback = typeof(arguments[2]) == 'function' ? arguments[2] : function () {};
  1926. var opt = arguments[1] || [];
  1927. if (!opt['duration']) {
  1928. opt['duration'] = 1500;
  1929. }
  1930. RGraph.Clear(obj.canvas);
  1931. RGraph.RedrawCanvas(obj.canvas);
  1932. /**
  1933. * Create the DIV that the second canvas will sit in
  1934. */
  1935. var div = document.createElement('DIV');
  1936. var xy = RGraph.getCanvasXY(obj.canvas);
  1937. div.id = '__rgraph_trace_animation_' + RGraph.random(0, 4351623) + '__';
  1938. div.style.left = xy[0] + 'px';
  1939. div.style.top = xy[1] + 'px';
  1940. div.style.width = obj.Get('chart.gutter.left');
  1941. div.style.height = obj.canvas.height + 'px';
  1942. div.style.position = 'absolute';
  1943. div.style.overflow = 'hidden';
  1944. document.body.appendChild(div);
  1945. /**
  1946. * Make the second canvas
  1947. */
  1948. var id = '__rgraph_scatter_trace_animation_' + RGraph.random(0, 99999999) + '__';
  1949. var canvas2 = document.createElement('CANVAS');
  1950. canvas2.width = obj.canvas.width;
  1951. canvas2.height = obj.canvas.height;
  1952. canvas2.style.position = 'absolute';
  1953. canvas2.style.left = 0;
  1954. canvas2.style.top = 0;
  1955. // This stops the clear effect clearing the canvas - which can happen if you have multiple canvas tags on the page all with
  1956. // dynamic effects that do redrawing
  1957. canvas2.noclear = true;
  1958. canvas2.id = id;
  1959. div.appendChild(canvas2);
  1960. var reposition_canvas2 = function (e)
  1961. {
  1962. var xy = RGraph.getCanvasXY(obj.canvas);
  1963. div.style.left = xy[0] + 'px';
  1964. div.style.top = xy[1] + 'px';
  1965. }
  1966. window.addEventListener('resize', reposition_canvas2, false)
  1967. /**
  1968. * Make a copy of the original Line object
  1969. */
  1970. var obj2 = new RGraph.Scatter(id, RGraph.array_clone(obj.data));
  1971. // Remove the new line from the ObjectRegistry so that it isn't redawn
  1972. RGraph.ObjectRegistry.Remove(obj2);
  1973. for (i in obj.properties) {
  1974. if (typeof(i) == 'string') {
  1975. obj2.Set(i, obj.properties[i]);
  1976. }
  1977. }
  1978. obj2.Set('chart.labels', []);
  1979. obj2.Set('chart.background.grid', false);
  1980. obj2.Set('chart.background.barcolor1', 'rgba(0,0,0,0)');
  1981. obj2.Set('chart.background.barcolor2', 'rgba(0,0,0,0)');
  1982. obj2.Set('chart.ylabels', false);
  1983. obj2.Set('chart.noaxes', true);
  1984. obj2.Set('chart.title', '');
  1985. obj2.Set('chart.title.xaxis', '');
  1986. obj2.Set('chart.title.yaxis', '');
  1987. obj.Set('chart.key', []);
  1988. obj2.Draw();
  1989. /**
  1990. * This effectively hides the line
  1991. */
  1992. obj.Set('chart.line.visible', false);
  1993. RGraph.Clear(obj.canvas);
  1994. RGraph.RedrawCanvas(obj.canvas);
  1995. /**
  1996. * Place a DIV over the canvas to stop interaction with it
  1997. */
  1998. if (!obj.canvas.__rgraph_scatter_trace_cover__) {
  1999. var div2 = document.createElement('DIV');
  2000. div2.id = '__rgraph_trace_animation_' + RGraph.random(0, 4351623) + '__';
  2001. div2.style.left = xy[0] + 'px';
  2002. div2.style.top = xy[1] + 'px';
  2003. div2.style.width = obj.canvas.width + 'px';
  2004. div2.style.height = obj.canvas.height + 'px';
  2005. div2.style.position = 'absolute';
  2006. div2.style.overflow = 'hidden';
  2007. div2.style.backgroundColor = 'rgba(0,0,0,0)';
  2008. div.div2 = div2;
  2009. obj.canvas.__rgraph_scatter_trace_cover__ = div2
  2010. document.body.appendChild(div2);
  2011. } else {
  2012. div2 = obj.canvas.__rgraph_scatter_trace_cover__;
  2013. }
  2014. /**
  2015. * Animate the DIV that contains the canvas
  2016. */
  2017. jQuery('#' + div.id).animate({
  2018. width: obj.canvas.width + 'px'
  2019. }, opt['duration'], function () {
  2020. // Remove the window resize listener
  2021. window.removeEventListener('resize', reposition_canvas2, false);
  2022. div.style.display = 'none';
  2023. div2.style.display = 'none';
  2024. //div.removeChild(canvas2);
  2025. obj.Set('chart.line.visible', true);
  2026. // Revert the colors back to what they were
  2027. obj.Set('chart.colors', RGraph.array_clone(obj2.Get('chart.colors')));
  2028. obj.Set('chart.key', RGraph.array_clone(obj2.Get('chart.key')));
  2029. RGraph.RedrawCanvas(obj.canvas);
  2030. obj.canvas.__rgraph_trace_cover__ = null;
  2031. callback(obj);
  2032. });
  2033. }
  2034. /**
  2035. * CornerGauge Grow
  2036. *
  2037. * This effect gradually increases the represented value
  2038. *
  2039. * @param object obj The chart object
  2040. * @param Not used - pass null
  2041. * @param function An optional callback function
  2042. */
  2043. RGraph.Effects.CornerGauge.Grow = function (obj)
  2044. {
  2045. var callback = arguments[2];
  2046. var numFrames = 30;
  2047. var frame = 0;
  2048. // Single pointer
  2049. if (typeof(obj.value) == 'number') {
  2050. var origValue = Number(obj.currentValue);
  2051. if (obj.currentValue == null) {
  2052. obj.currentValue = obj.min;
  2053. origValue = obj.min;
  2054. }
  2055. var newValue = obj.value;
  2056. var diff = newValue - origValue;
  2057. var step = (diff / numFrames);
  2058. var frame = 0;
  2059. function Grow_single ()
  2060. {
  2061. frame++;
  2062. obj.value = ((frame / numFrames) * diff) + origValue
  2063. if (obj.value > obj.max) obj.value = obj.max;
  2064. if (obj.value < obj.min) obj.value = obj.min;
  2065. RGraph.Clear(obj.canvas);
  2066. RGraph.RedrawCanvas(obj.canvas);
  2067. if (frame < 30) {
  2068. RGraph.Effects.UpdateCanvas(Grow_single);
  2069. } else if (typeof(callback) == 'function') {
  2070. callback(obj);
  2071. }
  2072. }
  2073. Grow_single();
  2074. // Multiple pointers
  2075. } else {
  2076. if (obj.currentValue == null) {
  2077. obj.currentValue = [];
  2078. for (var i=0; i<obj.value.length; ++i) {
  2079. obj.currentValue[i] = obj.min;
  2080. }
  2081. origValue = RGraph.array_clone(obj.currentValue);
  2082. }
  2083. var origValue = RGraph.array_clone(obj.currentValue);
  2084. var newValue = RGraph.array_clone(obj.value);
  2085. var diff = [];
  2086. var step = [];
  2087. for (var i=0; i<newValue.length; ++i) {
  2088. diff[i] = newValue[i] - Number(obj.currentValue[i]);
  2089. step[i] = (diff[i] / numFrames);
  2090. }
  2091. function Grow_multiple ()
  2092. {
  2093. frame++;
  2094. for (var i=0; i<obj.value.length; ++i) {
  2095. obj.value[i] = ((frame / numFrames) * diff[i]) + origValue[i];
  2096. if (obj.value[i] > obj.max) obj.value[i] = obj.max;
  2097. if (obj.value[i] < obj.min) obj.value[i] = obj.min;
  2098. RGraph.Clear(obj.canvas);
  2099. RGraph.RedrawCanvas(obj.canvas);
  2100. }
  2101. if (frame < 30) {
  2102. RGraph.Effects.UpdateCanvas(Grow_multiple);
  2103. } else if (typeof(callback) == 'function') {
  2104. callback(obj);
  2105. }
  2106. }
  2107. Grow_multiple();
  2108. }
  2109. }
  2110. /**
  2111. * Rose chart Grow
  2112. *
  2113. * This effect gradually increases the size of the Rose chart
  2114. *
  2115. * @param object obj The chart object
  2116. * @param Not used - pass null
  2117. * @param function An optional callback function
  2118. */
  2119. RGraph.Effects.Rose.Grow = function (obj)
  2120. {
  2121. var callback = arguments[2];
  2122. var numFrames = 60;
  2123. var frame = 0;
  2124. function Grow ()
  2125. {
  2126. frame++;
  2127. obj.Set('chart.animation.grow.multiplier', frame / numFrames);
  2128. RGraph.Clear(obj.canvas);
  2129. RGraph.RedrawCanvas(obj.canvas);
  2130. if (frame < numFrames) {
  2131. ++frame;
  2132. RGraph.Effects.UpdateCanvas(Grow);
  2133. } else {
  2134. obj.Set('chart.animation.grow.multiplier', 1);
  2135. RGraph.Clear(obj.canvas);
  2136. RGraph.RedrawCanvas(obj.canvas);
  2137. if (typeof(callback) == 'function') {
  2138. callback(obj);
  2139. }
  2140. }
  2141. }
  2142. RGraph.Effects.UpdateCanvas(Grow);
  2143. }
  2144. /**
  2145. * Horizontal Scissors (open)
  2146. *
  2147. * @param object obj The graph object
  2148. * @param @object An array of options
  2149. * @param function Optional callback function
  2150. *
  2151. */
  2152. RGraph.Effects.jQuery.HScissors.Open = function (obj)
  2153. {
  2154. var canvas = obj.isRGraph ? obj.canvas : obj;;
  2155. var id = canvas.id;
  2156. var opts = arguments[1] ? arguments[1] : [];
  2157. var delay = 1000;
  2158. var color = opts['color'] ? opts['color'] : 'white';
  2159. var xy = RGraph.getCanvasXY(canvas);
  2160. var height = canvas.height / 5;
  2161. /**
  2162. * First draw the chart
  2163. */
  2164. RGraph.Clear(canvas);
  2165. RGraph.RedrawCanvas(canvas);
  2166. for (var i=0; i<5; ++i) {
  2167. var div = document.getElementById(id + "scissors_" + i)
  2168. if (!div) {
  2169. var div = document.createElement('DIV');
  2170. div.id = id + 'scissors_' + i;
  2171. div.style.width = canvas.width + 'px';
  2172. div.style.height = height + 'px';
  2173. div.style.left = xy[0] + 'px';
  2174. div.style.top = (xy[1] + (canvas.height * (i / 5))) + 'px';
  2175. div.style.position = 'absolute';
  2176. div.style.backgroundColor = color;
  2177. document.body.appendChild(div);
  2178. }
  2179. if (i % 2 == 0) {
  2180. jQuery('#' + id + 'scissors_' + i).animate({left: canvas.width + 'px', width: 0}, delay);
  2181. } else {
  2182. jQuery('#' + id + 'scissors_' + i).animate({width: 0}, delay);
  2183. }
  2184. }
  2185. setTimeout(function () {document.body.removeChild(document.getElementById(id + 'scissors_0'));}, delay);
  2186. setTimeout(function () {document.body.removeChild(document.getElementById(id + 'scissors_1'));}, delay);
  2187. setTimeout(function () {document.body.removeChild(document.getElementById(id + 'scissors_2'));}, delay);
  2188. setTimeout(function () {document.body.removeChild(document.getElementById(id + 'scissors_3'));}, delay);
  2189. setTimeout(function () {document.body.removeChild(document.getElementById(id + 'scissors_4'));}, delay);
  2190. /**
  2191. * Callback
  2192. */
  2193. if (typeof(arguments[2]) == 'function') {
  2194. setTimeout(arguments[2], delay);
  2195. }
  2196. }
  2197. /**
  2198. * Horizontal Scissors (Close)
  2199. *
  2200. * @param object obj The graph object
  2201. * @param @object An array of options
  2202. * @param function Optional callback function
  2203. *
  2204. */
  2205. RGraph.Effects.jQuery.HScissors.Close = function (obj)
  2206. {
  2207. var canvas = obj.isRGraph ? obj.canvas : obj;
  2208. var id = canvas.id;
  2209. var opts = arguments[1] ? arguments[1] : [];
  2210. var delay = 1000;
  2211. var color = opts['color'] ? opts['color'] : 'white';
  2212. var xy = RGraph.getCanvasXY(canvas);
  2213. var height = canvas.height / 5;
  2214. /**
  2215. * First draw the chart
  2216. */
  2217. RGraph.Clear(canvas);
  2218. RGraph.RedrawCanvas(canvas);
  2219. for (var i=0; i<5; ++i) {
  2220. var div = document.createElement('DIV');
  2221. div.id = id + '_scissors_' + i;
  2222. div.style.width = 0;
  2223. div.style.height = height + 'px';
  2224. div.style.left = (i % 2 == 0 ? xy[0] + canvas.width : xy[0]) + 'px';
  2225. div.style.top = (xy[1] + (canvas.height * (i / 5))) + 'px';
  2226. div.style.position = 'absolute';
  2227. div.style.backgroundColor = color;
  2228. document.body.appendChild(div);
  2229. if (i % 2 == 0) {
  2230. jQuery('#' + id + '_scissors_' + i).animate({left: xy[0] + 'px', width: canvas.width + 'px'}, delay);
  2231. } else {
  2232. jQuery('#' + id + '_scissors_' + i).animate({width: canvas.width + 'px'}, delay);
  2233. }
  2234. }
  2235. /**
  2236. * Callback
  2237. */
  2238. if (typeof(arguments[2]) == 'function') {
  2239. setTimeout(arguments[2], delay);
  2240. }
  2241. }
  2242. /**
  2243. * Vertical Scissors (open)
  2244. *
  2245. * @param object obj The graph object
  2246. * @param @object An array of options
  2247. * @param function Optional callback function
  2248. *
  2249. */
  2250. RGraph.Effects.jQuery.VScissors.Open = function (obj)
  2251. {
  2252. var canvas = obj.isRGraph ? obj.canvas : obj;;
  2253. var id = canvas.id;
  2254. var opts = arguments[1] ? arguments[1] : [];
  2255. var delay = 1000;
  2256. var color = opts['color'] ? opts['color'] : 'white';
  2257. var xy = RGraph.getCanvasXY(canvas);
  2258. var width = canvas.width / 5;
  2259. /**
  2260. * First draw the chart
  2261. */
  2262. RGraph.Clear(canvas);
  2263. RGraph.RedrawCanvas(canvas);
  2264. for (var i=0; i<5; ++i) {
  2265. var div = document.getElementById(id + "_vscissors_" + i)
  2266. if (!div) {
  2267. var div = document.createElement('DIV');
  2268. div.id = id + '_vscissors_' + i;
  2269. div.style.width = width + 'px';
  2270. div.style.height = canvas.height + 'px';
  2271. div.style.left = xy[0] + (canvas.width * (i / 5)) + 'px';
  2272. div.style.top = xy[1] + 'px';
  2273. div.style.position = 'absolute';
  2274. div.style.backgroundColor = color;
  2275. document.body.appendChild(div);
  2276. }
  2277. if (i % 2 == 0) {
  2278. jQuery('#' + id + '_vscissors_' + i).animate({top: xy[1] + canvas.height + 'px', height: 0}, delay);
  2279. } else {
  2280. jQuery('#' + id + '_vscissors_' + i).animate({height: 0}, delay);
  2281. }
  2282. }
  2283. setTimeout(function () {document.body.removeChild(document.getElementById(id + '_vscissors_0'));}, delay);
  2284. setTimeout(function () {document.body.removeChild(document.getElementById(id + '_vscissors_1'));}, delay);
  2285. setTimeout(function () {document.body.removeChild(document.getElementById(id + '_vscissors_2'));}, delay);
  2286. setTimeout(function () {document.body.removeChild(document.getElementById(id + '_vscissors_3'));}, delay);
  2287. setTimeout(function () {document.body.removeChild(document.getElementById(id + '_vscissors_4'));}, delay);
  2288. /**
  2289. * Callback
  2290. */
  2291. if (typeof(arguments[2]) == 'function') {
  2292. setTimeout(arguments[2], delay);
  2293. }
  2294. }
  2295. /**
  2296. * Vertical Scissors (close)
  2297. *
  2298. * @param object obj The graph object
  2299. * @param @object An array of options
  2300. * @param function Optional callback function
  2301. *
  2302. */
  2303. RGraph.Effects.jQuery.VScissors.Close = function (obj)
  2304. {
  2305. var canvas = obj.isRGraph ? obj.canvas : obj;
  2306. var id = canvas.id;
  2307. var opts = arguments[1] ? arguments[1] : [];
  2308. var delay = 1000;
  2309. var color = opts['color'] ? opts['color'] : 'white';
  2310. var xy = RGraph.getCanvasXY(canvas);
  2311. var width = canvas.width / 5;
  2312. /**
  2313. * First draw the chart
  2314. */
  2315. RGraph.Clear(canvas);
  2316. RGraph.RedrawCanvas(canvas);
  2317. for (var i=0; i<5; ++i) {
  2318. var div = document.getElementById(id + "_vscissors_" + i)
  2319. if (!div) {
  2320. var div = document.createElement('DIV');
  2321. div.id = id + '_vscissors_' + i;
  2322. div.style.width = width + 'px';
  2323. div.style.height = 0;
  2324. div.style.left = xy[0] + (width * i) + 'px';
  2325. div.style.top = (i % 2 == 0 ? xy[1] + canvas.height : xy[1]) + 'px';
  2326. div.style.position = 'absolute';
  2327. div.style.backgroundColor = color;
  2328. document.body.appendChild(div);
  2329. }
  2330. if (i % 2 == 0) {
  2331. jQuery('#' + id + '_vscissors_' + i).animate({top: xy[1] + 'px', height: canvas.height + 'px'}, delay);
  2332. } else {
  2333. jQuery('#' + id + '_vscissors_' + i).animate({height: canvas.height + 'px'}, delay);
  2334. }
  2335. }
  2336. /**
  2337. * Callback
  2338. */
  2339. if (typeof(arguments[2]) == 'function') {
  2340. setTimeout(arguments[2], delay);
  2341. }
  2342. }