Source of Flex Finansdface

来源:百度文库 编辑:神马文学网 时间:2024/05/01 21:55:18
 0 && allowUpdateComplete){allowUpdateComplete = false;updateBoxFromSlider = true;updateBox();callLater(refreshAnnotations);this.visible = true;loadSampleAnnotations();}}/*** Simple parsing function to convert the date strings in our dataset to the equivalent Date object.*/private function dateParse(value:String):Date{var dateArray:Array = value.split('-');return new Date(dateArray[0], dateArray[1] - 1, dateArray[2]);}/*** Formats a date object from the DateTimeAxis into a label string*/private function formatDateLabel(value:Number, prevValue:Number, axis:DateTimeAxis):String{var dateValue:Date = new Date();dateValue.setTime(value + ((dateValue.timezoneOffset + 60) * 60 * 1000));switch(axis.labelUnits){case "months":return labelMonthFormatter.format(dateValue);break;case "days":return labelDayFormatter.format(dateValue);default:return labelDefaultFormatter.format(dateValue);break;}}/*Step 3 *//*** Called throughout use to update the mainData range of data that is displayed by slicing the* range data to the left and right values.*/private function updateMainData():void{mainData.source = rangeData.source.slice(leftIndicator.x, rightIndicator.x);refreshAnnotations();chartMouseOut();}/*** Called from the slider value changes.  It is filtered to only change when the slider calling it* directly.  The updateBoxFromSlider value is set to false when the moveSlider function effect is* playing because the box widths have already been set by the dividerRelease calling* updateIndicatorValuesWithEffect.*/private function updateBox():void{if(updateBoxFromSlider){//setting the box width value to the slider value times the ratio (to decrease                    //it to the equivalent width percentage                    //eg. full divided box width = 500, rangeDataRatio = 1/5 would equal 100 for the                    //proper left box width equal to range index value                    leftBox.width = slider.values[0] * rangeDataRatio;rightBox.width = dividedBox.width - ( slider.values[1] * rangeDataRatio );leftIndicator.x = slider.values[0];rightIndicator.x = slider.values[1];updateMainData();}}/*** Updates the range by moving the entire range left or right by a fixed number of units*/private function clickUpdate(value:int):void{leftIndicator.x += value; rightIndicator.x += value;slider.dispatchEvent(new SliderEvent('change'));}/*** Called from the divided box dividerRelease.  Calls a Move for the left and right Indicator* x values which has an easing function* applied.*/private function updateIndicatorValuesWithEffect():void{//setting indicator positions to the box width divided by the ratio (to increase                //it to the equivalent range value)                //eg. left box width = 100, rangeDataRation = 1/5 would equal 500 for the range index valuehideAnnotations();moveSlider(leftIndicator, (leftBox.width  / rangeDataRatio), false);moveSlider(rightIndicator, ((dividedBox.width - rightBox.width) / rangeDataRatio), false);}/*** Called from the thumbRelease on the slider instance, as well as creationComplete* to set the initial range values.* Updates the left and right indicator x values without the move effect.*/private function updateIndicatorsQuietly():void{//these two values are mapped 1:1 as the slider values and indicator values equal the rangeData length exactly                leftIndicator.x = slider.values[0];rightIndicator.x = slider.values[1];}/*** Moves the left and right indicator x values with an easing transition applied.  update* dictates whether this should update the divided box range measurements (false if we're calling this* from the divided box release) callbackFunc can be passed to get called when the move is finished.*/private function moveSlider(target:VRule, xTo:Number, update:Boolean, callbackFunc:Function = null, ... rest):void{var moveIndicator:Move = new Move();moveIndicator.end();moveIndicator.easingFunction = Cubic.easeOut;moveIndicator.duration = 750;moveIndicator.target = target;moveIndicator.xTo = xTo;moveIndicator.addEventListener(EffectEvent.EFFECT_START, function():void {updateBoxFromSlider = update});moveIndicator.addEventListener(TweenEvent.TWEEN_UPDATE, function():void { mainData.source = rangeData.source.slice(leftIndicator.x, rightIndicator.x);});moveIndicator.addEventListener(EffectEvent.EFFECT_END, function():void {updateBoxFromSlider = true;showAnnotations = true;callLater(refreshAnnotations);if(callbackFunc != null) callbackFunc.call(this, rest)});moveIndicator.play();}/*** Called from range chart or main chart and determines the position of the mouse as well as left* and right indicators (for static comparison when moving) and adds systemManager events* to capture mouse movement.  The values set here are used in the moveChart function to calculate* new position differences with start position*/private function setMouseDown(theChart:CartesianChart):void{//don't capture for drag if we're viewing the entire range of data                if(!(leftIndicator.x == 0 && rightIndicator.x == rangeData.length)){hideAnnotations();mouseXRef = this.mouseX;staticLeftBoundary = leftIndicator.x;staticRightBoundary = rightIndicator.x;if(theChart == mainChart) mainDrag = true;if(theChart == rangeChart) rangeDrag = true;this.systemManager.addEventListener(MouseEvent.MOUSE_MOVE, moveChart);this.systemManager.addEventListener(MouseEvent.MOUSE_UP, stopDragging);}}/*** Called when systemManager receives mouseUp event.  Sets the indicators for which range is* being dragged to false, and removes the system manager event listeners for drag movement.*/private function stopDragging(event:MouseEvent):void{if(mainData.length < 2){if(leftIndicator.x == rangeData.length){leftIndicator.x = rangeData.length - 5;rightIndicator.x = rangeData.length;}else if(rightIndicator.x == 0){leftIndicator.x = 0;rightIndicator.x = 5;}updateBox();}rangeDrag = false;mainDrag = false;this.systemManager.removeEventListener(MouseEvent.MOUSE_MOVE, moveChart);this.systemManager.removeEventListener(MouseEvent.MOUSE_UP, stopDragging);}/*** Determines which chart instance is being dragged, and updates the left and right indicator x values*/private function moveChart(event:MouseEvent):void{if(mainDrag){leftIndicator.x = staticLeftBoundary + (mouseXRef - this.mouseX) /(mainChartArea.width / mainData.length);rightIndicator.x = staticRightBoundary + (mouseXRef - this.mouseX) /(mainChartArea.width / mainData.length);}else if(rangeDrag){leftIndicator.x = staticLeftBoundary - (mouseXRef - this.mouseX) / rangeDataRatio;rightIndicator.x = staticRightBoundary - (mouseXRef - this.mouseX) / rangeDataRatio;}}/* Step 4 *//*** Finds the DateTimeAxis value (the date) of the mouseover position*/private function getChartDataPoint():void{//filtering to only run if the full dataset is present in the chart...                //this value is false if the indicator move effect is playing                if(updateBoxFromSlider){var chartPoint:Object = getChartCoordinates(new Point(mainChart.mouseX, mainChart.mouseY), mainChart);var formattedDate:String = fullDateFormat.format(new Date(chartPoint.x));for(var i:int = 0; i < mainData.length; i++){var dataItem:Object = mainData.getItemAt(i);if(dataItem.date == formattedDate){_selectedDate = labelSummaryDateFormatter.format(dateParse(dataItem.date));_selectedClose = 'Price: ' + dollarFormatter.format(Number(dataItem.close));_selectedVolume = 'Vol: ' + volumeFormatter.format(Number(dataItem.volume));mainChart.series[0].getChildAt(i + 1).showRenderer(true);mainChartVolume.series[0].getChildAt(i).showRenderer(true);}else{mainChart.series[0].getChildAt(i + 1).showRenderer(false);mainChartVolume.series[0].getChildAt(i).showRenderer(false);}}}}/*** Called when cursor is moved off of main chart area.  Clears any values that are bound* to mouseover position, and clears all* LineSeriesCustomRenderers on the chart that are showing*/private function chartMouseOut():void{if(mainData.length > 2){for(var i:int = 0; i < mainData.length; i++){try{mainChart.series[0].getChildAt(i + 1).showRenderer(false);mainChartVolume.series[0].getChildAt(i).showRenderer(false);}catch(e:Error) {};}_selectedDate = labelSummaryDateFormatter.format(dateParse(mainData.getItemAt(0).date)) + ' - ' +labelSummaryDateFormatter.format(dateParse(mainData.getItemAt(mainData.length - 1).date));_selectedClose = percentageFormatter.format((Number(mainData.getItemAt(mainData.length - 1).close) /Number(mainData.getItemAt(0).close) - 1) * 100) + '%';_selectedVolume = '';}else{_selectedDate = '';_selectedClose = '';_selectedVolume = '';}}/*** Finds the DateTimeAxis value (the date) of the mouseover position* invertTransform takes a point in stage space (x and y coordinate) and transforms it into the* relative point in data space, giving appropriate values along x axis (first item in return array),* and y axis (second item in return array)*/private function getChartCoordinates(thePos:Point, theChart:CartesianChart):Object{var tmpArray:Array;if(theChart.series[0] != null){tmpArray = theChart.series[0].dataTransform.invertTransform(thePos.x, thePos.y);return {x:tmpArray[0], y:tmpArray[1]};}else{return null;}}/*** Updates the date range display to reflect the current position of the divided box drag*/private function setDividerDragDate():void{var tmpLeftIndex:int = leftBox.width  / rangeDataRatio;var tmpRightIndex:int = ((dividedBox.width - rightBox.width) / rangeDataRatio) - 1;if(tmpLeftIndex >= 0 && tmpRightIndex <= rangeData.length){_selectedDate = labelSummaryDateFormatter.format(dateParse(rangeData.getItemAt(tmpLeftIndex).date)) + ' - ' +labelSummaryDateFormatter.format(dateParse(rangeData.getItemAt(tmpRightIndex).date));_selectedClose = percentageFormatter.format((Number(rangeData.getItemAt(tmpRightIndex).close) /Number(rangeData.getItemAt(tmpLeftIndex).close) - 1) * 100) + '%';_selectedVolume = '';}}/*Step 5 *//*** Prevents rollover or selection effects in the list control*/private function myEasingFunction(t:Number, b:Number, c:Number, d:Number):Number{return 0;}/*** Called from form entry for new annotation.  Creates an AnnotationVO instance with the form data, adds it to the array collection* and then sorts to include new annotation date and reset labels correspondingly.*/private function addAnnotation():void{annotationItems.addItem(new AnnotationVO(UIDUtil.createUID(),fullDateFormat.format(annDate.selectedDate),annDescription.text,false,''));var dateSort:Sort = new Sort();dateSort.fields = [new SortField("date", false, true)];dateSort.sort(annotationItems.source);setAnnotationLabels();annotationItems.refresh();refreshAnnotations();}/*** Whenever an annotation is added, this method is called to update the alphabetical letter*/private function setAnnotationLabels():void{for(var i:int = 0; i < annotationItems.length; i++){AnnotationVO(annotationItems[i]).letterLabel = alphabet[i];}};/*** This method is called from list of annotations when an instance is clicked.  It checks to see if the* annotation date is within the currently viewed range.  If not, it finds the appropriate index* value of the range data to expand to, calls the moveSlider function to move left or right to fit the range* and after the movement is completed, this function is re-called by the moveSlider end to check again.* If the item is within the viewable range, we loop through the array of anntations and sets selected to true* on the target annotation, and selected to false on all other annotations.  refreshAnnotations is then* called to update the annotation flags with the selected value*/public function hightlightAnnotation(args:Array):void{var targetUID:String = args[0];var targetDate:String = args[1];var i:int;var targetIndex:int;if(targetDate < mainData.getItemAt(0).date){for(i = 0; i < rangeData.length; i++){if(rangeData.getItemAt(i).date == targetDate){targetIndex = (i >= 10) ?  i - 10 : 0;break;}}showAnnotations = false;moveSlider(leftIndicator, targetIndex, true, hightlightAnnotation, targetUID, targetDate);}else if(targetDate > mainData.getItemAt(mainData.length - 1).date){for(i = 0; i < rangeData.length; i++){if(rangeData.getItemAt(i).date == targetDate){targetIndex = (i <= (rangeData.length - 11)) ?  i + 10 : 0;break;}}showAnnotations = false;moveSlider(rightIndicator, targetIndex, true, hightlightAnnotation, targetUID, targetDate);}else{for each(var annListItem:AnnotationVO in annotationItems){if(annListItem.annID == targetUID)annListItem.selected = true;elseannListItem.selected = false;}annotationItems.refresh();refreshAnnotations();}}/*** Loops through the array of annotation objects and sets selected on the target annotation.* refreshAnnotations is then called to update the annotation flags with the selected value*/private function highlightListAnnotation(event:Event):void{for each(var annListItem:AnnotationVO in annotationItems){if(annListItem.annID == event.target.annID)annListItem.selected = true;elseannListItem.selected = false;}refreshAnnotations();}/*** Loops through the array of annotation objects and looks for the data array item in the main chart* which matches this annotation's date.  When found, an EventAnnotation object is created and added to* the annotationCanvas (on annotationElements property of mainChart) and positioned to the AreaSeries* renderer instance for the datapoint on the chart.*/private function refreshAnnotations():void{if(mainData.length > 0){annotationCanvas.removeAllChildren();if(showAnnotations){var rangeStart:String = mainData.getItemAt(0).date;var rangeEnd:String = mainData.getItemAt(mainData.length - 1).date;//loop through the annotation instances                        for each(var annInstance:AnnotationVO in annotationItems){//if this annotations date is within the currently viewed range                            if(annInstance.date > rangeStart && annInstance.date < rangeEnd){for(var i:int = 0; i < mainData.length; i++){var dataItem:Object = mainData.getItemAt(i);//if this data itme matches our annotation, AND, if this isn't going to render                                    //off the edge of the graph                                    if(dataItem.date == annInstance.date && mainChart.series[0].numChildren >= i + 1){var newAnn:EventAnnotation = new EventAnnotation();newAnn.letterLabel = annInstance.letterLabel;newAnn.annID = annInstance.annID;newAnn.selected = annInstance.selected;//represents the LineSeriesCustomRenderer object for this datapoint on the chart                                        //adding one for our getChildAt to compensate for the area child of AreaChart                                        var foundItem:Object = mainChart.series[0].getChildAt(i + 1);newAnn.x = foundItem.x + 2;newAnn.y = foundItem.y -32;newAnn.addEventListener("annotationClicked", highlightListAnnotation);annotationCanvas.addChild(newAnn);}}}}}}}/*** removes all annotations showing on annotationCanvas and sets the showAnnotations flag to false.* called when the chart range is being changed by dragging the main or range chart, the divider* being released and the indicator moveSlider function is called.*/private function hideAnnotations():void{showAnnotations = false;annotationCanvas.removeAllChildren();}/*** Sample annotations*/private function loadSampleAnnotations():void{annotationItems.addItem(new AnnotationVO(UIDUtil.createUID(), '2007-03-15', 'Test Item 1', false, ''));annotationItems.addItem(new AnnotationVO(UIDUtil.createUID(), '2007-01-03', 'Test Item 2', false, ''));annotationItems.addItem(new AnnotationVO(UIDUtil.createUID(), '2006-11-29', 'Test Item 3', false, ''));annotationItems.addItem(new AnnotationVO(UIDUtil.createUID(), '2006-10-19', 'Test Item 4', false, ''));annotationItems.addItem(new AnnotationVO(UIDUtil.createUID(), '2006-09-12', 'Test Item 5', false, ''));annotationItems.addItem(new AnnotationVO(UIDUtil.createUID(), '2006-08-08', 'Test Item 6', false, ''));annotationItems.addItem(new AnnotationVO(UIDUtil.createUID(), '2006-07-14', 'Test Item 7', false, ''));setAnnotationLabels();}]]>