Reverse Y-Axis in wxMathplot

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
periscopewxyun
In need of some credit
In need of some credit
Posts: 5
Joined: Sat Dec 16, 2017 6:59 am

Reverse Y-Axis in wxMathplot

Post by periscopewxyun »

Hello all,

Does anyone know how to reverse y-axis in wxMathplot? Currently, my Y-Axis starts from 0 at the bottom and goes up to the max value (for example 100) on the top. Is there a function or method to make the Y-Axis to start at the max value (100) from the bottom and go up to 0 on the top?

I attached a picture for reference.

Thank you!

periscopewxyun
Attachments
Reversed_Y_axis.png
Reversed_Y_axis.png (44.67 KiB) Viewed 1514 times
rando
Knows some wx things
Knows some wx things
Posts: 35
Joined: Fri Nov 09, 2018 9:11 pm

Re: Reverse Y-Axis in wxMathplot

Post by rando »

The last commit to wxMathPlot was in 2009. You might want to consider something more up to date.

That being said, have you looked at the wiki? the class mpScaleY looks interesting.
periscopewxyun
In need of some credit
In need of some credit
Posts: 5
Joined: Sat Dec 16, 2017 6:59 am

Re: Reverse Y-Axis in wxMathplot

Post by periscopewxyun »

rando,

Thank you for your reply. I will consider other options.

Regards,

periscopewxyun
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: Reverse Y-Axis in wxMathplot

Post by ollydbg23 »

I also need such feature.

I just tried to modify its source code by adding some function like:

Code: Select all

SetAxisOrientation(true, false);
In the void mpWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )

But it does not work.

I also try to add some function like:

Code: Select all

SetUserScale (1.0, -1.0)
But it does not work either.
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

Re: Reverse Y-Axis in wxMathplot

Post by ollydbg23 »

I try to use the solution in this thread: SetAxisOrientation does not work on wxBufferedPaintDC, but only on wxPaintDC

The SetAxisOrientation works, but the wxMathplot's source are hard to modify because it natively assume that the X axis is from left to right, and the Y axis is from bottom to top.

For example, in wxMathplot.h there are some code like below:

Code: Select all

    /** Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
      * @sa p2y,x2p,y2p */
//     double p2x(wxCoord pixelCoordX, bool drawOutside = true ); // { return m_posX + pixelCoordX/m_scaleX; }
    inline double p2x(wxCoord pixelCoordX ) { return m_posX + pixelCoordX/m_scaleX; }

    /** Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
      * @sa p2x,x2p,y2p */
//     double p2y(wxCoord pixelCoordY, bool drawOutside = true ); //{ return m_posY - pixelCoordY/m_scaleY; }
    inline double p2y(wxCoord pixelCoordY ) { return m_posY - pixelCoordY/m_scaleY; }

    /** Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
      * @sa p2x,p2y,y2p */
//     wxCoord x2p(double x, bool drawOutside = true); // { return (wxCoord) ( (x-m_posX) * m_scaleX); }
    inline wxCoord x2p(double x) { return (wxCoord) ( (x-m_posX) * m_scaleX); }

    /** Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
      * @sa p2x,p2y,x2p */
//     wxCoord y2p(double y, bool drawOutside = true); // { return (wxCoord) ( (m_posY-y) * m_scaleY); }
    inline wxCoord y2p(double y) { return (wxCoord) ( (m_posY-y) * m_scaleY); }
You see the x and y coordinates are handled differently.

I can simply change the SetAxisOrientation, but I need to change those codes too, and there are other codes I have to change.

So, I think create a custom mpScaleY is the correct way to go.
Post Reply