jqplot.core.js 170 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087
  1. /**
  2. * Title: jqPlot Charts
  3. *
  4. * Pure JavaScript plotting plugin for jQuery.
  5. *
  6. * About: Version
  7. *
  8. * version: @VERSION
  9. * revision: @REVISION
  10. *
  11. * About: Copyright & License
  12. *
  13. * Copyright (c) 2009-2013 Chris Leonello
  14. * jqPlot is currently available for use in all personal or commercial projects
  15. * under both the MIT and GPL version 2.0 licenses. This means that you can
  16. * choose the license that best suits your project and use it accordingly.
  17. *
  18. * See <GPL Version 2> and <MIT License> contained within this distribution for further information.
  19. *
  20. * The author would appreciate an email letting him know of any substantial
  21. * use of jqPlot. You can reach the author at: chris at jqplot dot com
  22. * or see http://www.jqplot.com/info.php. This is, of course, not required.
  23. *
  24. * If you are feeling kind and generous, consider supporting the project by
  25. * making a donation at: http://www.jqplot.com/donate.php.
  26. *
  27. * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
  28. *
  29. * version 2007.04.27
  30. * author Ash Searle
  31. * http://hexmen.com/blog/2007/03/printf-sprintf/
  32. * http://hexmen.com/js/sprintf.js
  33. * The author (Ash Searle) has placed this code in the public domain:
  34. * "This code is unrestricted: you are free to use it however you like."
  35. *
  36. *
  37. * About: Introduction
  38. *
  39. * jqPlot requires jQuery (1.4+ required for certain features). jQuery 1.4.2 is included in the distribution.
  40. * To use jqPlot include jQuery, the jqPlot jQuery plugin, the jqPlot css file and optionally
  41. * the excanvas script for IE support in your web page:
  42. *
  43. * > <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="excanvas.js"></script><![endif]-->
  44. * > <script language="javascript" type="text/javascript" src="jquery-1.4.4.min.js"></script>
  45. * > <script language="javascript" type="text/javascript" src="jquery.jqplot.min.js"></script>
  46. * > <link rel="stylesheet" type="text/css" href="jquery.jqplot.css" />
  47. *
  48. * jqPlot can be customized by overriding the defaults of any of the objects which make
  49. * up the plot. The general usage of jqplot is:
  50. *
  51. * > chart = $.jqplot('targetElemId', [dataArray,...], {optionsObject});
  52. *
  53. * The options available to jqplot are detailed in <jqPlot Options> in the jqPlotOptions.txt file.
  54. *
  55. * An actual call to $.jqplot() may look like the
  56. * examples below:
  57. *
  58. * > chart = $.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);
  59. *
  60. * or
  61. *
  62. * > dataArray = [34,12,43,55,77];
  63. * > chart = $.jqplot('targetElemId', [dataArray, ...], {title:'My Plot', axes:{yaxis:{min:20, max:100}}});
  64. *
  65. * For more inforrmation, see <jqPlot Usage>.
  66. *
  67. * About: Usage
  68. *
  69. * See <jqPlot Usage>
  70. *
  71. * About: Available Options
  72. *
  73. * See <jqPlot Options> for a list of options available thorugh the options object (not complete yet!)
  74. *
  75. * About: Options Usage
  76. *
  77. * See <Options Tutorial>
  78. *
  79. * About: Changes
  80. *
  81. * See <Change Log>
  82. *
  83. */
  84. (function($) {
  85. // make sure undefined is undefined
  86. var undefined;
  87. $.fn.emptyForce = function() {
  88. for ( var i = 0, elem; (elem = $(this)[i]) != null; i++ ) {
  89. // Remove element nodes and prevent memory leaks
  90. if ( elem.nodeType === 1 ) {
  91. $.cleanData( elem.getElementsByTagName("*") );
  92. }
  93. // Remove any remaining nodes
  94. if ($.jqplot.use_excanvas) {
  95. elem.outerHTML = "";
  96. }
  97. else {
  98. while ( elem.firstChild ) {
  99. elem.removeChild( elem.firstChild );
  100. }
  101. }
  102. elem = null;
  103. }
  104. return $(this);
  105. };
  106. $.fn.removeChildForce = function(parent) {
  107. while ( parent.firstChild ) {
  108. this.removeChildForce( parent.firstChild );
  109. parent.removeChild( parent.firstChild );
  110. }
  111. };
  112. $.fn.jqplot = function() {
  113. var datas = [];
  114. var options = [];
  115. // see how many data arrays we have
  116. for (var i=0, l=arguments.length; i<l; i++) {
  117. if ($.isArray(arguments[i])) {
  118. datas.push(arguments[i]);
  119. }
  120. else if ($.isPlainObject(arguments[i])) {
  121. options.push(arguments[i]);
  122. }
  123. }
  124. return this.each(function(index) {
  125. var tid,
  126. plot,
  127. $this = $(this),
  128. dl = datas.length,
  129. ol = options.length,
  130. data,
  131. opts;
  132. if (index < dl) {
  133. data = datas[index];
  134. }
  135. else {
  136. data = dl ? datas[dl-1] : null;
  137. }
  138. if (index < ol) {
  139. opts = options[index];
  140. }
  141. else {
  142. opts = ol ? options[ol-1] : null;
  143. }
  144. // does el have an id?
  145. // if not assign it one.
  146. tid = $this.attr('id');
  147. if (tid === undefined) {
  148. tid = 'jqplot_target_' + $.jqplot.targetCounter++;
  149. $this.attr('id', tid);
  150. }
  151. plot = $.jqplot(tid, data, opts);
  152. $this.data('jqplot', plot);
  153. });
  154. };
  155. /**
  156. * Namespace: $.jqplot
  157. * jQuery function called by the user to create a plot.
  158. *
  159. * Parameters:
  160. * target - ID of target element to render the plot into.
  161. * data - an array of data series.
  162. * options - user defined options object. See the individual classes for available options.
  163. *
  164. * Properties:
  165. * config - object to hold configuration information for jqPlot plot object.
  166. *
  167. * attributes:
  168. * enablePlugins - False to disable plugins by default. Plugins must then be explicitly
  169. * enabled in the individual plot options. Default: false.
  170. * This property sets the "show" property of certain plugins to true or false.
  171. * Only plugins that can be immediately active upon loading are affected. This includes
  172. * non-renderer plugins like cursor, dragable, highlighter, and trendline.
  173. * defaultHeight - Default height for plots where no css height specification exists. This
  174. * is a jqplot wide default.
  175. * defaultWidth - Default height for plots where no css height specification exists. This
  176. * is a jqplot wide default.
  177. */
  178. $.jqplot = function(target, data, options) {
  179. var _data = null, _options = null;
  180. if (arguments.length === 3) {
  181. _data = data;
  182. _options = options;
  183. }
  184. else if (arguments.length === 2) {
  185. if ($.isArray(data)) {
  186. _data = data;
  187. }
  188. else if ($.isPlainObject(data)) {
  189. _options = data;
  190. }
  191. }
  192. if (_data === null && _options !== null && _options.data) {
  193. _data = _options.data;
  194. }
  195. var plot = new jqPlot();
  196. // remove any error class that may be stuck on target.
  197. $('#'+target).removeClass('jqplot-error');
  198. if ($.jqplot.config.catchErrors) {
  199. try {
  200. plot.init(target, _data, _options);
  201. plot.draw();
  202. plot.themeEngine.init.call(plot);
  203. return plot;
  204. }
  205. catch(e) {
  206. var msg = $.jqplot.config.errorMessage || e.message;
  207. $('#'+target).append('<div class="jqplot-error-message">'+msg+'</div>');
  208. $('#'+target).addClass('jqplot-error');
  209. document.getElementById(target).style.background = $.jqplot.config.errorBackground;
  210. document.getElementById(target).style.border = $.jqplot.config.errorBorder;
  211. document.getElementById(target).style.fontFamily = $.jqplot.config.errorFontFamily;
  212. document.getElementById(target).style.fontSize = $.jqplot.config.errorFontSize;
  213. document.getElementById(target).style.fontStyle = $.jqplot.config.errorFontStyle;
  214. document.getElementById(target).style.fontWeight = $.jqplot.config.errorFontWeight;
  215. }
  216. }
  217. else {
  218. plot.init(target, _data, _options);
  219. plot.draw();
  220. plot.themeEngine.init.call(plot);
  221. return plot;
  222. }
  223. };
  224. $.jqplot.version = "@VERSION";
  225. $.jqplot.revision = "@REVISION";
  226. $.jqplot.targetCounter = 1;
  227. // canvas manager to reuse canvases on the plot.
  228. // Should help solve problem of canvases not being freed and
  229. // problem of waiting forever for firefox to decide to free memory.
  230. $.jqplot.CanvasManager = function() {
  231. // canvases are managed globally so that they can be reused
  232. // across plots after they have been freed
  233. if (typeof $.jqplot.CanvasManager.canvases == 'undefined') {
  234. $.jqplot.CanvasManager.canvases = [];
  235. $.jqplot.CanvasManager.free = [];
  236. }
  237. var myCanvases = [];
  238. this.getCanvas = function() {
  239. var canvas;
  240. var makeNew = true;
  241. if (!$.jqplot.use_excanvas) {
  242. for (var i = 0, l = $.jqplot.CanvasManager.canvases.length; i < l; i++) {
  243. if ($.jqplot.CanvasManager.free[i] === true) {
  244. makeNew = false;
  245. canvas = $.jqplot.CanvasManager.canvases[i];
  246. // $(canvas).removeClass('jqplot-canvasManager-free').addClass('jqplot-canvasManager-inuse');
  247. $.jqplot.CanvasManager.free[i] = false;
  248. myCanvases.push(i);
  249. break;
  250. }
  251. }
  252. }
  253. if (makeNew) {
  254. canvas = document.createElement('canvas');
  255. myCanvases.push($.jqplot.CanvasManager.canvases.length);
  256. $.jqplot.CanvasManager.canvases.push(canvas);
  257. $.jqplot.CanvasManager.free.push(false);
  258. }
  259. return canvas;
  260. };
  261. // this method has to be used after settings the dimesions
  262. // on the element returned by getCanvas()
  263. this.initCanvas = function(canvas) {
  264. if ($.jqplot.use_excanvas) {
  265. return window.G_vmlCanvasManager.initElement(canvas);
  266. }
  267. return canvas;
  268. };
  269. this.freeAllCanvases = function() {
  270. for (var i = 0, l=myCanvases.length; i < l; i++) {
  271. this.freeCanvas(myCanvases[i]);
  272. }
  273. myCanvases = [];
  274. };
  275. this.freeCanvas = function(idx) {
  276. if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
  277. // excanvas can't be reused, but properly unset
  278. window.G_vmlCanvasManager.uninitElement($.jqplot.CanvasManager.canvases[idx]);
  279. $.jqplot.CanvasManager.canvases[idx] = null;
  280. }
  281. else {
  282. var canvas = $.jqplot.CanvasManager.canvases[idx];
  283. canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
  284. $(canvas).unbind().removeAttr('class').removeAttr('style');
  285. // Style attributes seemed to be still hanging around. wierd. Some ticks
  286. // still retained a left: 0px attribute after reusing a canvas.
  287. $(canvas).css({left: '', top: '', position: ''});
  288. // setting size to 0 may save memory of unused canvases?
  289. canvas.width = 0;
  290. canvas.height = 0;
  291. $.jqplot.CanvasManager.free[idx] = true;
  292. }
  293. };
  294. };
  295. // Convienence function that won't hang IE or FF without FireBug.
  296. $.jqplot.log = function() {
  297. if (window.console) {
  298. window.console.log.apply(window.console, arguments);
  299. }
  300. };
  301. $.jqplot.config = {
  302. addDomReference: false,
  303. enablePlugins:false,
  304. defaultHeight:300,
  305. defaultWidth:400,
  306. UTCAdjust:false,
  307. timezoneOffset: new Date(new Date().getTimezoneOffset() * 60000),
  308. errorMessage: '',
  309. errorBackground: '',
  310. errorBorder: '',
  311. errorFontFamily: '',
  312. errorFontSize: '',
  313. errorFontStyle: '',
  314. errorFontWeight: '',
  315. catchErrors: false,
  316. defaultTickFormatString: "%.1f",
  317. defaultColors: [ "#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc", "#c747a3", "#cddf54", "#FBD178", "#26B4E3", "#bd70c7"],
  318. defaultNegativeColors: [ "#498991", "#C08840", "#9F9274", "#546D61", "#646C4A", "#6F6621", "#6E3F5F", "#4F64B0", "#A89050", "#C45923", "#187399", "#945381", "#959E5C", "#C7AF7B", "#478396", "#907294"],
  319. dashLength: 4,
  320. gapLength: 4,
  321. dotGapLength: 2.5,
  322. srcLocation: 'jqplot/src/',
  323. pluginLocation: 'jqplot/src/plugins/'
  324. };
  325. $.jqplot.arrayMax = function( array ){
  326. return Math.max.apply( Math, array );
  327. };
  328. $.jqplot.arrayMin = function( array ){
  329. return Math.min.apply( Math, array );
  330. };
  331. $.jqplot.enablePlugins = $.jqplot.config.enablePlugins;
  332. // canvas related tests taken from modernizer:
  333. // Copyright (c) 2009 - 2010 Faruk Ates.
  334. // http://www.modernizr.com
  335. $.jqplot.support_canvas = function() {
  336. if (typeof $.jqplot.support_canvas.result == 'undefined') {
  337. $.jqplot.support_canvas.result = !!document.createElement('canvas').getContext;
  338. }
  339. return $.jqplot.support_canvas.result;
  340. };
  341. $.jqplot.support_canvas_text = function() {
  342. if (typeof $.jqplot.support_canvas_text.result == 'undefined') {
  343. if (window.G_vmlCanvasManager !== undefined && window.G_vmlCanvasManager._version > 887) {
  344. $.jqplot.support_canvas_text.result = true;
  345. }
  346. else {
  347. $.jqplot.support_canvas_text.result = !!(document.createElement('canvas').getContext && typeof document.createElement('canvas').getContext('2d').fillText == 'function');
  348. }
  349. }
  350. return $.jqplot.support_canvas_text.result;
  351. };
  352. $.jqplot.use_excanvas = ((!$.support.boxModel || !$.support.objectAll || !$support.leadingWhitespace) && !$.jqplot.support_canvas()) ? true : false;
  353. /**
  354. *
  355. * Hooks: jqPlot Pugin Hooks
  356. *
  357. * $.jqplot.preInitHooks - called before initialization.
  358. * $.jqplot.postInitHooks - called after initialization.
  359. * $.jqplot.preParseOptionsHooks - called before user options are parsed.
  360. * $.jqplot.postParseOptionsHooks - called after user options are parsed.
  361. * $.jqplot.preDrawHooks - called before plot draw.
  362. * $.jqplot.postDrawHooks - called after plot draw.
  363. * $.jqplot.preDrawSeriesHooks - called before each series is drawn.
  364. * $.jqplot.postDrawSeriesHooks - called after each series is drawn.
  365. * $.jqplot.preDrawLegendHooks - called before the legend is drawn.
  366. * $.jqplot.addLegendRowHooks - called at the end of legend draw, so plugins
  367. * can add rows to the legend table.
  368. * $.jqplot.preSeriesInitHooks - called before series is initialized.
  369. * $.jqplot.postSeriesInitHooks - called after series is initialized.
  370. * $.jqplot.preParseSeriesOptionsHooks - called before series related options
  371. * are parsed.
  372. * $.jqplot.postParseSeriesOptionsHooks - called after series related options
  373. * are parsed.
  374. * $.jqplot.eventListenerHooks - called at the end of plot drawing, binds
  375. * listeners to the event canvas which lays on top of the grid area.
  376. * $.jqplot.preDrawSeriesShadowHooks - called before series shadows are drawn.
  377. * $.jqplot.postDrawSeriesShadowHooks - called after series shadows are drawn.
  378. *
  379. */
  380. $.jqplot.preInitHooks = [];
  381. $.jqplot.postInitHooks = [];
  382. $.jqplot.preParseOptionsHooks = [];
  383. $.jqplot.postParseOptionsHooks = [];
  384. $.jqplot.preDrawHooks = [];
  385. $.jqplot.postDrawHooks = [];
  386. $.jqplot.preDrawSeriesHooks = [];
  387. $.jqplot.postDrawSeriesHooks = [];
  388. $.jqplot.preDrawLegendHooks = [];
  389. $.jqplot.addLegendRowHooks = [];
  390. $.jqplot.preSeriesInitHooks = [];
  391. $.jqplot.postSeriesInitHooks = [];
  392. $.jqplot.preParseSeriesOptionsHooks = [];
  393. $.jqplot.postParseSeriesOptionsHooks = [];
  394. $.jqplot.eventListenerHooks = [];
  395. $.jqplot.preDrawSeriesShadowHooks = [];
  396. $.jqplot.postDrawSeriesShadowHooks = [];
  397. // A superclass holding some common properties and methods.
  398. $.jqplot.ElemContainer = function() {
  399. this._elem;
  400. this._plotWidth;
  401. this._plotHeight;
  402. this._plotDimensions = {height:null, width:null};
  403. };
  404. $.jqplot.ElemContainer.prototype.createElement = function(el, offsets, clss, cssopts, attrib) {
  405. this._offsets = offsets;
  406. var klass = clss || 'jqplot';
  407. var elem = document.createElement(el);
  408. this._elem = $(elem);
  409. this._elem.addClass(klass);
  410. this._elem.css(cssopts);
  411. this._elem.attr(attrib);
  412. // avoid memory leak;
  413. elem = null;
  414. return this._elem;
  415. };
  416. $.jqplot.ElemContainer.prototype.getWidth = function() {
  417. if (this._elem) {
  418. return this._elem.outerWidth(true);
  419. }
  420. else {
  421. return null;
  422. }
  423. };
  424. $.jqplot.ElemContainer.prototype.getHeight = function() {
  425. if (this._elem) {
  426. return this._elem.outerHeight(true);
  427. }
  428. else {
  429. return null;
  430. }
  431. };
  432. $.jqplot.ElemContainer.prototype.getPosition = function() {
  433. if (this._elem) {
  434. return this._elem.position();
  435. }
  436. else {
  437. return {top:null, left:null, bottom:null, right:null};
  438. }
  439. };
  440. $.jqplot.ElemContainer.prototype.getTop = function() {
  441. return this.getPosition().top;
  442. };
  443. $.jqplot.ElemContainer.prototype.getLeft = function() {
  444. return this.getPosition().left;
  445. };
  446. $.jqplot.ElemContainer.prototype.getBottom = function() {
  447. return this._elem.css('bottom');
  448. };
  449. $.jqplot.ElemContainer.prototype.getRight = function() {
  450. return this._elem.css('right');
  451. };
  452. /**
  453. * Class: Axis
  454. * An individual axis object. Cannot be instantiated directly, but created
  455. * by the Plot object. Axis properties can be set or overridden by the
  456. * options passed in from the user.
  457. *
  458. */
  459. function Axis(name) {
  460. $.jqplot.ElemContainer.call(this);
  461. // Group: Properties
  462. //
  463. // Axes options are specified within an axes object at the top level of the
  464. // plot options like so:
  465. // > {
  466. // > axes: {
  467. // > xaxis: {min: 5},
  468. // > yaxis: {min: 2, max: 8, numberTicks:4},
  469. // > x2axis: {pad: 1.5},
  470. // > y2axis: {ticks:[22, 44, 66, 88]}
  471. // > }
  472. // > }
  473. // There are 2 x axes, 'xaxis' and 'x2axis', and
  474. // 9 yaxes, 'yaxis', 'y2axis'. 'y3axis', ... Any or all of which may be specified.
  475. this.name = name;
  476. this._series = [];
  477. // prop: show
  478. // Wether to display the axis on the graph.
  479. this.show = false;
  480. // prop: tickRenderer
  481. // A class of a rendering engine for creating the ticks labels displayed on the plot,
  482. // See <$.jqplot.AxisTickRenderer>.
  483. this.tickRenderer = $.jqplot.AxisTickRenderer;
  484. // prop: tickOptions
  485. // Options that will be passed to the tickRenderer, see <$.jqplot.AxisTickRenderer> options.
  486. this.tickOptions = {};
  487. // prop: labelRenderer
  488. // A class of a rendering engine for creating an axis label.
  489. this.labelRenderer = $.jqplot.AxisLabelRenderer;
  490. // prop: labelOptions
  491. // Options passed to the label renderer.
  492. this.labelOptions = {};
  493. // prop: label
  494. // Label for the axis
  495. this.label = null;
  496. // prop: showLabel
  497. // true to show the axis label.
  498. this.showLabel = true;
  499. // prop: min
  500. // minimum value of the axis (in data units, not pixels).
  501. this.min = null;
  502. // prop: max
  503. // maximum value of the axis (in data units, not pixels).
  504. this.max = null;
  505. // prop: autoscale
  506. // DEPRECATED
  507. // the default scaling algorithm produces superior results.
  508. this.autoscale = false;
  509. // prop: pad
  510. // Padding to extend the range above and below the data bounds.
  511. // The data range is multiplied by this factor to determine minimum and maximum axis bounds.
  512. // A value of 0 will be interpreted to mean no padding, and pad will be set to 1.0.
  513. this.pad = 1.2;
  514. // prop: padMax
  515. // Padding to extend the range above data bounds.
  516. // The top of the data range is multiplied by this factor to determine maximum axis bounds.
  517. // A value of 0 will be interpreted to mean no padding, and padMax will be set to 1.0.
  518. this.padMax = null;
  519. // prop: padMin
  520. // Padding to extend the range below data bounds.
  521. // The bottom of the data range is multiplied by this factor to determine minimum axis bounds.
  522. // A value of 0 will be interpreted to mean no padding, and padMin will be set to 1.0.
  523. this.padMin = null;
  524. // prop: ticks
  525. // 1D [val, val, ...] or 2D [[val, label], [val, label], ...] array of ticks for the axis.
  526. // If no label is specified, the value is formatted into an appropriate label.
  527. this.ticks = [];
  528. // prop: numberTicks
  529. // Desired number of ticks. Default is to compute automatically.
  530. this.numberTicks;
  531. // prop: tickInterval
  532. // number of units between ticks. Mutually exclusive with numberTicks.
  533. this.tickInterval;
  534. // prop: renderer
  535. // A class of a rendering engine that handles tick generation,
  536. // scaling input data to pixel grid units and drawing the axis element.
  537. this.renderer = $.jqplot.LinearAxisRenderer;
  538. // prop: rendererOptions
  539. // renderer specific options. See <$.jqplot.LinearAxisRenderer> for options.
  540. this.rendererOptions = {};
  541. // prop: showTicks
  542. // Wether to show the ticks (both marks and labels) or not.
  543. // Will not override showMark and showLabel options if specified on the ticks themselves.
  544. this.showTicks = true;
  545. // prop: showTickMarks
  546. // Wether to show the tick marks (line crossing grid) or not.
  547. // Overridden by showTicks and showMark option of tick itself.
  548. this.showTickMarks = true;
  549. // prop: showMinorTicks
  550. // Wether or not to show minor ticks. This is renderer dependent.
  551. this.showMinorTicks = true;
  552. // prop: drawMajorGridlines
  553. // True to draw gridlines for major axis ticks.
  554. this.drawMajorGridlines = true;
  555. // prop: drawMinorGridlines
  556. // True to draw gridlines for minor ticks.
  557. this.drawMinorGridlines = false;
  558. // prop: drawMajorTickMarks
  559. // True to draw tick marks for major axis ticks.
  560. this.drawMajorTickMarks = true;
  561. // prop: drawMinorTickMarks
  562. // True to draw tick marks for minor ticks. This is renderer dependent.
  563. this.drawMinorTickMarks = true;
  564. // prop: useSeriesColor
  565. // Use the color of the first series associated with this axis for the
  566. // tick marks and line bordering this axis.
  567. this.useSeriesColor = false;
  568. // prop: borderWidth
  569. // width of line stroked at the border of the axis. Defaults
  570. // to the width of the grid boarder.
  571. this.borderWidth = null;
  572. // prop: borderColor
  573. // color of the border adjacent to the axis. Defaults to grid border color.
  574. this.borderColor = null;
  575. // prop: scaleToHiddenSeries
  576. // True to include hidden series when computing axes bounds and scaling.
  577. this.scaleToHiddenSeries = false;
  578. // minimum and maximum values on the axis.
  579. this._dataBounds = {min:null, max:null};
  580. // statistics (min, max, mean) as well as actual data intervals for each series attached to axis.
  581. // holds collection of {intervals:[], min:, max:, mean: } objects for each series on axis.
  582. this._intervalStats = [];
  583. // pixel position from the top left of the min value and max value on the axis.
  584. this._offsets = {min:null, max:null};
  585. this._ticks=[];
  586. this._label = null;
  587. // prop: syncTicks
  588. // true to try and synchronize tick spacing across multiple axes so that ticks and
  589. // grid lines line up. This has an impact on autoscaling algorithm, however.
  590. // In general, autoscaling an individual axis will work better if it does not
  591. // have to sync ticks.
  592. this.syncTicks = null;
  593. // prop: tickSpacing
  594. // Approximate pixel spacing between ticks on graph. Used during autoscaling.
  595. // This number will be an upper bound, actual spacing will be less.
  596. this.tickSpacing = 75;
  597. // Properties to hold the original values for min, max, ticks, tickInterval and numberTicks
  598. // so they can be restored if altered by plugins.
  599. this._min = null;
  600. this._max = null;
  601. this._tickInterval = null;
  602. this._numberTicks = null;
  603. this.__ticks = null;
  604. // hold original user options.
  605. this._options = {};
  606. }
  607. Axis.prototype = new $.jqplot.ElemContainer();
  608. Axis.prototype.constructor = Axis;
  609. Axis.prototype.init = function() {
  610. if ($.isFunction(this.renderer)) {
  611. this.renderer = new this.renderer();
  612. }
  613. // set the axis name
  614. this.tickOptions.axis = this.name;
  615. // if showMark or showLabel tick options not specified, use value of axis option.
  616. // showTicks overrides showTickMarks.
  617. if (this.tickOptions.showMark == null) {
  618. this.tickOptions.showMark = this.showTicks;
  619. }
  620. if (this.tickOptions.showMark == null) {
  621. this.tickOptions.showMark = this.showTickMarks;
  622. }
  623. if (this.tickOptions.showLabel == null) {
  624. this.tickOptions.showLabel = this.showTicks;
  625. }
  626. if (this.label == null || this.label == '') {
  627. this.showLabel = false;
  628. }
  629. else {
  630. this.labelOptions.label = this.label;
  631. }
  632. if (this.showLabel == false) {
  633. this.labelOptions.show = false;
  634. }
  635. // set the default padMax, padMin if not specified
  636. // special check, if no padding desired, padding
  637. // should be set to 1.0
  638. if (this.pad == 0) {
  639. this.pad = 1.0;
  640. }
  641. if (this.padMax == 0) {
  642. this.padMax = 1.0;
  643. }
  644. if (this.padMin == 0) {
  645. this.padMin = 1.0;
  646. }
  647. if (this.padMax == null) {
  648. this.padMax = (this.pad-1)/2 + 1;
  649. }
  650. if (this.padMin == null) {
  651. this.padMin = (this.pad-1)/2 + 1;
  652. }
  653. // now that padMin and padMax are correctly set, reset pad in case user has supplied
  654. // padMin and/or padMax
  655. this.pad = this.padMax + this.padMin - 1;
  656. if (this.min != null || this.max != null) {
  657. this.autoscale = false;
  658. }
  659. // if not set, sync ticks for y axes but not x by default.
  660. if (this.syncTicks == null && this.name.indexOf('y') > -1) {
  661. this.syncTicks = true;
  662. }
  663. else if (this.syncTicks == null){
  664. this.syncTicks = false;
  665. }
  666. this.renderer.init.call(this, this.rendererOptions);
  667. };
  668. Axis.prototype.draw = function(ctx, plot) {
  669. // Memory Leaks patch
  670. if (this.__ticks) {
  671. this.__ticks = null;
  672. }
  673. return this.renderer.draw.call(this, ctx, plot);
  674. };
  675. Axis.prototype.set = function() {
  676. this.renderer.set.call(this);
  677. };
  678. Axis.prototype.pack = function(pos, offsets) {
  679. if (this.show) {
  680. this.renderer.pack.call(this, pos, offsets);
  681. }
  682. // these properties should all be available now.
  683. if (this._min == null) {
  684. this._min = this.min;
  685. this._max = this.max;
  686. this._tickInterval = this.tickInterval;
  687. this._numberTicks = this.numberTicks;
  688. this.__ticks = this._ticks;
  689. }
  690. };
  691. // reset the axis back to original values if it has been scaled, zoomed, etc.
  692. Axis.prototype.reset = function() {
  693. this.renderer.reset.call(this);
  694. };
  695. Axis.prototype.resetScale = function(opts) {
  696. $.extend(true, this, {min: null, max: null, numberTicks: null, tickInterval: null, _ticks: [], ticks: []}, opts);
  697. this.resetDataBounds();
  698. };
  699. Axis.prototype.resetDataBounds = function() {
  700. // Go through all the series attached to this axis and find
  701. // the min/max bounds for this axis.
  702. var db = this._dataBounds;
  703. db.min = null;
  704. db.max = null;
  705. var l, s, d;
  706. // check for when to force min 0 on bar series plots.
  707. var doforce = (this.show) ? true : false;
  708. for (var i=0; i<this._series.length; i++) {
  709. s = this._series[i];
  710. if (s.show || this.scaleToHiddenSeries) {
  711. d = s._plotData;
  712. if (s._type === 'line' && s.renderer.bands.show && this.name.charAt(0) !== 'x') {
  713. d = [[0, s.renderer.bands._min], [1, s.renderer.bands._max]];
  714. }
  715. var minyidx = 1, maxyidx = 1;
  716. if (s._type != null && s._type == 'ohlc') {
  717. minyidx = 3;
  718. maxyidx = 2;
  719. }
  720. for (var j=0, l=d.length; j<l; j++) {
  721. if (this.name == 'xaxis' || this.name == 'x2axis') {
  722. if ((d[j][0] != null && d[j][0] < db.min) || db.min == null) {
  723. db.min = d[j][0];
  724. }
  725. if ((d[j][0] != null && d[j][0] > db.max) || db.max == null) {
  726. db.max = d[j][0];
  727. }
  728. }
  729. else {
  730. if ((d[j][minyidx] != null && d[j][minyidx] < db.min) || db.min == null) {
  731. db.min = d[j][minyidx];
  732. }
  733. if ((d[j][maxyidx] != null && d[j][maxyidx] > db.max) || db.max == null) {
  734. db.max = d[j][maxyidx];
  735. }
  736. }
  737. }
  738. // Hack to not pad out bottom of bar plots unless user has specified a padding.
  739. // every series will have a chance to set doforce to false. once it is set to
  740. // false, it cannot be reset to true.
  741. // If any series attached to axis is not a bar, wont force 0.
  742. if (doforce && s.renderer.constructor !== $.jqplot.BarRenderer) {
  743. doforce = false;
  744. }
  745. else if (doforce && this._options.hasOwnProperty('forceTickAt0') && this._options.forceTickAt0 == false) {
  746. doforce = false;
  747. }
  748. else if (doforce && s.renderer.constructor === $.jqplot.BarRenderer) {
  749. if (s.barDirection == 'vertical' && this.name != 'xaxis' && this.name != 'x2axis') {
  750. if (this._options.pad != null || this._options.padMin != null) {
  751. doforce = false;
  752. }
  753. }
  754. else if (s.barDirection == 'horizontal' && (this.name == 'xaxis' || this.name == 'x2axis')) {
  755. if (this._options.pad != null || this._options.padMin != null) {
  756. doforce = false;
  757. }
  758. }
  759. }
  760. }
  761. }
  762. if (doforce && this.renderer.constructor === $.jqplot.LinearAxisRenderer && db.min >= 0) {
  763. this.padMin = 1.0;
  764. this.forceTickAt0 = true;
  765. }
  766. };
  767. /**
  768. * Class: Legend
  769. * Legend object. Cannot be instantiated directly, but created
  770. * by the Plot object. Legend properties can be set or overridden by the
  771. * options passed in from the user.
  772. */
  773. function Legend(options) {
  774. $.jqplot.ElemContainer.call(this);
  775. // Group: Properties
  776. // prop: show
  777. // Wether to display the legend on the graph.
  778. this.show = false;
  779. // prop: location
  780. // Placement of the legend. one of the compass directions: nw, n, ne, e, se, s, sw, w
  781. this.location = 'ne';
  782. // prop: labels
  783. // Array of labels to use. By default the renderer will look for labels on the series.
  784. // Labels specified in this array will override labels specified on the series.
  785. this.labels = [];
  786. // prop: showLabels
  787. // true to show the label text on the legend.
  788. this.showLabels = true;
  789. // prop: showSwatch
  790. // true to show the color swatches on the legend.
  791. this.showSwatches = true;
  792. // prop: placement
  793. // "insideGrid" places legend inside the grid area of the plot.
  794. // "outsideGrid" places the legend outside the grid but inside the plot container,
  795. // shrinking the grid to accomodate the legend.
  796. // "inside" synonym for "insideGrid",
  797. // "outside" places the legend ouside the grid area, but does not shrink the grid which
  798. // can cause the legend to overflow the plot container.
  799. this.placement = "insideGrid";
  800. // prop: xoffset
  801. // DEPRECATED. Set the margins on the legend using the marginTop, marginLeft, etc.
  802. // properties or via CSS margin styling of the .jqplot-table-legend class.
  803. this.xoffset = 0;
  804. // prop: yoffset
  805. // DEPRECATED. Set the margins on the legend using the marginTop, marginLeft, etc.
  806. // properties or via CSS margin styling of the .jqplot-table-legend class.
  807. this.yoffset = 0;
  808. // prop: border
  809. // css spec for the border around the legend box.
  810. this.border;
  811. // prop: background
  812. // css spec for the background of the legend box.
  813. this.background;
  814. // prop: textColor
  815. // css color spec for the legend text.
  816. this.textColor;
  817. // prop: fontFamily
  818. // css font-family spec for the legend text.
  819. this.fontFamily;
  820. // prop: fontSize
  821. // css font-size spec for the legend text.
  822. this.fontSize ;
  823. // prop: rowSpacing
  824. // css padding-top spec for the rows in the legend.
  825. this.rowSpacing = '0.5em';
  826. // renderer
  827. // A class that will create a DOM object for the legend,
  828. // see <$.jqplot.TableLegendRenderer>.
  829. this.renderer = $.jqplot.TableLegendRenderer;
  830. // prop: rendererOptions
  831. // renderer specific options passed to the renderer.
  832. this.rendererOptions = {};
  833. // prop: predraw
  834. // Wether to draw the legend before the series or not.
  835. // Used with series specific legend renderers for pie, donut, mekko charts, etc.
  836. this.preDraw = false;
  837. // prop: marginTop
  838. // CSS margin for the legend DOM element. This will set an element
  839. // CSS style for the margin which will override any style sheet setting.
  840. // The default will be taken from the stylesheet.
  841. this.marginTop = null;
  842. // prop: marginRight
  843. // CSS margin for the legend DOM element. This will set an element
  844. // CSS style for the margin which will override any style sheet setting.
  845. // The default will be taken from the stylesheet.
  846. this.marginRight = null;
  847. // prop: marginBottom
  848. // CSS margin for the legend DOM element. This will set an element
  849. // CSS style for the margin which will override any style sheet setting.
  850. // The default will be taken from the stylesheet.
  851. this.marginBottom = null;
  852. // prop: marginLeft
  853. // CSS margin for the legend DOM element. This will set an element
  854. // CSS style for the margin which will override any style sheet setting.
  855. // The default will be taken from the stylesheet.
  856. this.marginLeft = null;
  857. // prop: escapeHtml
  858. // True to escape special characters with their html entity equivalents
  859. // in legend text. "<" becomes &lt; and so on, so html tags are not rendered.
  860. this.escapeHtml = false;
  861. this._series = [];
  862. $.extend(true, this, options);
  863. }
  864. Legend.prototype = new $.jqplot.ElemContainer();
  865. Legend.prototype.constructor = Legend;
  866. Legend.prototype.setOptions = function(options) {
  867. $.extend(true, this, options);
  868. // Try to emulate deprecated behaviour
  869. // if user has specified xoffset or yoffset, copy these to
  870. // the margin properties.
  871. if (this.placement == 'inside') {
  872. this.placement = 'insideGrid';
  873. }
  874. if (this.xoffset >0) {
  875. if (this.placement == 'insideGrid') {
  876. switch (this.location) {
  877. case 'nw':
  878. case 'w':
  879. case 'sw':
  880. if (this.marginLeft == null) {
  881. this.marginLeft = this.xoffset + 'px';
  882. }
  883. this.marginRight = '0px';
  884. break;
  885. case 'ne':
  886. case 'e':
  887. case 'se':
  888. default:
  889. if (this.marginRight == null) {
  890. this.marginRight = this.xoffset + 'px';
  891. }
  892. this.marginLeft = '0px';
  893. break;
  894. }
  895. }
  896. else if (this.placement == 'outside') {
  897. switch (this.location) {
  898. case 'nw':
  899. case 'w':
  900. case 'sw':
  901. if (this.marginRight == null) {
  902. this.marginRight = this.xoffset + 'px';
  903. }
  904. this.marginLeft = '0px';
  905. break;
  906. case 'ne':
  907. case 'e':
  908. case 'se':
  909. default:
  910. if (this.marginLeft == null) {
  911. this.marginLeft = this.xoffset + 'px';
  912. }
  913. this.marginRight = '0px';
  914. break;
  915. }
  916. }
  917. this.xoffset = 0;
  918. }
  919. if (this.yoffset >0) {
  920. if (this.placement == 'outside') {
  921. switch (this.location) {
  922. case 'sw':
  923. case 's':
  924. case 'se':
  925. if (this.marginTop == null) {
  926. this.marginTop = this.yoffset + 'px';
  927. }
  928. this.marginBottom = '0px';
  929. break;
  930. case 'ne':
  931. case 'n':
  932. case 'nw':
  933. default:
  934. if (this.marginBottom == null) {
  935. this.marginBottom = this.yoffset + 'px';
  936. }
  937. this.marginTop = '0px';
  938. break;
  939. }
  940. }
  941. else if (this.placement == 'insideGrid') {
  942. switch (this.location) {
  943. case 'sw':
  944. case 's':
  945. case 'se':
  946. if (this.marginBottom == null) {
  947. this.marginBottom = this.yoffset + 'px';
  948. }
  949. this.marginTop = '0px';
  950. break;
  951. case 'ne':
  952. case 'n':
  953. case 'nw':
  954. default:
  955. if (this.marginTop == null) {
  956. this.marginTop = this.yoffset + 'px';
  957. }
  958. this.marginBottom = '0px';
  959. break;
  960. }
  961. }
  962. this.yoffset = 0;
  963. }
  964. // TO-DO:
  965. // Handle case where offsets are < 0.
  966. //
  967. };
  968. Legend.prototype.init = function() {
  969. if ($.isFunction(this.renderer)) {
  970. this.renderer = new this.renderer();
  971. }
  972. this.renderer.init.call(this, this.rendererOptions);
  973. };
  974. Legend.prototype.draw = function(offsets, plot) {
  975. for (var i=0; i<$.jqplot.preDrawLegendHooks.length; i++){
  976. $.jqplot.preDrawLegendHooks[i].call(this, offsets);
  977. }
  978. return this.renderer.draw.call(this, offsets, plot);
  979. };
  980. Legend.prototype.pack = function(offsets) {
  981. this.renderer.pack.call(this, offsets);
  982. };
  983. /**
  984. * Class: Title
  985. * Plot Title object. Cannot be instantiated directly, but created
  986. * by the Plot object. Title properties can be set or overridden by the
  987. * options passed in from the user.
  988. *
  989. * Parameters:
  990. * text - text of the title.
  991. */
  992. function Title(text) {
  993. $.jqplot.ElemContainer.call(this);
  994. // Group: Properties
  995. // prop: text
  996. // text of the title;
  997. this.text = text;
  998. // prop: show
  999. // whether or not to show the title
  1000. this.show = true;
  1001. // prop: fontFamily
  1002. // css font-family spec for the text.
  1003. this.fontFamily;
  1004. // prop: fontSize
  1005. // css font-size spec for the text.
  1006. this.fontSize ;
  1007. // prop: textAlign
  1008. // css text-align spec for the text.
  1009. this.textAlign;
  1010. // prop: textColor
  1011. // css color spec for the text.
  1012. this.textColor;
  1013. // prop: renderer
  1014. // A class for creating a DOM element for the title,
  1015. // see <$.jqplot.DivTitleRenderer>.
  1016. this.renderer = $.jqplot.DivTitleRenderer;
  1017. // prop: rendererOptions
  1018. // renderer specific options passed to the renderer.
  1019. this.rendererOptions = {};
  1020. // prop: escapeHtml
  1021. // True to escape special characters with their html entity equivalents
  1022. // in title text. "<" becomes &lt; and so on, so html tags are not rendered.
  1023. this.escapeHtml = false;
  1024. }
  1025. Title.prototype = new $.jqplot.ElemContainer();
  1026. Title.prototype.constructor = Title;
  1027. Title.prototype.init = function() {
  1028. if ($.isFunction(this.renderer)) {
  1029. this.renderer = new this.renderer();
  1030. }
  1031. this.renderer.init.call(this, this.rendererOptions);
  1032. };
  1033. Title.prototype.draw = function(width) {
  1034. return this.renderer.draw.call(this, width);
  1035. };
  1036. Title.prototype.pack = function() {
  1037. this.renderer.pack.call(this);
  1038. };
  1039. /**
  1040. * Class: Series
  1041. * An individual data series object. Cannot be instantiated directly, but created
  1042. * by the Plot object. Series properties can be set or overridden by the
  1043. * options passed in from the user.
  1044. */
  1045. function Series(options) {
  1046. options = options || {};
  1047. $.jqplot.ElemContainer.call(this);
  1048. // Group: Properties
  1049. // Properties will be assigned from a series array at the top level of the
  1050. // options. If you had two series and wanted to change the color and line
  1051. // width of the first and set the second to use the secondary y axis with
  1052. // no shadow and supply custom labels for each:
  1053. // > {
  1054. // > series:[
  1055. // > {color: '#ff4466', lineWidth: 5, label:'good line'},
  1056. // > {yaxis: 'y2axis', shadow: false, label:'bad line'}
  1057. // > ]
  1058. // > }
  1059. // prop: show
  1060. // whether or not to draw the series.
  1061. this.show = true;
  1062. // prop: xaxis
  1063. // which x axis to use with this series, either 'xaxis' or 'x2axis'.
  1064. this.xaxis = 'xaxis';
  1065. this._xaxis;
  1066. // prop: yaxis
  1067. // which y axis to use with this series, either 'yaxis' or 'y2axis'.
  1068. this.yaxis = 'yaxis';
  1069. this._yaxis;
  1070. this.gridBorderWidth = 2.0;
  1071. // prop: renderer
  1072. // A class of a renderer which will draw the series,
  1073. // see <$.jqplot.LineRenderer>.
  1074. this.renderer = $.jqplot.LineRenderer;
  1075. // prop: rendererOptions
  1076. // Options to pass on to the renderer.
  1077. this.rendererOptions = {};
  1078. this.data = [];
  1079. this.gridData = [];
  1080. // prop: label
  1081. // Line label to use in the legend.
  1082. this.label = '';
  1083. // prop: showLabel
  1084. // true to show label for this series in the legend.
  1085. this.showLabel = true;
  1086. // prop: color
  1087. // css color spec for the series
  1088. this.color;
  1089. // prop: negativeColor
  1090. // css color spec used for filled (area) plots that are filled to zero and
  1091. // the "useNegativeColors" option is true.
  1092. this.negativeColor;
  1093. // prop: lineWidth
  1094. // width of the line in pixels. May have different meanings depending on renderer.
  1095. this.lineWidth = 2.5;
  1096. // prop: lineJoin
  1097. // Canvas lineJoin style between segments of series.
  1098. this.lineJoin = 'round';
  1099. // prop: lineCap
  1100. // Canvas lineCap style at ends of line.
  1101. this.lineCap = 'round';
  1102. // prop: linePattern
  1103. // line pattern 'dashed', 'dotted', 'solid', some combination
  1104. // of '-' and '.' characters such as '.-.' or a numerical array like
  1105. // [draw, skip, draw, skip, ...] such as [1, 10] to draw a dotted line,
  1106. // [1, 10, 20, 10] to draw a dot-dash line, and so on.
  1107. this.linePattern = 'solid';
  1108. this.shadow = true;
  1109. // prop: shadowAngle
  1110. // Shadow angle in degrees
  1111. this.shadowAngle = 45;
  1112. // prop: shadowOffset
  1113. // Shadow offset from line in pixels
  1114. this.shadowOffset = 1.25;
  1115. // prop: shadowDepth
  1116. // Number of times shadow is stroked, each stroke offset shadowOffset from the last.
  1117. this.shadowDepth = 3;
  1118. // prop: shadowAlpha
  1119. // Alpha channel transparency of shadow. 0 = transparent.
  1120. this.shadowAlpha = '0.1';
  1121. // prop: breakOnNull
  1122. // Wether line segments should be be broken at null value.
  1123. // False will join point on either side of line.
  1124. this.breakOnNull = false;
  1125. // prop: markerRenderer
  1126. // A class of a renderer which will draw marker (e.g. circle, square, ...) at the data points,
  1127. // see <$.jqplot.MarkerRenderer>.
  1128. this.markerRenderer = $.jqplot.MarkerRenderer;
  1129. // prop: markerOptions
  1130. // renderer specific options to pass to the markerRenderer,
  1131. // see <$.jqplot.MarkerRenderer>.
  1132. this.markerOptions = {};
  1133. // prop: showLine
  1134. // whether to actually draw the line or not. Series will still be renderered, even if no line is drawn.
  1135. this.showLine = true;
  1136. // prop: showMarker
  1137. // whether or not to show the markers at the data points.
  1138. this.showMarker = true;
  1139. // prop: index
  1140. // 0 based index of this series in the plot series array.
  1141. this.index;
  1142. // prop: fill
  1143. // true or false, whether to fill under lines or in bars.
  1144. // May not be implemented in all renderers.
  1145. this.fill = false;
  1146. // prop: fillColor
  1147. // CSS color spec to use for fill under line. Defaults to line color.
  1148. this.fillColor;
  1149. // prop: fillAlpha
  1150. // Alpha transparency to apply to the fill under the line.
  1151. // Use this to adjust alpha separate from fill color.
  1152. this.fillAlpha;
  1153. // prop: fillAndStroke
  1154. // If true will stroke the line (with color this.color) as well as fill under it.
  1155. // Applies only when fill is true.
  1156. this.fillAndStroke = false;
  1157. // prop: disableStack
  1158. // true to not stack this series with other series in the plot.
  1159. // To render properly, non-stacked series must come after any stacked series
  1160. // in the plot's data series array. So, the plot's data series array would look like:
  1161. // > [stackedSeries1, stackedSeries2, ..., nonStackedSeries1, nonStackedSeries2, ...]
  1162. // disableStack will put a gap in the stacking order of series, and subsequent
  1163. // stacked series will not fill down through the non-stacked series and will
  1164. // most likely not stack properly on top of the non-stacked series.
  1165. this.disableStack = false;
  1166. // _stack is set by the Plot if the plot is a stacked chart.
  1167. // will stack lines or bars on top of one another to build a "mountain" style chart.
  1168. // May not be implemented in all renderers.
  1169. this._stack = false;
  1170. // prop: neighborThreshold
  1171. // how close or far (in pixels) the cursor must be from a point marker to detect the point.
  1172. this.neighborThreshold = 4;
  1173. // prop: fillToZero
  1174. // true will force bar and filled series to fill toward zero on the fill Axis.
  1175. this.fillToZero = false;
  1176. // prop: fillToValue
  1177. // fill a filled series to this value on the fill axis.
  1178. // Works in conjunction with fillToZero, so that must be true.
  1179. this.fillToValue = 0;
  1180. // prop: fillAxis
  1181. // Either 'x' or 'y'. Which axis to fill the line toward if fillToZero is true.
  1182. // 'y' means fill up/down to 0 on the y axis for this series.
  1183. this.fillAxis = 'y';
  1184. // prop: useNegativeColors
  1185. // true to color negative values differently in filled and bar charts.
  1186. this.useNegativeColors = true;
  1187. this._stackData = [];
  1188. // _plotData accounts for stacking. If plots not stacked, _plotData and data are same. If
  1189. // stacked, _plotData is accumulation of stacking data.
  1190. this._plotData = [];
  1191. // _plotValues hold the individual x and y values that will be plotted for this series.
  1192. this._plotValues = {x:[], y:[]};
  1193. // statistics about the intervals between data points. Used for auto scaling.
  1194. this._intervals = {x:{}, y:{}};
  1195. // data from the previous series, for stacked charts.
  1196. this._prevPlotData = [];
  1197. this._prevGridData = [];
  1198. this._stackAxis = 'y';
  1199. this._primaryAxis = '_xaxis';
  1200. // give each series a canvas to draw on. This should allow for redrawing speedups.
  1201. this.canvas = new $.jqplot.GenericCanvas();
  1202. this.shadowCanvas = new $.jqplot.GenericCanvas();
  1203. this.plugins = {};
  1204. // sum of y values in this series.
  1205. this._sumy = 0;
  1206. this._sumx = 0;
  1207. this._type = '';
  1208. }
  1209. Series.prototype = new $.jqplot.ElemContainer();
  1210. Series.prototype.constructor = Series;
  1211. Series.prototype.init = function(index, gridbw, plot) {
  1212. // weed out any null values in the data.
  1213. this.index = index;
  1214. this.gridBorderWidth = gridbw;
  1215. var d = this.data;
  1216. var temp = [], i, l;
  1217. for (i=0, l=d.length; i<l; i++) {
  1218. if (! this.breakOnNull) {
  1219. if (d[i] == null || d[i][0] == null || d[i][1] == null) {
  1220. continue;
  1221. }
  1222. else {
  1223. temp.push(d[i]);
  1224. }
  1225. }
  1226. else {
  1227. // TODO: figure out what to do with null values
  1228. // probably involve keeping nulls in data array
  1229. // and then updating renderers to break line
  1230. // when it hits null value.
  1231. // For now, just keep value.
  1232. temp.push(d[i]);
  1233. }
  1234. }
  1235. this.data = temp;
  1236. // parse the renderer options and apply default colors if not provided
  1237. // Set color even if not shown, so series don't change colors when other
  1238. // series on plot shown/hidden.
  1239. if (!this.color) {
  1240. this.color = plot.colorGenerator.get(this.index);
  1241. }
  1242. if (!this.negativeColor) {
  1243. this.negativeColor = plot.negativeColorGenerator.get(this.index);
  1244. }
  1245. if (!this.fillColor) {
  1246. this.fillColor = this.color;
  1247. }
  1248. if (this.fillAlpha) {
  1249. var comp = $.jqplot.normalize2rgb(this.fillColor);
  1250. var comp = $.jqplot.getColorComponents(comp);
  1251. this.fillColor = 'rgba('+comp[0]+','+comp[1]+','+comp[2]+','+this.fillAlpha+')';
  1252. }
  1253. if ($.isFunction(this.renderer)) {
  1254. this.renderer = new this.renderer();
  1255. }
  1256. this.renderer.init.call(this, this.rendererOptions, plot);
  1257. this.markerRenderer = new this.markerRenderer();
  1258. if (!this.markerOptions.color) {
  1259. this.markerOptions.color = this.color;
  1260. }
  1261. if (this.markerOptions.show == null) {
  1262. this.markerOptions.show = this.showMarker;
  1263. }
  1264. this.showMarker = this.markerOptions.show;
  1265. // the markerRenderer is called within its own scope, don't want to overwrite series options!!
  1266. this.markerRenderer.init(this.markerOptions);
  1267. };
  1268. // data - optional data point array to draw using this series renderer
  1269. // gridData - optional grid data point array to draw using this series renderer
  1270. // stackData - array of cumulative data for stacked plots.
  1271. Series.prototype.draw = function(sctx, opts, plot) {
  1272. var options = (opts == undefined) ? {} : opts;
  1273. sctx = (sctx == undefined) ? this.canvas._ctx : sctx;
  1274. var j, data, gridData;
  1275. // hooks get called even if series not shown
  1276. // we don't clear canvas here, it would wipe out all other series as well.
  1277. for (j=0; j<$.jqplot.preDrawSeriesHooks.length; j++) {
  1278. $.jqplot.preDrawSeriesHooks[j].call(this, sctx, options);
  1279. }
  1280. if (this.show) {
  1281. this.renderer.setGridData.call(this, plot);
  1282. if (!options.preventJqPlotSeriesDrawTrigger) {
  1283. $(sctx.canvas).trigger('jqplotSeriesDraw', [this.data, this.gridData]);
  1284. }
  1285. data = [];
  1286. if (options.data) {
  1287. data = options.data;
  1288. }
  1289. else if (!this._stack) {
  1290. data = this.data;
  1291. }
  1292. else {
  1293. data = this._plotData;
  1294. }
  1295. gridData = options.gridData || this.renderer.makeGridData.call(this, data, plot);
  1296. if (this._type === 'line' && this.renderer.smooth && this.renderer._smoothedData.length) {
  1297. gridData = this.renderer._smoothedData;
  1298. }
  1299. this.renderer.draw.call(this, sctx, gridData, options, plot);
  1300. }
  1301. for (j=0; j<$.jqplot.postDrawSeriesHooks.length; j++) {
  1302. $.jqplot.postDrawSeriesHooks[j].call(this, sctx, options, plot);
  1303. }
  1304. sctx = opts = plot = j = data = gridData = null;
  1305. };
  1306. Series.prototype.drawShadow = function(sctx, opts, plot) {
  1307. var options = (opts == undefined) ? {} : opts;
  1308. sctx = (sctx == undefined) ? this.shadowCanvas._ctx : sctx;
  1309. var j, data, gridData;
  1310. // hooks get called even if series not shown
  1311. // we don't clear canvas here, it would wipe out all other series as well.
  1312. for (j=0; j<$.jqplot.preDrawSeriesShadowHooks.length; j++) {
  1313. $.jqplot.preDrawSeriesShadowHooks[j].call(this, sctx, options);
  1314. }
  1315. if (this.shadow) {
  1316. this.renderer.setGridData.call(this, plot);
  1317. data = [];
  1318. if (options.data) {
  1319. data = options.data;
  1320. }
  1321. else if (!this._stack) {
  1322. data = this.data;
  1323. }
  1324. else {
  1325. data = this._plotData;
  1326. }
  1327. gridData = options.gridData || this.renderer.makeGridData.call(this, data, plot);
  1328. this.renderer.drawShadow.call(this, sctx, gridData, options, plot);
  1329. }
  1330. for (j=0; j<$.jqplot.postDrawSeriesShadowHooks.length; j++) {
  1331. $.jqplot.postDrawSeriesShadowHooks[j].call(this, sctx, options);
  1332. }
  1333. sctx = opts = plot = j = data = gridData = null;
  1334. };
  1335. // toggles series display on plot, e.g. show/hide series
  1336. Series.prototype.toggleDisplay = function(ev, callback) {
  1337. var s, speed;
  1338. if (ev.data.series) {
  1339. s = ev.data.series;
  1340. }
  1341. else {
  1342. s = this;
  1343. }
  1344. if (ev.data.speed) {
  1345. speed = ev.data.speed;
  1346. }
  1347. if (speed) {
  1348. // this can be tricky because series may not have a canvas element if replotting.
  1349. if (s.canvas._elem.is(':hidden') || !s.show) {
  1350. s.show = true;
  1351. s.canvas._elem.removeClass('jqplot-series-hidden');
  1352. if (s.shadowCanvas._elem) {
  1353. s.shadowCanvas._elem.fadeIn(speed);
  1354. }
  1355. s.canvas._elem.fadeIn(speed, callback);
  1356. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).fadeIn(speed);
  1357. }
  1358. else {
  1359. s.show = false;
  1360. s.canvas._elem.addClass('jqplot-series-hidden');
  1361. if (s.shadowCanvas._elem) {
  1362. s.shadowCanvas._elem.fadeOut(speed);
  1363. }
  1364. s.canvas._elem.fadeOut(speed, callback);
  1365. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).fadeOut(speed);
  1366. }
  1367. }
  1368. else {
  1369. // this can be tricky because series may not have a canvas element if replotting.
  1370. if (s.canvas._elem.is(':hidden') || !s.show) {
  1371. s.show = true;
  1372. s.canvas._elem.removeClass('jqplot-series-hidden');
  1373. if (s.shadowCanvas._elem) {
  1374. s.shadowCanvas._elem.show();
  1375. }
  1376. s.canvas._elem.show(0, callback);
  1377. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).show();
  1378. }
  1379. else {
  1380. s.show = false;
  1381. s.canvas._elem.addClass('jqplot-series-hidden');
  1382. if (s.shadowCanvas._elem) {
  1383. s.shadowCanvas._elem.hide();
  1384. }
  1385. s.canvas._elem.hide(0, callback);
  1386. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).hide();
  1387. }
  1388. }
  1389. };
  1390. /**
  1391. * Class: Grid
  1392. *
  1393. * Object representing the grid on which the plot is drawn. The grid in this
  1394. * context is the area bounded by the axes, the area which will contain the series.
  1395. * Note, the series are drawn on their own canvas.
  1396. * The Grid object cannot be instantiated directly, but is created by the Plot object.
  1397. * Grid properties can be set or overridden by the options passed in from the user.
  1398. */
  1399. function Grid() {
  1400. $.jqplot.ElemContainer.call(this);
  1401. // Group: Properties
  1402. // prop: drawGridlines
  1403. // whether to draw the gridlines on the plot.
  1404. this.drawGridlines = true;
  1405. // prop: gridLineColor
  1406. // color of the grid lines.
  1407. this.gridLineColor = '#cccccc';
  1408. // prop: gridLineWidth
  1409. // width of the grid lines.
  1410. this.gridLineWidth = 1.0;
  1411. // prop: background
  1412. // css spec for the background color.
  1413. this.background = '#fffdf6';
  1414. // prop: borderColor
  1415. // css spec for the color of the grid border.
  1416. this.borderColor = '#999999';
  1417. // prop: borderWidth
  1418. // width of the border in pixels.
  1419. this.borderWidth = 2.0;
  1420. // prop: drawBorder
  1421. // True to draw border around grid.
  1422. this.drawBorder = true;
  1423. // prop: shadow
  1424. // whether to show a shadow behind the grid.
  1425. this.shadow = true;
  1426. // prop: shadowAngle
  1427. // shadow angle in degrees
  1428. this.shadowAngle = 45;
  1429. // prop: shadowOffset
  1430. // Offset of each shadow stroke from the border in pixels
  1431. this.shadowOffset = 1.5;
  1432. // prop: shadowWidth
  1433. // width of the stoke for the shadow
  1434. this.shadowWidth = 3;
  1435. // prop: shadowDepth
  1436. // Number of times shadow is stroked, each stroke offset shadowOffset from the last.
  1437. this.shadowDepth = 3;
  1438. // prop: shadowColor
  1439. // an optional css color spec for the shadow in 'rgba(n, n, n, n)' form
  1440. this.shadowColor = null;
  1441. // prop: shadowAlpha
  1442. // Alpha channel transparency of shadow. 0 = transparent.
  1443. this.shadowAlpha = '0.07';
  1444. this._left;
  1445. this._top;
  1446. this._right;
  1447. this._bottom;
  1448. this._width;
  1449. this._height;
  1450. this._axes = [];
  1451. // prop: renderer
  1452. // Instance of a renderer which will actually render the grid,
  1453. // see <$.jqplot.CanvasGridRenderer>.
  1454. this.renderer = $.jqplot.CanvasGridRenderer;
  1455. // prop: rendererOptions
  1456. // Options to pass on to the renderer,
  1457. // see <$.jqplot.CanvasGridRenderer>.
  1458. this.rendererOptions = {};
  1459. this._offsets = {top:null, bottom:null, left:null, right:null};
  1460. }
  1461. Grid.prototype = new $.jqplot.ElemContainer();
  1462. Grid.prototype.constructor = Grid;
  1463. Grid.prototype.init = function() {
  1464. if ($.isFunction(this.renderer)) {
  1465. this.renderer = new this.renderer();
  1466. }
  1467. this.renderer.init.call(this, this.rendererOptions);
  1468. };
  1469. Grid.prototype.createElement = function(offsets,plot) {
  1470. this._offsets = offsets;
  1471. return this.renderer.createElement.call(this, plot);
  1472. };
  1473. Grid.prototype.draw = function() {
  1474. this.renderer.draw.call(this);
  1475. };
  1476. $.jqplot.GenericCanvas = function() {
  1477. $.jqplot.ElemContainer.call(this);
  1478. this._ctx;
  1479. };
  1480. $.jqplot.GenericCanvas.prototype = new $.jqplot.ElemContainer();
  1481. $.jqplot.GenericCanvas.prototype.constructor = $.jqplot.GenericCanvas;
  1482. $.jqplot.GenericCanvas.prototype.createElement = function(offsets, clss, plotDimensions, plot) {
  1483. this._offsets = offsets;
  1484. var klass = 'jqplot';
  1485. if (clss != undefined) {
  1486. klass = clss;
  1487. }
  1488. var elem;
  1489. elem = plot.canvasManager.getCanvas();
  1490. // if new plotDimensions supplied, use them.
  1491. if (plotDimensions != null) {
  1492. this._plotDimensions = plotDimensions;
  1493. }
  1494. elem.width = this._plotDimensions.width - this._offsets.left - this._offsets.right;
  1495. elem.height = this._plotDimensions.height - this._offsets.top - this._offsets.bottom;
  1496. this._elem = $(elem);
  1497. this._elem.css({ position: 'absolute', left: this._offsets.left, top: this._offsets.top });
  1498. this._elem.addClass(klass);
  1499. elem = plot.canvasManager.initCanvas(elem);
  1500. elem = null;
  1501. return this._elem;
  1502. };
  1503. $.jqplot.GenericCanvas.prototype.setContext = function() {
  1504. this._ctx = this._elem.get(0).getContext("2d");
  1505. return this._ctx;
  1506. };
  1507. // Memory Leaks patch
  1508. $.jqplot.GenericCanvas.prototype.resetCanvas = function() {
  1509. if (this._elem) {
  1510. if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
  1511. window.G_vmlCanvasManager.uninitElement(this._elem.get(0));
  1512. }
  1513. //this._elem.remove();
  1514. this._elem.emptyForce();
  1515. }
  1516. this._ctx = null;
  1517. };
  1518. $.jqplot.HooksManager = function () {
  1519. this.hooks =[];
  1520. this.args = [];
  1521. };
  1522. $.jqplot.HooksManager.prototype.addOnce = function(fn, args) {
  1523. args = args || [];
  1524. var havehook = false;
  1525. for (var i=0, l=this.hooks.length; i<l; i++) {
  1526. if (this.hooks[i] == fn) {
  1527. havehook = true;
  1528. }
  1529. }
  1530. if (!havehook) {
  1531. this.hooks.push(fn);
  1532. this.args.push(args);
  1533. }
  1534. };
  1535. $.jqplot.HooksManager.prototype.add = function(fn, args) {
  1536. args = args || [];
  1537. this.hooks.push(fn);
  1538. this.args.push(args);
  1539. };
  1540. $.jqplot.EventListenerManager = function () {
  1541. this.hooks =[];
  1542. };
  1543. $.jqplot.EventListenerManager.prototype.addOnce = function(ev, fn) {
  1544. var havehook = false, h, i;
  1545. for (var i=0, l=this.hooks.length; i<l; i++) {
  1546. h = this.hooks[i];
  1547. if (h[0] == ev && h[1] == fn) {
  1548. havehook = true;
  1549. }
  1550. }
  1551. if (!havehook) {
  1552. this.hooks.push([ev, fn]);
  1553. }
  1554. };
  1555. $.jqplot.EventListenerManager.prototype.add = function(ev, fn) {
  1556. this.hooks.push([ev, fn]);
  1557. };
  1558. var _axisNames = ['yMidAxis', 'xaxis', 'yaxis', 'x2axis', 'y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
  1559. /**
  1560. * Class: jqPlot
  1561. * Plot object returned by call to $.jqplot. Handles parsing user options,
  1562. * creating sub objects (Axes, legend, title, series) and rendering the plot.
  1563. */
  1564. function jqPlot() {
  1565. // Group: Properties
  1566. // These properties are specified at the top of the options object
  1567. // like so:
  1568. // > {
  1569. // > axesDefaults:{min:0},
  1570. // > series:[{color:'#6633dd'}],
  1571. // > title: 'A Plot'
  1572. // > }
  1573. //
  1574. // prop: animate
  1575. // True to animate the series on initial plot draw (renderer dependent).
  1576. // Actual animation functionality must be supported in the renderer.
  1577. this.animate = false;
  1578. // prop: animateReplot
  1579. // True to animate series after a call to the replot() method.
  1580. // Use with caution! Replots can happen very frequently under
  1581. // certain circumstances (e.g. resizing, dragging points) and
  1582. // animation in these situations can cause problems.
  1583. this.animateReplot = false;
  1584. // prop: axes
  1585. // up to 4 axes are supported, each with its own options,
  1586. // See <Axis> for axis specific options.
  1587. this.axes = {xaxis: new Axis('xaxis'), yaxis: new Axis('yaxis'), x2axis: new Axis('x2axis'), y2axis: new Axis('y2axis'), y3axis: new Axis('y3axis'), y4axis: new Axis('y4axis'), y5axis: new Axis('y5axis'), y6axis: new Axis('y6axis'), y7axis: new Axis('y7axis'), y8axis: new Axis('y8axis'), y9axis: new Axis('y9axis'), yMidAxis: new Axis('yMidAxis')};
  1588. this.baseCanvas = new $.jqplot.GenericCanvas();
  1589. // true to intercept right click events and fire a 'jqplotRightClick' event.
  1590. // this will also block the context menu.
  1591. this.captureRightClick = false;
  1592. // prop: data
  1593. // user's data. Data should *NOT* be specified in the options object,
  1594. // but be passed in as the second argument to the $.jqplot() function.
  1595. // The data property is described here soley for reference.
  1596. // The data should be in the form of an array of 2D or 1D arrays like
  1597. // > [ [[x1, y1], [x2, y2],...], [y1, y2, ...] ].
  1598. this.data = [];
  1599. // prop: dataRenderer
  1600. // A callable which can be used to preprocess data passed into the plot.
  1601. // Will be called with 3 arguments: the plot data, a reference to the plot,
  1602. // and the value of dataRendererOptions.
  1603. this.dataRenderer;
  1604. // prop: dataRendererOptions
  1605. // Options that will be passed to the dataRenderer.
  1606. // Can be of any type.
  1607. this.dataRendererOptions;
  1608. this.defaults = {
  1609. // prop: axesDefaults
  1610. // default options that will be applied to all axes.
  1611. // see <Axis> for axes options.
  1612. axesDefaults: {},
  1613. axes: {xaxis:{}, yaxis:{}, x2axis:{}, y2axis:{}, y3axis:{}, y4axis:{}, y5axis:{}, y6axis:{}, y7axis:{}, y8axis:{}, y9axis:{}, yMidAxis:{}},
  1614. // prop: seriesDefaults
  1615. // default options that will be applied to all series.
  1616. // see <Series> for series options.
  1617. seriesDefaults: {},
  1618. series:[]
  1619. };
  1620. // prop: defaultAxisStart
  1621. // 1-D data series are internally converted into 2-D [x,y] data point arrays
  1622. // by jqPlot. This is the default starting value for the missing x or y value.
  1623. // The added data will be a monotonically increasing series (e.g. [1, 2, 3, ...])
  1624. // starting at this value.
  1625. this.defaultAxisStart = 1;
  1626. // this.doCustomEventBinding = true;
  1627. // prop: drawIfHidden
  1628. // True to execute the draw method even if the plot target is hidden.
  1629. // Generally, this should be false. Most plot elements will not be sized/
  1630. // positioned correclty if renderered into a hidden container. To render into
  1631. // a hidden container, call the replot method when the container is shown.
  1632. this.drawIfHidden = false;
  1633. this.eventCanvas = new $.jqplot.GenericCanvas();
  1634. // prop: fillBetween
  1635. // Fill between 2 line series in a plot.
  1636. // Options object:
  1637. // {
  1638. // series1: first index (0 based) of series in fill
  1639. // series2: second index (0 based) of series in fill
  1640. // color: color of fill [default fillColor of series1]
  1641. // baseSeries: fill will be drawn below this series (0 based index)
  1642. // fill: false to turn off fill [default true].
  1643. // }
  1644. this.fillBetween = {
  1645. series1: null,
  1646. series2: null,
  1647. color: null,
  1648. baseSeries: 0,
  1649. fill: true
  1650. };
  1651. // prop; fontFamily
  1652. // css spec for the font-family attribute. Default for the entire plot.
  1653. this.fontFamily;
  1654. // prop: fontSize
  1655. // css spec for the font-size attribute. Default for the entire plot.
  1656. this.fontSize;
  1657. // prop: grid
  1658. // See <Grid> for grid specific options.
  1659. this.grid = new Grid();
  1660. // prop: legend
  1661. // see <$.jqplot.TableLegendRenderer>
  1662. this.legend = new Legend();
  1663. // prop: noDataIndicator
  1664. // Options to set up a mock plot with a data loading indicator if no data is specified.
  1665. this.noDataIndicator = {
  1666. show: false,
  1667. indicator: 'Loading Data...',
  1668. axes: {
  1669. xaxis: {
  1670. min: 0,
  1671. max: 10,
  1672. tickInterval: 2,
  1673. show: true
  1674. },
  1675. yaxis: {
  1676. min: 0,
  1677. max: 12,
  1678. tickInterval: 3,
  1679. show: true
  1680. }
  1681. }
  1682. };
  1683. // prop: negativeSeriesColors
  1684. // colors to use for portions of the line below zero.
  1685. this.negativeSeriesColors = $.jqplot.config.defaultNegativeColors;
  1686. // container to hold all of the merged options. Convienence for plugins.
  1687. this.options = {};
  1688. this.previousSeriesStack = [];
  1689. // Namespace to hold plugins. Generally non-renderer plugins add themselves to here.
  1690. this.plugins = {};
  1691. // prop: series
  1692. // Array of series object options.
  1693. // see <Series> for series specific options.
  1694. this.series = [];
  1695. // array of series indices. Keep track of order
  1696. // which series canvases are displayed, lowest
  1697. // to highest, back to front.
  1698. this.seriesStack = [];
  1699. // prop: seriesColors
  1700. // Ann array of CSS color specifications that will be applied, in order,
  1701. // to the series in the plot. Colors will wrap around so, if their
  1702. // are more series than colors, colors will be reused starting at the
  1703. // beginning. For pie charts, this specifies the colors of the slices.
  1704. this.seriesColors = $.jqplot.config.defaultColors;
  1705. // prop: sortData
  1706. // false to not sort the data passed in by the user.
  1707. // Many bar, stacked and other graphs as well as many plugins depend on
  1708. // having sorted data.
  1709. this.sortData = true;
  1710. // prop: stackSeries
  1711. // true or false, creates a stack or "mountain" plot.
  1712. // Not all series renderers may implement this option.
  1713. this.stackSeries = false;
  1714. // a shortcut for axis syncTicks options. Not implemented yet.
  1715. this.syncXTicks = true;
  1716. // a shortcut for axis syncTicks options. Not implemented yet.
  1717. this.syncYTicks = true;
  1718. // the jquery object for the dom target.
  1719. this.target = null;
  1720. // The id of the dom element to render the plot into
  1721. this.targetId = null;
  1722. // prop textColor
  1723. // css spec for the css color attribute. Default for the entire plot.
  1724. this.textColor;
  1725. // prop: title
  1726. // Title object. See <Title> for specific options. As a shortcut, you
  1727. // can specify the title option as just a string like: title: 'My Plot'
  1728. // and this will create a new title object with the specified text.
  1729. this.title = new Title();
  1730. // Count how many times the draw method has been called while the plot is visible.
  1731. // Mostly used to test if plot has never been dran (=0), has been successfully drawn
  1732. // into a visible container once (=1) or draw more than once into a visible container.
  1733. // Can use this in tests to see if plot has been visibly drawn at least one time.
  1734. // After plot has been visibly drawn once, it generally doesn't need redrawing if its
  1735. // container is hidden and shown.
  1736. this._drawCount = 0;
  1737. // sum of y values for all series in plot.
  1738. // used in mekko chart.
  1739. this._sumy = 0;
  1740. this._sumx = 0;
  1741. // array to hold the cumulative stacked series data.
  1742. // used to ajust the individual series data, which won't have access to other
  1743. // series data.
  1744. this._stackData = [];
  1745. // array that holds the data to be plotted. This will be the series data
  1746. // merged with the the appropriate data from _stackData according to the stackAxis.
  1747. this._plotData = [];
  1748. this._width = null;
  1749. this._height = null;
  1750. this._plotDimensions = {height:null, width:null};
  1751. this._gridPadding = {top:null, right:null, bottom:null, left:null};
  1752. this._defaultGridPadding = {top:10, right:10, bottom:23, left:10};
  1753. this._addDomReference = $.jqplot.config.addDomReference;
  1754. this.preInitHooks = new $.jqplot.HooksManager();
  1755. this.postInitHooks = new $.jqplot.HooksManager();
  1756. this.preParseOptionsHooks = new $.jqplot.HooksManager();
  1757. this.postParseOptionsHooks = new $.jqplot.HooksManager();
  1758. this.preDrawHooks = new $.jqplot.HooksManager();
  1759. this.postDrawHooks = new $.jqplot.HooksManager();
  1760. this.preDrawSeriesHooks = new $.jqplot.HooksManager();
  1761. this.postDrawSeriesHooks = new $.jqplot.HooksManager();
  1762. this.preDrawLegendHooks = new $.jqplot.HooksManager();
  1763. this.addLegendRowHooks = new $.jqplot.HooksManager();
  1764. this.preSeriesInitHooks = new $.jqplot.HooksManager();
  1765. this.postSeriesInitHooks = new $.jqplot.HooksManager();
  1766. this.preParseSeriesOptionsHooks = new $.jqplot.HooksManager();
  1767. this.postParseSeriesOptionsHooks = new $.jqplot.HooksManager();
  1768. this.eventListenerHooks = new $.jqplot.EventListenerManager();
  1769. this.preDrawSeriesShadowHooks = new $.jqplot.HooksManager();
  1770. this.postDrawSeriesShadowHooks = new $.jqplot.HooksManager();
  1771. this.colorGenerator = new $.jqplot.ColorGenerator();
  1772. this.negativeColorGenerator = new $.jqplot.ColorGenerator();
  1773. this.canvasManager = new $.jqplot.CanvasManager();
  1774. this.themeEngine = new $.jqplot.ThemeEngine();
  1775. var seriesColorsIndex = 0;
  1776. // Group: methods
  1777. //
  1778. // method: init
  1779. // sets the plot target, checks data and applies user
  1780. // options to plot.
  1781. this.init = function(target, data, options) {
  1782. options = options || {};
  1783. for (var i=0; i<$.jqplot.preInitHooks.length; i++) {
  1784. $.jqplot.preInitHooks[i].call(this, target, data, options);
  1785. }
  1786. for (var i=0; i<this.preInitHooks.hooks.length; i++) {
  1787. this.preInitHooks.hooks[i].call(this, target, data, options);
  1788. }
  1789. this.targetId = '#'+target;
  1790. this.target = $('#'+target);
  1791. //////
  1792. // Add a reference to plot
  1793. //////
  1794. if (this._addDomReference) {
  1795. this.target.data('jqplot', this);
  1796. }
  1797. // remove any error class that may be stuck on target.
  1798. this.target.removeClass('jqplot-error');
  1799. if (!this.target.get(0)) {
  1800. throw new Error("No plot target specified");
  1801. }
  1802. // make sure the target is positioned by some means and set css
  1803. if (this.target.css('position') == 'static') {
  1804. this.target.css('position', 'relative');
  1805. }
  1806. if (!this.target.hasClass('jqplot-target')) {
  1807. this.target.addClass('jqplot-target');
  1808. }
  1809. // if no height or width specified, use a default.
  1810. if (!this.target.height()) {
  1811. var h;
  1812. if (options && options.height) {
  1813. h = parseInt(options.height, 10);
  1814. }
  1815. else if (this.target.attr('data-height')) {
  1816. h = parseInt(this.target.attr('data-height'), 10);
  1817. }
  1818. else {
  1819. h = parseInt($.jqplot.config.defaultHeight, 10);
  1820. }
  1821. this._height = h;
  1822. this.target.css('height', h+'px');
  1823. }
  1824. else {
  1825. this._height = h = this.target.height();
  1826. }
  1827. if (!this.target.width()) {
  1828. var w;
  1829. if (options && options.width) {
  1830. w = parseInt(options.width, 10);
  1831. }
  1832. else if (this.target.attr('data-width')) {
  1833. w = parseInt(this.target.attr('data-width'), 10);
  1834. }
  1835. else {
  1836. w = parseInt($.jqplot.config.defaultWidth, 10);
  1837. }
  1838. this._width = w;
  1839. this.target.css('width', w+'px');
  1840. }
  1841. else {
  1842. this._width = w = this.target.width();
  1843. }
  1844. for (var i=0, l=_axisNames.length; i<l; i++) {
  1845. this.axes[_axisNames[i]] = new Axis(_axisNames[i]);
  1846. }
  1847. this._plotDimensions.height = this._height;
  1848. this._plotDimensions.width = this._width;
  1849. this.grid._plotDimensions = this._plotDimensions;
  1850. this.title._plotDimensions = this._plotDimensions;
  1851. this.baseCanvas._plotDimensions = this._plotDimensions;
  1852. this.eventCanvas._plotDimensions = this._plotDimensions;
  1853. this.legend._plotDimensions = this._plotDimensions;
  1854. if (this._height <=0 || this._width <=0 || !this._height || !this._width) {
  1855. throw new Error("Canvas dimension not set");
  1856. }
  1857. if (options.dataRenderer && $.isFunction(options.dataRenderer)) {
  1858. if (options.dataRendererOptions) {
  1859. this.dataRendererOptions = options.dataRendererOptions;
  1860. }
  1861. this.dataRenderer = options.dataRenderer;
  1862. data = this.dataRenderer(data, this, this.dataRendererOptions);
  1863. }
  1864. if (options.noDataIndicator && $.isPlainObject(options.noDataIndicator)) {
  1865. $.extend(true, this.noDataIndicator, options.noDataIndicator);
  1866. }
  1867. if (data == null || $.isArray(data) == false || data.length == 0 || $.isArray(data[0]) == false || data[0].length == 0) {
  1868. if (this.noDataIndicator.show == false) {
  1869. throw new Error("No data specified");
  1870. }
  1871. else {
  1872. // have to be descructive here in order for plot to not try and render series.
  1873. // This means that $.jqplot() will have to be called again when there is data.
  1874. //delete options.series;
  1875. for (var ax in this.noDataIndicator.axes) {
  1876. for (var prop in this.noDataIndicator.axes[ax]) {
  1877. this.axes[ax][prop] = this.noDataIndicator.axes[ax][prop];
  1878. }
  1879. }
  1880. this.postDrawHooks.add(function() {
  1881. var eh = this.eventCanvas.getHeight();
  1882. var ew = this.eventCanvas.getWidth();
  1883. var temp = $('<div class="jqplot-noData-container" style="position:absolute;"></div>');
  1884. this.target.append(temp);
  1885. temp.height(eh);
  1886. temp.width(ew);
  1887. temp.css('top', this.eventCanvas._offsets.top);
  1888. temp.css('left', this.eventCanvas._offsets.left);
  1889. var temp2 = $('<div class="jqplot-noData-contents" style="text-align:center; position:relative; margin-left:auto; margin-right:auto;"></div>');
  1890. temp.append(temp2);
  1891. temp2.html(this.noDataIndicator.indicator);
  1892. var th = temp2.height();
  1893. var tw = temp2.width();
  1894. temp2.height(th);
  1895. temp2.width(tw);
  1896. temp2.css('top', (eh - th)/2 + 'px');
  1897. });
  1898. }
  1899. }
  1900. // make a copy of the data
  1901. this.data = $.extend(true, [], data);
  1902. this.parseOptions(options);
  1903. if (this.textColor) {
  1904. this.target.css('color', this.textColor);
  1905. }
  1906. if (this.fontFamily) {
  1907. this.target.css('font-family', this.fontFamily);
  1908. }
  1909. if (this.fontSize) {
  1910. this.target.css('font-size', this.fontSize);
  1911. }
  1912. this.title.init();
  1913. this.legend.init();
  1914. this._sumy = 0;
  1915. this._sumx = 0;
  1916. this.computePlotData();
  1917. for (var i=0; i<this.series.length; i++) {
  1918. // set default stacking order for series canvases
  1919. this.seriesStack.push(i);
  1920. this.previousSeriesStack.push(i);
  1921. this.series[i].shadowCanvas._plotDimensions = this._plotDimensions;
  1922. this.series[i].canvas._plotDimensions = this._plotDimensions;
  1923. for (var j=0; j<$.jqplot.preSeriesInitHooks.length; j++) {
  1924. $.jqplot.preSeriesInitHooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  1925. }
  1926. for (var j=0; j<this.preSeriesInitHooks.hooks.length; j++) {
  1927. this.preSeriesInitHooks.hooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  1928. }
  1929. // this.populatePlotData(this.series[i], i);
  1930. this.series[i]._plotDimensions = this._plotDimensions;
  1931. this.series[i].init(i, this.grid.borderWidth, this);
  1932. for (var j=0; j<$.jqplot.postSeriesInitHooks.length; j++) {
  1933. $.jqplot.postSeriesInitHooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  1934. }
  1935. for (var j=0; j<this.postSeriesInitHooks.hooks.length; j++) {
  1936. this.postSeriesInitHooks.hooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  1937. }
  1938. this._sumy += this.series[i]._sumy;
  1939. this._sumx += this.series[i]._sumx;
  1940. }
  1941. var name,
  1942. axis;
  1943. for (var i=0, l=_axisNames.length; i<l; i++) {
  1944. name = _axisNames[i];
  1945. axis = this.axes[name];
  1946. axis._plotDimensions = this._plotDimensions;
  1947. axis.init();
  1948. if (this.axes[name].borderColor == null) {
  1949. if (name.charAt(0) !== 'x' && axis.useSeriesColor === true && axis.show) {
  1950. axis.borderColor = axis._series[0].color;
  1951. }
  1952. else {
  1953. axis.borderColor = this.grid.borderColor;
  1954. }
  1955. }
  1956. }
  1957. if (this.sortData) {
  1958. sortData(this.series);
  1959. }
  1960. this.grid.init();
  1961. this.grid._axes = this.axes;
  1962. this.legend._series = this.series;
  1963. for (var i=0; i<$.jqplot.postInitHooks.length; i++) {
  1964. $.jqplot.postInitHooks[i].call(this, target, this.data, options);
  1965. }
  1966. for (var i=0; i<this.postInitHooks.hooks.length; i++) {
  1967. this.postInitHooks.hooks[i].call(this, target, this.data, options);
  1968. }
  1969. };
  1970. // method: resetAxesScale
  1971. // Reset the specified axes min, max, numberTicks and tickInterval properties to null
  1972. // or reset these properties on all axes if no list of axes is provided.
  1973. //
  1974. // Parameters:
  1975. // axes - Boolean to reset or not reset all axes or an array or object of axis names to reset.
  1976. this.resetAxesScale = function(axes, options) {
  1977. var opts = options || {};
  1978. var ax = axes || this.axes;
  1979. if (ax === true) {
  1980. ax = this.axes;
  1981. }
  1982. if ($.isArray(ax)) {
  1983. for (var i = 0; i < ax.length; i++) {
  1984. this.axes[ax[i]].resetScale(opts[ax[i]]);
  1985. }
  1986. }
  1987. else if (typeof(ax) === 'object') {
  1988. for (var name in ax) {
  1989. this.axes[name].resetScale(opts[name]);
  1990. }
  1991. }
  1992. };
  1993. // method: reInitialize
  1994. // reinitialize plot for replotting.
  1995. // not called directly.
  1996. this.reInitialize = function (data, opts) {
  1997. // Plot should be visible and have a height and width.
  1998. // If plot doesn't have height and width for some
  1999. // reason, set it by other means. Plot must not have
  2000. // a display:none attribute, however.
  2001. var options = $.extend(true, {}, this.options, opts);
  2002. var target = this.targetId.substr(1);
  2003. var tdata = (data == null) ? this.data : data;
  2004. for (var i=0; i<$.jqplot.preInitHooks.length; i++) {
  2005. $.jqplot.preInitHooks[i].call(this, target, tdata, options);
  2006. }
  2007. for (var i=0; i<this.preInitHooks.hooks.length; i++) {
  2008. this.preInitHooks.hooks[i].call(this, target, tdata, options);
  2009. }
  2010. this._height = this.target.height();
  2011. this._width = this.target.width();
  2012. if (this._height <=0 || this._width <=0 || !this._height || !this._width) {
  2013. throw new Error("Target dimension not set");
  2014. }
  2015. this._plotDimensions.height = this._height;
  2016. this._plotDimensions.width = this._width;
  2017. this.grid._plotDimensions = this._plotDimensions;
  2018. this.title._plotDimensions = this._plotDimensions;
  2019. this.baseCanvas._plotDimensions = this._plotDimensions;
  2020. this.eventCanvas._plotDimensions = this._plotDimensions;
  2021. this.legend._plotDimensions = this._plotDimensions;
  2022. var name,
  2023. t,
  2024. j,
  2025. axis;
  2026. for (var i=0, l=_axisNames.length; i<l; i++) {
  2027. name = _axisNames[i];
  2028. axis = this.axes[name];
  2029. // Memory Leaks patch : clear ticks elements
  2030. t = axis._ticks;
  2031. for (var j = 0, tlen = t.length; j < tlen; j++) {
  2032. var el = t[j]._elem;
  2033. if (el) {
  2034. // if canvas renderer
  2035. if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
  2036. window.G_vmlCanvasManager.uninitElement(el.get(0));
  2037. }
  2038. el.emptyForce();
  2039. el = null;
  2040. t._elem = null;
  2041. }
  2042. }
  2043. t = null;
  2044. delete axis.ticks;
  2045. delete axis._ticks;
  2046. this.axes[name] = new Axis(name);
  2047. this.axes[name]._plotWidth = this._width;
  2048. this.axes[name]._plotHeight = this._height;
  2049. }
  2050. if (data) {
  2051. if (options.dataRenderer && $.isFunction(options.dataRenderer)) {
  2052. if (options.dataRendererOptions) {
  2053. this.dataRendererOptions = options.dataRendererOptions;
  2054. }
  2055. this.dataRenderer = options.dataRenderer;
  2056. data = this.dataRenderer(data, this, this.dataRendererOptions);
  2057. }
  2058. // make a copy of the data
  2059. this.data = $.extend(true, [], data);
  2060. }
  2061. if (opts) {
  2062. this.parseOptions(options);
  2063. }
  2064. this.title._plotWidth = this._width;
  2065. if (this.textColor) {
  2066. this.target.css('color', this.textColor);
  2067. }
  2068. if (this.fontFamily) {
  2069. this.target.css('font-family', this.fontFamily);
  2070. }
  2071. if (this.fontSize) {
  2072. this.target.css('font-size', this.fontSize);
  2073. }
  2074. this.title.init();
  2075. this.legend.init();
  2076. this._sumy = 0;
  2077. this._sumx = 0;
  2078. this.seriesStack = [];
  2079. this.previousSeriesStack = [];
  2080. this.computePlotData();
  2081. for (var i=0, l=this.series.length; i<l; i++) {
  2082. // set default stacking order for series canvases
  2083. this.seriesStack.push(i);
  2084. this.previousSeriesStack.push(i);
  2085. this.series[i].shadowCanvas._plotDimensions = this._plotDimensions;
  2086. this.series[i].canvas._plotDimensions = this._plotDimensions;
  2087. for (var j=0; j<$.jqplot.preSeriesInitHooks.length; j++) {
  2088. $.jqplot.preSeriesInitHooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  2089. }
  2090. for (var j=0; j<this.preSeriesInitHooks.hooks.length; j++) {
  2091. this.preSeriesInitHooks.hooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  2092. }
  2093. // this.populatePlotData(this.series[i], i);
  2094. this.series[i]._plotDimensions = this._plotDimensions;
  2095. this.series[i].init(i, this.grid.borderWidth, this);
  2096. for (var j=0; j<$.jqplot.postSeriesInitHooks.length; j++) {
  2097. $.jqplot.postSeriesInitHooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  2098. }
  2099. for (var j=0; j<this.postSeriesInitHooks.hooks.length; j++) {
  2100. this.postSeriesInitHooks.hooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  2101. }
  2102. this._sumy += this.series[i]._sumy;
  2103. this._sumx += this.series[i]._sumx;
  2104. }
  2105. for (var i=0, l=_axisNames.length; i<l; i++) {
  2106. name = _axisNames[i];
  2107. axis = this.axes[name];
  2108. axis._plotDimensions = this._plotDimensions;
  2109. axis.init();
  2110. if (axis.borderColor == null) {
  2111. if (name.charAt(0) !== 'x' && axis.useSeriesColor === true && axis.show) {
  2112. axis.borderColor = axis._series[0].color;
  2113. }
  2114. else {
  2115. axis.borderColor = this.grid.borderColor;
  2116. }
  2117. }
  2118. }
  2119. if (this.sortData) {
  2120. sortData(this.series);
  2121. }
  2122. this.grid.init();
  2123. this.grid._axes = this.axes;
  2124. this.legend._series = this.series;
  2125. for (var i=0, l=$.jqplot.postInitHooks.length; i<l; i++) {
  2126. $.jqplot.postInitHooks[i].call(this, target, this.data, options);
  2127. }
  2128. for (var i=0, l=this.postInitHooks.hooks.length; i<l; i++) {
  2129. this.postInitHooks.hooks[i].call(this, target, this.data, options);
  2130. }
  2131. };
  2132. // method: quickInit
  2133. //
  2134. // Quick reinitialization plot for replotting.
  2135. // Does not parse options ore recreate axes and series.
  2136. // not called directly.
  2137. this.quickInit = function () {
  2138. // Plot should be visible and have a height and width.
  2139. // If plot doesn't have height and width for some
  2140. // reason, set it by other means. Plot must not have
  2141. // a display:none attribute, however.
  2142. this._height = this.target.height();
  2143. this._width = this.target.width();
  2144. if (this._height <=0 || this._width <=0 || !this._height || !this._width) {
  2145. throw new Error("Target dimension not set");
  2146. }
  2147. this._plotDimensions.height = this._height;
  2148. this._plotDimensions.width = this._width;
  2149. this.grid._plotDimensions = this._plotDimensions;
  2150. this.title._plotDimensions = this._plotDimensions;
  2151. this.baseCanvas._plotDimensions = this._plotDimensions;
  2152. this.eventCanvas._plotDimensions = this._plotDimensions;
  2153. this.legend._plotDimensions = this._plotDimensions;
  2154. for (var n in this.axes) {
  2155. this.axes[n]._plotWidth = this._width;
  2156. this.axes[n]._plotHeight = this._height;
  2157. }
  2158. this.title._plotWidth = this._width;
  2159. if (this.textColor) {
  2160. this.target.css('color', this.textColor);
  2161. }
  2162. if (this.fontFamily) {
  2163. this.target.css('font-family', this.fontFamily);
  2164. }
  2165. if (this.fontSize) {
  2166. this.target.css('font-size', this.fontSize);
  2167. }
  2168. this._sumy = 0;
  2169. this._sumx = 0;
  2170. this.computePlotData();
  2171. for (var i=0; i<this.series.length; i++) {
  2172. // this.populatePlotData(this.series[i], i);
  2173. if (this.series[i]._type === 'line' && this.series[i].renderer.bands.show) {
  2174. this.series[i].renderer.initBands.call(this.series[i], this.series[i].renderer.options, this);
  2175. }
  2176. this.series[i]._plotDimensions = this._plotDimensions;
  2177. this.series[i].canvas._plotDimensions = this._plotDimensions;
  2178. //this.series[i].init(i, this.grid.borderWidth);
  2179. this._sumy += this.series[i]._sumy;
  2180. this._sumx += this.series[i]._sumx;
  2181. }
  2182. var name;
  2183. for (var j=0; j<12; j++) {
  2184. name = _axisNames[j];
  2185. // Memory Leaks patch : clear ticks elements
  2186. var t = this.axes[name]._ticks;
  2187. for (var i = 0; i < t.length; i++) {
  2188. var el = t[i]._elem;
  2189. if (el) {
  2190. // if canvas renderer
  2191. if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
  2192. window.G_vmlCanvasManager.uninitElement(el.get(0));
  2193. }
  2194. el.emptyForce();
  2195. el = null;
  2196. t._elem = null;
  2197. }
  2198. }
  2199. t = null;
  2200. this.axes[name]._plotDimensions = this._plotDimensions;
  2201. this.axes[name]._ticks = [];
  2202. // this.axes[name].renderer.init.call(this.axes[name], {});
  2203. }
  2204. if (this.sortData) {
  2205. sortData(this.series);
  2206. }
  2207. this.grid._axes = this.axes;
  2208. this.legend._series = this.series;
  2209. };
  2210. // sort the series data in increasing order.
  2211. function sortData(series) {
  2212. var d, sd, pd, ppd, ret;
  2213. for (var i=0; i<series.length; i++) {
  2214. var check;
  2215. var bat = [series[i].data, series[i]._stackData, series[i]._plotData, series[i]._prevPlotData];
  2216. for (var n=0; n<4; n++) {
  2217. check = true;
  2218. d = bat[n];
  2219. if (series[i]._stackAxis == 'x') {
  2220. for (var j = 0; j < d.length; j++) {
  2221. if (typeof(d[j][1]) != "number") {
  2222. check = false;
  2223. break;
  2224. }
  2225. }
  2226. if (check) {
  2227. d.sort(function(a,b) { return a[1] - b[1]; });
  2228. }
  2229. }
  2230. else {
  2231. for (var j = 0; j < d.length; j++) {
  2232. if (typeof(d[j][0]) != "number") {
  2233. check = false;
  2234. break;
  2235. }
  2236. }
  2237. if (check) {
  2238. d.sort(function(a,b) { return a[0] - b[0]; });
  2239. }
  2240. }
  2241. }
  2242. }
  2243. }
  2244. this.computePlotData = function() {
  2245. this._plotData = [];
  2246. this._stackData = [];
  2247. var series,
  2248. index,
  2249. l;
  2250. for (index=0, l=this.series.length; index<l; index++) {
  2251. series = this.series[index];
  2252. this._plotData.push([]);
  2253. this._stackData.push([]);
  2254. var cd = series.data;
  2255. this._plotData[index] = $.extend(true, [], cd);
  2256. this._stackData[index] = $.extend(true, [], cd);
  2257. series._plotData = this._plotData[index];
  2258. series._stackData = this._stackData[index];
  2259. var plotValues = {x:[], y:[]};
  2260. if (this.stackSeries && !series.disableStack) {
  2261. series._stack = true;
  2262. ///////////////////////////
  2263. // have to check for nulls
  2264. ///////////////////////////
  2265. var sidx = (series._stackAxis === 'x') ? 0 : 1;
  2266. for (var k=0, cdl=cd.length; k<cdl; k++) {
  2267. var temp = cd[k][sidx];
  2268. if (temp == null) {
  2269. temp = 0;
  2270. }
  2271. this._plotData[index][k][sidx] = temp;
  2272. this._stackData[index][k][sidx] = temp;
  2273. if (index > 0) {
  2274. for (var j=index; j--;) {
  2275. var prevval = this._plotData[j][k][sidx];
  2276. // only need to sum up the stack axis column of data
  2277. // and only sum if it is of same sign.
  2278. // if previous series isn't same sign, keep looking
  2279. // at earlier series untill we find one of same sign.
  2280. if (temp * prevval >= 0) {
  2281. this._plotData[index][k][sidx] += prevval;
  2282. this._stackData[index][k][sidx] += prevval;
  2283. break;
  2284. }
  2285. }
  2286. }
  2287. }
  2288. }
  2289. else {
  2290. for (var i=0; i<series.data.length; i++) {
  2291. plotValues.x.push(series.data[i][0]);
  2292. plotValues.y.push(series.data[i][1]);
  2293. }
  2294. this._stackData.push(series.data);
  2295. this.series[index]._stackData = series.data;
  2296. this._plotData.push(series.data);
  2297. series._plotData = series.data;
  2298. series._plotValues = plotValues;
  2299. }
  2300. if (index>0) {
  2301. series._prevPlotData = this.series[index-1]._plotData;
  2302. }
  2303. series._sumy = 0;
  2304. series._sumx = 0;
  2305. for (i=series.data.length-1; i>-1; i--) {
  2306. series._sumy += series.data[i][1];
  2307. series._sumx += series.data[i][0];
  2308. }
  2309. }
  2310. };
  2311. // populate the _stackData and _plotData arrays for the plot and the series.
  2312. this.populatePlotData = function(series, index) {
  2313. // if a stacked chart, compute the stacked data
  2314. this._plotData = [];
  2315. this._stackData = [];
  2316. series._stackData = [];
  2317. series._plotData = [];
  2318. var plotValues = {x:[], y:[]};
  2319. if (this.stackSeries && !series.disableStack) {
  2320. series._stack = true;
  2321. var sidx = (series._stackAxis === 'x') ? 0 : 1;
  2322. // var idx = sidx ? 0 : 1;
  2323. // push the current data into stackData
  2324. //this._stackData.push(this.series[i].data);
  2325. var temp = $.extend(true, [], series.data);
  2326. // create the data that will be plotted for this series
  2327. var plotdata = $.extend(true, [], series.data);
  2328. var tempx, tempy, dval, stackval, comparator;
  2329. // for first series, nothing to add to stackData.
  2330. for (var j=0; j<index; j++) {
  2331. var cd = this.series[j].data;
  2332. for (var k=0; k<cd.length; k++) {
  2333. dval = cd[k];
  2334. tempx = (dval[0] != null) ? dval[0] : 0;
  2335. tempy = (dval[1] != null) ? dval[1] : 0;
  2336. temp[k][0] += tempx;
  2337. temp[k][1] += tempy;
  2338. stackval = (sidx) ? tempy : tempx;
  2339. // only need to sum up the stack axis column of data
  2340. // and only sum if it is of same sign.
  2341. if (series.data[k][sidx] * stackval >= 0) {
  2342. plotdata[k][sidx] += stackval;
  2343. }
  2344. }
  2345. }
  2346. for (var i=0; i<plotdata.length; i++) {
  2347. plotValues.x.push(plotdata[i][0]);
  2348. plotValues.y.push(plotdata[i][1]);
  2349. }
  2350. this._plotData.push(plotdata);
  2351. this._stackData.push(temp);
  2352. series._stackData = temp;
  2353. series._plotData = plotdata;
  2354. series._plotValues = plotValues;
  2355. }
  2356. else {
  2357. for (var i=0; i<series.data.length; i++) {
  2358. plotValues.x.push(series.data[i][0]);
  2359. plotValues.y.push(series.data[i][1]);
  2360. }
  2361. this._stackData.push(series.data);
  2362. this.series[index]._stackData = series.data;
  2363. this._plotData.push(series.data);
  2364. series._plotData = series.data;
  2365. series._plotValues = plotValues;
  2366. }
  2367. if (index>0) {
  2368. series._prevPlotData = this.series[index-1]._plotData;
  2369. }
  2370. series._sumy = 0;
  2371. series._sumx = 0;
  2372. for (i=series.data.length-1; i>-1; i--) {
  2373. series._sumy += series.data[i][1];
  2374. series._sumx += series.data[i][0];
  2375. }
  2376. };
  2377. // function to safely return colors from the color array and wrap around at the end.
  2378. this.getNextSeriesColor = (function(t) {
  2379. var idx = 0;
  2380. var sc = t.seriesColors;
  2381. return function () {
  2382. if (idx < sc.length) {
  2383. return sc[idx++];
  2384. }
  2385. else {
  2386. idx = 0;
  2387. return sc[idx++];
  2388. }
  2389. };
  2390. })(this);
  2391. this.parseOptions = function(options){
  2392. for (var i=0; i<this.preParseOptionsHooks.hooks.length; i++) {
  2393. this.preParseOptionsHooks.hooks[i].call(this, options);
  2394. }
  2395. for (var i=0; i<$.jqplot.preParseOptionsHooks.length; i++) {
  2396. $.jqplot.preParseOptionsHooks[i].call(this, options);
  2397. }
  2398. this.options = $.extend(true, {}, this.defaults, options);
  2399. var opts = this.options;
  2400. this.animate = opts.animate;
  2401. this.animateReplot = opts.animateReplot;
  2402. this.stackSeries = opts.stackSeries;
  2403. if ($.isPlainObject(opts.fillBetween)) {
  2404. var temp = ['series1', 'series2', 'color', 'baseSeries', 'fill'],
  2405. tempi;
  2406. for (var i=0, l=temp.length; i<l; i++) {
  2407. tempi = temp[i];
  2408. if (opts.fillBetween[tempi] != null) {
  2409. this.fillBetween[tempi] = opts.fillBetween[tempi];
  2410. }
  2411. }
  2412. }
  2413. if (opts.seriesColors) {
  2414. this.seriesColors = opts.seriesColors;
  2415. }
  2416. if (opts.negativeSeriesColors) {
  2417. this.negativeSeriesColors = opts.negativeSeriesColors;
  2418. }
  2419. if (opts.captureRightClick) {
  2420. this.captureRightClick = opts.captureRightClick;
  2421. }
  2422. this.defaultAxisStart = (options && options.defaultAxisStart != null) ? options.defaultAxisStart : this.defaultAxisStart;
  2423. this.colorGenerator.setColors(this.seriesColors);
  2424. this.negativeColorGenerator.setColors(this.negativeSeriesColors);
  2425. // var cg = new this.colorGenerator(this.seriesColors);
  2426. // var ncg = new this.colorGenerator(this.negativeSeriesColors);
  2427. // this._gridPadding = this.options.gridPadding;
  2428. $.extend(true, this._gridPadding, opts.gridPadding);
  2429. this.sortData = (opts.sortData != null) ? opts.sortData : this.sortData;
  2430. for (var i=0; i<12; i++) {
  2431. var n = _axisNames[i];
  2432. var axis = this.axes[n];
  2433. axis._options = $.extend(true, {}, opts.axesDefaults, opts.axes[n]);
  2434. $.extend(true, axis, opts.axesDefaults, opts.axes[n]);
  2435. axis._plotWidth = this._width;
  2436. axis._plotHeight = this._height;
  2437. }
  2438. // if (this.data.length == 0) {
  2439. // this.data = [];
  2440. // for (var i=0; i<this.options.series.length; i++) {
  2441. // this.data.push(this.options.series.data);
  2442. // }
  2443. // }
  2444. var normalizeData = function(data, dir, start) {
  2445. // return data as an array of point arrays,
  2446. // in form [[x1,y1...], [x2,y2...], ...]
  2447. var temp = [];
  2448. var i, l;
  2449. dir = dir || 'vertical';
  2450. if (!$.isArray(data[0])) {
  2451. // we have a series of scalars. One line with just y values.
  2452. // turn the scalar list of data into a data array of form:
  2453. // [[1, data[0]], [2, data[1]], ...]
  2454. for (i=0, l=data.length; i<l; i++) {
  2455. if (dir == 'vertical') {
  2456. temp.push([start + i, data[i]]);
  2457. }
  2458. else {
  2459. temp.push([data[i], start+i]);
  2460. }
  2461. }
  2462. }
  2463. else {
  2464. // we have a properly formatted data series, copy it.
  2465. $.extend(true, temp, data);
  2466. }
  2467. return temp;
  2468. };
  2469. var colorIndex = 0;
  2470. this.series = [];
  2471. for (var i=0; i<this.data.length; i++) {
  2472. var sopts = $.extend(true, {index: i}, {seriesColors:this.seriesColors, negativeSeriesColors:this.negativeSeriesColors}, this.options.seriesDefaults, this.options.series[i], {rendererOptions:{animation:{show: this.animate}}});
  2473. // pass in options in case something needs set prior to initialization.
  2474. var temp = new Series(sopts);
  2475. for (var j=0; j<$.jqplot.preParseSeriesOptionsHooks.length; j++) {
  2476. $.jqplot.preParseSeriesOptionsHooks[j].call(temp, this.options.seriesDefaults, this.options.series[i]);
  2477. }
  2478. for (var j=0; j<this.preParseSeriesOptionsHooks.hooks.length; j++) {
  2479. this.preParseSeriesOptionsHooks.hooks[j].call(temp, this.options.seriesDefaults, this.options.series[i]);
  2480. }
  2481. // Now go back and apply the options to the series. Really should just do this during initializaiton, but don't want to
  2482. // mess up preParseSeriesOptionsHooks at this point.
  2483. $.extend(true, temp, sopts);
  2484. var dir = 'vertical';
  2485. if (temp.renderer === $.jqplot.BarRenderer && temp.rendererOptions && temp.rendererOptions.barDirection == 'horizontal') {
  2486. dir = 'horizontal';
  2487. temp._stackAxis = 'x';
  2488. temp._primaryAxis = '_yaxis';
  2489. }
  2490. temp.data = normalizeData(this.data[i], dir, this.defaultAxisStart);
  2491. switch (temp.xaxis) {
  2492. case 'xaxis':
  2493. temp._xaxis = this.axes.xaxis;
  2494. break;
  2495. case 'x2axis':
  2496. temp._xaxis = this.axes.x2axis;
  2497. break;
  2498. default:
  2499. break;
  2500. }
  2501. temp._yaxis = this.axes[temp.yaxis];
  2502. temp._xaxis._series.push(temp);
  2503. temp._yaxis._series.push(temp);
  2504. if (temp.show) {
  2505. temp._xaxis.show = true;
  2506. temp._yaxis.show = true;
  2507. }
  2508. else {
  2509. if (temp._xaxis.scaleToHiddenSeries) {
  2510. temp._xaxis.show = true;
  2511. }
  2512. if (temp._yaxis.scaleToHiddenSeries) {
  2513. temp._yaxis.show = true;
  2514. }
  2515. }
  2516. // // parse the renderer options and apply default colors if not provided
  2517. // if (!temp.color && temp.show != false) {
  2518. // temp.color = cg.next();
  2519. // colorIndex = cg.getIndex() - 1;;
  2520. // }
  2521. // if (!temp.negativeColor && temp.show != false) {
  2522. // temp.negativeColor = ncg.get(colorIndex);
  2523. // ncg.setIndex(colorIndex);
  2524. // }
  2525. if (!temp.label) {
  2526. temp.label = 'Series '+ (i+1).toString();
  2527. }
  2528. // temp.rendererOptions.show = temp.show;
  2529. // $.extend(true, temp.renderer, {color:this.seriesColors[i]}, this.rendererOptions);
  2530. this.series.push(temp);
  2531. for (var j=0; j<$.jqplot.postParseSeriesOptionsHooks.length; j++) {
  2532. $.jqplot.postParseSeriesOptionsHooks[j].call(this.series[i], this.options.seriesDefaults, this.options.series[i]);
  2533. }
  2534. for (var j=0; j<this.postParseSeriesOptionsHooks.hooks.length; j++) {
  2535. this.postParseSeriesOptionsHooks.hooks[j].call(this.series[i], this.options.seriesDefaults, this.options.series[i]);
  2536. }
  2537. }
  2538. // copy the grid and title options into this object.
  2539. $.extend(true, this.grid, this.options.grid);
  2540. // if axis border properties aren't set, set default.
  2541. for (var i=0, l=_axisNames.length; i<l; i++) {
  2542. var n = _axisNames[i];
  2543. var axis = this.axes[n];
  2544. if (axis.borderWidth == null) {
  2545. axis.borderWidth =this.grid.borderWidth;
  2546. }
  2547. }
  2548. if (typeof this.options.title == 'string') {
  2549. this.title.text = this.options.title;
  2550. }
  2551. else if (typeof this.options.title == 'object') {
  2552. $.extend(true, this.title, this.options.title);
  2553. }
  2554. this.title._plotWidth = this._width;
  2555. this.legend.setOptions(this.options.legend);
  2556. for (var i=0; i<$.jqplot.postParseOptionsHooks.length; i++) {
  2557. $.jqplot.postParseOptionsHooks[i].call(this, options);
  2558. }
  2559. for (var i=0; i<this.postParseOptionsHooks.hooks.length; i++) {
  2560. this.postParseOptionsHooks.hooks[i].call(this, options);
  2561. }
  2562. };
  2563. // method: destroy
  2564. // Releases all resources occupied by the plot
  2565. this.destroy = function() {
  2566. this.canvasManager.freeAllCanvases();
  2567. if (this.eventCanvas && this.eventCanvas._elem) {
  2568. this.eventCanvas._elem.unbind();
  2569. }
  2570. // Couple of posts on Stack Overflow indicate that empty() doesn't
  2571. // always cear up the dom and release memory. Sometimes setting
  2572. // innerHTML property to null is needed. Particularly on IE, may
  2573. // have to directly set it to null, bypassing $.
  2574. this.target.empty();
  2575. this.target[0].innerHTML = '';
  2576. };
  2577. // method: replot
  2578. // Does a reinitialization of the plot followed by
  2579. // a redraw. Method could be used to interactively
  2580. // change plot characteristics and then replot.
  2581. //
  2582. // Parameters:
  2583. // options - Options used for replotting.
  2584. //
  2585. // Properties:
  2586. // clear - false to not clear (empty) the plot container before replotting (default: true).
  2587. // resetAxes - true to reset all axes min, max, numberTicks and tickInterval setting so axes will rescale themselves.
  2588. // optionally pass in list of axes to reset (e.g. ['xaxis', 'y2axis']) (default: false).
  2589. this.replot = function(options) {
  2590. var opts = options || {};
  2591. var data = opts.data || null;
  2592. var clear = (opts.clear === false) ? false : true;
  2593. var resetAxes = opts.resetAxes || false;
  2594. delete opts.data;
  2595. delete opts.clear;
  2596. delete opts.resetAxes;
  2597. this.target.trigger('jqplotPreReplot');
  2598. if (clear) {
  2599. this.destroy();
  2600. }
  2601. // if have data or other options, full reinit.
  2602. // otherwise, quickinit.
  2603. if (data || !$.isEmptyObject(opts)) {
  2604. this.reInitialize(data, opts);
  2605. }
  2606. else {
  2607. this.quickInit();
  2608. }
  2609. if (resetAxes) {
  2610. this.resetAxesScale(resetAxes, opts.axes);
  2611. }
  2612. this.draw();
  2613. this.target.trigger('jqplotPostReplot');
  2614. };
  2615. // method: redraw
  2616. // Empties the plot target div and redraws the plot.
  2617. // This enables plot data and properties to be changed
  2618. // and then to comletely clear the plot and redraw.
  2619. // redraw *will not* reinitialize any plot elements.
  2620. // That is, axes will not be autoscaled and defaults
  2621. // will not be reapplied to any plot elements. redraw
  2622. // is used primarily with zooming.
  2623. //
  2624. // Parameters:
  2625. // clear - false to not clear (empty) the plot container before redrawing (default: true).
  2626. this.redraw = function(clear) {
  2627. clear = (clear != null) ? clear : true;
  2628. this.target.trigger('jqplotPreRedraw');
  2629. if (clear) {
  2630. this.canvasManager.freeAllCanvases();
  2631. this.eventCanvas._elem.unbind();
  2632. // Dont think I bind any events to the target, this shouldn't be necessary.
  2633. // It will remove user's events.
  2634. // this.target.unbind();
  2635. this.target.empty();
  2636. }
  2637. for (var ax in this.axes) {
  2638. this.axes[ax]._ticks = [];
  2639. }
  2640. this.computePlotData();
  2641. // for (var i=0; i<this.series.length; i++) {
  2642. // this.populatePlotData(this.series[i], i);
  2643. // }
  2644. this._sumy = 0;
  2645. this._sumx = 0;
  2646. for (var i=0, tsl = this.series.length; i<tsl; i++) {
  2647. this._sumy += this.series[i]._sumy;
  2648. this._sumx += this.series[i]._sumx;
  2649. }
  2650. this.draw();
  2651. this.target.trigger('jqplotPostRedraw');
  2652. };
  2653. // method: draw
  2654. // Draws all elements of the plot into the container.
  2655. // Does not clear the container before drawing.
  2656. this.draw = function(){
  2657. if (this.drawIfHidden || this.target.is(':visible')) {
  2658. this.target.trigger('jqplotPreDraw');
  2659. var i,
  2660. j,
  2661. l,
  2662. tempseries;
  2663. for (i=0, l=$.jqplot.preDrawHooks.length; i<l; i++) {
  2664. $.jqplot.preDrawHooks[i].call(this);
  2665. }
  2666. for (i=0, l=this.preDrawHooks.hooks.length; i<l; i++) {
  2667. this.preDrawHooks.hooks[i].apply(this, this.preDrawSeriesHooks.args[i]);
  2668. }
  2669. // create an underlying canvas to be used for special features.
  2670. this.target.append(this.baseCanvas.createElement({left:0, right:0, top:0, bottom:0}, 'jqplot-base-canvas', null, this));
  2671. this.baseCanvas.setContext();
  2672. this.target.append(this.title.draw());
  2673. this.title.pack({top:0, left:0});
  2674. // make room for the legend between the grid and the edge.
  2675. // pass a dummy offsets object and a reference to the plot.
  2676. var legendElem = this.legend.draw({}, this);
  2677. var gridPadding = {top:0, left:0, bottom:0, right:0};
  2678. if (this.legend.placement == "outsideGrid") {
  2679. // temporarily append the legend to get dimensions
  2680. this.target.append(legendElem);
  2681. switch (this.legend.location) {
  2682. case 'n':
  2683. gridPadding.top += this.legend.getHeight();
  2684. break;
  2685. case 's':
  2686. gridPadding.bottom += this.legend.getHeight();
  2687. break;
  2688. case 'ne':
  2689. case 'e':
  2690. case 'se':
  2691. gridPadding.right += this.legend.getWidth();
  2692. break;
  2693. case 'nw':
  2694. case 'w':
  2695. case 'sw':
  2696. gridPadding.left += this.legend.getWidth();
  2697. break;
  2698. default: // same as 'ne'
  2699. gridPadding.right += this.legend.getWidth();
  2700. break;
  2701. }
  2702. legendElem = legendElem.detach();
  2703. }
  2704. var ax = this.axes;
  2705. var name;
  2706. // draw the yMidAxis first, so xaxis of pyramid chart can adjust itself if needed.
  2707. for (i=0; i<12; i++) {
  2708. name = _axisNames[i];
  2709. this.target.append(ax[name].draw(this.baseCanvas._ctx, this));
  2710. ax[name].set();
  2711. }
  2712. if (ax.yaxis.show) {
  2713. gridPadding.left += ax.yaxis.getWidth();
  2714. }
  2715. var ra = ['y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
  2716. var rapad = [0, 0, 0, 0, 0, 0, 0, 0];
  2717. var gpr = 0;
  2718. var n;
  2719. for (n=0; n<8; n++) {
  2720. if (ax[ra[n]].show) {
  2721. gpr += ax[ra[n]].getWidth();
  2722. rapad[n] = gpr;
  2723. }
  2724. }
  2725. gridPadding.right += gpr;
  2726. if (ax.x2axis.show) {
  2727. gridPadding.top += ax.x2axis.getHeight();
  2728. }
  2729. if (this.title.show) {
  2730. gridPadding.top += this.title.getHeight();
  2731. }
  2732. if (ax.xaxis.show) {
  2733. gridPadding.bottom += ax.xaxis.getHeight();
  2734. }
  2735. // end of gridPadding adjustments.
  2736. // if user passed in gridDimensions option, check against calculated gridPadding
  2737. if (this.options.gridDimensions && $.isPlainObject(this.options.gridDimensions)) {
  2738. var gdw = parseInt(this.options.gridDimensions.width, 10) || 0;
  2739. var gdh = parseInt(this.options.gridDimensions.height, 10) || 0;
  2740. var widthAdj = (this._width - gridPadding.left - gridPadding.right - gdw)/2;
  2741. var heightAdj = (this._height - gridPadding.top - gridPadding.bottom - gdh)/2;
  2742. if (heightAdj >= 0 && widthAdj >= 0) {
  2743. gridPadding.top += heightAdj;
  2744. gridPadding.bottom += heightAdj;
  2745. gridPadding.left += widthAdj;
  2746. gridPadding.right += widthAdj;
  2747. }
  2748. }
  2749. var arr = ['top', 'bottom', 'left', 'right'];
  2750. for (var n in arr) {
  2751. if (this._gridPadding[arr[n]] == null && gridPadding[arr[n]] > 0) {
  2752. this._gridPadding[arr[n]] = gridPadding[arr[n]];
  2753. }
  2754. else if (this._gridPadding[arr[n]] == null) {
  2755. this._gridPadding[arr[n]] = this._defaultGridPadding[arr[n]];
  2756. }
  2757. }
  2758. var legendPadding = this._gridPadding;
  2759. if (this.legend.placement === 'outsideGrid') {
  2760. legendPadding = {top:this.title.getHeight(), left: 0, right: 0, bottom: 0};
  2761. if (this.legend.location === 's') {
  2762. legendPadding.left = this._gridPadding.left;
  2763. legendPadding.right = this._gridPadding.right;
  2764. }
  2765. }
  2766. ax.xaxis.pack({position:'absolute', bottom:this._gridPadding.bottom - ax.xaxis.getHeight(), left:0, width:this._width}, {min:this._gridPadding.left, max:this._width - this._gridPadding.right});
  2767. ax.yaxis.pack({position:'absolute', top:0, left:this._gridPadding.left - ax.yaxis.getWidth(), height:this._height}, {min:this._height - this._gridPadding.bottom, max: this._gridPadding.top});
  2768. ax.x2axis.pack({position:'absolute', top:this._gridPadding.top - ax.x2axis.getHeight(), left:0, width:this._width}, {min:this._gridPadding.left, max:this._width - this._gridPadding.right});
  2769. for (i=8; i>0; i--) {
  2770. ax[ra[i-1]].pack({position:'absolute', top:0, right:this._gridPadding.right - rapad[i-1]}, {min:this._height - this._gridPadding.bottom, max: this._gridPadding.top});
  2771. }
  2772. var ltemp = (this._width - this._gridPadding.left - this._gridPadding.right)/2.0 + this._gridPadding.left - ax.yMidAxis.getWidth()/2.0;
  2773. ax.yMidAxis.pack({position:'absolute', top:0, left:ltemp, zIndex:9, textAlign: 'center'}, {min:this._height - this._gridPadding.bottom, max: this._gridPadding.top});
  2774. this.target.append(this.grid.createElement(this._gridPadding, this));
  2775. this.grid.draw();
  2776. var series = this.series;
  2777. var seriesLength = series.length;
  2778. // put the shadow canvases behind the series canvases so shadows don't overlap on stacked bars.
  2779. for (i=0, l=seriesLength; i<l; i++) {
  2780. // draw series in order of stacking. This affects only
  2781. // order in which canvases are added to dom.
  2782. j = this.seriesStack[i];
  2783. this.target.append(series[j].shadowCanvas.createElement(this._gridPadding, 'jqplot-series-shadowCanvas', null, this));
  2784. series[j].shadowCanvas.setContext();
  2785. series[j].shadowCanvas._elem.data('seriesIndex', j);
  2786. }
  2787. for (i=0, l=seriesLength; i<l; i++) {
  2788. // draw series in order of stacking. This affects only
  2789. // order in which canvases are added to dom.
  2790. j = this.seriesStack[i];
  2791. this.target.append(series[j].canvas.createElement(this._gridPadding, 'jqplot-series-canvas', null, this));
  2792. series[j].canvas.setContext();
  2793. series[j].canvas._elem.data('seriesIndex', j);
  2794. }
  2795. // Need to use filled canvas to capture events in IE.
  2796. // Also, canvas seems to block selection of other elements in document on FF.
  2797. this.target.append(this.eventCanvas.createElement(this._gridPadding, 'jqplot-event-canvas', null, this));
  2798. this.eventCanvas.setContext();
  2799. this.eventCanvas._ctx.fillStyle = 'rgba(0,0,0,0)';
  2800. this.eventCanvas._ctx.fillRect(0,0,this.eventCanvas._ctx.canvas.width, this.eventCanvas._ctx.canvas.height);
  2801. // bind custom event handlers to regular events.
  2802. this.bindCustomEvents();
  2803. // draw legend before series if the series needs to know the legend dimensions.
  2804. if (this.legend.preDraw) {
  2805. this.eventCanvas._elem.before(legendElem);
  2806. this.legend.pack(legendPadding);
  2807. if (this.legend._elem) {
  2808. this.drawSeries({legendInfo:{location:this.legend.location, placement:this.legend.placement, width:this.legend.getWidth(), height:this.legend.getHeight(), xoffset:this.legend.xoffset, yoffset:this.legend.yoffset}});
  2809. }
  2810. else {
  2811. this.drawSeries();
  2812. }
  2813. }
  2814. else { // draw series before legend
  2815. this.drawSeries();
  2816. if (seriesLength) {
  2817. $(series[seriesLength-1].canvas._elem).after(legendElem);
  2818. }
  2819. this.legend.pack(legendPadding);
  2820. }
  2821. // register event listeners on the overlay canvas
  2822. for (var i=0, l=$.jqplot.eventListenerHooks.length; i<l; i++) {
  2823. // in the handler, this will refer to the eventCanvas dom element.
  2824. // make sure there are references back into plot objects.
  2825. this.eventCanvas._elem.bind($.jqplot.eventListenerHooks[i][0], {plot:this}, $.jqplot.eventListenerHooks[i][1]);
  2826. }
  2827. // register event listeners on the overlay canvas
  2828. for (var i=0, l=this.eventListenerHooks.hooks.length; i<l; i++) {
  2829. // in the handler, this will refer to the eventCanvas dom element.
  2830. // make sure there are references back into plot objects.
  2831. this.eventCanvas._elem.bind(this.eventListenerHooks.hooks[i][0], {plot:this}, this.eventListenerHooks.hooks[i][1]);
  2832. }
  2833. var fb = this.fillBetween;
  2834. if (fb.fill && fb.series1 !== fb.series2 && fb.series1 < seriesLength && fb.series2 < seriesLength && series[fb.series1]._type === 'line' && series[fb.series2]._type === 'line') {
  2835. this.doFillBetweenLines();
  2836. }
  2837. for (var i=0, l=$.jqplot.postDrawHooks.length; i<l; i++) {
  2838. $.jqplot.postDrawHooks[i].call(this);
  2839. }
  2840. for (var i=0, l=this.postDrawHooks.hooks.length; i<l; i++) {
  2841. this.postDrawHooks.hooks[i].apply(this, this.postDrawHooks.args[i]);
  2842. }
  2843. if (this.target.is(':visible')) {
  2844. this._drawCount += 1;
  2845. }
  2846. var temps,
  2847. tempr,
  2848. sel,
  2849. _els;
  2850. // ughh. ideally would hide all series then show them.
  2851. for (i=0, l=seriesLength; i<l; i++) {
  2852. temps = series[i];
  2853. tempr = temps.renderer;
  2854. sel = '.jqplot-point-label.jqplot-series-'+i;
  2855. if (tempr.animation && tempr.animation._supported && tempr.animation.show && (this._drawCount < 2 || this.animateReplot)) {
  2856. _els = this.target.find(sel);
  2857. _els.stop(true, true).hide();
  2858. temps.canvas._elem.stop(true, true).hide();
  2859. temps.shadowCanvas._elem.stop(true, true).hide();
  2860. temps.canvas._elem.jqplotEffect('blind', {mode: 'show', direction: tempr.animation.direction}, tempr.animation.speed);
  2861. temps.shadowCanvas._elem.jqplotEffect('blind', {mode: 'show', direction: tempr.animation.direction}, tempr.animation.speed);
  2862. _els.fadeIn(tempr.animation.speed*0.8);
  2863. }
  2864. }
  2865. _els = null;
  2866. this.target.trigger('jqplotPostDraw', [this]);
  2867. }
  2868. };
  2869. jqPlot.prototype.doFillBetweenLines = function () {
  2870. var fb = this.fillBetween;
  2871. var sid1 = fb.series1;
  2872. var sid2 = fb.series2;
  2873. // first series should always be lowest index
  2874. var id1 = (sid1 < sid2) ? sid1 : sid2;
  2875. var id2 = (sid2 > sid1) ? sid2 : sid1;
  2876. var series1 = this.series[id1];
  2877. var series2 = this.series[id2];
  2878. if (series2.renderer.smooth) {
  2879. var tempgd = series2.renderer._smoothedData.slice(0).reverse();
  2880. }
  2881. else {
  2882. var tempgd = series2.gridData.slice(0).reverse();
  2883. }
  2884. if (series1.renderer.smooth) {
  2885. var gd = series1.renderer._smoothedData.concat(tempgd);
  2886. }
  2887. else {
  2888. var gd = series1.gridData.concat(tempgd);
  2889. }
  2890. var color = (fb.color !== null) ? fb.color : this.series[sid1].fillColor;
  2891. var baseSeries = (fb.baseSeries !== null) ? fb.baseSeries : id1;
  2892. // now apply a fill to the shape on the lower series shadow canvas,
  2893. // so it is behind both series.
  2894. var sr = this.series[baseSeries].renderer.shapeRenderer;
  2895. var opts = {fillStyle: color, fill: true, closePath: true};
  2896. sr.draw(series1.shadowCanvas._ctx, gd, opts);
  2897. };
  2898. this.bindCustomEvents = function() {
  2899. this.eventCanvas._elem.bind('click', {plot:this}, this.onClick);
  2900. this.eventCanvas._elem.bind('dblclick', {plot:this}, this.onDblClick);
  2901. this.eventCanvas._elem.bind('mousedown', {plot:this}, this.onMouseDown);
  2902. this.eventCanvas._elem.bind('mousemove', {plot:this}, this.onMouseMove);
  2903. this.eventCanvas._elem.bind('mouseenter', {plot:this}, this.onMouseEnter);
  2904. this.eventCanvas._elem.bind('mouseleave', {plot:this}, this.onMouseLeave);
  2905. if (this.captureRightClick) {
  2906. this.eventCanvas._elem.bind('mouseup', {plot:this}, this.onRightClick);
  2907. this.eventCanvas._elem.get(0).oncontextmenu = function() {
  2908. return false;
  2909. };
  2910. }
  2911. else {
  2912. this.eventCanvas._elem.bind('mouseup', {plot:this}, this.onMouseUp);
  2913. }
  2914. };
  2915. function getEventPosition(ev) {
  2916. var plot = ev.data.plot;
  2917. var go = plot.eventCanvas._elem.offset();
  2918. var gridPos = {x:ev.pageX - go.left, y:ev.pageY - go.top};
  2919. var dataPos = {xaxis:null, yaxis:null, x2axis:null, y2axis:null, y3axis:null, y4axis:null, y5axis:null, y6axis:null, y7axis:null, y8axis:null, y9axis:null, yMidAxis:null};
  2920. var an = ['xaxis', 'yaxis', 'x2axis', 'y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis', 'yMidAxis'];
  2921. var ax = plot.axes;
  2922. var n, axis;
  2923. for (n=11; n>0; n--) {
  2924. axis = an[n-1];
  2925. if (ax[axis].show) {
  2926. dataPos[axis] = ax[axis].series_p2u(gridPos[axis.charAt(0)]);
  2927. }
  2928. }
  2929. return {offsets:go, gridPos:gridPos, dataPos:dataPos};
  2930. }
  2931. // function to check if event location is over a area area
  2932. function checkIntersection(gridpos, plot) {
  2933. var series = plot.series;
  2934. var i, j, k, s, r, x, y, theta, sm, sa, minang, maxang;
  2935. var d0, d, p, pp, points, bw, hp;
  2936. var threshold, t;
  2937. for (k=plot.seriesStack.length-1; k>=0; k--) {
  2938. i = plot.seriesStack[k];
  2939. s = series[i];
  2940. hp = s._highlightThreshold;
  2941. switch (s.renderer.constructor) {
  2942. case $.jqplot.BarRenderer:
  2943. x = gridpos.x;
  2944. y = gridpos.y;
  2945. for (j=0; j<s._barPoints.length; j++) {
  2946. points = s._barPoints[j];
  2947. p = s.gridData[j];
  2948. if (x>points[0][0] && x<points[2][0] && y>points[2][1] && y<points[0][1]) {
  2949. return {seriesIndex:s.index, pointIndex:j, gridData:p, data:s.data[j], points:s._barPoints[j]};
  2950. }
  2951. }
  2952. break;
  2953. case $.jqplot.PyramidRenderer:
  2954. x = gridpos.x;
  2955. y = gridpos.y;
  2956. for (j=0; j<s._barPoints.length; j++) {
  2957. points = s._barPoints[j];
  2958. p = s.gridData[j];
  2959. if (x > points[0][0] + hp[0][0] && x < points[2][0] + hp[2][0] && y > points[2][1] && y < points[0][1]) {
  2960. return {seriesIndex:s.index, pointIndex:j, gridData:p, data:s.data[j], points:s._barPoints[j]};
  2961. }
  2962. }
  2963. break;
  2964. case $.jqplot.DonutRenderer:
  2965. sa = s.startAngle/180*Math.PI;
  2966. x = gridpos.x - s._center[0];
  2967. y = gridpos.y - s._center[1];
  2968. r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  2969. if (x > 0 && -y >= 0) {
  2970. theta = 2*Math.PI - Math.atan(-y/x);
  2971. }
  2972. else if (x > 0 && -y < 0) {
  2973. theta = -Math.atan(-y/x);
  2974. }
  2975. else if (x < 0) {
  2976. theta = Math.PI - Math.atan(-y/x);
  2977. }
  2978. else if (x == 0 && -y > 0) {
  2979. theta = 3*Math.PI/2;
  2980. }
  2981. else if (x == 0 && -y < 0) {
  2982. theta = Math.PI/2;
  2983. }
  2984. else if (x == 0 && y == 0) {
  2985. theta = 0;
  2986. }
  2987. if (sa) {
  2988. theta -= sa;
  2989. if (theta < 0) {
  2990. theta += 2*Math.PI;
  2991. }
  2992. else if (theta > 2*Math.PI) {
  2993. theta -= 2*Math.PI;
  2994. }
  2995. }
  2996. sm = s.sliceMargin/180*Math.PI;
  2997. if (r < s._radius && r > s._innerRadius) {
  2998. for (j=0; j<s.gridData.length; j++) {
  2999. minang = (j>0) ? s.gridData[j-1][1]+sm : sm;
  3000. maxang = s.gridData[j][1];
  3001. if (theta > minang && theta < maxang) {
  3002. return {seriesIndex:s.index, pointIndex:j, gridData:[gridpos.x,gridpos.y], data:s.data[j]};
  3003. }
  3004. }
  3005. }
  3006. break;
  3007. case $.jqplot.PieRenderer:
  3008. sa = s.startAngle/180*Math.PI;
  3009. x = gridpos.x - s._center[0];
  3010. y = gridpos.y - s._center[1];
  3011. r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  3012. if (x > 0 && -y >= 0) {
  3013. theta = 2*Math.PI - Math.atan(-y/x);
  3014. }
  3015. else if (x > 0 && -y < 0) {
  3016. theta = -Math.atan(-y/x);
  3017. }
  3018. else if (x < 0) {
  3019. theta = Math.PI - Math.atan(-y/x);
  3020. }
  3021. else if (x == 0 && -y > 0) {
  3022. theta = 3*Math.PI/2;
  3023. }
  3024. else if (x == 0 && -y < 0) {
  3025. theta = Math.PI/2;
  3026. }
  3027. else if (x == 0 && y == 0) {
  3028. theta = 0;
  3029. }
  3030. if (sa) {
  3031. theta -= sa;
  3032. if (theta < 0) {
  3033. theta += 2*Math.PI;
  3034. }
  3035. else if (theta > 2*Math.PI) {
  3036. theta -= 2*Math.PI;
  3037. }
  3038. }
  3039. sm = s.sliceMargin/180*Math.PI;
  3040. if (r < s._radius) {
  3041. for (j=0; j<s.gridData.length; j++) {
  3042. minang = (j>0) ? s.gridData[j-1][1]+sm : sm;
  3043. maxang = s.gridData[j][1];
  3044. if (theta > minang && theta < maxang) {
  3045. return {seriesIndex:s.index, pointIndex:j, gridData:[gridpos.x,gridpos.y], data:s.data[j]};
  3046. }
  3047. }
  3048. }
  3049. break;
  3050. case $.jqplot.BubbleRenderer:
  3051. x = gridpos.x;
  3052. y = gridpos.y;
  3053. var ret = null;
  3054. if (s.show) {
  3055. for (var j=0; j<s.gridData.length; j++) {
  3056. p = s.gridData[j];
  3057. d = Math.sqrt( (x-p[0]) * (x-p[0]) + (y-p[1]) * (y-p[1]) );
  3058. if (d <= p[2] && (d <= d0 || d0 == null)) {
  3059. d0 = d;
  3060. ret = {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3061. }
  3062. }
  3063. if (ret != null) {
  3064. return ret;
  3065. }
  3066. }
  3067. break;
  3068. case $.jqplot.FunnelRenderer:
  3069. x = gridpos.x;
  3070. y = gridpos.y;
  3071. var v = s._vertices,
  3072. vfirst = v[0],
  3073. vlast = v[v.length-1],
  3074. lex,
  3075. rex,
  3076. cv;
  3077. // equations of right and left sides, returns x, y values given height of section (y value and 2 points)
  3078. function findedge (l, p1 , p2) {
  3079. var m = (p1[1] - p2[1])/(p1[0] - p2[0]);
  3080. var b = p1[1] - m*p1[0];
  3081. var y = l + p1[1];
  3082. return [(y - b)/m, y];
  3083. }
  3084. // check each section
  3085. lex = findedge(y, vfirst[0], vlast[3]);
  3086. rex = findedge(y, vfirst[1], vlast[2]);
  3087. for (j=0; j<v.length; j++) {
  3088. cv = v[j];
  3089. if (y >= cv[0][1] && y <= cv[3][1] && x >= lex[0] && x <= rex[0]) {
  3090. return {seriesIndex:s.index, pointIndex:j, gridData:null, data:s.data[j]};
  3091. }
  3092. }
  3093. break;
  3094. case $.jqplot.LineRenderer:
  3095. x = gridpos.x;
  3096. y = gridpos.y;
  3097. r = s.renderer;
  3098. if (s.show) {
  3099. if ((s.fill || (s.renderer.bands.show && s.renderer.bands.fill)) && (!plot.plugins.highlighter || !plot.plugins.highlighter.show)) {
  3100. // first check if it is in bounding box
  3101. var inside = false;
  3102. if (x>s._boundingBox[0][0] && x<s._boundingBox[1][0] && y>s._boundingBox[1][1] && y<s._boundingBox[0][1]) {
  3103. // now check the crossing number
  3104. var numPoints = s._areaPoints.length;
  3105. var ii;
  3106. var j = numPoints-1;
  3107. for(var ii=0; ii < numPoints; ii++) {
  3108. var vertex1 = [s._areaPoints[ii][0], s._areaPoints[ii][1]];
  3109. var vertex2 = [s._areaPoints[j][0], s._areaPoints[j][1]];
  3110. if (vertex1[1] < y && vertex2[1] >= y || vertex2[1] < y && vertex1[1] >= y) {
  3111. if (vertex1[0] + (y - vertex1[1]) / (vertex2[1] - vertex1[1]) * (vertex2[0] - vertex1[0]) < x) {
  3112. inside = !inside;
  3113. }
  3114. }
  3115. j = ii;
  3116. }
  3117. }
  3118. if (inside) {
  3119. return {seriesIndex:i, pointIndex:null, gridData:s.gridData, data:s.data, points:s._areaPoints};
  3120. }
  3121. break;
  3122. }
  3123. else {
  3124. t = s.markerRenderer.size/2+s.neighborThreshold;
  3125. threshold = (t > 0) ? t : 0;
  3126. for (var j=0; j<s.gridData.length; j++) {
  3127. p = s.gridData[j];
  3128. // neighbor looks different to OHLC chart.
  3129. if (r.constructor == $.jqplot.OHLCRenderer) {
  3130. if (r.candleStick) {
  3131. var yp = s._yaxis.series_u2p;
  3132. if (x >= p[0]-r._bodyWidth/2 && x <= p[0]+r._bodyWidth/2 && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
  3133. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3134. }
  3135. }
  3136. // if an open hi low close chart
  3137. else if (!r.hlc){
  3138. var yp = s._yaxis.series_u2p;
  3139. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
  3140. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3141. }
  3142. }
  3143. // a hi low close chart
  3144. else {
  3145. var yp = s._yaxis.series_u2p;
  3146. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][1]) && y <= yp(s.data[j][2])) {
  3147. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3148. }
  3149. }
  3150. }
  3151. else if (p[0] != null && p[1] != null){
  3152. d = Math.sqrt( (x-p[0]) * (x-p[0]) + (y-p[1]) * (y-p[1]) );
  3153. if (d <= threshold && (d <= d0 || d0 == null)) {
  3154. d0 = d;
  3155. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3156. }
  3157. }
  3158. }
  3159. }
  3160. }
  3161. break;
  3162. default:
  3163. x = gridpos.x;
  3164. y = gridpos.y;
  3165. r = s.renderer;
  3166. if (s.show) {
  3167. t = s.markerRenderer.size/2+s.neighborThreshold;
  3168. threshold = (t > 0) ? t : 0;
  3169. for (var j=0; j<s.gridData.length; j++) {
  3170. p = s.gridData[j];
  3171. // neighbor looks different to OHLC chart.
  3172. if (r.constructor == $.jqplot.OHLCRenderer) {
  3173. if (r.candleStick) {
  3174. var yp = s._yaxis.series_u2p;
  3175. if (x >= p[0]-r._bodyWidth/2 && x <= p[0]+r._bodyWidth/2 && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
  3176. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3177. }
  3178. }
  3179. // if an open hi low close chart
  3180. else if (!r.hlc){
  3181. var yp = s._yaxis.series_u2p;
  3182. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
  3183. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3184. }
  3185. }
  3186. // a hi low close chart
  3187. else {
  3188. var yp = s._yaxis.series_u2p;
  3189. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][1]) && y <= yp(s.data[j][2])) {
  3190. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3191. }
  3192. }
  3193. }
  3194. else {
  3195. d = Math.sqrt( (x-p[0]) * (x-p[0]) + (y-p[1]) * (y-p[1]) );
  3196. if (d <= threshold && (d <= d0 || d0 == null)) {
  3197. d0 = d;
  3198. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3199. }
  3200. }
  3201. }
  3202. }
  3203. break;
  3204. }
  3205. }
  3206. return null;
  3207. }
  3208. this.onClick = function(ev) {
  3209. // Event passed in is normalized and will have data attribute.
  3210. // Event passed out is unnormalized.
  3211. var positions = getEventPosition(ev);
  3212. var p = ev.data.plot;
  3213. var neighbor = checkIntersection(positions.gridPos, p);
  3214. var evt = $.Event('jqplotClick');
  3215. evt.pageX = ev.pageX;
  3216. evt.pageY = ev.pageY;
  3217. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3218. };
  3219. this.onDblClick = function(ev) {
  3220. // Event passed in is normalized and will have data attribute.
  3221. // Event passed out is unnormalized.
  3222. var positions = getEventPosition(ev);
  3223. var p = ev.data.plot;
  3224. var neighbor = checkIntersection(positions.gridPos, p);
  3225. var evt = $.Event('jqplotDblClick');
  3226. evt.pageX = ev.pageX;
  3227. evt.pageY = ev.pageY;
  3228. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3229. };
  3230. this.onMouseDown = function(ev) {
  3231. var positions = getEventPosition(ev);
  3232. var p = ev.data.plot;
  3233. var neighbor = checkIntersection(positions.gridPos, p);
  3234. var evt = $.Event('jqplotMouseDown');
  3235. evt.pageX = ev.pageX;
  3236. evt.pageY = ev.pageY;
  3237. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3238. };
  3239. this.onMouseUp = function(ev) {
  3240. var positions = getEventPosition(ev);
  3241. var evt = $.Event('jqplotMouseUp');
  3242. evt.pageX = ev.pageX;
  3243. evt.pageY = ev.pageY;
  3244. $(this).trigger(evt, [positions.gridPos, positions.dataPos, null, ev.data.plot]);
  3245. };
  3246. this.onRightClick = function(ev) {
  3247. var positions = getEventPosition(ev);
  3248. var p = ev.data.plot;
  3249. var neighbor = checkIntersection(positions.gridPos, p);
  3250. if (p.captureRightClick) {
  3251. if (ev.which == 3) {
  3252. var evt = $.Event('jqplotRightClick');
  3253. evt.pageX = ev.pageX;
  3254. evt.pageY = ev.pageY;
  3255. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3256. }
  3257. else {
  3258. var evt = $.Event('jqplotMouseUp');
  3259. evt.pageX = ev.pageX;
  3260. evt.pageY = ev.pageY;
  3261. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3262. }
  3263. }
  3264. };
  3265. this.onMouseMove = function(ev) {
  3266. var positions = getEventPosition(ev);
  3267. var p = ev.data.plot;
  3268. var neighbor = checkIntersection(positions.gridPos, p);
  3269. var evt = $.Event('jqplotMouseMove');
  3270. evt.pageX = ev.pageX;
  3271. evt.pageY = ev.pageY;
  3272. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3273. };
  3274. this.onMouseEnter = function(ev) {
  3275. var positions = getEventPosition(ev);
  3276. var p = ev.data.plot;
  3277. var evt = $.Event('jqplotMouseEnter');
  3278. evt.pageX = ev.pageX;
  3279. evt.pageY = ev.pageY;
  3280. evt.relatedTarget = ev.relatedTarget;
  3281. $(this).trigger(evt, [positions.gridPos, positions.dataPos, null, p]);
  3282. };
  3283. this.onMouseLeave = function(ev) {
  3284. var positions = getEventPosition(ev);
  3285. var p = ev.data.plot;
  3286. var evt = $.Event('jqplotMouseLeave');
  3287. evt.pageX = ev.pageX;
  3288. evt.pageY = ev.pageY;
  3289. evt.relatedTarget = ev.relatedTarget;
  3290. $(this).trigger(evt, [positions.gridPos, positions.dataPos, null, p]);
  3291. };
  3292. // method: drawSeries
  3293. // Redraws all or just one series on the plot. No axis scaling
  3294. // is performed and no other elements on the plot are redrawn.
  3295. // options is an options object to pass on to the series renderers.
  3296. // It can be an empty object {}. idx is the series index
  3297. // to redraw if only one series is to be redrawn.
  3298. this.drawSeries = function(options, idx){
  3299. var i, series, ctx;
  3300. // if only one argument passed in and it is a number, use it ad idx.
  3301. idx = (typeof(options) === "number" && idx == null) ? options : idx;
  3302. options = (typeof(options) === "object") ? options : {};
  3303. // draw specified series
  3304. if (idx != undefined) {
  3305. series = this.series[idx];
  3306. ctx = series.shadowCanvas._ctx;
  3307. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  3308. series.drawShadow(ctx, options, this);
  3309. ctx = series.canvas._ctx;
  3310. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  3311. series.draw(ctx, options, this);
  3312. if (series.renderer.constructor == $.jqplot.BezierCurveRenderer) {
  3313. if (idx < this.series.length - 1) {
  3314. this.drawSeries(idx+1);
  3315. }
  3316. }
  3317. }
  3318. else {
  3319. // if call series drawShadow method first, in case all series shadows
  3320. // should be drawn before any series. This will ensure, like for
  3321. // stacked bar plots, that shadows don't overlap series.
  3322. for (i=0; i<this.series.length; i++) {
  3323. // first clear the canvas
  3324. series = this.series[i];
  3325. ctx = series.shadowCanvas._ctx;
  3326. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  3327. series.drawShadow(ctx, options, this);
  3328. ctx = series.canvas._ctx;
  3329. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  3330. series.draw(ctx, options, this);
  3331. }
  3332. }
  3333. options = idx = i = series = ctx = null;
  3334. };
  3335. // method: moveSeriesToFront
  3336. // This method requires jQuery 1.4+
  3337. // Moves the specified series canvas in front of all other series canvases.
  3338. // This effectively "draws" the specified series on top of all other series,
  3339. // although it is performed through DOM manipulation, no redrawing is performed.
  3340. //
  3341. // Parameters:
  3342. // idx - 0 based index of the series to move. This will be the index of the series
  3343. // as it was first passed into the jqplot function.
  3344. this.moveSeriesToFront = function (idx) {
  3345. idx = parseInt(idx, 10);
  3346. var stackIndex = $.inArray(idx, this.seriesStack);
  3347. // if already in front, return
  3348. if (stackIndex == -1) {
  3349. return;
  3350. }
  3351. if (stackIndex == this.seriesStack.length -1) {
  3352. this.previousSeriesStack = this.seriesStack.slice(0);
  3353. return;
  3354. }
  3355. var opidx = this.seriesStack[this.seriesStack.length -1];
  3356. var serelem = this.series[idx].canvas._elem.detach();
  3357. var shadelem = this.series[idx].shadowCanvas._elem.detach();
  3358. this.series[opidx].shadowCanvas._elem.after(shadelem);
  3359. this.series[opidx].canvas._elem.after(serelem);
  3360. this.previousSeriesStack = this.seriesStack.slice(0);
  3361. this.seriesStack.splice(stackIndex, 1);
  3362. this.seriesStack.push(idx);
  3363. };
  3364. // method: moveSeriesToBack
  3365. // This method requires jQuery 1.4+
  3366. // Moves the specified series canvas behind all other series canvases.
  3367. //
  3368. // Parameters:
  3369. // idx - 0 based index of the series to move. This will be the index of the series
  3370. // as it was first passed into the jqplot function.
  3371. this.moveSeriesToBack = function (idx) {
  3372. idx = parseInt(idx, 10);
  3373. var stackIndex = $.inArray(idx, this.seriesStack);
  3374. // if already in back, return
  3375. if (stackIndex == 0 || stackIndex == -1) {
  3376. return;
  3377. }
  3378. var opidx = this.seriesStack[0];
  3379. var serelem = this.series[idx].canvas._elem.detach();
  3380. var shadelem = this.series[idx].shadowCanvas._elem.detach();
  3381. this.series[opidx].shadowCanvas._elem.before(shadelem);
  3382. this.series[opidx].canvas._elem.before(serelem);
  3383. this.previousSeriesStack = this.seriesStack.slice(0);
  3384. this.seriesStack.splice(stackIndex, 1);
  3385. this.seriesStack.unshift(idx);
  3386. };
  3387. // method: restorePreviousSeriesOrder
  3388. // This method requires jQuery 1.4+
  3389. // Restore the series canvas order to its previous state.
  3390. // Useful to put a series back where it belongs after moving
  3391. // it to the front.
  3392. this.restorePreviousSeriesOrder = function () {
  3393. var i, j, serelem, shadelem, temp, move, keep;
  3394. // if no change, return.
  3395. if (this.seriesStack == this.previousSeriesStack) {
  3396. return;
  3397. }
  3398. for (i=1; i<this.previousSeriesStack.length; i++) {
  3399. move = this.previousSeriesStack[i];
  3400. keep = this.previousSeriesStack[i-1];
  3401. serelem = this.series[move].canvas._elem.detach();
  3402. shadelem = this.series[move].shadowCanvas._elem.detach();
  3403. this.series[keep].shadowCanvas._elem.after(shadelem);
  3404. this.series[keep].canvas._elem.after(serelem);
  3405. }
  3406. temp = this.seriesStack.slice(0);
  3407. this.seriesStack = this.previousSeriesStack.slice(0);
  3408. this.previousSeriesStack = temp;
  3409. };
  3410. // method: restoreOriginalSeriesOrder
  3411. // This method requires jQuery 1.4+
  3412. // Restore the series canvas order to its original order
  3413. // when the plot was created.
  3414. this.restoreOriginalSeriesOrder = function () {
  3415. var i, j, arr=[], serelem, shadelem;
  3416. for (i=0; i<this.series.length; i++) {
  3417. arr.push(i);
  3418. }
  3419. if (this.seriesStack == arr) {
  3420. return;
  3421. }
  3422. this.previousSeriesStack = this.seriesStack.slice(0);
  3423. this.seriesStack = arr;
  3424. for (i=1; i<this.seriesStack.length; i++) {
  3425. serelem = this.series[i].canvas._elem.detach();
  3426. shadelem = this.series[i].shadowCanvas._elem.detach();
  3427. this.series[i-1].shadowCanvas._elem.after(shadelem);
  3428. this.series[i-1].canvas._elem.after(serelem);
  3429. }
  3430. };
  3431. this.activateTheme = function (name) {
  3432. this.themeEngine.activate(this, name);
  3433. };
  3434. }
  3435. // conpute a highlight color or array of highlight colors from given colors.
  3436. $.jqplot.computeHighlightColors = function(colors) {
  3437. var ret;
  3438. if ($.isArray(colors)) {
  3439. ret = [];
  3440. for (var i=0; i<colors.length; i++){
  3441. var rgba = $.jqplot.getColorComponents(colors[i]);
  3442. var newrgb = [rgba[0], rgba[1], rgba[2]];
  3443. var sum = newrgb[0] + newrgb[1] + newrgb[2];
  3444. for (var j=0; j<3; j++) {
  3445. // when darkening, lowest color component can be is 60.
  3446. newrgb[j] = (sum > 660) ? newrgb[j] * 0.85 : 0.73 * newrgb[j] + 90;
  3447. newrgb[j] = parseInt(newrgb[j], 10);
  3448. (newrgb[j] > 255) ? 255 : newrgb[j];
  3449. }
  3450. // newrgb[3] = (rgba[3] > 0.4) ? rgba[3] * 0.4 : rgba[3] * 1.5;
  3451. // newrgb[3] = (rgba[3] > 0.5) ? 0.8 * rgba[3] - .1 : rgba[3] + 0.2;
  3452. newrgb[3] = 0.3 + 0.35 * rgba[3];
  3453. ret.push('rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+newrgb[3]+')');
  3454. }
  3455. }
  3456. else {
  3457. var rgba = $.jqplot.getColorComponents(colors);
  3458. var newrgb = [rgba[0], rgba[1], rgba[2]];
  3459. var sum = newrgb[0] + newrgb[1] + newrgb[2];
  3460. for (var j=0; j<3; j++) {
  3461. // when darkening, lowest color component can be is 60.
  3462. // newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
  3463. // newrgb[j] = parseInt(newrgb[j], 10);
  3464. newrgb[j] = (sum > 660) ? newrgb[j] * 0.85 : 0.73 * newrgb[j] + 90;
  3465. newrgb[j] = parseInt(newrgb[j], 10);
  3466. (newrgb[j] > 255) ? 255 : newrgb[j];
  3467. }
  3468. // newrgb[3] = (rgba[3] > 0.4) ? rgba[3] * 0.4 : rgba[3] * 1.5;
  3469. // newrgb[3] = (rgba[3] > 0.5) ? 0.8 * rgba[3] - .1 : rgba[3] + 0.2;
  3470. newrgb[3] = 0.3 + 0.35 * rgba[3];
  3471. ret = 'rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+newrgb[3]+')';
  3472. }
  3473. return ret;
  3474. };
  3475. $.jqplot.ColorGenerator = function(colors) {
  3476. colors = colors || $.jqplot.config.defaultColors;
  3477. var idx = 0;
  3478. this.next = function () {
  3479. if (idx < colors.length) {
  3480. return colors[idx++];
  3481. }
  3482. else {
  3483. idx = 0;
  3484. return colors[idx++];
  3485. }
  3486. };
  3487. this.previous = function () {
  3488. if (idx > 0) {
  3489. return colors[idx--];
  3490. }
  3491. else {
  3492. idx = colors.length-1;
  3493. return colors[idx];
  3494. }
  3495. };
  3496. // get a color by index without advancing pointer.
  3497. this.get = function(i) {
  3498. var idx = i - colors.length * Math.floor(i/colors.length);
  3499. return colors[idx];
  3500. };
  3501. this.setColors = function(c) {
  3502. colors = c;
  3503. };
  3504. this.reset = function() {
  3505. idx = 0;
  3506. };
  3507. this.getIndex = function() {
  3508. return idx;
  3509. };
  3510. this.setIndex = function(index) {
  3511. idx = index;
  3512. };
  3513. };
  3514. // convert a hex color string to rgb string.
  3515. // h - 3 or 6 character hex string, with or without leading #
  3516. // a - optional alpha
  3517. $.jqplot.hex2rgb = function(h, a) {
  3518. h = h.replace('#', '');
  3519. if (h.length == 3) {
  3520. h = h.charAt(0)+h.charAt(0)+h.charAt(1)+h.charAt(1)+h.charAt(2)+h.charAt(2);
  3521. }
  3522. var rgb;
  3523. rgb = 'rgba('+parseInt(h.slice(0,2), 16)+', '+parseInt(h.slice(2,4), 16)+', '+parseInt(h.slice(4,6), 16);
  3524. if (a) {
  3525. rgb += ', '+a;
  3526. }
  3527. rgb += ')';
  3528. return rgb;
  3529. };
  3530. // convert an rgb color spec to a hex spec. ignore any alpha specification.
  3531. $.jqplot.rgb2hex = function(s) {
  3532. var pat = /rgba?\( *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *(?:, *[0-9.]*)?\)/;
  3533. var m = s.match(pat);
  3534. var h = '#';
  3535. for (var i=1; i<4; i++) {
  3536. var temp;
  3537. if (m[i].search(/%/) != -1) {
  3538. temp = parseInt(255*m[i]/100, 10).toString(16);
  3539. if (temp.length == 1) {
  3540. temp = '0'+temp;
  3541. }
  3542. }
  3543. else {
  3544. temp = parseInt(m[i], 10).toString(16);
  3545. if (temp.length == 1) {
  3546. temp = '0'+temp;
  3547. }
  3548. }
  3549. h += temp;
  3550. }
  3551. return h;
  3552. };
  3553. // given a css color spec, return an rgb css color spec
  3554. $.jqplot.normalize2rgb = function(s, a) {
  3555. if (s.search(/^ *rgba?\(/) != -1) {
  3556. return s;
  3557. }
  3558. else if (s.search(/^ *#?[0-9a-fA-F]?[0-9a-fA-F]/) != -1) {
  3559. return $.jqplot.hex2rgb(s, a);
  3560. }
  3561. else {
  3562. throw new Error('Invalid color spec');
  3563. }
  3564. };
  3565. // extract the r, g, b, a color components out of a css color spec.
  3566. $.jqplot.getColorComponents = function(s) {
  3567. // check to see if a color keyword.
  3568. s = $.jqplot.colorKeywordMap[s] || s;
  3569. var rgb = $.jqplot.normalize2rgb(s);
  3570. var pat = /rgba?\( *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *,? *([0-9.]* *)?\)/;
  3571. var m = rgb.match(pat);
  3572. var ret = [];
  3573. for (var i=1; i<4; i++) {
  3574. if (m[i].search(/%/) != -1) {
  3575. ret[i-1] = parseInt(255*m[i]/100, 10);
  3576. }
  3577. else {
  3578. ret[i-1] = parseInt(m[i], 10);
  3579. }
  3580. }
  3581. ret[3] = parseFloat(m[4]) ? parseFloat(m[4]) : 1.0;
  3582. return ret;
  3583. };
  3584. $.jqplot.colorKeywordMap = {
  3585. aliceblue: 'rgb(240, 248, 255)',
  3586. antiquewhite: 'rgb(250, 235, 215)',
  3587. aqua: 'rgb( 0, 255, 255)',
  3588. aquamarine: 'rgb(127, 255, 212)',
  3589. azure: 'rgb(240, 255, 255)',
  3590. beige: 'rgb(245, 245, 220)',
  3591. bisque: 'rgb(255, 228, 196)',
  3592. black: 'rgb( 0, 0, 0)',
  3593. blanchedalmond: 'rgb(255, 235, 205)',
  3594. blue: 'rgb( 0, 0, 255)',
  3595. blueviolet: 'rgb(138, 43, 226)',
  3596. brown: 'rgb(165, 42, 42)',
  3597. burlywood: 'rgb(222, 184, 135)',
  3598. cadetblue: 'rgb( 95, 158, 160)',
  3599. chartreuse: 'rgb(127, 255, 0)',
  3600. chocolate: 'rgb(210, 105, 30)',
  3601. coral: 'rgb(255, 127, 80)',
  3602. cornflowerblue: 'rgb(100, 149, 237)',
  3603. cornsilk: 'rgb(255, 248, 220)',
  3604. crimson: 'rgb(220, 20, 60)',
  3605. cyan: 'rgb( 0, 255, 255)',
  3606. darkblue: 'rgb( 0, 0, 139)',
  3607. darkcyan: 'rgb( 0, 139, 139)',
  3608. darkgoldenrod: 'rgb(184, 134, 11)',
  3609. darkgray: 'rgb(169, 169, 169)',
  3610. darkgreen: 'rgb( 0, 100, 0)',
  3611. darkgrey: 'rgb(169, 169, 169)',
  3612. darkkhaki: 'rgb(189, 183, 107)',
  3613. darkmagenta: 'rgb(139, 0, 139)',
  3614. darkolivegreen: 'rgb( 85, 107, 47)',
  3615. darkorange: 'rgb(255, 140, 0)',
  3616. darkorchid: 'rgb(153, 50, 204)',
  3617. darkred: 'rgb(139, 0, 0)',
  3618. darksalmon: 'rgb(233, 150, 122)',
  3619. darkseagreen: 'rgb(143, 188, 143)',
  3620. darkslateblue: 'rgb( 72, 61, 139)',
  3621. darkslategray: 'rgb( 47, 79, 79)',
  3622. darkslategrey: 'rgb( 47, 79, 79)',
  3623. darkturquoise: 'rgb( 0, 206, 209)',
  3624. darkviolet: 'rgb(148, 0, 211)',
  3625. deeppink: 'rgb(255, 20, 147)',
  3626. deepskyblue: 'rgb( 0, 191, 255)',
  3627. dimgray: 'rgb(105, 105, 105)',
  3628. dimgrey: 'rgb(105, 105, 105)',
  3629. dodgerblue: 'rgb( 30, 144, 255)',
  3630. firebrick: 'rgb(178, 34, 34)',
  3631. floralwhite: 'rgb(255, 250, 240)',
  3632. forestgreen: 'rgb( 34, 139, 34)',
  3633. fuchsia: 'rgb(255, 0, 255)',
  3634. gainsboro: 'rgb(220, 220, 220)',
  3635. ghostwhite: 'rgb(248, 248, 255)',
  3636. gold: 'rgb(255, 215, 0)',
  3637. goldenrod: 'rgb(218, 165, 32)',
  3638. gray: 'rgb(128, 128, 128)',
  3639. grey: 'rgb(128, 128, 128)',
  3640. green: 'rgb( 0, 128, 0)',
  3641. greenyellow: 'rgb(173, 255, 47)',
  3642. honeydew: 'rgb(240, 255, 240)',
  3643. hotpink: 'rgb(255, 105, 180)',
  3644. indianred: 'rgb(205, 92, 92)',
  3645. indigo: 'rgb( 75, 0, 130)',
  3646. ivory: 'rgb(255, 255, 240)',
  3647. khaki: 'rgb(240, 230, 140)',
  3648. lavender: 'rgb(230, 230, 250)',
  3649. lavenderblush: 'rgb(255, 240, 245)',
  3650. lawngreen: 'rgb(124, 252, 0)',
  3651. lemonchiffon: 'rgb(255, 250, 205)',
  3652. lightblue: 'rgb(173, 216, 230)',
  3653. lightcoral: 'rgb(240, 128, 128)',
  3654. lightcyan: 'rgb(224, 255, 255)',
  3655. lightgoldenrodyellow: 'rgb(250, 250, 210)',
  3656. lightgray: 'rgb(211, 211, 211)',
  3657. lightgreen: 'rgb(144, 238, 144)',
  3658. lightgrey: 'rgb(211, 211, 211)',
  3659. lightpink: 'rgb(255, 182, 193)',
  3660. lightsalmon: 'rgb(255, 160, 122)',
  3661. lightseagreen: 'rgb( 32, 178, 170)',
  3662. lightskyblue: 'rgb(135, 206, 250)',
  3663. lightslategray: 'rgb(119, 136, 153)',
  3664. lightslategrey: 'rgb(119, 136, 153)',
  3665. lightsteelblue: 'rgb(176, 196, 222)',
  3666. lightyellow: 'rgb(255, 255, 224)',
  3667. lime: 'rgb( 0, 255, 0)',
  3668. limegreen: 'rgb( 50, 205, 50)',
  3669. linen: 'rgb(250, 240, 230)',
  3670. magenta: 'rgb(255, 0, 255)',
  3671. maroon: 'rgb(128, 0, 0)',
  3672. mediumaquamarine: 'rgb(102, 205, 170)',
  3673. mediumblue: 'rgb( 0, 0, 205)',
  3674. mediumorchid: 'rgb(186, 85, 211)',
  3675. mediumpurple: 'rgb(147, 112, 219)',
  3676. mediumseagreen: 'rgb( 60, 179, 113)',
  3677. mediumslateblue: 'rgb(123, 104, 238)',
  3678. mediumspringgreen: 'rgb( 0, 250, 154)',
  3679. mediumturquoise: 'rgb( 72, 209, 204)',
  3680. mediumvioletred: 'rgb(199, 21, 133)',
  3681. midnightblue: 'rgb( 25, 25, 112)',
  3682. mintcream: 'rgb(245, 255, 250)',
  3683. mistyrose: 'rgb(255, 228, 225)',
  3684. moccasin: 'rgb(255, 228, 181)',
  3685. navajowhite: 'rgb(255, 222, 173)',
  3686. navy: 'rgb( 0, 0, 128)',
  3687. oldlace: 'rgb(253, 245, 230)',
  3688. olive: 'rgb(128, 128, 0)',
  3689. olivedrab: 'rgb(107, 142, 35)',
  3690. orange: 'rgb(255, 165, 0)',
  3691. orangered: 'rgb(255, 69, 0)',
  3692. orchid: 'rgb(218, 112, 214)',
  3693. palegoldenrod: 'rgb(238, 232, 170)',
  3694. palegreen: 'rgb(152, 251, 152)',
  3695. paleturquoise: 'rgb(175, 238, 238)',
  3696. palevioletred: 'rgb(219, 112, 147)',
  3697. papayawhip: 'rgb(255, 239, 213)',
  3698. peachpuff: 'rgb(255, 218, 185)',
  3699. peru: 'rgb(205, 133, 63)',
  3700. pink: 'rgb(255, 192, 203)',
  3701. plum: 'rgb(221, 160, 221)',
  3702. powderblue: 'rgb(176, 224, 230)',
  3703. purple: 'rgb(128, 0, 128)',
  3704. red: 'rgb(255, 0, 0)',
  3705. rosybrown: 'rgb(188, 143, 143)',
  3706. royalblue: 'rgb( 65, 105, 225)',
  3707. saddlebrown: 'rgb(139, 69, 19)',
  3708. salmon: 'rgb(250, 128, 114)',
  3709. sandybrown: 'rgb(244, 164, 96)',
  3710. seagreen: 'rgb( 46, 139, 87)',
  3711. seashell: 'rgb(255, 245, 238)',
  3712. sienna: 'rgb(160, 82, 45)',
  3713. silver: 'rgb(192, 192, 192)',
  3714. skyblue: 'rgb(135, 206, 235)',
  3715. slateblue: 'rgb(106, 90, 205)',
  3716. slategray: 'rgb(112, 128, 144)',
  3717. slategrey: 'rgb(112, 128, 144)',
  3718. snow: 'rgb(255, 250, 250)',
  3719. springgreen: 'rgb( 0, 255, 127)',
  3720. steelblue: 'rgb( 70, 130, 180)',
  3721. tan: 'rgb(210, 180, 140)',
  3722. teal: 'rgb( 0, 128, 128)',
  3723. thistle: 'rgb(216, 191, 216)',
  3724. tomato: 'rgb(255, 99, 71)',
  3725. turquoise: 'rgb( 64, 224, 208)',
  3726. violet: 'rgb(238, 130, 238)',
  3727. wheat: 'rgb(245, 222, 179)',
  3728. white: 'rgb(255, 255, 255)',
  3729. whitesmoke: 'rgb(245, 245, 245)',
  3730. yellow: 'rgb(255, 255, 0)',
  3731. yellowgreen: 'rgb(154, 205, 50)'
  3732. };
  3733. })(jQuery);