Skip to content
This repository was archived by the owner on Jul 13, 2024. It is now read-only.

Commit 63916ee

Browse files
committed
Add lineDash option to branch and commits
Document existing branch lineDash options for templates. Close #139
1 parent 4d9403c commit 63916ee

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

examples/index.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ var myTemplateConfig = {
66
colors: ["#F00", "#0F0", "#00F"], // branches colors, 1 per column
77
branch: {
88
lineWidth: 8,
9+
// Dash segments, see:
10+
// https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
11+
lineDash: [5, 3],
912
spacingX: 50
1013
},
1114
commit: {
1215
spacingY: -80,
1316
dot: {
14-
size: 12
17+
size: 12,
18+
lineDash: [4]
1519
},
1620
message: {
1721
displayAuthor: true,
@@ -56,6 +60,7 @@ gitGraph.commit("My second commit").commit("Add awesome feature");
5660
var dev = master.branch({
5761
name: "dev",
5862
color: "#F00",
63+
// lineDash: [5],
5964
commitDefaultOptions: {
6065
color: "#F00"
6166
}
@@ -204,3 +209,16 @@ test.commit({
204209
console.log("You just clicked my commit.", commit, event);
205210
}
206211
});
212+
213+
// Display WIP-like commit
214+
test
215+
.commit({
216+
lineDash: [3, 2],
217+
dotStrokeWidth: 5,
218+
dotColor: "white",
219+
messageHashDisplay: false,
220+
messageAuthorDisplay: false,
221+
message: "Current WIP",
222+
tag: "HEAD",
223+
displayTagBox: false
224+
});

src/gitgraph.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@
462462
* @param {Branch} [options.parentBranch = options.parentCommit.branch] - Parent branch
463463
* @param {Commit} [options.parentCommit = _getLast(options.parentBranch.commits)] - Parent commit
464464
* @param {string} [options.name = "no-name"] - Branch name
465+
* @param {number[]} [options.lineDash = this.template.branch.lineDash] - Branch line dash segments
465466
* @param {object} [options.commitDefaultOptions = {}] - Default options for commits
466467
*
467468
* @this Branch
@@ -605,19 +606,12 @@
605606
this.context.lineWidth = this.lineWidth;
606607
this.context.strokeStyle = this.color;
607608

608-
var prevLineDash;
609-
if (this.context.setLineDash !== undefined) {
610-
prevLineDash = this.context.getLineDash();
609+
if (typeof this.context.setLineDash === "function") {
611610
this.context.setLineDash(this.lineDash);
612611
}
613612

614613
this.context.stroke();
615614
this.context.closePath();
616-
617-
//Restore previous line dash setting, if any
618-
if (prevLineDash !== undefined) {
619-
this.context.setLineDash(prevLineDash);
620-
}
621615
};
622616

623617
/**
@@ -1049,6 +1043,7 @@
10491043
* @param {number} [options.dotSize = this.template.commit.dot.size] - Dot size
10501044
* @param {number} [options.dotStrokeWidth = this.template.commit.dot.strokeWidth] - Dot stroke width
10511045
* @param {string} [options.dotStrokeColor = this.template.commit.dot.strokeColor]
1046+
* @param {number[]} [options.lineDash = this.template.commit.dot.lineDash]
10521047
*
10531048
* @param {string} [options.message = "He doesn't like George Michael! Boooo!"] - Commit message
10541049
* @param {string} [options.messageColor = options.color] - Specific message color
@@ -1095,6 +1090,7 @@
10951090
this.dotSize = options.dotSize || this.template.commit.dot.size;
10961091
this.dotStrokeWidth = options.dotStrokeWidth || this.template.commit.dot.strokeWidth;
10971092
this.dotStrokeColor = options.dotStrokeColor || this.template.commit.dot.strokeColor || options.color;
1093+
this.lineDash = options.lineDash || this.template.commit.dot.lineDash;
10981094
this.type = options.type || null;
10991095
this.tooltipDisplay = _booleanOptionOr(options.tooltipDisplay, true);
11001096
this.onClick = options.onClick || null;
@@ -1121,7 +1117,6 @@
11211117

11221118
// Label
11231119
if (this.showLabel) {
1124-
11251120
/*
11261121
* For cases where we want a 0 or 180 degree label rotation in horizontal mode,
11271122
* we need to modify the position of the label to sit centrally above the commit dot.
@@ -1161,7 +1156,11 @@
11611156
this.context.strokeStyle = this.dotStrokeColor;
11621157
this.context.lineWidth = this.dotStrokeWidth;
11631158

1164-
if (typeof (this.dotStrokeWidth) === "number") {
1159+
if (typeof this.context.setLineDash === "function") {
1160+
this.context.setLineDash(this.lineDash);
1161+
}
1162+
1163+
if (typeof this.dotStrokeWidth === "number") {
11651164
this.context.stroke();
11661165
}
11671166

@@ -1362,6 +1361,7 @@
13621361
* @param {number} [options.arrow.offset] - Arrow offset
13631362
* @param {string} [options.branch.color] - Branch color
13641363
* @param {number} [options.branch.lineWidth] - Branch line width
1364+
* @param {number[]} [options.branch.lineDash] - Branch line dash segments
13651365
* @param {string} [options.branch.mergeStyle = ("bezier"|"straight")] - Branch merge style
13661366
* @param {number} [options.branch.spacingX] - Space between branches
13671367
* @param {number} [options.branch.spacingY] - Space between branches
@@ -1373,6 +1373,7 @@
13731373
* @param {number} [options.commit.dot.size] - Commit dot size
13741374
* @param {number} [options.commit.dot.strokeWidth] - Commit dot stroke width
13751375
* @param {string} [options.commit.dot.strokeColor] - Commit dot stroke color
1376+
* @param {number[]} [options.commit.dot.lineDash] - Commit dot line dash segments
13761377
* @param {string} [options.commit.message.color] - Commit message color
13771378
* @param {boolean} [options.commit.message.display] - Commit display policy
13781379
* @param {boolean} [options.commit.message.displayAuthor] - Commit message author policy
@@ -1446,6 +1447,7 @@
14461447
this.commit.dot.size = options.commit.dot.size || 3;
14471448
this.commit.dot.strokeWidth = options.commit.dot.strokeWidth || null;
14481449
this.commit.dot.strokeColor = options.commit.dot.strokeColor || null;
1450+
this.commit.dot.lineDash = options.commit.dot.lineDash || this.branch.lineDash;
14491451

14501452
this.commit.tag = {};
14511453
this.commit.tag.color = options.commit.tag.color || this.commit.dot.color;

0 commit comments

Comments
 (0)