* @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;
+};
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)
});
};
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;
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);