Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.xxxx.charts {
- import com.xxxx.charts.chartClasses.GanttConfig;
- import com.xxxx.charts.chartClasses.Snapping;
- import com.xxxx.charts.renderers.DateAxisRenderer;
- import flash.events.Event;
- import flash.geom.Rectangle;
- import mx.charts.DateTimeAxis;
- import mx.collections.IList;
- import mx.core.ClassFactory;
- import mx.events.CollectionEvent;
- import mx.events.CollectionEventKind;
- import org.as3commons.lang.DateUtils;
- import spark.components.DataGroup;
- import spark.components.ResizeMode;
- import spark.formatters.DateTimeFormatter;
- import spark.layouts.HorizontalLayout;
- // jjh - event metadata
- public class DateAxis extends DataGroup implements IList {
- public static const RENDERER_WIDTH:int = 30;
- /**
- * MajorTick Days
- */
- public static const DAYS:String = "days";
- /**
- * Major Tick Months
- */
- public static const MONTHS:String = "months";
- /**
- * Major Ticks weeks
- */
- public static const WEEKS:String = "weeks"
- private static const DEBUG:Boolean = GanttConfig.DEBUG;
- private static const GAP:int = 0;
- private static const PADDING_LEFT:Number = 8;
- private var logger:GanttLogger = GanttLogger.get();
- /**
- *
- *
- */
- public function DateAxis() {
- super();
- dateFormatter = new DateTimeFormatter()
- dateFormatter.dateTimePattern = "MMM. dd";
- // set the dataGroup dataProvider to this(DateAxis) instance
- // since the DateAxis implements IList we can do this
- // and supply working logic for getItemIndex and any other
- // IList methods we may need for an "virtual" dataProvider
- dataProvider = this;
- itemRenderer = new ClassFactory(DateAxisRenderer);
- var layout:HorizontalLayout = new HorizontalLayout();
- layout.paddingLeft = PADDING_LEFT;
- layout.columnWidth = _tickWidth;
- layout.variableColumnWidth = false;
- layout.gap = _gap;
- layout.useVirtualLayout = true;
- minWidth = 600;
- this.layout = layout;
- this.clipAndEnableScrolling = true;
- }
- public function get dateTimePattern():String {
- return dateFormatter.dateTimePattern;
- }
- /**
- * Set the date pattern to use when formatting the dateAxis labels
- * @param value Format to use
- * @see spark.formatters.DateTimeFormatter
- *
- */
- public function set dateTimePattern(value:String):void {
- if (value != dateFormatter.dateTimePattern) {
- dateFormatter.dateTimePattern = value
- invalidateDisplayList();
- }
- }
- private var _endDate:Number
- /**
- * Returns the axis end date
- * @return
- *
- */
- public function get endDate():Number {
- return _endDate;
- }
- /**
- * Sets the axis end date
- * @param value Date since epoch
- *
- */
- public function set endDate(value:Number):void {
- if (_endDate != value) {
- _endDate = value;
- invalidateCache("endDate");
- }
- }
- private var _gap:Number = GAP;
- /**
- * Returns the gap between each tick
- * @return
- *
- */
- public function get gap():Number {
- return _gap;
- }
- /**
- * Sets the gap between each gap
- * @param value
- *
- */
- public function set gap(value:Number):void {
- if (value != _gap) {
- _gap = value;
- }
- }
- private var _hourInterval:int = 12;
- private var dataProviderChanged:Boolean
- /**
- * Return the hour interval
- * @return
- *
- */
- public function get hourInterval():int {
- return _hourInterval;
- }
- /**
- * Sets the hour interval
- * @param value A interval of 8,12 or 24
- * @default 12
- *
- */
- public function set hourInterval(value:int):void {
- if (value != _hourInterval) {
- _hourInterval = value;
- dataProviderChanged = true;
- invalidateCache();
- }
- }
- /**
- *
- * @inheritDoc
- *
- */
- public function get length():int {
- return _totalTicks;
- }
- private var _majorTickUnits:String = WEEKS;
- /**
- * Returns the units used for the major ticks
- * @return
- *
- */
- public function get majorTickUnits():String {
- return _majorTickUnits;
- }
- /**
- * Sets the major tick units
- * @param value
- *
- */
- public function set majorTickUnits(value:String):void {
- if (_majorTickUnits != value) {
- _majorTickUnits = value;
- dataProviderChanged = true;
- invalidateCache("majorTickUnits");
- }
- }
- private var _showMinorTicks:Boolean = true;
- /**
- * Wether or not we are showing the minor tick parts
- * @return
- *
- */
- public function get showMinorTicks():Boolean {
- return _showMinorTicks;
- }
- /**
- * Wether or not to show minor ticks when drawing
- * @param value To show minor ticks or not
- *
- */
- public function set showMinorTicks(value:Boolean):void {
- if (_showMinorTicks != value) {
- _showMinorTicks = value
- invalidateDisplayList();
- }
- }
- private var _startDate:Number
- /**
- * Returns the axis start date
- * @return
- *
- */
- public function get startDate():Number {
- return _startDate;
- }
- public function get axisStartDate():Number {
- return actualStartDate.time;
- }
- /**
- * Sets the start date of the axis
- * @param value Start date since epoch
- *
- */
- public function set startDate(value:Number):void {
- if (_startDate != value) {
- _startDate = value;
- invalidateCache("startDate");
- }
- }
- private var _tickWidth:Number = RENDERER_WIDTH;
- /**
- * Returns the width of the tick
- * @return
- *
- */
- public function get tickWidth():Number {
- return _tickWidth;
- }
- /**
- * Set the tick width
- * @param value
- *
- */
- public function set tickWidth(value:Number):void {
- if (value != tickWidth) {
- _tickWidth = value;
- }
- }
- private var _timeZoneOffset:Number = localTimeZoneOffset;
- private var _weekInterval:int = 5;
- /**
- * Retuns the week interval
- * @return
- *
- */
- public function get weekInterval():int {
- return _weekInterval;
- }
- [Inspectable(category = "Other", enumeration = "5,7", defaultValue = "5")]
- /**
- * Sets the week interval
- * @param value Days in a week to show 5 or 7
- * @default 5
- *
- */
- public function set weekInterval(value:int):void {
- if (value != _weekInterval) {
- _weekInterval = value;
- dataProviderChanged = true;
- invalidateCache();
- }
- }
- /**
- *
- * @inheritDoc
- *
- */
- override public function set width(value:Number):void {
- if (width != value) {
- invalidateCache()
- super.width = value;
- }
- }
- private var _totalTicks:int
- private var actualEndDate:Date = new Date();
- private var actualStartDate:Date = new Date();
- private var adjustedEndDate:Date
- private var adjustedStartDate:Date
- private var adjustedStartDateEpoch:Number
- private var adjustedEndDateEpoch:Number
- private var cacheIsDirty:Boolean
- /**
- * Cached date objected used for caculation
- * */
- private var cachedDate:Date = new Date();
- //private var dateCache:Vector.<Number> = new Vector.<Number>();
- // TODO : switch back to an optomized vector
- private var dateCache:Object = {};
- private var dateFormatter:DateTimeFormatter
- private var inCommitPropertiesAsDirty:Boolean
- private var localTimeZoneOffset:Number = new Date().timezoneOffset;
- private var minorSingleUnitMilliseconds:Number
- private var minorTickInterval:int
- private var majorTickValue:Number
- private var minorTickValue:Number
- /**
- *
- * @inheritDoc
- *
- */
- public function addItem(item:Object):void {
- }
- /**
- *
- * @inheritDoc
- *
- */
- public function addItemAt(item:Object, index:int):void {
- }
- public function containsDate(date:Number):Boolean {
- return date >= adjustedStartDateEpoch && date <= adjustedEndDateEpoch;
- }
- /**
- * Formats the date
- * @param value Can be an Number or Date object
- * @return
- *
- */
- public function formatDate(value:Object):String {
- // jjh - should talk about how to handle the date format since only some formats will work for
- // the major/minor tick settings. Might want to make this a non-settable, compile-time thing.
- // jjh - also, need to see how DateTimeFormatter handles localization.
- return dateFormatter.format(value);
- }
- /**
- * Returns the date found at a given index
- * @param index Zero based index
- * @return Date in epoch value
- *
- */
- public function getDateAt(index:Number):Number {
- return calculateDateByIndex(index);
- }
- /**
- * Returns the date denoted by the change, if 2 is passed, then the return value
- * will be 2 dates after the passed <code>date</code>, if -2 is passed then the return
- * value will be 2 days before the passed <code>date</code>
- * @param date The based date
- * @param change Change factor
- * @param snap snapping type
- * @param includeDifference If set to false the hours,seconds,milliseconds and minutes
- * will not be carried over to the computed date, thus using what caculateDateByIndex rounding
- * which defaults to an actual tick mark.
- * @return
- *
- */
- public function getDateBeforeOrAfter(date:Number, change:int, snap:String = "snapDown"
- , includeDifference:Boolean = true):Number {
- var index:int = getDateIndex(date, snap)
- index += change;
- if (index < 0)
- index = 0;
- var current:Date = new Date(date);
- var result:Date = new Date(calculateDateByIndex(index, false, true));
- if (includeDifference) {
- result.hours = current.hours;
- result.seconds = current.seconds;
- result.milliseconds = current.milliseconds;
- result.minutes = current.minutes;
- }
- return result.time;
- }
- /**
- * Returns the milliseconds difference between 1 tick
- * @return
- *
- */
- public function get singleTickDifference():int {
- return minorSingleUnitMilliseconds;
- }
- /**
- * Returns the date value from a giving X
- * @param x The x value to evaluate
- * @param snap
- * @param calculateAhead
- * @return Returns the date value for the x position passed, if caculateAhead is false then NaN is
- * returned if the date index isn't in the current endDate - startDate range
- *
- */
- public function getDateFromX(x:Number, snap:String = "snapDown", calculateAhead:Boolean = false):Number {
- var index:Number = getXIndex(x, snap, calculateAhead);
- var date:Number
- = (index < 0 || (index > length - 1 && !calculateAhead)) ? NaN : calculateDateByIndex(index
- , snap == Snapping.SNAP_NONE ? false : true);
- return date;
- }
- /**
- * Returns the index of the date based on the snapping provided
- * @param date Date to find index of
- * @param snap Snapping rule
- * @return
- *
- */
- public function getDateIndex(date:Number, snap:String = "snapDown"):Number {
- return applySnap(itemIndex(date), snap);
- }
- /**
- *
- * @inheritDoc
- *
- */
- public function getItemAt(index:int, prefetch:int = 0):Object {
- return inCommitPropertiesAsDirty ? null : calculateDateByIndex(index);
- }
- /**
- *
- * @inheritDoc
- *
- */
- public function getItemIndex(item:Object):int {
- return applySnap(itemIndex(item));
- }
- /**
- * Return the x position based by the date
- * @param date Can either be a Number or an Date object
- * @return
- *
- */
- public function getXFromDate(date:Object, snap:String = "snapDown"):Number {
- var index:Number = applySnap(itemIndex(date), snap);
- return PADDING_LEFT + (RENDERER_WIDTH * index) + (RENDERER_WIDTH >> 1);
- }
- public static var MONTHS_DAYS:Array = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
- private var cachedMonthFirstMondays:Object = {}
- /**
- * Checks to see if the passed date value is a major or minor tick
- * @param value Can be either an Date or Number object
- * @return
- *
- */
- public function isMajorTick(date:Number):Boolean {
- cachedDate.setTime(date);
- var matches:Boolean = true;
- switch (majorTickUnits) {
- case WEEKS:
- // sunday
- return minorTickInterval == 7 ? cachedDate.day == 0 : cachedDate.day == 1;
- break;
- case DAYS:
- // 8 am, 8pm
- // 9 am
- if ((minorTickInterval == 12 && cachedDate.hours == 8)
- || (minorTickInterval == 8 && cachedDate.hours == 9)
- || (minorTickInterval == 24 && cachedDate.hours == 8)) {
- return cachedDate.seconds == 0 && cachedDate.minutes == 0 && cachedDate.milliseconds == 0;
- }
- break;
- case MONTHS:
- var cacheKey:String = cachedDate.fullYear + "_" + cachedDate.month;
- logger.debug(this, "isMajorTick {0}", cachedDate);
- var firstMondayDate:Number = cachedMonthFirstMondays[cacheKey]
- if (isNaN(firstMondayDate)) {
- var firstMonday:Date = new Date(cachedDate.fullYear, cachedDate.month, 1);
- if (firstMonday.day != 1) {
- firstMonday.dateUTC += firstMonday.day == 0 ? 1 : (7 - firstMonday.day) + 1;
- }
- firstMondayDate = firstMonday.date;
- cachedMonthFirstMondays[cacheKey] = firstMondayDate;
- }
- return firstMondayDate == cachedDate.date;
- }
- return false;
- }
- /**
- *
- * @inheritDoc
- *
- */
- public function itemUpdated(item:Object, property:Object = null, oldValue:Object = null
- , newValue:Object = null):void {
- }
- /**
- *
- * @inheritDoc
- *
- */
- public function removeAll():void {
- }
- /**
- *
- * @inheritDoc
- *
- */
- public function removeItemAt(index:int):Object {
- return null;
- }
- /**
- *
- * @inheritDoc
- *
- */
- public function setItemAt(item:Object, index:int):Object {
- return null;
- }
- /**
- *
- * @inheritDoc
- *
- */
- public function toArray():Array {
- return null;
- }
- override protected function commitProperties():void {
- if (cacheIsDirty) {
- ensureMinorTickInterval();
- resizeCache();
- cacheIsDirty = false;
- inCommitPropertiesAsDirty = true;
- }
- super.commitProperties();
- inCommitPropertiesAsDirty = false;
- }
- protected function itemIndex(item:Object):Number {
- var dateValue:Number = Number(item);
- if (isNaN(dateValue))
- return -1;
- dateValue = offsetDate(dateValue);
- var index:Number;
- var len:int = length;
- const cache:Object = dateCache;
- var date:Number
- var start:Number
- var end:Number
- var i:int
- do {
- date = cache[i];
- if (!date) {
- date = calculateDateByIndex(i);
- }
- if (date > dateValue) {
- if (i == 0)
- i += 1;
- start = cache[i - 1];
- end = date;
- index = i - 1;
- break;
- }
- i++;
- } while (true);
- if (dateValue == start)
- return index;
- cachedDate.setTime(dateValue);
- // caculate themillisecond difference
- var mills:Number = cachedDate.seconds * DateUtils.MILLIS_PER_SECOND + cachedDate.milliseconds
- if (majorTickUnits != DAYS)
- mills += cachedDate.hours * DateUtils.MILLIS_PER_HOUR;
- return index + (mills / minorSingleUnitMilliseconds);
- return index;
- }
- override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
- var oldTotalTicks:int = length;
- if (oldTotalTicks) {
- // check if we need to draw more ticks from a resize
- var newTotalTicks:int = caculateTotalTicks(adjustedStartDateEpoch, caculateMaxEndDate())
- if (newTotalTicks > oldTotalTicks) {
- dispatchDataProviderChangeEvent(oldTotalTicks, newTotalTicks);
- }
- }
- super.updateDisplayList(unscaledWidth, unscaledHeight);
- }
- private function handleDaylightSavings(oldEpoch:Number, newEpoch:Number):Number {
- cachedDate.setTime(oldEpoch);
- var result:Date = new Date(newEpoch);
- var originalHours:int = cachedDate.hours;
- if (originalHours != result.hours) {
- if (result.hours > 0) { // spring back
- result.hoursUTC -= result.hours;
- } else { // fall back
- result.hoursUTC += (24 - (result.hours - originalHours))
- }
- }
- var originalMinutes:int = cachedDate.minutes;
- if (originalMinutes != result.minutes)
- result.minutesUTC -= (result.minutes - originalMinutes);
- /*var originalOffset:int = cachedDate.getTimezoneOffset()
- if (originalOffset != result.getTimezoneOffset())
- result.minutesUTC -= (result.getTimezoneOffset() - originalOffset);*/
- return result.time
- }
- private function addToDateInContext(lastComputedIndex:int, amount:Number, withOffset:Boolean = true):Number {
- lastComputedIndex = lastComputedIndex < 0 ? 0 : lastComputedIndex;
- var lastComputedDate:Number = dateCache[lastComputedIndex];
- //lastComputedDate = offsetDate(lastComputedDate);
- var property:String
- var interval:int;
- var checkForDST:Boolean = true;
- switch (_majorTickUnits) {
- case WEEKS:
- property = "dateUTC";
- interval = 1;
- break;
- case DAYS:
- property = "hoursUTC";
- checkForDST = false;
- interval = 1;
- break;
- case MONTHS:
- property = "dateUTC";
- interval = 7;
- break;
- }
- // do on the fly computing, this happens when
- // we resize the viewing range and the virtualLayout only picks
- // up the items in view
- var cacheLength:int = length;
- var cacheIndex:int = lastComputedIndex;
- var oldDay:int
- for (var i:int; i < amount; i++) {
- cachedDate.setTime(lastComputedDate);
- oldDay = cachedDate.date;
- cachedDate[property] += interval;
- if (withOffset) {
- if (checkForDST) {
- lastComputedDate = handleDaylightSavings(lastComputedDate, offsetDate(cachedDate.time));
- } else {
- lastComputedDate = offsetDate(cachedDate.time);
- }
- } else if (checkForDST) {
- lastComputedDate = handleDaylightSavings(lastComputedDate, cachedDate.time);
- } else {
- lastComputedDate = cachedDate.time;
- }
- cacheIndex += 1;
- if (withOffset && !cachedDate[cacheIndex]) {
- dateCache[cacheIndex] = lastComputedDate;
- /*if(cacheIndex+1 >dateCache.length)
- dateCache.length = _totalTicks=cacheIndex*/
- }
- }
- return lastComputedDate;
- }
- private function caculateMaxEndDate():Number {
- var maxWidthEndDate:Number = getDateFromX(width, Snapping.SNAP_UP, true);
- actualEndDate.setTime(maxWidthEndDate > _endDate ? maxWidthEndDate : _endDate);
- if (actualEndDate.hours != 0) {
- adjustedEndDate = DateUtils.getEndOfDay(DateUtils.addDays(actualEndDate, 1));
- } else {
- adjustedEndDate = DateUtils.getEndOfDay(actualEndDate);
- }
- return adjustedEndDate.time;
- }
- private function caculateTotalTicks(start:Number, end:Number):int {
- var totalTime:Number = (end - start);
- return Math.ceil((totalTime / majorTickValue) * minorTickValue);
- }
- /**
- * The main function of the DateAxis, this function is called upon many other functions
- * @param index The index to caculate
- * @param snap The snapping rule
- * @param caculateAhead Should we allow to caculate ahead
- * @param withOffset When set to true we will call the offsetDate method to apply any
- * offet rules
- * @return
- *
- */
- private function calculateDateByIndex(index:Number, snap:Boolean = true, caculateAhead:Boolean = true
- , withOffset:Boolean = true):Number {
- const clampedIndex:int = int(index);
- const inRange:Boolean = clampedIndex >= 0 && clampedIndex < length;
- if (inRange && snap && dateCache[clampedIndex]) {
- return dateCache[clampedIndex];
- }
- var date:Number
- var maxCached:int = length;
- var lastComputedIndex:int;
- // try to find the last computed index so we dont have to compute from the start
- //in most cases this is index-1, but allows us to compute ahead by an x factor
- for (lastComputedIndex = clampedIndex - 1; lastComputedIndex > 0; lastComputedIndex--) {
- if (lastComputedIndex < maxCached && dateCache[lastComputedIndex]) {
- break;
- }
- }
- if (lastComputedIndex == -1)
- lastComputedIndex = 0;
- var indexDifference:Number = index - lastComputedIndex;
- var multipler:int
- var remainder:Number
- var clampedDate:Number
- if (snap) {
- clampedDate = date = addToDateInContext(lastComputedIndex, indexDifference)
- } else {
- // snap since we can have index difference of .<value>
- multipler = int(indexDifference);
- remainder = indexDifference - multipler;
- clampedDate = date = addToDateInContext(lastComputedIndex, multipler, withOffset)
- date += (minorSingleUnitMilliseconds * remainder);
- }
- return date;
- }
- private function ensureMinorTickInterval():void {
- switch (_majorTickUnits) {
- case WEEKS:
- switch (_weekInterval) {
- case 5:
- case 7:
- break;
- default:
- weekInterval = 5;
- }
- break;
- case DAYS:
- switch (_hourInterval) {
- case 8:
- case 12:
- case 24:
- break;
- default:
- hourInterval = 24;
- }
- }
- }
- private function applySnap(value:Number, snap:String = "snapDown"):Number {
- if (snap == Snapping.SNAP_DOWN) {
- value = Math.floor(value);
- } else if (snap == Snapping.SNAP_UP) {
- value = Math.ceil(value)
- } else if (snap == Snapping.SNAP_CLOSEST) {
- value = Math.round(value);
- }
- return value;
- }
- private function getXIndex(x:Number, snap:String = "snapDown", calculateAhead:Boolean = false):Number {
- // ensure that the index is witin the range
- var index:Number = ((x - PADDING_LEFT) - (RENDERER_WIDTH >> 1)) / RENDERER_WIDTH;
- if (index < 0)
- index = 0;
- return applySnap(index, snap);
- }
- private function invalidateCache(causedBy:String = null):void {
- cacheIsDirty = true;
- invalidateProperties();
- invalidateSize();
- invalidateDisplayList();
- if (causedBy) {
- // majorTick, startDate, endDate
- var eventType:String = causedBy + "Changed";
- if (hasEventListener(eventType))
- dispatchEvent(new Event(eventType))
- }
- dispatchEvent(new Event("dateAxisInvalidated"));
- }
- private function offsetDate(date:Number, resizing:Boolean = false):Number {
- cachedDate.setTime(date);
- var oldDate:Number = date;
- var offsetApplied:Boolean
- if (majorTickUnits == WEEKS && minorTickInterval == 5) {
- var oldDay:int = cachedDate.date;
- if (cachedDate.day == 0) {
- offsetApplied = true;
- // sunday
- cachedDate.dateUTC += 1;
- date = cachedDate.time;
- } else if (cachedDate.day == 6) {
- offsetApplied = true;
- // saturday
- cachedDate.dateUTC += 2
- date = cachedDate.time;
- }
- if (offsetApplied) {
- while (cachedDate.day != 1) {
- cachedDate.dateUTC += 1;
- cachedDate.hours = 0;
- }
- date = cachedDate.time;
- }
- }
- if (majorTickUnits == DAYS) {
- if (minorTickInterval == 8) {
- if (cachedDate.hours > 17) { // later then 5pm
- // if the date is the startDate then we need apply a special case, so we have some room to include the real start date
- cachedDate.dateUTC += resizing ? -1 : 1;
- offsetApplied = true;
- } else if (cachedDate.hours < 9) {
- offsetApplied = true;
- }
- if (offsetApplied) {
- cachedDate.hours = 9;
- cachedDate.milliseconds = 0;
- cachedDate.seconds = 0;
- cachedDate.minutes = 0;
- date = cachedDate.time;
- }
- }
- if (minorTickInterval == 12) {
- if (cachedDate.hours > 19) { // later then 8pm go to next day
- // if the date is the startDate then we need apply a special case, so we have some room to include the real start date
- //
- cachedDate.dateUTC += resizing ? -1 : 1;
- offsetApplied = true;
- } else if (cachedDate.hours < 8) {
- offsetApplied = true;
- }
- if (offsetApplied) {
- cachedDate.hours = 8;
- cachedDate.milliseconds = 0;
- cachedDate.seconds = 0;
- cachedDate.minutes = 0;
- date = cachedDate.time;
- }
- }
- }
- return date;
- }
- private function resizeCache():void {
- if (isNaN(_startDate) || isNaN(_endDate))
- return;
- actualStartDate.setTime(_startDate);
- switch (majorTickUnits) {
- case WEEKS:
- minorSingleUnitMilliseconds = DateUtils.MILLIS_PER_DAY
- minorTickValue = 7;
- minorTickInterval = _weekInterval; // seven days in a week
- actualStartDate.hours = 0;
- actualStartDate.milliseconds = 0;
- actualStartDate.seconds = 0;
- actualStartDate.minutes = 0;
- break;
- case DAYS:
- minorSingleUnitMilliseconds = DateUtils.MILLIS_PER_HOUR;
- minorTickValue = 24; // 24 hours in a day
- minorTickInterval = _hourInterval;
- actualStartDate.setTime(offsetDate(_startDate, true));
- actualStartDate.milliseconds = 0;
- actualStartDate.minutes = 0;
- actualStartDate.seconds = 0;
- break;
- case MONTHS:
- minorSingleUnitMilliseconds = DateUtils.MILLIS_PER_DAY * 7;
- minorTickValue = 4 // in most cases 4 weeks in a month
- if (actualStartDate.day != 1) {
- if (actualStartDate.day > 1) {
- actualStartDate.dateUTC -= (actualStartDate.day - 1);
- } else if (actualStartDate.day) {
- actualStartDate.dateUTC -= 5;
- }
- }
- actualStartDate.hours = 0;
- actualStartDate.milliseconds = 0;
- actualStartDate.minutes = 0;
- actualStartDate.seconds = 0;
- break;
- }
- cachedMonthFirstMondays = {};
- dateCache = {};
- adjustedStartDateEpoch = offsetDate(actualStartDate.time);
- dateCache[0] = adjustedStartDateEpoch;
- var oldTotalTicks:int = _totalTicks;
- _totalTicks = 0;
- // always ensure that ticks fill up atleast 600pixels
- var mesureWidth:Number = width < 600 ? 600 : width;
- var hl:HorizontalLayout = HorizontalLayout(layout);
- hl.requestedMinColumnCount = Math.round(600 / (RENDERER_WIDTH + GAP));
- hl.requestedMaxColumnCount = mesureWidth / (RENDERER_WIDTH + GAP)
- majorTickValue = minorSingleUnitMilliseconds * minorTickValue;
- var currentTotalTicks:int = caculateTotalTicks(adjustedStartDateEpoch, caculateMaxEndDate())
- dispatchDataProviderChangeEvent(oldTotalTicks, currentTotalTicks);
- }
- private function dispatchDataProviderChangeEvent(old:int, current:int):void {
- var event:CollectionEvent = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
- if (dataProviderChanged) {
- event.kind = CollectionEventKind.REFRESH;
- dataProviderChanged = false;
- } else {
- if (old > current) {
- event.kind = CollectionEventKind.REMOVE;
- event.items = new Array(old - current);
- event.location = current;
- } else if (old < current) {
- event.kind = CollectionEventKind.ADD;
- event.items = new Array(current - old);
- event.location = old;
- }
- }
- if (event.kind) {
- dispatchEvent(event);
- }
- _totalTicks = current;
- dateCache.length = current;
- }
- }
- }
Add Comment
Please, Sign In to add comment