コード例 #1
0
ファイル: DrawSetArgs.cs プロジェクト: huizh/xenadmin
 public MouseActionArgs(Point p, Rectangle r, DataTimeRange xrange, DataRange yrange)
 {
     Point = p;
     Rectangle = r;
     XRange = xrange;
     YRange = yrange;
 }
コード例 #2
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (ArchiveMaintainer == null || ArchiveMaintainer.LoadingInitialData)
            {
                return;
            }

            // Do the same thing for everything here for consistency
            DataTimeRange everything = CurrentArchiveRange;

            if (MouseDragging == DragMode.New && e.X == MouseDragStart)
            {
                LongPoint virtualclicked = LongPoint.DeTranslateFromScreen(new LongPoint(e.Location), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle));
                long      proposedoffset = ArchiveMaintainer.GraphNow.Ticks - (virtualclicked.X + (GraphWidth.Ticks / 2));

                GraphOffset = TimeSpan.FromTicks(proposedoffset > 0 ? proposedoffset : 0);
            }

            TimerScroll = ScrollMode.None;
            Scroller.Stop();

            AutoScaleGraph();

            GridSpacing = BodgeSpacing(GraphWidth);
            RefreshXRange(false);

            MouseDragging = DragMode.None;
            MouseResizing = ResizeMode.None;
        }
コード例 #3
0
ファイル: LongPoint.cs プロジェクト: huizh/xenadmin
        /// <summary>
        /// Virtual to Screen XY
        /// </summary>
        public static LongPoint TranslateToScreen(LongPoint virtualpoint, DataTimeRange xrange, DataRange yrange, LongRectangle rectangle)
        {
            if (xrange.Delta == 0 || yrange.Delta == 0)
            {
                // have seen this happen when we try to render graphs after the host failed to install a vm
                // doesn't matter too much what we return as the VM entry is going to get removed. Just don't crash.
                log.ErrorFormat("Tried to translate datapoint through range of zero. xrange.Delta: {0}, yrange.Delta: {1}",
                    xrange.Delta, yrange.Delta);
                return new LongPoint(0, 0);
            }
            // work out x, assume origin is bottom right
            double x = rectangle.Right - ((rectangle.Width * (virtualpoint.X - xrange.Min)) / xrange.Delta);

            // work out y
            double y = rectangle.Bottom - ((rectangle.Height * (virtualpoint.Y - yrange.Min)) / yrange.Delta);

            y = y > rectangle.Bottom ? rectangle.Bottom : y < rectangle.Y ? rectangle.Y : y;

            if (x >= ARBITRARY_MICROSOFT_LINE_MAX_LENGTH && y >= ARBITRARY_MICROSOFT_LINE_MAX_LENGTH)
            {
                log.DebugFormat("Point translated to more than max line length: x={0} y={1} vx={2} vy={3} xrange_min={4} xrange_max={5} yrange_min={6} yrange_max={7} rectangle_x={8} rectangle_y={9} rectangle_w={10} rectangle_h={11}",
                    x, y,
                    virtualpoint.X, virtualpoint.Y,
                    xrange.Min, xrange.Max,
                    yrange.Min, yrange.Max,
                    rectangle.X, rectangle.Y,
                    rectangle.Width, rectangle.Height);

                // draw a random line as this is better than crashing
                return new LongPoint(0, 0);
            }

            return new LongPoint((long)x, (long)y);
        }
コード例 #4
0
        public List <DataPoint> GetRange(DataTimeRange xrange, long intervalneed, long intervalat)
        {
            List <DataPoint> fine = BinaryChop(Points, xrange);

            if (fine.Count == 0)
            {
                return(new List <DataPoint>());
            }
            fine.Reverse();
            List <DataPoint> listout     = new List <DataPoint>();
            double           cumulativey = 0;
            int count = 0;

            foreach (DataPoint p in fine)
            {
                var secSince1970 = Util.TicksToSecondsSince1970(new DateTime(p.X).ToUniversalTime().Ticks);

                if (secSince1970 % (intervalneed / TimeSpan.TicksPerSecond) == secSince1970 % (intervalat / TimeSpan.TicksPerSecond))
                {
                    listout.Insert(0, new DataPoint(p.X, count != 0 ? cumulativey / count : p.Y));
                    cumulativey = 0;
                    count       = 0;
                }
                else
                {
                    cumulativey += p.Y;
                    count++;
                }
            }
            if (count != 0)
            {
                listout.Insert(0, new DataPoint(fine[fine.Count - 1].X, cumulativey / count));
            }
            return(listout);
        }
コード例 #5
0
ファイル: LongPoint.cs プロジェクト: zhukaixy/xenadmin-yeesan
        /// <summary>
        /// Virtual to Screen XY
        /// </summary>
        public static LongPoint TranslateToScreen(LongPoint virtualpoint, DataTimeRange xrange, DataRange yrange, LongRectangle rectangle)
        {
            if (xrange.Delta == 0 || yrange.Delta == 0)
            {
                // have seen this happen when we try to render graphs after the host failed to install a vm
                // doesn't matter too much what we return as the VM entry is going to get removed. Just don't crash.
                log.ErrorFormat("Tried to translate datapoint through range of zero. xrange.Delta: {0}, yrange.Delta: {1}",
                                xrange.Delta, yrange.Delta);
                return(new LongPoint(0, 0));
            }
            // work out x, assume origin is bottom right
            double x = rectangle.Right - ((rectangle.Width * (virtualpoint.X - xrange.Min)) / xrange.Delta);

            // work out y
            double y = rectangle.Bottom - ((rectangle.Height * (virtualpoint.Y - yrange.Min)) / yrange.Delta);

            y = y > rectangle.Bottom ? rectangle.Bottom : y < rectangle.Y ? rectangle.Y : y;

            if (x >= ARBITRARY_MICROSOFT_LINE_MAX_LENGTH && y >= ARBITRARY_MICROSOFT_LINE_MAX_LENGTH)
            {
                log.DebugFormat("Point translated to more than max line length: x={0} y={1} vx={2} vy={3} xrange_min={4} xrange_max={5} yrange_min={6} yrange_max={7} rectangle_x={8} rectangle_y={9} rectangle_w={10} rectangle_h={11}",
                                x, y,
                                virtualpoint.X, virtualpoint.Y,
                                xrange.Min, xrange.Max,
                                yrange.Min, yrange.Max,
                                rectangle.X, rectangle.Y,
                                rectangle.Width, rectangle.Height);

                // draw a random line as this is better than crashing
                return(new LongPoint(0, 0));
            }

            return(new LongPoint((long)x, (long)y));
        }
コード例 #6
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (ArchiveMaintainer == null || ArchiveMaintainer.LoadingInitialData)
            {
                return;
            }

            DataTimeRange everything = CurrentArchiveRange;

            long selectedleft  = LongPoint.TranslateToScreen(new LongPoint(GraphLeft.Ticks, 1), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle)).X;
            long selectedright = LongPoint.TranslateToScreen(new LongPoint(GraphRight.Ticks, 1), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle)).X;

            if (e.Location.X > selectedleft - 3 && e.Location.X < selectedleft + 3)
            {
                MouseResizing = ResizeMode.Left;
            }
            else if (e.Location.X > selectedright - 3 && e.Location.X < selectedright + 3)
            {
                MouseResizing = ResizeMode.Right;
            }
            else if (e.Location.X > selectedleft - 3 && e.Location.X < selectedright + 3)
            {
                MouseDragging = DragMode.Existing;
            }
            else
            {
                MouseDragStart = e.X;
                MouseDragging  = DragMode.New;
            }
        }
コード例 #7
0
ファイル: LongPoint.cs プロジェクト: hl10502/XenCenter
        /// <summary>
        /// Screen XY to Virtual
        /// </summary>
        public static LongPoint DeTranslateFromScreen(LongPoint screenpoint, DataTimeRange xrange, DataRange yrange, LongRectangle rectangle)
        {
            // work out x, assume origin is bottom right
            double x = xrange.Min + (xrange.Delta * (rectangle.Right - screenpoint.X)) / (double)rectangle.Width;

            // work out y
            double y = yrange.Min + (yrange.Delta * (rectangle.Bottom - screenpoint.Y)) / (double)rectangle.Height;

            return(new LongPoint((long)x, (long)y));
        }
コード例 #8
0
ファイル: DataSet.cs プロジェクト: zhaoyingpu/xenadmin
        public List <DataPoint> BinaryChop(List <DataPoint> points, DataTimeRange xrange)
        {
            if (xrange.Delta > 0)
            {
                log.DebugFormat("Get range: Delta should be negative, max={0}, min={1}", xrange.Max, xrange.Min);
                return(new List <DataPoint>());
            }
            // if there are no points or none are in range
            if (points == null || points.Count == 0 || points[points.Count - 1].X >= xrange.Min || points[0].X <= xrange.Max)
            {
                return(new List <DataPoint>());
            }

            int startindex = GetStart(points, xrange.Min, 0, points.Count);

            int endindex = GetStart(points, xrange.Max, 0, points.Count) + 1;

            if (endindex > 0 && endindex != points.Count)
            {
                endindex++;
            }

            if (startindex == -1 && endindex <= 0)
            {
                return(new List <DataPoint>());
            }

            if (startindex == -1)
            {
                if (endindex <= points.Count)
                {
                    return(points.GetRange(0, endindex));
                }
                else
                {
                    return(new List <DataPoint>());
                }
            }

            if (endindex <= 0)
            {
                if (startindex < points.Count)
                {
                    return(points.GetRange(startindex, points.Count - startindex));
                }
                else
                {
                    return(new List <DataPoint>());
                }
            }

            System.Diagnostics.Trace.Assert(startindex >= 0 && startindex <points.Count && endindex >= 0 && endindex <= points.Count && endindex> startindex, string.Format("Argument exception: startindex={0}; endindex={1}; points.Count={2}", startindex, endindex, points.Count));

            return(points.GetRange(startindex, endindex - startindex));
        }
コード例 #9
0
ファイル: DataEventList.cs プロジェクト: huizh/xenadmin
        public void RenderEvents(Graphics graphics, DataTimeRange xrange, Rectangle bounds, int spaceheight)
        {
            if (DataEvents == null)
                return;

            foreach (DataEvent vent in DataEvents)
            {
                if (vent.X < xrange.Max || vent.X > xrange.Min)
                    continue;

                LongPoint loc = LongPoint.TranslateToScreen(vent.Point, xrange, DataRange.UnitRange, new LongRectangle(bounds));
                vent.DrawToBuffer(graphics, loc.Point, bounds, spaceheight);
            }
        }
コード例 #10
0
ファイル: LineRenderer.cs プロジェクト: huizh/xenadmin
        public static void Render(Graphics g, Rectangle r, DataTimeRange xrange, DataRange yrange, Pen pen, Brush graphShadow, List<DataPoint> points, bool showselections)
        {
            if (points.Count == 0)
                return;

            int index = points.FindIndex(dataPoint => dataPoint.Y < 0);
            if (index >= 0)
            {
                //CA-38898: when there are no data from the server we do not want
                //to show anything; leave gaps instead of making up data (zeros or inf)
                DoRender(g, r, xrange, yrange, pen, graphShadow, points.Where((val, idx) => idx < index).ToList(), showselections);
                Render(g, r, xrange, yrange, pen, graphShadow, points.Where((val, idx) => idx > index).ToList(), showselections);
            }
            else
            {
                DoRender(g, r, xrange, yrange, pen, graphShadow, points, showselections);
            }
        }
コード例 #11
0
        public void RenderEvents(Graphics graphics, DataTimeRange xrange, Rectangle bounds, int spaceheight)
        {
            if (DataEvents == null)
            {
                return;
            }

            foreach (DataEvent vent in DataEvents)
            {
                if (vent.X < xrange.Max || vent.X > xrange.Min)
                {
                    continue;
                }

                LongPoint loc = LongPoint.TranslateToScreen(vent.Point, xrange, DataRange.UnitRange, new LongRectangle(bounds));
                vent.DrawToBuffer(graphics, loc.Point, bounds, spaceheight);
            }
        }
コード例 #12
0
        public static void Render(Graphics g, Rectangle r, DataTimeRange xrange, DataRange yrange, Pen pen, Brush graphShadow, List <DataPoint> points, bool showselections)
        {
            if (points.Count == 0)
            {
                return;
            }

            int index = points.FindIndex(dataPoint => dataPoint.Y < 0);

            if (index >= 0)
            {
                //CA-38898: when there are no data from the server we do not want
                //to show anything; leave gaps instead of making up data (zeros or inf)
                DoRender(g, r, xrange, yrange, pen, graphShadow, points.Where((val, idx) => idx < index).ToList(), showselections);
                Render(g, r, xrange, yrange, pen, graphShadow, points.Where((val, idx) => idx > index).ToList(), showselections);
            }
            else
            {
                DoRender(g, r, xrange, yrange, pen, graphShadow, points, showselections);
            }
        }
コード例 #13
0
        public void RefreshXRange(bool from_tick)
        {
            if (skip_tick && from_tick)
            {
                skip_tick = false;
                return;
            }

            if (!from_tick)
            {
                skip_tick = true;
            }

            XRange = new DataTimeRange(GraphLeft, GraphRight, GraphResolution);

            if (RangeChanged != null)
            {
                RangeChanged();
            }

            RefreshBuffer();
        }
コード例 #14
0
ファイル: DataPlotNav.cs プロジェクト: huizh/xenadmin
        public void RefreshXRange(bool from_tick)
        {
            if (skip_tick && from_tick)
            {
                skip_tick = false;
                return;
            }

            if (!from_tick)
                skip_tick = true;

            XRange = new DataTimeRange(GraphLeft, GraphRight, GraphResolution);

            if (RangeChanged != null)
                RangeChanged();

            RefreshBuffer();
        }
コード例 #15
0
ファイル: LongPoint.cs プロジェクト: huizh/xenadmin
 /// <summary>
 /// Screen XY to Virtual
 /// </summary>
 public static LongPoint DeTranslateFromScreen(LongPoint screenpoint, DataTimeRange xrange, DataRange yrange, LongRectangle rectangle)
 {
     // work out x, assume origin is bottom right
     double x = xrange.Min + (xrange.Delta * (rectangle.Right - screenpoint.X)) / (double)rectangle.Width;
     
     // work out y
     double y = yrange.Min + (yrange.Delta * (rectangle.Bottom - screenpoint.Y)) / (double)rectangle.Height;
     
     return new LongPoint((long)x, (long)y);
 }
コード例 #16
0
ファイル: DataPlotNav.cs プロジェクト: huizh/xenadmin
 public List<DataPoint> GetFinerPoints(DataSet set, DataTimeRange range, ArchiveInterval current)
 {
     return set.GetRange(range, ArchiveMaintainer.ToTicks(current), ArchiveMaintainer.ToTicks(ArchiveMaintainer.NextArchiveDown(current)));
 }
コード例 #17
0
ファイル: LineRenderer.cs プロジェクト: huizh/xenadmin
        private static void DoRender(Graphics g, Rectangle r, DataTimeRange xrange, DataRange yrange, Pen pen, Brush graphShadow, List<DataPoint> points, bool showselections)
        {
            if (points.Count == 0)
                return;

            // draw line 'tween points
            LongPoint locbase = LongPoint.TranslateToScreen(points[0].Point, xrange, yrange, new LongRectangle(r));

            List<Point> PointsToDraw = new List<Point>();

            for (int i = 1; i < points.Count; i++)
            {
                LongPoint loc = LongPoint.TranslateToScreen(points[i].Point, xrange, yrange, new LongRectangle(r));

                if (locbase.X == loc.X) continue;

                if (locbase.X > r.Right && loc.X < r.Left)
                {
                    // trim it to the Y axis
                    double delta = (double)(locbase.Y - loc.Y) / (locbase.X - loc.X);
                    int dxl = r.Left - (int)locbase.X;
                    int dxr = r.Right - (int)loc.X;
                    int newyr = (int)(delta * dxr);
                    int newyl = (int)(delta * dxl);
                    
                    PointsToDraw.Add(new Point(r.Right, newyr + (int)loc.Y));
                    PointsToDraw.Add(new Point(r.Left, newyl + (int)locbase.Y));
                    break;
                }
                else if (locbase.X > r.Right)
                {
                    // trim it to the Y axis
                    double delta = (double)(locbase.Y - loc.Y) / (locbase.X - loc.X);
                    int dx = r.Right - (int)loc.X;
                    int newy = (int)(delta * dx);
                    
                    PointsToDraw.Add(new Point(r.Right, newy + (int)loc.Y));
                }
                else if (loc.X < r.Left)
                {
                    // trim it to the Y axis
                    double delta = (double)(locbase.Y - loc.Y) / (locbase.X - loc.X);
                    int dx = r.Left - (int)locbase.X;
                    int newy = (int)(delta * dx);
                    
                    PointsToDraw.Add(locbase.Point);
                    PointsToDraw.Add(new Point(r.Left, newy + (int)locbase.Y));
                    break;
                }
                else
                {
                    PointsToDraw.Add(locbase.Point);
                    if (i == points.Count - 1)
                        PointsToDraw.Add(loc.Point);
                }
                if (points[i].Show && showselections)
                {
                    g.DrawRectangle(pen, new Rectangle((int)loc.X - 2, (int)loc.Y - 2, 4, 4));
                }
                locbase = loc;
            }
            if (PointsToDraw.Count <= 1)
                return;

            g.DrawLines(pen, PointsToDraw.ToArray());

            if (graphShadow == null)
                return;

            PointsToDraw.Add(new Point(PointsToDraw[PointsToDraw.Count - 1].X, r.Bottom));
            PointsToDraw.Add(new Point(PointsToDraw[0].X, r.Bottom));
            g.FillPolygon(graphShadow, PointsToDraw.ToArray());
        }
コード例 #18
0
        private static void DoRender(Graphics g, Rectangle r, DataTimeRange xrange, DataRange yrange, Pen pen, Brush graphShadow, List <DataPoint> points, bool showselections)
        {
            if (points.Count == 0)
            {
                return;
            }

            // draw line 'tween points
            LongPoint locbase = LongPoint.TranslateToScreen(points[0].Point, xrange, yrange, new LongRectangle(r));

            List <Point> PointsToDraw = new List <Point>();

            for (int i = 1; i < points.Count; i++)
            {
                LongPoint loc = LongPoint.TranslateToScreen(points[i].Point, xrange, yrange, new LongRectangle(r));

                if (locbase.X == loc.X)
                {
                    continue;
                }

                if (locbase.X > r.Right && loc.X < r.Left)
                {
                    // trim it to the Y axis
                    double delta = (double)(locbase.Y - loc.Y) / (locbase.X - loc.X);
                    int    dxl   = r.Left - (int)locbase.X;
                    int    dxr   = r.Right - (int)loc.X;
                    int    newyr = (int)(delta * dxr);
                    int    newyl = (int)(delta * dxl);

                    PointsToDraw.Add(new Point(r.Right, newyr + (int)loc.Y));
                    PointsToDraw.Add(new Point(r.Left, newyl + (int)locbase.Y));
                    break;
                }
                else if (locbase.X > r.Right)
                {
                    // trim it to the Y axis
                    double delta = (double)(locbase.Y - loc.Y) / (locbase.X - loc.X);
                    int    dx    = r.Right - (int)loc.X;
                    int    newy  = (int)(delta * dx);

                    PointsToDraw.Add(new Point(r.Right, newy + (int)loc.Y));
                }
                else if (loc.X < r.Left)
                {
                    // trim it to the Y axis
                    double delta = (double)(locbase.Y - loc.Y) / (locbase.X - loc.X);
                    int    dx    = r.Left - (int)locbase.X;
                    int    newy  = (int)(delta * dx);

                    PointsToDraw.Add(locbase.Point);
                    PointsToDraw.Add(new Point(r.Left, newy + (int)locbase.Y));
                    break;
                }
                else
                {
                    PointsToDraw.Add(locbase.Point);
                    if (i == points.Count - 1)
                    {
                        PointsToDraw.Add(loc.Point);
                    }
                }
                if (points[i].Show && showselections)
                {
                    g.DrawRectangle(pen, new Rectangle((int)loc.X - 2, (int)loc.Y - 2, 4, 4));
                }
                locbase = loc;
            }
            if (PointsToDraw.Count <= 1)
            {
                return;
            }

            g.DrawLines(pen, PointsToDraw.ToArray());

            if (graphShadow == null)
            {
                return;
            }

            PointsToDraw.Add(new Point(PointsToDraw[PointsToDraw.Count - 1].X, r.Bottom));
            PointsToDraw.Add(new Point(PointsToDraw[0].X, r.Bottom));
            g.FillPolygon(graphShadow, PointsToDraw.ToArray());
        }
コード例 #19
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (ArchiveMaintainer == null || ArchiveMaintainer.LoadingInitialData)
            {
                return;
            }

            DataTimeRange everything     = CurrentArchiveRange;
            LongPoint     virtualclicked = LongPoint.DeTranslateFromScreen(new LongPoint(e.Location), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle));
            long          selectedleft   = LongPoint.TranslateToScreen(new LongPoint(GraphLeft.Ticks, 1), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle)).X;
            long          selectedright  = LongPoint.TranslateToScreen(new LongPoint(GraphRight.Ticks, 1), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle)).X;

            if (MouseDragging == DragMode.Existing)
            {
                long proposedoffset = ArchiveMaintainer.GraphNow.Ticks - (virtualclicked.X + (GraphWidth.Ticks / 2));

                if (proposedoffset + GraphWidth.Ticks > ScrollViewOffset.Ticks + ScrollViewWidth.Ticks)
                {
                    //  -------------------------
                    // |  _______________________|____________________________________
                    // | |      -------------    |           _______--------          |
                    // | |     /             \___|__________/               \         |
                    // | |----                   |                           ----    -|
                    // | |_______________________|_______________________________\__/_|
                    //  -------------------------
                    //
                    // we have scrolled too far left (off the scroll view)

                    GraphOffset = TimeSpan.FromTicks(ScrollViewWidth.Ticks + ScrollViewOffset.Ticks - GraphWidth.Ticks);
                }
                else if (proposedoffset < ScrollViewOffset.Ticks)
                {
                    //                                       -------------------------
                    //   ___________________________________|_______________________  |
                    // |      -------------                _|_____--------          | |
                    // |     /             \______________/ |             \         | |
                    // |----                                |              ----    -| |
                    // |____________________________________|__________________\__/_| |
                    //                                       -------------------------
                    //
                    // we have scrolled too far right (off the scroll view)
                    if (GraphOffset == ScrollViewOffset)
                    {
                        return;
                    }
                    GraphOffset = ScrollViewOffset;
                }
                else
                {
                    //              -------------------------
                    //  ___________|_________________________|______________________
                    // |      -----|-------                __|____--------          |
                    // |     /     |       \______________/  |            \         |
                    // |----       |                         |             ----    -|
                    // |___________|_________________________|_________________\__/_|
                    //              -------------------------
                    //
                    // everything is fine, we are in the middle

                    GraphOffset = TimeSpan.FromTicks(proposedoffset > 0 ? proposedoffset : 0);
                }

                if (GraphOffset.Ticks + GraphWidth.Ticks - ScrollViewOffset.Ticks > 0.90 * ScrollViewWidth.Ticks)
                {
                    ScrollStrength = TimeSpan.FromTicks(GraphOffset.Ticks + GraphWidth.Ticks - (ScrollViewOffset.Ticks + (long)(0.90 * ScrollViewWidth.Ticks)));
                    TimerScroll    = ScrollMode.Left;
                    Scroller.Start();
                }
                else if (GraphOffset.Ticks - ScrollViewOffset.Ticks < 0.1 * ScrollViewWidth.Ticks)
                {
                    ScrollStrength = TimeSpan.FromTicks((long)(0.1 * ScrollViewWidth.Ticks) - (GraphOffset.Ticks - ScrollViewOffset.Ticks));
                    TimerScroll    = ScrollMode.Right;
                    Scroller.Start();
                }
                else
                {
                    TimerScroll = ScrollMode.None;
                }
            }
            else if (MouseDragging == DragMode.New)
            {
                LongPoint virtualstart = LongPoint.DeTranslateFromScreen(new LongPoint(MouseDragStart, 1), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle));
                if (e.X > MouseDragStart && e.X < ScrollViewRectangle.Width)
                {
                    GraphOffset = new TimeSpan(ArchiveMaintainer.GraphNow.Ticks - virtualclicked.X);
                    GraphWidth  = new TimeSpan(virtualclicked.X - virtualstart.X);
                }
                else if (e.X < MouseDragStart && e.X > 0)
                {
                    GraphOffset = new TimeSpan(ArchiveMaintainer.GraphNow.Ticks - virtualstart.X);
                    GraphWidth  = new TimeSpan(virtualstart.X - virtualclicked.X);
                }
                else if (e.X < MouseDragStart)
                {
                    GraphOffset = new TimeSpan(ArchiveMaintainer.GraphNow.Ticks - virtualstart.X);
                    GraphWidth  = ScrollViewOffset + ScrollViewWidth - GraphOffset;
                }
                else if (e.X > MouseDragStart)
                {
                    GraphOffset = ScrollViewOffset;
                    GraphWidth  = new TimeSpan(ScrollViewRight.Ticks - virtualstart.X);
                }
            }
            else if (MouseResizing == ResizeMode.Left)
            {
                long proposedwidth = ArchiveMaintainer.GraphNow.Ticks - (virtualclicked.X + GraphOffset.Ticks);
                if (((proposedwidth * ScrollViewRectangle.Width) / ScrollViewWidth.Ticks) > 2)
                {
                    GraphWidth = proposedwidth + GraphOffset.Ticks < ScrollViewWidth.Ticks + ScrollViewOffset.Ticks ? TimeSpan.FromTicks(proposedwidth) : ScrollViewWidth + ScrollViewOffset - GraphOffset;
                }
                else
                {
                    GraphWidth = TimeSpan.FromTicks((2 * ScrollViewWidth.Ticks) / ScrollViewRectangle.Width);
                }
            }
            else if (MouseResizing == ResizeMode.Right)
            {
                long proposedwidth = virtualclicked.X - GraphRight.Ticks;
                if (ArchiveMaintainer.GraphNow.Ticks - virtualclicked.X < ScrollViewOffset.Ticks)
                {
                    GraphWidth += GraphOffset - ScrollViewOffset;
                    GraphOffset = ScrollViewOffset;
                }
                else if ((((GraphWidth.Ticks + proposedwidth) * ScrollViewRectangle.Width) / ScrollViewWidth.Ticks) > 2)
                {
                    GraphWidth += TimeSpan.FromTicks(virtualclicked.X - GraphRight.Ticks);
                    GraphOffset = TimeSpan.FromTicks(ArchiveMaintainer.GraphNow.Ticks - virtualclicked.X);
                }
                else
                {
                    long oldwidth = GraphWidth.Ticks;
                    GraphWidth   = TimeSpan.FromTicks((2 * ScrollViewWidth.Ticks) / ScrollViewRectangle.Width);
                    GraphOffset += TimeSpan.FromTicks(oldwidth - GraphWidth.Ticks);
                }
            }
            else if (e.Location.X > selectedleft - 3 && e.Location.X < selectedleft + 3)
            {
                Cursor = Cursors.SizeWE;
                return;
            }
            else if (e.Location.X > selectedright - 3 && e.Location.X < selectedright + 3)
            {
                Cursor = Cursors.SizeWE;
                return;
            }
            else if (e.Location.X > selectedleft - 3 && e.Location.X < selectedright + 3)
            {
                Cursor = Cursors.SizeAll;
                return;
            }
            else
            {
                Cursor = Cursors.Cross;
                return;
            }

            GridSpacing = BodgeSpacing(GraphWidth);
            RefreshXRange(false);
        }
コード例 #20
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (GraphRectangle().Contains(e.Location))
            {
                Cursor = Cursors.SizeAll;
            }
            else
            {
                Cursor = Cursors.Default;
            }

            if (ArchiveMaintainer == null || ArchiveMaintainer.LoadingInitialData)
            {
                return;
            }

            if (e.Button == MouseButtons.None)
            {
                if (DataPlotNav == null || DataKey == null || ArchiveMaintainer == null)
                {
                    return;
                }
                if (SelectedPoint != null)
                {
                    SelectedPoint.Show = false;
                }
                if (DataKey.SelectedSet == null || !DataKey.SelectedSet.Sets.ContainsKey(DataPlotNav.GetCurrentLeftArchiveInterval()))
                {
                    return;
                }
                DataPoint found = DataKey.SelectedSet.Sets[DataPlotNav.GetCurrentLeftArchiveInterval()].OnMouseMove(new MouseActionArgs(e.Location, GraphRectangle(), DataPlotNav != null ? DataPlotNav.XRange : DataTimeRange.MaxRange, SelectedYRange));
                if (found == null)
                {
                    return;
                }
                found.Show = true;
                if (found != SelectedPoint)
                {
                    SelectedPoint = found;
                    RefreshBuffer();
                }
            }
            else if (e.Button == MouseButtons.Left && ScrollStart.X != Int16.MinValue && ScrollStart.Y != Int16.MinValue)
            {
                HaveMoved = true;
                long vdelta = DataTimeRange.DeTranslateDelta(e.Location.X - ScrollStart.X, DataPlotNav.GraphWidth.Ticks, GraphRectangle().Width);

                if (DataPlotNav.GraphOffset.Ticks + vdelta <= 0)
                {
                    if (DataPlotNav.GraphOffset == TimeSpan.Zero && DataPlotNav.ScrollViewOffset == TimeSpan.Zero)
                    {
                        return;
                    }
                    DataPlotNav.ScrollViewOffset = TimeSpan.Zero;
                    DataPlotNav.GraphOffset      = TimeSpan.Zero;
                }
                else
                {
                    if (DataPlotNav.ScrollViewOffset.Ticks + DataPlotNav.ScrollViewWidth.Ticks < DataPlotNav.GraphOffset.Ticks + DataPlotNav.GraphWidth.Ticks + vdelta)
                    {
                        DataPlotNav.ScrollViewOffset = TimeSpan.FromTicks(DataPlotNav.GraphOffset.Ticks + DataPlotNav.GraphWidth.Ticks + vdelta - DataPlotNav.ScrollViewWidth.Ticks);
                    }
                    else if (DataPlotNav.ScrollViewOffset.Ticks > DataPlotNav.GraphOffset.Ticks + vdelta)
                    {
                        DataPlotNav.ScrollViewOffset = TimeSpan.FromTicks(DataPlotNav.GraphOffset.Ticks + vdelta);
                    }

                    DataPlotNav.GraphOffset += TimeSpan.FromTicks(vdelta);
                }

                ScrollStart = e.Location;
                DataPlotNav.RefreshXRange(false);
            }
        }
コード例 #21
0
        protected override void OnDrawToBuffer(PaintEventArgs paintEventArgs)
        {
            Program.AssertOnEventThread();
            Rectangle rect = new Rectangle(ScrollViewRectangle.Left, ScrollViewRectangle.Top, ScrollViewRectangle.Width - 1, ScrollViewRectangle.Height - 1);

            paintEventArgs.Graphics.FillRectangle(Palette.PaperBrush, ScrollViewRectangle);
            paintEventArgs.Graphics.DrawRectangle(SystemPens.ActiveBorder, rect);


            if (ArchiveMaintainer == null || Axis == null)
            {
                return;
            }

            if (ArchiveMaintainer.LoadingInitialData)
            {
                paintEventArgs.Graphics.DrawString(Messages.GRAPH_LOADING, Palette.LabelFont, Palette.LabelBrush, ScrollViewRectangle.Left + 10, ScrollViewRectangle.Top + 10);
                return;
            }

            DataTimeRange everything = Animating ? AnimateTimeRange : CurrentArchiveRange;

            RectangleF clip = paintEventArgs.Graphics.ClipBounds;

            paintEventArgs.Graphics.SetClip(rect);

            foreach (DataSet set in ScrollWideArchive.Sets.ToArray())
            {
                if (!set.Draw || !DisplayedUuids.Contains(set.Uuid))
                {
                    continue;
                }

                List <DataPoint> todraw;
                ArchiveInterval  current      = ScrollViewLeftArchiveInterval;
                ArchiveInterval  currentwidth = ScrollViewWidthArchiveInterval;
                if (current == currentwidth)
                {
                    todraw = new List <DataPoint>(set.Points);
                    if (current != ArchiveInterval.FiveSecond)
                    {
                        if (todraw.Count > 0 && todraw[0].X < ScrollViewRight.Ticks)
                        {
                            todraw.InsertRange(0, GetFinerPoints(
                                                   set,
                                                   new DataTimeRange(todraw[0].X, ScrollViewRight.Ticks, XRange.Resolution),
                                                   current));
                        }
                    }
                }
                else // currentwidth must be a higer resolution archive
                {
                    int setindex = ArchiveMaintainer.Archives[currentwidth].Sets.IndexOf(set);
                    todraw = new List <DataPoint>(ArchiveMaintainer.Archives[currentwidth].Sets[setindex].Points);

                    if (todraw.Count > 0)
                    {
                        set.MergePointCollection(set.BinaryChop(set.Points, new DataTimeRange(ScrollViewLeft.Ticks, todraw[todraw.Count - 1].X, GraphResolution.Ticks)), todraw);
                    }
                }

                set.RefreshCustomY(everything, todraw);
                if (set.CustomYRange.ScaleMode == RangeScaleMode.Auto)
                {
                    set.CustomYRange.Max = DataSet.GetMaxY(set.CurrentlyDisplayed);
                    set.CustomYRange.RoundToNearestPowerOf10();
                }
            }

            Axis.DrawToBuffer(new DrawAxisNavArgs(paintEventArgs.Graphics, ScrollViewRectangle, new DataTimeRange(everything.Max, everything.Min, -BodgeSpacing(new TimeSpan(-everything.Delta)).Ticks), true));

            foreach (DataSet set in ScrollWideArchive.Sets.ToArray())
            {
                if (!set.Draw || !DisplayedUuids.Contains(set.Uuid))
                {
                    continue;
                }

                lock (Palette.PaletteLock)
                {
                    using (var normalPen = Palette.CreatePen(set.Uuid, Palette.PEN_THICKNESS_NORMAL))
                    {
                        LineRenderer.Render(paintEventArgs.Graphics, ScrollViewRectangle, everything, set.CustomYRange, normalPen, null, set.CurrentlyDisplayed, false);
                    }
                }
            }

            if (DataEventList != null)
            {
                DataEventList.RenderEvents(paintEventArgs.Graphics, everything, ScrollViewRectangle, 5);
            }
            paintEventArgs.Graphics.SetClip(clip);

            long selectedleft  = LongPoint.TranslateToScreen(new LongPoint(GraphLeft.Ticks, 1), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle)).X;
            long selectedright = LongPoint.TranslateToScreen(new LongPoint(GraphRight.Ticks, 1), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle)).X;

            paintEventArgs.Graphics.FillRectangle(Palette.ShadowRangeBrush, ScrollViewRectangle.Left, ScrollViewRectangle.Top, selectedleft - (ScrollViewRectangle.Left), ScrollViewRectangle.Height);
            paintEventArgs.Graphics.FillRectangle(Palette.ShadowRangeBrush, selectedright, ScrollViewRectangle.Top, ScrollViewRectangle.Width + (ScrollViewRectangle.Left) - selectedright, ScrollViewRectangle.Height);
            DrawGripper(paintEventArgs.Graphics, selectedright);
            DrawGripper(paintEventArgs.Graphics, selectedleft);
        }
コード例 #22
0
ファイル: DataAxis.cs プロジェクト: huizh/xenadmin
 public DrawAxisNavArgs(Graphics g, Rectangle r, DataTimeRange range, bool showlabels)
     : base(g, r, showlabels)
 {
     Range = range;
 }
コード例 #23
0
ファイル: DataSet.cs プロジェクト: zhaoyingpu/xenadmin
 public void RefreshCustomY(DataTimeRange range, List <DataPoint> points)
 {
     // find last element before beginning of xrange => binary chop
     CurrentlyDisplayed = BinaryChop(points, range);
 }
コード例 #24
0
 public DrawAxisNavArgs(Graphics g, Rectangle r, DataTimeRange range, bool showlabels)
     : base(g, r, showlabels)
 {
     Range = range;
 }
コード例 #25
0
 public List <DataPoint> GetFinerPoints(DataSet set, DataTimeRange range, ArchiveInterval current)
 {
     return(set.GetRange(range, ArchiveMaintainer.ToTicks(current), ArchiveMaintainer.ToTicks(ArchiveMaintainer.NextArchiveDown(current))));
 }