mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 20:29:12 +02:00
Merge pull request #3191 from chartjs/fix/2994
Fix issues with repeated labels in the category scale and added a tes…
This commit is contained in:
commit
8afac7bd3c
@ -59,7 +59,7 @@ module.exports = function(Chart) {
|
||||
// 1 is added because we need the length but we have the indexes
|
||||
var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
||||
|
||||
if (value !== undefined) {
|
||||
if (value !== undefined && isNaN(index)) {
|
||||
var labels = me.getLabels();
|
||||
var idx = labels.indexOf(value);
|
||||
index = idx !== -1 ? idx : index;
|
||||
|
@ -225,6 +225,54 @@ describe('Category scale tests', function() {
|
||||
expect(scale.getValueForPixel(557)).toBe(4);
|
||||
});
|
||||
|
||||
it ('Should get the correct pixel for a value when there are repeated labels', function() {
|
||||
var scaleID = 'myScale';
|
||||
|
||||
var mockData = {
|
||||
datasets: [{
|
||||
yAxisID: scaleID,
|
||||
data: [10, 5, 0, 25, 78]
|
||||
}],
|
||||
labels: ['tick1', 'tick1', 'tick3', 'tick3', 'tick_last']
|
||||
};
|
||||
|
||||
var mockContext = window.createMockContext();
|
||||
var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
|
||||
config.gridLines.offsetGridLines = true;
|
||||
var Constructor = Chart.scaleService.getScaleConstructor('category');
|
||||
var scale = new Constructor({
|
||||
ctx: mockContext,
|
||||
options: config,
|
||||
chart: {
|
||||
data: mockData
|
||||
},
|
||||
id: scaleID
|
||||
});
|
||||
|
||||
var minSize = scale.update(600, 100);
|
||||
|
||||
expect(scale.width).toBe(600);
|
||||
expect(scale.height).toBe(28);
|
||||
expect(scale.paddingTop).toBe(0);
|
||||
expect(scale.paddingBottom).toBe(0);
|
||||
expect(scale.paddingLeft).toBe(28);
|
||||
expect(scale.paddingRight).toBe(48);
|
||||
expect(scale.labelRotation).toBe(0);
|
||||
|
||||
expect(minSize).toEqual({
|
||||
width: 600,
|
||||
height: 28,
|
||||
});
|
||||
|
||||
scale.left = 5;
|
||||
scale.top = 5;
|
||||
scale.right = 605;
|
||||
scale.bottom = 33;
|
||||
|
||||
expect(scale.getPixelForValue('tick_1', 1, 0, false)).toBe(138);
|
||||
expect(scale.getPixelForValue('tick_1', 1, 0, true)).toBe(190);
|
||||
});
|
||||
|
||||
it ('Should get the correct pixel for a value when horizontal and zoomed', function() {
|
||||
var scaleID = 'myScale';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user