Skip to content

Commit

Permalink
[feat] support crossAlign on mirrored y-axis (#9563)
Browse files Browse the repository at this point in the history
  • Loading branch information
snoozbuster committed Aug 18, 2021
1 parent 4d99658 commit f8a9d60
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/core/core.scale.js
Expand Up @@ -1344,8 +1344,17 @@ export default class Scale extends Element {

if (position === 'left') {
if (mirror) {
textAlign = 'left';
x = me.right + padding;

if (crossAlign === 'near') {
textAlign = 'left';
} else if (crossAlign === 'center') {
textAlign = 'center';
x += (widest / 2);
} else {
textAlign = 'right';
x += widest;
}
} else {
x = me.right - tickAndPadding;

Expand All @@ -1361,8 +1370,17 @@ export default class Scale extends Element {
}
} else if (position === 'right') {
if (mirror) {
textAlign = 'right';
x = me.left + padding;

if (crossAlign === 'near') {
textAlign = 'right';
} else if (crossAlign === 'center') {
textAlign = 'center';
x -= (widest / 2);
} else {
textAlign = 'left';
x -= widest;
}
} else {
x = me.left + tickAndPadding;

Expand Down
@@ -0,0 +1,30 @@
module.exports = {
config: {
type: 'bar',
data: {
datasets: [{
data: [1, 2, 3],
}],
labels: ['Long long label 1', 'Label2', 'Label3']
},
options: {
indexAxis: 'y',
scales: {
y: {
position: 'left',
ticks: {
mirror: true,
crossAlign: 'center',
},
},
}
}
},
options: {
spriteText: true,
canvas: {
height: 256,
width: 512
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,30 @@
module.exports = {
config: {
type: 'bar',
data: {
datasets: [{
data: [1, 2, 3],
}],
labels: ['Long long label 1', 'Label2', 'Label3']
},
options: {
indexAxis: 'y',
scales: {
y: {
position: 'left',
ticks: {
mirror: true,
crossAlign: 'far',
},
},
}
}
},
options: {
spriteText: true,
canvas: {
height: 256,
width: 512
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,30 @@
module.exports = {
config: {
type: 'bar',
data: {
datasets: [{
data: [1, 2, 3],
}],
labels: ['Long long label 1', 'Label2', 'Label3']
},
options: {
indexAxis: 'y',
scales: {
y: {
position: 'left',
ticks: {
mirror: true,
crossAlign: 'near',
},
},
}
}
},
options: {
spriteText: true,
canvas: {
height: 256,
width: 512
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,30 @@
module.exports = {
config: {
type: 'bar',
data: {
datasets: [{
data: [1, 2, 3],
}],
labels: ['Long long label 1', 'Label2', 'Label3']
},
options: {
indexAxis: 'y',
scales: {
y: {
position: 'right',
ticks: {
mirror: true,
crossAlign: 'center',
},
},
}
}
},
options: {
spriteText: true,
canvas: {
height: 256,
width: 512
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,30 @@
module.exports = {
config: {
type: 'bar',
data: {
datasets: [{
data: [1, 2, 3],
}],
labels: ['Long long label 1', 'Label2', 'Label3']
},
options: {
indexAxis: 'y',
scales: {
y: {
position: 'right',
ticks: {
mirror: true,
crossAlign: 'far',
},
},
}
}
},
options: {
spriteText: true,
canvas: {
height: 256,
width: 512
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,30 @@
module.exports = {
config: {
type: 'bar',
data: {
datasets: [{
data: [1, 2, 3],
}],
labels: ['Long long label 1', 'Label2', 'Label3']
},
options: {
indexAxis: 'y',
scales: {
y: {
position: 'right',
ticks: {
mirror: true,
crossAlign: 'near',
},
},
}
}
},
options: {
spriteText: true,
canvas: {
height: 256,
width: 512
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f8a9d60

Please sign in to comment.