Provides the ability to draw histogram plots
Inheritance: BaseSequencePlot, IPlot, ISequencePlot
Esempio n. 1
0
        /// <summary>
        /// Stack the histogram to another HistogramPlot.
        /// </summary>
        public void StackedTo(HistogramPlot hp)
        {
            SequenceAdapter data =
                new SequenceAdapter(this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData);

            SequenceAdapter hpData =
                new SequenceAdapter(hp.DataSource, hp.DataMember, hp.OrdinateData, hp.AbscissaData);

            if (hp != null)
            {
                isStacked_ = true;
                if (hpData.Count != data.Count)
                {
                    throw new NPlotException("Can stack HistogramPlot data only with the same number of datapoints.");
                }
                for (int i = 0; i < data.Count; ++i)
                {
                    if (data[i].X != hpData[i].X)
                    {
                        throw new NPlotException("Can stack HistogramPlot data only with the same X coordinates.");
                    }
                    if (hpData[i].Y < 0.0f)
                    {
                        throw new NPlotException("Can stack HistogramPlot data only with positive Y coordinates.");
                    }
                }
            }
            stackedTo_ = hp;
        }
		void Refresh(object sender, EventArgs e)
		{
			_plotSurface.Clear();
			_plotSurface.BackColor = Color.Black;

			if (!_component.ComputeHistogram())
			{
				_plotSurface.Refresh();
				return;
			}

			HistogramPlot histogram = new HistogramPlot();
			histogram.AbscissaData = _component.BinLabels;
			histogram.OrdinateData = _component.Bins;
			histogram.Center = false;
			histogram.BaseWidth = 1.0f;
			histogram.Filled = true;
			histogram.Pen = new Pen(ClearCanvasStyle.ClearCanvasBlue);
			histogram.RectangleBrush = new RectangleBrushes.Solid(ClearCanvasStyle.ClearCanvasBlue);

			_plotSurface.Add(histogram);
			_plotSurface.PlotBackColor = Color.Black;
			_plotSurface.XAxis1.Color = Color.White;
			_plotSurface.YAxis1.Color = Color.White;
			_plotSurface.Refresh();
		}
Esempio n. 3
0
        public HistogramSample()
            : base()
        {
            infoText = "";
            infoText += "Gaussian Example. Demonstrates - \n";
            infoText += "  * HistogramPlot and LinePlot" ;

            plotCanvas.Clear();

            System.Random r = new Random ();

            int len = 35;
            double[] a = new double [len];
            double[] b = new double [len];

            for (int i=0; i<len; ++i) {
                a[i] = Math.Exp (-(double)(i-len/2)*(double)(i-len/2)/50.0);
                b[i] = a[i] + (r.Next(10)/50.0f)-0.05f;
                if (b[i] < 0) {
                    b[i] = 0;
                }
            }

            HistogramPlot sp = new HistogramPlot ();
            sp.DataSource = b;
            sp.BorderColor = Colors.DarkBlue;
            sp.Filled = true;
            sp.FillColor = Colors.Gold; //Gradient (Colors.Lavender, Color.Gold );
            sp.BaseWidth = 0.5;
            sp.Label = "Random Data";

            LinePlot lp = new LinePlot ();
            lp.DataSource = a;
            lp.LineColor = Colors.Blue;
            lp.LineWidth = 3;
            lp.Label = "Gaussian Function";
            plotCanvas.Add (sp);
            plotCanvas.Add (lp);
            plotCanvas.Legend = new Legend ();
            plotCanvas.YAxis1.WorldMin = 0.0;
            plotCanvas.Title = "Histogram Plot";

            PackStart (plotCanvas.Canvas, true);
            Label la = new Label (infoText);
            PackStart (la);
        }
Esempio n. 4
0
        /// <summary>
        /// Returns a y-axis that is suitable for drawing this plot.
        /// </summary>
        /// <returns>A suitable y-axis.</returns>
        public Axis SuggestYAxis()
        {
            if (this.isStacked_)
            {
                double    tmpMax      = 0.0f;
                ArrayList adapterList = new ArrayList();

                HistogramPlot currentPlot = this;
                do
                {
                    adapterList.Add(new SequenceAdapter(
                                        currentPlot.DataSource,
                                        currentPlot.DataMember,
                                        currentPlot.OrdinateData,
                                        currentPlot.AbscissaData)
                                    );
                } while ((currentPlot = currentPlot.stackedTo_) != null);

                SequenceAdapter[] adapters =
                    (SequenceAdapter[])adapterList.ToArray(typeof(SequenceAdapter));

                for (int i = 0; i < adapters[0].Count; ++i)
                {
                    double tmpHeight = 0.0f;
                    for (int j = 0; j < adapters.Length; ++j)
                    {
                        tmpHeight += adapters[j][i].Y;
                    }
                    tmpMax = Math.Max(tmpMax, tmpHeight);
                }

                Axis a = new LinearAxis(0.0f, tmpMax);
                // TODO make 0.08 a parameter.
                a.IncreaseRange(0.08);
                return(a);
            }
            else
            {
                SequenceAdapter data =
                    new SequenceAdapter(this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData);

                return(data.SuggestYAxis());
            }
        }
Esempio n. 5
0
        public PlotGaussian()
        {
            infoText = "";
            infoText += "Gaussian Example. Demonstrates - \n";
            infoText += "  * HistogramPlot and LinePlot." ;

            plotSurface.Clear();

            System.Random r = new Random();

            int len = 35;
            double[] a = new double[len];
            double[] b = new double[len];

            for (int i=0; i<len; ++i)
            {
                a[i] = (double)Math.Exp(-(double)(i-len/2)*(double)(i-len/2)/50.0f);
                b[i] = a[i] + (r.Next(10)/50.0f)-0.05f;
                if (b[i] < 0.0f) {
                    b[i] = 0;
                }
            }

            HistogramPlot sp = new HistogramPlot();
            sp.DataSource = b;
            sp.Pen = Pens.DarkBlue;
            sp.Filled = true;
            sp.RectangleBrush = new RectangleBrushes.HorizontalCenterFade( Color.Lavender, Color.Gold );
            sp.BaseWidth = 0.5f;
            sp.Label = "Random Data";
            LinePlot lp = new LinePlot();
            lp.DataSource = a;
            lp.Pen = new Pen( Color.Blue, 3.0f );
            lp.Label = "Gaussian Function";
            plotSurface.Add( sp );
            plotSurface.Add( lp );
            plotSurface.Legend = new Legend();
            plotSurface.YAxis1.WorldMin = 0.0f;
            plotSurface.Title = "Histogram Plot";
            plotSurface.Refresh();
        }
        /// <summary>
        /// Stack the histogram to another HistogramPlot.
        /// </summary>
        public void StackedTo(HistogramPlot hp)
        {
            SequenceAdapter data =
                new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData );

            SequenceAdapter hpData =
                new SequenceAdapter( hp.DataSource, hp.DataMember, hp.OrdinateData, hp.AbscissaData );

                if ( hp != null )
                {
                    isStacked_ = true;
                    if ( hpData.Count != data.Count )
                    {
                        throw new NPlotException("Can stack HistogramPlot data only with the same number of datapoints.");
                    }
                    for ( int i=0; i < data.Count; ++i )
                    {
                        if ( data[i].X != hpData[i].X )
                        {
                            throw new NPlotException("Can stack HistogramPlot data only with the same X coordinates.");
                        }
                        if ( hpData[i].Y < 0.0f)
                        {
                            throw new NPlotException("Can stack HistogramPlot data only with positive Y coordinates.");
                        }
                    }
                }
                stackedTo_ = hp;
        }
Esempio n. 7
0
        public PlotLabelAxis()
        {
            infoText = "";
            infoText += "Internet Usage Example. Demonstrates - \n";
            infoText += " * Label Axis with angled text. \n";
            infoText += " * RectangleBrushes.";

            plotSurface.Clear();

            Grid mygrid = new Grid();
            mygrid.VerticalGridType = Grid.GridType.Coarse;
            Pen majorGridPen = new Pen( Color.LightGray );
            float[] pattern = { 1.0f, 2.0f };
            majorGridPen.DashPattern = pattern;
            mygrid.MajorGridPen = majorGridPen;
            plotSurface.Add( mygrid );

            float[] xs = {20.0f, 31.0f, 27.0f, 38.0f, 24.0f, 3.0f, 2.0f };
            float[] xs2 = {7.0f, 10.0f, 42.0f, 9.0f, 2.0f, 79.0f, 70.0f };
            float[] xs3 = {1.0f, 20.0f, 20.0f, 25.0f, 10.0f, 30.0f, 30.0f };

            HistogramPlot hp = new HistogramPlot();
            hp.DataSource = xs;
            hp.BaseWidth = 0.6f;
            hp.RectangleBrush =
                new RectangleBrushes.HorizontalCenterFade( Color.FromArgb(255,255,200), Color.White );
            hp.Filled = true;
            hp.Label = "Developer Work";

            HistogramPlot hp2 = new HistogramPlot();
            hp2.DataSource = xs2;
            hp2.Label = "Web Browsing";
            hp2.RectangleBrush = RectangleBrushes.Horizontal.FaintGreenFade;
            hp2.Filled = true;
            hp2.StackedTo( hp );

            HistogramPlot hp3 = new HistogramPlot();
            hp3.DataSource = xs3;
            hp3.Label = "P2P Downloads";
            hp3.RectangleBrush = RectangleBrushes.Vertical.FaintBlueFade;
            hp3.Filled = true;
            hp3.StackedTo( hp2 );

            plotSurface.Add( hp );
            plotSurface.Add( hp2 );
            plotSurface.Add( hp3 );

            plotSurface.Legend = new Legend();

            LabelAxis la = new LabelAxis( plotSurface.XAxis1 );
            la.AddLabel( "Monday", 0.0f );
            la.AddLabel( "Tuesday", 1.0f );
            la.AddLabel( "Wednesday", 2.0f );
            la.AddLabel( "Thursday", 3.0f );
            la.AddLabel( "Friday", 4.0f );
            la.AddLabel( "Saturday", 5.0f );
            la.AddLabel( "Sunday", 6.0f );
            la.Label = "Days";
            la.TickTextFont = new Font( "Courier New", 8 );
            la.TicksBetweenText = true;

            plotSurface.XAxis1 = la;
            plotSurface.YAxis1.WorldMin = 0.0;
            plotSurface.YAxis1.Label = "MBytes";
            ((LinearAxis)plotSurface.YAxis1).NumberOfSmallTicks = 1;

            plotSurface.Title = "Internet useage for user:\n johnc 09/01/03 - 09/07/03";

            plotSurface.XAxis1.TicksLabelAngle = 30.0f;

            plotSurface.PlotBackBrush = RectangleBrushes.Vertical.FaintRedFade;
            plotSurface.Refresh();
        }
Esempio n. 8
0
        /// <summary>
        /// Renders the histogram.
        /// </summary>
        /// <param name="g">The Graphics surface on which to draw</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            SequenceAdapter data =
                new SequenceAdapter(this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData);

            float yoff;

            for (int i = 0; i < data.Count; ++i)
            {
                // (1) determine the top left hand point of the bar (assuming not centered)
                PointD p1 = data[i];
                if (double.IsNaN(p1.X) || double.IsNaN(p1.Y))
                {
                    continue;
                }

                // (2) determine the top right hand point of the bar (assuming not centered)
                PointD p2;
                if (i + 1 != data.Count)
                {
                    p2 = data[i + 1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y))
                    {
                        continue;
                    }
                    p2.Y = p1.Y;
                }
                else if (i != 0)
                {
                    p2 = data[i - 1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y))
                    {
                        continue;
                    }
                    double offset = p1.X - p2.X;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }
                else
                {
                    double offset = 1.0f;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }

                // (3) now account for plots this may be stacked on top of.
                HistogramPlot currentPlot = this;
                yoff = 0.0f;
                double yval = 0.0f;
                while (currentPlot.isStacked_)
                {
                    SequenceAdapter stackedToData = new SequenceAdapter(
                        currentPlot.stackedTo_.DataSource,
                        currentPlot.stackedTo_.DataMember,
                        currentPlot.stackedTo_.OrdinateData,
                        currentPlot.stackedTo_.AbscissaData);

                    yval       += stackedToData[i].Y;
                    yoff        = yAxis.WorldToPhysical(yval, false).Y;
                    p1.Y       += stackedToData[i].Y;
                    p2.Y       += stackedToData[i].Y;
                    currentPlot = currentPlot.stackedTo_;
                }

                // (4) now account for centering
                if (center_)
                {
                    double offset = (p2.X - p1.X) / 2.0f;
                    p1.X -= offset;
                    p2.X -= offset;
                }

                // (5) now account for BaseOffset (shift of bar sideways).
                p1.X += baseOffset_;
                p2.X += baseOffset_;

                // (6) now get physical coordinates of top two points.
                PointF xPos1 = xAxis.WorldToPhysical(p1.X, false);
                PointF yPos1 = yAxis.WorldToPhysical(p1.Y, false);
                PointF xPos2 = xAxis.WorldToPhysical(p2.X, false);
                PointF yPos2 = yAxis.WorldToPhysical(p2.Y, false);

                if (isStacked_)
                {
                    currentPlot = this;
                    while (currentPlot.isStacked_)
                    {
                        currentPlot = currentPlot.stackedTo_;
                    }
                    this.baseWidth_ = currentPlot.baseWidth_;
                }

                float width = xPos2.X - xPos1.X;
                float height;
                if (isStacked_)
                {
                    height = -yPos1.Y + yoff;
                }
                else
                {
                    height = -yPos1.Y + yAxis.PhysicalMin.Y;
                }

                float     xoff = (1.0f - baseWidth_) / 2.0f * width;
                Rectangle r    = new Rectangle((int)(xPos1.X + xoff), (int)yPos1.Y, (int)(width - 2 * xoff), (int)height);

                if (this.Filled)
                {
                    if (r.Height != 0 && r.Width != 0)
                    {
                        // room for optimization maybe.
                        g.FillRectangle(rectangleBrush_.Get(r), r);
                    }
                }

                g.DrawRectangle(Pen, r.X, r.Y, r.Width, r.Height);
            }
        }
Esempio n. 9
0
        public void Draw()
        {
            this.plot.PlotBackColor = Color.White;
            this.plot.BackColor = Color.White;

            ArrayList xs1 = new ArrayList();

            ArrayList times = new ArrayList();

            int split = 1;
            long lap = 0;
            float max = 0;
            float min = 32767 * 32767;
            long nlaps = 0;
            long totaltime = 0;

            this.plot.Clear();

            if (((long[])splits[winner]).Length < nsplits)
                return;

            for (int i = nsplits; i < ((long[])splits[winner]).Length; ++i)
            {
                lap += ((long[])splits[winner])[i];
                if (i != 0) lap -= ((long[])splits[winner])[i - 1];
                if (split == nsplits)
                {
                    //times.Add("     " + timetostr(lap));
                    string time = "  " + timetostr(lap, true) + "  :  ";
                    for (int s = nsplits - 1; s >= 0; --s)
                    {
                        if (i == nsplits && s == nsplits)
                            time += timetostr(((long[])splits[winner])[i - s], false);
                        else
                            time += timetostr(((long[])splits[winner])[i - s] - ((long[])splits[winner])[i - 1 - s], false);
                        if (s != 0)
                            time += " , ";
                    }

                    time += "  ";
                    times.Add(time);
                    totaltime += lap;

                    ++nlaps;
                    if (max < lap) max = lap;
                    if (min > lap) min = lap;
                    xs1.Add((double)lap);
                    split = 1;
                    lap = 0;
                }
                else split++;
            }

            if (nlaps != 0)
                this.winner_avgtime = totaltime / nlaps;

            if (nlaps == 0)
                return;

            Grid mygrid = new Grid();
            mygrid.VerticalGridType = Grid.GridType.Coarse;
            mygrid.HorizontalGridType = Grid.GridType.Coarse;
            mygrid.MajorGridPen = new Pen(Color.LightGray, 1f);

            this.plot.Add(mygrid);

            for (int i = 0; i < xs1.Count; ++i)
            {
                double[] abscissa = { 0 };
                double[] ordinate = { 0 };

                if ((double)xs1[i] < winner_avgtime)
                {
                    abscissa[0] = (i);
                    ordinate[0] = ((double)xs1[i]) / 10000.0;
                    HistogramPlot hp = new HistogramPlot();
                    hp.OrdinateData = ordinate;
                    hp.AbscissaData = abscissa;

                    hp.RectangleBrush = new RectangleBrushes.Horizontal(Color.FromArgb(106, 205, 84), Color.FromArgb(235, 255, 213));
                    hp.Pen.Color = Color.FromArgb(0, 150, 0);
                    hp.Filled = true;
                    hp.ShowInLegend = false;
                    this.plot.Add(hp);
                }

                if ((double)xs1[i] >= winner_avgtime)
                {
                    abscissa[0] = i;
                    if (Settings.LimitLapTimes && (((double)xs1[i] - winner_avgtime) > (winner_avgtime - min) * Settings.LimitMultiplier))
                        ordinate[0] = (winner_avgtime + (winner_avgtime - min) * Settings.LimitMultiplier) / 10000.0;
                    else
                        ordinate[0] = ((double)xs1[i]) / 10000.0;

                    HistogramPlot hp = new HistogramPlot();
                    hp.OrdinateData = ordinate;
                    hp.AbscissaData = abscissa;

                    if (Settings.LimitLapTimes && (((double)xs1[i] - winner_avgtime) > (winner_avgtime - min) * Settings.LimitMultiplier))
                    {
                        hp.RectangleBrush = new RectangleBrushes.Horizontal(Color.FromArgb(190, 39, 92), Color.FromArgb(235, 124, 177));
                    }
                    else
                    {
                        hp.RectangleBrush = new RectangleBrushes.Horizontal(Color.FromArgb(235, 84, 137), Color.FromArgb(255, 230, 210));
                    }
                    hp.Pen.Color = Color.FromArgb(150, 0, 0);
                    hp.Filled = true;
                    hp.ShowInLegend = false;
                    this.plot.Add(hp);
                }

            }

            //int xmax = ((long[])splits[winner]).Length / nsplits;

            LabelAxis la = new LabelAxis(this.plot.XAxis1);
            la.TicksBetweenText = false;
            la.TicksCrossAxis = false;
            la.LargeTickSize = 0;
            la.TickTextFont = Settings.lapTimesFont;

            for (int i = 0; i < times.Count; ++i)
                la.AddLabel((string)times[i], i);

            la.TicksLabelAngle = -90.0f;
            this.plot.XAxis1 = la;

            la = new LabelAxis((LabelAxis)la.Clone());
            la.TicksBetweenText = false;
            la.TicksCrossAxis = true;
            la.LargeTickSize = 2;
            la.TicksLabelAngle = -90.0f;
            la.TickTextNextToAxis = false;
            la.TickTextFont = Settings.commonFont;

            for (int i = 0; i < times.Count; ++i)
            {
                la.AddLabel(System.Convert.ToString(i + 2), i);
            }
            la.LabelFont = Settings.commonFont;
            this.plot.XAxis2 = la;

            this.plot.YAxis1.TicksCrossAxis = true;

            this.plot.YAxis1.Label = ((string)this.players[this.player]);
            this.plot.YAxis1.LabelFont = Settings.titleFont;
            this.plot.YAxis1.LabelOffset = 20;
            this.plot.YAxis1.NumberFormat = "";
            this.plot.YAxis1.TicksCrossAxis = false;
            if (Settings.LimitToGlobalBestLap) this.plot.YAxis1.WorldMin = (double)this.bestlap / 10000.0;
            ((LinearAxis)this.plot.YAxis1).NumberOfSmallTicks = 4;
            ((LinearAxis)this.plot.YAxis1).LargeTickStep = 1;
            ((LinearAxis)this.plot.YAxis1).TicksLabelAngle = -90f;

            HorizontalLine hl = new HorizontalLine((float)winner_avgtime / 10000, Color.Gray);
            hl.Pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
            this.plot.Add(hl);

            this.laps = (int)nlaps;

            //            this.plot.YAxis1.WorldMax += 1;
            if (this.plot.YAxis1.WorldMax - this.plot.YAxis1.WorldMin <= 0.1)
                this.plot.YAxis1.WorldMax += 1;
            this.plot.Refresh();
            //            System.Console.WriteLine(System.Convert.ToString(this.plot.YAxis1.WorldMin) + " " + System.Convert.ToString(this.plot.YAxis1.WorldMax));
        }
Esempio n. 10
0
        public void PlotMultiHistogram()
        {
            double[] data = new double[]  { 0, 4, 3, 2, 5, 4, 2, 3 };
            double[] data2 = new double[] { 5, 2, 4, 1, 2, 1, 5, 3 };

            HistogramPlot hp = new HistogramPlot();
            hp.OrdinateData = data;
            hp.RectangleBrush = RectangleBrushes.Horizontal.FaintRedFade;
            hp.Filled = true;
            hp.BaseOffset = -0.15;
            hp.BaseWidth = 0.25f;

            HistogramPlot hp2 = new HistogramPlot();
            hp2.OrdinateData = data2;
            hp2.RectangleBrush = RectangleBrushes.Horizontal.FaintGreenFade;
            hp2.Filled = true;
            hp2.BaseOffset = 0.15;
            hp2.BaseWidth = 0.25f;

            plotSurface.Clear();

            plotSurface.Add(hp);
            plotSurface.Add(hp2);

            plotSurface.PlotBackBrush = RectangleBrushes.Vertical.FaintBlueFade;
            plotSurface.Refresh();
        }
Esempio n. 11
0
        public void PlotProfitLoss()
        {
            // this example will in the future demonstrate histogram plots with +- values.
            // currently not used - histograms don't support this.
            plotSurface.Clear();

            int[] values = {-10,2,-3, 4, 6, -1, 10, 4, -4, -3 };
            HistogramPlot hp = new HistogramPlot();
            hp.OrdinateData = values;
            plotSurface.Add(hp);

            plotSurface.Refresh();
        }