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

CPTPlotSymbol shadow does not work #478

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
CPTPlotSymbol has a property 'shadow', but it does not work.  No shadow is 
displayed.  I found one problem: it is not copied in the method -copyWithZone:, 
but even after I fixed this, the shadow is incorrectly drawn. It appears to be 
drawn on top of the plot symbol.

Original issue reported on code.google.com by tony....@netbrains.com on 20 Nov 2012 at 10:34

GoogleCodeExporter commented 8 years ago
This happens because of the way that a plot symbol is rendered.  Below is the 
code from CPTPlotSymbol.m 
You will notice in this code that shadow is set in context, then fill is done, 
then line is drawn.  When line is drawn, it is given its own shadow, as if the 
line does not have a fill.  The result is that the shadow is drawn on top of 
the fill.  In the attached screen shot, the plot symbol is a blue circle with 
black border and red shadow, with shadow offset = (0,-4) and shadowBlurRadius = 
1.

-(void)renderAsVectorInContext:(CGContextRef)context atPoint:(CGPoint)center 
scale:(CGFloat)scale
{ 
// ...

        if ( theLineStyle || theFill ) {
            CGPoint symbolAnchor = self.anchorPoint;
            CGSize symbolSize    = self.size;

            CGContextSaveGState(context);
            CGContextTranslateCTM(context, center.x + ( symbolAnchor.x - CPTFloat(0.5) ) * symbolSize.width, center.y + ( symbolAnchor.y - CPTFloat(0.5) ) * symbolSize.height);
            CGContextScaleCTM(context, scale, scale);
            [self.shadow setShadowInContext:context];

            if ( theFill ) {
                // use fillRect instead of fillPath so that images and gradients are properly centered in the symbol
                CGSize halfSize = CPTSizeMake( symbolSize.width * CPTFloat(0.5), symbolSize.height * CPTFloat(0.5) );
                CGRect bounds   = CPTRectMake(-halfSize.width, -halfSize.height, symbolSize.width, symbolSize.height);

                CGContextSaveGState(context);
                if ( !CGPathIsEmpty(theSymbolPath) ) {
                    CGContextBeginPath(context);
                    CGContextAddPath(context, theSymbolPath);
                    if ( self.usesEvenOddClipRule ) {
                        CGContextEOClip(context);
                    }
                    else {
                        CGContextClip(context);
                    }
                }
                [theFill fillRect:bounds inContext:context];
                CGContextRestoreGState(context);
            }

            if ( theLineStyle ) {
                [theLineStyle setLineStyleInContext:context];
                CGContextBeginPath(context);
                CGContextAddPath(context, theSymbolPath);
                [theLineStyle strokePathInContext:context];
            }

            CGContextRestoreGState(context);
        }

Original comment by tony....@netbrains.com on 20 Nov 2012 at 11:03

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by eskr...@mac.com on 21 Nov 2012 at 1:43

GoogleCodeExporter commented 8 years ago
This issue was closed by revision cb8b991b805a.

Original comment by eskr...@mac.com on 25 Nov 2012 at 4:51