From 77414673d8f74000e0fc907d57fdad145e21a6fe Mon Sep 17 00:00:00 2001 From: Carlo Rivera Date: Thu, 5 Jul 2018 15:16:09 -0400 Subject: [PATCH 1/3] Add support for "messageShort" to put some text in the commit bubble. --- examples/index.js | 4 +++- src/gitgraph.js | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/index.js b/examples/index.js index 3d890796..0e4ae318 100644 --- a/examples/index.js +++ b/examples/index.js @@ -77,6 +77,7 @@ var commitConfig = { dotStrokeWidth: 10, messageHashDisplay: false, messageAuthorDisplay: true, + messageShort: "C1", message: "Alors c'est qui le papa ?", tooltipDisplay: false, author: "Me " @@ -128,7 +129,8 @@ test.merge(master, "My special merge commit message"); // Then, continue committing on the "test" branch test.commit({ - message: "It works !" + message: "It works !", + messageShort: "C2" }); var fastForwardBranch = test.branch("fast-forward"); diff --git a/src/gitgraph.js b/src/gitgraph.js index 384c88b9..b123f12d 100644 --- a/src/gitgraph.js +++ b/src/gitgraph.js @@ -1053,6 +1053,7 @@ * @param {number[]} [options.lineDash = this.template.commit.dot.lineDash] * * @param {string} [options.message = "He doesn't like George Michael! Boooo!"] - Commit message + * @param {string} [options.message] - short commit message (A few chars) to appear on the commit dot * @param {string} [options.messageColor = options.color] - Specific message color * @param {string} [options.messageFont = this.template.commit.message.font] - Font of the message * @param {boolean} [options.messageDisplay = this.template.commit.message.display] - Commit message display policy @@ -1085,7 +1086,8 @@ this.date = options.date || new Date().toUTCString(); this.detail = options.detail || null; this.sha1 = options.sha1 || (Math.random(100)).toString(16).substring(3, 10); - this.message = options.message || "He doesn't like George Michael! Boooo!"; + this.message = options.message || options.messageShort || "He doesn't like George Michael! Boooo!"; + this.messageShort = options.messageShort; this.arrowDisplay = options.arrowDisplay; this.messageDisplay = _booleanOptionOr(options.messageDisplay, this.template.commit.message.display); this.messageAuthorDisplay = _booleanOptionOr(options.messageAuthorDisplay, this.template.commit.message.displayAuthor); @@ -1205,6 +1207,16 @@ } } + if (this.messageShort !== undefined) { + //this.context.textAlign="start"; + this.context.fillStyle = "#000"; + var oldTextBaseline = this.context.textBaseline; + this.context.textAlign="center"; + this.context.textBaseline = 'middle'; + this.context.fillText(this.messageShort, this.x, this.y); + this.context.textBaseline = oldTextBaseline; + } + // Message if (this.messageDisplay) { var message = this.message; From b698e18c41f0193ce60f0eb817bf413027086549 Mon Sep 17 00:00:00 2001 From: Carlo Rivera Date: Thu, 5 Jul 2018 15:35:02 -0400 Subject: [PATCH 2/3] Minor tweaks to the messageShort code block. --- src/gitgraph.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gitgraph.js b/src/gitgraph.js index b123f12d..f72d01b1 100644 --- a/src/gitgraph.js +++ b/src/gitgraph.js @@ -1208,13 +1208,16 @@ } if (this.messageShort !== undefined) { - //this.context.textAlign="start"; + var previousTextBaseline = this.context.textBaseline; + var previousTextAlign = this.context.textAlign; + this.context.fillStyle = "#000"; - var oldTextBaseline = this.context.textBaseline; - this.context.textAlign="center"; + this.context.textAlign = "center"; this.context.textBaseline = 'middle'; this.context.fillText(this.messageShort, this.x, this.y); - this.context.textBaseline = oldTextBaseline; + + this.context.textBaseline = previousTextBaseline; + this.context.textAlign = previousTextAlign; } // Message From 07d7f7f8d69321b029bc5b5ac81cca91107ff995 Mon Sep 17 00:00:00 2001 From: Carlo Rivera Date: Sun, 8 Jul 2018 19:55:53 -0400 Subject: [PATCH 3/3] Change messageShort to commitDotText --- examples/index.js | 4 ++-- src/gitgraph.js | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/index.js b/examples/index.js index 0e4ae318..f662a14e 100644 --- a/examples/index.js +++ b/examples/index.js @@ -77,7 +77,7 @@ var commitConfig = { dotStrokeWidth: 10, messageHashDisplay: false, messageAuthorDisplay: true, - messageShort: "C1", + commitDotText: "C1", message: "Alors c'est qui le papa ?", tooltipDisplay: false, author: "Me " @@ -130,7 +130,7 @@ test.merge(master, "My special merge commit message"); // Then, continue committing on the "test" branch test.commit({ message: "It works !", - messageShort: "C2" + commitDotText: "C2" }); var fastForwardBranch = test.branch("fast-forward"); diff --git a/src/gitgraph.js b/src/gitgraph.js index f72d01b1..78f4234d 100644 --- a/src/gitgraph.js +++ b/src/gitgraph.js @@ -1053,7 +1053,7 @@ * @param {number[]} [options.lineDash = this.template.commit.dot.lineDash] * * @param {string} [options.message = "He doesn't like George Michael! Boooo!"] - Commit message - * @param {string} [options.message] - short commit message (A few chars) to appear on the commit dot + * @param {string} [options.commitDotText] - short commit message (A few chars) to appear on the commit dot * @param {string} [options.messageColor = options.color] - Specific message color * @param {string} [options.messageFont = this.template.commit.message.font] - Font of the message * @param {boolean} [options.messageDisplay = this.template.commit.message.display] - Commit message display policy @@ -1086,8 +1086,8 @@ this.date = options.date || new Date().toUTCString(); this.detail = options.detail || null; this.sha1 = options.sha1 || (Math.random(100)).toString(16).substring(3, 10); - this.message = options.message || options.messageShort || "He doesn't like George Michael! Boooo!"; - this.messageShort = options.messageShort; + this.message = options.message || "He doesn't like George Michael! Boooo!"; + this.commitDotText = options.commitDotText; this.arrowDisplay = options.arrowDisplay; this.messageDisplay = _booleanOptionOr(options.messageDisplay, this.template.commit.message.display); this.messageAuthorDisplay = _booleanOptionOr(options.messageAuthorDisplay, this.template.commit.message.displayAuthor); @@ -1207,14 +1207,15 @@ } } - if (this.messageShort !== undefined) { + // Commit Dot Text + if (this.commitDotText) { var previousTextBaseline = this.context.textBaseline; var previousTextAlign = this.context.textAlign; this.context.fillStyle = "#000"; this.context.textAlign = "center"; this.context.textBaseline = 'middle'; - this.context.fillText(this.messageShort, this.x, this.y); + this.context.fillText(this.commitDotText, this.x, this.y); this.context.textBaseline = previousTextBaseline; this.context.textAlign = previousTextAlign;