MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / avoidOverlap

Function avoidOverlap

libs/echarts/echarts.simple.js:43997–44078  ·  view source on GitHub ↗
(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop)

Source from the content-addressed store, hash-verified

43995}
43996
43997function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop) {
43998 var leftList = [];
43999 var rightList = [];
44000 var leftmostX = Number.MAX_VALUE;
44001 var rightmostX = -Number.MAX_VALUE;
44002 for (var i = 0; i < labelLayoutList.length; i++) {
44003 if (isPositionCenter(labelLayoutList[i])) {
44004 continue;
44005 }
44006 if (labelLayoutList[i].x < cx) {
44007 leftmostX = Math.min(leftmostX, labelLayoutList[i].x);
44008 leftList.push(labelLayoutList[i]);
44009 }
44010 else {
44011 rightmostX = Math.max(rightmostX, labelLayoutList[i].x);
44012 rightList.push(labelLayoutList[i]);
44013 }
44014 }
44015
44016 adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight, viewLeft, viewTop, rightmostX);
44017 adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight, viewLeft, viewTop, leftmostX);
44018
44019 for (var i = 0; i < labelLayoutList.length; i++) {
44020 var layout = labelLayoutList[i];
44021 if (isPositionCenter(layout)) {
44022 continue;
44023 }
44024
44025 var linePoints = layout.linePoints;
44026 if (linePoints) {
44027 var isAlignToEdge = layout.labelAlignTo === 'edge';
44028
44029 var realTextWidth = layout.textRect.width;
44030 var targetTextWidth;
44031 if (isAlignToEdge) {
44032 if (layout.x < cx) {
44033 targetTextWidth = linePoints[2][0] - layout.labelDistance
44034 - viewLeft - layout.labelMargin;
44035 }
44036 else {
44037 targetTextWidth = viewLeft + viewWidth - layout.labelMargin
44038 - linePoints[2][0] - layout.labelDistance;
44039 }
44040 }
44041 else {
44042 if (layout.x < cx) {
44043 targetTextWidth = layout.x - viewLeft - layout.bleedMargin;
44044 }
44045 else {
44046 targetTextWidth = viewLeft + viewWidth - layout.x - layout.bleedMargin;
44047 }
44048 }
44049 if (targetTextWidth < layout.textRect.width) {
44050 layout.text = truncateText(layout.text, targetTextWidth, layout.font);
44051 if (layout.labelAlignTo === 'edge') {
44052 realTextWidth = getWidth(layout.text, layout.font);
44053 }
44054 }

Callers 1

labelLayoutFunction · 0.70

Calls 7

minMethod · 0.80
pushMethod · 0.80
maxMethod · 0.80
isPositionCenterFunction · 0.70
adjustSingleSideFunction · 0.70
truncateTextFunction · 0.70
getWidthFunction · 0.70

Tested by

no test coverage detected