Skip to content

Commit 7992cb9

Browse files
committed
Merge pull request #112 from plotly/3d_zeroline_bug
3d zeroline modification
2 parents 53343bd + 2a957d3 commit 7992cb9

39 files changed

+74
-78
lines changed

src/plots/gl3d/layout/convert.js

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,53 +18,53 @@ var arrayCopy1D = arrtools.copy1D;
1818
var AXES_NAMES = ['xaxis', 'yaxis', 'zaxis'];
1919

2020
function AxesOptions() {
21-
this.bounds = [ [-10, -10, -10],
22-
[ 10, 10, 10] ];
23-
24-
this.ticks = [ [], [], [] ];
25-
this.tickEnable = [ true, true, true ];
26-
this.tickFont = [ 'sans-serif', 'sans-serif', 'sans-serif' ];
27-
this.tickSize = [ 12, 12, 12 ];
28-
this.tickAngle = [ 0, 0, 0 ];
29-
this.tickColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
30-
this.tickPad = [ 18, 18, 18 ];
31-
32-
this.labels = [ 'x', 'y', 'z' ];
33-
this.labelEnable = [ true, true, true ];
34-
this.labelFont = ['Open Sans','Open Sans','Open Sans'];
35-
this.labelSize = [ 20, 20, 20 ];
36-
this.labelAngle = [ 0, 0, 0 ];
37-
this.labelColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
38-
this.labelPad = [ 30, 30, 30 ];
39-
40-
this.lineEnable = [ true, true, true ];
41-
this.lineMirror = [ false, false, false ];
42-
this.lineWidth = [ 1, 1, 1 ];
43-
this.lineColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
21+
this.bounds = [ [-10, -10, -10],
22+
[ 10, 10, 10] ];
23+
24+
this.ticks = [ [], [], [] ];
25+
this.tickEnable = [ true, true, true ];
26+
this.tickFont = [ 'sans-serif', 'sans-serif', 'sans-serif' ];
27+
this.tickSize = [ 12, 12, 12 ];
28+
this.tickAngle = [ 0, 0, 0 ];
29+
this.tickColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
30+
this.tickPad = [ 18, 18, 18 ];
31+
32+
this.labels = [ 'x', 'y', 'z' ];
33+
this.labelEnable = [ true, true, true ];
34+
this.labelFont = ['Open Sans','Open Sans','Open Sans'];
35+
this.labelSize = [ 20, 20, 20 ];
36+
this.labelAngle = [ 0, 0, 0 ];
37+
this.labelColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
38+
this.labelPad = [ 30, 30, 30 ];
39+
40+
this.lineEnable = [ true, true, true ];
41+
this.lineMirror = [ false, false, false ];
42+
this.lineWidth = [ 1, 1, 1 ];
43+
this.lineColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
4444

4545
this.lineTickEnable = [ true, true, true ];
4646
this.lineTickMirror = [ false, false, false ];
4747
this.lineTickLength = [ 10, 10, 10 ];
48-
this.lineTickWidth = [ 1, 1, 1 ];
49-
this.lineTickColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
48+
this.lineTickWidth = [ 1, 1, 1 ];
49+
this.lineTickColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
5050

51-
this.gridEnable = [ true, true, true ];
52-
this.gridWidth = [ 1, 1, 1 ];
53-
this.gridColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
51+
this.gridEnable = [ true, true, true ];
52+
this.gridWidth = [ 1, 1, 1 ];
53+
this.gridColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
5454

55-
this.zeroEnable = [ true, true, true ];
56-
this.zeroLineColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
57-
this.zeroLineWidth = [ 2, 2, 2 ];
55+
this.zeroEnable = [ true, true, true ];
56+
this.zeroLineColor = [ [0,0,0,1], [0,0,0,1], [0,0,0,1] ];
57+
this.zeroLineWidth = [ 2, 2, 2 ];
5858

5959
this.backgroundEnable = [ true, true, true ];
6060
this.backgroundColor = [ [0.8, 0.8, 0.8, 0.5],
6161
[0.8, 0.8, 0.8, 0.5],
6262
[0.8, 0.8, 0.8, 0.5] ];
6363

6464
// some default values are stored for applying model transforms
65-
this._defaultTickPad = arrayCopy1D(this.tickPad);
66-
this._defaultLabelPad = arrayCopy1D(this.labelPad);
67-
this._defaultLineTickLength = arrayCopy1D(this.lineTickLength);
65+
this._defaultTickPad = arrayCopy1D(this.tickPad);
66+
this._defaultLabelPad = arrayCopy1D(this.labelPad);
67+
this._defaultLineTickLength = arrayCopy1D(this.lineTickLength);
6868
}
6969

7070
var proto = AxesOptions.prototype;
@@ -78,27 +78,30 @@ proto.merge = function(sceneLayout) {
7878
opts.labels[i] = convertHTML(axes.title);
7979
if ('titlefont' in axes) {
8080
if (axes.titlefont.color) opts.labelColor[i] = str2RgbaArray(axes.titlefont.color);
81-
if (axes.titlefont.family) opts.labelFont[i] = axes.titlefont.family;
82-
if (axes.titlefont.size) opts.labelSize[i] = axes.titlefont.size;
81+
if (axes.titlefont.family) opts.labelFont[i] = axes.titlefont.family;
82+
if (axes.titlefont.size) opts.labelSize[i] = axes.titlefont.size;
8383
}
8484

8585
/////// LINES ////////
8686
if ('showline' in axes) opts.lineEnable[i] = axes.showline;
87-
if ('linecolor' in axes) opts.lineColor[i] = str2RgbaArray(axes.linecolor);
88-
if ('linewidth' in axes) opts.lineWidth[i] = axes.linewidth;
87+
if ('linecolor' in axes) opts.lineColor[i] = str2RgbaArray(axes.linecolor);
88+
if ('linewidth' in axes) opts.lineWidth[i] = axes.linewidth;
8989

9090
if ('showgrid' in axes) opts.gridEnable[i] = axes.showgrid;
91-
if ('gridcolor' in axes) opts.gridColor[i] = str2RgbaArray(axes.gridcolor);
92-
if ('gridwidth' in axes) opts.gridWidth[i] = axes.gridwidth;
91+
if ('gridcolor' in axes) opts.gridColor[i] = str2RgbaArray(axes.gridcolor);
92+
if ('gridwidth' in axes) opts.gridWidth[i] = axes.gridwidth;
9393

94-
if ('zeroline' in axes) opts.zeroEnable[i] = axes.zeroline;
94+
// Remove zeroline if axis type is log
95+
// otherwise the zeroline is incorrectly drawn at 1 on log axes
96+
if (axes.type === 'log') opts.zeroEnable[i] = false;
97+
else if ('zeroline' in axes) opts.zeroEnable[i] = axes.zeroline;
9598
if ('zerolinecolor' in axes) opts.zeroLineColor[i] = str2RgbaArray(axes.zerolinecolor);
9699
if ('zerolinewidth' in axes) opts.zeroLineWidth[i] = axes.zerolinewidth;
97100

98101
//////// TICKS /////////
99102
/// tick lines
100103
if ('ticks' in axes && !!axes.ticks) opts.lineTickEnable[i] = true;
101-
else opts.lineTickEnable[i] = false;
104+
else opts.lineTickEnable[i] = false;
102105

103106
if ('ticklen' in axes) {
104107
opts.lineTickLength[i] = opts._defaultLineTickLength[i] = axes.ticklen;
@@ -111,9 +114,9 @@ proto.merge = function(sceneLayout) {
111114
//// tick labels
112115
if ('showticklabels' in axes) opts.tickEnable[i] = axes.showticklabels;
113116
if ('tickfont' in axes) {
114-
if (axes.tickfont.color) opts.tickColor[i] = str2RgbaArray(axes.tickfont.color);
115-
if (axes.tickfont.family) opts.tickFont[i] = axes.tickfont.family;
116-
if (axes.tickfont.size) opts.tickSize[i] = axes.tickfont.size;
117+
if (axes.tickfont.color) opts.tickColor[i] = str2RgbaArray(axes.tickfont.color);
118+
if (axes.tickfont.family) opts.tickFont[i] = axes.tickfont.family;
119+
if (axes.tickfont.size) opts.tickSize[i] = axes.tickfont.size;
117120
}
118121

119122
if ('mirror' in axes) {
@@ -131,8 +134,8 @@ proto.merge = function(sceneLayout) {
131134

132135
////// grid background
133136
if ('showbackground' in axes && axes.showbackground !== false) {
134-
opts.backgroundEnable[i] = true;
135-
opts.backgroundColor[i] = str2RgbaArray(axes.backgroundcolor);
137+
opts.backgroundEnable[i] = true;
138+
opts.backgroundColor[i] = str2RgbaArray(axes.backgroundcolor);
136139
} else opts.backgroundEnable[i] = false;
137140
}
138141
};

src/plots/gl3d/layout/tick_marks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ function computeTickMarks(scene) {
4949
if (Math.abs(axes._length) === Infinity) {
5050
ticks[i] = [];
5151
} else {
52-
axes.range[0] = (glRange[i].lo + scene.dataCenter[i]) / scene.dataScale[i];
53-
axes.range[1] = (glRange[i].hi + scene.dataCenter[i]) / scene.dataScale[i];
52+
axes.range[0] = (glRange[i].lo) / scene.dataScale[i];
53+
axes.range[1] = (glRange[i].hi) / scene.dataScale[i];
5454
axes._m = 1.0 / (scene.dataScale[i] * glRange[i].pixelsPerDataUnit);
5555

5656
if(axes.range[0] === axes.range[1]) {
@@ -69,7 +69,7 @@ function computeTickMarks(scene) {
6969
}
7070
var dataTicks = Plotly.Axes.calcTicks(axes);
7171
for(var j=0; j<dataTicks.length; ++j) {
72-
dataTicks[j].x = dataTicks[j].x * scene.dataScale[i] - scene.dataCenter[i];
72+
dataTicks[j].x = dataTicks[j].x * scene.dataScale[i];
7373
dataTicks[j].text = convertHTML(dataTicks[j].text);
7474
}
7575
ticks[i] = dataTicks;

src/plots/gl3d/scene.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ function Scene(options, fullLayout) {
218218

219219
//Coordinate rescaling
220220
this.dataScale = [1,1,1];
221-
this.dataCenter = [0,0,0];
222221

223222
this.contourLevels = [ [], [], [] ];
224223

@@ -334,24 +333,20 @@ proto.plot = function(sceneData, fullLayout, layout) {
334333
computeTraceBounds(this, data, dataBounds);
335334
}
336335
var dataScale = [1,1,1];
337-
var dataCenter = [0,0,0];
338336
for(var j=0; j<3; ++j) {
339337
if(dataBounds[0][j] > dataBounds[1][j]) {
340338
dataScale[j] = 1.0;
341-
dataCenter[j] = 0.0;
342339
} else {
343340
if(dataBounds[1][j] === dataBounds[0][j]) {
344341
dataScale[j] = 1.0;
345342
} else {
346343
dataScale[j] = 1.0/(dataBounds[1][j] - dataBounds[0][j]);
347344
}
348-
dataCenter[j] = 0.5 * (dataBounds[0][j] + dataBounds[1][j]) * dataScale[j];
349345
}
350346
}
351347

352-
//Save scale and offset factors
348+
//Save scale
353349
this.dataScale = dataScale;
354-
this.dataCenter = dataCenter;
355350

356351
//Update traces
357352
for(var i = 0; i < sceneData.length; ++i) {
@@ -422,9 +417,9 @@ trace_id_loop:
422417
for(j = 0; j < this.glplot.objects.length; ++j) {
423418
var objBounds = this.glplot.objects[j].bounds;
424419
sceneBounds[0][i] = Math.min(sceneBounds[0][i],
425-
(objBounds[0][i] + dataCenter[i]) / dataScale[i]);
420+
objBounds[0][i] / dataScale[i]);
426421
sceneBounds[1][i] = Math.max(sceneBounds[1][i],
427-
(objBounds[1][i] + dataCenter[i]) / dataScale[i]);
422+
objBounds[1][i] / dataScale[i]);
428423
}
429424
if('rangemode' in axis && axis.rangemode === 'tozero') {
430425
sceneBounds[0][i] = Math.min(sceneBounds[0][i], 0);
@@ -450,8 +445,8 @@ trace_id_loop:
450445
axisDataRange[i] = sceneBounds[1][i] - sceneBounds[0][i];
451446

452447
//Update plot bounds
453-
this.glplot.bounds[0][i] = sceneBounds[0][i] * dataScale[i] - dataCenter[i];
454-
this.glplot.bounds[1][i] = sceneBounds[1][i] * dataScale[i] - dataCenter[i];
448+
this.glplot.bounds[0][i] = sceneBounds[0][i] * dataScale[i];
449+
this.glplot.bounds[1][i] = sceneBounds[1][i] * dataScale[i];
455450
}
456451

457452
var axesScaleRatio = [1, 1, 1];

src/traces/mesh3d/convert.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ proto.update = function(data) {
7676
this.data = data;
7777

7878
//Unpack position data
79-
function toDataCoords(axis, coord, scale, offset) {
79+
function toDataCoords(axis, coord, scale) {
8080
return coord.map(function(x) {
81-
return axis.d2l(x) * scale - offset;
81+
return axis.d2l(x) * scale;
8282
});
8383
}
8484
var positions = zip3(
85-
toDataCoords(layout.xaxis, data.x, scene.dataScale[0], scene.dataCenter[0]),
86-
toDataCoords(layout.yaxis, data.y, scene.dataScale[1], scene.dataCenter[1]),
87-
toDataCoords(layout.zaxis, data.z, scene.dataScale[2], scene.dataCenter[2]));
85+
toDataCoords(layout.xaxis, data.x, scene.dataScale[0]),
86+
toDataCoords(layout.yaxis, data.y, scene.dataScale[1]),
87+
toDataCoords(layout.zaxis, data.z, scene.dataScale[2]));
8888

8989

9090
var cells;

src/traces/scatter3d/convert.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ function convertPlotlyOptions(scene, data) {
169169
points = [],
170170
sceneLayout = scene.fullSceneLayout,
171171
scaleFactor = scene.dataScale,
172-
offset = scene.dataCenter,
173172
xaxis = sceneLayout.xaxis,
174173
yaxis = sceneLayout.yaxis,
175174
zaxis = sceneLayout.zaxis,
@@ -184,9 +183,9 @@ function convertPlotlyOptions(scene, data) {
184183
//Convert points
185184
for (i = 0; i < len; i++) {
186185
// sanitize numbers and apply transforms based on axes.type
187-
xc = xaxis.d2l(x[i]) * scaleFactor[0] - offset[0];
188-
yc = yaxis.d2l(y[i]) * scaleFactor[1] - offset[1];
189-
zc = zaxis.d2l(z[i]) * scaleFactor[2] - offset[2];
186+
xc = xaxis.d2l(x[i]) * scaleFactor[0];
187+
yc = yaxis.d2l(y[i]) * scaleFactor[1];
188+
zc = zaxis.d2l(z[i]) * scaleFactor[2];
190189

191190
points[i] = [xc, yc, zc];
192191
}

src/traces/surface/convert.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ proto.handlePick = function(selection) {
5252

5353
var sceneLayout = this.scene.fullSceneLayout;
5454
selection.dataCoordinate = [
55-
sceneLayout.xaxis.d2l(traceCoordinate[0])*this.scene.dataScale[0] - this.scene.dataCenter[0],
56-
sceneLayout.yaxis.d2l(traceCoordinate[1])*this.scene.dataScale[1] - this.scene.dataCenter[1],
57-
sceneLayout.zaxis.d2l(traceCoordinate[2])*this.scene.dataScale[2] - this.scene.dataCenter[2]
55+
sceneLayout.xaxis.d2l(traceCoordinate[0])*this.scene.dataScale[0],
56+
sceneLayout.yaxis.d2l(traceCoordinate[1])*this.scene.dataScale[1],
57+
sceneLayout.zaxis.d2l(traceCoordinate[2])*this.scene.dataScale[2]
5858
];
5959

6060
var text = this.data.text;
@@ -165,7 +165,6 @@ proto.update = function(data) {
165165
yaxis = sceneLayout.yaxis,
166166
zaxis = sceneLayout.zaxis,
167167
scaleFactor = scene.dataScale,
168-
offset = scene.dataCenter,
169168
xlen = z[0].length,
170169
ylen = z.length,
171170
coords = [
@@ -188,30 +187,30 @@ proto.update = function(data) {
188187
* which is the transpose of 'gl-surface-plot'.
189188
*/
190189
fill(coords[2], function(row, col) {
191-
return zaxis.d2l(z[col][row]) * scaleFactor[2] - offset[2];
190+
return zaxis.d2l(z[col][row]) * scaleFactor[2];
192191
});
193192

194193
// coords x
195194
if (Array.isArray(x[0])) {
196195
fill(xc, function(row, col) {
197-
return xaxis.d2l(x[col][row]) * scaleFactor[0] - offset[0];
196+
return xaxis.d2l(x[col][row]) * scaleFactor[0];
198197
});
199198
} else {
200199
// ticks x
201200
fill(xc, function(row) {
202-
return xaxis.d2l(x[row]) * scaleFactor[0] - offset[0];
201+
return xaxis.d2l(x[row]) * scaleFactor[0];
203202
});
204203
}
205204

206205
// coords y
207206
if (Array.isArray(y[0])) {
208207
fill(yc, function(row, col) {
209-
return yaxis.d2l(y[col][row]) * scaleFactor[1] - offset[1];
208+
return yaxis.d2l(y[col][row]) * scaleFactor[1];
210209
});
211210
} else {
212211
// ticks y
213212
fill(yc, function(row, col) {
214-
return yaxis.d2l(y[col]) * scaleFactor[1] - offset[1];
213+
return yaxis.d2l(y[col]) * scaleFactor[1];
215214
});
216215
}
217216

-564 Bytes
Loading
-109 Bytes
Loading
-1.21 KB
Loading

test/image/baselines/gl3d_bunny.png

-1.2 KB
Loading
-428 Bytes
Loading
-550 Bytes
Loading
-1.2 KB
Loading
-1.2 KB
Loading
-52 Bytes
Loading
-331 Bytes
Loading
-222 Bytes
Loading
-715 Bytes
Loading
-276 Bytes
Loading
-734 Bytes
Loading
-807 Bytes
Loading
-1.57 KB
Loading
-1.78 KB
Loading
-258 Bytes
Loading
-142 Bytes
Loading
-1.07 KB
Loading
Loading
7 Bytes
Loading
-1.5 KB
Loading

test/image/baselines/gl3d_ribbons.png

-1.9 KB
Loading
-1.89 KB
Loading
-951 Bytes
Loading

test/image/baselines/gl3d_snowden.png

-882 Bytes
Loading
-878 Bytes
Loading
-1.7 KB
Loading
-51 Bytes
Loading
-1.51 KB
Loading
-1.02 KB
Loading

test/image/baselines/gl3d_z-range.png

-1 Bytes
Loading

0 commit comments

Comments
 (0)