Skip to content
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

Mathematical reciprocal Axis #2056

Open
yangkuiking opened this issue Jan 11, 2024 · 4 comments
Open

Mathematical reciprocal Axis #2056

yangkuiking opened this issue Jan 11, 2024 · 4 comments

Comments

@yangkuiking
Copy link

Feature description

the LogarithmicAxis is very usefull. but i also want use Mathematical reciprocal (example 1/X ),i search all internet no one todo this . it is necessary for me.

@VisualMelon
Copy link
Contributor

See #1278

I vaguely recall looking into this and having difficulty with something... but that would have been years ago and I have no recollection as to what the problem was, so it may be something I'll look into again.

@yangkuiking
Copy link
Author

ok. waiting for good news

@yangkuiking
Copy link
Author

I did a "quick and dirty" implementation for my purposes,

public class ReciprocalAxis : Axis
 {
     public ReciprocalAxis()
     {

     }

     public override bool IsXyAxis()
     {
         return true;
     }

     public override double Transform(double x)
     {
          return (ActualMinimum * ActualMaximum / x - this.Offset) * this.Scale;
     }

     public override void GetTickValues(out IList<double> majorLabelValues, out IList<double> majorTickValues, out IList<double> minorTickValues)
     {
         var dBandwidth = Math.Abs(this.ActualMaximum - this.ActualMinimum);
         var axisBandwidth = Math.Abs(this.IsVertical() ? this.ScreenMax.Y - this.ScreenMin.Y : this.ScreenMax.X - this.ScreenMin.X);

         var desiredNumberOfTicks = axisBandwidth / this.IntervalLength;
         var ticksPerDecade = desiredNumberOfTicks / dBandwidth;
         

         if (ticksPerDecade < 0.5)
         {
             minorTickValues = this.CreateTickValues(this.ActualMinimum, this.ActualMaximum, 1);
             majorTickValues = this.CreateTickValues(this.ActualMinimum, this.ActualMaximum,5);
             majorLabelValues = majorTickValues;
         }
         else if (ticksPerDecade < 1)
         {
             minorTickValues = this.CreateTickValues(this.ActualMinimum, this.ActualMaximum, 2);
             majorTickValues = this.CreateTickValues(this.ActualMinimum, this.ActualMaximum, 5);
             majorLabelValues = majorTickValues;
         }
         else
         {
             base.GetTickValues(out majorLabelValues, out majorTickValues, out minorTickValues);
         }

     }
 }

and how to use

      var xAxis = new ReciprocalAxis
      {
          Position = AxisPosition.Bottom,
          Title = tagCurveInfo.tagModelInfo.strXTitle,
          MajorGridlineStyle = LineStyle.Solid,
          MinorGridlineStyle = LineStyle.Dot,
          IsZoomEnabled = false,
          IsPanEnabled = false,
      };
     
      TmpModel.Axes.Add(xAxis);

it's really solve my problem
image
image
image

@VisualMelon
Copy link
Contributor

Thanks for sharing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants