liuyisnake commented on code in PR #19717:
URL: https://github.com/apache/echarts/pull/19717#discussion_r1883559528
##########
src/component/tooltip/TooltipHTMLContent.ts:
##########
@@ -73,34 +73,49 @@ function assembleArrow(
borderColor = convertToColorString(borderColor);
const arrowPos = mirrorPos(arrowPosition);
const arrowSize = Math.max(Math.round(borderWidth) * 1.5, 6);
- let positionStyle = '';
- let transformStyle = CSS_TRANSFORM_VENDOR + ':';
+
+ const arrowClasses = ['tooltip-arrow'];
+ const transformClasses = [];
let rotateDeg;
- if (indexOf(['left', 'right'], arrowPos) > -1) {
- positionStyle += 'top:50%';
- transformStyle += `translateY(-50%) rotate(${rotateDeg = arrowPos ===
'left' ? -225 : -45}deg)`;
+
+ if (['left', 'right'].includes(arrowPos)) {
+ arrowClasses.push('tooltip-arrow-horizontal');
+ transformClasses.push(`tooltip-arrow-rotate-${rotateDeg = arrowPos ===
'left' ? -225 : -45}`);
}
else {
- positionStyle += 'left:50%';
- transformStyle += `translateX(-50%) rotate(${rotateDeg = arrowPos ===
'top' ? 225 : 45}deg)`;
+ arrowClasses.push('tooltip-arrow-vertical');
+ transformClasses.push(`tooltip-arrow-rotate-${rotateDeg = arrowPos ===
'top' ? 225 : 45}`);
+ }
+
+ function calculateArrowOffset(rotatedWH: number, borderWidth: number,
arrowWH: number) {
+ return Math.round(
+ (
+ ((rotatedWH - Math.SQRT2 * borderWidth) / 2
+ + Math.SQRT2 * borderWidth
+ - (rotatedWH - arrowWH) / 2)
+ * 100
+ ) / 100
+ );
}
+
+ function getColorClassName(color: ZRColor) {
+ const colorValue = convertToColorString(color);
+ return colorValue.replace(/[^a-zA-Z0-9]/g, '');
+ }
+
const rotateRadian = rotateDeg * Math.PI / 180;
const arrowWH = arrowSize + borderWidth;
const rotatedWH = arrowWH * Math.abs(Math.cos(rotateRadian)) + arrowWH *
Math.abs(Math.sin(rotateRadian));
- const arrowOffset = Math.round(((rotatedWH - Math.SQRT2 * borderWidth) / 2
- + Math.SQRT2 * borderWidth - (rotatedWH - arrowWH) / 2) * 100) / 100;
- positionStyle += `;${arrowPos}:-${arrowOffset}px`;
-
- const borderStyle = `${borderColor} solid ${borderWidth}px;`;
- const styleCss = [
-
`position:absolute;width:${arrowSize}px;height:${arrowSize}px;z-index:-1;`,
- `${positionStyle};${transformStyle};`,
- `border-bottom:${borderStyle}`,
- `border-right:${borderStyle}`,
- `background-color:${backgroundColor};`
- ];
-
- return `<div style="${styleCss.join('')}"></div>`;
Review Comment:
met the same issue , insert a styled item to dom will violate the
unsafe-inline policy
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]