diff --git a/src/lib/index.js b/src/lib/index.js index 9ec4313587e..331c5dbefb4 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -257,10 +257,10 @@ lib.bBoxIntersect = function(a, b, pad) { * func: the function to apply * x1, x2: optional extra args */ -lib.simpleMap = function(array, func, x1, x2) { +lib.simpleMap = function(array, func, x1, x2, opts) { var len = array.length; var out = new Array(len); - for(var i = 0; i < len; i++) out[i] = func(array[i], x1, x2); + for(var i = 0; i < len; i++) out[i] = func(array[i], x1, x2, opts); return out; }; diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 5a25212bb41..d17e33c6945 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -509,8 +509,8 @@ function autoShiftMonthBins(binStart, data, dtick, dataMin, calendar) { // ---------------------------------------------------- // ensure we have tick0, dtick, and tick rounding calculated -axes.prepTicks = function(ax) { - var rng = Lib.simpleMap(ax.range, ax.r2l); +axes.prepTicks = function(ax, opts) { + var rng = Lib.simpleMap(ax.range, ax.r2l, undefined, undefined, opts); // calculate max number of (auto) ticks to display based on plot size if(ax.tickmode === 'auto' || !ax.dtick) { @@ -563,16 +563,16 @@ axes.prepTicks = function(ax) { // if ticks are set to automatic, determine the right values (tick0,dtick) // in any case, set tickround to # of digits to round tick labels to, // or codes to this effect for log and date scales -axes.calcTicks = function calcTicks(ax) { - axes.prepTicks(ax); - var rng = Lib.simpleMap(ax.range, ax.r2l); +axes.calcTicks = function calcTicks(ax, opts) { + axes.prepTicks(ax, opts); + var rng = Lib.simpleMap(ax.range, ax.r2l, undefined, undefined, opts); // now that we've figured out the auto values for formatting // in case we're missing some ticktext, we can break out for array ticks if(ax.tickmode === 'array') return arrayTicks(ax); // find the first tick - ax._tmin = axes.tickFirst(ax); + ax._tmin = axes.tickFirst(ax, opts); // add a tiny bit so we get ticks which may have rounded out var exRng = expandRange(rng); @@ -962,9 +962,9 @@ axes.tickIncrement = function(x, dtick, axrev, calendar) { }; // calculate the first tick on an axis -axes.tickFirst = function(ax) { +axes.tickFirst = function(ax, opts) { var r2l = ax.r2l || Number; - var rng = Lib.simpleMap(ax.range, r2l); + var rng = Lib.simpleMap(ax.range, r2l, undefined, undefined, opts); var axrev = rng[1] < rng[0]; var sRound = axrev ? Math.floor : Math.ceil; // add a tiny extra bit to make sure we get ticks diff --git a/src/plots/cartesian/set_convert.js b/src/plots/cartesian/set_convert.js index 612cd668815..b8d0803e638 100644 --- a/src/plots/cartesian/set_convert.js +++ b/src/plots/cartesian/set_convert.js @@ -90,7 +90,7 @@ module.exports = function setConvert(ax, fullLayout) { * - inserts a dummy arg so calendar is the 3rd arg (see notes below). * - defaults to ax.calendar */ - function dt2ms(v, _, calendar, msUTC) { + function dt2ms(v, _, calendar, opts) { // NOTE: Changed this behavior: previously we took any numeric value // to be a ms, even if it was a string that could be a bare year. // Now we convert it as a date if at all possible, and only try @@ -99,7 +99,7 @@ module.exports = function setConvert(ax, fullLayout) { if(ms === BADNUM) { if(isNumeric(v)) { v = +v; - if(msUTC) { + if((opts || {}).msUTC) { // For now it is only used // to fix bar length in milliseconds. // It could be applied in other places in v2 @@ -798,7 +798,7 @@ module.exports = function setConvert(ax, fullLayout) { // the first letter of ax._id?) // in case the expected data isn't there, make a list of // integers based on the opposite data - ax.makeCalcdata = function(trace, axLetter, msUTC) { + ax.makeCalcdata = function(trace, axLetter, opts) { var arrayIn, arrayOut, i, len; var axType = ax.type; @@ -822,10 +822,10 @@ module.exports = function setConvert(ax, fullLayout) { arrayOut = new Array(len); for(i = 0; i < len; i++) { - arrayOut[i] = ax.d2c(arrayIn[i], 0, cal, msUTC); + arrayOut[i] = ax.d2c(arrayIn[i], 0, cal, opts); } } else { - var v0 = ((axLetter + '0') in trace) ? ax.d2c(trace[axLetter + '0'], 0, cal, false) : 0; + var v0 = ((axLetter + '0') in trace) ? ax.d2c(trace[axLetter + '0'], 0, cal) : 0; var dv = (trace['d' + axLetter]) ? Number(trace['d' + axLetter]) : 1; // the opposing data, for size if we have x and dx etc diff --git a/src/plots/gl3d/layout/tick_marks.js b/src/plots/gl3d/layout/tick_marks.js index 5cbbcbd775f..737cf17c32d 100644 --- a/src/plots/gl3d/layout/tick_marks.js +++ b/src/plots/gl3d/layout/tick_marks.js @@ -69,7 +69,7 @@ function computeTickMarks(scene) { var nticks = axes.nticks || Lib.constrain((axes._length / 40), 4, 9); Axes.autoTicks(axes, Math.abs(axes.range[1] - axes.range[0]) / nticks); } - var dataTicks = Axes.calcTicks(axes); + var dataTicks = Axes.calcTicks(axes, { msUTC: true }); for(var j = 0; j < dataTicks.length; ++j) { dataTicks[j].x = dataTicks[j].x * scene.dataScale[i]; diff --git a/src/traces/bar/calc.js b/src/traces/bar/calc.js index e03d4799f24..67b994e98cb 100644 --- a/src/traces/bar/calc.js +++ b/src/traces/bar/calc.js @@ -19,13 +19,15 @@ module.exports = function calc(gd, trace) { var ya = Axes.getFromId(gd, trace.yaxis || 'y'); var size, pos; - var msUTC = !!(trace.base || trace.base === 0); + var sizeOpts = { + msUTC: !!(trace.base || trace.base === 0) + }; if(trace.orientation === 'h') { - size = xa.makeCalcdata(trace, 'x', msUTC); + size = xa.makeCalcdata(trace, 'x', sizeOpts); pos = ya.makeCalcdata(trace, 'y'); } else { - size = ya.makeCalcdata(trace, 'y', msUTC); + size = ya.makeCalcdata(trace, 'y', sizeOpts); pos = xa.makeCalcdata(trace, 'x'); } diff --git a/test/image/baselines/gl3d_ticks-milliseconds.png b/test/image/baselines/gl3d_ticks-milliseconds.png new file mode 100644 index 00000000000..6e62532bfc6 Binary files /dev/null and b/test/image/baselines/gl3d_ticks-milliseconds.png differ diff --git a/test/image/mocks/gl3d_ticks-milliseconds.json b/test/image/mocks/gl3d_ticks-milliseconds.json new file mode 100644 index 00000000000..69f451a62c9 --- /dev/null +++ b/test/image/mocks/gl3d_ticks-milliseconds.json @@ -0,0 +1,26 @@ +{ + "data": [{ + "type": "scatter3d", + "x": ["1970-01-01 01:00:00", "1970-01-01 13:00:00"], + "y": ["1970-01-01 01:00:00", "1970-01-01 02:00:00"], + "z": ["1970-01-01 01:00:00", "1970-01-01 01:30:00"] + }], + "layout": { + "width": 400, + "height": 400, + "margin": { + "t": 10, + "b": 10, + "l": 10, + "r": 10 + }, + "scene": { + "xaxis": { "nticks": 12, "type": "date" }, + "yaxis": { "nticks": 12, "type": "date" }, + "zaxis": { "nticks": 12, "type": "date" }, + "camera": { + "eye": { "x": 0.25, "y": 2.5, "z": 0.25 } + } + } + } +}