PageRenderTime 101ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/charts/as/com/yahoo/astra/fl/charts/CartesianChart.as

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