<?xml version="1.0" encoding="utf-8"?>
<!--
////////////////////////////////////////////////////////////////////////////////
// 株式会社　アイエルエス
// Copyright 2010 ILS
// All Rights Reserved.
//
// NOTICE:円グラフ
////////////////////////////////////////////////////////////////////////////////
-->
<GcPanel 
	xmlns="bizLibrary.sharedComponent.*"
	xmlns:mx="http://www.adobe.com/2006/mxml"
	width="{Application.application.width}"
	height="{Application.application.height}" 
	creationComplete="onCreationComplete()"
	resize="true"
	>

    <!-- データモデルの定義 -->
	
	<mx:Script>
		<![CDATA[
			import mx.collections.XMLListCollection;
			import mx.charts.series.BarSeries;
			import mx.core.Application;
			import mx.controls.Image;
			import mx.charts.HitData;
			import mx.charts.DateTimeAxis;
			import mx.charts.CategoryAxis;
			import mx.charts.chartClasses.Series;
			import mx.charts.chartClasses.ChartBase;
			import mx.collections.ArrayCollection;
			import mx.events.ItemClickEvent;
			import mx.charts.series.ColumnSeries;
			import mx.charts.Legend;
			import mx.core.DragSource;
			import mx.containers.Canvas;
			import mx.charts.events.LegendMouseEvent;
			import mx.charts.LegendItem;
			import mx.controls.Alert;
			import mx.core.UIComponent;
			import mx.charts.series.LineSeries;
			import mx.managers.DragManager;
			import mx.events.DragEvent;
			import mx.managers.PopUpManager;

			//一覧情報
			[Bindable]
			public var dataModel:XML;
	        public var selData:XML;
			

			//private var itemList:Array = new Array;
			private var lcRegionSeries:Array = new Array;

			private var chart:ChartBase;
			private var series:Series;
			
			
			/**
			 * 共通初期化処理
			 * 
			 */		
			private function onCreationComplete():void{
	            //外部設定ファイルの読込      
	            getXMLFile(setChart);
			}

			/**
			 * グラフの設定
			 * 
			 */					
	        private function setChart():void{
				//グラフデータの設定
			    dataModel = xmlData;
			    selData = XML(dataModel.data.chart);

				//グラフタイトルのセット
	        	lblTitle.text = dataModel.data.grapfTitle.toString();
	        	if(lblTitle.text==""){
	        		boxTitleArea.visible = false;
	        	}
			    
			    
			    //カテゴリリストの作成
				createCategoryList(selData.axis);
				//カテゴリコンボボックスの設定
				if(categorylist.length == 0){
					cmbCateGory.visible = false;
				}else{
					//Magicに埋め込むとコンボボックスが使用できないため、visibleをfalseに変更
					cmbCateGory.visible = false;
					cmbCateGory.dataProvider = categorylist;
					//初期値の設定
					cmbCateGory.selectedItem = categorylist[0];	
				}
				
				makeChart();
				        	
	        }
	        
			/**
			 * グラフ作成
			 */				
			private function makeChart():void{
								
				//カテゴリコンボボックスの設定
				if(categorylist.length == 0){
					pcRegion.dataProvider = sortSeq(selData.item);
				}else{
					pcRegion.dataProvider = sortSeq(selData.item.(category==cmbCateGory.text));
				}
				
			}

			
	        private function getSliceLabel(item:Object, arg2:String, arg3:Number, arg4:Number):String
	        {
	            return item==null?"":item.name.slice(0,30);
	        }
			
	        private function formatDataTip(hitData:HitData):String
	        {
	            var name:String = hitData.item.name;
	            var category:String = hitData.item.category;
	            var value:Number = hitData.item.value;
	            return "<b>"+name+"</b><br>"+category+"<br>"+suDisplay.format(value);
	        }
            


		]]>
	</mx:Script>
	
	<mx:NumberFormatter id="suDisplay" 
		decimalSeparatorTo="."
		thousandsSeparatorTo=","
		useThousandsSeparator="true"/>
		
    <mx:VBox id="boxChart" left="0" right="0" verticalGap="0" height="100%">
	    <mx:HBox id="boxTitleArea" horizontalGap="0" >
	    	<mx:Label id="lblTitle" fontWeight="bold" paddingLeft="20" fontSize="12" />
	    </mx:HBox>
	    
	    <mx:HBox id="boxCategory" horizontalGap="0" paddingLeft="20" >
	    	<mx:ComboBox id="cmbCateGory" change="callLater(makeChart)"/>
	    </mx:HBox>
	    
	    <mx:Canvas id="cnv2" label="cv2" width="100%" height="100%"  horizontalScrollPolicy="off" verticalScrollPolicy="off">
	    	<mx:HBox width="100%" height="100%" id="lineBox" horizontalGap="0">
			    <mx:PieChart id="pcRegion" width="80%" height="{cnv2.height}" 
			    	showDataTips="true"
					paddingTop="0"
			    	paddingBottom="0"
			        dataTipFunction="formatDataTip"
			        >        
			        <mx:series>
			            <mx:Array>
			                <mx:PieSeries  startAngle="90" id="psView" nameField="name" field="value" 
			                	labelFunction="getSliceLabel"
			                	>
			                </mx:PieSeries>
			            </mx:Array>
			        </mx:series>
				</mx:PieChart>
			
				<mx:HBox height="{cnv2.height}" width="20%" horizontalScrollPolicy="off">
					<mx:Legend id="legend1" dataProvider="{pcRegion}" maxWidth="180"/>
				</mx:HBox>	    	
				    	
		    </mx:HBox>
		</mx:Canvas>    	
    </mx:VBox>

</GcPanel>
