-
Notifications
You must be signed in to change notification settings - Fork 369
Support branch label rotation in 'horizontal mode'. #134
Support branch label rotation in 'horizontal mode'. #134
Conversation
… mode, plus fies for tag labels between vertical and horizontal modes.
…ting to acquire its value.
…thub.com/cgddrd/gitgraph.js into orientation-modes-support-label-rotation
Closed due to CI failure. Will fix and resubmit. |
…ackarrow' template definitions.
…n return values for condition checking).
…rrectly, and addressed JSHint warnings within '.every()' polyfill.
Re-opened having addressed failing tests and JSHint warnings. |
Hi @cgddrd! Thanks a lot for this. This is awesome 👌 I'll take some time to review and test it in the following days, I'll let you know. |
Hi @nicoespeon, That sounds great! Thanks very much, looking forward to hearing back from you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot again for your submission. That's a really cool contribution!
I've a few requested changes, only minor stuff − some console.log and personal preferences.
Let me know when you're done so I can merge your contribution, add some docs and release it 👍
@@ -45,7 +45,8 @@ | |||
case "vertical-reverse" : | |||
this.template.commit.spacingY *= -1; | |||
this.orientation = "vertical-reverse"; | |||
this.template.branch.labelRotation = 0; | |||
this.template.branch.labelRotation = !(_isNullOrUndefined(options, "template.branch.labelRotation")) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to avoid negated conditions for readability. Could you reverse this ternary?
@@ -55,7 +56,8 @@ | |||
this.template.commit.spacingY = 0; | |||
this.template.branch.spacingX = 0; | |||
this.orientation = "horizontal"; | |||
this.template.branch.labelRotation = -90; | |||
this.template.branch.labelRotation = !(_isNullOrUndefined(options, "template.branch.labelRotation")) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, I prefer to have a "positive" condition than keeping "default value at the end".
this.template.commit.tag.spacingX = -this.template.commit.spacingY; | ||
this.template.commit.tag.spacingY = this.template.branch.spacingY; | ||
break; | ||
default: | ||
this.orientation = "vertical"; | ||
this.template.branch.labelRotation = 0; | ||
console.log(options); | ||
console.log(_isNullOrUndefined(options, "template.branch.labelRotation")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spotted remaining console.log
😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, thought I'd cleared these out! Poor checking on my part! Removed.
@@ -66,13 +68,17 @@ | |||
this.template.commit.spacingY = 0; | |||
this.template.branch.spacingX = 0; | |||
this.orientation = "horizontal-reverse"; | |||
this.template.branch.labelRotation = 90; | |||
this.template.branch.labelRotation = !(_isNullOrUndefined(options, "template.branch.labelRotation")) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here =)
this.template.branch.labelRotation = 0; | ||
console.log(options); | ||
console.log(_isNullOrUndefined(options, "template.branch.labelRotation")); | ||
this.template.branch.labelRotation = !(_isNullOrUndefined(options, "template.branch.labelRotation")) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also removed.
@@ -1388,6 +1439,7 @@ | |||
* @private | |||
*/ | |||
function _drawTextBG ( context, x, y, text, color, font, angle, useStroke ) { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this blank line a typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it's a habit of mine to add more whitespace when working on a function. Scheduled for removal.
throw new TypeError("this is null or not defined"); | ||
} | ||
|
||
// 1. Let O be the result of calling ToObject passing the this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed polyfill and the link to the source, that's helpful (and documented).
Still, you can get rid of all the detailed implementation comments as they mostly describe what the code is doing rather than why, which is not really useful.
Thanks a lot =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments removed.
// Expose GitGraph object | ||
window.GitGraph = GitGraph; | ||
window.GitGraph.Branch = Branch; | ||
window.GitGraph.Commit = Commit; | ||
window.GitGraph.Template = Template; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: was this blank line intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was also force of habit on my part. Will be removed.
…support-label-rotation.
Hi @nicoespeon, Apologies for the delay, I've now finished making the requested changes. Let me know your thoughts. Cheers! |
@@ -1088,7 +1085,7 @@ | |||
var textHeight = _getFontHeight( this.tagFont ); | |||
_drawTextBG( this.context, | |||
this.x - this.dotSize / 2, | |||
((this.parent.columnMax + 1) * this.template.commit.tag.spacingY) - this.template.commit.tag.spacingY / 2 + (this.parent.tagNum % 2) * textHeight * 1.5, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was not meant to be committed. I have since reversed this change and recommitted.
I realised I had accidentally introduced an unintended change (related to the discussion for #132) as part of 23a13a5#r94837041. I have since reversed this change: 830b1f0. Please accept my apologies. |
Thanks for the changes @cgddrd, all seems good to me. I'll release all of these today 👍 |
This PR enables graphs rendered in 'horizontal mode' to support branch label rotations besides the default of -90 (270) degrees.
Whilst the motivation and focus of this work is to allow for branch labels to be set to zero degrees of rotation whilst rendered under 'horizontal mode', no limitations on the rotation angle are enforced. It should be noted however, that any label rendered with a rotation angle NOT set to an increment of 90 degrees (i.e 0, 90, 180 or 270) is not guaranteed to render in a sensible manner.
See below for an illustration of these changes using the example file 'gitflowsupport.js':
Before: labels auto-default to a rotation of -90 degrees in horizontal mode
Before: labels (manually) forced to render at 0 degrees (positioning issues)
After: labels configured to render at 0 degrees (positioning and alignment handled correctly)
Please note: These changes do not affect the current behaviour for rendering branch labels under 'vertical' or 'vertical-reverse' modes.
Configuration of the rotation angle for branch labels continues to be set using the existing
template.branch.labelRotation
property, as highlighted in the example below: