/// <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 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(-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();
      }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Saves a graphics container with the current state of this XGraphics and 
    /// opens and uses a new graphics container.
    /// </summary>
    public XGraphicsContainer BeginContainer(XRect dstrect, XRect srcrect, XGraphicsUnit unit)
    {
      // TODO: unit
      if (unit != XGraphicsUnit.Point)
        throw new ArgumentException("The current implementation supports XGraphicsUnit.Point only.", "unit");

      XGraphicsContainer xContainer = null;
#if GDI
      if (this.targetContext == XGraphicTargetContext.GDI)
        xContainer = new XGraphicsContainer(this.gfx.Save());
#endif
#if WPF
      if (this.targetContext == XGraphicTargetContext.WPF)
        xContainer = new XGraphicsContainer();
#endif
      InternalGraphicsState iState = new InternalGraphicsState(this, xContainer);
      iState.Transform = this.transform;

      this.gsStack.Push(iState);

      if (this.renderer != null)
        this.renderer.BeginContainer(xContainer, dstrect, srcrect, unit);

      XMatrix matrix = new XMatrix();  //XMatrix.Identity;
#if true
      double scaleX = dstrect.Width / srcrect.Width;
      double scaleY = dstrect.Height / srcrect.Height;
      matrix.TranslatePrepend(-srcrect.X, -srcrect.Y);
      matrix.ScalePrepend(scaleX, scaleY);
      matrix.TranslatePrepend(dstrect.X / scaleX, dstrect.Y / scaleY);
#else
      matrix.Translate(-dstrect.X, -dstrect.Y);
      matrix.Scale(dstrect.Width / srcrect.Width, dstrect.Height / srcrect.Height);
      matrix.Translate(srcrect.X, srcrect.Y);
#endif
      AddTransform(matrix, XMatrixOrder.Prepend);

      return xContainer;
    }
Exemplo n.º 4
0
    /// <summary>
    /// Some test code to check that there are no typing errors in the formulars.
    /// </summary>
    public static void Test()
    {
      XMatrix xm1 = new XMatrix(23, -35, 837, 332, -3, 12);
      Matrix  m1 = new Matrix(23, -35, 837, 332, -3, 12);
      DumpMatrix(xm1, m1);
      XMatrix xm2 = new XMatrix(12, 235, 245, 42, 33, -56);
      Matrix  m2 = xm2.ToMatrix();
      DumpMatrix(xm2, m2);

//      xm1.Multiply(xm2, XMatrixOrder.Prepend);
//      m1.Multiply(m2, MatrixOrder.Append);
      xm1.Multiply(xm2, XMatrixOrder.Append);
      m1.Multiply(m2, MatrixOrder.Append);
      DumpMatrix(xm1, m1);

      xm1.Translate(-243, 342, XMatrixOrder.Append);
      m1.Translate(-243, 342, MatrixOrder.Append);
      DumpMatrix(xm1, m1);

      xm1.Scale(-5.66, 7.87);
      m1.Scale(-5.66f, 7.87f);
//      xm1.Scale(-5.66, 7.87, XMatrixOrder.Prepend);
//      m1.Scale(-5.66f, 7.87f, MatrixOrder.Prepend);
      DumpMatrix(xm1, m1);


      xm1.Rotate(135, XMatrixOrder.Append);
      m1.Rotate(135, MatrixOrder.Append);
      //      xm1.Scale(-5.66, 7.87, XMatrixOrder.Prepend);
      //      m1.Scale(-5.66f, 7.87f, MatrixOrder.Prepend);
      DumpMatrix(xm1, m1);

      xm1.RotateAt(177, new XPoint(-3456, 654), XMatrixOrder.Append);
      m1.RotateAt(177, new PointF(-3456, 654), MatrixOrder.Append);
      DumpMatrix(xm1, m1);

      xm1.Shear(0.76, -0.87, XMatrixOrder.Prepend);
      m1.Shear(0.76f, -0.87f, MatrixOrder.Prepend);
      DumpMatrix(xm1, m1);

      xm1 = new XMatrix(23, -35, 837, 332, -3, 12);
      m1 = new Matrix(23, -35, 837, 332, -3, 12);

      XPoint[] xpoints = new XPoint[3]{new XPoint(23, 10), new XPoint(-27, 120), new XPoint(-87, -55)};
      PointF[] points = new PointF[3]{new PointF(23, 10), new PointF(-27, 120), new PointF(-87, -55)};

      xm1.TransformPoints(xpoints);
      m1.TransformPoints(points);

      xm1.Invert();
      m1.Invert();
      DumpMatrix(xm1, m1);

    }