Skip to content

Commit 2d6cf3d

Browse files
authored
Merge pull request #4903 from plotly/gl3d-ticks-fix-milliseconds
Fix gl3d ticks when converting dates to milliseconds
2 parents 8e2771e + 904351a commit 2d6cf3d

File tree

7 files changed

+47
-19
lines changed

7 files changed

+47
-19
lines changed

src/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ lib.bBoxIntersect = function(a, b, pad) {
257257
* func: the function to apply
258258
* x1, x2: optional extra args
259259
*/
260-
lib.simpleMap = function(array, func, x1, x2) {
260+
lib.simpleMap = function(array, func, x1, x2, opts) {
261261
var len = array.length;
262262
var out = new Array(len);
263-
for(var i = 0; i < len; i++) out[i] = func(array[i], x1, x2);
263+
for(var i = 0; i < len; i++) out[i] = func(array[i], x1, x2, opts);
264264
return out;
265265
};
266266

src/plots/cartesian/axes.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ function autoShiftMonthBins(binStart, data, dtick, dataMin, calendar) {
509509
// ----------------------------------------------------
510510

511511
// ensure we have tick0, dtick, and tick rounding calculated
512-
axes.prepTicks = function(ax) {
513-
var rng = Lib.simpleMap(ax.range, ax.r2l);
512+
axes.prepTicks = function(ax, opts) {
513+
var rng = Lib.simpleMap(ax.range, ax.r2l, undefined, undefined, opts);
514514

515515
// calculate max number of (auto) ticks to display based on plot size
516516
if(ax.tickmode === 'auto' || !ax.dtick) {
@@ -563,16 +563,16 @@ axes.prepTicks = function(ax) {
563563
// if ticks are set to automatic, determine the right values (tick0,dtick)
564564
// in any case, set tickround to # of digits to round tick labels to,
565565
// or codes to this effect for log and date scales
566-
axes.calcTicks = function calcTicks(ax) {
567-
axes.prepTicks(ax);
568-
var rng = Lib.simpleMap(ax.range, ax.r2l);
566+
axes.calcTicks = function calcTicks(ax, opts) {
567+
axes.prepTicks(ax, opts);
568+
var rng = Lib.simpleMap(ax.range, ax.r2l, undefined, undefined, opts);
569569

570570
// now that we've figured out the auto values for formatting
571571
// in case we're missing some ticktext, we can break out for array ticks
572572
if(ax.tickmode === 'array') return arrayTicks(ax);
573573

574574
// find the first tick
575-
ax._tmin = axes.tickFirst(ax);
575+
ax._tmin = axes.tickFirst(ax, opts);
576576

577577
// add a tiny bit so we get ticks which may have rounded out
578578
var exRng = expandRange(rng);
@@ -962,9 +962,9 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) {
962962
};
963963

964964
// calculate the first tick on an axis
965-
axes.tickFirst = function(ax) {
965+
axes.tickFirst = function(ax, opts) {
966966
var r2l = ax.r2l || Number;
967-
var rng = Lib.simpleMap(ax.range, r2l);
967+
var rng = Lib.simpleMap(ax.range, r2l, undefined, undefined, opts);
968968
var axrev = rng[1] < rng[0];
969969
var sRound = axrev ? Math.floor : Math.ceil;
970970
// add a tiny extra bit to make sure we get ticks

src/plots/cartesian/set_convert.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module.exports = function setConvert(ax, fullLayout) {
9090
* - inserts a dummy arg so calendar is the 3rd arg (see notes below).
9191
* - defaults to ax.calendar
9292
*/
93-
function dt2ms(v, _, calendar, msUTC) {
93+
function dt2ms(v, _, calendar, opts) {
9494
// NOTE: Changed this behavior: previously we took any numeric value
9595
// to be a ms, even if it was a string that could be a bare year.
9696
// Now we convert it as a date if at all possible, and only try
@@ -99,7 +99,7 @@ module.exports = function setConvert(ax, fullLayout) {
9999
if(ms === BADNUM) {
100100
if(isNumeric(v)) {
101101
v = +v;
102-
if(msUTC) {
102+
if((opts || {}).msUTC) {
103103
// For now it is only used
104104
// to fix bar length in milliseconds.
105105
// It could be applied in other places in v2
@@ -798,7 +798,7 @@ module.exports = function setConvert(ax, fullLayout) {
798798
// the first letter of ax._id?)
799799
// in case the expected data isn't there, make a list of
800800
// integers based on the opposite data
801-
ax.makeCalcdata = function(trace, axLetter, msUTC) {
801+
ax.makeCalcdata = function(trace, axLetter, opts) {
802802
var arrayIn, arrayOut, i, len;
803803

804804
var axType = ax.type;
@@ -822,10 +822,10 @@ module.exports = function setConvert(ax, fullLayout) {
822822

823823
arrayOut = new Array(len);
824824
for(i = 0; i < len; i++) {
825-
arrayOut[i] = ax.d2c(arrayIn[i], 0, cal, msUTC);
825+
arrayOut[i] = ax.d2c(arrayIn[i], 0, cal, opts);
826826
}
827827
} else {
828-
var v0 = ((axLetter + '0') in trace) ? ax.d2c(trace[axLetter + '0'], 0, cal, false) : 0;
828+
var v0 = ((axLetter + '0') in trace) ? ax.d2c(trace[axLetter + '0'], 0, cal) : 0;
829829
var dv = (trace['d' + axLetter]) ? Number(trace['d' + axLetter]) : 1;
830830

831831
// the opposing data, for size if we have x and dx etc

src/plots/gl3d/layout/tick_marks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function computeTickMarks(scene) {
6969
var nticks = axes.nticks || Lib.constrain((axes._length / 40), 4, 9);
7070
Axes.autoTicks(axes, Math.abs(axes.range[1] - axes.range[0]) / nticks);
7171
}
72-
var dataTicks = Axes.calcTicks(axes);
72+
var dataTicks = Axes.calcTicks(axes, { msUTC: true });
7373
for(var j = 0; j < dataTicks.length; ++j) {
7474
dataTicks[j].x = dataTicks[j].x * scene.dataScale[i];
7575

src/traces/bar/calc.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ module.exports = function calc(gd, trace) {
1919
var ya = Axes.getFromId(gd, trace.yaxis || 'y');
2020
var size, pos;
2121

22-
var msUTC = !!(trace.base || trace.base === 0);
22+
var sizeOpts = {
23+
msUTC: !!(trace.base || trace.base === 0)
24+
};
2325

2426
if(trace.orientation === 'h') {
25-
size = xa.makeCalcdata(trace, 'x', msUTC);
27+
size = xa.makeCalcdata(trace, 'x', sizeOpts);
2628
pos = ya.makeCalcdata(trace, 'y');
2729
} else {
28-
size = ya.makeCalcdata(trace, 'y', msUTC);
30+
size = ya.makeCalcdata(trace, 'y', sizeOpts);
2931
pos = xa.makeCalcdata(trace, 'x');
3032
}
3133

Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"data": [{
3+
"type": "scatter3d",
4+
"x": ["1970-01-01 01:00:00", "1970-01-01 13:00:00"],
5+
"y": ["1970-01-01 01:00:00", "1970-01-01 02:00:00"],
6+
"z": ["1970-01-01 01:00:00", "1970-01-01 01:30:00"]
7+
}],
8+
"layout": {
9+
"width": 400,
10+
"height": 400,
11+
"margin": {
12+
"t": 10,
13+
"b": 10,
14+
"l": 10,
15+
"r": 10
16+
},
17+
"scene": {
18+
"xaxis": { "nticks": 12, "type": "date" },
19+
"yaxis": { "nticks": 12, "type": "date" },
20+
"zaxis": { "nticks": 12, "type": "date" },
21+
"camera": {
22+
"eye": { "x": 0.25, "y": 2.5, "z": 0.25 }
23+
}
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)