Repository navigation
Add AxisArea, AxisLineArea and AxisTitleArea property in Axis class (… #1966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 4 commits
1959a5f
77d5352
53b2ef2
a7a5db8
284c795
e8e3df6
ac877c1
aa9a369
c3eb7e3
ce40c13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,13 +51,18 @@ public override void Render(Axis axis, int pass) | |
|
|
||
| var axisLength = Math.Abs(scaledEndAngle - scaledStartAngle); | ||
| var eps = axis.MinorStep * 1e-3; | ||
|
|
||
| ScreenPoint someScreenPoint = ScreenPoint.Undefined; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could do with a better name
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it not the case that all points of the angle axis have the same distance to the center? Am I getting it wrong right now?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes of course: sorry, my mistake.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... but I admit:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the points are all on the circumference, can we just derive one using Actually, that inspires a name: |
||
| double maxTextLength = double.MinValue; | ||
|
|
||
| if (this.MinorPen != null) | ||
| { | ||
| var tickCount = Math.Abs((int)(axisLength / axis.ActualMinorStep)); | ||
| var screenPoints = this.MinorTickValues | ||
| .Take(tickCount + 1) | ||
| .Select(x => magnitudeAxis.Transform(magnitudeAxis.ClipMaximum, x, axis)); | ||
|
|
||
| someScreenPoint = screenPoints.FirstOrDefault(); | ||
|
VisualMelon marked this conversation as resolved.
Outdated
|
||
| foreach (var screenPoint in screenPoints) | ||
| { | ||
| this.RenderContext.DrawLine(magnitudeAxis.MidPoint.x, magnitudeAxis.MidPoint.y, screenPoint.x, screenPoint.y, this.MinorPen, axis.EdgeRenderingMode); | ||
|
|
@@ -77,6 +82,8 @@ public override void Render(Axis axis, int pass) | |
| .Take(majorTickCount) | ||
| .Select(x => magnitudeAxis.Transform(magnitudeAxis.ClipMaximum, x, axis)); | ||
|
|
||
| if (someScreenPoint.Equals(ScreenPoint.Undefined) && screenPoints.Count() > 0) | ||
| someScreenPoint = screenPoints.FirstOrDefault(); | ||
| foreach (var point in screenPoints) | ||
| { | ||
| this.RenderContext.DrawLine(magnitudeAxis.MidPoint.x, magnitudeAxis.MidPoint.y, point.x, point.y, this.MajorPen, axis.EdgeRenderingMode); | ||
|
|
@@ -112,9 +119,26 @@ public override void Render(Axis axis, int pass) | |
| ha = HorizontalAlignment.Right; | ||
| } | ||
|
|
||
| maxTextLength = Math.Max(maxTextLength, this.RenderContext.MeasureText(text).Width); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be |
||
|
|
||
| this.RenderContext.DrawMathText( | ||
| pt, text, axis.ActualTextColor, axis.ActualFont, axis.ActualFontSize, axis.ActualFontWeight, angle, ha, va); | ||
| } | ||
|
|
||
| if (!someScreenPoint.Equals(ScreenPoint.Undefined)) | ||
| { | ||
| double r1 = magnitudeAxis.MidPoint.DistanceTo(someScreenPoint); | ||
| double r2 = r1 + maxTextLength + axis.AxisTickToLabelDistance; | ||
| if (r2 < 5) | ||
| r2 = r1 + 5; | ||
| axis.AxisLineArea = new OxyAnnulus(magnitudeAxis.MidPoint, r1, r2); | ||
| axis.AxisArea = new OxyAnnulus(magnitudeAxis.MidPoint, r1, r2); | ||
| } | ||
| else | ||
| { | ||
| axis.AxisLineArea = new OxyCircle(0, 0, 0); | ||
| axis.AxisArea = new OxyCircle(0, 0, 0); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,11 @@ namespace OxyPlot.Axes | |
| /// </summary> | ||
| public class HorizontalAndVerticalAxisRenderer : AxisRendererBase | ||
| { | ||
| private ScreenPoint pt0; | ||
|
VisualMelon marked this conversation as resolved.
Outdated
|
||
| private ScreenPoint pt1; | ||
| private ScreenPoint pt2; | ||
| private ScreenPoint pt3; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="HorizontalAndVerticalAxisRenderer" /> class. | ||
| /// </summary> | ||
|
|
@@ -274,6 +279,37 @@ protected virtual void RenderAxisTitle(Axis axis, double titlePosition) | |
|
|
||
| var lpt = this.GetAxisTitlePositionAndAlignment(axis, titlePosition, ref angle, ref halign, ref valign); | ||
|
|
||
| var titleSize = this.RenderContext.MeasureText(axis.ActualTitle, axis.ActualTitleFont, axis.TitleFontSize, axis.TitleFontWeight); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be |
||
|
|
||
| switch (axis.Position) | ||
| { | ||
| case AxisPosition.Left: | ||
| this.pt3 = new ScreenPoint(lpt.X, lpt.Y + titleSize.Width * 0.5); | ||
| this.pt2 = new ScreenPoint(lpt.X + titleSize.Height, lpt.Y - titleSize.Width * 0.5); | ||
| break; | ||
| case AxisPosition.Right: | ||
| this.pt3 = new ScreenPoint(lpt.X - titleSize.Height, lpt.Y + titleSize.Width * 0.5); | ||
| this.pt2 = new ScreenPoint(lpt.X, lpt.Y - titleSize.Width * 0.5); | ||
| break; | ||
| case AxisPosition.Top: | ||
| this.pt3 = new ScreenPoint(lpt.X - titleSize.Width * 0.5, lpt.Y + titleSize.Height); | ||
| this.pt2 = new ScreenPoint(lpt.X + titleSize.Width * 0.5, lpt.Y); | ||
| break; | ||
| case AxisPosition.Bottom: | ||
| this.pt3 = new ScreenPoint(lpt.x - titleSize.Width * 0.5, lpt.Y); | ||
| this.pt2 = new ScreenPoint(lpt.X + titleSize.Width * 0.5, lpt.Y - titleSize.Height); | ||
| break; | ||
|
|
||
| } | ||
| // TODO: ensure min area of 5px x X to capture clicks, o this above acc. to axis position | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this TODO get resolved?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @VisualMelon I added two examples based on @Jonarw's code above and added the AxisArea to be set for the MagnitudeAxisRenderer.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks indeed! Shall try to take a proper look myself later today. |
||
| //if (Math.Abs(this.pt2.X - this.pt3.X) < 5) | ||
| // this.pt3.X = this.pt2.X + 5; | ||
|
|
||
| axis.TitleArea = new OxyRect(this.pt2, this.pt3); | ||
|
|
||
| if (axis.AxisLineArea is OxyRect axisLineArea) | ||
| axis.AxisArea = axisLineArea.Union(new OxyRect(this.pt2, this.pt3)); | ||
|
|
||
| this.RenderContext.DrawMathText( | ||
| lpt, | ||
| axis.ActualTitle, | ||
|
|
@@ -378,6 +414,10 @@ protected virtual void RenderMajorItems(Axis axis, double axisPosition, double t | |
| } | ||
| } | ||
|
|
||
| // Label max width | ||
| double labelEndPosition = double.MinValue; | ||
| if (axis.Position == AxisPosition.Left || axis.Position == AxisPosition.Top) labelEndPosition = double.MaxValue; | ||
|
|
||
| // Render the axis labels (numbers or category names) | ||
| foreach (double value in this.MajorLabelValues) | ||
| { | ||
|
|
@@ -403,6 +443,9 @@ protected virtual void RenderMajorItems(Axis axis, double axisPosition, double t | |
| SnapTo(plotAreaBottom, ref transformedValue); | ||
| } | ||
|
|
||
| string text = axis.FormatValue(value); | ||
| var labelSize = this.RenderContext.MeasureText(text, axis.ActualFont, axis.ActualFontSize, axis.ActualFontWeight); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the overload that takes an angle and passing it |
||
|
|
||
| var pt = new ScreenPoint(); | ||
| var ha = HorizontalAlignment.Right; | ||
| var va = VerticalAlignment.Middle; | ||
|
|
@@ -412,25 +455,40 @@ protected virtual void RenderMajorItems(Axis axis, double axisPosition, double t | |
| pt = new ScreenPoint(axisPosition + a1 - axis.AxisTickToLabelDistance, transformedValue); | ||
| this.GetRotatedAlignments(axis.Angle, -90, out ha, out va); | ||
|
|
||
| if (axis.Angle % 90 == 0) | ||
| labelEndPosition = Math.Min(labelEndPosition, pt.x - labelSize.Width); | ||
| else | ||
| labelEndPosition = Math.Min(labelEndPosition, pt.x - labelSize.Height); | ||
| break; | ||
| case AxisPosition.Right: | ||
| pt = new ScreenPoint(axisPosition + a1 + axis.AxisTickToLabelDistance, transformedValue); | ||
| this.GetRotatedAlignments(axis.Angle, 90, out ha, out va); | ||
|
|
||
| if (axis.Angle % 90 == 0) | ||
| labelEndPosition = Math.Max(labelEndPosition, pt.x + labelSize.Width); | ||
| else | ||
| labelEndPosition = Math.Max(labelEndPosition, pt.x + labelSize.Height); | ||
| break; | ||
|
|
||
| case AxisPosition.Top: | ||
| pt = new ScreenPoint(transformedValue, axisPosition + a1 - axis.AxisTickToLabelDistance); | ||
| this.GetRotatedAlignments(axis.Angle, 0, out ha, out va); | ||
|
|
||
| if (axis.Angle % 90 == 0) | ||
| labelEndPosition = Math.Min(labelEndPosition, pt.y - labelSize.Height); | ||
| else | ||
| labelEndPosition = Math.Min(labelEndPosition, pt.y - labelSize.Width); | ||
| break; | ||
| case AxisPosition.Bottom: | ||
| pt = new ScreenPoint(transformedValue, axisPosition + a1 + axis.AxisTickToLabelDistance); | ||
| this.GetRotatedAlignments(axis.Angle, -180, out ha, out va); | ||
|
|
||
| if (axis.Angle % 90 == 0) | ||
| labelEndPosition = Math.Max(labelEndPosition, pt.y + labelSize.Width); | ||
| else | ||
| labelEndPosition = Math.Max(labelEndPosition, pt.y + labelSize.Height); | ||
| break; | ||
| } | ||
|
|
||
| string text = axis.FormatValue(value); | ||
| this.RenderContext.DrawMathText( | ||
| pt, | ||
| text, | ||
|
|
@@ -471,6 +529,21 @@ protected virtual void RenderMajorItems(Axis axis, double axisPosition, double t | |
| this.RenderContext.DrawLineSegments(extraSegments, this.ExtraPen, axis.EdgeRenderingMode.GetActual(EdgeRenderingMode.PreferSharpness)); | ||
| } | ||
|
|
||
| // Capture the points for the axis area | ||
| if (isHorizontal) | ||
| { | ||
| this.pt0 = new ScreenPoint(axis.Transform(clipMinimum), axisPosition); | ||
| this.pt1 = new ScreenPoint(axis.Transform(clipMaximum), labelEndPosition); | ||
| } | ||
| else | ||
| { | ||
| this.pt0 = new ScreenPoint(axisPosition, axis.Transform(clipMinimum)); | ||
| this.pt1 = new ScreenPoint(labelEndPosition, axis.Transform(clipMaximum)); | ||
| } | ||
|
|
||
| axis.AxisLineArea = new OxyRect(this.pt0, this.pt1); | ||
| axis.AxisArea = new OxyRect(this.pt0, this.pt1); | ||
|
|
||
| if (drawAxisLine) | ||
| { | ||
| // Draw the axis line (across the tick marks) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| using System; | ||
|
|
||
| namespace OxyPlot | ||
| { | ||
| /// <summary> | ||
| /// Describes the Interface for a shape. | ||
| /// </summary> | ||
| public interface IShape | ||
| { | ||
| /// <summary> | ||
| /// Determines whether the specified point is inside the shape. | ||
| /// </summary> | ||
| /// <param name="x">The x coordinate.</param> | ||
| /// <param name="y">The y coordinate.</param> | ||
| /// <returns><c>true</c> if the shape contains the specified point; otherwise, <c>false</c>.</returns> | ||
| bool Contains(double x, double y); | ||
|
|
||
| /// <summary> | ||
| /// Returns a <see cref="System.String" /> that represents this instance. | ||
| /// </summary> | ||
| /// <returns>A <see cref="System.String" /> that represents this instance.</returns> | ||
| string ToString(); | ||
|
|
||
| /// <summary> | ||
| /// Returns a <see cref="System.String" /> that represents this instance. | ||
| /// </summary> | ||
| /// <param name="format">The format.</param> | ||
| /// <param name="formatProvider">The format provider.</param> | ||
| /// <returns> | ||
| /// A <see cref="System.String" /> that represents this instance. | ||
| /// </returns> | ||
| public string ToString(string format, IFormatProvider formatProvider); | ||
|
VisualMelon marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.