MCPcopy Index your code
hub / github.com/apache/echarts / assembleArrow

Function assembleArrow

src/component/tooltip/TooltipHTMLContent.ts:61–104  ·  view source on GitHub ↗
(
    tooltipModel: Model<TooltipOption>,
    borderColor: ZRColor,
    arrowPosition: TooltipOption['position']
)

Source from the content-addressed store, hash-verified

59}
60
61function assembleArrow(
62 tooltipModel: Model<TooltipOption>,
63 borderColor: ZRColor,
64 arrowPosition: TooltipOption['position']
65) {
66 if (!isString(arrowPosition) || arrowPosition === 'inside') {
67 return '';
68 }
69
70 const backgroundColor = tooltipModel.get('backgroundColor');
71 const borderWidth = tooltipModel.get('borderWidth');
72
73 borderColor = convertToColorString(borderColor);
74 const arrowPos = mirrorPos(arrowPosition);
75 const arrowSize = Math.max(Math.round(borderWidth) * 1.5, 6);
76 let positionStyle = '';
77 let transformStyle = CSS_TRANSFORM_VENDOR + ':';
78 let rotateDeg;
79 if (indexOf(['left', 'right'], arrowPos) > -1) {
80 positionStyle += 'top:50%';
81 transformStyle += `translateY(-50%) rotate(${rotateDeg = arrowPos === 'left' ? -225 : -45}deg)`;
82 }
83 else {
84 positionStyle += 'left:50%';
85 transformStyle += `translateX(-50%) rotate(${rotateDeg = arrowPos === 'top' ? 225 : 45}deg)`;
86 }
87 const rotateRadian = rotateDeg * Math.PI / 180;
88 const arrowWH = arrowSize + borderWidth;
89 const rotatedWH = arrowWH * Math.abs(Math.cos(rotateRadian)) + arrowWH * Math.abs(Math.sin(rotateRadian));
90 const arrowOffset = Math.round(((rotatedWH - Math.SQRT2 * borderWidth) / 2
91 + Math.SQRT2 * borderWidth - (rotatedWH - arrowWH) / 2) * 100) / 100;
92 positionStyle += `;${arrowPos}:-${arrowOffset}px`;
93
94 const borderStyle = `${borderColor} solid ${borderWidth}px;`;
95 const styleCss = [
96 `position:absolute;width:${arrowSize}px;height:${arrowSize}px;z-index:-1;`,
97 `${positionStyle};${transformStyle};`,
98 `border-bottom:${borderStyle}`,
99 `border-right:${borderStyle}`,
100 `background-color:${backgroundColor};`
101 ];
102
103 return `<div style="${styleCss.join('')}"></div>`;
104}
105
106function assembleTransition(duration: number, onlyFadeTransition: boolean, enableDisplayTransition: boolean): string {
107 const transitionCurve = 'cubic-bezier(0.23,1,0.32,1)';

Callers 1

setContentMethod · 0.85

Calls 3

convertToColorStringFunction · 0.90
mirrorPosFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…