plainheart commented on a change in pull request #14393:
URL: https://github.com/apache/echarts/pull/14393#discussion_r664285310
##########
File path: src/component/tooltip/TooltipHTMLContent.ts
##########
@@ -81,15 +85,15 @@ function assembleArrow(
transformStyle += `translateX(-50%) rotate(${arrowPos === 'top' ? 225
: 45}deg)`;
}
- const borderStyle = `${borderColor} solid 1px;`;
+ const borderStyle = `${borderColor} solid ${borderWidth}px;`;
const styleCss = [
- 'position:absolute;width:10px;height:10px;',
+ `position:absolute;width:${borderWidth}px;height:${borderWidth}px;`,
Review comment:
@g7i Thanks for your work. But I think our current calculation is still
not accurate enough. It needs to be improved.
##########
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
```
##########
File path: src/component/tooltip/TooltipHTMLContent.ts
##########
@@ -81,15 +85,15 @@ function assembleArrow(
transformStyle += `translateX(-50%) rotate(${arrowPos === 'top' ? 225
: 45}deg)`;
}
- const borderStyle = `${borderColor} solid 1px;`;
+ const borderStyle = `${borderColor} solid ${borderWidth}px;`;
const styleCss = [
- 'position:absolute;width:10px;height:10px;',
+ `position:absolute;width:${borderWidth}px;height:${borderWidth}px;`,
Review comment:
@g7i You could use various `borderWidth` to test if the arrow will be
off a bit.
##########
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;
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;
- const borderStyle = `${borderColor} solid 1px;`;
+ const borderStyle = `${borderColor} solid ${borderWidth}px;`;
const styleCss = [
- 'position:absolute;width:10px;height:10px;',
+ `position:absolute;width:${arrowSize}px;height:${arrowSize}px;`,
`${positionStyle};${transformStyle};`,
+ `margin-${arrowPos}:${margin}px;`,
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]