         }
     }
     
+    func drawLegend(c:Canvas, x:Int) {
+        
+        // draw title
+        c.drawText("Number of Lines Changed", origin: P(x + 10, c.height() - 25), fontName: "Monaco", fontSize: 10)
+        
+        let numberOfLines = ["0", "0+", "1000+", "2500+", "4000+", "5000+"]
+        
+        for i in 0...5 {
+            let origin = P(x + 10 + i/3 * 80, c.height() - 15 - COL_WIDTH - (i%3+1) * self.ROW_HEIGHT)
+            let r = Rect(origin, width: COL_WIDTH, height: self.ROW_HEIGHT)
+            let intensity = CGFloat(i) * 0.2
+            let color = NSColor.grayColor().colorWithAlphaComponent(intensity)
+            
+            c.drawRectangle(r, strokeColor: NSColor.lightGrayColor(), fillColor: color)
+            
+            let textPoint = P(origin.x + COL_WIDTH + 10, origin.y + 4)
+            let s = numberOfLines[i]
+            c.drawText(s, origin: textPoint, fontName:"Monaco", fontSize: 10)
+        }
+        
+    }
+    
     func drawTimeline(fromDay fromDay:String, toDay:String, repoTuples:[(repo:String, jsonPath:String)], outPath:String) throws {
         
         guard let c = Canvas(880,560, backgroundColor: NSColor.whiteColor()) else {

        return daysInfo
    }
    
    func rectForDay(offset:Int, rowIndex:Int, canvasHeight:Int) -> Rect? {
        
        let COL_WIDTH = Constants.COL_WIDTH
        let ROW_HEIGHT = Constants.ROW_HEIGHT
        let LEFT_MARGIN_WIDTH = Constants.LEFT_MARGIN_WIDTH
        let TOP_MARGIN_HEIGTH = Constants.TOP_MARGIN_HEIGTH
        
        let p = P(
            LEFT_MARGIN_WIDTH + offset,

                return
            }
            
            let authorsInRepoSet = Set(json.values.flatMap({ $0.keys }))
            let authorsInRepo = Array(authorsInRepoSet).sort()
            
            // draw repo name
            c.drawText(repo, origin: P(LEFT_MARGIN_WIDTH, c.height() - self.TOP_MARGIN_HEIGTH - (currentRow) * ROW_HEIGHT - 18), fontName: "Monaco", fontSize: 10)
            
            currentRow += 1
            
            // draw authors
            for (authorIndex, author) in authorsInRepo.enumerate() {
                // draw author name
                c.drawText(
                    author,
                    origin: P(legendAndAuthorsXPosition, c.height() - self.TOP_MARGIN_HEIGTH - (currentRow+authorIndex) * ROW_HEIGHT - 15),
                    fontName: "Monaco",
                    fontSize: 10)
            }
            
            // draw background cells
            let weekDayOffsetTuples = sortedDayInfo.map( { $0.1 } ).filter( { weekDaysToSkip.contains($0.0) == false } )
            
            for (_, offset) in weekDayOffsetTuples {
                for (i, _) in authorsInRepo.enumerate() {
                    let rect = rectForDay (offset, rowIndex: currentRow+i, canvasHeight: c.height())
                    c.drawRectangle(rect, strokeColor: NSColor.lightGrayColor(), fillColor: NSColor.clearColor())
                }
            }
            
            // draw activity rectangles
            for (day, authorsDict) in json {
                for (author, addedRemovedDict) in authorsDict {

                    var linesChanged = 0
                    
                    linesChanged +=? addedRemovedDict["added"]
                    linesChanged +=? addedRemovedDict["removed"]
                    
                    if let (weekDay, offset) = daysInfo[day], indexOfAuthor = authorsInRepo.indexOf(author) {
                        
                        if weekDaysToSkip.contains(weekDay) { continue }
                        
                        let rect = rectForDay(offset, rowIndex: currentRow+indexOfAuthor, canvasHeight: c.height())
                        let fillColor = fillColorForLineCountPerDay(linesChanged, baseColor:colorForAuthor(author))
                        c.drawRectangle(rect, strokeColor: NSColor.lightGrayColor(), fillColor: fillColor)
                    }
                }
            }
            
            currentRow += authorsInRepo.count
        }
        
        c.saveAtPath(outPath)
