Skip to content

Commit d35bcb0

Browse files
committed
Merge branch 'release/v1.0.0'
2 parents 05c273a + 7c37f08 commit d35bcb0

20 files changed

+2071
-117
lines changed

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = function ( grunt ) {
2222
// The `clean` task ensures all files are removed from the misc. directories
2323
// so that no files linger from previous builds.
2424
clean: {
25+
options: {force: true},
2526
dist: [ "dist/" ],
2627
jsdoc: [ "dist/jsdoc/" ],
2728
release: [ "build/", "docs/" ]

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
gitgraph.js [![Build Status](https://secure.travis-ci.org/nicoespeon/gitgraph.js.png)](http://travis-ci.org/nicoespeon/gitgraph.js) [![devDependency Status](https://david-dm.org/nicoespeon/gitgraph.js/dev-status.png)](https://david-dm.org/nicoespeon/gitgraph.js#info=devDependencies)
1+
![gitgraph.js](/assets/logo/gitgraph-logo.png)
2+
3+
[![Build Status](https://secure.travis-ci.org/nicoespeon/gitgraph.js.png)](http://travis-ci.org/nicoespeon/gitgraph.js) [![devDependency Status](https://david-dm.org/nicoespeon/gitgraph.js/dev-status.png)](https://david-dm.org/nicoespeon/gitgraph.js#info=devDependencies)
24
===========
35

46
A JavaScript library to draw pretty git graphs in the browser.
57

68
## How to start
79

8-
The project is not stable so far but you still can download [the latest release](https://github.com/nicoespeon/gitgraph.js/releases/tag/v0.3.0).
10+
You have different options to start with the library:
11+
12+
- [Download the latest release](https://github.com/nicoespeon/gitgraph.js/releases/tag/v0.3.0).
13+
- Clone the repo: `git clone git://github.com/nicoespeon/gitgraph.js.git`.
14+
- Install with [Bower](http://bower.io/): `bower install gitgraph.js`.
15+
16+
Production files are available under the `build/` directory.
917

1018
## Report a bug / Ask for a feature
1119

assets/logo/gitgraph-logo.ai

Lines changed: 1281 additions & 0 deletions
Large diffs are not rendered by default.

assets/logo/gitgraph-logo.png

6.61 KB
Loading

bower.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "gitgraph.js",
3+
"version": "0.3.0",
4+
"main": [ "./build/gitgraph.js", "./build/gitgraph.css" ],
5+
"ignore": [
6+
"**/.*"
7+
]
8+
}

build/gitgraph.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
.gitgraph-tooltip:after {
1515
position: absolute;
1616
top: 10px;
17-
left: -20px;
17+
left: -18px;
1818
width: 0;
1919
height: 0;
2020
border-width: 10px;
@@ -23,3 +23,11 @@
2323
border-right-color: #EEE;
2424
content: "";
2525
}
26+
27+
.gitgraph-detail {
28+
position: absolute;
29+
padding: 10px;
30+
text-align: justify;
31+
width: 600px;
32+
display: none;
33+
}

build/gitgraph.js

Lines changed: 100 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ==========================================================
2-
* GitGraph v0.3.0
2+
* GitGraph v1.0.0
33
* https://github.com/nicoespeon/gitgraph.js
44
* ==========================================================
55
* Copyright (c) 2013 Nicolas CARLO (@nicoespeon) ٩(^‿^)۶
@@ -9,6 +9,7 @@
99
* ========================================================== */
1010

1111
(function () {
12+
"use strict";
1213
/**
1314
* GitGraph
1415
*
@@ -20,7 +21,6 @@
2021
* @param {String} [options.author = "Sergio Flores <[email protected]>"] - Default author for commits
2122
* @param {String} [options.mode = (null|"compact")] - Display mode
2223
* @param {DOM} [options.canvas] - DOM canvas (ex: document.getElementById("id"))
23-
* @param {Boolean} [options.testMode] - Active test mode for Jasmine
2424
* @param {String} [options.orientation = ("vertical-reverse"|"horizontal"|"horizontal-reverse")] - Graph orientation
2525
*
2626
* @this GitGraph
@@ -39,7 +39,7 @@
3939
options.template = this.newTemplate(options.template);
4040
}
4141
this.template = (options.template instanceof Template) ?
42-
options.template : this.newTemplate();
42+
options.template : this.newTemplate("metro");
4343
this.mode = options.mode || null;
4444
if (this.mode === "compact") {
4545
this.template.commit.message.display = false;
@@ -53,20 +53,26 @@
5353
switch (options.orientation) {
5454
case "vertical-reverse" :
5555
this.template.commit.spacingY *= -1;
56+
this.orientation = "verticale-reverse";
5657
break;
5758
case "horizontal" :
5859
this.template.commit.message.display = false;
5960
this.template.commit.spacingX = this.template.commit.spacingY;
6061
this.template.branch.spacingY = this.template.branch.spacingX;
6162
this.template.commit.spacingY = 0;
6263
this.template.branch.spacingX = 0;
64+
this.orientation = "horizontal";
6365
break;
6466
case "horizontal-reverse" :
6567
this.template.commit.message.display = false;
6668
this.template.commit.spacingX = - this.template.commit.spacingY;
6769
this.template.branch.spacingY = this.template.branch.spacingX;
6870
this.template.commit.spacingY = 0;
6971
this.template.branch.spacingX = 0;
72+
this.orientation = "horizontale-reverse";
73+
break;
74+
default:
75+
this.orientation = "vertical";
7076
break;
7177
}
7278

@@ -80,10 +86,8 @@
8086
this.tooltip.style.position = "fixed";
8187
this.tooltip.style.display = "none";
8288

83-
if (!options.testMode) {
84-
// Add tooltip div into body
85-
document.body.appendChild(this.tooltip);
86-
}
89+
// Add tooltip div into body
90+
document.body.appendChild(this.tooltip);
8791

8892
// Navigation vars
8993
this.HEAD = null;
@@ -103,13 +107,21 @@
103107
gitgraph: this
104108
}, false);
105109
}
110+
111+
// Render on window resize
112+
var self = this;
113+
window.onresize = function (event) {
114+
self.render();
115+
};
116+
106117
}
107118

108119
/**
109120
* Create new branch
110121
*
111122
* @param {(String | Object)} options - Branch name | Options of Branch
112123
* @see Branch
124+
* @return {Branch} New branch
113125
* @this GitGraph
114126
**/
115127
GitGraph.prototype.branch = function (options) {
@@ -132,6 +144,14 @@
132144
return branch;
133145
};
134146

147+
/**
148+
* Create new orphan branch
149+
*
150+
* @param {(String | Object)} options - Branch name | Options of Branch
151+
* @return {Branch} New branch
152+
* @see Branch
153+
* @this GitGraph
154+
**/
135155
GitGraph.prototype.orphanBranch = function (options) {
136156
// Options
137157
if (typeof options === "string") {
@@ -232,6 +252,12 @@
232252
var test = 0;
233253
var out = true; // Flag for hide tooltip
234254

255+
// Fix firefox MouseEvent
256+
event.offsetX = event.offsetX ? event.offsetX : event.layerX;
257+
event.offsetY = event.offsetY ? event.offsetY : event.layerY;
258+
event.x = event.x ? event.x : event.clientX;
259+
event.y = event.y ? event.y : event.clientY;
260+
235261
for (var i = 0, commit; !! (commit = this.gitgraph.commits[i]); i++) {
236262
test = Math.sqrt((commit.x + self.offsetX + self.marginX - event.offsetX) * (commit.x + self.offsetX + self.marginX - event.offsetX) + (commit.y + self.offsetY +self.marginY - event.offsetY) * (commit.y + self.offsetY + self.marginY - event.offsetY)); // Distance between commit and mouse (Pythagore)
237263
if (test < self.template.commit.dot.size) {
@@ -302,6 +328,34 @@
302328
this.checkout();
303329
}
304330

331+
/**
332+
* Create new branch
333+
*
334+
* @param {(String | Object)} options - Branch name | Options of Branch
335+
* @see Branch
336+
* @return {Branch} New Branch
337+
* @this Branch
338+
**/
339+
Branch.prototype.branch = function (options) {
340+
// Options
341+
if (typeof options === "string") {
342+
var name = options;
343+
options = {};
344+
options.name = name;
345+
}
346+
347+
options = (typeof options === "object") ? options : {};
348+
options.parent = this.parent;
349+
options.parentBranch = options.parentBranch || this;
350+
351+
// Add branch
352+
var branch = new Branch(options);
353+
this.parent.branchs.push(branch);
354+
355+
// Return
356+
return branch;
357+
};
358+
305359
/**
306360
* Render the branch
307361
*
@@ -335,6 +389,7 @@
335389
* Add a commit
336390
*
337391
* @param {(String | Object)} [options] - Message | Options of commit
392+
* @param {String} [options.detailId] - Id of detail DOM Element
338393
* @see Commit
339394
* @this Branch
340395
**/
@@ -369,6 +424,15 @@
369424
options.x = this.offsetX - this.parent.commitOffsetX;
370425
options.y = this.offsetY - this.parent.commitOffsetY;
371426

427+
// Detail
428+
if (typeof options.detailId === "string"
429+
&& this.parent.orientation === "vertical"
430+
&& this.parent.mode !== "compact") {
431+
options.detail = document.getElementById(options.detailId);
432+
} else {
433+
options.detail = null;
434+
}
435+
372436
// Check collision (Cause of special compact mode)
373437
if (options.branch.commits.slice(-1)[0] && options.x + options.y === options.branch.commits.slice(-1)[0].x + options.branch.commits.slice(-1)[0].y) {
374438
this.parent.commitOffsetX += this.template.commit.spacingX;
@@ -411,7 +475,13 @@
411475
// Increment commitOffset for next commit position
412476
this.parent.commitOffsetX += this.template.commit.spacingX;
413477
this.parent.commitOffsetY += this.template.commit.spacingY;
414-
478+
479+
// Add height of detail div (normal vertical mode only)
480+
if (commit.detail !== null) {
481+
commit.detail.style.display = "block";
482+
this.parent.commitOffsetY -= commit.detail.clientHeight - 40;
483+
}
484+
415485
// Auto-render
416486
this.parent.render();
417487

@@ -441,10 +511,11 @@
441511
* Merge branch
442512
*
443513
* @param {Branch} [target = this.parent.HEAD]
444-
* @param {string} [message]
514+
* @param {(String | Object)} [commitOptions] - Message | Options of commit
515+
* @return {Branch} this
445516
* @this Branch
446517
**/
447-
Branch.prototype.merge = function (target, message) {
518+
Branch.prototype.merge = function (target, commitOptions) {
448519
// Merge target
449520
var targetBranch = target || this.parent.HEAD;
450521

@@ -454,13 +525,14 @@
454525
}
455526

456527
// Merge commit
457-
message = (typeof message === "string") ?
458-
message : "Merge branch `" + this.name + "` into `" + targetBranch.name + "`";
459-
targetBranch.commit({
460-
message: message,
461-
type: "mergeCommit",
462-
parentCommit: this.commits.slice(-1)[0]
463-
});
528+
var message = commitOptions;
529+
commitOptions = commitOptions || {};
530+
commitOptions.message = commitOptions.message
531+
|| ((typeof message === "string") ? message : "Merge branch `" + this.name + "` into `" + targetBranch.name + "`");
532+
commitOptions.type = "mergeCommit";
533+
commitOptions.parentCommit = this.commits.slice(-1)[0];
534+
535+
targetBranch.commit(commitOptions);
464536

465537
// Add points to path
466538
var endOfBranch = {
@@ -525,6 +597,7 @@
525597
* @param {Boolean} options.arrowDisplay - Add a arrow under commit dot
526598
* @param {String} [options.author = this.parent.author] - Author name & email
527599
* @param {String} [options.date] - Date of commit, default is now
600+
* @param {String} [options.detail] - DOM Element of detail part
528601
* @param {String} [options.sha1] - Sha1, default is a random short sha1
529602
* @param {String} [options.dotColor = options.color] - Specific dot color
530603
* @param {Number} [options.dotSize = this.template.commit.dot.size] - Dot size
@@ -552,6 +625,7 @@
552625
this.branch = options.branch;
553626
this.author = options.author || this.parent.author;
554627
this.date = options.date || new Date().toUTCString();
628+
this.detail = options.detail || null;
555629
this.sha1 = options.sha1 || (Math.random(100)).toString(16).substring(3, 10);
556630
this.message = options.message || "He doesn't like George Michael! Boooo!";
557631
this.arrowDisplay = options.arrowDisplay;
@@ -594,12 +668,19 @@
594668
this.arrow();
595669
}
596670

671+
// Detail
672+
if (this.detail !== null) {
673+
this.detail.style.left = this.parent.canvas.offsetLeft + (this.parent.columnMax + 1) * this.template.branch.spacingX + 30 + "px";
674+
this.detail.style.top = this.parent.canvas.offsetTop + this.y + 40 + "px";
675+
this.detail.width = 30;
676+
}
677+
597678
// Message
598679
if (this.messageDisplay) {
599-
var message = this.sha1 + " " + this.message + " - " + this.author;
680+
var message = this.sha1 + " " + this.message + (this.author ? " - " + this.author : "");
600681
this.context.font = this.template.commit.message.font;
601682
this.context.fillStyle = this.messageColor;
602-
this.context.fillText(message, (this.parent.columnMax + 2) * this.template.branch.spacingX, this.y + 3);
683+
this.context.fillText(message, (this.parent.columnMax + 1) * this.template.branch.spacingX, this.y + 3);
603684
}
604685
};
605686

0 commit comments

Comments
 (0)