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

Commit 11b9210

Browse files
authored
Merge pull request #2165 from wimrijnders/PR6
Moved recurring code for StepNumber to start() method
2 parents 0187ab9 + a2350bb commit 11b9210

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

lib/graph3d/Graph3d.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,10 +1118,8 @@ Graph3d.prototype._redrawLegend = function() {
11181118
var legendMin = isValueLegend ? this.valueMin : this.zMin;
11191119
var legendMax = isValueLegend ? this.valueMax : this.zMax;
11201120
var step = new StepNumber(legendMin, legendMax, (legendMax-legendMin)/5, true);
1121-
step.start();
1122-
if (step.getCurrent() < legendMin) {
1123-
step.next();
1124-
}
1121+
step.start(true);
1122+
11251123
var y;
11261124
while (!step.end()) {
11271125
y = bottom - (step.getCurrent() - legendMin) / (legendMax - legendMin) * height;
@@ -1267,10 +1265,8 @@ Graph3d.prototype._redrawAxis = function() {
12671265
ctx.lineWidth = 1;
12681266
prettyStep = (this.defaultXStep === undefined);
12691267
step = new StepNumber(this.xMin, this.xMax, this.xStep, prettyStep);
1270-
step.start();
1271-
if (step.getCurrent() < this.xMin) {
1272-
step.next();
1273-
}
1268+
step.start(true);
1269+
12741270
while (!step.end()) {
12751271
var x = step.getCurrent();
12761272

@@ -1314,10 +1310,8 @@ Graph3d.prototype._redrawAxis = function() {
13141310
ctx.lineWidth = 1;
13151311
prettyStep = (this.defaultYStep === undefined);
13161312
step = new StepNumber(this.yMin, this.yMax, this.yStep, prettyStep);
1317-
step.start();
1318-
if (step.getCurrent() < this.yMin) {
1319-
step.next();
1320-
}
1313+
step.start(true);
1314+
13211315
while (!step.end()) {
13221316
if (this.showGrid) {
13231317
from = new Point3d(this.xMin, step.getCurrent(), this.zMin);
@@ -1359,10 +1353,8 @@ Graph3d.prototype._redrawAxis = function() {
13591353
ctx.lineWidth = 1;
13601354
prettyStep = (this.defaultZStep === undefined);
13611355
step = new StepNumber(this.zMin, this.zMax, this.zStep, prettyStep);
1362-
step.start();
1363-
if (step.getCurrent() < this.zMin) {
1364-
step.next();
1365-
}
1356+
step.start(true);
1357+
13661358
xText = (Math.cos(armAngle ) > 0) ? this.xMin : this.xMax;
13671359
yText = (Math.sin(armAngle ) < 0) ? this.yMin : this.yMax;
13681360
while (!step.end()) {

lib/graph3d/StepNumber.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,29 @@ StepNumber.prototype.getStep = function () {
115115
};
116116

117117
/**
118-
* Set the current value to the largest value smaller than start, which
119-
* is a multiple of the step size
118+
* Set the current to its starting value.
119+
*
120+
* By default, this will be the largest value smaller than start, which
121+
* is a multiple of the step size.
122+
*
123+
* Parameters checkFirst is optional, default false.
124+
* If set to true, move the current value one step if smaller than start.
120125
*/
121-
StepNumber.prototype.start = function() {
126+
StepNumber.prototype.start = function(checkFirst) {
127+
if (checkFirst === undefined) {
128+
checkFirst = false;
129+
}
130+
122131
this._current = this._start - this._start % this._step;
132+
133+
if (checkFirst) {
134+
if (this.getCurrent() < this._start) {
135+
this.next();
136+
}
137+
}
123138
};
124139

140+
125141
/**
126142
* Do a step, add the step size to the current value
127143
*/

0 commit comments

Comments
 (0)