Skip to content
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

Incorrect conversion of number to boolean #5209

Merged
merged 7 commits into from Jul 29, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scales/scale.linearbase.js
Expand Up @@ -25,7 +25,7 @@ function generateTicks(generationOptions, dataRange) {
var niceMax = Math.ceil(dataRange.max / spacing) * spacing;

// If min, max and stepSize is set and they make an evenly spaced scale use it.
if (generationOptions.min && generationOptions.max && generationOptions.stepSize) {
if (!helpers.isNullOrUndef(generationOptions.min) && !helpers.isNullOrUndef(generationOptions.max) && !helpers.isNullOrUndef(generationOptions.stepSize)) {
Copy link
Member

Choose a reason for hiding this comment

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

@teroman I just realized that we should not apply the same logic to stepSize because stepSize === 0 is invalid (we divide by stepSize line 30).

Should be:

if (!helpers.isNullOrUndef(generationOptions.min) && !helpers.isNullOrUndef(generationOptions.max) && generationOptions.stepSize) {

// If very close to our whole number, use it.
if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) {
niceMin = generationOptions.min;
Expand Down
29 changes: 29 additions & 0 deletions test/specs/scale.linear.tests.js
Expand Up @@ -905,4 +905,33 @@ describe('Linear Scale', function() {
expect(chart.scales['x-axis-0'].min).toEqual(20);
expect(chart.scales['x-axis-0'].max).toEqual(21);
});

it('max setting should be used if it set to zero', function() {
var barData = {
labels: ['S1', 'S2', 'S3'],
datasets: [{
label: 'dataset 1',
backgroundColor: '#382765',
data: [-2500, -2000, -1500],
hidden: true,
}]
};

var chart = window.acquireChart({
type: 'horizontalBar',
data: barData,
options: {
scales: {
xAxes: [{
ticks: {
min: -3000,
max: 0
}
}]
}
}
});

expect(chart.scales['x-axis-0'].max).toEqual(0);
});
});