charts.js 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061
  1. /*
  2. Copyright (c) 2009, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.net/yui/license.txt
  5. version: 2.8.0r4
  6. */
  7. /**
  8. * The Charts widget provides a Flash control for displaying data
  9. * graphically by series across A-grade browsers with Flash Player installed.
  10. *
  11. * @module charts
  12. * @requires yahoo, dom, event, datasource
  13. * @title Charts Widget
  14. * @experimental
  15. */
  16. /****************************************************************************/
  17. /****************************************************************************/
  18. /****************************************************************************/
  19. /**
  20. * Chart class for the YUI Charts widget.
  21. *
  22. * @namespace YAHOO.widget
  23. * @class Chart
  24. * @uses YAHOO.util.AttributeProvider
  25. * @constructor
  26. * @param type {String} The char type. May be "line", "column", "bar", or "pie"
  27. * @param containerId {HTMLElement} Container element for the Flash Player instance.
  28. * @param dataSource {YAHOO.util.DataSource} DataSource instance.
  29. * @param attributes {object} (optional) Object literal of configuration values.
  30. */
  31. YAHOO.widget.Chart = function(type, containerId, dataSource, configurationAttributes)
  32. {
  33. this._type = type;
  34. this._dataSource = dataSource;
  35. var possibleParams = {align:"", allowNetworking:"", allowScriptAccess:"", base:"", bgcolor:"", menu:"", name:"", quality:"", salign:"", scale:"", tabindex:"", wmode:""};
  36. var attributes = {fixedAttributes:{allowScriptAccess:"always"}, flashVars:{allowedDomain : document.location.hostname}, backgroundColor:"#ffffff", host:this, version:9.045};
  37. for(var i in configurationAttributes)
  38. {
  39. if(possibleParams.hasOwnProperty(i))
  40. {
  41. attributes.fixedAttributes[i] = configurationAttributes[i];
  42. }
  43. else
  44. {
  45. attributes[i] = configurationAttributes[i];
  46. }
  47. }
  48. this._id = attributes.id = attributes.id || YAHOO.util.Dom.generateId(null, "yuigen");
  49. if(attributes.version && attributes.version != null && attributes.version != undefined && attributes.version != "undefined")
  50. {
  51. var version = (/\w*.\w*/.exec(((attributes.version).toString()).replace(/.0./g, "."))).toString();
  52. var verSplit = version.split(".");
  53. version = verSplit[0] + ".";
  54. switch((verSplit[1].toString()).length)
  55. {
  56. case 1:
  57. version += "00";
  58. break;
  59. case 2:
  60. version += "0";
  61. break;
  62. }
  63. version += verSplit[1];
  64. attributes.version = parseFloat(version);
  65. }
  66. this._swfURL = YAHOO.widget.Chart.SWFURL;
  67. this._containerID = containerId;
  68. this._attributes = attributes
  69. this._swfEmbed = new YAHOO.widget.SWF(containerId, YAHOO.widget.Chart.SWFURL, attributes);
  70. this._swf = this._swfEmbed.swf;
  71. this._swfEmbed.subscribe("swfReady", this._eventHandler, this, true);
  72. /**
  73. * Fires when the SWF is initialized and communication is possible.
  74. * @event contentReady
  75. */
  76. //Fix for iframe cross-domain issue with FF2x
  77. try
  78. {
  79. this.createEvent("contentReady");
  80. }
  81. catch(e){}
  82. /**
  83. * Fires when the user moves the mouse over the bounds of an item renderer in the chart.
  84. *
  85. * @event itemMouseOverEvent
  86. * @param event.type {String} The event type
  87. * @param event.item {Object} The data displayed by the renderer
  88. * @param event.index {Number} The position within the series that the item appears.
  89. * @param event.seriesIndex {Number} The position within the series definition that the series appears.
  90. * @param event.x {Number} The horizontal position of the mouse, relative to the SWF.
  91. * @param event.y {Number} The vertical position of the mouse, relative to the SWF.
  92. */
  93. this.createEvent("itemMouseOverEvent");
  94. /**
  95. * Fires when the user moves the mouse out of the bounds of an item renderer in the chart.
  96. *
  97. * @event itemMouseOutEvent
  98. * @param event.type {String} The event type
  99. * @param event.item {Object} The data displayed by the renderer
  100. * @param event.index {Number} The position within the series that the item appears.
  101. * @param event.seriesIndex {Number} The position within the series definition that the series appears.
  102. * @param event.x {Number} The horizontal position of the mouse, relative to the SWF.
  103. * @param event.y {Number} The vertical position of the mouse, relative to the SWF.
  104. */
  105. this.createEvent("itemMouseOutEvent");
  106. /**
  107. * Fires when the user clicks an item renderer in the chart with the mouse.
  108. *
  109. * @event itemClickEvent
  110. * @param event.type {String} The event type
  111. * @param event.item {Object} The data displayed by the renderer
  112. * @param event.index {Number} The position within the series that the item appears.
  113. * @param event.seriesIndex {Number} The position within the series definition that the series appears.
  114. * @param event.x {Number} The horizontal position of the mouse, relative to the SWF.
  115. * @param event.y {Number} The vertical position of the mouse, relative to the SWF.
  116. */
  117. this.createEvent("itemClickEvent");
  118. /**
  119. * Fires when the user double-clicks an item renderer in the chart with the mouse.
  120. *
  121. * @event itemDoubleClickEvent
  122. * @param event.type {String} The event type
  123. * @param event.item {Object} The data displayed by the renderer
  124. * @param event.index {Number} The position within the series that the item appears.
  125. * @param event.seriesIndex {Number} The position within the series definition that the series appears.
  126. * @param event.x {Number} The horizontal position of the mouse, relative to the SWF.
  127. * @param event.y {Number} The vertical position of the mouse, relative to the SWF.
  128. */
  129. this.createEvent("itemDoubleClickEvent");
  130. /**
  131. * Fires when the user presses the mouse down on an item to initiate a drag action.
  132. *
  133. * @event itemDragStartEvent
  134. * @param event.type {String} The event type
  135. * @param event.item {Object} The data displayed by the renderer
  136. * @param event.index {Number} The position within the series that the item appears.
  137. * @param event.seriesIndex {Number} The position within the series definition that the series appears.
  138. * @param event.x {Number} The horizontal position of the mouse, relative to the SWF.
  139. * @param event.y {Number} The vertical position of the mouse, relative to the SWF.
  140. */
  141. this.createEvent("itemDragStartEvent");
  142. /**
  143. * Fires when the user moves the mouse during a drag action.
  144. *
  145. * @event itemDragEvent
  146. * @param event.type {String} The event type
  147. * @param event.item {Object} The data displayed by the renderer
  148. * @param event.index {Number} The position within the series that the item appears.
  149. * @param event.seriesIndex {Number} The position within the series definition that the series appears.
  150. * @param event.x {Number} The horizontal position of the mouse, relative to the SWF.
  151. * @param event.y {Number} The vertical position of the mouse, relative to the SWF.
  152. */
  153. this.createEvent("itemDragEvent");
  154. /**
  155. * Fires when the user releases the mouse during a drag action.
  156. *
  157. * @event itemDragEndEvent
  158. * @param event.type {String} The event type
  159. * @param event.item {Object} The data displayed by the renderer
  160. * @param event.index {Number} The position within the series that the item appears.
  161. * @param event.seriesIndex {Number} The position within the series definition that the series appears.
  162. * @param event.x {Number} The horizontal position of the mouse, relative to the SWF.
  163. * @param event.y {Number} The vertical position of the mouse, relative to the SWF.
  164. */
  165. this.createEvent("itemDragEndEvent");
  166. };
  167. YAHOO.extend(YAHOO.widget.Chart, YAHOO.util.AttributeProvider,
  168. {
  169. /**
  170. * The type of this chart instance.
  171. * @property _type
  172. * @type String
  173. * @private
  174. */
  175. _type: null,
  176. /**
  177. * The id returned from the DataSource's setInterval function.
  178. * @property _pollingID
  179. * @type Number
  180. * @private
  181. */
  182. _pollingID: null,
  183. /**
  184. * The time, in ms, between requests for data.
  185. * @property _pollingInterval
  186. * @type Number
  187. * @private
  188. */
  189. _pollingInterval: null,
  190. /**
  191. * Stores a reference to the dataTipFunction created by
  192. * YAHOO.widget.Chart.createProxyFunction()
  193. * @property _dataTipFunction
  194. * @type String
  195. * @private
  196. */
  197. _dataTipFunction: null,
  198. /**
  199. * Stores a reference to the legendLabelFunction created by
  200. * YAHOO.widget.Chart.createProxyFunction()
  201. * @property _legendLabelFunction
  202. * @type String
  203. * @private
  204. */
  205. _legendLabelFunction: null,
  206. /**
  207. * Stores references to series function values created by
  208. * YAHOO.widget.Chart.createProxyFunction()
  209. * @property _seriesFunctions
  210. * @type Array
  211. * @private
  212. */
  213. _seriesFunctions: null,
  214. /**
  215. * Public accessor to the unique name of the Chart instance.
  216. *
  217. * @method toString
  218. * @return {String} Unique name of the Chart instance.
  219. */
  220. toString: function()
  221. {
  222. return "Chart " + this._id;
  223. },
  224. /**
  225. * Sets a single style value on the Chart instance.
  226. *
  227. * @method setStyle
  228. * @param name {String} Name of the Chart style value to change.
  229. * @param value {Object} New value to pass to the Chart style.
  230. */
  231. setStyle: function(name, value)
  232. {
  233. //we must jsonify this because Flash Player versions below 9.0.60 don't handle
  234. //complex ExternalInterface parsing correctly
  235. value = YAHOO.lang.JSON.stringify(value);
  236. this._swf.setStyle(name, value);
  237. },
  238. /**
  239. * Resets all styles on the Chart instance.
  240. *
  241. * @method setStyles
  242. * @param styles {Object} Initializer for all Chart styles.
  243. */
  244. setStyles: function(styles)
  245. {
  246. //we must jsonify this because Flash Player versions below 9.0.60 don't handle
  247. //complex ExternalInterface parsing correctly
  248. styles = YAHOO.lang.JSON.stringify(styles);
  249. this._swf.setStyles(styles);
  250. },
  251. /**
  252. * Sets the styles on all series in the Chart.
  253. *
  254. * @method setSeriesStyles
  255. * @param styles {Array} Initializer for all Chart series styles.
  256. */
  257. setSeriesStyles: function(styles)
  258. {
  259. //we must jsonify this because Flash Player versions below 9.0.60 don't handle
  260. //complex ExternalInterface parsing correctly
  261. for(var i = 0; i < styles.length; i++)
  262. {
  263. styles[i] = YAHOO.lang.JSON.stringify(styles[i]);
  264. }
  265. this._swf.setSeriesStyles(styles);
  266. },
  267. destroy: function()
  268. {
  269. //stop polling if needed
  270. if(this._dataSource !== null)
  271. {
  272. if(this._pollingID !== null)
  273. {
  274. this._dataSource.clearInterval(this._pollingID);
  275. this._pollingID = null;
  276. }
  277. }
  278. //remove proxy functions
  279. if(this._dataTipFunction)
  280. {
  281. YAHOO.widget.Chart.removeProxyFunction(this._dataTipFunction);
  282. }
  283. if(this._legendLabelFunction)
  284. {
  285. YAHOO.widget.Chart.removeProxyFunction(this._legendLabelFunction);
  286. }
  287. //kill the Flash Player instance
  288. if(this._swf)
  289. {
  290. var container = YAHOO.util.Dom.get(this._containerID);
  291. container.removeChild(this._swf);
  292. }
  293. var instanceName = this._id;
  294. //null out properties
  295. for(var prop in this)
  296. {
  297. if(YAHOO.lang.hasOwnProperty(this, prop))
  298. {
  299. this[prop] = null;
  300. }
  301. }
  302. },
  303. /**
  304. * Initializes the attributes.
  305. *
  306. * @method _initAttributes
  307. * @private
  308. */
  309. _initAttributes: function(attributes)
  310. {
  311. //YAHOO.widget.Chart.superclass._initAttributes.call(this, attributes);
  312. /**
  313. * @attribute wmode
  314. * @description Sets the window mode of the Flash Player control. May be
  315. * "window", "opaque", or "transparent". Only available in the constructor
  316. * because it may not be set after Flash Player has been embedded in the page.
  317. * @type String
  318. */
  319. /**
  320. * @attribute expressInstall
  321. * @description URL pointing to a SWF file that handles Flash Player's express
  322. * install feature. Only available in the constructor because it may not be
  323. * set after Flash Player has been embedded in the page.
  324. * @type String
  325. */
  326. /**
  327. * @attribute version
  328. * @description Minimum required version for the SWF file. Only available in the constructor because it may not be
  329. * set after Flash Player has been embedded in the page.
  330. * @type String
  331. */
  332. /**
  333. * @attribute backgroundColor
  334. * @description The background color of the SWF. Only available in the constructor because it may not be
  335. * set after Flash Player has been embedded in the page.
  336. * @type String
  337. */
  338. /**
  339. * @attribute altText
  340. * @description The alternative text to provide for screen readers and other assistive technology.
  341. * @type String
  342. */
  343. this.setAttributeConfig("altText",
  344. {
  345. method: this._setAltText,
  346. getter: this._getAltText
  347. });
  348. /**
  349. * @attribute swfURL
  350. * @description Absolute or relative URL to the SWF displayed by the Chart. Only available in the constructor because it may not be
  351. * set after Flash Player has been embedded in the page.
  352. * @type String
  353. */
  354. this.setAttributeConfig("swfURL",
  355. {
  356. getter: this._getSWFURL
  357. });
  358. /**
  359. * @attribute request
  360. * @description Request to be sent to the Chart's DataSource.
  361. * @type String
  362. */
  363. this.setAttributeConfig("request",
  364. {
  365. method: this._setRequest,
  366. getter: this._getRequest
  367. });
  368. /**
  369. * @attribute dataSource
  370. * @description The DataSource instance to display in the Chart.
  371. * @type DataSource
  372. */
  373. this.setAttributeConfig("dataSource",
  374. {
  375. method: this._setDataSource,
  376. getter: this._getDataSource
  377. });
  378. /**
  379. * @attribute series
  380. * @description Defines the series to be displayed by the Chart.
  381. * @type Array
  382. */
  383. this.setAttributeConfig("series",
  384. {
  385. method: this._setSeriesDefs,
  386. getter: this._getSeriesDefs
  387. });
  388. /**
  389. * @attribute categoryNames
  390. * @description Defines the names of the categories to be displayed in the Chart..
  391. * @type Array
  392. */
  393. this.setAttributeConfig("categoryNames",
  394. {
  395. validator: YAHOO.lang.isArray,
  396. method: this._setCategoryNames,
  397. getter: this._getCategoryNames
  398. });
  399. /**
  400. * @attribute dataTipFunction
  401. * @description The string representation of a globally-accessible function
  402. * that may be called by the SWF to generate the datatip text for a Chart's item.
  403. * @type String
  404. */
  405. this.setAttributeConfig("dataTipFunction",
  406. {
  407. method: this._setDataTipFunction,
  408. getter: this._getDataTipFunction
  409. });
  410. /**
  411. * @attribute legendLabelFunction
  412. * @description The string representation of a globally-accessible function
  413. * that may be called by the SWF to format the labels of a Chart's legend.
  414. * @type String
  415. */
  416. this.setAttributeConfig("legendLabelFunction",
  417. {
  418. method: this._setLegendLabelFunction,
  419. getter: this._legendLabelFunction
  420. });
  421. /**
  422. * @attribute polling
  423. * @description A numeric value indicating the number of milliseconds between
  424. * polling requests to the DataSource.
  425. * @type Number
  426. */
  427. this.setAttributeConfig("polling",
  428. {
  429. method: this._setPolling,
  430. getter: this._getPolling
  431. });
  432. },
  433. /**
  434. * Handles swfReady event from SWF.
  435. *
  436. * @method _eventHandler
  437. * @private
  438. */
  439. _eventHandler: function(event)
  440. {
  441. if(event.type == "swfReady")
  442. {
  443. this._swf = this._swfEmbed._swf;
  444. this._loadHandler();
  445. this.fireEvent("contentReady");
  446. }
  447. },
  448. /**
  449. * Called when the SWF is ready for communication. Sets the type, initializes
  450. * the styles, and sets the DataSource.
  451. *
  452. * @method _loadHandler
  453. * @private
  454. */
  455. _loadHandler: function()
  456. {
  457. //the type is set separately because it must be first!
  458. if(!this._swf || !this._swf.setType) return;
  459. this._swf.setType(this._type);
  460. //set initial styles
  461. if(this._attributes.style)
  462. {
  463. var style = this._attributes.style;
  464. this.setStyles(style);
  465. }
  466. this._initialized = false;
  467. this._initAttributes(this._attributes);
  468. this.setAttributes(this._attributes, true);
  469. this._initialized = true;
  470. if(this._dataSource)
  471. {
  472. this.set("dataSource", this._dataSource);
  473. }
  474. },
  475. /**
  476. * Sends (or resends) the request to the DataSource.
  477. *
  478. * @method refreshData
  479. */
  480. refreshData: function()
  481. {
  482. if(!this._initialized)
  483. {
  484. return;
  485. }
  486. if(this._dataSource !== null)
  487. {
  488. if(this._pollingID !== null)
  489. {
  490. this._dataSource.clearInterval(this._pollingID);
  491. this._pollingID = null;
  492. }
  493. if(this._pollingInterval > 0)
  494. {
  495. this._pollingID = this._dataSource.setInterval(this._pollingInterval, this._request, this._loadDataHandler, this);
  496. }
  497. this._dataSource.sendRequest(this._request, this._loadDataHandler, this);
  498. }
  499. },
  500. /**
  501. * Called when the DataSource receives new data. The series definitions are used
  502. * to build a data provider for the SWF chart.
  503. *
  504. * @method _loadDataHandler
  505. * @private
  506. */
  507. _loadDataHandler: function(request, response, error)
  508. {
  509. if(this._swf)
  510. {
  511. if(error)
  512. {
  513. }
  514. else
  515. {
  516. var i;
  517. if(this._seriesFunctions)
  518. {
  519. var count = this._seriesFunctions.length;
  520. for(i = 0; i < count; i++)
  521. {
  522. YAHOO.widget.Chart.removeProxyFunction(this._seriesFunctions[i]);
  523. }
  524. this._seriesFunctions = null;
  525. }
  526. this._seriesFunctions = [];
  527. //make a copy of the series definitions so that we aren't
  528. //editing them directly.
  529. var dataProvider = [];
  530. var seriesCount = 0;
  531. var currentSeries = null;
  532. if(this._seriesDefs !== null)
  533. {
  534. seriesCount = this._seriesDefs.length;
  535. for(i = 0; i < seriesCount; i++)
  536. {
  537. currentSeries = this._seriesDefs[i];
  538. var clonedSeries = {};
  539. for(var prop in currentSeries)
  540. {
  541. if(YAHOO.lang.hasOwnProperty(currentSeries, prop))
  542. {
  543. if(prop == "style")
  544. {
  545. if(currentSeries.style !== null)
  546. {
  547. clonedSeries.style = YAHOO.lang.JSON.stringify(currentSeries.style);
  548. }
  549. }
  550. else if(prop == "labelFunction")
  551. {
  552. if(currentSeries.labelFunction !== null)
  553. {
  554. clonedSeries.labelFunction = YAHOO.widget.Chart.getFunctionReference(currentSeries.labelFunction);
  555. this._seriesFunctions.push(clonedSeries.labelFunction);
  556. }
  557. }
  558. else if(prop == "dataTipFunction")
  559. {
  560. if(currentSeries.dataTipFunction !== null)
  561. {
  562. clonedSeries.dataTipFunction = YAHOO.widget.Chart.getFunctionReference(currentSeries.dataTipFunction);
  563. this._seriesFunctions.push(clonedSeries.dataTipFunction);
  564. }
  565. }
  566. else if(prop == "legendLabelFunction")
  567. {
  568. if(currentSeries.legendLabelFunction !== null)
  569. {
  570. clonedSeries.legendLabelFunction = YAHOO.widget.Chart.getFunctionReference(currentSeries.legendLabelFunction);
  571. this._seriesFunctions.push(clonedSeries.legendLabelFunction);
  572. }
  573. }
  574. else
  575. {
  576. clonedSeries[prop] = currentSeries[prop];
  577. }
  578. }
  579. }
  580. dataProvider.push(clonedSeries);
  581. }
  582. }
  583. if(seriesCount > 0)
  584. {
  585. for(i = 0; i < seriesCount; i++)
  586. {
  587. currentSeries = dataProvider[i];
  588. if(!currentSeries.type)
  589. {
  590. currentSeries.type = this._type;
  591. }
  592. currentSeries.dataProvider = response.results;
  593. }
  594. }
  595. else
  596. {
  597. var series = {type: this._type, dataProvider: response.results};
  598. dataProvider.push(series);
  599. }
  600. try
  601. {
  602. if(this._swf.setDataProvider) this._swf.setDataProvider(dataProvider);
  603. }
  604. catch(e)
  605. {
  606. this._swf.setDataProvider(dataProvider);
  607. }
  608. }
  609. }
  610. },
  611. /**
  612. * Storage for the request attribute.
  613. *
  614. * @property _request
  615. * @private
  616. */
  617. _request: "",
  618. /**
  619. * Getter for the request attribute.
  620. *
  621. * @method _getRequest
  622. * @private
  623. */
  624. _getRequest: function()
  625. {
  626. return this._request;
  627. },
  628. /**
  629. * Setter for the request attribute.
  630. *
  631. * @method _setRequest
  632. * @private
  633. */
  634. _setRequest: function(value)
  635. {
  636. this._request = value;
  637. this.refreshData();
  638. },
  639. /**
  640. * Storage for the dataSource attribute.
  641. *
  642. * @property _dataSource
  643. * @private
  644. */
  645. _dataSource: null,
  646. /**
  647. * Getter for the dataSource attribute.
  648. *
  649. * @method _getDataSource
  650. * @private
  651. */
  652. _getDataSource: function()
  653. {
  654. return this._dataSource;
  655. },
  656. /**
  657. * Setter for the dataSource attribute.
  658. *
  659. * @method _setDataSource
  660. * @private
  661. */
  662. _setDataSource: function(value)
  663. {
  664. this._dataSource = value;
  665. this.refreshData();
  666. },
  667. /**
  668. * Storage for the series attribute.
  669. *
  670. * @property _seriesDefs
  671. * @private
  672. */
  673. _seriesDefs: null,
  674. /**
  675. * Getter for the series attribute.
  676. *
  677. * @method _getSeriesDefs
  678. * @private
  679. */
  680. _getSeriesDefs: function()
  681. {
  682. return this._seriesDefs;
  683. },
  684. /**
  685. * Setter for the series attribute.
  686. *
  687. * @method _setSeriesDefs
  688. * @private
  689. */
  690. _setSeriesDefs: function(value)
  691. {
  692. this._seriesDefs = value;
  693. this.refreshData();
  694. },
  695. /**
  696. * Getter for the categoryNames attribute.
  697. *
  698. * @method _getCategoryNames
  699. * @private
  700. */
  701. _getCategoryNames: function()
  702. {
  703. return this._swf.getCategoryNames();
  704. },
  705. /**
  706. * Setter for the categoryNames attribute.
  707. *
  708. * @method _setCategoryNames
  709. * @private
  710. */
  711. _setCategoryNames: function(value)
  712. {
  713. this._swf.setCategoryNames(value);
  714. },
  715. /**
  716. * Setter for the dataTipFunction attribute.
  717. *
  718. * @method _setDataTipFunction
  719. * @private
  720. */
  721. _setDataTipFunction: function(value)
  722. {
  723. if(this._dataTipFunction)
  724. {
  725. YAHOO.widget.Chart.removeProxyFunction(this._dataTipFunction);
  726. }
  727. if(value)
  728. {
  729. this._dataTipFunction = value = YAHOO.widget.Chart.getFunctionReference(value);
  730. }
  731. this._swf.setDataTipFunction(value);
  732. },
  733. /**
  734. * Setter for the legendLabelFunction attribute.
  735. *
  736. * @method _setLegendLabelFunction
  737. * @private
  738. */
  739. _setLegendLabelFunction: function(value)
  740. {
  741. if(this._legendLabelFunction)
  742. {
  743. YAHOO.widget.Chart.removeProxyFunction(this._legendLabelFunction);
  744. }
  745. if(value)
  746. {
  747. this._legendLabelFunction = value = YAHOO.widget.Chart.getFunctionReference(value);
  748. }
  749. this._swf.setLegendLabelFunction(value);
  750. },
  751. /**
  752. * Getter for the polling attribute.
  753. *
  754. * @method _getPolling
  755. * @private
  756. */
  757. _getPolling: function()
  758. {
  759. return this._pollingInterval;
  760. },
  761. /**
  762. * Setter for the polling attribute.
  763. *
  764. * @method _setPolling
  765. * @private
  766. */
  767. _setPolling: function(value)
  768. {
  769. this._pollingInterval = value;
  770. this.refreshData();
  771. },
  772. /**
  773. * The javascript wrapper for the swf object
  774. *
  775. * @property _swfEmbed
  776. * @type swf
  777. * @private
  778. */
  779. _swfEmbed: null,
  780. /**
  781. * The URL of the SWF file.
  782. * @property _swfURL
  783. * @type String
  784. * @private
  785. */
  786. _swfURL: null,
  787. /**
  788. * The ID of the containing DIV.
  789. * @property _containerID
  790. * @type String
  791. * @private
  792. */
  793. _containerID: null,
  794. /**
  795. * A reference to the embedded SWF file.
  796. * @property _swf
  797. * @private
  798. */
  799. _swf: null,
  800. /**
  801. * The id of this instance.
  802. * @property _id
  803. * @type String
  804. * @private
  805. */
  806. _id: null,
  807. /**
  808. * Indicates whether the SWF has been initialized and is ready
  809. * to communicate with JavaScript
  810. * @property _initialized
  811. * @type Boolean
  812. * @private
  813. */
  814. _initialized: false,
  815. /**
  816. * The initializing attributes are stored here until the SWF is ready.
  817. * @property _attributes
  818. * @type Object
  819. * @private
  820. */
  821. _attributes: null, //the intializing attributes
  822. set: function(name, value)
  823. {
  824. //save all the attributes in case the swf reloads
  825. //so that we can pass them in again
  826. this._attributes[name] = value;
  827. YAHOO.widget.Chart.superclass.set.call(this, name, value);
  828. },
  829. /**
  830. * Getter for swfURL attribute.
  831. *
  832. * @method _getSWFURL
  833. * @private
  834. */
  835. _getSWFURL: function()
  836. {
  837. return this._swfURL;
  838. },
  839. /**
  840. * Getter for altText attribute.
  841. *
  842. * @method _getAltText
  843. * @private
  844. */
  845. _getAltText: function()
  846. {
  847. return this._swf.getAltText();
  848. },
  849. /**
  850. * Setter for altText attribute.
  851. *
  852. * @method _setAltText
  853. * @private
  854. */
  855. _setAltText: function(value)
  856. {
  857. this._swf.setAltText(value);
  858. }
  859. });
  860. /**
  861. * The number of proxy functions that have been created.
  862. * @static
  863. * @private
  864. */
  865. YAHOO.widget.Chart.proxyFunctionCount = 0;
  866. /**
  867. * Creates a globally accessible function that wraps a function reference.
  868. * Returns the proxy function's name as a string for use by the SWF through
  869. * ExternalInterface.
  870. *
  871. * @method YAHOO.widget.Chart.createProxyFunction
  872. * @static
  873. * @private
  874. */
  875. YAHOO.widget.Chart.createProxyFunction = function(func, scope)
  876. {
  877. var scope = scope || null;
  878. var index = YAHOO.widget.Chart.proxyFunctionCount;
  879. YAHOO.widget.Chart["proxyFunction" + index] = function()
  880. {
  881. return func.apply(scope, arguments);
  882. };
  883. YAHOO.widget.Chart.proxyFunctionCount++;
  884. return "YAHOO.widget.Chart.proxyFunction" + index.toString();
  885. };
  886. /**
  887. * Uses YAHOO.widget.Chart.createProxyFunction to return string
  888. * reference to a function.
  889. *
  890. * @method YAHOO.widget.Chart.getFunctionReference
  891. * @static
  892. * @private
  893. */
  894. YAHOO.widget.Chart.getFunctionReference = function(value)
  895. {
  896. if(typeof value == "function")
  897. {
  898. value = YAHOO.widget.Chart.createProxyFunction(value);
  899. }
  900. else if(value.func && typeof value.func == "function")
  901. {
  902. var args = [value.func];
  903. if(value.scope && typeof value.scope == "object")
  904. {
  905. args.push(value.scope);
  906. }
  907. value = YAHOO.widget.Chart.createProxyFunction.apply(this, args);
  908. }
  909. return value;
  910. }
  911. /**
  912. * Removes a function created with createProxyFunction()
  913. *
  914. * @method YAHOO.widget.Chart.removeProxyFunction
  915. * @static
  916. * @private
  917. */
  918. YAHOO.widget.Chart.removeProxyFunction = function(funcName)
  919. {
  920. //quick error check
  921. if(!funcName || funcName.indexOf("YAHOO.widget.Chart.proxyFunction") < 0)
  922. {
  923. return;
  924. }
  925. funcName = funcName.substr(26);
  926. YAHOO.widget.Chart[funcName] = null;
  927. };
  928. /**
  929. * Storage for the dataTipFunction attribute.
  930. *
  931. * @property Chart.SWFURL
  932. * @private
  933. * @static
  934. * @final
  935. * @default "assets/charts.swf"
  936. */
  937. YAHOO.widget.Chart.SWFURL = "assets/charts.swf";
  938. /**
  939. * PieChart class for the YUI Charts widget.
  940. *
  941. * @namespace YAHOO.widget
  942. * @class PieChart
  943. * @uses YAHOO.widget.Chart
  944. * @constructor
  945. * @param containerId {HTMLElement} Container element for the Flash Player instance.
  946. * @param dataSource {YAHOO.util.DataSource} DataSource instance.
  947. * @param attributes {object} (optional) Object literal of configuration values.
  948. */
  949. YAHOO.widget.PieChart = function(containerId, dataSource, attributes)
  950. {
  951. YAHOO.widget.PieChart.superclass.constructor.call(this, "pie", containerId, dataSource, attributes);
  952. };
  953. YAHOO.lang.extend(YAHOO.widget.PieChart, YAHOO.widget.Chart,
  954. {
  955. /**
  956. * Initializes the attributes.
  957. *
  958. * @method _initAttributes
  959. * @private
  960. */
  961. _initAttributes: function(attributes)
  962. {
  963. YAHOO.widget.PieChart.superclass._initAttributes.call(this, attributes);
  964. /**
  965. * @attribute dataField
  966. * @description The field in each item that corresponds to the data value.
  967. * @type String
  968. */
  969. this.setAttributeConfig("dataField",
  970. {
  971. validator: YAHOO.lang.isString,
  972. method: this._setDataField,
  973. getter: this._getDataField
  974. });
  975. /**
  976. * @attribute categoryField
  977. * @description The field in each item that corresponds to the category value.
  978. * @type String
  979. */
  980. this.setAttributeConfig("categoryField",
  981. {
  982. validator: YAHOO.lang.isString,
  983. method: this._setCategoryField,
  984. getter: this._getCategoryField
  985. });
  986. },
  987. /**
  988. * Getter for the dataField attribute.
  989. *
  990. * @method _getDataField
  991. * @private
  992. */
  993. _getDataField: function()
  994. {
  995. return this._swf.getDataField();
  996. },
  997. /**
  998. * Setter for the dataField attribute.
  999. *
  1000. * @method _setDataField
  1001. * @private
  1002. */
  1003. _setDataField: function(value)
  1004. {
  1005. this._swf.setDataField(value);
  1006. },
  1007. /**
  1008. * Getter for the categoryField attribute.
  1009. *
  1010. * @method _getCategoryField
  1011. * @private
  1012. */
  1013. _getCategoryField: function()
  1014. {
  1015. return this._swf.getCategoryField();
  1016. },
  1017. /**
  1018. * Setter for the categoryField attribute.
  1019. *
  1020. * @method _setCategoryField
  1021. * @private
  1022. */
  1023. _setCategoryField: function(value)
  1024. {
  1025. this._swf.setCategoryField(value);
  1026. }
  1027. });
  1028. /**
  1029. * CartesianChart class for the YUI Charts widget.
  1030. *
  1031. * @namespace YAHOO.widget
  1032. * @class CartesianChart
  1033. * @uses YAHOO.widget.Chart
  1034. * @constructor
  1035. * @param type {String} The char type. May be "line", "column", or "bar"
  1036. * @param containerId {HTMLElement} Container element for the Flash Player instance.
  1037. * @param dataSource {YAHOO.util.DataSource} DataSource instance.
  1038. * @param attributes {object} (optional) Object literal of configuration values.
  1039. */
  1040. YAHOO.widget.CartesianChart = function(type, containerId, dataSource, attributes)
  1041. {
  1042. YAHOO.widget.CartesianChart.superclass.constructor.call(this, type, containerId, dataSource, attributes);
  1043. };
  1044. YAHOO.lang.extend(YAHOO.widget.CartesianChart, YAHOO.widget.Chart,
  1045. {
  1046. /**
  1047. * Stores a reference to the xAxis labelFunction created by
  1048. * YAHOO.widget.Chart.createProxyFunction()
  1049. * @property _xAxisLabelFunctions
  1050. * @type String
  1051. * @private
  1052. */
  1053. _xAxisLabelFunctions: [],
  1054. /**
  1055. * Stores a reference to the yAxis labelFunctions created by
  1056. * YAHOO.widget.Chart.createProxyFunction()
  1057. * @property _yAxisLabelFunctions
  1058. * @type Array
  1059. * @private
  1060. */
  1061. _yAxisLabelFunctions: [],
  1062. destroy: function()
  1063. {
  1064. //remove proxy functions
  1065. this._removeAxisFunctions(this._xAxisLabelFunctions);
  1066. this._removeAxisFunctions(this._yAxisLabelFunctions);
  1067. //call last
  1068. YAHOO.widget.CartesianChart.superclass.destroy.call(this);
  1069. },
  1070. /**
  1071. * Initializes the attributes.
  1072. *
  1073. * @method _initAttributes
  1074. * @private
  1075. */
  1076. _initAttributes: function(attributes)
  1077. {
  1078. YAHOO.widget.CartesianChart.superclass._initAttributes.call(this, attributes);
  1079. /**
  1080. * @attribute xField
  1081. * @description The field in each item that corresponds to a value on the x axis.
  1082. * @type String
  1083. */
  1084. this.setAttributeConfig("xField",
  1085. {
  1086. validator: YAHOO.lang.isString,
  1087. method: this._setXField,
  1088. getter: this._getXField
  1089. });
  1090. /**
  1091. * @attribute yField
  1092. * @description The field in each item that corresponds to a value on the x axis.
  1093. * @type String
  1094. */
  1095. this.setAttributeConfig("yField",
  1096. {
  1097. validator: YAHOO.lang.isString,
  1098. method: this._setYField,
  1099. getter: this._getYField
  1100. });
  1101. /**
  1102. * @attribute xAxis
  1103. * @description A custom configuration for the horizontal x axis.
  1104. * @type Axis
  1105. */
  1106. this.setAttributeConfig("xAxis",
  1107. {
  1108. method: this._setXAxis
  1109. });
  1110. /**
  1111. * @attribute xAxes
  1112. * @description Custom configurations for the horizontal x axes.
  1113. * @type Array
  1114. */
  1115. this.setAttributeConfig("xAxes",
  1116. {
  1117. method: this._setXAxes
  1118. });
  1119. /**
  1120. * @attribute yAxis
  1121. * @description A custom configuration for the vertical y axis.
  1122. * @type Axis
  1123. */
  1124. this.setAttributeConfig("yAxis",
  1125. {
  1126. method: this._setYAxis
  1127. });
  1128. /**
  1129. * @attribute yAxes
  1130. * @description Custom configurations for the vertical y axes.
  1131. * @type Array
  1132. */
  1133. this.setAttributeConfig("yAxes",
  1134. {
  1135. method: this._setYAxes
  1136. });
  1137. /**
  1138. * @attribute constrainViewport
  1139. * @description Determines whether the viewport is constrained to prevent series data from overflow.
  1140. * @type Boolean
  1141. */
  1142. this.setAttributeConfig("constrainViewport",
  1143. {
  1144. method: this._setConstrainViewport
  1145. });
  1146. },
  1147. /**
  1148. * Getter for the xField attribute.
  1149. *
  1150. * @method _getXField
  1151. * @private
  1152. */
  1153. _getXField: function()
  1154. {
  1155. return this._swf.getHorizontalField();
  1156. },
  1157. /**
  1158. * Setter for the xField attribute.
  1159. *
  1160. * @method _setXField
  1161. * @private
  1162. */
  1163. _setXField: function(value)
  1164. {
  1165. this._swf.setHorizontalField(value);
  1166. },
  1167. /**
  1168. * Getter for the yField attribute.
  1169. *
  1170. * @method _getYField
  1171. * @private
  1172. */
  1173. _getYField: function()
  1174. {
  1175. return this._swf.getVerticalField();
  1176. },
  1177. /**
  1178. * Setter for the yField attribute.
  1179. *
  1180. * @method _setYField
  1181. * @private
  1182. */
  1183. _setYField: function(value)
  1184. {
  1185. this._swf.setVerticalField(value);
  1186. },
  1187. /**
  1188. * Receives an axis object, creates a proxy function for
  1189. * the labelFunction and returns the updated object.
  1190. *
  1191. * @method _getClonedAxis
  1192. * @private
  1193. */
  1194. _getClonedAxis: function(value)
  1195. {
  1196. var clonedAxis = {};
  1197. for(var prop in value)
  1198. {
  1199. if(prop == "labelFunction")
  1200. {
  1201. if(value.labelFunction && value.labelFunction !== null)
  1202. {
  1203. clonedAxis.labelFunction = YAHOO.widget.Chart.getFunctionReference(value.labelFunction);
  1204. }
  1205. }
  1206. else
  1207. {
  1208. clonedAxis[prop] = value[prop];
  1209. }
  1210. }
  1211. return clonedAxis;
  1212. },
  1213. /**
  1214. * Removes axis functions contained in an array
  1215. *
  1216. * @method _removeAxisFunctions
  1217. * @private
  1218. */
  1219. _removeAxisFunctions: function(axisFunctions)
  1220. {
  1221. if(axisFunctions && axisFunctions.length > 0)
  1222. {
  1223. var len = axisFunctions.length;
  1224. for(var i = 0; i < len; i++)
  1225. {
  1226. if(axisFunctions[i] !== null)
  1227. {
  1228. YAHOO.widget.Chart.removeProxyFunction(axisFunctions[i]);
  1229. }
  1230. }
  1231. axisFunctions = [];
  1232. }
  1233. },
  1234. /**
  1235. * Setter for the xAxis attribute.
  1236. *
  1237. * @method _setXAxis
  1238. * @private
  1239. */
  1240. _setXAxis: function(value)
  1241. {
  1242. if(value.position != "bottom" && value.position != "top") value.position = "bottom";
  1243. this._removeAxisFunctions(this._xAxisLabelFunctions);
  1244. value = this._getClonedAxis(value);
  1245. this._xAxisLabelFunctions.push(value.labelFunction);
  1246. this._swf.setHorizontalAxis(value);
  1247. },
  1248. /**
  1249. * Setter for the xAxes attribute
  1250. *
  1251. * @method _setXAxes
  1252. * @private
  1253. */
  1254. _setXAxes: function(value)
  1255. {
  1256. this._removeAxisFunctions(this._xAxisLabelFunctions);
  1257. var len = value.length;
  1258. for(var i = 0; i < len; i++)
  1259. {
  1260. if(value[i].position == "left") value[i].position = "bottom";
  1261. value[i] = this._getClonedAxis(value[i]);
  1262. if(value[i].labelFunction) this._xAxisLabelFunctions.push(value[i].labelFunction);
  1263. this._swf.setHorizontalAxis(value[i]);
  1264. }
  1265. },
  1266. /**
  1267. * Setter for the yAxis attribute.
  1268. *
  1269. * @method _setYAxis
  1270. * @private
  1271. */
  1272. _setYAxis: function(value)
  1273. {
  1274. this._removeAxisFunctions(this._yAxisLabelFunctions);
  1275. value = this._getClonedAxis(value);
  1276. this._yAxisLabelFunctions.push(value.labelFunction);
  1277. this._swf.setVerticalAxis(value);
  1278. },
  1279. /**
  1280. * Setter for the yAxes attribute.
  1281. *
  1282. * @method _setYAxes
  1283. * @private
  1284. */
  1285. _setYAxes: function(value)
  1286. {
  1287. this._removeAxisFunctions(this._yAxisLabelFunctions);
  1288. var len = value.length;
  1289. for(var i = 0; i < len; i++)
  1290. {
  1291. value[i] = this._getClonedAxis(value[i]);
  1292. if(value[i].labelFunction) this._yAxisLabelFunctions.push(value[i].labelFunction);
  1293. this._swf.setVerticalAxis(value[i]);
  1294. }
  1295. },
  1296. /**
  1297. * Setter for the constrainViewport attribute
  1298. *
  1299. * @method _setConstrainViewport
  1300. * @private
  1301. */
  1302. _setConstrainViewport: function(value)
  1303. {
  1304. this._swf.setConstrainViewport(value);
  1305. },
  1306. /**
  1307. * Sets the style object for a single series based on its index
  1308. *
  1309. * @method setSeriesStylesByIndex
  1310. * @param index {Number} The position within the series definition to apply the style
  1311. * @param style {object} Style object to be applied to the selected series
  1312. */
  1313. setSeriesStylesByIndex:function(index, style)
  1314. {
  1315. style = YAHOO.lang.JSON.stringify(style);
  1316. if(this._swf && this._swf.setSeriesStylesByIndex) this._swf.setSeriesStylesByIndex(index, style);
  1317. }
  1318. });
  1319. /**
  1320. * LineChart class for the YUI Charts widget.
  1321. *
  1322. * @namespace YAHOO.widget
  1323. * @class LineChart
  1324. * @uses YAHOO.widget.CartesianChart
  1325. * @constructor
  1326. * @param containerId {HTMLElement} Container element for the Flash Player instance.
  1327. * @param dataSource {YAHOO.util.DataSource} DataSource instance.
  1328. * @param attributes {object} (optional) Object literal of configuration values.
  1329. */
  1330. YAHOO.widget.LineChart = function(containerId, dataSource, attributes)
  1331. {
  1332. YAHOO.widget.LineChart.superclass.constructor.call(this, "line", containerId, dataSource, attributes);
  1333. };
  1334. YAHOO.lang.extend(YAHOO.widget.LineChart, YAHOO.widget.CartesianChart);
  1335. /**
  1336. * ColumnChart class for the YUI Charts widget.
  1337. *
  1338. * @namespace YAHOO.widget
  1339. * @class ColumnChart
  1340. * @uses YAHOO.widget.CartesianChart
  1341. * @constructor
  1342. * @param containerId {HTMLElement} Container element for the Flash Player instance.
  1343. * @param dataSource {YAHOO.util.DataSource} DataSource instance.
  1344. * @param attributes {object} (optional) Object literal of configuration values.
  1345. */
  1346. YAHOO.widget.ColumnChart = function(containerId, dataSource, attributes)
  1347. {
  1348. YAHOO.widget.ColumnChart.superclass.constructor.call(this, "column", containerId, dataSource, attributes);
  1349. };
  1350. YAHOO.lang.extend(YAHOO.widget.ColumnChart, YAHOO.widget.CartesianChart);
  1351. /**
  1352. * BarChart class for the YUI Charts widget.
  1353. *
  1354. * @namespace YAHOO.widget
  1355. * @class BarChart
  1356. * @uses YAHOO.widget.CartesianChart
  1357. * @constructor
  1358. * @param containerId {HTMLElement} Container element for the Flash Player instance.
  1359. * @param dataSource {YAHOO.util.DataSource} DataSource instance.
  1360. * @param attributes {object} (optional) Object literal of configuration values.
  1361. */
  1362. YAHOO.widget.BarChart = function(containerId, dataSource, attributes)
  1363. {
  1364. YAHOO.widget.BarChart.superclass.constructor.call(this, "bar", containerId, dataSource, attributes);
  1365. };
  1366. YAHOO.lang.extend(YAHOO.widget.BarChart, YAHOO.widget.CartesianChart);
  1367. /**
  1368. * StackedColumnChart class for the YUI Charts widget.
  1369. *
  1370. * @namespace YAHOO.widget
  1371. * @class StackedColumnChart
  1372. * @uses YAHOO.widget.CartesianChart
  1373. * @constructor
  1374. * @param containerId {HTMLElement} Container element for the Flash Player instance.
  1375. * @param dataSource {YAHOO.util.DataSource} DataSource instance.
  1376. * @param attributes {object} (optional) Object literal of configuration values.
  1377. */
  1378. YAHOO.widget.StackedColumnChart = function(containerId, dataSource, attributes)
  1379. {
  1380. YAHOO.widget.StackedColumnChart.superclass.constructor.call(this, "stackcolumn", containerId, dataSource, attributes);
  1381. };
  1382. YAHOO.lang.extend(YAHOO.widget.StackedColumnChart, YAHOO.widget.CartesianChart);
  1383. /**
  1384. * StackedBarChart class for the YUI Charts widget.
  1385. *
  1386. * @namespace YAHOO.widget
  1387. * @class StackedBarChart
  1388. * @uses YAHOO.widget.CartesianChart
  1389. * @constructor
  1390. * @param containerId {HTMLElement} Container element for the Flash Player instance.
  1391. * @param dataSource {YAHOO.util.DataSource} DataSource instance.
  1392. * @param attributes {object} (optional) Object literal of configuration values.
  1393. */
  1394. YAHOO.widget.StackedBarChart = function(containerId, dataSource, attributes)
  1395. {
  1396. YAHOO.widget.StackedBarChart.superclass.constructor.call(this, "stackbar", containerId, dataSource, attributes);
  1397. };
  1398. YAHOO.lang.extend(YAHOO.widget.StackedBarChart, YAHOO.widget.CartesianChart);
  1399. /**
  1400. * Defines a CartesianChart's vertical or horizontal axis.
  1401. *
  1402. * @namespace YAHOO.widget
  1403. * @class Axis
  1404. * @constructor
  1405. */
  1406. YAHOO.widget.Axis = function()
  1407. {
  1408. };
  1409. YAHOO.widget.Axis.prototype =
  1410. {
  1411. /**
  1412. * The type of axis.
  1413. *
  1414. * @property type
  1415. * @type String
  1416. */
  1417. type: null,
  1418. /**
  1419. * If true, the items on the axis will be drawn in opposite direction.
  1420. *
  1421. * @property reverse
  1422. * @type Boolean
  1423. */
  1424. reverse: false,
  1425. /**
  1426. * A string reference to the globally-accessible function that may be called to
  1427. * determine each of the label values for this axis. Also accepts function references.
  1428. *
  1429. * @property labelFunction
  1430. * @type String
  1431. */
  1432. labelFunction: null,
  1433. /**
  1434. * The space, in pixels, between labels on an axis.
  1435. *
  1436. * @property labelSpacing
  1437. * @type Number
  1438. */
  1439. labelSpacing: 2,
  1440. /**
  1441. * The text that will appear next to the axis to indicate information about the data that it displays.
  1442. *
  1443. * @property title
  1444. * @type String
  1445. */
  1446. title: null
  1447. };
  1448. /**
  1449. * A type of axis whose units are measured in numeric values.
  1450. *
  1451. * @namespace YAHOO.widget
  1452. * @class NumericAxis
  1453. * @extends YAHOO.widget.Axis
  1454. * @constructor
  1455. */
  1456. YAHOO.widget.NumericAxis = function()
  1457. {
  1458. YAHOO.widget.NumericAxis.superclass.constructor.call(this);
  1459. };
  1460. YAHOO.lang.extend(YAHOO.widget.NumericAxis, YAHOO.widget.Axis,
  1461. {
  1462. type: "numeric",
  1463. /**
  1464. * The minimum value drawn by the axis. If not set explicitly, the axis minimum
  1465. * will be calculated automatically.
  1466. *
  1467. * @property minimum
  1468. * @type Number
  1469. */
  1470. minimum: NaN,
  1471. /**
  1472. * The maximum value drawn by the axis. If not set explicitly, the axis maximum
  1473. * will be calculated automatically.
  1474. *
  1475. * @property maximum
  1476. * @type Number
  1477. */
  1478. maximum: NaN,
  1479. /**
  1480. * The spacing between major intervals on this axis.
  1481. *
  1482. * @property majorUnit
  1483. * @type Number
  1484. */
  1485. majorUnit: NaN,
  1486. /**
  1487. * The spacing between minor intervals on this axis.
  1488. *
  1489. * @property minorUnit
  1490. * @type Number
  1491. */
  1492. minorUnit: NaN,
  1493. /**
  1494. * If true, the labels, ticks, gridlines, and other objects will snap to
  1495. * the nearest major or minor unit. If false, their position will be based
  1496. * on the minimum value.
  1497. *
  1498. * @property snapToUnits
  1499. * @type Boolean
  1500. */
  1501. snapToUnits: true,
  1502. /**
  1503. * Series that are stackable will only stack when this value is set to true.
  1504. *
  1505. * @property stackingEnabled
  1506. * @type Boolean
  1507. */
  1508. stackingEnabled: false,
  1509. /**
  1510. * If true, and the bounds are calculated automatically, either the minimum or
  1511. * maximum will be set to zero.
  1512. *
  1513. * @property alwaysShowZero
  1514. * @type Boolean
  1515. */
  1516. alwaysShowZero: true,
  1517. /**
  1518. * The scaling algorithm to use on this axis. May be "linear" or "logarithmic".
  1519. *
  1520. * @property scale
  1521. * @type String
  1522. */
  1523. scale: "linear",
  1524. /**
  1525. * Indicates whether to round the major unit.
  1526. *
  1527. * @property roundMajorUnit
  1528. * @type Boolean
  1529. */
  1530. roundMajorUnit: true,
  1531. /**
  1532. * Indicates whether to factor in the size of the labels when calculating a major unit.
  1533. *
  1534. * @property calculateByLabelSize
  1535. * @type Boolean
  1536. */
  1537. calculateByLabelSize: true,
  1538. /**
  1539. * Indicates the position of the axis relative to the chart
  1540. *
  1541. * @property position
  1542. * @type String
  1543. */
  1544. position:"left",
  1545. /**
  1546. * Indicates whether to extend maximum beyond data's maximum to the nearest
  1547. * majorUnit.
  1548. *
  1549. * @property adjustMaximumByMajorUnit
  1550. * @type Boolean
  1551. */
  1552. adjustMaximumByMajorUnit:true,
  1553. /**
  1554. * Indicates whether to extend the minimum beyond data's minimum to the nearest
  1555. * majorUnit.
  1556. *
  1557. * @property adjustMinimumByMajorUnit
  1558. * @type Boolean
  1559. */
  1560. adjustMinimumByMajorUnit:true
  1561. });
  1562. /**
  1563. * A type of axis whose units are measured in time-based values.
  1564. *
  1565. * @namespace YAHOO.widget
  1566. * @class TimeAxis
  1567. * @constructor
  1568. */
  1569. YAHOO.widget.TimeAxis = function()
  1570. {
  1571. YAHOO.widget.TimeAxis.superclass.constructor.call(this);
  1572. };
  1573. YAHOO.lang.extend(YAHOO.widget.TimeAxis, YAHOO.widget.Axis,
  1574. {
  1575. type: "time",
  1576. /**
  1577. * The minimum value drawn by the axis. If not set explicitly, the axis minimum
  1578. * will be calculated automatically.
  1579. *
  1580. * @property minimum
  1581. * @type Date
  1582. */
  1583. minimum: null,
  1584. /**
  1585. * The maximum value drawn by the axis. If not set explicitly, the axis maximum
  1586. * will be calculated automatically.
  1587. *
  1588. * @property maximum
  1589. * @type Number
  1590. */
  1591. maximum: null,
  1592. /**
  1593. * The spacing between major intervals on this axis.
  1594. *
  1595. * @property majorUnit
  1596. * @type Number
  1597. */
  1598. majorUnit: NaN,
  1599. /**
  1600. * The time unit used by the majorUnit.
  1601. *
  1602. * @property majorTimeUnit
  1603. * @type String
  1604. */
  1605. majorTimeUnit: null,
  1606. /**
  1607. * The spacing between minor intervals on this axis.
  1608. *
  1609. * @property majorUnit
  1610. * @type Number
  1611. */
  1612. minorUnit: NaN,
  1613. /**
  1614. * The time unit used by the minorUnit.
  1615. *
  1616. * @property majorTimeUnit
  1617. * @type String
  1618. */
  1619. minorTimeUnit: null,
  1620. /**
  1621. * If true, the labels, ticks, gridlines, and other objects will snap to
  1622. * the nearest major or minor unit. If false, their position will be based
  1623. * on the minimum value.
  1624. *
  1625. * @property snapToUnits
  1626. * @type Boolean
  1627. */
  1628. snapToUnits: true,
  1629. /**
  1630. * Series that are stackable will only stack when this value is set to true.
  1631. *
  1632. * @property stackingEnabled
  1633. * @type Boolean
  1634. */
  1635. stackingEnabled: false,
  1636. /**
  1637. * Indicates whether to factor in the size of the labels when calculating a major unit.
  1638. *
  1639. * @property calculateByLabelSize
  1640. * @type Boolean
  1641. */
  1642. calculateByLabelSize: true
  1643. });
  1644. /**
  1645. * A type of axis that displays items in categories.
  1646. *
  1647. * @namespace YAHOO.widget
  1648. * @class CategoryAxis
  1649. * @constructor
  1650. */
  1651. YAHOO.widget.CategoryAxis = function()
  1652. {
  1653. YAHOO.widget.CategoryAxis.superclass.constructor.call(this);
  1654. };
  1655. YAHOO.lang.extend(YAHOO.widget.CategoryAxis, YAHOO.widget.Axis,
  1656. {
  1657. type: "category",
  1658. /**
  1659. * A list of category names to display along this axis.
  1660. *
  1661. * @property categoryNames
  1662. * @type Array
  1663. */
  1664. categoryNames: null,
  1665. /**
  1666. * Indicates whether or not to calculate the number of categories (ticks and labels)
  1667. * when there is not enough room to display all labels on the axis. If set to true, the axis
  1668. * will determine the number of categories to plot. If not, all categories will be plotted.
  1669. *
  1670. * @property calculateCategoryCount
  1671. * @type Boolean
  1672. */
  1673. calculateCategoryCount: false
  1674. });
  1675. /**
  1676. * Functionality common to most series. Generally, a <code>Series</code>
  1677. * object shouldn't be instantiated directly. Instead, a subclass with a
  1678. * concrete implementation should be used.
  1679. *
  1680. * @namespace YAHOO.widget
  1681. * @class Series
  1682. * @constructor
  1683. */
  1684. YAHOO.widget.Series = function() {};
  1685. YAHOO.widget.Series.prototype =
  1686. {
  1687. /**
  1688. * The type of series.
  1689. *
  1690. * @property type
  1691. * @type String
  1692. */
  1693. type: null,
  1694. /**
  1695. * The human-readable name of the series.
  1696. *
  1697. * @property displayName
  1698. * @type String
  1699. */
  1700. displayName: null
  1701. };
  1702. /**
  1703. * Functionality common to most series appearing in cartesian charts.
  1704. * Generally, a <code>CartesianSeries</code> object shouldn't be
  1705. * instantiated directly. Instead, a subclass with a concrete implementation
  1706. * should be used.
  1707. *
  1708. * @namespace YAHOO.widget
  1709. * @class CartesianSeries
  1710. * @uses YAHOO.widget.Series
  1711. * @constructor
  1712. */
  1713. YAHOO.widget.CartesianSeries = function()
  1714. {
  1715. YAHOO.widget.CartesianSeries.superclass.constructor.call(this);
  1716. };
  1717. YAHOO.lang.extend(YAHOO.widget.CartesianSeries, YAHOO.widget.Series,
  1718. {
  1719. /**
  1720. * The field used to access the x-axis value from the items from the data source.
  1721. *
  1722. * @property xField
  1723. * @type String
  1724. */
  1725. xField: null,
  1726. /**
  1727. * The field used to access the y-axis value from the items from the data source.
  1728. *
  1729. * @property yField
  1730. * @type String
  1731. */
  1732. yField: null,
  1733. /**
  1734. * Indicates which axis the series will bind to
  1735. *
  1736. * @property axis
  1737. * @type String
  1738. */
  1739. axis: "primary",
  1740. /**
  1741. * When a Legend is present, indicates whether the series will show in the legend.
  1742. *
  1743. * @property showInLegend
  1744. * @type Boolean
  1745. */
  1746. showInLegend: true
  1747. });
  1748. /**
  1749. * ColumnSeries class for the YUI Charts widget.
  1750. *
  1751. * @namespace YAHOO.widget
  1752. * @class ColumnSeries
  1753. * @uses YAHOO.widget.CartesianSeries
  1754. * @constructor
  1755. */
  1756. YAHOO.widget.ColumnSeries = function()
  1757. {
  1758. YAHOO.widget.ColumnSeries.superclass.constructor.call(this);
  1759. };
  1760. YAHOO.lang.extend(YAHOO.widget.ColumnSeries, YAHOO.widget.CartesianSeries,
  1761. {
  1762. type: "column"
  1763. });
  1764. /**
  1765. * LineSeries class for the YUI Charts widget.
  1766. *
  1767. * @namespace YAHOO.widget
  1768. * @class LineSeries
  1769. * @uses YAHOO.widget.CartesianSeries
  1770. * @constructor
  1771. */
  1772. YAHOO.widget.LineSeries = function()
  1773. {
  1774. YAHOO.widget.LineSeries.superclass.constructor.call(this);
  1775. };
  1776. YAHOO.lang.extend(YAHOO.widget.LineSeries, YAHOO.widget.CartesianSeries,
  1777. {
  1778. type: "line"
  1779. });
  1780. /**
  1781. * BarSeries class for the YUI Charts widget.
  1782. *
  1783. * @namespace YAHOO.widget
  1784. * @class BarSeries
  1785. * @uses YAHOO.widget.CartesianSeries
  1786. * @constructor
  1787. */
  1788. YAHOO.widget.BarSeries = function()
  1789. {
  1790. YAHOO.widget.BarSeries.superclass.constructor.call(this);
  1791. };
  1792. YAHOO.lang.extend(YAHOO.widget.BarSeries, YAHOO.widget.CartesianSeries,
  1793. {
  1794. type: "bar"
  1795. });
  1796. /**
  1797. * PieSeries class for the YUI Charts widget.
  1798. *
  1799. * @namespace YAHOO.widget
  1800. * @class PieSeries
  1801. * @uses YAHOO.widget.Series
  1802. * @constructor
  1803. */
  1804. YAHOO.widget.PieSeries = function()
  1805. {
  1806. YAHOO.widget.PieSeries.superclass.constructor.call(this);
  1807. };
  1808. YAHOO.lang.extend(YAHOO.widget.PieSeries, YAHOO.widget.Series,
  1809. {
  1810. type: "pie",
  1811. /**
  1812. * The field used to access the data value from the items from the data source.
  1813. *
  1814. * @property dataField
  1815. * @type String
  1816. */
  1817. dataField: null,
  1818. /**
  1819. * The field used to access the category value from the items from the data source.
  1820. *
  1821. * @property categoryField
  1822. * @type String
  1823. */
  1824. categoryField: null,
  1825. /**
  1826. * A string reference to the globally-accessible function that may be called to
  1827. * determine each of the label values for this series. Also accepts function references.
  1828. *
  1829. * @property labelFunction
  1830. * @type String
  1831. */
  1832. labelFunction: null
  1833. });
  1834. /**
  1835. * StackedBarSeries class for the YUI Charts widget.
  1836. *
  1837. * @namespace YAHOO.widget
  1838. * @class StackedBarSeries
  1839. * @uses YAHOO.widget.CartesianSeries
  1840. * @constructor
  1841. */
  1842. YAHOO.widget.StackedBarSeries = function()
  1843. {
  1844. YAHOO.widget.StackedBarSeries.superclass.constructor.call(this);
  1845. };
  1846. YAHOO.lang.extend(YAHOO.widget.StackedBarSeries, YAHOO.widget.CartesianSeries,
  1847. {
  1848. type: "stackbar"
  1849. });
  1850. /**
  1851. * StackedColumnSeries class for the YUI Charts widget.
  1852. *
  1853. * @namespace YAHOO.widget
  1854. * @class StackedColumnSeries
  1855. * @uses YAHOO.widget.CartesianSeries
  1856. * @constructor
  1857. */
  1858. YAHOO.widget.StackedColumnSeries = function()
  1859. {
  1860. YAHOO.widget.StackedColumnSeries.superclass.constructor.call(this);
  1861. };
  1862. YAHOO.lang.extend(YAHOO.widget.StackedColumnSeries, YAHOO.widget.CartesianSeries,
  1863. {
  1864. type: "stackcolumn"
  1865. });
  1866. YAHOO.register("charts", YAHOO.widget.Chart, {version: "2.8.0r4", build: "2449"});