plainheart commented on a change in pull request #14393:
URL: https://github.com/apache/echarts/pull/14393#discussion_r664344993
##########
File path: src/component/tooltip/TooltipHTMLContent.ts
##########
@@ -60,36 +60,45 @@ function mirrorPos(pos: string): string {
}
function assembleArrow(
- backgroundColor: ColorString,
+ tooltipModel: Model<TooltipOption>,
borderColor: ZRColor,
arrowPosition: TooltipOption['position']
) {
if (!isString(arrowPosition) || arrowPosition === 'inside') {
return '';
}
+ const backgroundColor = tooltipModel.get('backgroundColor');
+ const borderWidth = tooltipModel.get('borderWidth');
+
borderColor = convertToColorString(borderColor);
const arrowPos = mirrorPos(arrowPosition);
- let positionStyle = `${arrowPos}:-6px;`;
+ const arrowSize = Math.max(Math.round(borderWidth) * 1.5, 6);
+ let positionStyle = '';
let transformStyle = CSS_TRANSFORM_VENDOR + ':';
+ let rotateDeg = 0;
if (indexOf(['left', 'right'], arrowPos) > -1) {
positionStyle += 'top:50%';
- transformStyle += `translateY(-50%) rotate(${arrowPos === 'left' ?
-225 : -45}deg)`;
+ transformStyle += `translateY(-50%) rotate(${rotateDeg = arrowPos ===
'left' ? -225 : -45}deg)`;
}
else {
positionStyle += 'left:50%';
- transformStyle += `translateX(-50%) rotate(${arrowPos === 'top' ? 225
: 45}deg)`;
+ transformStyle += `translateX(-50%) rotate(${rotateDeg = arrowPos ===
'top' ? 225 : 45}deg)`;
}
+ const arrowOffset = Math.round((borderWidth * Math.SQRT2 + arrowSize / 2)
* 100) / 100;
Review comment:
```suggestion
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;
```
##########
File path: src/component/tooltip/TooltipHTMLContent.ts
##########
@@ -60,36 +60,45 @@ function mirrorPos(pos: string): string {
}
function assembleArrow(
- backgroundColor: ColorString,
+ tooltipModel: Model<TooltipOption>,
borderColor: ZRColor,
arrowPosition: TooltipOption['position']
) {
if (!isString(arrowPosition) || arrowPosition === 'inside') {
return '';
}
+ const backgroundColor = tooltipModel.get('backgroundColor');
+ const borderWidth = tooltipModel.get('borderWidth');
+
borderColor = convertToColorString(borderColor);
const arrowPos = mirrorPos(arrowPosition);
- let positionStyle = `${arrowPos}:-6px;`;
+ const arrowSize = Math.max(Math.round(borderWidth) * 1.5, 6);
+ let positionStyle = '';
let transformStyle = CSS_TRANSFORM_VENDOR + ':';
+ let rotateDeg = 0;
Review comment:
```suggestion
let rotateDeg;
```
##########
File path: src/component/tooltip/TooltipHTMLContent.ts
##########
@@ -60,36 +60,45 @@ function mirrorPos(pos: string): string {
}
function assembleArrow(
- backgroundColor: ColorString,
+ tooltipModel: Model<TooltipOption>,
borderColor: ZRColor,
arrowPosition: TooltipOption['position']
) {
if (!isString(arrowPosition) || arrowPosition === 'inside') {
return '';
}
+ const backgroundColor = tooltipModel.get('backgroundColor');
+ const borderWidth = tooltipModel.get('borderWidth');
+
borderColor = convertToColorString(borderColor);
const arrowPos = mirrorPos(arrowPosition);
- let positionStyle = `${arrowPos}:-6px;`;
+ const arrowSize = Math.max(Math.round(borderWidth) * 1.5, 6);
+ let positionStyle = '';
let transformStyle = CSS_TRANSFORM_VENDOR + ':';
+ let rotateDeg = 0;
if (indexOf(['left', 'right'], arrowPos) > -1) {
positionStyle += 'top:50%';
- transformStyle += `translateY(-50%) rotate(${arrowPos === 'left' ?
-225 : -45}deg)`;
+ transformStyle += `translateY(-50%) rotate(${rotateDeg = arrowPos ===
'left' ? -225 : -45}deg)`;
}
else {
positionStyle += 'left:50%';
- transformStyle += `translateX(-50%) rotate(${arrowPos === 'top' ? 225
: 45}deg)`;
+ transformStyle += `translateX(-50%) rotate(${rotateDeg = arrowPos ===
'top' ? 225 : 45}deg)`;
}
+ const arrowOffset = Math.round((borderWidth * Math.SQRT2 + arrowSize / 2)
* 100) / 100;
+ positionStyle += `;${arrowPos}:-${arrowOffset}px`;
+ const margin = Math.round(borderWidth / 2 * Math.abs(Math.cos(rotateDeg))
* 100) / 100;
Review comment:
```suggestion
```
--
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]