/// <summary>
 /// Draws the border around the plot area.
 /// </summary>
 internal override void Draw()
 {
   ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;
   if (cri.plotAreaRendererInfo.LineFormat != null && cri.plotAreaRendererInfo.LineFormat.Width > 0)
   {
     XGraphics gfx = this.rendererParms.Graphics;
     LineFormatRenderer lineFormatRenderer = new LineFormatRenderer(gfx, cri.plotAreaRendererInfo.LineFormat);
     lineFormatRenderer.DrawRectangle(cri.plotAreaRendererInfo.Rect);
   }
 }
예제 #2
0
        /// <summary>
        /// Draws the border around the plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

            if (cri.plotAreaRendererInfo.LineFormat != null && cri.plotAreaRendererInfo.LineFormat.Width > 0)
            {
                XGraphics          gfx = this.rendererParms.Graphics;
                LineFormatRenderer lineFormatRenderer = new LineFormatRenderer(gfx, cri.plotAreaRendererInfo.LineFormat);
                lineFormatRenderer.DrawRectangle(cri.plotAreaRendererInfo.Rect);
            }
        }
    /// <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();
      }
    }
    /// <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]);
        }
      }
    }
예제 #5
0
        /// <summary>
        /// Draws the gridlines into the plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)_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;
            double xMaxExtension = xari.MajorTick;

            XMatrix matrix = cri.plotAreaRendererInfo._matrix;

            LineFormatRenderer lineFormatRenderer;
            XGraphics          gfx = _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].Y = x;
                    points[0].X = yMin;
                    points[1].Y = x;
                    points[1].X = 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].Y = x;
                    points[0].X = yMin;
                    points[1].Y = x;
                    points[1].X = 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].Y = xMin;
                    points[0].X = y;
                    points[1].Y = xMax;
                    points[1].X = 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].Y = xMin;
                    points[0].X = y;
                    points[1].Y = xMax;
                    points[1].X = y;
                    matrix.TransformPoints(points);
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Draws the content of the bar plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)_rendererParms.RendererInfo;

            XRect plotAreaBox = cri.plotAreaRendererInfo.Rect;

            if (plotAreaBox.IsEmpty)
            {
                return;
            }

            XGraphics gfx = _rendererParms.Graphics;

            double xMin       = cri.xAxisRendererInfo.MinimumScale;
            double xMax       = cri.xAxisRendererInfo.MaximumScale;
            double yMin       = cri.yAxisRendererInfo.MinimumScale;
            double yMax       = cri.yAxisRendererInfo.MaximumScale;
            double xMajorTick = cri.xAxisRendererInfo.MajorTick;

            LineFormatRenderer lineFormatRenderer;

            // Under some circumstances it is possible that no zero base line will be drawn,
            // e. g. because of unfavourable minimum/maximum scale and/or major tick, so force to draw
            // a zero base line if necessary.
            if (cri.yAxisRendererInfo.MajorGridlinesLineFormat != null ||
                cri.yAxisRendererInfo.MinorGridlinesLineFormat != null)
            {
                if (yMin < 0 && yMax > 0)
                {
                    XPoint[] points = new XPoint[2];
                    points[0].X = 0;
                    points[0].Y = xMin;
                    points[1].X = 0;
                    points[1].Y = xMax;
                    cri.plotAreaRendererInfo._matrix.TransformPoints(points);

                    if (cri.yAxisRendererInfo.MinorGridlinesLineFormat != null)
                    {
                        lineFormatRenderer = new LineFormatRenderer(gfx, cri.yAxisRendererInfo.MinorGridlinesLineFormat);
                    }
                    else
                    {
                        lineFormatRenderer = new LineFormatRenderer(gfx, cri.yAxisRendererInfo.MajorGridlinesLineFormat);
                    }

                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            // Draw bars
            XGraphicsState state = gfx.Save();

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                foreach (ColumnRendererInfo column in sri._pointRendererInfos)
                {
                    // Do not draw bar if value is outside yMin/yMax range. Clipping does not make sense.
                    if (IsDataInside(yMin, yMax, column.Point._value))
                    {
                        gfx.DrawRectangle(column.FillFormat, column.Rect);
                    }
                }
            }

            // Draw borders around bar.
            // A border can overlap neighbor bars, so it is important to draw borders at the end.
            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                foreach (ColumnRendererInfo column in sri._pointRendererInfos)
                {
                    // Do not draw bar if value is outside yMin/yMax range. Clipping does not make sense.
                    if (IsDataInside(yMin, yMax, column.Point._value))
                    {
                        lineFormatRenderer = new LineFormatRenderer(gfx, column.LineFormat);
                        lineFormatRenderer.DrawRectangle(column.Rect);
                    }
                }
            }
            gfx.Restore(state);
        }
    /// <summary>
    /// Draws the content of the bar plot area.
    /// </summary>
    internal override void Draw()
    {
      ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

      XRect plotAreaBox = cri.plotAreaRendererInfo.Rect;
      if (plotAreaBox.IsEmpty)
        return;

      XGraphics gfx = this.rendererParms.Graphics;

      double xMin = cri.xAxisRendererInfo.MinimumScale;
      double xMax = cri.xAxisRendererInfo.MaximumScale;
      double yMin = cri.yAxisRendererInfo.MinimumScale;
      double yMax = cri.yAxisRendererInfo.MaximumScale;
      double xMajorTick = cri.xAxisRendererInfo.MajorTick;

      LineFormatRenderer lineFormatRenderer;

      // Under some circumstances it is possible that no zero base line will be drawn,
      // e. g. because of unfavourable minimum/maximum scale and/or major tick, so force to draw
      // a zero base line if necessary.
      if (cri.yAxisRendererInfo.MajorGridlinesLineFormat != null ||
          cri.yAxisRendererInfo.MinorGridlinesLineFormat != null)
      {
        if (yMin < 0 && yMax > 0)
        {
          XPoint[] points = new XPoint[2];
          points[0].X = 0;
          points[0].Y = xMin;
          points[1].X = 0;
          points[1].Y = xMax;
          cri.plotAreaRendererInfo.matrix.TransformPoints(points);

          if (cri.yAxisRendererInfo.MinorGridlinesLineFormat != null)
            lineFormatRenderer = new LineFormatRenderer(gfx, cri.yAxisRendererInfo.MinorGridlinesLineFormat);
          else
            lineFormatRenderer = new LineFormatRenderer(gfx, cri.yAxisRendererInfo.MajorGridlinesLineFormat);

          lineFormatRenderer.DrawLine(points[0], points[1]);
        }
      }

      // Draw bars
      XGraphicsState state = gfx.Save();
      foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
      {
        foreach (ColumnRendererInfo column in sri.pointRendererInfos)
        {
          // Do not draw bar if value is outside yMin/yMax range. Clipping does not make sense.
          if (IsDataInside(yMin, yMax, column.point.value))
            gfx.DrawRectangle(column.FillFormat, column.Rect);
        }
      }

      // Draw borders around bar.
      // A border can overlap neighbor bars, so it is important to draw borders at the end.
      foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
      {
        foreach (ColumnRendererInfo column in sri.pointRendererInfos)
        {
          // Do not draw bar if value is outside yMin/yMax range. Clipping does not make sense.
          if (IsDataInside(yMin, yMax, column.point.value))
          {
            lineFormatRenderer = new LineFormatRenderer(gfx, column.LineFormat);
            lineFormatRenderer.DrawRectangle(column.Rect);
          }
        }
      }
      gfx.Restore(state);
    }
    /// <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 = XMatrix.Identity;
      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 = this.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(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();
      }
    }
        /// <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);
            }
        }
    /// <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.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);
          gfx.DrawString(tickLabel, xari.TickLabelsFont, xari.TickLabelsBrush, startPos.X - size.Width, startPos.Y + size.Height / 2);
          startPos.Y += 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.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);
      }
    }
예제 #11
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();
            }
        }
        /// <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(-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                = _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();
            }
        }
예제 #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);
            }
        }