forked from chartjs/Chart.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue chartjs#4928: linear tick generator doesn't round values to…
… needed precision. (chartjs#4943) * Fix issue 4928 - linear tick generator doesn't round values to needed precision. * Improve: replace toPrecision() in toString() to improve readability. * Fix: logarithmic tick generator doesn't round values to needed precision. * Fix: rounding tick values didn't work for negative values. * Add: Core ticks tests
- Loading branch information
1 parent
15d1056
commit 6f34b22
Showing
2 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
describe('Test tick generators', function() { | ||
it('Should generate linear spaced ticks with correct precision', function() { | ||
var chart = window.acquireChart({ | ||
type: 'line', | ||
data: { | ||
datasets: [{ | ||
data: [] | ||
}], | ||
}, | ||
options: { | ||
legend: { | ||
display: false, | ||
}, | ||
scales: { | ||
xAxes: [{ | ||
type: 'linear', | ||
position: 'bottom', | ||
ticks: { | ||
callback: function(value) { | ||
return value.toString(); | ||
} | ||
} | ||
}], | ||
yAxes: [{ | ||
type: 'linear', | ||
ticks: { | ||
callback: function(value) { | ||
return value.toString(); | ||
} | ||
} | ||
}] | ||
} | ||
} | ||
}); | ||
|
||
var xAxis = chart.scales['x-axis-0']; | ||
var yAxis = chart.scales['y-axis-0']; | ||
|
||
expect(xAxis.ticks).toEqual(['-1', '-0.8', '-0.6', '-0.4', '-0.2', '0', '0.2', '0.4', '0.6', '0.8', '1']); | ||
expect(yAxis.ticks).toEqual(['1', '0.8', '0.6', '0.4', '0.2', '0', '-0.2', '-0.4', '-0.6', '-0.8', '-1']); | ||
}); | ||
|
||
it('Should generate logarithmic spaced ticks with correct precision', function() { | ||
var chart = window.acquireChart({ | ||
type: 'line', | ||
data: { | ||
datasets: [{ | ||
data: [] | ||
}], | ||
}, | ||
options: { | ||
legend: { | ||
display: false, | ||
}, | ||
scales: { | ||
xAxes: [{ | ||
type: 'logarithmic', | ||
position: 'bottom', | ||
ticks: { | ||
min: 0.1, | ||
max: 1, | ||
callback: function(value) { | ||
return value.toString(); | ||
} | ||
} | ||
}], | ||
yAxes: [{ | ||
type: 'logarithmic', | ||
ticks: { | ||
min: 0.1, | ||
max: 1, | ||
callback: function(value) { | ||
return value.toString(); | ||
} | ||
} | ||
}] | ||
} | ||
} | ||
}); | ||
|
||
var xAxis = chart.scales['x-axis-0']; | ||
var yAxis = chart.scales['y-axis-0']; | ||
|
||
expect(xAxis.ticks).toEqual(['0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1']); | ||
expect(yAxis.ticks).toEqual(['1', '0.9', '0.8', '0.7', '0.6', '0.5', '0.4', '0.3', '0.2', '0.1']); | ||
}); | ||
}); |