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.
This commit is contained in:
Pieter de Bie
2008-08-28 00:20:42 +02:00
parent 727e42fe1d
commit a294d911b0
8 changed files with 100 additions and 39 deletions
+4 -3
View File
@@ -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
+6
View File
@@ -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 = "<group>"; };
F5945E160E02B0C200706420 /* PBGitRepository.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitRepository.m; sourceTree = "<group>"; };
F5B721C30E05CF7E00AF29DC /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
F5C6F68B0E65FF9300478D97 /* PBGitLane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitLane.h; sourceTree = "<group>"; };
F5C6F68C0E65FF9300478D97 /* PBGitLane.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitLane.m; sourceTree = "<group>"; };
F5DFFA6A0E075D8800617813 /* PBEasyFS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBEasyFS.h; sourceTree = "<group>"; };
F5DFFA6B0E075D8800617813 /* PBEasyFS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBEasyFS.m; sourceTree = "<group>"; };
F5FF4E160E0829C20006317A /* PBGitRevList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRevList.h; sourceTree = "<group>"; };
@@ -308,6 +311,8 @@
F56CC7280E65E0AD004307B4 /* PBGitGraphLine.m */,
F56CC7300E65E0E5004307B4 /* PBGraphCellInfo.h */,
F56CC7310E65E0E5004307B4 /* PBGraphCellInfo.m */,
F5C6F68B0E65FF9300478D97 /* PBGitLane.h */,
F5C6F68C0E65FF9300478D97 /* PBGitLane.m */,
);
name = Graphing;
sourceTree = "<group>";
@@ -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;
};
+5 -4
View File
@@ -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
+7 -7
View File
@@ -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
+23 -18
View File
@@ -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;
+23
View File
@@ -0,0 +1,23 @@
//
// PBGitLane.h
// GitX
//
// Created by Pieter de Bie on 27-08-08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
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
+27
View File
@@ -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
+5 -7
View File
@@ -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];