Skip to content
This repository was archived by the owner on Jul 29, 2019. It is now read-only.

Consolidated code for drawing x-axis label #2167

Merged
merged 1 commit into from
Oct 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Consolidated code for drawing x-axis label
wimrijnders committed Oct 18, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 9e13640d8dc2f26c942bc698e21097d8a340b16d
68 changes: 34 additions & 34 deletions lib/graph3d/Graph3d.js
Original file line number Diff line number Diff line change
@@ -1230,6 +1230,32 @@ Graph3d.prototype._line = function(ctx, from, to, strokeStyle) {
}


Graph3d.prototype.drawAxisLabelX = function(ctx, point3d, text, armAngle, yMargin) {
if (yMargin === undefined) {
yMargin = 0;
}

var point2d = this._convert3Dto2D(point3d);

if (Math.cos(armAngle * 2) > 0) {
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
point2d.y += yMargin;
}
else if (Math.sin(armAngle * 2) < 0){
ctx.textAlign = 'right';
ctx.textBaseline = 'middle';
}
else {
ctx.textAlign = 'left';
ctx.textBaseline = 'middle';
}

ctx.fillStyle = this.axisColor;
ctx.fillText(text, point2d.x, point2d.y);
}


/**
* Redraw the axis
*/
@@ -1276,23 +1302,10 @@ Graph3d.prototype._redrawAxis = function() {
this._line(ctx, from, to, this.axisColor);
}

yText = (Math.cos(armAngle) > 0) ? this.yMin : this.yMax;
text = this._convert3Dto2D(new Point3d(x, yText, this.zMin));
if (Math.cos(armAngle * 2) > 0) {
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
text.y += textMargin;
}
else if (Math.sin(armAngle * 2) < 0){
ctx.textAlign = 'right';
ctx.textBaseline = 'middle';
}
else {
ctx.textAlign = 'left';
ctx.textBaseline = 'middle';
}
ctx.fillStyle = this.axisColor;
ctx.fillText(' ' + this.xValueLabel(step.getCurrent()) + ' ', text.x, text.y);
yText = (Math.cos(armAngle) > 0) ? this.yMin : this.yMax;
var point3d = new Point3d(x, yText, this.zMin);
var msg = ' ' + this.xValueLabel(x) + ' ';
this.drawAxisLabelX(ctx, point3d, msg, armAngle, textMargin);

step.next();
}
@@ -1396,23 +1409,10 @@ Graph3d.prototype._redrawAxis = function() {
var xLabel = this.xLabel;
if (xLabel.length > 0) {
yOffset = 0.1 / this.scale.y;
xText = (this.xMin + this.xMax) / 2;
yText = (Math.cos(armAngle) > 0) ? this.yMin - yOffset: this.yMax + yOffset;
text = this._convert3Dto2D(new Point3d(xText, yText, this.zMin));
if (Math.cos(armAngle * 2) > 0) {
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
}
else if (Math.sin(armAngle * 2) < 0){
ctx.textAlign = 'right';
ctx.textBaseline = 'middle';
}
else {
ctx.textAlign = 'left';
ctx.textBaseline = 'middle';
}
ctx.fillStyle = this.axisColor;
ctx.fillText(xLabel, text.x, text.y);
xText = (this.xMin + this.xMax) / 2;
yText = (Math.cos(armAngle) > 0) ? this.yMin - yOffset: this.yMax + yOffset;
text = new Point3d(xText, yText, this.zMin);
this.drawAxisLabelX(ctx, text, xLabel, armAngle);
}

// draw y-label