Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support branch label rotation in 'horizontal mode'. #134

Merged

Conversation

cgddrd
Copy link
Contributor

@cgddrd cgddrd commented Dec 26, 2016

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

screen shot 2016-12-26 at 11 54 24

Before: labels (manually) forced to render at 0 degrees (positioning issues)

screen shot 2016-12-26 at 11 51 00

After: labels configured to render at 0 degrees (positioning and alignment handled correctly)

screen shot 2016-12-26 at 11 48 57

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:

var graphConfig = new GitGraph.Template({
    branch: {
        color: "#000000",
        mergeStyle: "straight",
        labelRotation: 0
    },
});

var config = {
  template: graphConfig,
  mode: "extended",
  orientation: "horizontal"
};

@cgddrd cgddrd closed this Dec 26, 2016
@cgddrd
Copy link
Contributor Author

cgddrd commented Dec 26, 2016

Closed due to CI failure. Will fix and resubmit.

@cgddrd cgddrd reopened this Dec 27, 2016
@cgddrd
Copy link
Contributor Author

cgddrd commented Dec 27, 2016

Re-opened having addressed failing tests and JSHint warnings.

@cgddrd cgddrd changed the title Orientation modes support label rotation Support branch label rotation in 'horizontal mode'. Dec 27, 2016
@nicoespeon
Copy link
Owner

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.
Still, this is awesome 😄

@cgddrd
Copy link
Contributor Author

cgddrd commented Jan 2, 2017

Hi @nicoespeon,

That sounds great! Thanks very much, looking forward to hearing back from you!

Copy link
Owner

@nicoespeon nicoespeon left a 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")) ?
Copy link
Owner

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")) ?
Copy link
Owner

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"));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spotted remaining console.log 😉

Copy link
Contributor Author

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")) ?
Copy link
Owner

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")) ?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here =)

Copy link
Contributor Author

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 ) {

Copy link
Owner

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?

Copy link
Contributor Author

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
Copy link
Owner

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 =)

Copy link
Contributor Author

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;

Copy link
Owner

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?

Copy link
Contributor Author

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.

@cgddrd
Copy link
Contributor Author

cgddrd commented Jan 5, 2017

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,
Copy link
Contributor Author

@cgddrd cgddrd Jan 5, 2017

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.

@cgddrd
Copy link
Contributor Author

cgddrd commented Jan 5, 2017

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.

@nicoespeon
Copy link
Owner

Thanks for the changes @cgddrd, all seems good to me.

I'll release all of these today 👍

@nicoespeon nicoespeon merged commit 5a3326d into nicoespeon:develop Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants