Skip to content

Fix small sizes of bar with base #5061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ module.exports = function setConvert(ax, fullLayout) {
* - defaults to ax.calendar
*/
function dt2ms(v, _, calendar, opts) {
if((opts || {}).msUTC && isNumeric(v)) {
// For now it is only used
// to fix bar length in milliseconds & gl3d ticks
// It could be applied in other places in v2
return +v;
}

// 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
Expand All @@ -100,13 +107,6 @@ module.exports = function setConvert(ax, fullLayout) {
if(ms === BADNUM) {
if(isNumeric(v)) {
v = +v;
if((opts || {}).msUTC) {
// For now it is only used
// to fix bar length in milliseconds.
// It could be applied in other places in v2
return v;
}

// keep track of tenths of ms, that `new Date` will drop
// same logic as in Lib.ms2DateTime
var msecTenths = Math.floor(Lib.mod(v + 0.05, 1) * 10);
Expand Down
25 changes: 25 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,31 @@ describe('Bar.calc', function() {
var cd = gd.calcdata;
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 10]]);
});

it('should translate sizes e.g. 2000 to milliseconds not to year when base is present (vertical case)', function() {
var gd = mockBarPlot([{
type: 'bar',
base: [0],
y: [2000],
x: ['A']
}], {yaxis: {type: 'date'}});

var cd = gd.calcdata;
assertPointField(cd, 's', [[2000]]);
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't these tests need to explicitly specify date axis type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed in 3e439e0.


it('should translate sizes e.g. 2000 to milliseconds not to year when base is present (horizontal case)', function() {
var gd = mockBarPlot([{
type: 'bar',
orientation: 'h',
base: [0],
x: [2000],
y: ['A']
}], {xaxis: {type: 'date'}});

var cd = gd.calcdata;
assertPointField(cd, 's', [[2000]]);
});
});

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