mmerezhko-hv commented on code in PR #19717:
URL: https://github.com/apache/echarts/pull/19717#discussion_r1577447199
##########
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:
styles properties that are set directly on the element's style property will
not be blocked, allowing users to safely manipulate styles via JavaScript. e.g.
this, document.body.style.background = 'green'; won't cause an unsafe-inline
violation.
--
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]