2019-10-31 23:45:13 +01:00
|
|
|
function getLabels(scale) {
|
|
|
|
return scale.ticks.map(t => t.label);
|
|
|
|
}
|
|
|
|
|
2017-12-02 15:24:57 +01:00
|
|
|
describe('Test tick generators', function() {
|
2018-01-06 18:59:47 +01:00
|
|
|
// formatters are used as default config values so users want to be able to reference them
|
|
|
|
it('Should expose formatters api', function() {
|
|
|
|
expect(typeof Chart.Ticks).toBeDefined();
|
|
|
|
expect(typeof Chart.Ticks.formatters).toBeDefined();
|
|
|
|
expect(typeof Chart.Ticks.formatters.values).toBe('function');
|
2020-02-03 13:36:31 +01:00
|
|
|
expect(typeof Chart.Ticks.formatters.numeric).toBe('function');
|
2018-01-06 18:59:47 +01:00
|
|
|
});
|
|
|
|
|
2017-12-02 15:24:57 +01:00
|
|
|
it('Should generate linear spaced ticks with correct precision', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: []
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
legend: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-12-02 15:24:57 +01:00
|
|
|
type: 'linear',
|
|
|
|
position: 'bottom',
|
|
|
|
ticks: {
|
|
|
|
callback: function(value) {
|
|
|
|
return value.toString();
|
|
|
|
}
|
|
|
|
}
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2017-12-02 15:24:57 +01:00
|
|
|
type: 'linear',
|
|
|
|
ticks: {
|
|
|
|
callback: function(value) {
|
|
|
|
return value.toString();
|
|
|
|
}
|
|
|
|
}
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2017-12-02 15:24:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-11-22 00:46:49 +01:00
|
|
|
var xLabels = getLabels(chart.scales.x);
|
|
|
|
var yLabels = getLabels(chart.scales.y);
|
2017-12-02 15:24:57 +01:00
|
|
|
|
2019-10-31 23:45:13 +01:00
|
|
|
expect(xLabels).toEqual(['0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1']);
|
2020-06-29 13:52:28 +02:00
|
|
|
expect(yLabels).toEqual(['0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1']);
|
2017-12-02 15:24:57 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should generate logarithmic spaced ticks with correct precision', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'line',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: []
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
legend: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-12-02 15:24:57 +01:00
|
|
|
type: 'logarithmic',
|
|
|
|
position: 'bottom',
|
2019-11-15 18:11:13 +01:00
|
|
|
min: 0.1,
|
|
|
|
max: 1,
|
2017-12-02 15:24:57 +01:00
|
|
|
ticks: {
|
|
|
|
callback: function(value) {
|
|
|
|
return value.toString();
|
|
|
|
}
|
|
|
|
}
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2017-12-02 15:24:57 +01:00
|
|
|
type: 'logarithmic',
|
2019-11-15 18:11:13 +01:00
|
|
|
min: 0.1,
|
|
|
|
max: 1,
|
2017-12-02 15:24:57 +01:00
|
|
|
ticks: {
|
|
|
|
callback: function(value) {
|
|
|
|
return value.toString();
|
|
|
|
}
|
|
|
|
}
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2017-12-02 15:24:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-11-22 00:46:49 +01:00
|
|
|
var xLabels = getLabels(chart.scales.x);
|
|
|
|
var yLabels = getLabels(chart.scales.y);
|
2017-12-02 15:24:57 +01:00
|
|
|
|
2019-10-31 23:45:13 +01:00
|
|
|
expect(xLabels).toEqual(['0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1']);
|
|
|
|
expect(yLabels).toEqual(['1', '0.9', '0.8', '0.7', '0.6', '0.5', '0.4', '0.3', '0.2', '0.1']);
|
2017-12-02 15:24:57 +01:00
|
|
|
});
|
|
|
|
});
|