Skip to content

Commit ad1e8ff

Browse files
authored
Merge pull request #5061 from plotly/fix5057-tiny-base
Fix small sizes of bar with base
2 parents e65fede + 3e439e0 commit ad1e8ff

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/plots/cartesian/set_convert.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ module.exports = function setConvert(ax, fullLayout) {
9292
* - defaults to ax.calendar
9393
*/
9494
function dt2ms(v, _, calendar, opts) {
95+
if((opts || {}).msUTC && isNumeric(v)) {
96+
// For now it is only used
97+
// to fix bar length in milliseconds & gl3d ticks
98+
// It could be applied in other places in v2
99+
return +v;
100+
}
101+
95102
// NOTE: Changed this behavior: previously we took any numeric value
96103
// to be a ms, even if it was a string that could be a bare year.
97104
// Now we convert it as a date if at all possible, and only try
@@ -100,13 +107,6 @@ module.exports = function setConvert(ax, fullLayout) {
100107
if(ms === BADNUM) {
101108
if(isNumeric(v)) {
102109
v = +v;
103-
if((opts || {}).msUTC) {
104-
// For now it is only used
105-
// to fix bar length in milliseconds.
106-
// It could be applied in other places in v2
107-
return v;
108-
}
109-
110110
// keep track of tenths of ms, that `new Date` will drop
111111
// same logic as in Lib.ms2DateTime
112112
var msecTenths = Math.floor(Lib.mod(v + 0.05, 1) * 10);

test/jasmine/tests/bar_test.js

+25
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,31 @@ describe('Bar.calc', function() {
423423
var cd = gd.calcdata;
424424
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 10]]);
425425
});
426+
427+
it('should translate sizes e.g. 2000 to milliseconds not to year when base is present (vertical case)', function() {
428+
var gd = mockBarPlot([{
429+
type: 'bar',
430+
base: [0],
431+
y: [2000],
432+
x: ['A']
433+
}], {yaxis: {type: 'date'}});
434+
435+
var cd = gd.calcdata;
436+
assertPointField(cd, 's', [[2000]]);
437+
});
438+
439+
it('should translate sizes e.g. 2000 to milliseconds not to year when base is present (horizontal case)', function() {
440+
var gd = mockBarPlot([{
441+
type: 'bar',
442+
orientation: 'h',
443+
base: [0],
444+
x: [2000],
445+
y: ['A']
446+
}], {xaxis: {type: 'date'}});
447+
448+
var cd = gd.calcdata;
449+
assertPointField(cd, 's', [[2000]]);
450+
});
426451
});
427452

428453
describe('Bar.crossTraceCalc (formerly known as setPositions)', function() {

0 commit comments

Comments
 (0)