Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core-Plot: How to center custom image plot symbol

I'm using a custom image symbol, as described in Showing images on Scattering Graph as plot symbols in Core plot iOS. Also refer to Positioning label on CPTBarPlot (Core-Plot) regarding positioning of the data label in a CPTPlot.

However, I'm not seeing the behavior from CPTScatterPlot.labelOffset that I need. Positive values increase the distance between the image bottom and the point, while negative values increase the distance between the image top and the point. I need to center the image on the point. See screenshots:

  • positive labelOffset values: http://i.stack.imgur.com/O1uSe.png
  • negative labelOffset values: http://i.stack.imgur.com/E9fkL.png

My solution is hacky and requires me to modify the image frame in my CustomImageForScatterPlot's drawInContext method. Any ideas on how to make labelOffset work how I want?

like image 916
danhbear Avatar asked Feb 03 '13 18:02

danhbear


1 Answers

That behavior is correct for data labels. You want to use a plot symbol.

-(CPTPlotSymbol *)symbolForScatterPlot:(CPTScatterPlot *)plot
                           recordIndex:(NSUInteger)index
{
    CPTPlotSymbol *symbol = nil;

    if ( /* use symbol for this index? */ ) {
        symbol = [CPTPlotSymbol ellipsePlotSymbol];
        symbol.fill = [CPTFill fillWithImage:/* symbol image */];
        symbol.size = CGSizeMake(width, height);
    }

    return symbol;
}

If you want every point to have a symbol, set the plotSymbol property instead of implementing this datasource method.

like image 103
Eric Skroch Avatar answered Oct 22 '22 14:10

Eric Skroch