It does sound like you require very high refresh rates.
The bottleneck is likely to simply be the drawing. Each time you update the data, the whole plot is redrawn. This is probably why insert/delete doesn't improve much over reload data: the data loading is a small part of the total time. The quartz drawing is the slow part.
So, it may be that doing the drawing yourself in your own view may not be that much faster. If Quartz is the bottleneck, that is.
To make a very high performance scope-like view, you probably have to move away from the quartz vector drawing, and just go to the bitmap level, drawing paths yourself.
Or, if you do use quartz, you may be better off drawing the path in individual line segments, rather than what Core Plot does, which is generate a complete path for the plot before rendering it.
A few other things to consider: fills are expensive, so if you are using a fill, you probably should turn that off.
Also, it may be worth experimenting with reducing the refresh rate of data reloading. This may actually improve rendering performance because it won't be overwhelmed.
In other words, don't update every time new data is available, but instead at some fixed interval of time (a few times a second).
To clear the drawing, just set a flag in your data source (eg BOOL clearDrawing), and in your numberOfRecords... data source method, return 0.
Drew
> --
> You received this message because you are subscribed to the Google Groups "coreplot-discuss" group.
> To post to this group, send email to coreplot...@googlegroups.com.
> To unsubscribe from this group, send email to coreplot-discu...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/coreplot-discuss?hl=en.
>
-(void)pointReceived:(id)point{
[self.snapshot enqueue:point]; //Add a point to the end of our array
[dataSourceLinePlot insertDataAtIndex:self.snapshot.count -1 numberOfRecords:1];
if ([self.snapshot count] > MAX_POINTS){
[dataSourceLinePlot deleteDataInIndexRange:NSMakeRange (0, 1)];
[self.snapshot removeLastObject];
}}
-(void)pointReceived:(id)point{
[self.snapshot addObject:point]; //Add new point to the end of the array
if (waitBuffer > MAX_POINTS /2) {
[dataSourceLinePlot insertDataAtIndex:self.snapshot.count-101 numberOfRecords:100]; //tell the Graph to reload said point
[dataSourceLinePlot deleteDataInIndexRange:NSMakeRange (0, 100)];//Tell the graph to delete said point
[self reconfigure];
waitBuffer = 0;
}
if (self.snapshot.count > MAX_POINTS)
[self.snapshot dequeue]; //remove the First Item in the Array
waitBuffer++;
-(void)reconfigure
{
if(!graph)
{
graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
//self.view = [[CPGraphHostingView alloc]initWithFrame:[UIScreen mainScreen].bounds];
//self.graphHost = (CPGraphHostingView *)self.view;
self.graphHost.collapsesLayers = NO;
self.graphHost.hostedGraph = graph;
graph.delegate = self;
CPTheme *theme = [CPTheme themeNamed:kCPDarkGradientTheme];
[graph applyTheme:theme];
// graph.paddingTop = 30.0;
//graph.paddingBottom = 30.0;
//graph.paddingLeft = 50.0;
//graph.paddingRight = 50.0;
dataSourceLinePlot = [[[CPScatterPlot alloc] initWithFrame:graph.bounds] autorelease];
dataSourceLinePlot.identifier = @"Data Source Plot";
CPMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
lineStyle.lineWidth = 1.f;
lineStyle.lineColor = [CPColor greenColor];
dataSourceLinePlot.dataLineStyle = lineStyle;
dataSourceLinePlot.dataSource = self;
[graph addPlot:dataSourceLinePlot];
if (plotTimer == nil){
//DLog(@"Timer Interval: %f", timerInterval);
//plotTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(rollPoints) userInfo:nil repeats:YES];
}
if([[self.graphHost.layer sublayers] indexOfObject:graph] == NSNotFound)
[self.graphHost.layer addSublayer:graph];
}
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
NSDecimalNumber *high = [NSDecimalNumber decimalNumberWithDecimal:[[NSNumber numberWithFloat:[dataPuller overallHigh]] decimalValue]];
NSDecimalNumber *low = [NSDecimalNumber decimalNumberWithDecimal:[[NSNumber numberWithFloat:[dataPuller overallLow]] decimalValue]];
NSDecimalNumber *length = [high decimalNumberBySubtracting:low];
//NSLog(@"high = %@, low = %@, length = %@", high, low, length);
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(0.0) length:CPDecimalFromUnsignedInteger(MAX_POINTS)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:[low decimalValue] length:[length decimalValue]];
// Create grid line styles
/* CPMutableLineStyle *majorGridLineStyle = [CPMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 1.0f;
majorGridLineStyle.lineColor = [[CPColor redColor] colorWithAlphaComponent:0.75];
CPMutableLineStyle *minorGridLineStyle = [CPMutableLineStyle lineStyle];
minorGridLineStyle.lineWidth = 1.0f;
minorGridLineStyle.lineColor = [[CPColor redColor] colorWithAlphaComponent:0.25]; */
// Axes
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPXYAxis *x = axisSet.xAxis;
x.majorIntervalLength = CPDecimalFromDouble(10.0);
x.orthogonalCoordinateDecimal = CPDecimalFromInteger(0);
//x.minorTicksPerInterval = 1;
//x.majorGridLineStyle = majorGridLineStyle;
//x.minorGridLineStyle = minorGridLineStyle;
//x.visibleRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-0.5f) length:CPDecimalFromFloat(10.0f)];
//x.gridLinesRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0f) length:CPDecimalFromFloat(100.0f)];
CPXYAxis *y = axisSet.yAxis;
NSDecimal six = CPDecimalFromInteger(6);
y.majorIntervalLength = CPDecimalDivide([length decimalValue], six);
y.majorTickLineStyle = nil;
// y.minorTicksPerInterval = 4;
y.minorTickLineStyle = nil;
y.orthogonalCoordinateDecimal = CPDecimalFromInteger(0);
//y.majorGridLineStyle = majorGridLineStyle;
//y.minorGridLineStyle = minorGridLineStyle;
//y.gridLinesRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-0.1f) length:CPDecimalFromFloat(.3f)];
//y.visibleRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0f) length:CPDecimalFromFloat(.4f)];
//y.alternatingBandFills = [NSArray arrayWithObjects:[[CPColor whiteColor] colorWithAlphaComponent:0.1], [NSNull null], nil];
int waitBuffer = 0;
-(void)pointReceived:(id)point
{
[self.snapshot addObject:point]; //Add new point to the end of the array
if (self.snapshot.count > MAX_POINTS +5)
[self.snapshot dequeue]; //remove the First Item in the Array
waitBuffer++;
if (waitBuffer > MAX_POINTS) {
// delete old data first so fewer numbers need to be moved around in memory; also reduces the max memory requirement
if ( dataSourceLinePlot.cachedDataCount > MAX_POINTS) {
[dataSourceLinePlot deleteDataInIndexRange:NSMakeRange(0, MAX_POINTS)];
}
[dataSourceLinePlot insertDataAtIndex:dataSourceLinePlot.cachedDataCount numberOfRecords:MAX_POINTS];
[self reconfigure];
waitBuffer = 0;
}
}
#define MAX_POINTS 800
NSTimer *plotTimer;
-(void)reconfigure
{
CPXYPlotSpace *plotSpace;
NSDecimalNumber *length;
NSDecimalNumber *high;
NSDecimalNumber *low;
if (!graph){ //One time setup
graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds];
//self.view = [[CPGraphHostingView alloc]initWithFrame:[UIScreen mainScreen].bounds];
//self.graphHost = (CPGraphHostingView *)self.view;
self.graphHost.collapsesLayers = NO;
self.graphHost.hostedGraph = graph;
graph.delegate = self;
CPTheme *theme = [CPTheme themeNamed:kCPDarkGradientTheme];
[graph applyTheme:theme];
// graph.paddingTop = 30.0;
//graph.paddingBottom = 30.0;
//graph.paddingLeft = 50.0;
//graph.paddingRight = 50.0;
dataSourceLinePlot = [[[CPScatterPlot alloc] initWithFrame:graph.bounds] autorelease];
dataSourceLinePlot.identifier = @"Data Source Plot";
dataSourceLinePlot.cachePrecision = CPPlotCachePrecisionDouble;
CPMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
lineStyle.lineWidth = 1.f;
lineStyle.lineColor = [CPColor greenColor];
dataSourceLinePlot.dataLineStyle = lineStyle;
dataSourceLinePlot.dataSource = self;
[graph addPlot:dataSourceLinePlot];
if (plotTimer == nil){
//DLog(@"Timer Interval: %f", timerInterval);
//plotTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(refreshGraph) userInfo:nil repeats:YES];
}
if([[self.graphHost.layer sublayers] indexOfObject:graph] == NSNotFound)
[self.graphHost.layer addSublayer:graph];
plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
high = [NSDecimalNumber decimalNumberWithDecimal:[[NSNumber numberWithFloat:[dataPuller overallHigh]] decimalValue]];
low = [NSDecimalNumber decimalNumberWithDecimal:[[NSNumber numberWithFloat:[dataPuller overallLow]] decimalValue]];
length = [high decimalNumberBySubtracting:low];
//NSLog(@"high = %@, low = %@, length = %@", high, low, length);
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromDouble(0.0) length:CPDecimalFromUnsignedInteger(MAX_POINTS)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:[low decimalValue] length:[length decimalValue]];
// Axes
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPXYAxis *x = axisSet.xAxis;
x.majorIntervalLength = CPDecimalFromDouble(10.0);
x.orthogonalCoordinateDecimal = CPDecimalFromInteger(0);
//x.minorTicksPerInterval = 1;
//x.majorGridLineStyle = majorGridLineStyle;
//x.minorGridLineStyle = minorGridLineStyle;
//x.visibleRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-0.5f) length:CPDecimalFromFloat(10.0f)];
//x.gridLinesRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0f) length:CPDecimalFromFloat(100.0f)];
CPXYAxis *y = axisSet.yAxis;
NSDecimal six = CPDecimalFromInteger(6);
y.majorIntervalLength = CPDecimalDivide([length decimalValue], six);
y.majorTickLineStyle = nil;
// y.minorTicksPerInterval = 4;
y.minorTickLineStyle = nil;
y.orthogonalCoordinateDecimal = CPDecimalFromInteger(0);
//y.majorGridLineStyle = majorGridLineStyle;
//y.minorGridLineStyle = minorGridLineStyle;
//y.gridLinesRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-0.1f) length:CPDecimalFromFloat(.3f)];
//y.visibleRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0.0f) length:CPDecimalFromFloat(.4f)];
//y.alternatingBandFills = [NSArray arrayWithObjects:[[CPColor whiteColor] colorWithAlphaComponent:0.1], [NSNull null], nil];
} else {
plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
high = [NSDecimalNumber decimalNumberWithDecimal:[[NSNumber numberWithFloat:[dataPuller overallHigh]] decimalValue]];
low = [NSDecimalNumber decimalNumberWithDecimal:[[NSNumber numberWithFloat:[dataPuller overallLow]] decimalValue]];
length = [high decimalNumberBySubtracting:low];