/// <summary>
    /// Returns a initialized rendererInfo based on the Y axis.
    /// </summary>
    internal override RendererInfo Init()
    {
      Chart chart = (Chart)this.rendererParms.DrawingItem;
      XGraphics gfx = this.rendererParms.Graphics;

      AxisRendererInfo yari = new AxisRendererInfo();
      yari.axis = chart.yAxis;
      InitScale(yari);
      if (yari.axis != null)
      {
        ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;
        InitTickLabels(yari, cri.DefaultFont);
        InitAxisTitle(yari, cri.DefaultFont);
        InitAxisLineFormat(yari);
        InitGridlines(yari);
      }
      return yari;
    }
    /// <summary>
    /// Returns an initialized rendererInfo based on the X axis.
    /// </summary>
    internal override RendererInfo Init()
    {
      Chart chart = (Chart)this.rendererParms.DrawingItem;

      AxisRendererInfo xari = new AxisRendererInfo();
      xari.axis = chart.xAxis;
      if (xari.axis != null)
      {
        ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

        CalculateXAxisValues(xari);
        InitXValues(xari);
        InitAxisTitle(xari, cri.DefaultFont);
        InitTickLabels(xari, cri.DefaultFont);
        InitAxisLineFormat(xari);
        InitGridlines(xari);
      }
      return xari;
    }
Пример #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;
            }
        }
Пример #4
0
        /// <summary>
        /// Initializes the tick labels of the rendererInfo. All missing font attributes will be taken
        /// from the specified defaultFont.
        /// </summary>
        protected void InitTickLabels(AxisRendererInfo rendererInfo, XFont defaultFont)
        {
            if (rendererInfo._axis._tickLabels != null)
            {
                rendererInfo.TickLabelsFont = Converter.ToXFont(rendererInfo._axis._tickLabels._font, defaultFont);
                XColor fontColor = XColors.Black;
                if (rendererInfo._axis._tickLabels._font != null && !rendererInfo._axis._tickLabels._font._color.IsEmpty)
                    fontColor = rendererInfo._axis._tickLabels._font._color;
                rendererInfo.TickLabelsBrush = new XSolidBrush(fontColor);

                rendererInfo.TickLabelsFormat = rendererInfo._axis._tickLabels._format;
                if (rendererInfo.TickLabelsFormat == null)
                    rendererInfo.TickLabelsFormat = GetDefaultTickLabelsFormat();
            }
            else
            {
                rendererInfo.TickLabelsFont = defaultFont;
                rendererInfo.TickLabelsBrush = new XSolidBrush(XColors.Black);
                rendererInfo.TickLabelsFormat = GetDefaultTickLabelsFormat();
            }
        }
    /// <summary>
    /// Calculates all values necessary for scaling the axis like minimum/maximum scale or
    /// minor/major tick.
    /// </summary>
    private void InitScale(AxisRendererInfo rendererInfo)
    {
      double yMin, yMax;
      CalcYAxis(out yMin, out yMax);
      FineTuneYAxis(rendererInfo, yMin, yMax);

      rendererInfo.MajorTickMarkWidth = DefaultMajorTickMarkWidth;
      rendererInfo.MinorTickMarkWidth = DefaultMinorTickMarkWidth;
    }
Пример #6
0
    /// <summary>
    /// Calculates optimal minimum/maximum scale and minor/major tick based on yMin and yMax.
    /// </summary>
    protected void FineTuneYAxis(AxisRendererInfo rendererInfo, double yMin, double yMax)
    {
      if (yMin == double.MaxValue && yMax == double.MinValue)
      {
        // No series data given.
        yMin = 0.0f;
        yMax = 0.9f;
      }

      if (yMin == yMax)
      {
        if (yMin == 0)
          yMax = 0.9f;
        else if (yMin < 0)
          yMax = 0;
        else if (yMin > 0)
          yMax = yMin + 1;
      }

      // If the ratio between yMax to yMin is more than 1.2, the smallest number will be set too zero.
      // It's Excel's behavior.
      if (yMin != 0)
      {
        if (yMin < 0 && yMax < 0)
        {
          if (yMin / yMax >= 1.2)
            yMax = 0;
        }
        else if (yMax / yMin >= 1.2)
          yMin = 0;
      }

      double deltaYRaw = yMax - yMin;

      int digits = (int)(Math.Log(deltaYRaw, 10) + 1);
      double normed = deltaYRaw / Math.Pow(10, digits) * 10;

      double normedStepWidth = 1;
      if (normed < 2)
        normedStepWidth = 0.2f;
      else if (normed < 5)
        normedStepWidth = 0.5f;

      AxisRendererInfo yari = rendererInfo;
      double stepWidth = normedStepWidth * Math.Pow(10.0, digits - 1.0);
      if (yari.axis == null || double.IsNaN(yari.axis.majorTick))
        yari.MajorTick = stepWidth;
      else
        yari.MajorTick = yari.axis.majorTick;

      double roundFactor = stepWidth * 0.5;
      if (yari.axis == null || double.IsNaN(yari.axis.minimumScale))
      {
        double signumMin = (yMin != 0) ? yMin / Math.Abs(yMin) : 0;
        yari.MinimumScale = (int)(Math.Abs((yMin - roundFactor) / stepWidth) - (1 * signumMin)) * stepWidth * signumMin;
      }
      else
        yari.MinimumScale = yari.axis.minimumScale;

      if (yari.axis == null || double.IsNaN(yari.axis.maximumScale))
      {
        double signumMax = (yMax != 0) ? yMax / Math.Abs(yMax) : 0;
        yari.MaximumScale = (int)(Math.Abs((yMax + roundFactor) / stepWidth) + (1 * signumMax)) * stepWidth * signumMax;
      }
      else
        yari.MaximumScale = yari.axis.maximumScale;

      if (yari.axis == null || double.IsNaN(yari.axis.minorTick))
        yari.MinorTick = yari.MajorTick / 5;
      else
        yari.MinorTick = yari.axis.minorTick;
    }
    /// <summary>
    /// Calculates the starting and ending y position for the minor and major tick marks.
    /// </summary>
    private void GetTickMarkPos(AxisRendererInfo rendererInfo,
                                ref double majorTickMarkStart, ref double majorTickMarkEnd,
                                ref double minorTickMarkStart, ref double minorTickMarkEnd)
    {
      double majorTickMarkWidth = rendererInfo.MajorTickMarkWidth;
      double minorTickMarkWidth = rendererInfo.MinorTickMarkWidth;
      double x = rendererInfo.Rect.X + rendererInfo.Rect.Width;

      switch (rendererInfo.MajorTickMark)
      {
        case TickMarkType.Inside:
          majorTickMarkStart = x;
          majorTickMarkEnd = x + majorTickMarkWidth;
          break;

        case TickMarkType.Outside:
          majorTickMarkStart = x - majorTickMarkWidth;
          majorTickMarkEnd   = x;
          break;

        case TickMarkType.Cross:
          majorTickMarkStart = x - majorTickMarkWidth;
          majorTickMarkEnd = x + majorTickMarkWidth;
          break;

        case TickMarkType.None:
          majorTickMarkStart = 0;
          majorTickMarkEnd = 0;
          break;
      }

      switch (rendererInfo.MinorTickMark)
      {
        case TickMarkType.Inside:
          minorTickMarkStart = x;
          minorTickMarkEnd = x + minorTickMarkWidth;
          break;

        case TickMarkType.Outside:
          minorTickMarkStart = x - minorTickMarkWidth;
          minorTickMarkEnd = x;
          break;

        case TickMarkType.Cross:
          minorTickMarkStart = x - minorTickMarkWidth;
          minorTickMarkEnd = x + minorTickMarkWidth;
          break;

        case TickMarkType.None:
          minorTickMarkStart = 0;
          minorTickMarkEnd = 0;
          break;
      }
    }
 /// <summary>
 /// Initializes the rendererInfo's xvalues. If not set by the user xvalues will be simply numbers
 /// from minimum scale + 1 to maximum scale.
 /// </summary>
 private void InitXValues(AxisRendererInfo rendererInfo)
 {
   rendererInfo.XValues = ((Chart)rendererInfo.axis.parent).xValues;
   if (rendererInfo.XValues == null)
   {
     rendererInfo.XValues = new XValues();
     XSeries xs = rendererInfo.XValues.AddXSeries();
     for (double i = rendererInfo.MinimumScale + 1; i <= rendererInfo.MaximumScale; ++i)
       xs.Add(i.ToString(CultureInfo.InvariantCulture));
   }
 }
    /// <summary>
    /// Calculates the X axis describing values like minimum/maximum scale, major/minor tick and
    /// major/minor tick mark width.
    /// </summary>
    private void CalculateXAxisValues(AxisRendererInfo rendererInfo)
    {
      // Calculates the maximum number of data points over all series.
      SeriesCollection seriesCollection = ((Chart)rendererInfo.axis.parent).seriesCollection;
      int count = 0;
      foreach (Series series in seriesCollection)
        count = Math.Max(count, series.Count);

      rendererInfo.MinimumScale = 0;
      rendererInfo.MaximumScale = count; // At least 0
      rendererInfo.MajorTick = 1;
      rendererInfo.MinorTick = 0.5;
      rendererInfo.MajorTickMarkWidth = DefaultMajorTickMarkWidth;
      rendererInfo.MinorTickMarkWidth = DefaultMinorTickMarkWidth;
    }
Пример #10
0
        /// <summary>
        /// Draws the vertical Y axis.
        /// </summary>
        internal override void Draw()
        {
            AxisRendererInfo yari = ((ChartRendererInfo)this.rendererParms.RendererInfo).yAxisRendererInfo;

            double yMin       = yari.MinimumScale;
            double yMax       = yari.MaximumScale;
            double yMajorTick = yari.MajorTick;
            double yMinorTick = yari.MinorTick;

            XMatrix matrix = new XMatrix(); //XMatrix.Identity;

            matrix.TranslatePrepend(-yMin, -yari.Y);
            matrix.Scale(yari.InnerRect.Width / (yMax - yMin), 1, XMatrixOrder.Append);
            matrix.Translate(yari.X, yari.Y, XMatrixOrder.Append);

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

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

            XGraphics          gfx                = this.rendererParms.Graphics;
            LineFormatRenderer lineFormatRenderer = new LineFormatRenderer(gfx, yari.LineFormat);

            XPoint[] points = new XPoint[2];
            if (yari.MinorTickMark != TickMarkType.None)
            {
                for (double y = yMin + yMinorTick; y < yMax; y += yMinorTick)
                {
                    points[0].X = y;
                    points[0].Y = minorTickMarkStart;
                    points[1].X = y;
                    points[1].Y = minorTickMarkEnd;
                    matrix.TransformPoints(points);
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            XStringFormat xsf = new XStringFormat();

            xsf.LineAlignment = XLineAlignment.Near;
            int countTickLabels = (int)((yMax - yMin) / yMajorTick) + 1;

            for (int i = 0; i < countTickLabels; ++i)
            {
                double y   = yMin + yMajorTick * i;
                string str = y.ToString(yari.TickLabelsFormat);

                XSize labelSize = gfx.MeasureString(str, yari.TickLabelsFont);
                if (yari.MajorTickMark != TickMarkType.None)
                {
                    labelSize.Height += 1.5f * yari.MajorTickMarkWidth;
                    points[0].X       = y;
                    points[0].Y       = majorTickMarkStart;
                    points[1].X       = y;
                    points[1].Y       = majorTickMarkEnd;
                    matrix.TransformPoints(points);
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }

                XPoint[] layoutText = new XPoint[1];
                layoutText[0].X = y;
                layoutText[0].Y = yari.Y + 1.5 * yari.MajorTickMarkWidth;
                matrix.TransformPoints(layoutText);
                layoutText[0].X -= labelSize.Width / 2; // Center text vertically.
                gfx.DrawString(str, yari.TickLabelsFont, yari.TickLabelsBrush, layoutText[0], xsf);
            }

            if (yari.LineFormat != null)
            {
                points[0].X = yMin;
                points[0].Y = yari.Y;
                points[1].X = yMax;
                points[1].Y = yari.Y;
                matrix.TransformPoints(points);
                if (yari.MajorTickMark != TickMarkType.None)
                {
                    // yMax is at the upper side of the axis
                    points[0].X -= yari.LineFormat.Width / 2;
                    points[1].X += yari.LineFormat.Width / 2;
                }
                lineFormatRenderer.DrawLine(points[0], points[1]);
            }

            // Draw axis title
            if (yari.axisTitleRendererInfo != null)
            {
                RendererParameters parms = new RendererParameters();
                parms.Graphics     = gfx;
                parms.RendererInfo = yari;
                XRect rcTitle = yari.Rect;
                rcTitle.Height = yari.axisTitleRendererInfo.Height;
                rcTitle.Y     += yari.Rect.Height - rcTitle.Height;
                yari.axisTitleRendererInfo.Rect = rcTitle;
                AxisTitleRenderer atr = new AxisTitleRenderer(parms);
                atr.Draw();
            }
        }
Пример #11
0
        /// <summary>
        /// Initializes the gridlines of the rendererInfo.
        /// </summary>
        protected void InitGridlines(AxisRendererInfo rendererInfo)
        {
            if (rendererInfo._axis._minorGridlines != null)
            {
                rendererInfo.MinorGridlinesLineFormat =
                  Converter.ToXPen(rendererInfo._axis._minorGridlines._lineFormat, XColors.Black, DefaultGridLineWidth);
            }
            else if (rendererInfo._axis._hasMinorGridlines)
            {
                // No minor gridlines object are given, but user asked for.
                rendererInfo.MinorGridlinesLineFormat = new XPen(XColors.Black, DefaultGridLineWidth);
            }

            if (rendererInfo._axis._majorGridlines != null)
            {
                rendererInfo.MajorGridlinesLineFormat =
                  Converter.ToXPen(rendererInfo._axis._majorGridlines._lineFormat, XColors.Black, DefaultGridLineWidth);
            }
            else if (rendererInfo._axis._hasMajorGridlines)
            {
                // No major gridlines object are given, but user asked for.
                rendererInfo.MajorGridlinesLineFormat = new XPen(XColors.Black, DefaultGridLineWidth);
            }
        }
Пример #12
0
        /// <summary>
        /// Draws the vertical Y axis.
        /// </summary>
        internal override void Draw()
        {
            AxisRendererInfo yari = ((ChartRendererInfo)_rendererParms.RendererInfo).yAxisRendererInfo;

            double yMin       = yari.MinimumScale;
            double yMax       = yari.MaximumScale;
            double yMajorTick = yari.MajorTick;
            double yMinorTick = yari.MinorTick;

            XMatrix matrix = new XMatrix();

            matrix.TranslatePrepend(-yari.InnerRect.X, yMax);
            matrix.Scale(1, yari.InnerRect.Height / (yMax - yMin), XMatrixOrder.Append);
            matrix.ScalePrepend(1, -1); // mirror horizontal
            matrix.Translate(yari.InnerRect.X, yari.InnerRect.Y, XMatrixOrder.Append);

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

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

            XGraphics          gfx                     = _rendererParms.Graphics;
            LineFormatRenderer lineFormatRenderer      = new LineFormatRenderer(gfx, yari.LineFormat);
            LineFormatRenderer minorTickMarkLineFormat = new LineFormatRenderer(gfx, yari.MinorTickMarkLineFormat);
            LineFormatRenderer majorTickMarkLineFormat = new LineFormatRenderer(gfx, yari.MajorTickMarkLineFormat);

            XPoint[] points = new XPoint[2];

            // Draw minor tick marks.
            if (yari.MinorTickMark != TickMarkType.None)
            {
                for (double y = yMin + yMinorTick; y < yMax; y += yMinorTick)
                {
                    points[0].X = minorTickMarkStart;
                    points[0].Y = y;
                    points[1].X = minorTickMarkEnd;
                    points[1].Y = y;
                    matrix.TransformPoints(points);
                    minorTickMarkLineFormat.DrawLine(points[0], points[1]);
                }
            }

            double lineSpace = yari.TickLabelsFont.GetHeight(); // old: yari.TickLabelsFont.GetHeight(gfx);
            int    cellSpace = yari.TickLabelsFont.FontFamily.GetLineSpacing(yari.TickLabelsFont.Style);
            double xHeight   = yari.TickLabelsFont.Metrics.XHeight;

            XSize labelSize = new XSize(0, 0);

            labelSize.Height = lineSpace * xHeight / cellSpace;

            int countTickLabels = (int)((yMax - yMin) / yMajorTick) + 1;

            for (int i = 0; i < countTickLabels; ++i)
            {
                double y   = yMin + yMajorTick * i;
                string str = y.ToString(yari.TickLabelsFormat);

                labelSize.Width = gfx.MeasureString(str, yari.TickLabelsFont).Width;

                // Draw major tick marks.
                if (yari.MajorTickMark != TickMarkType.None)
                {
                    labelSize.Width += yari.MajorTickMarkWidth * 1.5;
                    points[0].X      = majorTickMarkStart;
                    points[0].Y      = y;
                    points[1].X      = majorTickMarkEnd;
                    points[1].Y      = y;
                    matrix.TransformPoints(points);
                    majorTickMarkLineFormat.DrawLine(points[0], points[1]);
                }
                else
                {
                    labelSize.Width += SpaceBetweenLabelAndTickmark;
                }

                // Draw label text.
                XPoint[] layoutText = new XPoint[1];
                layoutText[0].X = yari.InnerRect.X + yari.InnerRect.Width - labelSize.Width;
                layoutText[0].Y = y;
                matrix.TransformPoints(layoutText);
                layoutText[0].Y += labelSize.Height / 2; // Center text vertically.
                gfx.DrawString(str, yari.TickLabelsFont, yari.TickLabelsBrush, layoutText[0]);
            }

            // Draw axis.
            if (yari.LineFormat != null && yari.LineFormat.Width > 0)
            {
                points[0].X = yari.InnerRect.X + yari.InnerRect.Width;
                points[0].Y = yMin;
                points[1].X = yari.InnerRect.X + yari.InnerRect.Width;
                points[1].Y = yMax;
                matrix.TransformPoints(points);
                if (yari.MajorTickMark != TickMarkType.None)
                {
                    // yMax is at the upper side of the axis
                    points[1].Y -= yari.LineFormat.Width / 2;
                    points[0].Y += yari.LineFormat.Width / 2;
                }
                lineFormatRenderer.DrawLine(points[0], points[1]);
            }

            // Draw axis title
            if (yari._axisTitleRendererInfo != null && yari._axisTitleRendererInfo.AxisTitleText != "")
            {
                RendererParameters parms = new RendererParameters();
                parms.Graphics     = gfx;
                parms.RendererInfo = yari;
                double width = yari._axisTitleRendererInfo.Width;
                yari._axisTitleRendererInfo.Rect  = yari.InnerRect;
                yari._axisTitleRendererInfo.Width = width;
                AxisTitleRenderer atr = new AxisTitleRenderer(parms);
                atr.Draw();
            }
        }
Пример #13
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);
            }
        }
Пример #14
0
 /// <summary>
 /// Initializes the rendererInfo's xvalues. If not set by the user xvalues will be simply numbers
 /// from minimum scale + 1 to maximum scale.
 /// </summary>
 private void InitXValues(AxisRendererInfo rendererInfo)
 {
     rendererInfo.XValues = ((Chart)rendererInfo._axis._parent)._xValues;
     if (rendererInfo.XValues == null)
     {
         rendererInfo.XValues = new XValues();
         XSeries xs = rendererInfo.XValues.AddXSeries();
         for (double i = rendererInfo.MinimumScale + 1; i <= rendererInfo.MaximumScale; ++i)
             xs.Add(i.ToString(rendererInfo.TickLabelsFormat));
     }
 }
Пример #15
0
        /// <summary>
        /// Draws the gridlines into the plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

            XRect plotAreaRect = cri.plotAreaRendererInfo.Rect;

            if (plotAreaRect.IsEmpty)
            {
                return;
            }

            AxisRendererInfo xari = cri.xAxisRendererInfo;
            AxisRendererInfo yari = cri.yAxisRendererInfo;

            double xMin       = xari.MinimumScale;
            double xMax       = xari.MaximumScale;
            double yMin       = yari.MinimumScale;
            double yMax       = yari.MaximumScale;
            double xMajorTick = xari.MajorTick;
            double yMajorTick = yari.MajorTick;
            double xMinorTick = xari.MinorTick;
            double yMinorTick = yari.MinorTick;

            XMatrix matrix = cri.plotAreaRendererInfo.matrix;

            LineFormatRenderer lineFormatRenderer;
            XGraphics          gfx = this.rendererParms.Graphics;

            XPoint[] points = new XPoint[2];
            if (xari.MinorGridlinesLineFormat != null)
            {
                lineFormatRenderer = new LineFormatRenderer(gfx, xari.MinorGridlinesLineFormat);
                for (double x = xMin + xMinorTick; x < xMax; x += xMinorTick)
                {
                    points[0].X = x;
                    points[0].Y = yMin;
                    points[1].X = x;
                    points[1].Y = yMax;
                    matrix.TransformPoints(points);
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            if (xari.MajorGridlinesLineFormat != null)
            {
                lineFormatRenderer = new LineFormatRenderer(gfx, xari.MajorGridlinesLineFormat);
                for (double x = xMin; x <= xMax; x += xMajorTick)
                {
                    points[0].X = x;
                    points[0].Y = yMin;
                    points[1].X = x;
                    points[1].Y = yMax;
                    matrix.TransformPoints(points);
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            if (yari.MinorGridlinesLineFormat != null)
            {
                lineFormatRenderer = new LineFormatRenderer(gfx, yari.MinorGridlinesLineFormat);
                for (double y = yMin + yMinorTick; y < yMax; y += yMinorTick)
                {
                    points[0].X = xMin;
                    points[0].Y = y;
                    points[1].X = xMax;
                    points[1].Y = y;
                    matrix.TransformPoints(points);
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            if (yari.MajorGridlinesLineFormat != null)
            {
                lineFormatRenderer = new LineFormatRenderer(gfx, yari.MajorGridlinesLineFormat);
                for (double y = yMin; y <= yMax; y += yMajorTick)
                {
                    points[0].X = xMin;
                    points[0].Y = y;
                    points[1].X = xMax;
                    points[1].Y = y;
                    matrix.TransformPoints(points);
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }
        }
    /// <summary>
    /// Gets the top and bottom position of the major and minor tick marks depending on the
    /// tick mark type.
    /// </summary>
    private void GetTickMarkPos(AxisRendererInfo rendererInfo,
                                ref double majorTickMarkStart, ref double majorTickMarkEnd,
                                ref double minorTickMarkStart, ref double minorTickMarkEnd)
    {
      double majorTickMarkWidth = rendererInfo.MajorTickMarkWidth;
      double minorTickMarkWidth = rendererInfo.MinorTickMarkWidth;
      double y = rendererInfo.Rect.Y;

      switch (rendererInfo.MajorTickMark)
      {
        case TickMarkType.Inside:
          majorTickMarkStart = y - majorTickMarkWidth;
          majorTickMarkEnd = y;
          break;

        case TickMarkType.Outside:
          majorTickMarkStart = y;
          majorTickMarkEnd   = y + majorTickMarkWidth;
          break;

        case TickMarkType.Cross:
          majorTickMarkStart = y - majorTickMarkWidth;
          majorTickMarkEnd = y + majorTickMarkWidth;
          break;

        //TickMarkType.None:
        default:
          majorTickMarkStart = 0;
          majorTickMarkEnd = 0;
          break;
      }

      switch (rendererInfo.MinorTickMark)
      {
        case TickMarkType.Inside:
          minorTickMarkStart = y - minorTickMarkWidth;
          minorTickMarkEnd = y;
          break;

        case TickMarkType.Outside:
          minorTickMarkStart = y;
          minorTickMarkEnd = y + minorTickMarkWidth;
          break;

        case TickMarkType.Cross:
          minorTickMarkStart = y - minorTickMarkWidth;
          minorTickMarkEnd = y + minorTickMarkWidth;
          break;

        //TickMarkType.None:
        default:
          minorTickMarkStart = 0;
          minorTickMarkEnd = 0;
          break;
      }
    }
Пример #17
0
        /// <summary>
        /// Initializes the line format of the rendererInfo.
        /// </summary>
        protected void InitAxisLineFormat(AxisRendererInfo rendererInfo)
        {
            if (rendererInfo._axis._minorTickMarkInitialized)
                rendererInfo.MinorTickMark = rendererInfo._axis.MinorTickMark;

            if (rendererInfo._axis._majorTickMarkInitialized)
                rendererInfo.MajorTickMark = rendererInfo._axis.MajorTickMark;
            else
                rendererInfo.MajorTickMark = TickMarkType.Outside;

            if (rendererInfo.MinorTickMark != TickMarkType.None)
                rendererInfo.MinorTickMarkLineFormat = Converter.ToXPen(rendererInfo._axis._lineFormat, XColors.Black, DefaultMinorTickMarkLineWidth);

            if (rendererInfo.MajorTickMark != TickMarkType.None)
                rendererInfo.MajorTickMarkLineFormat = Converter.ToXPen(rendererInfo._axis._lineFormat, XColors.Black, DefaultMajorTickMarkLineWidth);

            if (rendererInfo._axis._lineFormat != null)
            {
                rendererInfo.LineFormat = Converter.ToXPen(rendererInfo._axis.LineFormat, XColors.Black, DefaultLineWidth);
                if (!rendererInfo._axis._majorTickMarkInitialized)
                    rendererInfo.MajorTickMark = TickMarkType.Outside;
            }
        }
Пример #18
0
        /// <summary>
        /// Draws the axis title.
        /// </summary>
        internal override void Draw()
        {
            AxisRendererInfo      ari  = (AxisRendererInfo)this.rendererParms.RendererInfo;
            AxisTitleRendererInfo atri = ari.axisTitleRendererInfo;

            if (atri.AxisTitleText != "")
            {
                XGraphics gfx = this.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);
                }
            }
        }