Exemplo n.º 1
0
 public void PaintMajorLabels(Graphics g, IPlotArea layer)
 {
     if (AreMajorLabelsEnabled)
     {
         var labelSide      = _majorLabelStyle.PredictLabelSide(_cachedAxisInfo);
         var outerDistance  = null == _axisLineStyle ? 0 : _axisLineStyle.GetOuterDistance(labelSide);
         var scaleWithTicks = layer.Scales[_cachedAxisInfo.Identifier.ParallelAxisNumber];
         _majorLabelStyle.Paint(g, layer.CoordinateSystem, scaleWithTicks, _customTickSpacing ?? scaleWithTicks.TickSpacing, _cachedAxisInfo, outerDistance, false);
     }
 }
Exemplo n.º 2
0
    private GraphicsPath _enclosingPath = new GraphicsPath(); // with Winding also overlapping rectangles are selected
    public override void Paint(Graphics g, XYPlotLayer layer, CSAxisInformation styleInfo, AxisLineStyle axisstyle, bool useMinorTicks)
    {
      _cachedStyleID = styleInfo.Identifier;
      CSLineID styleID = styleInfo.Identifier;
      Scale raxis = styleID.ParallelAxisNumber==0 ? layer.XAxis : layer.YAxis;

      _enclosingPath.Reset();
      _enclosingPath.FillMode = FillMode.Winding; // with Winding also overlapping rectangles are selected
      GraphicsPath helperPath = new GraphicsPath();
      Matrix math = new Matrix();

      Logical3D r0 = _cachedStyleID.Begin;
      Logical3D r1 = _cachedStyleID.End;

      SizeF layerSize = layer.Size;
      PointF outVector;
      Logical3D outer;
      float outerDistance = null==axisstyle? 0 : axisstyle.GetOuterDistance(styleInfo.PreferedLabelSide);
      float dist_x = outerDistance; // Distance from axis tick point to label
      float dist_y = outerDistance; // y distance from axis tick point to label

      // dist_x += this._font.SizeInPoints/3; // add some space to the horizontal direction in order to separate the chars a little from the ticks

      // next statement is necessary to have a consistent string length both
      // on 0 degree rotated text and rotated text
      // without this statement, the text is fitted to the pixel grid, which
      // leads to "steps" during scaling
      g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

      double[] relpositions;
      AltaxoVariant[] ticks;
      if(useMinorTicks)
      {
        relpositions = raxis.GetMinorTicksNormal();
        ticks = raxis.GetMinorTicksAsVariant();
      }
      else
      {
        relpositions = raxis.GetMajorTicksNormal();
        ticks = raxis.GetMajorTicksAsVariant();
      }
      
      IMeasuredLabelItem[] labels = _labelFormatting.GetMeasuredItems(g,_font,_stringFormat,ticks);

      float emSize = _font.SizeInPoints;
      for(int i=0;i<ticks.Length;i++)
      {
        double r = relpositions[i];

        outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, styleInfo.PreferedLabelSide);
        PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector);
        PointF tickend = tickorg;
        tickend.X += outVector.X * outerDistance;
        tickend.Y += outVector.Y * outerDistance;
       

        SizeF msize = labels[i].Size;
        PointF morg = tickend;

        if (_automaticRotationShift)
        {
          double alpha = _rotation * Math.PI / 180 - Math.Atan2(outVector.Y, outVector.X);
          double shift = msize.Height * 0.5 * Math.Abs(Math.Sin(alpha)) + (msize.Width + _font.SizeInPoints / 2) * 0.5 * Math.Abs(Math.Cos(alpha));
          morg.X += (float)(outVector.X * shift);
          morg.Y += (float)(outVector.Y * shift);
        }
        else
        {
          morg.X += (float)(outVector.X * _font.SizeInPoints/3);
        }

       
        RectangleF mrect = new RectangleF(morg,msize);
        if(_automaticRotationShift)
          AdjustRectangle(ref mrect, StringAlignment.Center, StringAlignment.Center);
        else
          AdjustRectangle(ref mrect, _horizontalAlignment, _verticalAlignment);

        math.Reset();
        math.Translate((float)morg.X, (float)morg.Y);
        if (this._rotation != 0)
        {
          math.Rotate((float)-this._rotation);
        }
        math.Translate((float)(mrect.X - morg.X + emSize * _xOffset), (float)(mrect.Y - morg.Y + emSize * _yOffset));


        System.Drawing.Drawing2D.GraphicsState gs = g.Save();
        g.MultiplyTransform(math);

        if(this._backgroundStyle!=null)
          _backgroundStyle.Draw(g,new RectangleF(PointF.Empty,msize));

        _brush.Rectangle = new RectangleF(PointF.Empty, msize);      
        labels[i].Draw(g,_brush,new PointF(0,0));
        g.Restore(gs); // Restore the graphics state

        helperPath.Reset();
        helperPath.AddRectangle(new RectangleF(PointF.Empty, msize));
        helperPath.Transform(math);

        _enclosingPath.AddPath(helperPath,true);

       
      }
    

    }
Exemplo n.º 3
0
        private GraphicsPath _enclosingPath = new GraphicsPath(); // with Winding also overlapping rectangles are selected
        public override void Paint(Graphics g, XYPlotLayer layer, CSAxisInformation styleInfo, AxisLineStyle axisstyle, bool useMinorTicks)
        {
            _cachedStyleID = styleInfo.Identifier;
            CSLineID styleID = styleInfo.Identifier;
            Scale    raxis   = styleID.ParallelAxisNumber == 0 ? layer.XAxis : layer.YAxis;

            _enclosingPath.Reset();
            _enclosingPath.FillMode = FillMode.Winding; // with Winding also overlapping rectangles are selected
            GraphicsPath helperPath = new GraphicsPath();
            Matrix       math       = new Matrix();

            Logical3D r0 = _cachedStyleID.Begin;
            Logical3D r1 = _cachedStyleID.End;

            SizeF     layerSize = layer.Size;
            PointF    outVector;
            Logical3D outer;
            float     outerDistance = null == axisstyle? 0 : axisstyle.GetOuterDistance(styleInfo.PreferedLabelSide);
            float     dist_x        = outerDistance; // Distance from axis tick point to label
            float     dist_y        = outerDistance; // y distance from axis tick point to label

            // dist_x += this._font.SizeInPoints/3; // add some space to the horizontal direction in order to separate the chars a little from the ticks

            // next statement is necessary to have a consistent string length both
            // on 0 degree rotated text and rotated text
            // without this statement, the text is fitted to the pixel grid, which
            // leads to "steps" during scaling
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            double[]        relpositions;
            AltaxoVariant[] ticks;
            if (useMinorTicks)
            {
                relpositions = raxis.GetMinorTicksNormal();
                ticks        = raxis.GetMinorTicksAsVariant();
            }
            else
            {
                relpositions = raxis.GetMajorTicksNormal();
                ticks        = raxis.GetMajorTicksAsVariant();
            }

            IMeasuredLabelItem[] labels = _labelFormatting.GetMeasuredItems(g, _font, _stringFormat, ticks);

            float emSize = _font.SizeInPoints;

            for (int i = 0; i < ticks.Length; i++)
            {
                double r = relpositions[i];

                outer = layer.CoordinateSystem.GetLogicalDirection(styleID.ParallelAxisNumber, styleInfo.PreferedLabelSide);
                PointF tickorg = layer.CoordinateSystem.GetNormalizedDirection(r0, r1, r, outer, out outVector);
                PointF tickend = tickorg;
                tickend.X += outVector.X * outerDistance;
                tickend.Y += outVector.Y * outerDistance;


                SizeF  msize = labels[i].Size;
                PointF morg  = tickend;

                if (_automaticRotationShift)
                {
                    double alpha = _rotation * Math.PI / 180 - Math.Atan2(outVector.Y, outVector.X);
                    double shift = msize.Height * 0.5 * Math.Abs(Math.Sin(alpha)) + (msize.Width + _font.SizeInPoints / 2) * 0.5 * Math.Abs(Math.Cos(alpha));
                    morg.X += (float)(outVector.X * shift);
                    morg.Y += (float)(outVector.Y * shift);
                }
                else
                {
                    morg.X += (float)(outVector.X * _font.SizeInPoints / 3);
                }


                RectangleF mrect = new RectangleF(morg, msize);
                if (_automaticRotationShift)
                {
                    AdjustRectangle(ref mrect, StringAlignment.Center, StringAlignment.Center);
                }
                else
                {
                    AdjustRectangle(ref mrect, _horizontalAlignment, _verticalAlignment);
                }

                math.Reset();
                math.Translate((float)morg.X, (float)morg.Y);
                if (this._rotation != 0)
                {
                    math.Rotate((float)-this._rotation);
                }
                math.Translate((float)(mrect.X - morg.X + emSize * _xOffset), (float)(mrect.Y - morg.Y + emSize * _yOffset));


                System.Drawing.Drawing2D.GraphicsState gs = g.Save();
                g.MultiplyTransform(math);

                if (this._backgroundStyle != null)
                {
                    _backgroundStyle.Draw(g, new RectangleF(PointF.Empty, msize));
                }

                _brush.Rectangle = new RectangleF(PointF.Empty, msize);
                labels[i].Draw(g, _brush, new PointF(0, 0));
                g.Restore(gs); // Restore the graphics state

                helperPath.Reset();
                helperPath.AddRectangle(new RectangleF(PointF.Empty, msize));
                helperPath.Transform(math);

                _enclosingPath.AddPath(helperPath, true);
            }
        }