PageRenderTime 8068ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/includes/yui/as-src/charts/com/yahoo/astra/fl/charts/CartesianChart.as

https://github.com/gisanfu/project-and-template-manage-system
ActionScript | 1714 lines | 680 code | 215 blank | 819 comment | 59 complexity | 648dd09571ee0be48f600f72b125b61a MD5 | raw file
Possible License(s): LGPL-2.1
  1. package com.yahoo.astra.fl.charts
  2. {
  3. import com.yahoo.astra.fl.charts.axes.AxisOrientation;
  4. import com.yahoo.astra.fl.charts.axes.CategoryAxis;
  5. import com.yahoo.astra.fl.charts.axes.DefaultAxisRenderer;
  6. import com.yahoo.astra.fl.charts.axes.DefaultGridLinesRenderer;
  7. import com.yahoo.astra.fl.charts.axes.IAxis;
  8. import com.yahoo.astra.fl.charts.axes.ICartesianAxisRenderer;
  9. import com.yahoo.astra.fl.charts.axes.IGridLinesRenderer;
  10. import com.yahoo.astra.fl.charts.axes.IStackingAxis;
  11. import com.yahoo.astra.fl.charts.axes.NumericAxis;
  12. import com.yahoo.astra.fl.charts.axes.TimeAxis;
  13. import com.yahoo.astra.fl.charts.series.CartesianSeries;
  14. import com.yahoo.astra.fl.charts.series.ISeries;
  15. import com.yahoo.astra.fl.charts.series.IStackedSeries;
  16. import com.yahoo.astra.fl.utils.UIComponentUtil;
  17. import fl.core.InvalidationType;
  18. import fl.core.UIComponent;
  19. import flash.display.DisplayObject;
  20. import flash.display.Sprite;
  21. import flash.geom.Point;
  22. import flash.geom.Rectangle;
  23. import flash.text.TextFormat;
  24. import flash.text.TextFormatAlign;
  25. //--------------------------------------
  26. // Styles
  27. //--------------------------------------
  28. /**
  29. * An object containing style values to be passed to the vertical axis
  30. * renderer. The available styles are listed with the class that is used as the
  31. * axis renderer.
  32. *
  33. * @example
  34. * <listing version="3.0">
  35. * {
  36. * showTicks: true,
  37. * tickWeight: 1,
  38. * tickColor: 0x999999,
  39. * showMinorTicks: true,
  40. * minorTickWeight: 1,
  41. * minorTickColor: 0xcccccc
  42. * }
  43. * </listing>
  44. *
  45. * <p><strong>Note:</strong> Previously, all styles for the axis renderers
  46. * were listed as individual styles on the chart, but since it is possible
  47. * to use a renderer class that has completely different styles than the
  48. * default renderer, we need to deprecate the previous method to allow
  49. * maximum flexibility when new or custom renderers are added.</p>
  50. *
  51. * <p>The old styles still exist, and legacy code will continue to work
  52. * for the time being. However, it is recommended that you begin porting
  53. * code to the new system as soon as possible.</p>
  54. *
  55. * <p>For the vertical axis, you should use the following method to set
  56. * styles at runtime:</p>
  57. *
  58. * @example
  59. * <listing version="3.0">
  60. * chart.setVerticalAxisStyle("showTicks", false);
  61. * </listing>
  62. *
  63. * @see setVerticalAxisStyle()
  64. * @see com.yahoo.astra.fl.charts.axes.DefaultAxisRenderer
  65. */
  66. [Style(name="verticalAxisStyles", type="Object")]
  67. /**
  68. * The class used to instantiate the visual representation of the vertical
  69. * axis.
  70. *
  71. * @default DefaultAxisRenderer
  72. * @see com.yahoo.astra.fl.charts.axes.DefaultAxisRenderer
  73. */
  74. [Style(name="verticalAxisRenderer", type="Class")]
  75. /**
  76. * An object containing style values to be passed to the horizontal axis
  77. * renderer. The available styles are listed with the class that is used as the
  78. * axis renderer.
  79. *
  80. * @example
  81. * <listing version="3.0">
  82. * {
  83. * showTicks: true,
  84. * tickWeight: 1,
  85. * tickColor: 0x999999,
  86. * showMinorTicks: true,
  87. * minorTickWeight: 1,
  88. * minorTickColor: 0xcccccc
  89. * }
  90. * </listing>
  91. *
  92. * <p><strong>Note:</strong> Previously, all styles for the grid lines
  93. * renderer were listed as individual styles on the chart, but since it is
  94. * possible to use a renderer class that has completely different styles
  95. * than the default renderer, we need to deprecate the previous
  96. * method to allow maximum flexibility when new or custom renderers are
  97. * added.</p>
  98. *
  99. * <p>The old styles still exist, and legacy code will continue to work
  100. * for the time being. However, it is recommended that you begin porting
  101. * code to the new system as soon as possible.</p>
  102. *
  103. * <p>For the horizontal axis, you should use the following method to set
  104. * styles at runtime:</p>
  105. *
  106. * @example
  107. * <listing version="3.0">
  108. * chart.setHorizontalAxisStyle("showTicks", false);
  109. * </listing>
  110. *
  111. * @see setHorizontalAxisStyle()
  112. * @see com.yahoo.astra.fl.charts.axes.DefaultAxisRenderer
  113. */
  114. [Style(name="horizontalAxisStyles", type="Object")]
  115. /**
  116. * The class used to instantiate the visual representation of the horizontal
  117. * axis.
  118. *
  119. * @default DefaultAxisRenderer
  120. * @see com.yahoo.astra.fl.charts.axes.DefaultAxisRenderer
  121. */
  122. [Style(name="horizontalAxisRenderer", type="Class")]
  123. /**
  124. * An object containing style values to be passed to the vertical axis grid
  125. * lines renderer. The available styles are listed with the class that is used as the
  126. * grid lines renderer.
  127. *
  128. * @example
  129. * <listing version="3.0">
  130. * {
  131. * showLines: true,
  132. * lineWeight: 1,
  133. * lineColor: 0x999999,
  134. * showMinorLines: false
  135. * }
  136. * </listing>
  137. *
  138. * <p><strong>Note:</strong> Previously, all styles for the grid lines were listed as individual
  139. * styles on the chart, but since it is possible to use a renderer class
  140. * that has completely different styles, we need to deprecate the previous
  141. * method to allow maximum flexibility when new or custom renderers are
  142. * added.</p>
  143. *
  144. * <p>The old styles still exist, and legacy code will continue to work
  145. * for the time being. However, it is recommended that you begin porting
  146. * code to the new system as soon as possible.</p>
  147. *
  148. * <p>For the vertical axis grid lines, you should use the following method to set
  149. * styles at runtime:</p>
  150. *
  151. * @example
  152. * <listing version="3.0">
  153. * chart.setVerticalAxisGridLinesStyle("lineColor", 0x999999);
  154. * </listing>
  155. *
  156. * @see setVerticalAxisGridLinesStyle()
  157. * @see com.yahoo.astra.fl.charts.axes.DefaultGridLinesRenderer
  158. */
  159. [Style(name="verticalAxisGridLinesStyles", type="Object")]
  160. /**
  161. * The class used to instantiate the vertical axis grid lines.
  162. *
  163. * @default DefaultGridLinesRenderer
  164. * @see com.yahoo.astra.fl.charts.axes.DefaultGridLinesRenderer
  165. */
  166. [Style(name="verticalAxisGridLinesRenderer", type="Class")]
  167. /**
  168. * An object containing style values to be passed to the horizontal axis grid
  169. * lines renderer. The available styles are listed with the class that is used as the
  170. * grid lines renderer.
  171. *
  172. * @example
  173. * <listing version="3.0">
  174. * {
  175. * showLines: true,
  176. * lineWeight: 1,
  177. * lineColor: 0x999999,
  178. * showMinorLines: false
  179. * }
  180. * </listing>
  181. *
  182. * <p><strong>Note:</strong> Previously, all styles for the grid lines were listed as individual
  183. * styles on the chart, but since it is possible to use a renderer class
  184. * that has completely different styles, we need to deprecate the previous
  185. * method to allow maximum flexibility when new or custom renderers are
  186. * added.</p>
  187. *
  188. * <p>The old styles still exist, and legacy code will continue to work
  189. * for the time being. However, it is recommended that you begin porting
  190. * code to the new system as soon as possible.</p>
  191. *
  192. * <p>For the horizontal axis grid lines, you should use the following method to set
  193. * styles at runtime:</p>
  194. *
  195. * @example
  196. * <listing version="3.0">
  197. * chart.setHorizontalAxisGridLinesStyle("lineColor", 0x999999);
  198. * </listing>
  199. *
  200. * @see setHorizontalAxisGridLinesStyle()
  201. * @see com.yahoo.astra.fl.charts.axes.DefaultGridLinesRenderer
  202. */
  203. [Style(name="horizontalAxisGridLinesStyles", type="Object")]
  204. /**
  205. * The class used to instantiate the horizontal axis grid lines.
  206. *
  207. * @default DefaultGridLinesRenderer
  208. */
  209. [Style(name="horizontalAxisGridLinesRenderer", type="Class")]
  210. //-- DEPRECATED Vertical Axis styles
  211. /**
  212. * If false, the vertical axis is not drawn. Titles, labels, ticks, and grid
  213. * lines may still be drawn, however, so you must specifically hide each
  214. * item if nothing should be drawn.
  215. *
  216. * @default true
  217. * @deprecated
  218. */
  219. [Style(name="showVerticalAxis", type="Boolean")]
  220. /**
  221. * The line weight, in pixels, for the vertical axis.
  222. *
  223. * @default 1
  224. * @deprecated
  225. */
  226. [Style(name="verticalAxisWeight", type="int")]
  227. /**
  228. * The line color for the vertical axis.
  229. *
  230. * @default #888a85
  231. * @deprecated
  232. */
  233. [Style(name="verticalAxisColor", type="uint")]
  234. //-- Labels - Vertical Axis
  235. /**
  236. * If true, labels will be displayed on the vertical axis.
  237. *
  238. * @default true
  239. * @deprecated
  240. */
  241. [Style(name="showVerticalAxisLabels", type="Boolean")]
  242. /**
  243. * The distance, in pixels, between a label and the vertical axis.
  244. *
  245. * @default 2
  246. * @deprecated
  247. */
  248. [Style(name="verticalAxisLabelDistance", type="Number")]
  249. /**
  250. * Defines the TextFormat used by labels on the vertical axis. If null,
  251. * the <code>textFormat</code> style will be used.
  252. *
  253. * @default null
  254. * @deprecated
  255. */
  256. [Style(name="verticalAxisTextFormat", type="TextFormat")]
  257. /**
  258. * If true, labels that overlap previously drawn labels on the axis will be
  259. * hidden. The first and last labels on the axis will always be drawn.
  260. *
  261. * @default true
  262. * @deprecated
  263. */
  264. [Style(name="verticalAxisHideOverlappingLabels", type="Boolean")]
  265. /**
  266. * The angle, in degrees, of the labels on the vertical axis. May be a value
  267. * between <code>-90</code> and <code>90</code>. The font must be embedded
  268. * in the SWF and the <code>embedFonts</code> style on the chart must be set
  269. * to <code>true</code> before labels may be rotated. If these conditions
  270. * aren't met, the labels will not be rotated.
  271. *
  272. * @default 0
  273. * @deprecated
  274. */
  275. [Style(name="verticalAxisLabelRotation", type="Number")]
  276. //-- Grid - Vertical Axis
  277. /**
  278. * An Array of <code>uint</code> color values that is used to draw
  279. * alternating fills between the vertical axis' grid lines.
  280. *
  281. * @default []
  282. * @deprecated
  283. */
  284. [Style(name="verticalAxisGridFillColors", type="Array")]
  285. /**
  286. * An Array of alpha values (in the range of 0 to 1) that is used to draw
  287. * alternating fills between the vertical axis' grid lines.
  288. *
  289. * @default []
  290. * @deprecated
  291. */
  292. [Style(name="verticalAxisGridFillAlphas", type="Array")]
  293. //-- DEPRECATED Grid Lines styles - Vertical Axis
  294. /**
  295. * If true, grid lines will be displayed on the vertical axis.
  296. *
  297. * @default false
  298. * @deprecated
  299. */
  300. [Style(name="showVerticalAxisGridLines", type="Boolean")]
  301. /**
  302. * The line weight, in pixels, for the grid lines on the vertical axis.
  303. *
  304. * @default 1
  305. * @deprecated
  306. */
  307. [Style(name="verticalAxisGridLineWeight", type="int")]
  308. /**
  309. * The line color for the grid lines on the vertical axis.
  310. *
  311. * @default #babdb6
  312. * @deprecated
  313. */
  314. [Style(name="verticalAxisGridLineColor", type="uint")]
  315. //-- Minor Grid Lines - Vertical Axis
  316. /**
  317. * If true, minor grid lines will be displayed on the vertical axis.
  318. *
  319. * @default false
  320. * @deprecated
  321. */
  322. [Style(name="showVerticalAxisMinorGridLines", type="Boolean")]
  323. /**
  324. * The line weight, in pixels, for the minor grid lines on the vertical axis.
  325. *
  326. * @default 1
  327. * @deprecated
  328. */
  329. [Style(name="verticalAxisMinorGridLineWeight", type="int")]
  330. /**
  331. * The line color for the minor grid lines on the vertical axis.
  332. *
  333. * @default #eeeeec
  334. * @deprecated
  335. */
  336. [Style(name="verticalAxisMinorGridLineColor", type="uint")]
  337. //-- Ticks - Vertical Axis
  338. /**
  339. * If true, ticks will be displayed on the vertical axis.
  340. *
  341. * @default true
  342. * @deprecated
  343. */
  344. [Style(name="showVerticalAxisTicks", type="Boolean")]
  345. /**
  346. * The line weight, in pixels, for the ticks on the vertical axis.
  347. *
  348. * @default 1
  349. * @deprecated
  350. */
  351. [Style(name="verticalAxisTickWeight", type="int")]
  352. /**
  353. * The line color for the ticks on the vertical axis.
  354. *
  355. * @default #888a85
  356. * @deprecated
  357. */
  358. [Style(name="verticalAxisTickColor", type="uint")]
  359. /**
  360. * The length, in pixels, of the ticks on the vertical axis.
  361. *
  362. * @default 4
  363. * @deprecated
  364. */
  365. [Style(name="verticalAxisTickLength", type="Number")]
  366. /**
  367. * The position of the ticks on the vertical axis.
  368. *
  369. * @default "cross"
  370. * @see com.yahoo.astra.fl.charts.axes.TickPosition
  371. * @deprecated
  372. */
  373. [Style(name="verticalAxisTickPosition", type="String")]
  374. //-- Minor ticks - Vertical Axis
  375. /**
  376. * If true, ticks will be displayed on the vertical axis at minor positions.
  377. *
  378. * @default true
  379. * @deprecated
  380. */
  381. [Style(name="showVerticalAxisMinorTicks", type="Boolean")]
  382. /**
  383. * The line weight, in pixels, for the minor ticks on the vertical axis.
  384. *
  385. * @default 1
  386. * @deprecated
  387. */
  388. [Style(name="verticalAxisMinorTickWeight", type="int")]
  389. /**
  390. * The line color for the minor ticks on the vertical axis.
  391. *
  392. * @default #888a85
  393. * @deprecated
  394. */
  395. [Style(name="verticalAxisMinorTickColor", type="uint")]
  396. /**
  397. * The length of the minor ticks on the vertical axis.
  398. *
  399. * @default 3
  400. * @deprecated
  401. */
  402. [Style(name="verticalAxisMinorTickLength", type="Number")]
  403. /**
  404. * The position of the minor ticks on the vertical axis.
  405. *
  406. * @default "outside"
  407. * @see com.yahoo.astra.fl.charts.axes.TickPosition
  408. * @deprecated
  409. */
  410. [Style(name="verticalAxisMinorTickPosition", type="String")]
  411. //-- Title - Vertical Axis
  412. /**
  413. * If true, the vertical axis title will be displayed.
  414. *
  415. * @default 2
  416. * @deprecated
  417. */
  418. [Style(name="showVerticalAxisTitle", type="Boolean")]
  419. /**
  420. * The TextFormat object to use to render the vertical axis title label.
  421. *
  422. * @default TextFormat("_sans", 11, 0x000000, false, false, false, '', '', TextFormatAlign.LEFT, 0, 0, 0, 0)
  423. * @deprecated
  424. */
  425. [Style(name="verticalAxisTitleTextFormat", type="TextFormat")]
  426. //-- DEPRECATED Horizontal Axis styles
  427. /**
  428. * If false, the horizontal axis is not drawn. Titles, labels, ticks, and grid
  429. * lines may still be drawn, however, so you must specifically hide each
  430. * item if nothing should be drawn.
  431. *
  432. * @default true
  433. * @deprecated
  434. */
  435. [Style(name="showHorizontalAxis", type="Boolean")]
  436. /**
  437. * The line weight, in pixels, for the horizontal axis.
  438. *
  439. * @default 1
  440. * @deprecated
  441. */
  442. [Style(name="horizontalAxisWeight", type="int")]
  443. /**
  444. * The line color for the horizontal axis.
  445. *
  446. * @default #888a85
  447. * @deprecated
  448. */
  449. [Style(name="horizontalAxisColor", type="uint")]
  450. //-- Labels - Horizontal Axis
  451. /**
  452. * If true, labels will be displayed on the horizontal axis.
  453. *
  454. * @default true
  455. * @deprecated
  456. */
  457. [Style(name="showHorizontalAxisLabels", type="Boolean")]
  458. /**
  459. * The distance, in pixels, between a label and the horizontal axis.
  460. *
  461. * @default 2
  462. * @deprecated
  463. */
  464. [Style(name="horizontalAxisLabelDistance", type="Number")]
  465. /**
  466. * Defines the TextFormat used by labels on the horizontal axis. If null,
  467. * the <code>textFormat</code> style will be used.
  468. *
  469. * @default null
  470. * @deprecated
  471. */
  472. [Style(name="horizontalAxisTextFormat", type="TextFormat")]
  473. /**
  474. * If true, labels that overlap previously drawn labels on the axis will be
  475. * hidden. The first and last labels on the axis will always be drawn.
  476. *
  477. * @default true
  478. * @deprecated
  479. */
  480. [Style(name="horizontalAxisHideOverlappingLabels", type="Boolean")]
  481. /**
  482. * The angle, in degrees, of the labels on the horizontal axis. May be a value
  483. * between <code>-90</code> and <code>90</code>. The font must be embedded
  484. * in the SWF and the <code>embedFonts</code> style on the chart must be set
  485. * to <code>true</code> before labels may be rotated. If these conditions
  486. * aren't met, the labels will not be rotated.
  487. *
  488. * @default 0
  489. * @deprecated
  490. */
  491. [Style(name="horizontalAxisLabelRotation", type="Number")]
  492. //-- Grid - Horizontal Axis
  493. /**
  494. * An Array of <code>uint</code> color values that is used to draw
  495. * alternating fills between the horizontal axis' grid lines.
  496. *
  497. * @default []
  498. * @deprecated
  499. */
  500. [Style(name="horizontalAxisGridFillColors", type="Array")]
  501. /**
  502. * An Array of alpha values (in the range of 0 to 1) that is used to draw
  503. * alternating fills between the horizontal axis' grid lines.
  504. *
  505. * @default []
  506. * @deprecated
  507. */
  508. [Style(name="horizontalAxisGridFillAlphas", type="Array")]
  509. //-- DEPRECATED Grid Lines - Horizontal Axis
  510. /**
  511. * If true, grid lines will be displayed on the horizontal axis.
  512. *
  513. * @default false
  514. * @deprecated
  515. */
  516. [Style(name="showHorizontalAxisGridLines", type="Boolean")]
  517. /**
  518. * The line weight, in pixels, for the grid lines on the horizontal axis.
  519. *
  520. * @default 1
  521. * @deprecated
  522. */
  523. [Style(name="horizontalAxisGridLineWeight", type="int")]
  524. /**
  525. * The line color for the grid lines on the horizontal axis.
  526. *
  527. * @default #babdb6
  528. * @deprecated
  529. */
  530. [Style(name="horizontalAxisGridLineColor", type="uint")]
  531. //-- Minor Grid Lines - Horizontal Axis
  532. /**
  533. * If true, minor grid lines will be displayed on the horizontal axis.
  534. *
  535. * @default false
  536. * @deprecated
  537. */
  538. [Style(name="showHorizontalAxisMinorGridLines", type="Boolean")]
  539. /**
  540. * The line weight, in pixels, for the minor grid lines on the horizontal axis.
  541. *
  542. * @default 1
  543. * @deprecated
  544. */
  545. [Style(name="horizontalAxisMinorGridLineWeight", type="int")]
  546. /**
  547. * The line color for the minor grid lines on the horizontal axis.
  548. *
  549. * @default #eeeeec
  550. * @deprecated
  551. */
  552. [Style(name="horizontalAxisMinorGridLineColor", type="uint")]
  553. //-- Ticks - Horizontal Axis
  554. /**
  555. * If true, ticks will be displayed on the horizontal axis.
  556. *
  557. * @default true
  558. * @deprecated
  559. */
  560. [Style(name="showHorizontalAxisTicks", type="Boolean")]
  561. /**
  562. * The line weight, in pixels, for the ticks on the horizontal axis.
  563. *
  564. * @default 1
  565. * @deprecated
  566. */
  567. [Style(name="horizontalAxisTickWeight", type="int")]
  568. /**
  569. * The line color for the ticks on the horizontal axis.
  570. *
  571. * @default #888a85
  572. * @deprecated
  573. */
  574. [Style(name="horizontalAxisTickColor", type="uint")]
  575. /**
  576. * The length, in pixels, of the ticks on the horizontal axis.
  577. *
  578. * @default 4
  579. * @deprecated
  580. */
  581. [Style(name="horizontalAxisTickLength", type="Number")]
  582. /**
  583. * The position of the ticks on the horizontal axis.
  584. *
  585. * @default "cross"
  586. * @see com.yahoo.astra.fl.charts.axes.TickPosition
  587. * @deprecated
  588. */
  589. [Style(name="horizontalAxisTickPosition", type="String")]
  590. //-- Minor ticks - Horizontal Axis
  591. /**
  592. * If true, ticks will be displayed on the horizontal axis at minor positions.
  593. *
  594. * @default true
  595. * @deprecated
  596. */
  597. [Style(name="showHorizontalAxisMinorTicks", type="Boolean")]
  598. /**
  599. * The line weight, in pixels, for the minor ticks on the horizontal axis.
  600. *
  601. * @default 1
  602. * @deprecated
  603. */
  604. [Style(name="horizontalAxisMinorTickWeight", type="int")]
  605. /**
  606. * The line color for the minor ticks on the horizontal axis.
  607. *
  608. * @default #888a85
  609. * @deprecated
  610. */
  611. [Style(name="horizontalAxisMinorTickColor", type="uint")]
  612. /**
  613. * The length of the minor ticks on the horizontal axis.
  614. *
  615. * @default 3
  616. * @deprecated
  617. */
  618. [Style(name="horizontalAxisMinorTickLength", type="Number")]
  619. /**
  620. * The position of the minor ticks on the horizontal axis.
  621. *
  622. * @default "outside"
  623. * @see com.yahoo.astra.fl.charts.axes.TickPosition
  624. * @deprecated
  625. */
  626. [Style(name="horizontalAxisMinorTickPosition", type="String")]
  627. //-- Title - Horizontal Axis
  628. /**
  629. * If true, the horizontal axis title will be displayed.
  630. *
  631. * @default 2
  632. * @deprecated
  633. */
  634. [Style(name="showHorizontalAxisTitle", type="Boolean")]
  635. /**
  636. * The TextFormat object to use to render the horizontal axis title label.
  637. *
  638. * @default TextFormat("_sans", 11, 0x000000, false, false, false, '', '', TextFormatAlign.LEFT, 0, 0, 0, 0)
  639. * @deprecated
  640. */
  641. [Style(name="horizontalAxisTitleTextFormat", type="TextFormat")]
  642. /**
  643. * A chart based on the cartesian coordinate system (x, y).
  644. *
  645. * @author Josh Tynjala
  646. */
  647. public class CartesianChart extends Chart implements IChart, ICategoryChart
  648. {
  649. //--------------------------------------
  650. // Class Variables
  651. //--------------------------------------
  652. /**
  653. * @private
  654. * Exists simply to reference dependencies that aren't used
  655. * anywhere else by this component.
  656. */
  657. private static const DEPENDENCIES:Array = [TimeAxis];
  658. /**
  659. * @private
  660. */
  661. private static var defaultStyles:Object =
  662. {
  663. horizontalAxisStyles: {},
  664. horizontalAxisGridLinesStyles: {},
  665. horizontalAxisRenderer: DefaultAxisRenderer,
  666. horizontalAxisGridLinesRenderer: DefaultGridLinesRenderer,
  667. verticalAxisStyles: {},
  668. verticalAxisGridLinesStyles: {},
  669. verticalAxisRenderer: DefaultAxisRenderer,
  670. verticalAxisGridLinesRenderer: DefaultGridLinesRenderer,
  671. //DEPRECATED BELOW THIS POINT!
  672. //(to be removed in a future version)
  673. //axis
  674. showHorizontalAxis: true,
  675. horizontalAxisWeight: 1,
  676. horizontalAxisColor: 0x888a85,
  677. //title
  678. showHorizontalAxisTitle: true,
  679. horizontalAxisTitleTextFormat: new TextFormat("_sans", 11, 0x000000, false, false, false, "", "", TextFormatAlign.LEFT, 0, 0, 0, 0),
  680. //labels
  681. showHorizontalAxisLabels: true,
  682. horizontalAxisTextFormat: null,
  683. horizontalAxisLabelDistance: 2,
  684. horizontalAxisHideOverlappingLabels: true,
  685. horizontalAxisLabelRotation: 0,
  686. //grid lines
  687. horizontalAxisGridLineWeight: 1,
  688. horizontalAxisGridLineColor: 0xbabdb6,
  689. showHorizontalAxisGridLines: false,
  690. horizontalAxisMinorGridLineWeight: 1,
  691. horizontalAxisMinorGridLineColor: 0xeeeeec,
  692. showHorizontalAxisMinorGridLines: false,
  693. horizontalAxisGridFillColors: [],
  694. horizontalAxisGridFillAlphas: [],
  695. //ticks
  696. showHorizontalAxisTicks: false,
  697. horizontalAxisTickWeight: 1,
  698. horizontalAxisTickColor: 0x888a85,
  699. horizontalAxisTickLength: 4,
  700. horizontalAxisTickPosition: "cross",
  701. showHorizontalAxisMinorTicks: false,
  702. horizontalAxisMinorTickWeight: 1,
  703. horizontalAxisMinorTickColor: 0x888a85,
  704. horizontalAxisMinorTickLength: 3,
  705. horizontalAxisMinorTickPosition: "outside",
  706. //axis
  707. showVerticalAxis: true,
  708. verticalAxisWeight: 1,
  709. verticalAxisColor: 0x888a85,
  710. //title
  711. showVerticalAxisTitle: true,
  712. verticalAxisTitleTextFormat: new TextFormat("_sans", 11, 0x000000, false, false, false, "", "", TextFormatAlign.LEFT, 0, 0, 0, 0),
  713. //labels
  714. showVerticalAxisLabels: true,
  715. verticalAxisTextFormat: null,
  716. verticalAxisLabelDistance: 2,
  717. verticalAxisHideOverlappingLabels: true,
  718. verticalAxisLabelRotation: 0,
  719. //grid lines
  720. showVerticalAxisGridLines: true,
  721. verticalAxisGridLineWeight: 1,
  722. verticalAxisGridLineColor: 0xbabdb6,
  723. verticalAxisMinorGridLineWeight: 1,
  724. verticalAxisMinorGridLineColor: 0xeeeeec,
  725. showVerticalAxisMinorGridLines: false,
  726. verticalAxisGridFillColors: [],
  727. verticalAxisGridFillAlphas: [],
  728. //ticks
  729. showVerticalAxisTicks: true,
  730. verticalAxisTickWeight: 1,
  731. verticalAxisTickColor: 0x888a85,
  732. verticalAxisTickLength: 4,
  733. verticalAxisTickPosition: "cross",
  734. showVerticalAxisMinorTicks: true,
  735. verticalAxisMinorTickWeight: 1,
  736. verticalAxisMinorTickColor: 0x888a85,
  737. verticalAxisMinorTickLength: 3,
  738. verticalAxisMinorTickPosition: "outside"
  739. };
  740. /**
  741. * @private
  742. * The chart styles that correspond to styles on the horizontal axis.
  743. */
  744. private static const HORIZONTAL_AXIS_STYLES:Object =
  745. {
  746. showAxis: "showHorizontalAxis",
  747. axisWeight: "horizontalAxisWeight",
  748. axisColor: "horizontalAxisColor",
  749. textFormat: "textFormat",
  750. embedFonts: "embedFonts",
  751. hideOverlappingLabels: "horizontalAxisHideOverlappingLabels",
  752. labelRotation: "horizontalAxisLabelRotation",
  753. labelDistance: "horizontalAxisLabelDistance",
  754. showLabels: "showHorizontalAxisLabels",
  755. showTitle: "showHorizontalAxisTitle",
  756. titleTextFormat: "horizontalAxisTitleTextFormat",
  757. tickWeight: "horizontalAxisTickWeight",
  758. tickColor: "horizontalAxisTickColor",
  759. tickLength: "horizontalAxisTickLength",
  760. tickPosition: "horizontalAxisTickPosition",
  761. showTicks: "showHorizontalAxisTicks",
  762. minorTickWeight: "horizontalAxisMinorTickWeight",
  763. minorTickColor: "horizontalAxisMinorTickColor",
  764. minorTickLength: "horizontalAxisMinorTickLength",
  765. minorTickPosition: "horizontalAxisMinorTickPosition",
  766. showMinorTicks: "showHorizontalAxisMinorTicks"
  767. };
  768. /**
  769. * @private
  770. * The chart styles that correspond to styles on the horizontal axis
  771. * grid lines.
  772. */
  773. private static const HORIZONTAL_GRID_LINES_STYLES:Object =
  774. {
  775. lineWeight: "horizontalAxisGridLineWeight",
  776. lineColor: "horizontalAxisGridLineColor",
  777. showLines: "showHorizontalAxisGridLines",
  778. minorLineWeight: "horizontalAxisMinorGridLineWeight",
  779. minorLineColor: "horizontalAxisMinorGridLineColor",
  780. showMinorLines: "showHorizontalAxisMinorGridLines",
  781. fillColors: "horizontalAxisGridFillColors",
  782. fillAlphas: "horizontalAxisGridFillAlphas"
  783. }
  784. /**
  785. * @private
  786. * The chart styles that correspond to styles on the vertical axis.
  787. */
  788. private static const VERTICAL_AXIS_STYLES:Object =
  789. {
  790. showAxis: "showVerticalAxis",
  791. axisWeight: "verticalAxisWeight",
  792. axisColor: "verticalAxisColor",
  793. textFormat: "textFormat",
  794. embedFonts: "embedFonts",
  795. hideOverlappingLabels: "verticalAxisHideOverlappingLabels",
  796. labelRotation: "verticalAxisLabelRotation",
  797. labelDistance: "verticalAxisLabelDistance",
  798. showLabels: "showVerticalAxisLabels",
  799. showTitle: "showVerticalAxisTitle",
  800. titleTextFormat: "verticalAxisTitleTextFormat",
  801. tickWeight: "verticalAxisTickWeight",
  802. tickColor: "verticalAxisTickColor",
  803. tickLength: "verticalAxisTickLength",
  804. tickPosition: "verticalAxisTickPosition",
  805. showTicks: "showVerticalAxisTicks",
  806. minorTickWeight: "verticalAxisMinorTickWeight",
  807. minorTickColor: "verticalAxisMinorTickColor",
  808. minorTickLength: "verticalAxisMinorTickLength",
  809. minorTickPosition: "verticalAxisMinorTickPosition",
  810. showMinorTicks: "showVerticalAxisMinorTicks"
  811. };
  812. /**
  813. * @private
  814. * The chart styles that correspond to styles on the vertical axis
  815. * grid lines.
  816. */
  817. private static const VERTICAL_GRID_LINES_STYLES:Object =
  818. {
  819. lineWeight: "verticalAxisGridLineWeight",
  820. lineColor: "verticalAxisGridLineColor",
  821. showLines: "showVerticalAxisGridLines",
  822. minorLineWeight: "verticalAxisMinorGridLineWeight",
  823. minorLineColor: "verticalAxisMinorGridLineColor",
  824. showMinorLines: "showVerticalAxisMinorGridLines",
  825. fillColors: "verticalAxisGridFillColors",
  826. fillAlphas: "verticalAxisGridFillAlphas"
  827. }
  828. //--------------------------------------
  829. // Class Methods
  830. //--------------------------------------
  831. /**
  832. * @copy fl.core.UIComponent#getStyleDefinition()
  833. */
  834. public static function getStyleDefinition():Object
  835. {
  836. return mergeStyles(defaultStyles, Chart.getStyleDefinition());
  837. }
  838. //--------------------------------------
  839. // Constructor
  840. //--------------------------------------
  841. /**
  842. * Constructor.
  843. */
  844. public function CartesianChart()
  845. {
  846. super();
  847. }
  848. //--------------------------------------
  849. // Properties
  850. //--------------------------------------
  851. /**
  852. * @private
  853. * Storage for the contentBounds property.
  854. */
  855. protected var _contentBounds:Rectangle = new Rectangle();
  856. /**
  857. * The rectangular bounds where the cartesian chart's data is drawn.
  858. */
  859. public function get contentBounds():Rectangle
  860. {
  861. return this._contentBounds;
  862. }
  863. /**
  864. * @private
  865. */
  866. protected var horizontalGridLines:IGridLinesRenderer;
  867. /**
  868. * @private
  869. */
  870. protected var verticalGridLines:IGridLinesRenderer;
  871. /**
  872. * @private
  873. */
  874. protected var verticalMinorGridLines:Sprite;
  875. /**
  876. * @private
  877. * The visual representation of the horizontal axis.
  878. */
  879. protected var horizontalAxisRenderer:ICartesianAxisRenderer;
  880. /**
  881. * @private
  882. * Storage for the horizontalAxis property.
  883. */
  884. private var _horizontalAxis:IAxis;
  885. /**
  886. * The axis representing the horizontal range.
  887. */
  888. public function get horizontalAxis():IAxis
  889. {
  890. return this._horizontalAxis;
  891. }
  892. /**
  893. * @private
  894. */
  895. public function set horizontalAxis(axis:IAxis):void
  896. {
  897. if(this._horizontalAxis != axis)
  898. {
  899. this._horizontalAxis = axis;
  900. this._horizontalAxis.chart = this;
  901. this.invalidate("axes");
  902. }
  903. }
  904. /**
  905. * @private
  906. * The visual representation of the horizontal axis.
  907. */
  908. protected var verticalAxisRenderer:ICartesianAxisRenderer;
  909. /**
  910. * @private
  911. * Storage for the verticalAxis property.
  912. */
  913. private var _verticalAxis:IAxis;
  914. /**
  915. * The axis representing the vertical range.
  916. */
  917. public function get verticalAxis():IAxis
  918. {
  919. return this._verticalAxis;
  920. }
  921. /**
  922. * @private
  923. */
  924. public function set verticalAxis(axis:IAxis):void
  925. {
  926. if(this._verticalAxis != axis)
  927. {
  928. this._verticalAxis = axis;
  929. this._verticalAxis.chart = this;
  930. this.invalidate("axes");
  931. }
  932. }
  933. //-- Data
  934. /**
  935. * @private
  936. * Storage for the horizontalField property.
  937. */
  938. private var _horizontalField:String = "category";
  939. [Inspectable(defaultValue="category",verbose=1)]
  940. /**
  941. * If the items displayed on the chart are complex objects, the horizontalField string
  942. * defines the property to access when determining the x value.
  943. */
  944. public function get horizontalField():String
  945. {
  946. return this._horizontalField;
  947. }
  948. /**
  949. * @private
  950. */
  951. public function set horizontalField(value:String):void
  952. {
  953. if(this._horizontalField != value)
  954. {
  955. this._horizontalField = value;
  956. this.invalidate(InvalidationType.DATA);
  957. }
  958. }
  959. /**
  960. * @private
  961. * Storage for the verticalField property.
  962. */
  963. private var _verticalField:String = "value";
  964. [Inspectable(defaultValue="value",verbose=1)]
  965. /**
  966. * If the items displayed on the chart are complex objects, the verticalField string
  967. * defines the property to access when determining the y value.
  968. */
  969. public function get verticalField():String
  970. {
  971. return this._verticalField;
  972. }
  973. /**
  974. * @private
  975. */
  976. public function set verticalField(value:String):void
  977. {
  978. if(this._verticalField != value)
  979. {
  980. this._verticalField = value;
  981. this.invalidate(InvalidationType.DATA);
  982. }
  983. }
  984. //-- Titles
  985. /**
  986. * @private
  987. * Storage for the horizontalAxisTitle property.
  988. */
  989. private var _horizontalAxisTitle:String = "";
  990. [Inspectable(defaultValue="")]
  991. /**
  992. * The title text displayed on the horizontal axis.
  993. */
  994. public function get horizontalAxisTitle():String
  995. {
  996. return this._horizontalAxisTitle;
  997. }
  998. /**
  999. * @private
  1000. */
  1001. public function set horizontalAxisTitle(value:String):void
  1002. {
  1003. if(this._horizontalAxisTitle != value)
  1004. {
  1005. this._horizontalAxisTitle = value;
  1006. this.invalidate(InvalidationType.DATA);
  1007. this.invalidate("axes");
  1008. }
  1009. }
  1010. /**
  1011. * @private
  1012. * Storage for the verticalAxisTitle property.
  1013. */
  1014. private var _verticalAxisTitle:String = "";
  1015. [Inspectable(defaultValue="")]
  1016. /**
  1017. * The title text displayed on the horizontal axis.
  1018. */
  1019. public function get verticalAxisTitle():String
  1020. {
  1021. return this._verticalAxisTitle;
  1022. }
  1023. /**
  1024. * @private
  1025. */
  1026. public function set verticalAxisTitle(value:String):void
  1027. {
  1028. if(this._verticalAxisTitle != value)
  1029. {
  1030. this._verticalAxisTitle = value;
  1031. this.invalidate(InvalidationType.DATA);
  1032. this.invalidate("axes");
  1033. }
  1034. }
  1035. //-- Category names
  1036. /**
  1037. * @private
  1038. * Storage for the categoryNames property.
  1039. */
  1040. private var _explicitCategoryNames:Array;
  1041. [Inspectable]
  1042. /**
  1043. * The names of the categories displayed on the category axis. If the
  1044. * chart does not have a category axis, this value will be ignored.
  1045. */
  1046. public function get categoryNames():Array
  1047. {
  1048. if(this._explicitCategoryNames && this._explicitCategoryNames.length > 0)
  1049. {
  1050. return this._explicitCategoryNames;
  1051. }
  1052. else if(this.horizontalAxis is CategoryAxis)
  1053. {
  1054. return CategoryAxis(this.horizontalAxis).categoryNames;
  1055. }
  1056. else if(this.verticalAxis is CategoryAxis)
  1057. {
  1058. return CategoryAxis(this.verticalAxis).categoryNames;
  1059. }
  1060. return null;
  1061. }
  1062. /**
  1063. * @private
  1064. */
  1065. public function set categoryNames(value:Array):void
  1066. {
  1067. if(this._explicitCategoryNames != value)
  1068. {
  1069. this._explicitCategoryNames = value;
  1070. this.invalidate(InvalidationType.DATA);
  1071. this.invalidate("axes");
  1072. }
  1073. }
  1074. /**
  1075. * @private
  1076. * Storage for the overflowEnabled property.
  1077. */
  1078. private var _overflowEnabled:Boolean = false;
  1079. [Inspectable(defaultValue=false,verbose=1)]
  1080. /**
  1081. * If false, which is the default, the axes will be resized to fit within the defined
  1082. * bounds of the plot area. However, if set to true, the axes themselves will grow to
  1083. * fit the plot area bounds and the labels and other items that normally cause the
  1084. * resize will be drawn outside.
  1085. */
  1086. public function get overflowEnabled():Boolean
  1087. {
  1088. return this._overflowEnabled;
  1089. }
  1090. /**
  1091. * @private
  1092. */
  1093. public function set overflowEnabled(value:Boolean):void
  1094. {
  1095. if(this._overflowEnabled != value)
  1096. {
  1097. this._overflowEnabled = value;
  1098. this.invalidate("axes");
  1099. }
  1100. }
  1101. //--------------------------------------
  1102. // Public Methods
  1103. //--------------------------------------
  1104. /**
  1105. * @inheritDoc
  1106. */
  1107. public function itemToPosition(series:ISeries, itemIndex:int):Point
  1108. {
  1109. var horizontalValue:Object = this.itemToAxisValue(series, itemIndex, this.horizontalAxis);
  1110. var xPosition:Number = this.horizontalAxis.valueToLocal(horizontalValue);
  1111. var verticalValue:Object = this.itemToAxisValue(series, itemIndex, this.verticalAxis);
  1112. var yPosition:Number = this.verticalAxis.valueToLocal(verticalValue);
  1113. return new Point(xPosition, yPosition);
  1114. }
  1115. /**
  1116. * @private
  1117. */
  1118. public function itemToAxisValue(series:ISeries, itemIndex:int, axis:IAxis, stack:Boolean = true):Object
  1119. {
  1120. if(!stack || !ChartUtil.isStackingAllowed(axis, series))
  1121. {
  1122. var item:Object = series.dataProvider[itemIndex];
  1123. var valueField:String = this.axisAndSeriesToField(axis, series);
  1124. return item[valueField];
  1125. }
  1126. var type:Class = UIComponentUtil.getClassDefinition(series);
  1127. var stackAxis:IStackingAxis = IStackingAxis(axis);
  1128. var stackValue:Object;
  1129. var allSeriesOfType:Array = ChartUtil.findSeriesOfType(series, this);
  1130. var seriesIndex:int = allSeriesOfType.indexOf(series);
  1131. var values:Array = [];
  1132. for(var i:int = 0; i <= seriesIndex; i++)
  1133. {
  1134. var stackedSeries:IStackedSeries = IStackedSeries(allSeriesOfType[i]);
  1135. item = stackedSeries.dataProvider[itemIndex];
  1136. valueField = this.axisAndSeriesToField(stackAxis, stackedSeries);
  1137. values.unshift(item[valueField]);
  1138. }
  1139. if(values.length > 0)
  1140. {
  1141. stackValue = stackAxis.stack.apply(stackAxis, values);
  1142. }
  1143. return stackValue;
  1144. }
  1145. /**
  1146. * Sets a style on the horizontal axis.
  1147. */
  1148. public function setHorizontalAxisStyle(name:String, value:Object):void
  1149. {
  1150. this.setComplexStyle("horizontalAxisStyles", name, value);
  1151. }
  1152. /**
  1153. * Sets a style on the vertical axis.
  1154. */
  1155. public function setVerticalAxisStyle(name:String, value:Object):void
  1156. {
  1157. this.setComplexStyle("verticalAxisStyles", name, value);
  1158. }
  1159. /**
  1160. * Sets a style on the horizontal axis grid lines.
  1161. */
  1162. public function setHorizontalAxisGridLinesStyle(name:String, value:Object):void
  1163. {
  1164. this.setComplexStyle("horizontalAxisGridLinesStyles", name, value);
  1165. }
  1166. /**
  1167. * Sets a style on the vertical axis grid lines.
  1168. */
  1169. public function setVerticalAxisGridLinesStyle(name:String, value:Object):void
  1170. {
  1171. this.setComplexStyle("verticalAxisGridLinesStyles", name, value);
  1172. }
  1173. //--------------------------------------
  1174. // Protected Methods
  1175. //--------------------------------------
  1176. /**
  1177. * @private
  1178. */
  1179. override protected function draw():void
  1180. {
  1181. var dataInvalid:Boolean = this.isInvalid(InvalidationType.DATA);
  1182. var stylesInvalid:Boolean = this.isInvalid(InvalidationType.STYLES);
  1183. var sizeInvalid:Boolean = this.isInvalid(InvalidationType.SIZE);
  1184. var axesInvalid:Boolean = this.isInvalid("axes")
  1185. super.draw();
  1186. if(stylesInvalid)
  1187. {
  1188. this.updateRenderers();
  1189. }
  1190. if(sizeInvalid || dataInvalid || stylesInvalid || axesInvalid)
  1191. {
  1192. this.drawAxes();
  1193. //the series display objects are dependant on the axes, so all series redraws must
  1194. //happen after the axes have redrawn
  1195. this.drawSeries();
  1196. }
  1197. this.updateLegend();
  1198. }
  1199. /**
  1200. * @private
  1201. * Make sure no numeric points exist. Convert to objects compatible with the axes.
  1202. */
  1203. override protected function refreshSeries():void
  1204. {
  1205. super.refreshSeries();
  1206. var numericAxis:IAxis = this.horizontalAxis;
  1207. var otherAxis:IAxis = this.verticalAxis;
  1208. if(this.verticalAxis is NumericAxis)
  1209. {
  1210. numericAxis = this.verticalAxis;
  1211. otherAxis = this.horizontalAxis;
  1212. }
  1213. var seriesCount:int = this.series.length;
  1214. for(var i:int = 0; i < seriesCount; i++)
  1215. {
  1216. var currentSeries:ISeries = this.series[i] as ISeries;
  1217. var numericField:String = this.axisAndSeriesToField(numericAxis, currentSeries);
  1218. var otherField:String = this.axisAndSeriesToField(otherAxis, currentSeries);
  1219. var seriesLength:int = currentSeries.length;
  1220. for(var j:int = 0; j < seriesLength; j++)
  1221. {
  1222. var item:Object = currentSeries.dataProvider[j];
  1223. if(item is Number || !isNaN(Number(item)))
  1224. {
  1225. //if we only have a number, then it is safe to convert
  1226. //to a default type for a category chart.
  1227. //if it's not a number, then the user is expected to update
  1228. //the x and y fields so that the plot area knows how to handle it.
  1229. var point:Object = {};
  1230. point[numericField] = item;
  1231. //we assume it's a category axis
  1232. if(this._explicitCategoryNames && this._explicitCategoryNames.length > 0)
  1233. {
  1234. point[otherField] = this.categoryNames[j];
  1235. }
  1236. else point[otherField] = j;
  1237. currentSeries.dataProvider[j] = point;
  1238. }
  1239. }
  1240. }
  1241. }
  1242. /**
  1243. * @private
  1244. * Creates the default axes. Without user intervention, the x-axis is a category
  1245. * axis and the y-axis is a numeric axis.
  1246. */
  1247. override protected function configUI():void
  1248. {
  1249. super.configUI();
  1250. //by default, the x axis is for categories. other types of charts will need
  1251. //to override this if they need a numeric or other type of axis
  1252. if(!this.horizontalAxis)
  1253. {
  1254. var categoryAxis:CategoryAxis = new CategoryAxis();
  1255. this.horizontalAxis = categoryAxis;
  1256. }
  1257. if(!this.horizontalAxisRenderer)
  1258. {
  1259. var RendererClass:Class = this.getStyleValue("horizontalAxisRenderer") as Class;
  1260. this.horizontalAxisRenderer = new RendererClass(AxisOrientation.HORIZONTAL);
  1261. this.addChild(DisplayObject(this.horizontalAxisRenderer));
  1262. this.horizontalAxis.renderer = this.horizontalAxisRenderer;
  1263. }
  1264. if(!this.verticalAxis)
  1265. {
  1266. var numericAxis:NumericAxis = new NumericAxis();
  1267. numericAxis.stackingEnabled = true;
  1268. this.verticalAxis = numericAxis;
  1269. }
  1270. if(!this.verticalAxisRenderer)
  1271. {
  1272. RendererClass = this.getStyleValue("verticalAxisRenderer") as Class;
  1273. this.verticalAxisRenderer = new RendererClass(AxisOrientation.VERTICAL);
  1274. this.addChild(DisplayObject(this.verticalAxisRenderer));
  1275. this.verticalAxis.renderer = this.verticalAxisRenderer;
  1276. }
  1277. }
  1278. /**
  1279. * @private
  1280. * Determines the text that will appear on the data tip.
  1281. */
  1282. override protected function defaultDataTipFunction(item:Object, index:int, series:ISeries):String
  1283. {
  1284. var text:String = super.defaultDataTipFunction(item, index, series);
  1285. if(text.length > 0)
  1286. {
  1287. text += "\n";
  1288. }
  1289. var categoryAxis:CategoryAxis = this.verticalAxis as CategoryAxis;
  1290. var otherAxis:IAxis = this.horizontalAxis;
  1291. if(!categoryAxis)
  1292. {
  1293. categoryAxis = this.horizontalAxis as CategoryAxis;
  1294. otherAxis = this.verticalAxis;
  1295. }
  1296. //if we have a category axis, the category is always displayed first
  1297. if(categoryAxis)
  1298. {
  1299. var categoryValue:Object = this.itemToAxisValue(series, index, categoryAxis, false);
  1300. text += categoryAxis.valueToLabel(categoryValue) + "\n";
  1301. var otherValue:Object = this.itemToAxisValue(series, index, otherAxis, false);
  1302. text += otherAxis.valueToLabel(otherValue) + "\n";
  1303. }
  1304. //otherwise, display the horizontal axis value first
  1305. else
  1306. {
  1307. var horizontalValue:Object = this.itemToAxisValue(series, index, this.horizontalAxis, false);
  1308. text += horizontalAxis.valueToLabel(horizontalValue) + "\n";
  1309. var verticalValue:Object = this.itemToAxisValue(series, index, this.verticalAxis, false);
  1310. text += verticalAxis.valueToLabel(verticalValue) + "\n";
  1311. }
  1312. return text;
  1313. }
  1314. /**
  1315. * @private
  1316. * Positions and updates the series objects.
  1317. */
  1318. protected function drawSeries():void
  1319. {
  1320. var contentPadding:Number = this.getStyleValue("contentPadding") as Number;
  1321. var seriesWidth:Number = this._contentBounds.width;
  1322. var seriesHeight:Number = this._contentBounds.height;
  1323. var contentScrollRect:Rectangle = new Rectangle(0, 0, seriesWidth, seriesHeight);
  1324. this.content.x = contentPadding + this._contentBounds.x;
  1325. this.content.y = contentPadding + this._contentBounds.y;
  1326. this.content.scrollRect = contentScrollRect;
  1327. var seriesCount:int = this.series.length;
  1328. for(var i:int = 0; i < seriesCount; i++)
  1329. {
  1330. var series:UIComponent = this.series[i] as UIComponent;
  1331. series.width = seriesWidth;
  1332. series.height = seriesHeight;
  1333. series.drawNow();
  1334. }
  1335. }
  1336. /**
  1337. * @private
  1338. * Removes the old axis renderers and create new instances.
  1339. */
  1340. protected function updateRenderers():void
  1341. {
  1342. //create axis renderers
  1343. if(this.horizontalAxisRenderer)
  1344. {
  1345. this.removeChild(DisplayObject(this.horizontalAxisRenderer));
  1346. this.horizontalAxisRenderer = null;
  1347. }
  1348. var RendererClass:Class = this.getStyleValue("horizontalAxisRenderer") as Class;
  1349. this.horizontalAxisRenderer = new RendererClass(AxisOrientation.HORIZONTAL);
  1350. this.addChild(DisplayObject(this.horizontalAxisRenderer));
  1351. this.copyStylesToChild(UIComponent(this.horizontalAxisRenderer), CartesianChart.HORIZONTAL_AXIS_STYLES);
  1352. this.copyStyleObjectToChild(UIComponent(this.horizontalAxisRenderer), this.getStyleValue("horizontalAxisStyles"));
  1353. var horizontalAxisTextFormat:TextFormat = this.getStyleValue("horizontalAxisTextFormat") as TextFormat;
  1354. if(horizontalAxisTextFormat)
  1355. {
  1356. UIComponent(this.horizontalAxisRenderer).setStyle("textFormat", horizontalAxisTextFormat);
  1357. }
  1358. if(this.verticalAxisRenderer)
  1359. {
  1360. this.removeChild(DisplayObject(this.verticalAxisRenderer));
  1361. this.verticalAxisRenderer = null;
  1362. }
  1363. RendererClass = this.getStyleValue("verticalAxisRenderer") as Class;
  1364. this.verticalAxisRenderer = new RendererClass(AxisOrientation.VERTICAL);
  1365. this.addChild(DisplayObject(this.verticalAxisRenderer));
  1366. this.copyStylesToChild(UIComponent(verticalAxisRenderer), CartesianChart.VERTICAL_AXIS_STYLES);
  1367. this.copyStyleObjectToChild(UIComponent(this.verticalAxisRenderer), this.getStyleValue("verticalAxisStyles"));
  1368. var verticalAxisTextFormat:TextFormat = this.getStyleValue("verticalAxisTextFormat") as TextFormat;
  1369. if(verticalAxisTextFormat)
  1370. {
  1371. UIComponent(this.verticalAxisRenderer).setStyle("textFormat", verticalAxisTextFormat);
  1372. }
  1373. //create grid lines renderers
  1374. if(this.horizontalGridLines)
  1375. {
  1376. this.removeChild(DisplayObject(this.horizontalGridLines));
  1377. }
  1378. RendererClass = this.getStyleValue("horizontalAxisGridLinesRenderer") as Class;
  1379. this.horizontalGridLines = new RendererClass();
  1380. this.horizontalGridLines.axisRenderer = this.horizontalAxisRenderer;
  1381. this.addChild(DisplayObject(this.horizontalGridLines));
  1382. this.copyStylesToChild(UIComponent(this.horizontalGridLines), CartesianChart.HORIZONTAL_GRID_LINES_STYLES);
  1383. this.copyStyleObjectToChild(UIComponent(this.horizontalGridLines), this.getStyleValue("horizontalAxisGridLinesStyles"));
  1384. if(this.verticalGridLines)
  1385. {
  1386. this.removeChild(DisplayObject(this.verticalGridLines));
  1387. }
  1388. RendererClass = this.getStyleValue("verticalAxisGridLinesRenderer") as Class;
  1389. this.verticalGridLines = new RendererClass();
  1390. this.verticalGridLines.axisRenderer = this.verticalAxisRenderer;
  1391. this.addChild(DisplayObject(this.verticalGridLines));
  1392. this.copyStylesToChild(UIComponent(this.verticalGridLines), CartesianChart.VERTICAL_GRID_LINES_STYLES);
  1393. this.copyStyleObjectToChild(UIComponent(this.verticalGridLines), this.getStyleValue("verticalAxisGridLinesStyles"));
  1394. }
  1395. /**
  1396. * @private
  1397. * Positions and sizes the axes based on their edge metrics.
  1398. */
  1399. protected function drawAxes():void
  1400. {
  1401. var contentPadding:Number = this.getStyleValue("contentPadding") as Number;
  1402. var axisWidth:Number = this.width - (2 * contentPadding);
  1403. var axisHeight:Number = this.height - (2 * contentPadding);
  1404. this.horizontalAxis.renderer = this.horizontalAxisRenderer;
  1405. if(horizontalAxis is CategoryAxis && this._explicitCategoryNames && this._explicitCategoryNames.length > 0)
  1406. {
  1407. CategoryAxis(this.horizontalAxis).categoryNames = this._explicitCategoryNames;
  1408. }
  1409. var horizontalAxisRenderer:UIComponent = UIComponent(this.horizontalAxisRenderer);
  1410. horizontalAxisRenderer.move(contentPadding, contentPadding);
  1411. horizontalAxisRenderer.setSize(axisWidth, axisHeight);
  1412. this.setChildIndex(horizontalAxisRenderer, this.numChildren - 1);
  1413. this.verticalAxis.renderer = this.verticalAxisRenderer;
  1414. if(verticalAxis is CategoryAxis && this._explicitCategoryNames && this._explicitCategoryNames.length > 0)
  1415. {
  1416. CategoryAxis(this.verticalAxis).categoryNames = this._explicitCategoryNames;
  1417. }
  1418. var verticalAxisRenderer:UIComponent = UIComponent(this.verticalAxisRenderer);
  1419. verticalAxisRenderer.move(contentPadding, contentPadding);
  1420. verticalAxisRenderer.setSize(axisWidth, axisHeight);
  1421. this.setChildIndex(verticalAxisRenderer, this.numChildren - 1);
  1422. //TODO: This should probably be done differently...
  1423. this.horizontalAxisRenderer.title = this.horizontalAxis.title;
  1424. this.verticalAxisRenderer.title = this.verticalAxis.title;
  1425. this.updateAxisScalesAndBounds();
  1426. horizontalAxisRenderer.drawNow();
  1427. verticalAxisRenderer.drawNow();
  1428. this.drawGridLines();
  1429. }
  1430. /**
  1431. * @private
  1432. * Determines the axis scales, and positions the axes based on their
  1433. * <code>contentBounds</code> properties.
  1434. */
  1435. protected function updateAxisScalesAndBounds():void
  1436. {
  1437. //reset the ticks and minor ticks (start with a clean axis)
  1438. this.horizontalAxisRenderer.ticks = [];
  1439. this.horizontalAxisRenderer.minorTicks = [];
  1440. this.verticalAxisRenderer.ticks = [];
  1441. this.verticalAxisRenderer.minorTicks = [];
  1442. /*
  1443. we need to run this a few times because the axis positions and
  1444. sizes are slowly corrected until they properly align themselves.
  1445. NOTE: If this seems to be failing, increase the loop count.
  1446. more iterations == more accuracy
  1447. worst case scenario: use a while loop and check to see if
  1448. calculateContentBounds() has made changes to the sizes or
  1449. positions of the renderers. if not, then break. if there have
  1450. been corrections, keep going. I suggest that you stop the loop
  1451. at 10 iterations because that's most likely an infinite loop.
  1452. you're probably only running into rounding errors at that point,
  1453. so there's little reason to continue anyway.
  1454. */
  1455. this.calculateContentBounds();
  1456. var count:int = 0;
  1457. do
  1458. {
  1459. var hOldContentBounds:Rectangle = this.horizontalAxisRenderer.contentBounds.clone();
  1460. var vOldContentBounds:Rectangle = this.verticalAxisRenderer.contentBounds.clone();
  1461. this._horizontalAxis.updateScale(this.series);
  1462. this._verticalAxis.updateScale(this.series);
  1463. this.calculateContentBounds();
  1464. count++;
  1465. }
  1466. //if count == 10, we're close enough
  1467. while(count < 10 &&
  1468. (!hOldContentBounds.equals(this.horizontalAxisRenderer.contentBounds) ||
  1469. !vOldContentBounds.equals(this.verticalAxisRenderer.contentBounds)))
  1470. }
  1471. /**
  1472. * @private
  1473. * Combine the content bounds to determine the series positioning.
  1474. */
  1475. protected function calculateContentBounds():void
  1476. {
  1477. this.horizontalAxisRenderer.updateBounds();
  1478. this.verticalAxisRenderer.updateBounds();
  1479. var contentPadding:Number = this.getStyleValue("contentPadding") as Number;
  1480. var axisWidth:Number = this.width - (2 * contentPadding);
  1481. var axisHeight:Number = this.height - (2 * contentPadding);
  1482. var horizontalAxisRenderer:UIComponent = this.horizontalAxisRenderer as UIComponent;
  1483. var verticalAxisRenderer:UIComponent = this.verticalAxisRenderer as UIComponent;
  1484. var horizontalBounds:Rectangle = this.horizontalAxisRenderer.contentBounds;
  1485. var verticalBounds:Rectangle = this.verticalAxisRenderer.contentBounds;
  1486. this._contentBounds = new Rectangle();
  1487. this._contentBounds.x = Math.max(horizontalBounds.x, verticalBounds.x);
  1488. this._contentBounds.y = Math.max(horizontalBounds.y, verticalBounds.y);
  1489. this._contentBounds.width = Math.min(horizontalBounds.width, verticalBounds.width);
  1490. this._contentBounds.height = Math.min(horizontalBounds.height, verticalBounds.height);
  1491. var hRight:Number = horizontalAxisRenderer.width - horizontalBounds.width - horizontalBounds.x;
  1492. var hBottom:Number = horizontalAxisRenderer.height - horizontalBounds.height - horizontalBounds.y;
  1493. var vRight:Number = verticalAxisRenderer.width - verticalBounds.width - verticalBounds.x;
  1494. var vBottom:Number = verticalAxisRenderer.height - verticalBounds.height - verticalBounds.y;
  1495. var contentBottom:Number = Math.max(hBottom, vBottom);
  1496. var contentRight:Number = Math.max(hRight, vRight);
  1497. horizontalAxisRenderer.x = contentPadding + this._contentBounds.