@gitgraph/core
Advanced tools
Comparing version 1.0.0-1 to 1.1.0-0
@@ -7,3 +7,3 @@ import { CommitStyle } from "./template"; | ||
renderDot?: (commit: Commit<TNode>) => TNode; | ||
renderMessage?: (commit: Commit<TNode>, commitMessagesX: number) => TNode; | ||
renderMessage?: (commit: Commit<TNode>) => TNode; | ||
renderTooltip?: (commit: Commit<TNode>) => TNode; | ||
@@ -138,3 +138,3 @@ } | ||
*/ | ||
renderMessage?: (commit: Commit<TNode>, commitMessagesX: number) => TNode; | ||
renderMessage?: (commit: Commit<TNode>) => TNode; | ||
/** | ||
@@ -141,0 +141,0 @@ * Custom tooltip render |
@@ -116,2 +116,3 @@ "use strict"; | ||
onClick: this.onClick, | ||
onMessageClick: this.onMessageClick, | ||
onMouseOver: this.onMouseOver, | ||
@@ -118,0 +119,0 @@ onMouseOut: this.onMouseOut, |
@@ -29,3 +29,4 @@ import { Branch } from "./branch"; | ||
orientation?: Orientation; | ||
isVertical: boolean; | ||
readonly isHorizontal: boolean; | ||
readonly isVertical: boolean; | ||
reverseArrow: boolean; | ||
@@ -32,0 +33,0 @@ initCommitOffsetX: number; |
@@ -29,6 +29,2 @@ "use strict"; | ||
this.orientation = options.orientation; | ||
this.isVertical = [ | ||
undefined, | ||
orientation_1.Orientation.VerticalReverse, | ||
].includes(this.orientation); | ||
this.reverseArrow = utils_1.booleanOptionOr(options.reverseArrow, false); | ||
@@ -42,2 +38,9 @@ this.initCommitOffsetX = utils_1.numberOptionOr(options.initCommitOffsetX, 0); | ||
} | ||
get isHorizontal() { | ||
return (this.orientation === orientation_1.Orientation.Horizontal || | ||
this.orientation === orientation_1.Orientation.HorizontalReverse); | ||
} | ||
get isVertical() { | ||
return !this.isHorizontal; | ||
} | ||
/** | ||
@@ -92,3 +95,4 @@ * Return the API to manipulate Gitgraph as a user. | ||
else { | ||
options = Object.assign({}, options, args); | ||
args.style = args.style || {}; | ||
options = Object.assign({}, options, args, { style: Object.assign({}, options.style, args.style, { label: Object.assign({}, options.style.label, args.style.label) }) }); | ||
} | ||
@@ -95,0 +99,0 @@ const branch = new branch_1.Branch(options); |
@@ -44,4 +44,35 @@ export { MergeStyle, ArrowStyle, BranchStyle, CommitDotStyle, CommitMessageStyle, CommitStyleBase, CommitStyle, TemplateOptions, Template, TemplateName, blackArrowTemplate, metroTemplate, templateExtend, getTemplate, }; | ||
spacing: number; | ||
/** | ||
* Branch label style | ||
*/ | ||
label: BranchLabelStyleOptions; | ||
} | ||
declare type BranchStyleOptions = Partial<BranchStyle>; | ||
interface BranchLabelStyle { | ||
/** | ||
* Branch label visibility | ||
*/ | ||
display: boolean; | ||
/** | ||
* Branch label text color | ||
*/ | ||
color: string; | ||
/** | ||
* Branch label stroke color | ||
*/ | ||
strokeColor: string; | ||
/** | ||
* Branch label background color | ||
*/ | ||
bgColor: string; | ||
/** | ||
* Branch label font | ||
*/ | ||
font: string; | ||
/** | ||
* Branch label border radius | ||
*/ | ||
borderRadius: number; | ||
} | ||
declare type BranchLabelStyleOptions = Partial<BranchLabelStyle>; | ||
interface CommitDotStyle { | ||
@@ -84,6 +115,2 @@ /** | ||
/** | ||
* Commit message branch display policy | ||
*/ | ||
displayBranch: boolean; | ||
/** | ||
* Commit message hash display policy | ||
@@ -90,0 +117,0 @@ */ |
@@ -23,2 +23,3 @@ "use strict"; | ||
options.branch = options.branch || {}; | ||
options.branch.label = options.branch.label || {}; | ||
options.arrow = options.arrow || {}; | ||
@@ -36,2 +37,12 @@ options.commit = options.commit || {}; | ||
spacing: utils_1.numberOptionOr(options.branch.spacing, 20), | ||
label: { | ||
display: utils_1.booleanOptionOr(options.branch.label.display, true), | ||
color: options.branch.label.color || options.commit.color, | ||
strokeColor: options.branch.label.strokeColor || options.commit.color, | ||
bgColor: options.branch.label.bgColor || "white", | ||
font: options.branch.label.font || | ||
options.commit.message.font || | ||
"normal 12pt Calibri", | ||
borderRadius: utils_1.numberOptionOr(options.branch.label.borderRadius, 10), | ||
}, | ||
}; | ||
@@ -61,3 +72,2 @@ // Arrow style | ||
displayAuthor: utils_1.booleanOptionOr(options.commit.message.displayAuthor, true), | ||
displayBranch: utils_1.booleanOptionOr(options.commit.message.displayBranch, true), | ||
displayHash: utils_1.booleanOptionOr(options.commit.message.displayHash, true), | ||
@@ -64,0 +74,0 @@ color: options.commit.message.color || options.commit.color, |
@@ -126,3 +126,3 @@ "use strict"; | ||
const message = Object.assign({}, utils_1.withoutUndefinedKeys(this._graph.template.commit.message), utils_1.withoutUndefinedKeys(this._branch.commitDefaultOptions.style.message), style.message); | ||
if (!this._graph.isVertical || this._graph.mode === gitgraph_1.Mode.Compact) { | ||
if (this._graph.isHorizontal || this._graph.mode === gitgraph_1.Mode.Compact) { | ||
message.display = false; | ||
@@ -129,0 +129,0 @@ } |
import { Commit } from "./commit"; | ||
import { GitgraphCore } from "./gitgraph"; | ||
import { Coordinate } from "./branches-paths"; | ||
export { Omit, NonMatchingPropNames, NonMatchingProp, booleanOptionOr, numberOptionOr, pick, debug, isUndefined, withoutUndefinedKeys, arrowSvgPath, }; | ||
@@ -33,3 +34,3 @@ /** | ||
*/ | ||
declare function numberOptionOr(value: any, defaultValue: number | null): number | null; | ||
declare function numberOptionOr(value: any, defaultValue: number): number; | ||
/** | ||
@@ -66,2 +67,2 @@ * Creates an object composed of the picked object properties. | ||
*/ | ||
declare function arrowSvgPath<TNode = SVGElement>(graph: GitgraphCore<TNode>, parent: Commit<TNode>, commit: Commit<TNode>): string; | ||
declare function arrowSvgPath<TNode = SVGElement>(graph: GitgraphCore<TNode>, parent: Coordinate, commit: Commit<TNode>): string; |
@@ -95,3 +95,3 @@ "use strict"; | ||
let alphaX; | ||
// Angle always start from previous commit Y position: | ||
// Angle usually start from previous commit Y position: | ||
// | ||
@@ -105,3 +105,3 @@ // o | ||
// | ||
// So we need to default to commit spacing. | ||
// So we can to default to commit spacing. | ||
// For horizontal orientation => same with commit X position. | ||
@@ -126,24 +126,22 @@ switch (graph.orientation) { | ||
} | ||
// If commit is distant from its parent, there should be no angle. | ||
// | ||
// o ︎ | ||
// ↑ <-- arrow is like previous commit was on same X position | ||
// o | | ||
// | / | ||
// o | ||
// | ||
// For horizontal orientation => same with commit Y position. | ||
if (graph.isVertical) { | ||
if (Math.abs(deltaY) > commitSpacing) | ||
alphaX = 0; | ||
} | ||
else { | ||
if (Math.abs(deltaX) > commitSpacing) | ||
alphaY = 0; | ||
} | ||
if (graph.reverseArrow) { | ||
alphaY *= -1; | ||
alphaX *= -1; | ||
// If arrow is reverse, the previous commit position is considered | ||
// the same on the straight part of the curved path. | ||
// | ||
// o | ||
// ↓ \ | ||
// o ↓ <-- arrow is like previous commit was on same X position | ||
// | o | ||
// ↓ ↙︎ | ||
// o | ||
// | ||
// For horizontal orientation => same with commit Y position. | ||
if (graph.isVertical) { | ||
if (Math.abs(deltaY) > commitSpacing) | ||
alphaX = 0; | ||
} | ||
else { | ||
if (Math.abs(deltaX) > commitSpacing) | ||
alphaY = 0; | ||
} | ||
} | ||
@@ -150,0 +148,0 @@ return Math.atan2(alphaY, alphaX); |
{ | ||
"name": "@gitgraph/core", | ||
"version": "1.0.0-1", | ||
"version": "1.1.0-0", | ||
"description": "Core of gitgraph, a JavaScript library to draw pretty git graphs", | ||
@@ -58,3 +58,3 @@ "author": "Nicolas Carlo <nicolascarlo.espeon@gmail.com>", | ||
"rollup": "^0.51.8", | ||
"typescript": "^2.8.1", | ||
"typescript": "^3.1.0", | ||
"uglify-es": "^3.3.9" | ||
@@ -61,0 +61,0 @@ }, |
@@ -86,2 +86,32 @@ import { GitgraphCore } from "../gitgraph"; | ||
}); | ||
it("should fallback on template style for non-provided keys", () => { | ||
const core = new GitgraphCore(); | ||
const gitgraph = core.getUserApi(); | ||
gitgraph.branch({ name: "master", style: {} }); | ||
const master = core.branches.get("master"); | ||
expect(Object.keys(master.style).length).not.toBe(0); | ||
}); | ||
it("should fallback on template style of label for non-provided keys", () => { | ||
const core = new GitgraphCore(); | ||
const gitgraph = core.getUserApi(); | ||
gitgraph.branch({ name: "master", style: { label: {} } }); | ||
const master = core.branches.get("master"); | ||
expect(Object.keys(master.style.label).length).not.toBe(0); | ||
}); | ||
it("should override template style for provided keys", () => { | ||
const core = new GitgraphCore(); | ||
const gitgraph = core.getUserApi(); | ||
gitgraph.branch({ name: "master", style: { spacing: 12345 } }); | ||
const master = core.branches.get("master"); | ||
expect(master.style.spacing).toBe(12345); | ||
}); | ||
}); |
@@ -298,3 +298,2 @@ import { GitgraphCore, Mode } from "../gitgraph"; | ||
displayAuthor: true, | ||
displayBranch: true, | ||
displayHash: true, | ||
@@ -301,0 +300,0 @@ font: "normal 14pt Arial", |
@@ -9,3 +9,3 @@ import { CommitStyle } from "./template"; | ||
renderDot?: (commit: Commit<TNode>) => TNode; | ||
renderMessage?: (commit: Commit<TNode>, commitMessagesX: number) => TNode; | ||
renderMessage?: (commit: Commit<TNode>) => TNode; | ||
renderTooltip?: (commit: Commit<TNode>) => TNode; | ||
@@ -165,6 +165,3 @@ } | ||
*/ | ||
public renderMessage?: ( | ||
commit: Commit<TNode>, | ||
commitMessagesX: number, | ||
) => TNode; | ||
public renderMessage?: (commit: Commit<TNode>) => TNode; | ||
/** | ||
@@ -275,2 +272,3 @@ * Custom tooltip render | ||
onClick: this.onClick, | ||
onMessageClick: this.onMessageClick, | ||
onMouseOver: this.onMouseOver, | ||
@@ -277,0 +275,0 @@ onMouseOut: this.onMouseOut, |
@@ -45,3 +45,12 @@ import { | ||
public orientation?: Orientation; | ||
public isVertical: boolean; | ||
public get isHorizontal(): boolean { | ||
return ( | ||
this.orientation === Orientation.Horizontal || | ||
this.orientation === Orientation.HorizontalReverse | ||
); | ||
} | ||
public get isVertical(): boolean { | ||
return !this.isHorizontal; | ||
} | ||
public reverseArrow: boolean; | ||
@@ -71,15 +80,5 @@ public initCommitOffsetX: number; | ||
this.orientation = options.orientation; | ||
this.isVertical = [ | ||
undefined, // default value = Vertical | ||
Orientation.VerticalReverse, | ||
].includes(this.orientation); | ||
this.reverseArrow = booleanOptionOr(options.reverseArrow, false); | ||
this.initCommitOffsetX = numberOptionOr( | ||
options.initCommitOffsetX, | ||
0, | ||
) as number; | ||
this.initCommitOffsetY = numberOptionOr( | ||
options.initCommitOffsetY, | ||
0, | ||
) as number; | ||
this.initCommitOffsetX = numberOptionOr(options.initCommitOffsetX, 0); | ||
this.initCommitOffsetY = numberOptionOr(options.initCommitOffsetY, 0); | ||
this.mode = options.mode; | ||
@@ -157,3 +156,15 @@ this.author = options.author || "Sergio Flores <saxo-guy@epic.com>"; | ||
} else { | ||
options = { ...options, ...args }; | ||
args.style = args.style || {}; | ||
options = { | ||
...options, | ||
...args, | ||
style: { | ||
...options.style, | ||
...args.style, | ||
label: { | ||
...options.style.label, | ||
...args.style.label, | ||
}, | ||
}, | ||
}; | ||
} | ||
@@ -160,0 +171,0 @@ const branch = new Branch<TNode>(options); |
@@ -67,2 +67,6 @@ import { merge } from "lodash"; | ||
spacing: number; | ||
/** | ||
* Branch label style | ||
*/ | ||
label: BranchLabelStyleOptions; | ||
} | ||
@@ -72,2 +76,31 @@ | ||
interface BranchLabelStyle { | ||
/** | ||
* Branch label visibility | ||
*/ | ||
display: boolean; | ||
/** | ||
* Branch label text color | ||
*/ | ||
color: string; | ||
/** | ||
* Branch label stroke color | ||
*/ | ||
strokeColor: string; | ||
/** | ||
* Branch label background color | ||
*/ | ||
bgColor: string; | ||
/** | ||
* Branch label font | ||
*/ | ||
font: string; | ||
/** | ||
* Branch label border radius | ||
*/ | ||
borderRadius: number; | ||
} | ||
type BranchLabelStyleOptions = Partial<BranchLabelStyle>; | ||
interface CommitDotStyle { | ||
@@ -112,6 +145,2 @@ /** | ||
/** | ||
* Commit message branch display policy | ||
*/ | ||
displayBranch: boolean; | ||
/** | ||
* Commit message hash display policy | ||
@@ -210,2 +239,3 @@ */ | ||
options.branch = options.branch || {}; | ||
options.branch.label = options.branch.label || {}; | ||
options.arrow = options.arrow || {}; | ||
@@ -224,3 +254,14 @@ options.commit = options.commit || {}; | ||
mergeStyle: options.branch.mergeStyle || MergeStyle.Bezier, | ||
spacing: numberOptionOr(options.branch.spacing, 20) as number, | ||
spacing: numberOptionOr(options.branch.spacing, 20), | ||
label: { | ||
display: booleanOptionOr(options.branch.label.display, true), | ||
color: options.branch.label.color || options.commit.color, | ||
strokeColor: options.branch.label.strokeColor || options.commit.color, | ||
bgColor: options.branch.label.bgColor || "white", | ||
font: | ||
options.branch.label.font || | ||
options.commit.message.font || | ||
"normal 12pt Calibri", | ||
borderRadius: numberOptionOr(options.branch.label.borderRadius, 10), | ||
}, | ||
}; | ||
@@ -238,3 +279,3 @@ | ||
color: options.commit.color, | ||
spacing: numberOptionOr(options.commit.spacing, 25) as number, | ||
spacing: numberOptionOr(options.commit.spacing, 25), | ||
hasTooltipInCompactMode: booleanOptionOr( | ||
@@ -247,6 +288,3 @@ options.commit.hasTooltipInCompactMode, | ||
size: options.commit.dot.size || 3, | ||
strokeWidth: numberOptionOr( | ||
options.commit.dot.strokeWidth, | ||
0, | ||
) as number, | ||
strokeWidth: numberOptionOr(options.commit.dot.strokeWidth, 0), | ||
strokeColor: options.commit.dot.strokeColor, | ||
@@ -264,6 +302,2 @@ font: | ||
), | ||
displayBranch: booleanOptionOr( | ||
options.commit.message.displayBranch, | ||
true, | ||
), | ||
displayHash: booleanOptionOr(options.commit.message.displayHash, true), | ||
@@ -270,0 +304,0 @@ color: options.commit.message.color || options.commit.color, |
@@ -225,3 +225,3 @@ import { GitgraphCore, Mode } from "../gitgraph"; | ||
if (!this._graph.isVertical || this._graph.mode === Mode.Compact) { | ||
if (this._graph.isHorizontal || this._graph.mode === Mode.Compact) { | ||
message.display = false; | ||
@@ -228,0 +228,0 @@ } |
import { Commit } from "./commit"; | ||
import { GitgraphCore } from "./gitgraph"; | ||
import { Orientation } from "./orientation"; | ||
import { Coordinate } from "./branches-paths"; | ||
@@ -53,6 +54,3 @@ export { | ||
*/ | ||
function numberOptionOr( | ||
value: any, | ||
defaultValue: number | null, | ||
): number | null { | ||
function numberOptionOr(value: any, defaultValue: number): number { | ||
return typeof value === "number" ? value : defaultValue; | ||
@@ -120,3 +118,3 @@ } | ||
graph: GitgraphCore<TNode>, | ||
parent: Commit<TNode>, | ||
parent: Coordinate, | ||
commit: Commit<TNode>, | ||
@@ -155,3 +153,3 @@ ): string { | ||
graph: GitgraphCore<TNode>, | ||
parent: Commit<TNode>, | ||
parent: Coordinate, | ||
commit: Commit<TNode>, | ||
@@ -166,3 +164,3 @@ ): number { | ||
// Angle always start from previous commit Y position: | ||
// Angle usually start from previous commit Y position: | ||
// | ||
@@ -176,3 +174,3 @@ // o | ||
// | ||
// So we need to default to commit spacing. | ||
// So we can to default to commit spacing. | ||
// For horizontal orientation => same with commit X position. | ||
@@ -201,22 +199,20 @@ switch (graph.orientation) { | ||
// If commit is distant from its parent, there should be no angle. | ||
// | ||
// o ︎ | ||
// ↑ <-- arrow is like previous commit was on same X position | ||
// o | | ||
// | / | ||
// o | ||
// | ||
// For horizontal orientation => same with commit Y position. | ||
if (graph.isVertical) { | ||
if (Math.abs(deltaY) > commitSpacing) alphaX = 0; | ||
} else { | ||
if (Math.abs(deltaX) > commitSpacing) alphaY = 0; | ||
} | ||
if (graph.reverseArrow) { | ||
alphaY *= -1; | ||
alphaX *= -1; | ||
// If arrow is reverse, the previous commit position is considered | ||
// the same on the straight part of the curved path. | ||
// | ||
// o | ||
// ↓ \ | ||
// o ↓ <-- arrow is like previous commit was on same X position | ||
// | o | ||
// ↓ ↙︎ | ||
// o | ||
// | ||
// For horizontal orientation => same with commit Y position. | ||
if (graph.isVertical) { | ||
if (Math.abs(deltaY) > commitSpacing) alphaX = 0; | ||
} else { | ||
if (Math.abs(deltaX) > commitSpacing) alphaY = 0; | ||
} | ||
} | ||
@@ -223,0 +219,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1291110
91
31897