1////////////////////////////////////////////////////////////////////////////////
2//
3//  ADOBE SYSTEMS INCORPORATED
4//  Copyright 2009 Adobe Systems Incorporated
5//  All Rights Reserved.
6//
7//  NOTICE: Adobe permits you to use, modify, and distribute this file
8//  in accordance with the terms of the license agreement accompanying it.
9//
10////////////////////////////////////////////////////////////////////////////////
11
12package mx.charts
13{
14
15import flash.filters.DropShadowFilter;
16
17import mx.charts.chartClasses.CartesianChart;
18import mx.charts.chartClasses.DataTip;
19import mx.charts.chartClasses.IAxis;
20import mx.charts.renderers.LineRenderer;
21import mx.charts.styles.HaloDefaults;
22import mx.core.ClassFactory;
23import mx.core.IFlexModuleFactory;
24import mx.core.mx_internal;
25import mx.graphics.SolidColor;
26import mx.graphics.SolidColorStroke;
27import mx.graphics.Stroke;
28import mx.styles.CSSStyleDeclaration;
29
30use namespace mx_internal;
31
32[DefaultBindingProperty(destination="dataProvider")]
33
34[DefaultTriggerEvent("itemClick")]
35
36[IconFile("LineChart.png")]
37
38/**
39 *  The LineChart control represents a data series
40 *  as points connected by a continuous line.
41 *  You can use an icon or symbol to represent each data point
42 *  along the line, or show a simple line with no icons.
43 *
44 *  <p>The LineChart control expects its <code>series</code> property
45 *  to contain an Array of LineSeries objects.</p>
46 *
47 *  @mxml
48 *
49 *  The <code>&lt;mx:LineChart&gt;</code> tag inherits all the properties
50 *  of its parent classes and adds the following properties:</p>
51 *
52 *  <pre>
53 *  &lt;mx:LineChart
54 *  /&gt;
55 *  </pre>
56 *
57 *  @includeExample examples/Line_AreaChartExample.mxml
58 *
59 *  @see mx.charts.series.LineSeries
60 *
61 *  @langversion 3.0
62 *  @playerversion Flash 9
63 *  @playerversion AIR 1.1
64 *  @productversion Flex 3
65 */
66public class LineChart extends CartesianChart
67{
68    include "../core/Version.as";
69
70    //--------------------------------------------------------------------------
71    //
72    //  Class initialization
73    //
74    //--------------------------------------------------------------------------
75
76
77    //--------------------------------------------------------------------------
78    //
79    //  Constructor
80    //
81    //--------------------------------------------------------------------------
82
83    /**
84     *  Constructor.
85     *
86     *  @langversion 3.0
87     *  @playerversion Flash 9
88     *  @playerversion AIR 1.1
89     *  @productversion Flex 3
90     */
91    public function LineChart()
92    {
93        super();
94
95        LinearAxis(horizontalAxis).autoAdjust = false;
96
97        seriesFilters = [ new DropShadowFilter() ];
98    }
99
100    //--------------------------------------------------------------------------
101    //
102    //  Variables
103    //
104    //--------------------------------------------------------------------------
105
106    /**
107     *  @private
108     */
109    private var _moduleFactoryInitialized:Boolean = false;
110
111    //--------------------------------------------------------------------------
112    //
113    //  Overridden properties
114    //
115    //--------------------------------------------------------------------------
116
117    //----------------------------------
118    //  horizontalAxis
119    //----------------------------------
120
121    [Inspectable(category="Data")]
122
123    /**
124     *  @private
125     */
126    override public function set horizontalAxis(value:IAxis):void
127    {
128        if (value is CategoryAxis)
129            CategoryAxis(value).padding = 0;
130
131        super.horizontalAxis = value;
132    }
133
134    //--------------------------------------------------------------------------
135    //
136    //  Overridden methods: UIComponent
137    //
138    //--------------------------------------------------------------------------
139
140    /**
141     *  @private
142     */
143    private function initStyles():Boolean
144    {
145        HaloDefaults.init(styleManager);
146
147        var lineChartSeriesStyles:Array /* of Object */ = [];
148
149		var lineChartStyle:CSSStyleDeclaration = styleManager.getStyleDeclaration("mx.charts.LineChart");
150		lineChartStyle.setStyle("chartSeriesStyles", lineChartSeriesStyles);
151		lineChartStyle.setStyle("fill", new SolidColor(0xFFFFFF, 0));
152		lineChartStyle.setStyle("calloutStroke", new SolidColorStroke(0x888888,2));
153		lineChartStyle.setStyle("horizontalAxisStyleNames", ["hangingCategoryAxis"]);
154		lineChartStyle.setStyle("verticalAxisStyleNames", ["blockNumericAxis"]);
155
156        var n:int = HaloDefaults.defaultColors.length;
157        for (var i:int = 0; i < n; i++)
158        {
159            var styleName:String = "haloLineSeries" + i;
160            lineChartSeriesStyles[i] = styleName;
161
162            var o:CSSStyleDeclaration =
163                HaloDefaults.createSelector("." + styleName, styleManager);
164
165            var f:Function = function(o:CSSStyleDeclaration, stroke:Stroke):void
166            {
167                o.defaultFactory = function():void
168                {
169                    this.lineStroke = stroke;
170                    this.stroke = stroke;
171                    this.lineSegmentRenderer = new ClassFactory(LineRenderer);
172                }
173            }
174
175            f(o, new Stroke(HaloDefaults.defaultColors[i], 3, 1));
176        }
177
178        return true;
179    }
180
181    /**
182     *   A module factory is used as context for using embedded fonts and for finding the style manager that controls the styles for this component.
183     *
184     *  @langversion 3.0
185     *  @playerversion Flash 9
186     *  @playerversion AIR 1.1
187     *  @productversion Flex 3
188     */
189    override public function set moduleFactory(factory:IFlexModuleFactory):void
190    {
191        super.moduleFactory = factory;
192
193        if (_moduleFactoryInitialized)
194            return;
195
196        _moduleFactoryInitialized = true;
197
198        // our style settings
199        initStyles();
200    }
201}
202
203}
204