* @private
(ctx, pt, i, rtlHelper, options)
| 787 | * @private |
| 788 | */ |
| 789 | _drawColorBox(ctx, pt, i, rtlHelper, options) { |
| 790 | const labelColor = this.labelColors[i]; |
| 791 | const labelPointStyle = this.labelPointStyles[i]; |
| 792 | const {boxHeight, boxWidth} = options; |
| 793 | const bodyFont = toFont(options.bodyFont); |
| 794 | const colorX = getAlignedX(this, 'left', options); |
| 795 | const rtlColorX = rtlHelper.x(colorX); |
| 796 | const yOffSet = boxHeight < bodyFont.lineHeight ? (bodyFont.lineHeight - boxHeight) / 2 : 0; |
| 797 | const colorY = pt.y + yOffSet; |
| 798 | |
| 799 | if (options.usePointStyle) { |
| 800 | const drawOptions = { |
| 801 | radius: Math.min(boxWidth, boxHeight) / 2, // fit the circle in the box |
| 802 | pointStyle: labelPointStyle.pointStyle, |
| 803 | rotation: labelPointStyle.rotation, |
| 804 | borderWidth: 1 |
| 805 | }; |
| 806 | // Recalculate x and y for drawPoint() because its expecting |
| 807 | // x and y to be center of figure (instead of top left) |
| 808 | const centerX = rtlHelper.leftForLtr(rtlColorX, boxWidth) + boxWidth / 2; |
| 809 | const centerY = colorY + boxHeight / 2; |
| 810 | |
| 811 | // Fill the point with white so that colours merge nicely if the opacity is < 1 |
| 812 | ctx.strokeStyle = options.multiKeyBackground; |
| 813 | ctx.fillStyle = options.multiKeyBackground; |
| 814 | drawPoint(ctx, drawOptions, centerX, centerY); |
| 815 | |
| 816 | // Draw the point |
| 817 | ctx.strokeStyle = labelColor.borderColor; |
| 818 | ctx.fillStyle = labelColor.backgroundColor; |
| 819 | drawPoint(ctx, drawOptions, centerX, centerY); |
| 820 | } else { |
| 821 | // Border |
| 822 | ctx.lineWidth = isObject(labelColor.borderWidth) ? Math.max(...Object.values(labelColor.borderWidth)) : (labelColor.borderWidth || 1); // TODO, v4 remove fallback |
| 823 | ctx.strokeStyle = labelColor.borderColor; |
| 824 | ctx.setLineDash(labelColor.borderDash || []); |
| 825 | ctx.lineDashOffset = labelColor.borderDashOffset || 0; |
| 826 | |
| 827 | // Fill a white rect so that colours merge nicely if the opacity is < 1 |
| 828 | const outerX = rtlHelper.leftForLtr(rtlColorX, boxWidth); |
| 829 | const innerX = rtlHelper.leftForLtr(rtlHelper.xPlus(rtlColorX, 1), boxWidth - 2); |
| 830 | const borderRadius = toTRBLCorners(labelColor.borderRadius); |
| 831 | |
| 832 | if (Object.values(borderRadius).some(v => v !== 0)) { |
| 833 | ctx.beginPath(); |
| 834 | ctx.fillStyle = options.multiKeyBackground; |
| 835 | addRoundedRectPath(ctx, { |
| 836 | x: outerX, |
| 837 | y: colorY, |
| 838 | w: boxWidth, |
| 839 | h: boxHeight, |
| 840 | radius: borderRadius, |
| 841 | }); |
| 842 | ctx.fill(); |
| 843 | ctx.stroke(); |
| 844 | |
| 845 | // Inner square |
| 846 | ctx.fillStyle = labelColor.backgroundColor; |
no test coverage detected