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.renderers
13{
14
15import flash.display.Graphics;
16import flash.geom.Rectangle;
17import mx.charts.ChartItem;
18import mx.charts.chartClasses.GraphicsUtilities;
19import mx.core.IDataRenderer;
20import mx.graphics.IFill;
21import mx.graphics.IStroke;
22import mx.skins.ProgrammaticSkin;
23import mx.graphics.SolidColor;
24import mx.utils.ColorUtil;
25
26/**
27 *  A simple chart itemRenderer implementation
28 *  that fills a rectangular area.
29 *  This class is the default itemRenderer for ColumnSeries and BarSeries objects.
30 *  It can be used as an itemRenderer for ColumnSeries, BarSeries, AreaSeries,
31 *  LineSeries, PlotSeries, and BubbleSeries objects.
32 *  This class renders its area on screen using the <code>fill</code> and <code>stroke</code> styles
33 *  of its associated series.
34 *
35 *  @langversion 3.0
36 *  @playerversion Flash 9
37 *  @playerversion AIR 1.1
38 *  @productversion Flex 3
39 */
40public class BoxItemRenderer extends ProgrammaticSkin implements IDataRenderer
41{
42    include "../../core/Version.as";
43
44	//--------------------------------------------------------------------------
45    //
46    //  Constructor
47    //
48    //--------------------------------------------------------------------------
49
50	/**
51	 *  Constructor.
52	 *
53	 *  @langversion 3.0
54	 *  @playerversion Flash 9
55	 *  @playerversion AIR 1.1
56	 *  @productversion Flex 3
57	 */
58	public function BoxItemRenderer()
59	{
60		super();
61	}
62
63    //--------------------------------------------------------------------------
64    //
65    //  Properties
66    //
67    //--------------------------------------------------------------------------
68
69    //----------------------------------
70	//  data
71    //----------------------------------
72
73	/**
74	 *  @private
75	 *  Storage for the data property.
76	 */
77	private var _data:Object;
78
79	[Inspectable(environment="none")]
80
81   	/**
82	 *  The chartItem that this itemRenderer is displaying.
83	 *  This value is assigned by the owning series
84	 *
85	 *  @langversion 3.0
86	 *  @playerversion Flash 9
87	 *  @playerversion AIR 1.1
88	 *  @productversion Flex 3
89	 */
90	public function get data():Object
91	{
92		return _data;
93	}
94
95	/**
96	 *  @private
97	 */
98	public function set data(value:Object):void
99	{
100		if (_data == value)
101			return;
102		_data = value;
103	}
104
105	//--------------------------------------------------------------------------
106    //
107    //  Overridden methods
108    //
109    //--------------------------------------------------------------------------
110
111	/**
112	 *  @private
113	 */
114	override protected function updateDisplayList(unscaledWidth:Number,
115												  unscaledHeight:Number):void
116	{
117		super.updateDisplayList(unscaledWidth, unscaledHeight);
118
119		var fill:IFill;
120		var state:String = "";
121
122		if (_data is ChartItem && _data.hasOwnProperty('fill'))
123		{
124			state = _data.currentState;
125			fill = _data.fill;
126		}
127		else
128		 	fill = GraphicsUtilities.fillFromStyle(getStyle('fill'));
129
130		var color:uint;
131		var adjustedRadius:Number = 0;
132
133		switch (state)
134		{
135			case ChartItem.FOCUSED:
136			case ChartItem.ROLLOVER:
137					if (styleManager.isValidStyleValue(getStyle('itemRollOverColor')))
138						color = getStyle('itemRollOverColor');
139					else
140						color = ColorUtil.adjustBrightness2(GraphicsUtilities.colorFromFill(fill),-20);
141					fill = new SolidColor(color);
142					adjustedRadius = getStyle('adjustedRadius');
143					if (!adjustedRadius)
144						adjustedRadius = 0;
145					break;
146			case ChartItem.DISABLED:
147					if (styleManager.isValidStyleValue(getStyle('itemDisabledColor')))
148						color = getStyle('itemDisabledColor');
149					else
150						color = ColorUtil.adjustBrightness2(GraphicsUtilities.colorFromFill(fill),20);
151					fill = new SolidColor(GraphicsUtilities.colorFromFill(color));
152					break;
153			case ChartItem.FOCUSEDSELECTED:
154			case ChartItem.SELECTED:
155					if (styleManager.isValidStyleValue(getStyle('itemSelectionColor')))
156						color = getStyle('itemSelectionColor');
157					else
158						color = ColorUtil.adjustBrightness2(GraphicsUtilities.colorFromFill(fill),-30);
159					fill = new SolidColor(color);
160					adjustedRadius = getStyle('adjustedRadius');
161					if (!adjustedRadius)
162						adjustedRadius = 0;
163					break;
164		}
165
166		var stroke:IStroke = getStyle("stroke");
167
168		var w:Number = stroke ? stroke.weight / 2 : 0;
169
170		var rc:Rectangle = new Rectangle(w - adjustedRadius, w - adjustedRadius, width - 2 * w + adjustedRadius * 2, height - 2 * w + adjustedRadius * 2);
171
172		var g:Graphics = graphics;
173		g.clear();
174		g.moveTo(rc.left,rc.top);
175		if (stroke)
176			stroke.apply(g,null,null);
177		if (fill)
178			fill.begin(g,rc,null);
179		g.lineTo(rc.right,rc.top);
180		g.lineTo(rc.right,rc.bottom);
181		g.lineTo(rc.left,rc.bottom);
182		g.lineTo(rc.left,rc.top);
183		if (fill)
184			fill.end(g);
185	}
186}
187
188}
189