Reputation: 317
I need to make a realtime visual plot of some data much like the "heart beat" scope. Currently, I have data that comes in and I append a Path using lineTo(int, int)
. When the plot gets to the edge of the screen, I would like to either shift the data to the left to make room for the new data (preferred) or jump back to the left side of the screen and start erasing the beginning of the path with the new data.
I can get the data to move to the left using the offset(int, int)
method, but as a large amount of data gets added this makes a path that is unnecessarily long when all that is needed is to display the most current data. I can't find a method to remove the first part of a path. What is an efficient way to rebuild the path with the oldest data removed?
Upvotes: 0
Views: 416
Reputation: 3454
You cannot remove any Path (or parts of a Path) from an existing Path, you can only add, see Path, hence you must manage the parts on your own. To do so you split the path in seperate chunks
Path[] chunks = new Path[2]; //two chunks should be enough
Path currentPath;
private void reCreatePath(){
currentPath = new Path(chunks[0]);
currentPath.addPath(chunks[1]);
}
you can reCreate the path any time and and shift the content for the chunks
chunks[0] = chunks[1]; //moving chunks 1 -> chunks 0
chunks[1] = ... //add here your new Path
reCreatePath(); //makes a new Path using data from chunks
Upvotes: 1