Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
Refactored layout code.
Browse files Browse the repository at this point in the history
Reviewed graphLayout code and supporting routines.  Refactored code for
clarity and new features, it reads better now.
  • Loading branch information
epreston committed Sep 15, 2011
1 parent 167cbfa commit 878a7ee
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 282 deletions.
4 changes: 2 additions & 2 deletions PSTreeGraphView/PSBaseBranchView.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright 2010 Preston Software. All rights reserved. // Copyright 2010 Preston Software. All rights reserved.
// //
// //
// This is a port of the sample code from Max OS X to iOS (iPad). // This is a port of the sample code from Max OS X to iOS (iPad).
// //
// WWDC 2010 Session 141, “Crafting Custom Cocoa Views” // WWDC 2010 Session 141, “Crafting Custom Cocoa Views”
// //




Expand Down
34 changes: 21 additions & 13 deletions PSTreeGraphView/PSBaseBranchView.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright 2010 Preston Software. All rights reserved. // Copyright 2010 Preston Software. All rights reserved.
// //
// //
// This is a port of the sample code from Max OS X to iOS (iPad). // This is a port of the sample code from Max OS X to iOS (iPad).
// //
// WWDC 2010 Session 141, “Crafting Custom Cocoa Views” // WWDC 2010 Session 141, “Crafting Custom Cocoa Views”
// //




Expand Down Expand Up @@ -52,9 +52,11 @@ - (UIBezierPath *) directConnectionsPath
PSTreeGraphOrientationStyle treeDirection = [[self enclosingTreeGraph] treeGraphOrientation]; PSTreeGraphOrientationStyle treeDirection = [[self enclosingTreeGraph] treeGraphOrientation];


if ( treeDirection == PSTreeGraphOrientationStyleHorizontal ) { if ( treeDirection == PSTreeGraphOrientationStyleHorizontal ) {
rootPoint = CGPointMake(CGRectGetMinX(bounds), CGRectGetMidY(bounds)); rootPoint = CGPointMake(CGRectGetMinX(bounds),
CGRectGetMidY(bounds));
} else { } else {
rootPoint = CGPointMake(CGRectGetMidX(bounds), CGRectGetMinY(bounds)); rootPoint = CGPointMake(CGRectGetMidX(bounds),
CGRectGetMinY(bounds));
} }


// Create a single bezier path that we'll use to stroke all the lines. // Create a single bezier path that we'll use to stroke all the lines.
Expand All @@ -70,9 +72,11 @@ - (UIBezierPath *) directConnectionsPath
CGPoint targetPoint = CGPointZero; CGPoint targetPoint = CGPointZero;


if ( treeDirection == PSTreeGraphOrientationStyleHorizontal ) { if ( treeDirection == PSTreeGraphOrientationStyleHorizontal ) {
targetPoint = [self convertPoint:CGPointMake(CGRectGetMinX(subviewBounds), CGRectGetMidY(subviewBounds)) fromView:subview]; targetPoint = [self convertPoint:CGPointMake(CGRectGetMinX(subviewBounds), CGRectGetMidY(subviewBounds))
fromView:subview];
} else { } else {
targetPoint = [self convertPoint:CGPointMake(CGRectGetMidX(subviewBounds), CGRectGetMinY(subviewBounds)) fromView:subview]; targetPoint = [self convertPoint:CGPointMake(CGRectGetMidX(subviewBounds), CGRectGetMinY(subviewBounds))
fromView:subview];
} }


[path moveToPoint:rootPoint]; [path moveToPoint:rootPoint];
Expand Down Expand Up @@ -111,9 +115,11 @@ - (UIBezierPath *) orthogonalConnectionsPath
CGPoint rootPoint = CGPointZero; CGPoint rootPoint = CGPointZero;
if ( treeDirection == PSTreeGraphOrientationStyleHorizontal ) { if ( treeDirection == PSTreeGraphOrientationStyleHorizontal ) {
// Compute point at right edge of root node, from which its connecting line to the vertical line will emerge. // Compute point at right edge of root node, from which its connecting line to the vertical line will emerge.
rootPoint = CGPointMake(CGRectGetMinX(bounds), CGRectGetMidY(bounds)); rootPoint = CGPointMake(CGRectGetMinX(bounds),
CGRectGetMidY(bounds));
} else { } else {
rootPoint = CGPointMake(CGRectGetMidX(bounds), CGRectGetMinY(bounds)); rootPoint = CGPointMake(CGRectGetMidX(bounds),
CGRectGetMinY(bounds));
} }




Expand All @@ -124,8 +130,8 @@ - (UIBezierPath *) orthogonalConnectionsPath
// rootPoint = [self convertPointFromBase:basePoint]; // rootPoint = [self convertPointFromBase:basePoint];




// Compute point (really, we're just interested in the x value) at which line from root node intersects the // Compute point (really, we're just interested in the x value) at which line
// vertical connecting line. // from root node intersects the vertical connecting line.


CGPoint rootIntersection = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); CGPoint rootIntersection = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));


Expand Down Expand Up @@ -161,9 +167,11 @@ - (UIBezierPath *) orthogonalConnectionsPath
CGPoint targetPoint = CGPointZero; CGPoint targetPoint = CGPointZero;


if ( treeDirection == PSTreeGraphOrientationStyleHorizontal ) { if ( treeDirection == PSTreeGraphOrientationStyleHorizontal ) {
targetPoint = [self convertPoint:CGPointMake(CGRectGetMinX(subviewBounds), CGRectGetMidY(subviewBounds)) fromView:subview]; targetPoint = [self convertPoint:CGPointMake(CGRectGetMinX(subviewBounds), CGRectGetMidY(subviewBounds))
fromView:subview];
} else { } else {
targetPoint = [self convertPoint:CGPointMake(CGRectGetMidX(subviewBounds), CGRectGetMinY(subviewBounds)) fromView:subview]; targetPoint = [self convertPoint:CGPointMake(CGRectGetMidX(subviewBounds), CGRectGetMinY(subviewBounds))
fromView:subview];
} }


// Align the line to get exact pixel coverage, for sharper rendering. // Align the line to get exact pixel coverage, for sharper rendering.
Expand Down Expand Up @@ -222,7 +230,7 @@ - (UIBezierPath *) orthogonalConnectionsPath
} }


- (void) drawRect:(CGRect)dirtyRect - (void) drawRect:(CGRect)dirtyRect
{ {
// Build the set of lines to stroke, according to our enclosingTreeGraph's connectingLineStyle. // Build the set of lines to stroke, according to our enclosingTreeGraph's connectingLineStyle.
UIBezierPath *path = nil; UIBezierPath *path = nil;


Expand Down
4 changes: 2 additions & 2 deletions PSTreeGraphView/PSBaseLeafView.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright 2010 Preston Software. All rights reserved. // Copyright 2010 Preston Software. All rights reserved.
// //
// //
// This is a port of the sample code from Max OS X to iOS (iPad). // This is a port of the sample code from Max OS X to iOS (iPad).
// //
// WWDC 2010 Session 141, “Crafting Custom Cocoa Views” // WWDC 2010 Session 141, “Crafting Custom Cocoa Views”
// //




Expand Down
4 changes: 2 additions & 2 deletions PSTreeGraphView/PSBaseLeafView.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright 2010 Preston Software. All rights reserved. // Copyright 2010 Preston Software. All rights reserved.
// //
// //
// This is a port of the sample code from Max OS X to iOS (iPad). // This is a port of the sample code from Max OS X to iOS (iPad).
// //
// WWDC 2010 Session 141, “Crafting Custom Cocoa Views” // WWDC 2010 Session 141, “Crafting Custom Cocoa Views”
// //




Expand Down
10 changes: 6 additions & 4 deletions PSTreeGraphView/PSBaseSubtreeView.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@
// Copyright 2010 Preston Software. All rights reserved. // Copyright 2010 Preston Software. All rights reserved.
// //
// //
// This is a port of the sample code from Max OS X to iOS (iPad). // This is a port of the sample code from Max OS X to iOS (iPad).
// //
// WWDC 2010 Session 141, “Crafting Custom Cocoa Views” // WWDC 2010 Session 141, “Crafting Custom Cocoa Views”
// //




#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>


#import "PSTreeGraphModelNode.h" #import "PSTreeGraphModelNode.h"



@class PSBaseBranchView; @class PSBaseBranchView;
@class PSBaseTreeGraphView; @class PSBaseTreeGraphView;




/// A SubtreeView draws nothing itself (unless showsSubtreeFrames is set to YES for the enclosingTreeGraph), but /// A SubtreeView draws nothing itself (unless showsSubtreeFrames is set to YES for
/// provides a local coordinate frame and grouping mechanism for a graph subtree, and implements subtree layout. /// the enclosingTreeGraph), but provides a local coordinate frame and grouping mechanism
/// for a graph subtree, and implements subtree layout.




@interface PSBaseSubtreeView : UIView @interface PSBaseSubtreeView : UIView
Expand Down
Loading

0 comments on commit 878a7ee

Please sign in to comment.