From a294d911b03dcc6383b3b0f0bbb02e7b369655e4 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Thu, 28 Aug 2008 00:20:42 +0200 Subject: [PATCH] Grapher: Add colors to lane This introduces a new object, PBGitLane that keeps track of the current lane. We used to only need a sha for a lane, but now that more information is needed, an extra object is in order. PBGitLane keeps a lane index number. This number is later used to pick a color. --- Documentation/GraphingAPI.txt | 7 +++--- GitX.xcodeproj/project.pbxproj | 6 +++++ PBGitGraphLine.h | 9 ++++---- PBGitGraphLine.m | 14 ++++++------ PBGitGrapher.m | 41 +++++++++++++++++++--------------- PBGitLane.h | 23 +++++++++++++++++++ PBGitLane.m | 27 ++++++++++++++++++++++ PBGitRevisionCell.m | 12 +++++----- 8 files changed, 100 insertions(+), 39 deletions(-) create mode 100644 PBGitLane.h create mode 100644 PBGitLane.m diff --git a/Documentation/GraphingAPI.txt b/Documentation/GraphingAPI.txt index b600491..2916900 100644 --- a/Documentation/GraphingAPI.txt +++ b/Documentation/GraphingAPI.txt @@ -7,10 +7,11 @@ The PBGraphCellInfo has only basic information -- The column the commit associated with this commit should be drawn in, and other lines that should be drawn. -These lines are in an array of PBLines. A PBLine has three pieces of +These lines are in an array of PBLines. A PBLine has a few pieces of information -- a start column, an end column and whether the line should be -drawn on the top or bottom part of the row. This should later be extended to -add color information for the lines. +drawn on the top or bottom part of the row. Furthermore, it has a colorIndex +to indicate the color the line should be given. Note that this number +increases forever, so you can modulo it with the number of colors you have. In the PBDetailController, the - (void)tableView:willDisplayCell:forTableColumn:row: is implemented which sets diff --git a/GitX.xcodeproj/project.pbxproj b/GitX.xcodeproj/project.pbxproj index 2812c4b..a91ba82 100644 --- a/GitX.xcodeproj/project.pbxproj +++ b/GitX.xcodeproj/project.pbxproj @@ -38,6 +38,7 @@ F58A8F280E043698007E3FC0 /* commits.css in Resources */ = {isa = PBXBuildFile; fileRef = F58A8F270E043698007E3FC0 /* commits.css */; }; F5945E170E02B0C200706420 /* PBGitRepository.m in Sources */ = {isa = PBXBuildFile; fileRef = F5945E160E02B0C200706420 /* PBGitRepository.m */; }; F5B721C40E05CF7E00AF29DC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F5B721C20E05CF7E00AF29DC /* MainMenu.xib */; }; + F5C6F68D0E65FF9300478D97 /* PBGitLane.m in Sources */ = {isa = PBXBuildFile; fileRef = F5C6F68C0E65FF9300478D97 /* PBGitLane.m */; }; F5DFFA6C0E075D8800617813 /* PBEasyFS.m in Sources */ = {isa = PBXBuildFile; fileRef = F5DFFA6B0E075D8800617813 /* PBEasyFS.m */; }; F5FF4E180E0829C20006317A /* PBGitRevList.m in Sources */ = {isa = PBXBuildFile; fileRef = F5FF4E170E0829C20006317A /* PBGitRevList.m */; }; F5FF4E7A0E082E440006317A /* PBGitGrapher.m in Sources */ = {isa = PBXBuildFile; fileRef = F5FF4E790E082E440006317A /* PBGitGrapher.m */; }; @@ -106,6 +107,8 @@ F5945E150E02B0C200706420 /* PBGitRepository.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRepository.h; sourceTree = ""; }; F5945E160E02B0C200706420 /* PBGitRepository.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitRepository.m; sourceTree = ""; }; F5B721C30E05CF7E00AF29DC /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = ""; }; + F5C6F68B0E65FF9300478D97 /* PBGitLane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitLane.h; sourceTree = ""; }; + F5C6F68C0E65FF9300478D97 /* PBGitLane.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitLane.m; sourceTree = ""; }; F5DFFA6A0E075D8800617813 /* PBEasyFS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBEasyFS.h; sourceTree = ""; }; F5DFFA6B0E075D8800617813 /* PBEasyFS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBEasyFS.m; sourceTree = ""; }; F5FF4E160E0829C20006317A /* PBGitRevList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRevList.h; sourceTree = ""; }; @@ -308,6 +311,8 @@ F56CC7280E65E0AD004307B4 /* PBGitGraphLine.m */, F56CC7300E65E0E5004307B4 /* PBGraphCellInfo.h */, F56CC7310E65E0E5004307B4 /* PBGraphCellInfo.m */, + F5C6F68B0E65FF9300478D97 /* PBGitLane.h */, + F5C6F68C0E65FF9300478D97 /* PBGitLane.m */, ); name = Graphing; sourceTree = ""; @@ -413,6 +418,7 @@ 913D5E5F0E556A9300CECEA2 /* PBCLIProxy.mm in Sources */, F56CC7290E65E0AD004307B4 /* PBGitGraphLine.m in Sources */, F56CC7320E65E0E5004307B4 /* PBGraphCellInfo.m in Sources */, + F5C6F68D0E65FF9300478D97 /* PBGitLane.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/PBGitGraphLine.h b/PBGitGraphLine.h index a1dcd4f..1f7ad60 100644 --- a/PBGitGraphLine.h +++ b/PBGitGraphLine.h @@ -14,10 +14,11 @@ int upper; int from; int to; + int colorIndex; } -@property(readonly) int upper, from, to; -- (id)initWithUpper: (int) u From: (int) f to: (int) t; -+ (PBGitGraphLine*) lowerLineFrom:(int) f to: (int) t; -+ (PBGitGraphLine*) upperLineFrom:(int) f to: (int) t; +@property(readonly) int upper, from, to, colorIndex; +- (id)initWithUpper: (int) u From: (int) f to: (int) t color: (int) c; ++ (PBGitGraphLine*) lowerLineFrom:(int) f to: (int) t color: (int) c; ++ (PBGitGraphLine*) upperLineFrom:(int) f to: (int) t color: (int) c; @end \ No newline at end of file diff --git a/PBGitGraphLine.m b/PBGitGraphLine.m index cf09e77..85a9f8d 100644 --- a/PBGitGraphLine.m +++ b/PBGitGraphLine.m @@ -10,23 +10,23 @@ @implementation PBGitGraphLine -@synthesize upper, from, to; -- (id)initWithUpper: (int) u From: (int) f to: (int) t; +@synthesize upper, from, to, colorIndex; +- (id)initWithUpper: (int) u From: (int) f to: (int) t color: (int) c; { upper = u; from = f; to = t; - + colorIndex = c; return self; } -+ (PBGitGraphLine*) lowerLineFrom:(int) f to: (int) t ++ (PBGitGraphLine*) lowerLineFrom:(int) f to: (int) t color: (int) c { - return [[PBGitGraphLine alloc] initWithUpper:0 From:f to:t]; + return [[PBGitGraphLine alloc] initWithUpper:0 From:f to:t color:c]; } -+ (PBGitGraphLine*) upperLineFrom:(int) f to: (int) t ++ (PBGitGraphLine*) upperLineFrom:(int) f to: (int) t color: (int) c { - return [[PBGitGraphLine alloc] initWithUpper:1 From:f to:t]; + return [[PBGitGraphLine alloc] initWithUpper:1 From:f to:t color: c]; } @end diff --git a/PBGitGrapher.m b/PBGitGrapher.m index 7bae235..c69aa53 100644 --- a/PBGitGrapher.m +++ b/PBGitGrapher.m @@ -8,6 +8,7 @@ #import "PBGitGrapher.h" #import "PBGitCommit.h" +#import "PBGitLane.h" @implementation PBGitGrapher @@ -21,7 +22,7 @@ NSMutableArray* previousLanes = [NSMutableArray array]; for (PBGitCommit* commit in commits) { - int i = 0, newPos = -1; + int i = 0, newPos = -1, newColor = PBGITLANE_CURRENT_INDEX; NSMutableArray* currentLanes = [NSMutableArray array]; NSMutableArray* lines = [NSMutableArray array]; BOOL didFirst = NO; @@ -30,31 +31,33 @@ if (previous != nil) { // We can't count until numColumns here, as it's only used for the width of the cell. - for (NSString* lane in previousLanes) { + for (PBGitLane* lane in previousLanes) { i++; // This is our commit! We should do a "merge": move the line from // our upperMapping to their lowerMapping - if ([lane isEqualToString:commit.sha]) { + if ([lane isCommit:commit.sha]) { if (!didFirst) { didFirst = YES; - [currentLanes addObject: [commit.parents objectAtIndex:0]]; + lane.sha = [commit.parents objectAtIndex:0]; + [currentLanes addObject: lane]; newPos = [currentLanes count]; + newColor = [lane index]; } - [lines addObject: [PBGitGraphLine upperLineFrom: i to: newPos]]; + [lines addObject: [PBGitGraphLine upperLineFrom: i to: newPos color: [lane index]]]; } else { // We are not this commit. // Try to find an earlier column for this commit. int j = 0; BOOL found = NO; - for (NSString* column in currentLanes) { + for (PBGitLane* column in currentLanes) { j++; // ??? what is this? if (j == newPos) continue; - if ([column isEqualToString: lane]) { + if ([lane isCommit: commit.sha]) { // We already have a column for this commit. use it instead - [lines addObject: [PBGitGraphLine upperLineFrom: i to: j]]; + [lines addObject: [PBGitGraphLine upperLineFrom: i to: j color: [lane index]]]; found = YES; break; } @@ -68,13 +71,13 @@ // continue; [currentLanes addObject: lane]; - [lines addObject: [PBGitGraphLine upperLineFrom: [currentLanes count] to: [currentLanes count]]]; - [lines addObject: [PBGitGraphLine lowerLineFrom: [currentLanes count] to: [currentLanes count]]]; + [lines addObject: [PBGitGraphLine upperLineFrom: [currentLanes count] to: [currentLanes count] color: [lane index]]]; + [lines addObject: [PBGitGraphLine lowerLineFrom: [currentLanes count] to: [currentLanes count] color: [lane index]]]; } } // For existing columns, we always just continue straight down // ^^ I don't know what that means anymore :( - [lines addObject:[PBGitGraphLine lowerLineFrom:newPos to:newPos]]; + [lines addObject:[PBGitGraphLine lowerLineFrom:newPos to:newPos color: newColor]]; } } @@ -82,9 +85,10 @@ // If we already did the first parent, don't do so again if (!didFirst) { - [currentLanes addObject: [commit.parents objectAtIndex:0]]; + PBGitLane* newLane = [[PBGitLane alloc] initWithCommit:[commit.parents objectAtIndex:0]]; + [currentLanes addObject: newLane]; newPos = [currentLanes count]; - [lines addObject:[PBGitGraphLine lowerLineFrom: newPos to: newPos]]; + [lines addObject:[PBGitGraphLine lowerLineFrom: newPos to: newPos color: [newLane index]]]; } // Add all other parents @@ -96,10 +100,10 @@ for (NSString* parent in [commit.parents subarrayWithRange:NSMakeRange(1, [commit.parents count] -1)]) { int i = 0; BOOL was_displayed = NO; - for (NSString* column in currentLanes) { + for (PBGitLane* column in currentLanes) { i++; - if ([column isEqualToString: parent]) { - [lines addObject:[PBGitGraphLine lowerLineFrom: i to: newPos]]; + if ([column isCommit: parent]) { + [lines addObject:[PBGitGraphLine lowerLineFrom: i to: newPos color: [column index]]]; was_displayed = YES; break; } @@ -109,8 +113,9 @@ // Really add this parent addedParent = YES; - [currentLanes addObject:parent]; - [lines addObject:[PBGitGraphLine lowerLineFrom: [currentLanes count] to: newPos]]; + PBGitLane* newLane = [[PBGitLane alloc] initWithCommit:parent]; + [currentLanes addObject: newLane]; + [lines addObject:[PBGitGraphLine lowerLineFrom: [currentLanes count] to: newPos color: [newLane index]]]; } ++row; diff --git a/PBGitLane.h b/PBGitLane.h new file mode 100644 index 0000000..4365f03 --- /dev/null +++ b/PBGitLane.h @@ -0,0 +1,23 @@ +// +// PBGitLane.h +// GitX +// +// Created by Pieter de Bie on 27-08-08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import + +static int PBGITLANE_CURRENT_INDEX = 0; + +@interface PBGitLane : NSObject { + NSString* sha; + int index; +} +- (id) initWithCommit: (NSString*) c; +- (BOOL) isCommit: (NSString*) c; + +@property(assign) NSString* sha; +@property(readonly) int index; + +@end diff --git a/PBGitLane.m b/PBGitLane.m new file mode 100644 index 0000000..14a0a66 --- /dev/null +++ b/PBGitLane.m @@ -0,0 +1,27 @@ +// +// PBGitLane.m +// GitX +// +// Created by Pieter de Bie on 27-08-08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import "PBGitLane.h" + + +@implementation PBGitLane + +@synthesize sha, index; +- (id) initWithCommit: (NSString*) c +{ + index = PBGITLANE_CURRENT_INDEX++; + sha = c; + + return self; +} + +- (BOOL) isCommit: (NSString*) s +{ + return [sha isEqualToString:s]; +} +@end diff --git a/PBGitRevisionCell.m b/PBGitRevisionCell.m index d47bfb7..a038885 100644 --- a/PBGitRevisionCell.m +++ b/PBGitRevisionCell.m @@ -33,7 +33,7 @@ [NSColor orangeColor], [NSColor blackColor], [NSColor greenColor], nil]; } -- (void) drawLineFromColumn: (int) from toColumn: (int) to inRect: (NSRect) r offset: (int) offset +- (void) drawLineFromColumn: (int) from toColumn: (int) to inRect: (NSRect) r offset: (int) offset color: (int) c { int columnWidth = 10; @@ -43,7 +43,7 @@ NSPoint center = NSMakePoint( origin.x + columnWidth * to, origin.y + r.size.height * 0.5); // Just use red for now. - [[[self colors] objectAtIndex:0] set]; + [[[self colors] objectAtIndex: c % 5] set]; NSBezierPath * path = [NSBezierPath bezierPath]; [path setLineWidth:2]; @@ -56,9 +56,7 @@ - (void) drawCircleForColumn: (int) c inRect: (NSRect) r { - NSArray* col = [NSArray arrayWithObjects:[NSColor redColor], [NSColor blueColor], - [NSColor orangeColor], [NSColor blackColor], [NSColor greenColor], nil]; - + [[NSColor blackColor] set]; int columnWidth = 10; NSPoint origin = r.origin; NSPoint columnOrigin = { origin.x + columnWidth * c, origin.y}; @@ -89,9 +87,9 @@ for (PBGitGraphLine* line in cellInfo.lines) { if (line.upper == 0) - [self drawLineFromColumn: line.from toColumn: line.to inRect:ownRect offset: ownRect.size.height]; + [self drawLineFromColumn: line.from toColumn: line.to inRect:ownRect offset: ownRect.size.height color: line.colorIndex]; else - [self drawLineFromColumn:line.from toColumn: line.to inRect:ownRect offset: 0]; + [self drawLineFromColumn: line.from toColumn: line.to inRect:ownRect offset: 0 color:line.colorIndex]; } [self drawCircleForColumn: cellInfo.position inRect: ownRect];