diff --git a/bower.json b/bower.json index 0c50efe8..ee76797b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "gitgraph.js", - "version": "1.3.0", + "version": "1.3.1", "main": [ "./build/gitgraph.js", "./build/gitgraph.css" ], "ignore": [ "**/.*" diff --git a/build/gitgraph.js b/build/gitgraph.js index d67ac4e9..a94dcc00 100644 --- a/build/gitgraph.js +++ b/build/gitgraph.js @@ -1,5 +1,5 @@ /* ========================================================== - * GitGraph v1.3.0 + * GitGraph v1.3.1 * https://github.com/nicoespeon/gitgraph.js * ========================================================== * Copyright (c) 2016 Nicolas CARLO (@nicoespeon) ٩(^‿^)۶ @@ -384,8 +384,18 @@ **/ GitGraph.prototype.applyCommits = function ( event, callbackFn ) { // Fallback onto layerX/layerY for older versions of Firefox. - var offsetX = event.offsetX || event.layerX; - var offsetY = event.offsetY || event.layerY; + function getOffsetById ( id ) { + var el = document.getElementById( id ); + var rect = el.getBoundingClientRect(); + + return { + top: rect.top + document.body.scrollTop, + left: rect.left + document.body.scrollLeft + }; + } + + var offsetX = event.offsetX || (event.pageX - getOffsetById( this.elementId ).left); + var offsetY = event.offsetY || (event.pageY - getOffsetById( this.elementId ).top); for ( var i = 0, commit; !!(commit = this.commits[ i ]); i++ ) { var distanceX = (commit.x + (this.offsetX + this.marginX) / this.scalingFactor - offsetX); diff --git a/build/gitgraph.min.js b/build/gitgraph.min.js index 26f73231..30920524 100644 --- a/build/gitgraph.min.js +++ b/build/gitgraph.min.js @@ -1,5 +1,5 @@ /* ========================================================== - * GitGraph v1.3.0 + * GitGraph v1.3.1 * https://github.com/nicoespeon/gitgraph.js * ========================================================== * Copyright (c) 2016 Nicolas CARLO (@nicoespeon) ٩(^‿^)۶ @@ -7,4 +7,4 @@ * * GitGraph.js may be freely distributed under the MIT Licence * ========================================================== */ -!function(){"use strict";function a(a,b,c){var d;document.createEvent?(d=document.createEvent("HTMLEvents"),d.initEvent(b,!0,!0)):(d=document.createEventObject(),d.eventType=b),d.eventName=b,d.data=c||{},document.createEvent?a.dispatchEvent(d):a.fireEvent("on"+d.eventType,d)}function b(a){var b,c;return c=1,window.devicePixelRatio&&(b=a.webkitBackingStorePixelRatio||a.mozBackingStorePixelRatio||a.msBackingStorePixelRatio||a.oBackingStorePixelRatio||a.backingStorePixelRatio||1,c*=window.devicePixelRatio/b),c}function c(a){return"vertical"===a.orientation||"vertical-reverse"===a.orientation}function d(a){return"horizontal"===a.orientation||"horizontal-reverse"===a.orientation}function e(a){switch(a="object"==typeof a?a:{},this.elementId="string"==typeof a.elementId?a.elementId:"gitGraph",this.author="string"==typeof a.author?a.author:"Sergio Flores ",this.reverseArrow=i(a.reverseArrow,!1),this.template="string"==typeof a.template||"object"==typeof a.template?this.newTemplate(a.template):a.template instanceof h?a.template:this.newTemplate("metro"),this.mode=a.mode||null,"compact"===this.mode&&(this.template.commit.message.display=!1),a.orientation){case"vertical-reverse":this.template.commit.spacingY*=-1,this.orientation="vertical-reverse",this.template.branch.labelRotation=0,this.template.commit.tag.spacingY*=-1;break;case"horizontal":this.template.commit.message.display=!1,this.template.commit.spacingX=this.template.commit.spacingY,this.template.branch.spacingY=this.template.branch.spacingX,this.template.commit.spacingY=0,this.template.branch.spacingX=0,this.orientation="horizontal",this.template.branch.labelRotation=-90,this.template.commit.tag.spacingX=-this.template.commit.spacingX,this.template.commit.tag.spacingY=this.template.branch.spacingY;break;case"horizontal-reverse":this.template.commit.message.display=!1,this.template.commit.spacingX=-this.template.commit.spacingY,this.template.branch.spacingY=this.template.branch.spacingX,this.template.commit.spacingY=0,this.template.branch.spacingX=0,this.orientation="horizontal-reverse",this.template.branch.labelRotation=90,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}this.marginX=this.template.branch.spacingX+2*this.template.commit.dot.size,this.marginY=this.template.branch.spacingY+2*this.template.commit.dot.size,this.offsetX=0,this.offsetY=0,this.canvas=document.getElementById(this.elementId)||a.canvas,this.context=this.canvas.getContext("2d"),this.context.textBaseline="center",this.tooltip=document.createElement("div"),this.tooltip.className="gitgraph-tooltip",this.tooltip.style.position="fixed",this.tooltip.style.display="none",document.body.appendChild(this.tooltip),this.HEAD=null,this.branches=[],this.commits=[],this.columnMax=0,this.commitOffsetX=a.initCommitOffsetX||0,this.commitOffsetY=a.initCommitOffsetY||0;var b={handleEvent:this.hover,gitgraph:this};this.canvas.addEventListener("mousemove",b,!1);var c={handleEvent:this.click,gitgraph:this};this.canvas.addEventListener("mousedown",c,!1),window.onresize=this.render.bind(this)}function f(a){if(a.parent instanceof e!=!1){if(a="object"==typeof a?a:{},this.parent=a.parent,a.parentCommit&&a.parentBranch){if(a.parentCommit.branch!==a.parentBranch)return;this.parentCommit=a.parentCommit,this.parentBranch=a.parentBranch}else a.parentCommit?(this.parentCommit=a.parentCommit,this.parentBranch=a.parentCommit.branch):a.parentBranch?(this.parentCommit=a.parentBranch.commits.slice(-1)[0],this.parentBranch=a.parentBranch):(this.parentCommit=null,this.parentBranch=null);this.name="string"==typeof a.name?a.name:"no-name",this.context=this.parent.context,this.template=this.parent.template,this.lineWidth=a.lineWidth||this.template.branch.lineWidth,this.lineDash=a.lineDash||this.template.branch.lineDash,this.showLabel=i(a.showLabel,this.template.branch.showLabel),this.spacingX=this.template.branch.spacingX,this.spacingY=this.template.branch.spacingY,this.size=0,this.height=0,this.width=0,this.commits=[],this.path=[],"number"==typeof a.column?this.column=a.column:(this.column=0,this.calculColumn()),this.parent.columnMax=this.column>this.parent.columnMax?this.column:this.parent.columnMax,this.offsetX=this.column*this.spacingX,this.offsetY=this.column*this.spacingY,this.startPoint=this.parentBranch?this.parentCommit===this.parentBranch.commits.slice(-1)[0]?{x:this.parentBranch.offsetX-this.parent.commitOffsetX+this.template.commit.spacingX,y:this.parentBranch.offsetY-this.parent.commitOffsetY+this.template.commit.spacingY,type:"start"}:{x:this.parentCommit.x,y:this.parentCommit.y,type:"start"}:null;var b=this.column%this.template.colors.length;this.color=a.color||this.template.branch.color||this.template.colors[b],this.checkout()}}function g(a){a.parent instanceof e!=!1&&(a="object"==typeof a?a:{},this.parent=a.parent,this.template=this.parent.template,this.context=this.parent.context,this.branch=a.branch,this.author=a.author||this.parent.author,this.date=a.date||(new Date).toUTCString(),this.detail=a.detail||null,this.tag=a.tag||null,this.tagColor=a.tagColor||a.color,this.tagFont=a.tagFont||this.template.commit.tag.font,this.displayTagBox=i(a.displayTagBox,!0),this.sha1=a.sha1||Math.random(100).toString(16).substring(3,10),this.message=a.message||"He doesn't like George Michael! Boooo!",this.arrowDisplay=a.arrowDisplay,this.messageDisplay=i(a.messageDisplay,this.template.commit.message.display),this.messageAuthorDisplay=i(a.messageAuthorDisplay,this.template.commit.message.displayAuthor),this.messageBranchDisplay=i(a.messageBranchDisplay,this.template.commit.message.displayBranch),this.messageHashDisplay=i(a.messageHashDisplay,this.template.commit.message.displayHash),this.messageColor=a.messageColor||a.color,this.messageFont=a.messageFont||this.template.commit.message.font,this.dotColor=a.dotColor||a.color,this.dotSize=a.dotSize||this.template.commit.dot.size,this.dotStrokeWidth=a.dotStrokeWidth||this.template.commit.dot.strokeWidth,this.dotStrokeColor=a.dotStrokeColor||this.template.commit.dot.strokeColor||a.color,this.type=a.type||null,this.onClick=a.onClick||null,this.representedObject=a.representedObject||null,this.parentCommit=a.parentCommit,this.x=a.x,this.y=a.y,this.showLabel=a.showLabel,this.labelColor=a.labelColor||a.color,this.labelFont=a.labelFont||this.template.branch.labelFont,this.parent.commits.push(this))}function h(a){a="object"==typeof a?a:{},a.branch=a.branch||{},a.arrow=a.arrow||{},a.commit=a.commit||{},a.commit.dot=a.commit.dot||{},a.commit.tag=a.commit.tag||{},a.commit.message=a.commit.message||{},this.colors=a.colors||["#6963FF","#47E8D4","#6BDB52","#E84BA5","#FFA657"],this.branch={},this.branch.color=a.branch.color||null,this.branch.lineWidth=a.branch.lineWidth||2,this.branch.lineDash=a.branch.lineDash||[],this.branch.showLabel=a.branch.showLabel||!1,this.branch.labelColor=a.branch.labelColor||null,this.branch.labelFont=a.branch.labelFont||"normal 8pt Calibri",this.branch.labelRotation=a.branch.labelRotation||0,this.branch.mergeStyle=a.branch.mergeStyle||"bezier",this.branch.spacingX="number"==typeof a.branch.spacingX?a.branch.spacingX:20,this.branch.spacingY=a.branch.spacingY||0,this.arrow={},this.arrow.size=a.arrow.size||null,this.arrow.color=a.arrow.color||null,this.arrow.active="number"==typeof this.arrow.size,this.arrow.offset=a.arrow.offset||2,this.commit={},this.commit.spacingX=a.commit.spacingX||0,this.commit.spacingY="number"==typeof a.commit.spacingY?a.commit.spacingY:25,this.commit.widthExtension="number"==typeof a.commit.widthExtension?a.commit.widthExtension:0,this.commit.tooltipHTMLFormatter=a.commit.tooltipHTMLFormatter||null,this.commit.shouldDisplayTooltipsInCompactMode=i(a.commit.shouldDisplayTooltipsInCompactMode,!0),this.commit.color=a.commit.color||null,this.commit.dot={},this.commit.dot.color=a.commit.dot.color||null,this.commit.dot.size=a.commit.dot.size||3,this.commit.dot.strokeWidth=a.commit.dot.strokeWidth||null,this.commit.dot.strokeColor=a.commit.dot.strokeColor||null,this.commit.tag={},this.commit.tag.color=a.commit.tag.color||this.commit.dot.color,this.commit.tag.font=a.commit.tag.font||a.commit.message.font||"normal 10pt Calibri",this.commit.tag.spacingX=this.branch.spacingX,this.commit.tag.spacingY=this.commit.spacingY,this.commit.message={},this.commit.message.display=i(a.commit.message.display,!0),this.commit.message.displayAuthor=i(a.commit.message.displayAuthor,!0),this.commit.message.displayBranch=i(a.commit.message.displayBranch,!0),this.commit.message.displayHash=i(a.commit.message.displayHash,!0),this.commit.message.color=a.commit.message.color||null,this.commit.message.font=a.commit.message.font||"normal 12pt Calibri"}function i(a,b){return"boolean"==typeof a?a:b}function j(a,b,c,d,e,f,g,h){a.save(),a.translate(b,c),a.rotate(g*(Math.PI/180)),a.textAlign="center",a.font=f;var i=a.measureText(d).width,j=k(f);h?(a.beginPath(),a.rect(-(i/2)-4,-(j/2)+2,i+8,j+2),a.fillStyle=e,a.fill(),a.lineWidth=2,a.strokeStyle="black",a.stroke(),a.fillStyle="black"):a.fillStyle=e,a.fillText(d,0,j/2),a.restore()}e.prototype.branch=function(a){if("string"==typeof a){var b=a;a={},a.name=b}a="object"==typeof a?a:{},a.parent=this,a.parentBranch=a.parentBranch||this.HEAD;var c=new f(a);return this.branches.push(c),c},e.prototype.orphanBranch=function(a){if("string"==typeof a){var b=a;a={},a.name=b}a="object"==typeof a?a:{},a.parent=this;var c=new f(a);return this.branches.push(c),c},e.prototype.commit=function(a){return this.HEAD.commit(a),this},e.prototype.newTemplate=function(a){return"string"==typeof a?(new h).get(a):new h(a)},e.prototype.render=function(){this.scalingFactor=b(this.context);var c={x:Math.abs((this.columnMax+1)*this.template.branch.spacingX)+Math.abs(this.commitOffsetX)+2*this.marginX,y:Math.abs((this.columnMax+1)*this.template.branch.spacingY)+Math.abs(this.commitOffsetY)+2*this.marginY};this.template.commit.message.display&&(c.x+=800),c.x+=this.template.commit.widthExtension,this.canvas.style.width=c.x+"px",this.canvas.style.height=c.y+"px",this.canvas.width=c.x*this.scalingFactor,this.canvas.height=c.y*this.scalingFactor,this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.context.translate(this.marginX,this.marginY),this.template.commit.spacingY>0&&(this.context.translate(0,this.canvas.height-2*this.marginY),this.offsetY=this.canvas.height-2*this.marginY),this.template.commit.spacingX>0&&(this.context.translate(this.canvas.width-2*this.marginX,0),this.offsetX=this.canvas.width-2*this.marginX),this.context.scale(this.scalingFactor,this.scalingFactor);for(var d,e=this.branches.length-1;d=this.branches[e];e--)d.render();this.tagNum=0;for(var f,g=0;f=this.commits[g];g++)f.render();a(this.canvas,"graph:render",{id:this.elementId})},e.prototype.applyCommits=function(a,b){for(var c,d=a.offsetX||a.layerX,e=a.offsetY||a.layerY,f=0;c=this.commits[f];f++){var g=c.x+(this.offsetX+this.marginX)/this.scalingFactor-d,h=c.y+(this.offsetY+this.marginY)/this.scalingFactor-e,i=Math.sqrt(Math.pow(g,2)+Math.pow(h,2)),j=ia?b:a}this.context.font=this.messageFont;var d=(this.parent.columnMax+1)*this.template.branch.spacingX+a;if(null!==this.detail&&(this.detail.style.left=this.parent.canvas.offsetLeft+d+this.x+30+"px",this.detail.style.top=this.parent.canvas.offsetTop+this.y+40+"px",this.detail.width=30),this.messageDisplay){var e=this.message;this.messageHashDisplay&&(e=this.sha1+" "+e),this.messageAuthorDisplay&&(e+=this.author?" - "+this.author:""),this.messageBranchDisplay&&(e=(this.branch.name?"["+this.branch.name+"] ":"")+e),this.context.fillStyle=this.messageColor,this.context.fillText(e,d,this.y+this.dotSize/2)}},g.prototype.arrow=function(){function a(a,b){var c=f?-1:1;return Math.atan2(c*a,c*b)}var b=this.template.arrow.size,e=this.template.arrow.color||this.branch.color,f=this.parent.reverseArrow,g=a(this.parentCommit.y-this.y,this.parentCommit.x-this.x);if("mergeCommit"===this.type||this===this.branch.commits[0]){var h=this.parentCommit.branch.column-this.branch.column,i=this.showLabel?2:1,j=f&&c(this.parent)&&Math.abs(this.y-this.parentCommit.y)>Math.abs(this.template.commit.spacingY)||c(this.parent)&&i>1,k=j?0:this.template.branch.spacingX*h+this.template.commit.spacingX*i,l=f&&d(this.parent)&&Math.abs(this.x-this.parentCommit.x)>Math.abs(this.template.commit.spacingX)||d(this.parent)&&i>1,m=l?0:this.template.branch.spacingY*h+this.template.commit.spacingY*i;g=a(m,k),e=this.parentCommit.branch.color}var n=Math.PI/7,o=f?this.parentCommit.x:this.x,p=f?this.parentCommit.y:this.y,q=this.template.commit.dot.size+this.template.arrow.offset,r=q*Math.cos(g)+o,s=q*Math.sin(g)+p,t=(q+b)*Math.cos(g-n)+o,u=(q+b)*Math.sin(g-n)+p,v=(q+b/2)*Math.cos(g)+o,w=(q+b/2)*Math.sin(g)+p,x=(q+b)*Math.cos(g+n)+o,y=(q+b)*Math.sin(g+n)+p;this.context.beginPath(),this.context.fillStyle=e,this.context.moveTo(r,s),this.context.lineTo(t,u),this.context.quadraticCurveTo(v,w,x,y),this.context.lineTo(x,y),this.context.fill()},h.prototype.get=function(a){var b={};switch(a){case"blackarrow":b={branch:{color:"#000000",lineWidth:4,spacingX:50,mergeStyle:"straight"},commit:{spacingY:-60,dot:{size:12,strokeColor:"#000000",strokeWidth:7},message:{color:"black"}},arrow:{size:16,offset:2.5}};break;case"metro":default:b={colors:["#979797","#008fb5","#f1c109"],branch:{lineWidth:10,spacingX:50},commit:{spacingY:-80,dot:{size:14},message:{font:"normal 14pt Arial"}}}}return new h(b)};var k=function(a){var b=document.getElementsByTagName("body")[0],c=document.createElement("div"),d=document.createTextNode("Mg");c.appendChild(d),c.setAttribute("style","font: "+a+";"),b.appendChild(c);var e=c.offsetHeight;return b.removeChild(c),e};window.GitGraph=e,window.GitGraph.Branch=f,window.GitGraph.Commit=g,window.GitGraph.Template=h}(); \ No newline at end of file +!function(){"use strict";function a(a,b,c){var d;document.createEvent?(d=document.createEvent("HTMLEvents"),d.initEvent(b,!0,!0)):(d=document.createEventObject(),d.eventType=b),d.eventName=b,d.data=c||{},document.createEvent?a.dispatchEvent(d):a.fireEvent("on"+d.eventType,d)}function b(a){var b,c;return c=1,window.devicePixelRatio&&(b=a.webkitBackingStorePixelRatio||a.mozBackingStorePixelRatio||a.msBackingStorePixelRatio||a.oBackingStorePixelRatio||a.backingStorePixelRatio||1,c*=window.devicePixelRatio/b),c}function c(a){return"vertical"===a.orientation||"vertical-reverse"===a.orientation}function d(a){return"horizontal"===a.orientation||"horizontal-reverse"===a.orientation}function e(a){switch(a="object"==typeof a?a:{},this.elementId="string"==typeof a.elementId?a.elementId:"gitGraph",this.author="string"==typeof a.author?a.author:"Sergio Flores ",this.reverseArrow=i(a.reverseArrow,!1),this.template="string"==typeof a.template||"object"==typeof a.template?this.newTemplate(a.template):a.template instanceof h?a.template:this.newTemplate("metro"),this.mode=a.mode||null,"compact"===this.mode&&(this.template.commit.message.display=!1),a.orientation){case"vertical-reverse":this.template.commit.spacingY*=-1,this.orientation="vertical-reverse",this.template.branch.labelRotation=0,this.template.commit.tag.spacingY*=-1;break;case"horizontal":this.template.commit.message.display=!1,this.template.commit.spacingX=this.template.commit.spacingY,this.template.branch.spacingY=this.template.branch.spacingX,this.template.commit.spacingY=0,this.template.branch.spacingX=0,this.orientation="horizontal",this.template.branch.labelRotation=-90,this.template.commit.tag.spacingX=-this.template.commit.spacingX,this.template.commit.tag.spacingY=this.template.branch.spacingY;break;case"horizontal-reverse":this.template.commit.message.display=!1,this.template.commit.spacingX=-this.template.commit.spacingY,this.template.branch.spacingY=this.template.branch.spacingX,this.template.commit.spacingY=0,this.template.branch.spacingX=0,this.orientation="horizontal-reverse",this.template.branch.labelRotation=90,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}this.marginX=this.template.branch.spacingX+2*this.template.commit.dot.size,this.marginY=this.template.branch.spacingY+2*this.template.commit.dot.size,this.offsetX=0,this.offsetY=0,this.canvas=document.getElementById(this.elementId)||a.canvas,this.context=this.canvas.getContext("2d"),this.context.textBaseline="center",this.tooltip=document.createElement("div"),this.tooltip.className="gitgraph-tooltip",this.tooltip.style.position="fixed",this.tooltip.style.display="none",document.body.appendChild(this.tooltip),this.HEAD=null,this.branches=[],this.commits=[],this.columnMax=0,this.commitOffsetX=a.initCommitOffsetX||0,this.commitOffsetY=a.initCommitOffsetY||0;var b={handleEvent:this.hover,gitgraph:this};this.canvas.addEventListener("mousemove",b,!1);var c={handleEvent:this.click,gitgraph:this};this.canvas.addEventListener("mousedown",c,!1),window.onresize=this.render.bind(this)}function f(a){if(a.parent instanceof e!=!1){if(a="object"==typeof a?a:{},this.parent=a.parent,a.parentCommit&&a.parentBranch){if(a.parentCommit.branch!==a.parentBranch)return;this.parentCommit=a.parentCommit,this.parentBranch=a.parentBranch}else a.parentCommit?(this.parentCommit=a.parentCommit,this.parentBranch=a.parentCommit.branch):a.parentBranch?(this.parentCommit=a.parentBranch.commits.slice(-1)[0],this.parentBranch=a.parentBranch):(this.parentCommit=null,this.parentBranch=null);this.name="string"==typeof a.name?a.name:"no-name",this.context=this.parent.context,this.template=this.parent.template,this.lineWidth=a.lineWidth||this.template.branch.lineWidth,this.lineDash=a.lineDash||this.template.branch.lineDash,this.showLabel=i(a.showLabel,this.template.branch.showLabel),this.spacingX=this.template.branch.spacingX,this.spacingY=this.template.branch.spacingY,this.size=0,this.height=0,this.width=0,this.commits=[],this.path=[],"number"==typeof a.column?this.column=a.column:(this.column=0,this.calculColumn()),this.parent.columnMax=this.column>this.parent.columnMax?this.column:this.parent.columnMax,this.offsetX=this.column*this.spacingX,this.offsetY=this.column*this.spacingY,this.startPoint=this.parentBranch?this.parentCommit===this.parentBranch.commits.slice(-1)[0]?{x:this.parentBranch.offsetX-this.parent.commitOffsetX+this.template.commit.spacingX,y:this.parentBranch.offsetY-this.parent.commitOffsetY+this.template.commit.spacingY,type:"start"}:{x:this.parentCommit.x,y:this.parentCommit.y,type:"start"}:null;var b=this.column%this.template.colors.length;this.color=a.color||this.template.branch.color||this.template.colors[b],this.checkout()}}function g(a){a.parent instanceof e!=!1&&(a="object"==typeof a?a:{},this.parent=a.parent,this.template=this.parent.template,this.context=this.parent.context,this.branch=a.branch,this.author=a.author||this.parent.author,this.date=a.date||(new Date).toUTCString(),this.detail=a.detail||null,this.tag=a.tag||null,this.tagColor=a.tagColor||a.color,this.tagFont=a.tagFont||this.template.commit.tag.font,this.displayTagBox=i(a.displayTagBox,!0),this.sha1=a.sha1||Math.random(100).toString(16).substring(3,10),this.message=a.message||"He doesn't like George Michael! Boooo!",this.arrowDisplay=a.arrowDisplay,this.messageDisplay=i(a.messageDisplay,this.template.commit.message.display),this.messageAuthorDisplay=i(a.messageAuthorDisplay,this.template.commit.message.displayAuthor),this.messageBranchDisplay=i(a.messageBranchDisplay,this.template.commit.message.displayBranch),this.messageHashDisplay=i(a.messageHashDisplay,this.template.commit.message.displayHash),this.messageColor=a.messageColor||a.color,this.messageFont=a.messageFont||this.template.commit.message.font,this.dotColor=a.dotColor||a.color,this.dotSize=a.dotSize||this.template.commit.dot.size,this.dotStrokeWidth=a.dotStrokeWidth||this.template.commit.dot.strokeWidth,this.dotStrokeColor=a.dotStrokeColor||this.template.commit.dot.strokeColor||a.color,this.type=a.type||null,this.onClick=a.onClick||null,this.representedObject=a.representedObject||null,this.parentCommit=a.parentCommit,this.x=a.x,this.y=a.y,this.showLabel=a.showLabel,this.labelColor=a.labelColor||a.color,this.labelFont=a.labelFont||this.template.branch.labelFont,this.parent.commits.push(this))}function h(a){a="object"==typeof a?a:{},a.branch=a.branch||{},a.arrow=a.arrow||{},a.commit=a.commit||{},a.commit.dot=a.commit.dot||{},a.commit.tag=a.commit.tag||{},a.commit.message=a.commit.message||{},this.colors=a.colors||["#6963FF","#47E8D4","#6BDB52","#E84BA5","#FFA657"],this.branch={},this.branch.color=a.branch.color||null,this.branch.lineWidth=a.branch.lineWidth||2,this.branch.lineDash=a.branch.lineDash||[],this.branch.showLabel=a.branch.showLabel||!1,this.branch.labelColor=a.branch.labelColor||null,this.branch.labelFont=a.branch.labelFont||"normal 8pt Calibri",this.branch.labelRotation=a.branch.labelRotation||0,this.branch.mergeStyle=a.branch.mergeStyle||"bezier",this.branch.spacingX="number"==typeof a.branch.spacingX?a.branch.spacingX:20,this.branch.spacingY=a.branch.spacingY||0,this.arrow={},this.arrow.size=a.arrow.size||null,this.arrow.color=a.arrow.color||null,this.arrow.active="number"==typeof this.arrow.size,this.arrow.offset=a.arrow.offset||2,this.commit={},this.commit.spacingX=a.commit.spacingX||0,this.commit.spacingY="number"==typeof a.commit.spacingY?a.commit.spacingY:25,this.commit.widthExtension="number"==typeof a.commit.widthExtension?a.commit.widthExtension:0,this.commit.tooltipHTMLFormatter=a.commit.tooltipHTMLFormatter||null,this.commit.shouldDisplayTooltipsInCompactMode=i(a.commit.shouldDisplayTooltipsInCompactMode,!0),this.commit.color=a.commit.color||null,this.commit.dot={},this.commit.dot.color=a.commit.dot.color||null,this.commit.dot.size=a.commit.dot.size||3,this.commit.dot.strokeWidth=a.commit.dot.strokeWidth||null,this.commit.dot.strokeColor=a.commit.dot.strokeColor||null,this.commit.tag={},this.commit.tag.color=a.commit.tag.color||this.commit.dot.color,this.commit.tag.font=a.commit.tag.font||a.commit.message.font||"normal 10pt Calibri",this.commit.tag.spacingX=this.branch.spacingX,this.commit.tag.spacingY=this.commit.spacingY,this.commit.message={},this.commit.message.display=i(a.commit.message.display,!0),this.commit.message.displayAuthor=i(a.commit.message.displayAuthor,!0),this.commit.message.displayBranch=i(a.commit.message.displayBranch,!0),this.commit.message.displayHash=i(a.commit.message.displayHash,!0),this.commit.message.color=a.commit.message.color||null,this.commit.message.font=a.commit.message.font||"normal 12pt Calibri"}function i(a,b){return"boolean"==typeof a?a:b}function j(a,b,c,d,e,f,g,h){a.save(),a.translate(b,c),a.rotate(g*(Math.PI/180)),a.textAlign="center",a.font=f;var i=a.measureText(d).width,j=k(f);h?(a.beginPath(),a.rect(-(i/2)-4,-(j/2)+2,i+8,j+2),a.fillStyle=e,a.fill(),a.lineWidth=2,a.strokeStyle="black",a.stroke(),a.fillStyle="black"):a.fillStyle=e,a.fillText(d,0,j/2),a.restore()}e.prototype.branch=function(a){if("string"==typeof a){var b=a;a={},a.name=b}a="object"==typeof a?a:{},a.parent=this,a.parentBranch=a.parentBranch||this.HEAD;var c=new f(a);return this.branches.push(c),c},e.prototype.orphanBranch=function(a){if("string"==typeof a){var b=a;a={},a.name=b}a="object"==typeof a?a:{},a.parent=this;var c=new f(a);return this.branches.push(c),c},e.prototype.commit=function(a){return this.HEAD.commit(a),this},e.prototype.newTemplate=function(a){return"string"==typeof a?(new h).get(a):new h(a)},e.prototype.render=function(){this.scalingFactor=b(this.context);var c={x:Math.abs((this.columnMax+1)*this.template.branch.spacingX)+Math.abs(this.commitOffsetX)+2*this.marginX,y:Math.abs((this.columnMax+1)*this.template.branch.spacingY)+Math.abs(this.commitOffsetY)+2*this.marginY};this.template.commit.message.display&&(c.x+=800),c.x+=this.template.commit.widthExtension,this.canvas.style.width=c.x+"px",this.canvas.style.height=c.y+"px",this.canvas.width=c.x*this.scalingFactor,this.canvas.height=c.y*this.scalingFactor,this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.context.translate(this.marginX,this.marginY),this.template.commit.spacingY>0&&(this.context.translate(0,this.canvas.height-2*this.marginY),this.offsetY=this.canvas.height-2*this.marginY),this.template.commit.spacingX>0&&(this.context.translate(this.canvas.width-2*this.marginX,0),this.offsetX=this.canvas.width-2*this.marginX),this.context.scale(this.scalingFactor,this.scalingFactor);for(var d,e=this.branches.length-1;d=this.branches[e];e--)d.render();this.tagNum=0;for(var f,g=0;f=this.commits[g];g++)f.render();a(this.canvas,"graph:render",{id:this.elementId})},e.prototype.applyCommits=function(a,b){function c(a){var b=document.getElementById(a),c=b.getBoundingClientRect();return{top:c.top+document.body.scrollTop,left:c.left+document.body.scrollLeft}}for(var d,e=a.offsetX||a.pageX-c(this.elementId).left,f=a.offsetY||a.pageY-c(this.elementId).top,g=0;d=this.commits[g];g++){var h=d.x+(this.offsetX+this.marginX)/this.scalingFactor-e,i=d.y+(this.offsetY+this.marginY)/this.scalingFactor-f,j=Math.sqrt(Math.pow(h,2)+Math.pow(i,2)),k=ja?b:a}this.context.font=this.messageFont;var d=(this.parent.columnMax+1)*this.template.branch.spacingX+a;if(null!==this.detail&&(this.detail.style.left=this.parent.canvas.offsetLeft+d+this.x+30+"px",this.detail.style.top=this.parent.canvas.offsetTop+this.y+40+"px",this.detail.width=30),this.messageDisplay){var e=this.message;this.messageHashDisplay&&(e=this.sha1+" "+e),this.messageAuthorDisplay&&(e+=this.author?" - "+this.author:""),this.messageBranchDisplay&&(e=(this.branch.name?"["+this.branch.name+"] ":"")+e),this.context.fillStyle=this.messageColor,this.context.fillText(e,d,this.y+this.dotSize/2)}},g.prototype.arrow=function(){function a(a,b){var c=f?-1:1;return Math.atan2(c*a,c*b)}var b=this.template.arrow.size,e=this.template.arrow.color||this.branch.color,f=this.parent.reverseArrow,g=a(this.parentCommit.y-this.y,this.parentCommit.x-this.x);if("mergeCommit"===this.type||this===this.branch.commits[0]){var h=this.parentCommit.branch.column-this.branch.column,i=this.showLabel?2:1,j=f&&c(this.parent)&&Math.abs(this.y-this.parentCommit.y)>Math.abs(this.template.commit.spacingY)||c(this.parent)&&i>1,k=j?0:this.template.branch.spacingX*h+this.template.commit.spacingX*i,l=f&&d(this.parent)&&Math.abs(this.x-this.parentCommit.x)>Math.abs(this.template.commit.spacingX)||d(this.parent)&&i>1,m=l?0:this.template.branch.spacingY*h+this.template.commit.spacingY*i;g=a(m,k),e=this.parentCommit.branch.color}var n=Math.PI/7,o=f?this.parentCommit.x:this.x,p=f?this.parentCommit.y:this.y,q=this.template.commit.dot.size+this.template.arrow.offset,r=q*Math.cos(g)+o,s=q*Math.sin(g)+p,t=(q+b)*Math.cos(g-n)+o,u=(q+b)*Math.sin(g-n)+p,v=(q+b/2)*Math.cos(g)+o,w=(q+b/2)*Math.sin(g)+p,x=(q+b)*Math.cos(g+n)+o,y=(q+b)*Math.sin(g+n)+p;this.context.beginPath(),this.context.fillStyle=e,this.context.moveTo(r,s),this.context.lineTo(t,u),this.context.quadraticCurveTo(v,w,x,y),this.context.lineTo(x,y),this.context.fill()},h.prototype.get=function(a){var b={};switch(a){case"blackarrow":b={branch:{color:"#000000",lineWidth:4,spacingX:50,mergeStyle:"straight"},commit:{spacingY:-60,dot:{size:12,strokeColor:"#000000",strokeWidth:7},message:{color:"black"}},arrow:{size:16,offset:2.5}};break;case"metro":default:b={colors:["#979797","#008fb5","#f1c109"],branch:{lineWidth:10,spacingX:50},commit:{spacingY:-80,dot:{size:14},message:{font:"normal 14pt Arial"}}}}return new h(b)};var k=function(a){var b=document.getElementsByTagName("body")[0],c=document.createElement("div"),d=document.createTextNode("Mg");c.appendChild(d),c.setAttribute("style","font: "+a+";"),b.appendChild(c);var e=c.offsetHeight;return b.removeChild(c),e};window.GitGraph=e,window.GitGraph.Branch=f,window.GitGraph.Commit=g,window.GitGraph.Template=h}(); \ No newline at end of file diff --git a/docs/Branch.html b/docs/Branch.html index 7e735925..84b0c69d 100644 --- a/docs/Branch.html +++ b/docs/Branch.html @@ -324,7 +324,7 @@
Properties
Source:
@@ -465,7 +465,7 @@
Parameters:
Source:
@@ -566,7 +566,7 @@
This:
Source:
@@ -638,7 +638,7 @@
This:
Source:
@@ -833,7 +833,7 @@
Properties
Source:
@@ -912,7 +912,7 @@
This:
Source:
@@ -1092,7 +1092,7 @@
Parameters:
Source:
@@ -1187,7 +1187,7 @@
This:
Source:
@@ -1259,7 +1259,7 @@
This:
Source:
@@ -1306,7 +1306,7 @@

Index

Classes

  • diff --git a/docs/Commit.html b/docs/Commit.html index 65c43190..0cfc387f 100644 --- a/docs/Commit.html +++ b/docs/Commit.html @@ -1296,7 +1296,7 @@
    Properties
    Source:
    @@ -1386,7 +1386,7 @@
    This:
    Source:
    @@ -1458,7 +1458,7 @@
    This:
    Source:
    @@ -1505,7 +1505,7 @@

    Index

    Classes

    • diff --git a/docs/GitGraph.html b/docs/GitGraph.html index 0aa320ae..53547f24 100644 --- a/docs/GitGraph.html +++ b/docs/GitGraph.html @@ -946,7 +946,7 @@
      Parameters:
      Source:
      @@ -1215,7 +1215,7 @@
      Parameters:
      Source:
      @@ -1624,7 +1624,7 @@

      Index

      Classes

      • diff --git a/docs/Template.html b/docs/Template.html index 6cd1053d..d8eed500 100644 --- a/docs/Template.html +++ b/docs/Template.html @@ -1093,7 +1093,7 @@
        Properties
        Source:
        @@ -1228,7 +1228,7 @@
        Parameters:
        Source:
        @@ -1297,7 +1297,7 @@

        Index

        Classes

        • diff --git a/docs/gitgraph.js.html b/docs/gitgraph.js.html index 2738f2e4..a26a346e 100644 --- a/docs/gitgraph.js.html +++ b/docs/gitgraph.js.html @@ -401,8 +401,18 @@

          Source: gitgraph.js

          **/ GitGraph.prototype.applyCommits = function ( event, callbackFn ) { // Fallback onto layerX/layerY for older versions of Firefox. - var offsetX = event.offsetX || event.layerX; - var offsetY = event.offsetY || event.layerY; + function getOffsetById ( id ) { + var el = document.getElementById( id ); + var rect = el.getBoundingClientRect(); + + return { + top: rect.top + document.body.scrollTop, + left: rect.left + document.body.scrollLeft + }; + } + + var offsetX = event.offsetX || (event.pageX - getOffsetById( this.elementId ).left); + var offsetY = event.offsetY || (event.pageY - getOffsetById( this.elementId ).top); for ( var i = 0, commit; !!(commit = this.commits[ i ]); i++ ) { var distanceX = (commit.x + (this.offsetX + this.marginX) / this.scalingFactor - offsetX); @@ -1430,7 +1440,7 @@

          Index

          Classes

          • diff --git a/docs/global.html b/docs/global.html index 9f7bda6c..49010683 100644 --- a/docs/global.html +++ b/docs/global.html @@ -867,7 +867,7 @@

            Index

            Classes

            • diff --git a/docs/index.html b/docs/index.html index 5fbd01df..e398d520 100644 --- a/docs/index.html +++ b/docs/index.html @@ -115,7 +115,7 @@

              Index

              Classes

              • diff --git a/package.json b/package.json index 592374f2..2e1aff88 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitgraph.js", - "version": "1.3.0", + "version": "1.3.1", "author": "Nicolas Carlo ", "description": "A JavaScript library to draw pretty git graphs in the browser", "contributors": [ diff --git a/src/gitgraph.js b/src/gitgraph.js index 751d1a1b..33119b09 100644 --- a/src/gitgraph.js +++ b/src/gitgraph.js @@ -374,8 +374,18 @@ **/ GitGraph.prototype.applyCommits = function ( event, callbackFn ) { // Fallback onto layerX/layerY for older versions of Firefox. - var offsetX = event.offsetX || event.layerX; - var offsetY = event.offsetY || event.layerY; + function getOffsetById ( id ) { + var el = document.getElementById( id ); + var rect = el.getBoundingClientRect(); + + return { + top: rect.top + document.body.scrollTop, + left: rect.left + document.body.scrollLeft + }; + } + + var offsetX = event.offsetX || (event.pageX - getOffsetById( this.elementId ).left); + var offsetY = event.offsetY || (event.pageY - getOffsetById( this.elementId ).top); for ( var i = 0, commit; !!(commit = this.commits[ i ]); i++ ) { var distanceX = (commit.x + (this.offsetX + this.marginX) / this.scalingFactor - offsetX);