Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/helpers/helpers.extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export const _alignStartEnd = (align, start, end) => align === 'start' ? start :
* @param {string} align start, end, center
* @param {number} left value for start
* @param {number} right value for end
* @param {boolean} rtl Is this an RTL draw
* @private
*/
export const _textX = (align, left, right) => align === 'right' ? right : align === 'center' ? (left + right) / 2 : left;
export const _textX = (align, left, right, rtl) => {
const check = rtl ? 'left' : 'right';
return align === check ? right : align === 'center' ? (left + right) / 2 : left;
};
6 changes: 3 additions & 3 deletions src/plugins/plugin.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export class Legend extends Element {
const fillText = function(x, y, legendItem) {
renderText(ctx, legendItem.text, x, y + (itemHeight / 2), labelFont, {
strikethrough: legendItem.hidden,
textAlign: legendItem.textAlign
textAlign: rtlHelper.textAlign(legendItem.textAlign)
});
};

Expand Down Expand Up @@ -402,7 +402,7 @@ export class Legend extends Element {

const textWidth = ctx.measureText(legendItem.text).width;
const textAlign = rtlHelper.textAlign(legendItem.textAlign || (legendItem.textAlign = labelOpts.textAlign));
const width = boxWidth + (fontSize / 2) + textWidth;
const width = boxWidth + halfFontSize + textWidth;
let x = cursor.x;
let y = cursor.y;

Expand All @@ -424,7 +424,7 @@ export class Legend extends Element {

drawLegendBox(realX, y, legendItem);

x = _textX(textAlign, x + boxWidth + halfFontSize, me.right);
x = _textX(textAlign, x + boxWidth + halfFontSize, isHorizontal ? x + width : me.right, opts.rtl);

// Fill the actual label
fillText(rtlHelper.x(x), y, legendItem);
Expand Down
30 changes: 30 additions & 0 deletions test/fixtures/plugin.legend/label-textAlign/horizontal-left.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
config: {
type: 'pie',
data: {
labels: ['aaaa', 'bb', 'c'],
datasets: [
{
data: [1, 2, 3]
}
]
},
options: {
plugins: {
legend: {
position: 'top',
labels: {
textAlign: 'left'
}
}
}
}
},
options: {
spriteText: true,
canvas: {
width: 256,
height: 256
}
}
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions test/fixtures/plugin.legend/label-textAlign/horizontal-right.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
config: {
type: 'pie',
data: {
labels: ['aaaa', 'bb', 'c'],
datasets: [
{
data: [1, 2, 3]
}
]
},
options: {
plugins: {
legend: {
position: 'top',
labels: {
textAlign: 'right'
}
}
}
}
},
options: {
spriteText: true,
canvas: {
width: 256,
height: 256
}
}
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions test/fixtures/plugin.legend/label-textAlign/horizontal-rtl-left.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
config: {
type: 'pie',
data: {
labels: ['aaaa', 'bb', 'c'],
datasets: [
{
data: [1, 2, 3]
}
]
},
options: {
plugins: {
legend: {
position: 'top',
rtl: true,
labels: {
textAlign: 'left'
}
}
}
}
},
options: {
spriteText: true,
canvas: {
width: 256,
height: 256
}
}
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
config: {
type: 'pie',
data: {
labels: ['aaaa', 'bb', 'c'],
datasets: [
{
data: [1, 2, 3]
}
]
},
options: {
plugins: {
legend: {
rtl: true,
position: 'top',
labels: {
textAlign: 'right'
}
}
}
}
},
options: {
spriteText: true,
canvas: {
width: 256,
height: 256
}
}
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/plugin.legend/label-textAlign/rtl-left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/plugin.legend/label-textAlign/rtl-right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.