Exemplo n.º 1
0
        /// <summary>
        /// Uses Sets (which is used for drawing) so must be on the event thread)
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseClick(MouseEventArgs e)
        {
            Program.AssertOnEventThread();

            base.OnMouseClick(e);
            Select();

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

            if (HaveMoved || DataPlotNav == null || DataKey == null || ArchiveMaintainer == null)
            {
                HaveMoved = false;
                return;
            }
            if (DataEventList != null && e.Location.Y < Padding.Top + 18)
            {
                DataEventList.OnEventsMouseClick(new MouseActionArgs(e.Location, GraphRectangle(), DataPlotNav.XRange, SelectedYRange));
                DataKey.SelectedItem = null;
            }
            else if (GraphRectangle().Contains(e.Location))
            {
                foreach (DataSet set in DataPlotNav.CurrentArchive.Sets.ToArray())
                {
                    if (!set.Draw || DataKey == null || !DataKey.DataSourceUUIDsToShow.Contains(set.Uuid))
                    {
                        continue;
                    }
                    if (set.OnMouseClick(new MouseActionArgs(e.Location, GraphRectangle(), DataPlotNav.XRange, SelectedYRange)))
                    {
                        DataKey.SelectDataSet(set);
                        return;
                    }
                }
                DataKey.SelectedItem = null;
            }
            else
            {
                DataKey.SelectedItem = null;
            }
        }
Exemplo n.º 2
0
        protected override void OnDrawToBuffer(PaintEventArgs paintEventArgs)
        {
            Program.AssertOnEventThread();

            Rectangle SlightlySmaller = GraphRectangle(paintEventArgs.ClipRectangle);

            // Fill BG
            paintEventArgs.Graphics.FillRectangle(Palette.PaperBrush, SlightlySmaller);

            if (ArchiveMaintainer == null || DataKey == null || DataPlotNav == null)
            {
                return;
            }

            if (IsSelected)
            {
                Rectangle rect = Rectangle.Inflate(paintEventArgs.ClipRectangle, 1, 1);
                paintEventArgs.Graphics.FillRectangle(Palette.GraphShadow, rect);
                paintEventArgs.Graphics.FillRectangle(Palette.PaperBrush, SlightlySmaller);
            }

            // Draw Rectangle around graph area
            paintEventArgs.Graphics.DrawRectangle(Palette.GridPen, SlightlySmaller);

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

            bool require_tools = true;

            foreach (DataSetCollectionWrapper set in DataKey.CurrentKeys)
            {
                if (set.Sets[ArchiveInterval.FiveSecond].TypeString != "memory")
                {
                    require_tools = false;
                    break;
                }
            }
            if (require_tools && DataKey.CurrentKeys.Count > 0)
            {
                Rectangle messageRect = Rectangle.Inflate(SlightlySmaller, -10, -10);
                paintEventArgs.Graphics.DrawString(Messages.GRAPH_NEEDS_TOOLS, Palette.LabelFont, Palette.LabelBrush,
                                                   messageRect);
                return;
            }

            // Refresh all sets
            foreach (DataSet set in DataPlotNav.CurrentArchive.Sets.ToArray())
            {
                if (!set.Draw || !DataKey.DataSourceUUIDsToShow.Contains(set.Uuid))
                {
                    continue;
                }

                List <DataPoint> todraw;
                ArchiveInterval  current      = DataPlotNav.GetCurrentLeftArchiveInterval();
                ArchiveInterval  currentwidth = DataPlotNav.GetCurrentWidthArchiveInterval();
                if (current == currentwidth)
                {
                    todraw = new List <DataPoint>(set.Points);
                    if (current != ArchiveInterval.FiveSecond)
                    {
                        if (todraw.Count > 0 && todraw[0].X < DataPlotNav.GraphRight.Ticks)
                        {
                            todraw.InsertRange(0, DataPlotNav.GetFinerPoints(
                                                   set,
                                                   new DataTimeRange(todraw[0].X, DataPlotNav.GraphRight.Ticks, DataPlotNav.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(DataPlotNav.GraphLeft.Ticks, todraw[todraw.Count - 1].X, DataPlotNav.GraphResolution.Ticks)), todraw);
                    }
                }
                set.RefreshCustomY(DataPlotNav.XRange, todraw);
                DataRange ymax = DataRange.UnitRange;
                foreach (DataSetCollectionWrapper wrapper in DataKey.CurrentKeys)
                {
                    if (wrapper.Sets.ContainsKey(current))
                    {
                        DataSet dataSet = wrapper.Sets[current];
                        if (!dataSet.Hide && dataSet.CustomYRange != null &&
                            dataSet.CustomYRange.Units == set.CustomYRange.Units)
                        {
                            ymax.ScaleMode = dataSet.CustomYRange.ScaleMode;
                            if (dataSet.CustomYRange.ScaleMode != RangeScaleMode.Auto)
                            {
                                if (dataSet.CustomYRange.Max > ymax.Max)
                                {
                                    ymax = dataSet.CustomYRange;
                                }
                            }
                            else
                            {
                                double maxY = DataSet.GetMaxY(dataSet.BinaryChop(dataSet.CurrentlyDisplayed, DataPlotNav.XRange));
                                if (maxY < 1)
                                {
                                    maxY = 1;
                                }
                                if (maxY >= ymax.Max)
                                {
                                    ymax     = dataSet.CustomYRange;
                                    ymax.Max = maxY;
                                }
                            }
                        }
                    }
                }
                if (set.CustomYRange.ScaleMode == RangeScaleMode.Auto)
                {
                    ymax.RoundToNearestPowerOf10();
                }
                foreach (DataSetCollectionWrapper wrapper in DataKey.CurrentKeys)
                {
                    foreach (DataSet ds in wrapper.Sets.Values)
                    {
                        if (ds.Hide || ds.CustomYRange == null || ds.CustomYRange.Units != set.CustomYRange.Units)
                        {
                            continue;
                        }

                        ds.CustomYRange.Max        = ymax.Max;
                        ds.CustomYRange.Min        = ymax.Min;
                        ds.CustomYRange.Resolution = ymax.Resolution;
                    }
                }
            }

            // Draw Axes
            XAxis.DrawToBuffer(new DrawAxisXArgs(paintEventArgs.Graphics, SlightlySmaller, DataPlotNav != null ? DataPlotNav.XRange : DataTimeRange.MaxRange, ShowLabels));
            YAxis.DrawToBuffer(new DrawAxisYArgs(paintEventArgs.Graphics, SlightlySmaller, SelectedYRange, ShowLabels));

            // Draw Sets
            DataSet[] sets_to_show = DataPlotNav.CurrentArchive.Sets.ToArray();
            Array.Sort(sets_to_show);
            Array.Reverse(sets_to_show);
            foreach (DataSet set in sets_to_show)
            {
                if (!set.Draw || DataKey == null || !DataKey.DataSourceUUIDsToShow.Contains(set.Uuid))
                {
                    continue;
                }

                lock (Palette.PaletteLock)
                {
                    using (var thickPen = Palette.CreatePen(set.Uuid, Palette.PEN_THICKNESS_THICK))
                    {
                        using (var normalPen = Palette.CreatePen(set.Uuid, Palette.PEN_THICKNESS_NORMAL))
                        {
                            using (var shadowBrush = Palette.CreateBrush(set.Uuid))
                            {
                                LineRenderer.Render(paintEventArgs.Graphics, SlightlySmaller, DataPlotNav.XRange, set.CustomYRange ?? SelectedYRange, set.Selected ? thickPen : normalPen, shadowBrush, set.CurrentlyDisplayed, true);
                            }
                        }
                    }
                }
            }

            if (DataEventList != null)
            {
                DataEventList.RenderEvents(paintEventArgs.Graphics, DataPlotNav.XRange, new Rectangle(SlightlySmaller.Left, SlightlySmaller.Top + 2, SlightlySmaller.Width, SlightlySmaller.Height - 2), 16);
            }

            SizeF labelsize = new SizeF(0, 0);

            if (SelectedPoint != null && DataKey.SelectedDataSet != null)
            {
                string label = string.Format(string.Format("{0} - {1} = {2}", DataPlotNav.XRange.GetString(SelectedPoint.X + ArchiveMaintainer.ClientServerOffset.Ticks), DataKey.SelectedDataSet.Name,
                                                           SelectedPoint.Y >= 0 ? SelectedYRange.GetString(SelectedPoint.Y) : Messages.GRAPHS_NO_DATA));
                labelsize = paintEventArgs.Graphics.MeasureString(label, Palette.LabelFont);
                paintEventArgs.Graphics.DrawString(label, Palette.LabelFont, Palette.LabelBrush, SlightlySmaller.Right - labelsize.Width, SlightlySmaller.Top - (labelsize.Height + 1));
            }

            // Draw graph's name
            if (DisplayName != String.Empty)
            {
                Rectangle rect = new Rectangle(SlightlySmaller.Location, SlightlySmaller.Size);
                rect.Width -= Convert.ToInt32(labelsize.Width);
                string nameLabel     = DisplayName.Ellipsise(paintEventArgs.Graphics, rect, Palette.LabelFont);
                SizeF  nameLabelSize = paintEventArgs.Graphics.MeasureString(nameLabel, Palette.LabelFont);
                paintEventArgs.Graphics.DrawString(nameLabel, Palette.LabelFont, Palette.LabelBrush, SlightlySmaller.Left, SlightlySmaller.Top - (nameLabelSize.Height + 1));
            }

            // Draw to screen
            Refresh();
        }
Exemplo n.º 3
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);
        }