Ejemplo n.º 1
0
        /// <summary>
        /// Calculates the space used for the axis title.
        /// </summary>
        internal override void Format()
        {
            XGraphics gfx = _rendererParms.Graphics;

            AxisTitleRendererInfo atri = ((AxisRendererInfo)_rendererParms.RendererInfo)._axisTitleRendererInfo;

            if (atri.AxisTitleText != "")
            {
                XSize size = gfx.MeasureString(atri.AxisTitleText, atri.AxisTitleFont);
                if (atri.AxisTitleOrientation != 0)
                {
                    XPoint[] points = new XPoint[2];
                    points[0].X = 0;
                    points[0].Y = 0;
                    points[1].X = size.Width;
                    points[1].Y = size.Height;

                    XMatrix matrix = new XMatrix();
                    matrix.RotatePrepend(-atri.AxisTitleOrientation);
                    matrix.TransformPoints(points);

                    size.Width  = Math.Abs(points[1].X - points[0].X);
                    size.Height = Math.Abs(points[1].Y - points[0].Y);
                }

                atri.X      = 0;
                atri.Y      = 0;
                atri.Height = size.Height;
                atri.Width  = size.Width;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculates the space used for the X axis.
        /// </summary>
        internal override void Format()
        {
            AxisRendererInfo xari = ((ChartRendererInfo)_rendererParms.RendererInfo).xAxisRendererInfo;

            if (xari._axis != null)
            {
                AxisTitleRendererInfo atri = xari._axisTitleRendererInfo;

                // Calculate space used for axis title.
                XSize titleSize = new XSize(0, 0);
                if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0)
                {
                    titleSize          = _rendererParms.Graphics.MeasureString(atri.AxisTitleText, atri.AxisTitleFont);
                    atri.AxisTitleSize = titleSize;
                }

                // Calculate space used for tick labels.
                XSize size = new XSize(0, 0);
                if (xari.XValues.Count > 0)
                {
                    XSeries xs = xari.XValues[0];
                    foreach (XValue xv in xs)
                    {
                        if (xv != null)
                        {
                            string tickLabel = xv._value;
                            XSize  valueSize = _rendererParms.Graphics.MeasureString(tickLabel, xari.TickLabelsFont);

                            XRect rect = new XRect(new XPoint(0, 0), valueSize);
                            rect.Transform(RotateByDegrees(xari._axis.TickLabelAngle, rect.Center));
                            valueSize = rect.Size;

                            size.Height = Math.Max(valueSize.Height, size.Height);
                            size.Width += valueSize.Width;
                        }
                    }
                }

                // Remember space for later drawing.
                xari.TickLabelsHeight = size.Height;
                xari.Height           = titleSize.Height + size.Height + xari.MajorTickMarkWidth;
                xari.Width            = Math.Max(titleSize.Width, size.Width);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the axis title of the rendererInfo. All missing font attributes will be taken
        /// from the specified defaultFont.
        /// </summary>
        protected void InitAxisTitle(AxisRendererInfo rendererInfo, XFont defaultFont)
        {
            if (rendererInfo._axis._title != null)
            {
                AxisTitleRendererInfo atri = new AxisTitleRendererInfo();
                rendererInfo._axisTitleRendererInfo = atri;

                atri._axisTitle = rendererInfo._axis._title;
                atri.AxisTitleText = rendererInfo._axis._title._caption;
                atri.AxisTitleAlignment = rendererInfo._axis._title._alignment;
                atri.AxisTitleVerticalAlignment = rendererInfo._axis._title._verticalAlignment;
                atri.AxisTitleFont = Converter.ToXFont(rendererInfo._axis._title._font, defaultFont);
                XColor fontColor = XColors.Black;
                if (rendererInfo._axis._title._font != null && !rendererInfo._axis._title._font._color.IsEmpty)
                    fontColor = rendererInfo._axis._title._font._color;
                atri.AxisTitleBrush = new XSolidBrush(fontColor);
                atri.AxisTitleOrientation = rendererInfo._axis._title._orientation;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes the axis title of the rendererInfo. All missing font attributes will be taken
        /// from the specified defaultFont.
        /// </summary>
        protected void InitAxisTitle(AxisRendererInfo rendererInfo, XFont defaultFont)
        {
            if (rendererInfo.axis.title != null)
            {
                AxisTitleRendererInfo atri = new AxisTitleRendererInfo();
                rendererInfo.axisTitleRendererInfo = atri;

                atri.axisTitle                  = rendererInfo.axis.title;
                atri.AxisTitleText              = rendererInfo.axis.title.caption;
                atri.AxisTitleAlignment         = rendererInfo.axis.title.alignment;
                atri.AxisTitleVerticalAlignment = rendererInfo.axis.title.verticalAlignment;
                atri.AxisTitleFont              = Converter.ToXFont(rendererInfo.axis.title.font, defaultFont);
                XColor fontColor = XColors.Black;
                if (rendererInfo.axis.title.font != null && !rendererInfo.axis.title.font.color.IsEmpty)
                {
                    fontColor = rendererInfo.axis.title.font.color;
                }
                atri.AxisTitleBrush       = new XSolidBrush(fontColor);
                atri.AxisTitleOrientation = rendererInfo.axis.title.orientation;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Calculates the space used for the X axis.
        /// </summary>
        internal override void Format()
        {
            AxisRendererInfo xari = ((ChartRendererInfo)_rendererParms.RendererInfo).xAxisRendererInfo;

            if (xari._axis != null)
            {
                AxisTitleRendererInfo atri = xari._axisTitleRendererInfo;

                // Calculate space used for axis title.
                XSize titleSize = new XSize(0, 0);
                if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0)
                {
                    titleSize = _rendererParms.Graphics.MeasureString(atri.AxisTitleText, atri.AxisTitleFont);
                }

                // Calculate space used for tick labels.
                XSize size = new XSize(0, 0);
                foreach (XSeries xs in xari.XValues)
                {
                    foreach (XValue xv in xs)
                    {
                        XSize valueSize = _rendererParms.Graphics.MeasureString(xv._value, xari.TickLabelsFont);
                        size.Height += valueSize.Height;
                        size.Width   = Math.Max(valueSize.Width, size.Width);
                    }
                }

                // Remember space for later drawing.
                if (atri != null)
                {
                    atri.AxisTitleSize = titleSize;
                }
                xari.TickLabelsHeight = size.Height;
                xari.Height           = size.Height;
                xari.Width            = titleSize.Width + size.Width + xari.MajorTickMarkWidth;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Draws the horizontal X axis.
        /// </summary>
        internal override void Draw()
        {
            XGraphics         gfx  = _rendererParms.Graphics;
            ChartRendererInfo cri  = (ChartRendererInfo)_rendererParms.RendererInfo;
            AxisRendererInfo  xari = cri.xAxisRendererInfo;

            double xMin          = xari.MinimumScale;
            double xMax          = xari.MaximumScale;
            double xMajorTick    = xari.MajorTick;
            double xMinorTick    = xari.MinorTick;
            double xMaxExtension = xari.MajorTick;

            // Draw tick labels. Each tick label will be aligned centered.
            int    countTickLabels = (int)xMax;
            double tickLabelStep   = xari.Height / countTickLabels;
            XPoint startPos        = new XPoint(xari.X + xari.Width - xari.MajorTickMarkWidth, xari.Y + tickLabelStep / 2);

            foreach (XSeries xs in xari.XValues)
            {
                for (int idx = countTickLabels - 1; idx >= 0; --idx)
                {
                    XValue xv        = xs[idx];
                    string tickLabel = xv._value;
                    XSize  size      = gfx.MeasureString(tickLabel, xari.TickLabelsFont);
                    XPoint point     = new XPoint(startPos.X - size.Width, startPos.Y + size.Height / 2);
                    startPos.Y += tickLabelStep;

                    XRect bounds = DrawTickLabel(gfx, tickLabel, point, size, xari);
                }
            }

            // Draw axis.
            // First draw tick marks, second draw axis.
            double majorTickMarkStart = 0, majorTickMarkEnd = 0,
                   minorTickMarkStart = 0, minorTickMarkEnd = 0;

            GetTickMarkPos(xari, ref majorTickMarkStart, ref majorTickMarkEnd, ref minorTickMarkStart, ref minorTickMarkEnd);

            LineFormatRenderer lineFormatRenderer = new LineFormatRenderer(gfx, xari.LineFormat);

            XPoint[] points = new XPoint[2];

            // Minor ticks.
            if (xari.MinorTickMark != TickMarkType.None)
            {
                int    countMinorTickMarks = (int)(xMax / xMinorTick);
                double minorTickMarkStep   = xari.Height / countMinorTickMarks;
                startPos.Y = xari.Y;
                for (int x = 0; x <= countMinorTickMarks; x++)
                {
                    points[0].X = minorTickMarkStart;
                    points[0].Y = startPos.Y + minorTickMarkStep * x;
                    points[1].X = minorTickMarkEnd;
                    points[1].Y = points[0].Y;
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            // Major ticks.
            if (xari.MajorTickMark != TickMarkType.None)
            {
                int    countMajorTickMarks = (int)(xMax / xMajorTick);
                double majorTickMarkStep   = xari.Height / countMajorTickMarks;
                startPos.Y = xari.Y;
                for (int x = 0; x <= countMajorTickMarks; x++)
                {
                    points[0].X = majorTickMarkStart;
                    points[0].Y = startPos.Y + majorTickMarkStep * x;
                    points[1].X = majorTickMarkEnd;
                    points[1].Y = points[0].Y;
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            // Axis.
            if (xari.LineFormat != null)
            {
                points[0].X = xari.X + xari.Width;
                points[0].Y = xari.Y;
                points[1].X = xari.X + xari.Width;
                points[1].Y = xari.Y + xari.Height;
                if (xari.MajorTickMark != TickMarkType.None)
                {
                    points[0].Y -= xari.LineFormat.Width / 2;
                    points[1].Y += xari.LineFormat.Width / 2;
                }
                lineFormatRenderer.DrawLine(points[0], points[1]);
            }

            // Draw axis title.
            AxisTitleRendererInfo atri = xari._axisTitleRendererInfo;

            if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0)
            {
                XRect rect = new XRect(xari.X, xari.Y + xari.Height / 2, atri.AxisTitleSize.Width, 0);
                gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, rect);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Draws the axis title.
        /// </summary>
        internal override void Draw()
        {
            AxisRendererInfo      ari  = (AxisRendererInfo)_rendererParms.RendererInfo;
            AxisTitleRendererInfo atri = ari._axisTitleRendererInfo;

            if (atri.AxisTitleText != "")
            {
                XGraphics gfx = _rendererParms.Graphics;
                if (atri.AxisTitleOrientation != 0)
                {
                    XRect layout = atri.Rect;
                    layout.X = -(layout.Width / 2);
                    layout.Y = -(layout.Height / 2);

                    double x = 0;
                    switch (atri.AxisTitleAlignment)
                    {
                    case HorizontalAlignment.Center:
                        x = atri.X + atri.Width / 2;
                        break;

                    case HorizontalAlignment.Right:
                        x = atri.X + atri.Width - layout.Width / 2;
                        break;

                    case HorizontalAlignment.Left:
                    default:
                        x = atri.X;
                        break;
                    }

                    double y = 0;
                    switch (atri.AxisTitleVerticalAlignment)
                    {
                    case VerticalAlignment.Center:
                        y = atri.Y + atri.Height / 2;
                        break;

                    case VerticalAlignment.Bottom:
                        y = atri.Y + atri.Height - layout.Height / 2;
                        break;

                    case VerticalAlignment.Top:
                    default:
                        y = atri.Y;
                        break;
                    }

                    XStringFormat xsf = new XStringFormat();
                    xsf.Alignment     = XStringAlignment.Center;
                    xsf.LineAlignment = XLineAlignment.Center;

                    XGraphicsState state = gfx.Save();
                    gfx.TranslateTransform(x, y);
                    gfx.RotateTransform(-atri.AxisTitleOrientation);
                    gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, layout, xsf);
                    gfx.Restore(state);
                }
                else
                {
                    XStringFormat format = new XStringFormat();
                    switch (atri.AxisTitleAlignment)
                    {
                    case HorizontalAlignment.Center:
                        format.Alignment = XStringAlignment.Center;
                        break;

                    case HorizontalAlignment.Right:
                        format.Alignment = XStringAlignment.Far;
                        break;

                    case HorizontalAlignment.Left:
                    default:
                        format.Alignment = XStringAlignment.Near;
                        break;
                    }

                    switch (atri.AxisTitleVerticalAlignment)
                    {
                    case VerticalAlignment.Center:
                        format.LineAlignment = XLineAlignment.Center;
                        break;

                    case VerticalAlignment.Bottom:
                        format.LineAlignment = XLineAlignment.Far;
                        break;

                    case VerticalAlignment.Top:
                    default:
                        format.LineAlignment = XLineAlignment.Near;
                        break;
                    }

                    gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, atri.Rect, format);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Draws the horizontal X axis.
        /// </summary>
        internal override void Draw()
        {
            XGraphics         gfx  = this.rendererParms.Graphics;
            ChartRendererInfo cri  = (ChartRendererInfo)this.rendererParms.RendererInfo;
            AxisRendererInfo  xari = cri.xAxisRendererInfo;

            double xMin          = xari.MinimumScale;
            double xMax          = xari.MaximumScale;
            double xMajorTick    = xari.MajorTick;
            double xMinorTick    = xari.MinorTick;
            double xMaxExtension = xari.MajorTick;

            // Draw tick labels. Each tick label will be aligned centered.
            int    countTickLabels = (int)xMax;
            double tickLabelStep   = xari.Width;

            if (countTickLabels != 0)
            {
                tickLabelStep = xari.Width / countTickLabels;
            }

            //XPoint startPos = new XPoint(xari.X + tickLabelStep / 2, xari.Y + /*xari.TickLabelsHeight +*/ xari.MajorTickMarkWidth);
            XPoint startPos = new XPoint(xari.X + tickLabelStep / 2, xari.Y + xari.TickLabelsHeight);

            if (xari.MajorTickMark != TickMarkType.None)
            {
                startPos.Y += xari.MajorTickMarkWidth;
            }
            foreach (XSeries xs in xari.XValues)
            {
                for (int idx = 0; idx < countTickLabels && idx < xs.Count; ++idx)
                {
                    XValue xv = xs[idx];
                    if (xv != null)
                    {
                        string tickLabel = xv.Value;
                        XSize  size      = gfx.MeasureString(tickLabel, xari.TickLabelsFont);
                        gfx.DrawString(tickLabel, xari.TickLabelsFont, xari.TickLabelsBrush, startPos.X - size.Width / 2, startPos.Y);
                    }
                    startPos.X += tickLabelStep;
                }
            }

            // Draw axis.
            // First draw tick marks, second draw axis.
            double majorTickMarkStart = 0, majorTickMarkEnd = 0,
                   minorTickMarkStart = 0, minorTickMarkEnd = 0;

            GetTickMarkPos(xari, ref majorTickMarkStart, ref majorTickMarkEnd, ref minorTickMarkStart, ref minorTickMarkEnd);

            LineFormatRenderer lineFormatRenderer = new LineFormatRenderer(gfx, xari.LineFormat);

            XPoint[] points = new XPoint[2];

            // Minor ticks.
            if (xari.MinorTickMark != TickMarkType.None)
            {
                int    countMinorTickMarks = (int)(xMax / xMinorTick);
                double minorTickMarkStep   = xari.Width / countMinorTickMarks;
                startPos.X = xari.X;
                for (int x = 0; x <= countMinorTickMarks; x++)
                {
                    points[0].X = startPos.X + minorTickMarkStep * x;
                    points[0].Y = minorTickMarkStart;
                    points[1].X = points[0].X;
                    points[1].Y = minorTickMarkEnd;
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            // Major ticks.
            if (xari.MajorTickMark != TickMarkType.None)
            {
                int    countMajorTickMarks = (int)(xMax / xMajorTick);
                double majorTickMarkStep   = xari.Width;
                if (countMajorTickMarks != 0)
                {
                    majorTickMarkStep = xari.Width / countMajorTickMarks;
                }
                startPos.X = xari.X;
                for (int x = 0; x <= countMajorTickMarks; x++)
                {
                    points[0].X = startPos.X + majorTickMarkStep * x;
                    points[0].Y = majorTickMarkStart;
                    points[1].X = points[0].X;
                    points[1].Y = majorTickMarkEnd;
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            // Axis.
            if (xari.LineFormat != null)
            {
                points[0].X = xari.X;
                points[0].Y = xari.Y;
                points[1].X = xari.X + xari.Width;
                points[1].Y = xari.Y;
                if (xari.MajorTickMark != TickMarkType.None)
                {
                    points[0].X -= xari.LineFormat.Width / 2;
                    points[1].X += xari.LineFormat.Width / 2;
                }
                lineFormatRenderer.DrawLine(points[0], points[1]);
            }

            // Draw axis title.
            AxisTitleRendererInfo atri = xari.axisTitleRendererInfo;

            if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0)
            {
                XRect rect = new XRect(xari.Rect.Right / 2 - atri.AxisTitleSize.Width / 2, xari.Rect.Bottom,
                                       atri.AxisTitleSize.Width, 0);
                gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, rect);
            }
        }