* @private
(ctx, pt, i, rtlHelper, options)
| 845 | * @private |
| 846 | */ |
| 847 | _drawColorBox(ctx, pt, i, rtlHelper, options) { |
| 848 | const labelColor = this.labelColors[i]; |
| 849 | const labelPointStyle = this.labelPointStyles[i]; |
| 850 | const {boxHeight, boxWidth} = options; |
| 851 | const bodyFont = toFont(options.bodyFont); |
| 852 | const colorX = getAlignedX(this, 'left', options); |
| 853 | const rtlColorX = rtlHelper.x(colorX); |
| 854 | const yOffSet = boxHeight < bodyFont.lineHeight ? (bodyFont.lineHeight - boxHeight) / 2 : 0; |
| 855 | const colorY = pt.y + yOffSet; |
| 856 | |
| 857 | if (options.usePointStyle) { |
| 858 | const drawOptions = { |
| 859 | radius: Math.min(boxWidth, boxHeight) / 2, // fit the circle in the box |
| 860 | pointStyle: labelPointStyle.pointStyle, |
| 861 | rotation: labelPointStyle.rotation, |
| 862 | borderWidth: 1 |
| 863 | }; |
| 864 | // Recalculate x and y for drawPoint() because its expecting |
| 865 | // x and y to be center of figure (instead of top left) |
| 866 | const centerX = rtlHelper.leftForLtr(rtlColorX, boxWidth) + boxWidth / 2; |
| 867 | const centerY = colorY + boxHeight / 2; |
| 868 | |
| 869 | // Fill the point with white so that colours merge nicely if the opacity is < 1 |
| 870 | ctx.strokeStyle = options.multiKeyBackground; |
| 871 | ctx.fillStyle = options.multiKeyBackground; |
| 872 | drawPoint(ctx, drawOptions, centerX, centerY); |
| 873 | |
| 874 | // Draw the point |
| 875 | ctx.strokeStyle = labelColor.borderColor; |
| 876 | ctx.fillStyle = labelColor.backgroundColor; |
| 877 | drawPoint(ctx, drawOptions, centerX, centerY); |
| 878 | } else { |
| 879 | // Border |
| 880 | ctx.lineWidth = isObject(labelColor.borderWidth) ? Math.max(...Object.values(labelColor.borderWidth)) : (labelColor.borderWidth || 1); // TODO, v4 remove fallback |
| 881 | ctx.strokeStyle = labelColor.borderColor; |
| 882 | ctx.setLineDash(labelColor.borderDash || []); |
| 883 | ctx.lineDashOffset = labelColor.borderDashOffset || 0; |
| 884 | |
| 885 | // Fill a white rect so that colours merge nicely if the opacity is < 1 |
| 886 | const outerX = rtlHelper.leftForLtr(rtlColorX, boxWidth); |
| 887 | const innerX = rtlHelper.leftForLtr(rtlHelper.xPlus(rtlColorX, 1), boxWidth - 2); |
| 888 | const borderRadius = toTRBLCorners(labelColor.borderRadius); |
| 889 | |
| 890 | if (Object.values(borderRadius).some(v => v !== 0)) { |
| 891 | ctx.beginPath(); |
| 892 | ctx.fillStyle = options.multiKeyBackground; |
| 893 | addRoundedRectPath(ctx, { |
| 894 | x: outerX, |
| 895 | y: colorY, |
| 896 | w: boxWidth, |
| 897 | h: boxHeight, |
| 898 | radius: borderRadius, |
| 899 | }); |
| 900 | ctx.fill(); |
| 901 | ctx.stroke(); |
| 902 | |
| 903 | // Inner square |
| 904 | ctx.fillStyle = labelColor.backgroundColor; |
no test coverage detected