예제 #1
0
        private static void DrawPlotAxis(Canvas On, AxisSettings axis, Size plotSize, Rect plotRect, Boolean First = true)
        {
            int   dividers = axis.Divider * axis.SubDivider;
            Point StartPoint, EndPoint;

            //draw dividers and subdividers
            for (int i = 0; i < (dividers) + 1; i++)
            {
                Boolean isDivider = (i % axis.SubDivider == 0);

                if (axis.AxisType == AxisType.X)
                {
                    double Coord = plotRect.Left + (i * (plotRect.Width / dividers));
                    double yPos  = (First) ? plotRect.Bottom : plotRect.Top;

                    StartPoint = new Point(
                        Coord,
                        yPos - (isDivider ? axis.DividerShortLength : axis.SubDividerShortLength));
                    EndPoint = new Point(
                        Coord,
                        yPos + (isDivider ? axis.DividerShortLength : axis.SubDividerShortLength));
                }
                else
                {
                    double Coord = plotRect.Top + (i * (plotRect.Height / dividers));
                    double xPos  = (First) ? plotRect.Left : plotRect.Right;

                    StartPoint = new Point(
                        xPos - (isDivider ? axis.DividerShortLength : axis.SubDividerShortLength),
                        Coord);
                    EndPoint = new Point(
                        xPos + (isDivider ? axis.DividerShortLength : axis.SubDividerShortLength),
                        Coord);
                }

                Line dividerLine = new Line
                {
                    X1                 = StartPoint.X,
                    Y1                 = StartPoint.Y,
                    X2                 = EndPoint.X,
                    Y2                 = EndPoint.Y,
                    Stroke             = (isDivider ? axis.DividerBrush : axis.SubDividerBrush),
                    StrokeThickness    = (isDivider ? axis.DividerBrushThickness : axis.SubDividerBrushThickness),
                    StrokeStartLineCap = PenLineCap.Flat,
                    StrokeEndLineCap   = PenLineCap.Triangle
                };

                DocHelper.PutElementOn(dividerLine, On);

                //if divider draw text
                if (isDivider)
                {
                    double val = 0;
                    if (axis.AxisType == AxisType.X)
                    {
                        val = axis.Info.Min + (i * (axis.Info.Range / dividers));
                    }
                    else
                    {
                        val = axis.Info.Max - (i * (axis.Info.Range / dividers));
                    }

                    string valString = "";
                    switch (axis.AxisValueType)
                    {
                    case AxisValueType.Raw: valString = val.ToString(axis.AxisValueFormat); break;

                    case AxisValueType.DataPointNumber: valString = (axis.AxisType == AxisType.X)?(i * axis.Info.Values / dividers).ToString():""; break;

                    case AxisValueType.OADate: valString = (DateTime.FromOADate(val)).ToString(axis.AxisValueFormat); break;

                    case AxisValueType.OADateRelative: valString = (DateTime.FromOADate(val - axis.Info.Min)).ToString(axis.AxisValueFormat); break;
                    }

                    TextBlock axisValueText = DocHelper.NewText(valString,
                                                                new DocHelper.FontSettings
                    {
                        Size = DocHelper.MM2Dibs(3),
                    });

                    Point TextPosition;

                    if (axis.AxisType == AxisType.X)
                    {
                        TextPosition = new Point(StartPoint.X - (axisValueText.Width / 2), 0);

                        if (First)
                        {
                            TextPosition.Y = plotRect.Bottom + (axisValueText.Height * 0.5);
                        }
                        else
                        {
                            TextPosition.Y = plotRect.Top - (axisValueText.Height * 1.5);
                        }
                    }
                    else
                    {
                        TextPosition = new Point(0, StartPoint.Y - (axisValueText.Height / 2));

                        if (First)
                        {
                            TextPosition.X = (plotRect.Left - axisValueText.Width) / 2;
                        }
                        else
                        {
                            TextPosition.X = plotRect.Right + (((plotSize.Width - plotRect.Right) - axisValueText.Width) / 2);
                        }
                    }

                    DocHelper.PutElementOn(axisValueText, On, Left: TextPosition.X, Top: TextPosition.Y);
                }
            }

            //Draw axis
            StartPoint = new Point();
            EndPoint   = new Point();

            if (axis.AxisType == AxisType.X)
            {
                if (First)
                {
                    StartPoint = plotRect.BottomLeft;
                    EndPoint   = plotRect.BottomRight;
                }
                else
                {
                    StartPoint = plotRect.TopLeft;
                    EndPoint   = plotRect.TopRight;
                }
            }
            else
            {
                if (First)
                {
                    StartPoint = plotRect.BottomLeft;
                    EndPoint   = plotRect.TopLeft;
                }
                else
                {
                    StartPoint = plotRect.TopRight;
                    EndPoint   = plotRect.BottomRight;
                }
            }

            Line axisLine = new Line
            {
                X1                 = StartPoint.X,
                Y1                 = StartPoint.Y,
                X2                 = EndPoint.X,
                Y2                 = EndPoint.Y,
                Stroke             = axis.AxisBrush,
                StrokeThickness    = axis.AxisThickness,
                StrokeStartLineCap = PenLineCap.Flat,
                StrokeEndLineCap   = PenLineCap.Flat
            };

            DocHelper.PutElementOn(axisLine, On);
        }
예제 #2
0
        public static Canvas NewPlot(double Width, double Height, PlotSettings Options)
        {
            Canvas content = new Canvas
            {
                Width        = Width,
                Height       = Height,
                Background   = Brushes.White,
                ClipToBounds = true
            };

            //PlotSettings plotSettings = Options;

            //get info for sizings ...


            Thickness Distance = new Thickness(DocHelper.MM2Dibs(15),
                                               DocHelper.MM2Dibs(15),
                                               DocHelper.MM2Dibs(15),
                                               DocHelper.MM2Dibs(7.5));

            Size PlotSize = new Size(Width - (Distance.Left + Distance.Right), Height - (Distance.Top + Distance.Bottom));


            //Plot

            //double xScaler = rangeX / plot.Width;
            //double yScaler = rangeY / plot.Height;

            Rect plotArea    = new Rect(new Point(Distance.Left, Distance.Top), PlotSize);
            Size contentSize = new Size(Width, Height);

            //draw plots
            //plotline
            PlotData[] plotData = Options.GetPlotData();
            Canvas[]   plots    = new Canvas[plotData.Count()];
            for (int i = 0; i < plotData.Length; i++)
            {
                DocHelper.PutElementOn(NewPlotLine(plotData[i], PlotSize), content, Top: Distance.Top, Left: Distance.Left);
                //
                //plots[i] = NewPlotLine(plotData[i], PlotSize);
            }

            // AXIS
            DrawPlotAxis(content, Options.First(AxisType.X), contentSize, plotArea, true);
            DrawPlotAxis(content, Options.First(AxisType.Y), contentSize, plotArea, true);
            if (Options.Second(AxisType.X) != null)
            {
                DrawPlotAxis(content, Options.Second(AxisType.X), contentSize, plotArea, false);
            }
            if (Options.Second(AxisType.Y) != null)
            {
                DrawPlotAxis(content, Options.Second(AxisType.Y), contentSize, plotArea, false);
            }

            //draw title
            TextBlock titleText = DocHelper.NewText(Options.title,
                                                    Options.TitleFont);

            DocHelper.PutElementOn(titleText, content, CenterHorizontal: true, Top: DocHelper.MM2Dibs(3));

            Rectangle border = new Rectangle
            {
                Width           = Width,
                Height          = Height,
                Stroke          = Brushes.DarkGray,
                StrokeThickness = DocHelper.MM2Dibs(0.25)
            };

            DocHelper.PutElementOn(border, content);


            return(content);
        }