eoinnorris / core-plot

Automatically exported from code.google.com/p/core-plot
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

[CPTLegend legendWithPlots:] does not use retina graphics for plot symbols if plot is not part of the graph #524

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If you want to display symbols in your legend that are different to your plot 
you need to use [CPTLegend legendWithPlots:]. Unfortunately this does not work 
correctly on retina iPhone.

What steps will reproduce the problem?
1.Using SimpleScatterPlot from the Coreplot Gallery create a dummy plot and 
assign a plot symbol with image fill like so:

    // Add plot symbols
    CPTPlotSymbol *plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
    UIImage *img = [UIImage imageNamed:@"graph-point-yellow"];
    plotSymbol.fill               = [CPTFill fillWithImage:[CPTImage imageWithCGImage:img.CGImage scale:img.scale]];
    plotSymbol.size               = CGSizeMake(21.0, 21.0);
    dataSourceLinePlot.plotSymbol = plotSymbol;

    CPTScatterPlot *dummyPlot = [[[CPTScatterPlot alloc] init] autorelease];
    dummyPlot.dataLineStyle = dataSourceLinePlot.dataLineStyle;
    dummyPlot.plotSymbol = plotSymbol;
    dummyPlot.identifier = @"Dummy";

    // Add legend
    //graph.legend                 = [CPTLegend legendWithGraph:graph];
    graph.legend                 = [CPTLegend legendWithPlots:@[dummyPlot]];

What is the expected output? What do you see instead?
The legend will be displayed using the non retina plot symbol image. On retina 
devices it should use the correct @2x image.

What version of the product are you using? On what operating system?
CorePlot 1.1, iOS

Please provide any additional information below.
This does work if you add the dummy plot to the actual graph:
[graph addPlot:dummyPlot];
graph.legend = [CPTLegend legendWithPlots:@[dummyPlot]];

Original issue reported on code.google.com by imu...@gmail.com on 11 Apr 2013 at 10:00

GoogleCodeExporter commented 9 years ago
Created again with correct formatting, please discard previous version.

Original comment by imu...@gmail.com on 11 Apr 2013 at 10:02

GoogleCodeExporter commented 9 years ago
Issue 523 has been merged into this issue.

Original comment by eskr...@mac.com on 11 Apr 2013 at 11:06

GoogleCodeExporter commented 9 years ago

Original comment by eskr...@mac.com on 11 Apr 2013 at 11:17

GoogleCodeExporter commented 9 years ago
After further investigation, I've determined that is working as designed. Every 
CALayer, including all visual elements in Core Plot, has a property called 
contentsScale that defaults to 1.0. When a graph is added to a hosting view, 
the hosting view sets the contentsScale for the graph and all of its sublayers.

The solution is to set the contentsScale of the dummyPlot like this:

dummyPlot.contentsScale = [UIScreen mainScreen].scale;

Original comment by eskr...@mac.com on 26 Apr 2013 at 11:45