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

Interactive Plots Take up all of ram #6

Open
jgkogan opened this issue Jun 26, 2017 · 1 comment
Open

Interactive Plots Take up all of ram #6

jgkogan opened this issue Jun 26, 2017 · 1 comment

Comments

@jgkogan
Copy link

jgkogan commented Jun 26, 2017

I'm trying to make a gui where the plot changes as time goes on. The problem is the only way to do it is to continually draw plots on top of each other. This makes it so that the program has over a thousand identical plots and it cannot work anymore. There needs to be a way to close a plot and then redraw it so it doesn't take up all of memory.

import controlP5.;
import grafica.
;

ControlP5 cp5;
int nPoints = 0;
String textValue = "";
GPlot plot;
void setup() {
size(700, 900);
PFont font = createFont("arial", 20);
cp5 = new ControlP5(this);
cp5.addTextfield("drops")
.setPosition(150, 100)
.setSize(100, 40)
.setFont(font)
.setFocus(true)
.setAutoClear(false);
cp5.addTextfield("time in secs")
.setPosition(300, 100)
.setSize(100, 40)
.setFont(font)
.setAutoClear(false);
cp5.addBang("Deliver Water")
.setPosition(450, 100)
.setSize(100, 40)
.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER);

//textFont(font);
//intro();
plot = new GPlot(this);
plot.getXAxis().setAxisLabelText("x axis");
plot.getYAxis().setAxisLabelText("y axis");
plot.setPos(100, 400);

}

void draw () {

//plot.setPoints(points);
plot.beginDraw();
plot.drawBackground();
plot.drawBox();
plot.drawXAxis();
plot.drawYAxis();
plot.drawTopAxis();
plot.drawRightAxis();
plot.drawTitle();
plot.getMainLayer().drawPoints();
plot.endDraw();

plot.addPoint(float(nPoints),float(nPoints),"pt" + nPoints);

nPoints++;
//delay(500);
}

void generatePlot(){

}

void controlEvent(ControlEvent theEvent) {

println(theEvent.getName());
println(cp5.get(Textfield.class, "drops").getText());
println(cp5.get(Textfield.class, "time in secs").getText());

}

@jagracar
Copy link
Owner

Hi,

I tested your program and it runs fine on my laptop, with no memory problems.

Note that each time you draw the plot inside the draw method you are not creating a new plot object,
so this should not add up to the memory. You are however adding a new point to the points
arrays inside the plot object, so this could have some effect on the memory, but it should be minimal.

My recommendation is that you could control the total number of points that are drawn, setting a
maximum number of points. For example, you can define a global variable:

int maxPoints = 5000;

and then add this if at the end of the draw method:

if (nPoints > maxPoints){
plot.removePoint(0);
nPoints--;
}

That will remove the oldest (first) point in the current array.

Cheers!

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