Skip to content

Commit

Permalink
Modified the sublayer layout in CPLayer, CPPlotArea, and CPPlotAreaFr…
Browse files Browse the repository at this point in the history
…ame to to use the frame instead of adjusting the anchor point and position. Fixed issue #157.
  • Loading branch information
eskroch committed Jun 22, 2010
1 parent b8889e4 commit 42feefc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
13 changes: 6 additions & 7 deletions framework/Source/CPLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -378,20 +378,19 @@ -(void)layoutSublayers
// This is where we do our custom replacement for the Mac-only layout manager and autoresizing mask
// Subclasses should override to lay out their own sublayers
// Sublayers fill the super layer's bounds minus any padding by default
CGFloat leftPadding = self.paddingLeft;
CGFloat bottomPadding = self.paddingBottom;

CGRect selfBounds = self.bounds;
CGSize subLayerSize = selfBounds.size;
subLayerSize.width -= self.paddingLeft + self.paddingRight;
subLayerSize.width -= leftPadding + self.paddingRight;
subLayerSize.width = MAX(subLayerSize.width, 0.0);
subLayerSize.height -= self.paddingTop + self.paddingBottom;
subLayerSize.height -= self.paddingTop + bottomPadding;
subLayerSize.height = MAX(subLayerSize.height, 0.0);

for (CALayer *subLayer in self.sublayers) {
if ([subLayer isKindOfClass:[CPLayer class]]) {
CGRect subLayerBounds = subLayer.bounds;
subLayerBounds.size = subLayerSize;
subLayer.bounds = subLayerBounds;
subLayer.anchorPoint = CGPointZero;
subLayer.position = CGPointMake(selfBounds.origin.x + self.paddingLeft, selfBounds.origin.y + self.paddingBottom);
subLayer.frame = CGRectMake(leftPadding, bottomPadding, subLayerSize.width, subLayerSize.height);
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions framework/Source/CPPieChart.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@ -(void)reloadData
}
}

#pragma mark -
#pragma mark Layout

-(void)layoutSublayers
{
[super layoutSublayers];
// [self addLabelLayers];
}

#pragma mark -
#pragma mark Drawing

Expand Down
8 changes: 3 additions & 5 deletions framework/Source/CPPlotArea.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,14 @@ -(void)layoutSublayers
sublayerPosition = CGPointMake(-sublayerPosition.x, -sublayerPosition.y);

for (CALayer *subLayer in self.sublayers) {
subLayer.bounds = sublayerBounds;
subLayer.anchorPoint = CGPointZero;
subLayer.position = sublayerPosition;
subLayer.frame = CGRectMake(sublayerPosition.x, sublayerPosition.y, sublayerBounds.size.width, sublayerBounds.size.height);
}

// make the plot group the same size as the plot area to clip the plots
CPPlotGroup *thePlotGroup = self.plotGroup;
if ( thePlotGroup ) {
thePlotGroup.bounds = self.bounds;
thePlotGroup.position = CGPointZero;
CGSize selfBoundsSize = self.bounds.size;
thePlotGroup.frame = CGRectMake(0.0, 0.0, selfBoundsSize.width, selfBoundsSize.height);
}
}

Expand Down
15 changes: 6 additions & 9 deletions framework/Source/CPPlotAreaFrame.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,21 @@ +(CGFloat)defaultZPosition

-(void)layoutSublayers
{
[super layoutSublayers];

CPPlotArea *thePlotArea = self.plotArea;
if ( thePlotArea ) {
CGFloat leftPadding = self.paddingLeft;
CGFloat bottomPadding = self.paddingBottom;

CGRect selfBounds = self.bounds;
CGSize subLayerSize = selfBounds.size;
CGFloat lineWidth = self.borderLineStyle.lineWidth;

subLayerSize.width -= self.paddingLeft + self.paddingRight + lineWidth;
subLayerSize.width -= leftPadding + self.paddingRight + lineWidth;
subLayerSize.width = MAX(subLayerSize.width, 0.0);
subLayerSize.height -= self.paddingTop + self.paddingBottom + lineWidth;
subLayerSize.height -= self.paddingTop + bottomPadding + lineWidth;
subLayerSize.height = MAX(subLayerSize.height, 0.0);

CGRect subLayerBounds = thePlotArea.bounds;
subLayerBounds.size = subLayerSize;
thePlotArea.bounds = subLayerBounds;
thePlotArea.anchorPoint = CGPointZero;
thePlotArea.position = CGPointMake(selfBounds.origin.x + self.paddingLeft, selfBounds.origin.y + self.paddingBottom);
thePlotArea.frame = CGRectMake(leftPadding, bottomPadding, subLayerSize.width, subLayerSize.height);
}
}

Expand Down

0 comments on commit 42feefc

Please sign in to comment.