wxmathplot Slow on updating graph on zooming

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
arun_nemo
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Nov 05, 2020 9:48 am

wxmathplot Slow on updating graph on zooming

Post by arun_nemo »

Hello,
I created a wxmathplot with 62000 samples (X and Y data from csv). (http://wxmathplot.sourceforge.net/)
It takes 2 seconds to zoom and fit again for every ctrl + mouse scroll to zoom in and out.

I used the exact following code except the creation of x_values and y_values vectors.

Code: Select all

	--------------------------------------------------------

    
	double fRand(double fMin, double fMax)
	{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
	}
	
	--------------------------------------------------------
	
	std::vector<double> x_values; 
	std::vector<double> y_values; 
	for(int i=0; i<62000;i++)
	{
		x_values.push_back(i);
		y_values.push_back(fRand(1,1000));
	}
	
		--------------------------------------------------------

	mpFXYVector* vectorLayer = new mpFXYVector("Series-1");
	vectorLayer->SetData(x_values, y_values);
	vectorLayer->SetContinuity(true);
	wxPen vectorpen(*wxBLUE, 1, wxDOT);
	vectorLayer->SetPen(vectorpen); 
	vectorLayer->SetDrawOutsideMargins(false);
	

	wxFont graphFont(11, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
	m_plot = new mpWindow(m_panel6, -1, wxPoint(0, 0), wxSize(1600, 950), wxSUNKEN_BORDER);//Output Panel //900, 750
	mpScaleX* xaxis = new mpScaleX(wxT("TIME"), mpALIGN_BOTTOM, true, mpX_NORMAL);
	mpScaleY* yaxis = new mpScaleY(wxT("MAGNITUDE"), mpALIGN_LEFT, true);

	xaxis->SetFont(graphFont); 
	yaxis->SetFont(graphFont);

	xaxis->SetDrawOutsideMargins(false); 
	yaxis->SetDrawOutsideMargins(false); 

	m_plot->SetMargins(10, 110, 110, 110);
	m_plot->AddLayer(xaxis);
	m_plot->AddLayer(yaxis);


	m_plot->AddLayer(vectorLayer);
	
	m_plot->EnableDoubleBuffer(true);
	m_plot->Fit();
Please help in this regard. How to make the zoom in and zoom out seamless without any freezing.

Thank you,
Arun
Last edited by DavidHart on Tue Sep 28, 2021 12:19 pm, edited 1 time in total.
Reason: Added code-tags
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxmathplot Slow on updating graph on zooming

Post by doublemax »

I don't think there is much you can do about it. The drawing code is not optimized and draws all 62000 samples each time.

I don't know how to do it in mathplot, but you should provide a custom function that only draws one line per physical pixel in x-direction on screen, so that you don't draw so many lines each time.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxmathplot Slow on updating graph on zooming

Post by ONEEYEMAN »

Hi,
Are you on Windows? Doing a Debug build?

Thank you.
arun_nemo
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Nov 05, 2020 9:48 am

Re: wxmathplot Slow on updating graph on zooming

Post by arun_nemo »

ONEEYEMAN wrote: Tue Sep 28, 2021 8:04 pm Hi,
Are you on Windows? Doing a Debug build?

Thank you.
I am building in Windows x64, Release mode.
Thank you
arun_nemo
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Nov 05, 2020 9:48 am

Re: wxmathplot Slow on updating graph on zooming

Post by arun_nemo »

doublemax wrote: Tue Sep 28, 2021 6:39 pm I don't think there is much you can do about it. The drawing code is not optimized and draws all 62000 samples each time.

I don't know how to do it in mathplot, but you should provide a custom function that only draws one line per physical pixel in x-direction on screen, so that you don't draw so many lines each time.
Thank you for the reply.
Can you please share some link or articles to understand more on drawing per pixel if possible. Thanks again
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxmathplot Slow on updating graph on zooming

Post by doublemax »

arun_nemo wrote: Wed Sep 29, 2021 2:12 am
doublemax wrote: Tue Sep 28, 2021 6:39 pm I don't think there is much you can do about it. The drawing code is not optimized and draws all 62000 samples each time.

I don't know how to do it in mathplot, but you should provide a custom function that only draws one line per physical pixel in x-direction on screen, so that you don't draw so many lines each time.
Thank you for the reply.
Can you please share some link or articles to understand more on drawing per pixel if possible. Thanks again
This is more a logical than a technical issue.

In very simplified form, the current code does something like this:

Code: Select all

const int sampleSize = 62000;
for(int i=0; i < sampleSize; i++)
{
  int x = (int)(someScaleValue * i);
  int y = (int)(anotherScaleValue * samples[i]);
  drawPixel(x,y);
}
Which means it draws all 62000 sample regardless of the size of the display area. Which is a waste of performance, because most of the values will overlap and overdraw.

What you need is something like this:

Code: Select all

int windowWidth = 1000;
for( int x = 0, x < windowWidth; x++)
{
  y = getSample(x + offset);     // this could return the nearest value, or a maximum / average over a range of values
  drawPixel(x, y);
}
But i don't know how to do that with mathPlot, but i'm pretty sure it's possible.
Use the source, Luke!
Post Reply