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