Skip to content

Commit 042d108

Browse files
committed
Fixed StripLine rare bug in 3D mode. Tinny optimizations.
1 parent 1032e1f commit 042d108

File tree

1 file changed

+18
-9
lines changed
  • src/System.Windows.Forms.DataVisualization/General

1 file changed

+18
-9
lines changed

src/System.Windows.Forms.DataVisualization/General/StripLine.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ private void PaintTitle(ChartGraphics graph, RectangleF rect)
546546
return;
547547

548548
// Get title text
549-
string titleText = this.Text;
549+
string titleText = this.Text.Replace("\\n", "\n");
550+
TextOrientation drawOrientation = GetTextOrientation();
550551

551552
// Prepare string format
552553
using StringFormat format = new StringFormat();
@@ -598,7 +599,7 @@ private void PaintTitle(ChartGraphics graph, RectangleF rect)
598599
}
599600

600601
// Measure string size
601-
SizeF size = graph.MeasureStringRel(titleText.Replace("\\n", "\n"), this.Font, new SizeF(100, 100), format, this.GetTextOrientation());
602+
SizeF size = graph.MeasureStringRel(titleText, this.Font, new SizeF(100, 100), format, drawOrientation);
602603

603604
// Adjust text size
604605
float zPositon = 0f;
@@ -616,8 +617,16 @@ private void PaintTitle(ChartGraphics graph, RectangleF rect)
616617

617618
// Adjust text size
618619
int index = this.Axis.ChartArea.IsMainSceneWallOnFront() ? 0 : 1;
619-
size.Width *= size.Width / (textSizeProjection[index].X - textSizeProjection[(index == 0) ? 1 : 0].X);
620-
size.Height *= size.Height / (textSizeProjection[2].Y - textSizeProjection[0].Y);
620+
float f = textSizeProjection[index].X - textSizeProjection[(index == 0) ? 1 : 0].X;
621+
if (Math.Abs(f) < 1)
622+
f = f >= 0 ? 1 : -1;
623+
624+
size.Width *= size.Width / f;
625+
f = textSizeProjection[2].Y - textSizeProjection[0].Y;
626+
if (Math.Abs(f) < 1)
627+
f = f >= 0 ? 1 : -1;
628+
629+
size.Height *= size.Height / f;
621630
}
622631

623632

@@ -688,25 +697,25 @@ private void PaintTitle(ChartGraphics graph, RectangleF rect)
688697
rotationCenterProjection[0].PointF = graph.GetAbsolutePoint(rotationCenterProjection[0].PointF);
689698
rotationCenterProjection[1].PointF = graph.GetAbsolutePoint(rotationCenterProjection[1].PointF);
690699

691-
// Calcuate axis angle
692-
float angleXAxis = (float)Math.Atan(
700+
// Calculate axis angle
701+
float angleXAxis = MathF.Atan(
693702
(rotationCenterProjection[1].Y - rotationCenterProjection[0].Y) /
694703
(rotationCenterProjection[1].X - rotationCenterProjection[0].X));
695-
angleXAxis = (float)Math.Round(angleXAxis * 180f / (float)Math.PI);
704+
angleXAxis = MathF.Round(angleXAxis * 180 / MathF.PI);
696705
angle += (int)angleXAxis;
697706
}
698707
}
699708

700709
// Draw string
701710
using Brush brush = new SolidBrush(this.ForeColor);
702711
graph.DrawStringRel(
703-
titleText.Replace("\\n", "\n"),
712+
titleText,
704713
this.Font,
705714
brush,
706715
rotationCenter,
707716
format,
708717
angle,
709-
this.GetTextOrientation());
718+
drawOrientation);
710719
}
711720

712721
#endregion

0 commit comments

Comments
 (0)