Exemplo n.º 1
0
        /// <summary>
        /// Generates and stores the default scaling information for the current canvas
        /// </summary>
        /// <param name="displayUnit">the unit of time covered by the viewport at one time</param>
        /// <param name="startTime">the time at which the canvas starts</param>
        /// <param name="endTime">the time at which the canvas ends</param>
        public GraphScaleData(FrameNodeLevel displayUnit, DateTime startTime, DateTime endTime, int totalFilters = 0)
        {
            DisplayUnit = displayUnit;
            Debug.Assert(displayUnit != FrameNodeLevel.Second);
            DateTime spanStart;

            _empty = true; //graph is initially empty
            TimeSpan span;

            switch (displayUnit)
            {
            case FrameNodeLevel.Root:
                span      = endTime.Subtract(startTime);
                spanStart = CanvasManager.FileManager.StartTime;
                break;

            case FrameNodeLevel.Year:
                spanStart = new DateTime(startTime.Year, 1, 1);
                span      = new DateTime(startTime.Year + 1, 1, 1).Subtract(spanStart);

                break;

            case FrameNodeLevel.Month:
                spanStart = new DateTime(startTime.Year, startTime.Month, 1);
                span      = spanStart.AddMonths(1).Subtract(spanStart);
                break;

            case FrameNodeLevel.Day:
                spanStart = new DateTime(startTime.Year, startTime.Month, startTime.Day);
                span      = spanStart.AddDays(1).Subtract(spanStart);
                break;

            case FrameNodeLevel.Hour:
                spanStart = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, 0, 0);
                span      = spanStart.AddHours(1).Subtract(spanStart);
                break;

            case FrameNodeLevel.PartHour:
                spanStart = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour,
                                         startTime.Minute - (startTime.Minute % 5), 0);
                span = spanStart.AddMinutes(5).Subtract(spanStart);
                break;

            case FrameNodeLevel.Minute:
                spanStart = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour,
                                         startTime.Minute, 0);
                span = spanStart.AddMinutes(1).Subtract(spanStart);
                break;

            default:
                throw new ArgumentOutOfRangeException("displayUnit", displayUnit, "GraphScaleData Constructor: RenderUnit out of range. Seconds cannot be subdivided, and are not valid.");
            }
            XShift       = (float)startTime.Subtract(spanStart).TotalSeconds;
            XShift      -= CanvasManager.TimeToOffset(spanStart);
            BaseScale    = (float)(span.TotalSeconds);
            TotalPackets = 0;
            TotalData    = 0;
            VertexCount  = 0;

            TotalMatchingPackets = new List <long>(totalFilters);
            MinMatchingCount     = new List <long>(totalFilters);
            MaxMatchingCount     = new List <long>(totalFilters);
            for (int k = 0; k < totalFilters; k++)
            {
                TotalMatchingPackets.Add(0);
                MinMatchingCount.Add(0);
                MaxMatchingCount.Add(0);
            }
        }
Exemplo n.º 2
0
 public void DrillLocation()
 {
     CanvasManager.Drill(_background.StartPosition, _background.EndPosition);
     SetCanvasData(CanvasManager.CurrentCanvasData);
 }
Exemplo n.º 3
0
        public void Generate(CanvasData data)
        {
            Debug.Assert(data.RenderUnit != FrameNodeLevel.Root); //cannot render at the root level

            var start = data.StartTime;
            var end   = data.EndTime;

            MajorOffsets.Clear();
            MinorOffsets.Clear();

            DateTime currMajor, currMinor, tmp;

            switch (data.RenderUnit)
            {
            case FrameNodeLevel.Year:
            case FrameNodeLevel.Month:
                currMinor = new DateTime(start.Year, 1, 1);
                tmp       = new DateTime(end.Year, 1, 1);
                if (end != tmp)
                {
                    end = tmp.AddYears(1);
                }

                while (currMinor <= end)
                {
                    MinorOffsets.Add(CanvasManager.TimeToOffset(currMinor));
                    currMinor = currMinor.AddYears(1);
                }
                MinorTickLevel = FrameNodeLevel.Year;
                break;

            case FrameNodeLevel.Day:
                currMajor = new DateTime(start.Year, 1, 1);
                currMinor = currMajor;     // end of first month
                tmp       = new DateTime(end.Year, 1, 1);
                if (end != tmp)
                {
                    end = tmp.AddYears(1);
                }

                while (currMajor <= end)
                {
                    MajorOffsets.Add(CanvasManager.TimeToOffset(currMajor));
                    currMajor = currMajor.AddYears(1);
                    while (currMinor < currMajor)
                    {
                        MinorOffsets.Add(CanvasManager.TimeToOffset(currMinor));
                        currMinor = currMinor.AddMonths(1);
                    }
                }
                MinorTickLevel = FrameNodeLevel.Month;
                break;

            case FrameNodeLevel.Hour:
                currMajor = new DateTime(start.Year, start.Month, 1);
                currMinor = currMajor;     // 2nd day
                tmp       = new DateTime(end.Year, end.Month, 1);
                if (end != tmp)
                {
                    end = tmp.AddMonths(1);
                }

                while (currMajor <= end)
                {
                    MajorOffsets.Add(CanvasManager.TimeToOffset(currMajor));
                    currMajor = currMajor.AddMonths(1);
                    while (currMinor < currMajor)
                    {
                        MinorOffsets.Add(CanvasManager.TimeToOffset(currMinor));
                        currMinor = currMinor.AddDays(1);
                    }
                }
                MinorTickLevel = FrameNodeLevel.Day;
                break;

            case FrameNodeLevel.PartHour:
                currMajor = new DateTime(start.Year, start.Month, start.Day);
                currMinor = currMajor;     // 2nd day
                tmp       = new DateTime(end.Year, end.Month, end.Day);
                if (end != tmp)
                {
                    end = tmp.AddDays(1);
                }

                while (currMajor <= end)
                {
                    MajorOffsets.Add(CanvasManager.TimeToOffset(currMajor));
                    currMajor = currMajor.AddDays(1);
                    while (currMinor < currMajor)
                    {
                        MinorOffsets.Add(CanvasManager.TimeToOffset(currMinor));
                        currMinor = currMinor.AddHours(1);
                    }
                }
                MinorTickLevel = FrameNodeLevel.Hour;
                break;

            case FrameNodeLevel.Minute:
                currMajor = new DateTime(start.Year, start.Month, start.Day, start.Hour, 0, 0);
                currMinor = currMajor;     // 2nd day
                tmp       = new DateTime(end.Year, end.Month, end.Day, start.Hour, 0, 0);
                if (end != tmp)
                {
                    end = tmp.AddHours(1);
                }

                while (currMajor <= end)
                {
                    MajorOffsets.Add(CanvasManager.TimeToOffset(currMajor));
                    currMajor = currMajor.AddHours(1);
                    while (currMinor < currMajor)
                    {
                        MinorOffsets.Add(CanvasManager.TimeToOffset(currMinor));
                        currMinor = currMinor.AddMinutes(10);
                    }
                }
                MinorTickLevel = FrameNodeLevel.PartHour;
                break;

            case FrameNodeLevel.Second:
                currMajor = new DateTime(start.Year, start.Month, start.Day, start.Hour, start.Minute - (start.Minute % 5), 0);
                currMinor = currMajor;     // 2nd day
                tmp       = new DateTime(end.Year, end.Month, end.Day, end.Hour, end.Minute - (start.Minute % 5), 0);
                if (end != tmp)
                {
                    end = tmp.AddMinutes(5);
                }

                while (currMajor <= end)
                {
                    MajorOffsets.Add(CanvasManager.TimeToOffset(currMajor));
                    currMajor = data.DisplayUnit == FrameNodeLevel.Minute ? currMajor.AddMinutes(1) : currMajor.AddMinutes(5);
                    while (currMinor < currMajor)
                    {
                        MinorOffsets.Add(CanvasManager.TimeToOffset(currMinor));
                        currMinor = data.DisplayUnit == FrameNodeLevel.Minute ? currMinor.AddSeconds(1) : currMinor.AddMinutes(1);
                    }
                }
                MinorTickLevel = FrameNodeLevel.Minute;
                break;

            default:
                throw new ArgumentOutOfRangeException("axisMajorLevel");
            }

            //generate major axis
            if (MajorOffsets.Count > 0)
            {
                _majorTick = new Vector2[MajorOffsets.Count * 2];
                _majorGrid = new Vector2[MajorOffsets.Count * 2];

                for (int k = 0; k < MajorOffsets.Count; k++)
                {
                    _majorTick[k * 2] = new Vector2(MajorOffsets[k], 0);
                    _majorGrid[k * 2] = new Vector2(MajorOffsets[k], 0);

                    _majorTick[k * 2 + 1] = new Vector2(MajorOffsets[k], -CanvasManager.TickSize * 2 * CanvasManager.PixelSize.X);
                    _majorGrid[k * 2 + 1] = new Vector2(MajorOffsets[k], 2);
                }

                _tickMajorBuffer.BindData(_majorTick);
                _gridMajorBuffer.BindData(_majorGrid);
            }
            else
            {
                _majorTick = null;
            }

            //generate minor axis if possible
            if (MinorOffsets.Count > 0)
            {
                _minorTick = new Vector2[MinorOffsets.Count * 2];
                _minorGrid = new Vector2[MinorOffsets.Count * 2];

                for (int k = 0; k < MinorOffsets.Count; k++)
                {
                    _minorTick[k * 2] = new Vector2(MinorOffsets[k], 0);
                    _minorGrid[k * 2] = new Vector2(MinorOffsets[k], 0);

                    _minorTick[k * 2 + 1] = new Vector2(MinorOffsets[k],
                                                        -(CanvasManager.TickSize * 2) * MinorTickScale * CanvasManager.PixelSize.X);
                    _minorGrid[k * 2 + 1] = new Vector2(MinorOffsets[k], 2);
                }
                _tickMinorBuffer.BindData(_minorTick);
                _gridMinorBuffer.BindData(_minorGrid);
            }
            else
            {
                _minorTick = null;
            }
        }