Skip to content

Commit a6dfa82

Browse files
committed
better alignment for frequency labels
1 parent cb631fe commit a6dfa82

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Chart.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,7 @@
16651665
},this);
16661666

16671667
var xFreq = this.xLabelsFreq;
1668+
16681669
each(this.xLabels,function(label,index){
16691670
var xPos = this.calculateX(index) + aliasPixel(this.lineWidth),
16701671
// Check to see if line/bar here and decide where to place the line
@@ -1705,20 +1706,23 @@
17051706

17061707
// Small lines at the bottom of the base grid line
17071708
ctx.beginPath();
1708-
ctx.moveTo(linePos,this.endPoint);
1709+
ctx.moveTo(linePos+20,this.endPoint);
17091710
ctx.lineTo(linePos,this.endPoint + 5);
17101711
ctx.stroke();
17111712
ctx.closePath();
17121713

17131714
ctx.save();
17141715
ctx.translate(xPos,(isRotated) ? this.endPoint + 12 : this.endPoint + 8);
17151716

1717+
if(xFreq > 1) {
1718+
isRotated = true;
1719+
}
17161720
ctx.font = this.font;
1717-
ctx.textAlign = (isRotated) ? "right" : "center";
1721+
ctx.textAlign = (isRotated) ? "right" : (xFreq > 1) ? "right" : "center";
17181722
ctx.textBaseline = (isRotated) ? "middle" : "top";
17191723
if(xFreq) {
17201724
if(index%xFreq === 0) {
1721-
ctx.fillText(label, 0, 0);
1725+
ctx.fillText(label, xFreq>1 ? 45 + xFreq*0.4 : 0, 0);
17221726
}
17231727
} else {
17241728
ctx.rotate(toRadians(this.xLabelRotation)*-1);

0 commit comments

Comments
 (0)