Example #1
0
        public Boolean AddAxis(AxisSettings axis)
        {
            if (Axes.Count() == 4)
            {
                return(false);
            }

            if (Axes.Where(x => x.AxisType == axis.AxisType).Count() == 2)
            {
                return(false);
            }

            Axes.Add(axis);

            return(true);
        }
Example #2
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);
        }