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

Function hideOverlap

src/label/labelLayoutHelper.ts:522–577  ·  view source on GitHub ↗
(labelList: LabelLayoutData[])

Source from the content-addressed store, hash-verified

520 * the bad case is not noticeable in the zooming scenario.
521 */
522export function hideOverlap(labelList: LabelLayoutData[]): void {
523 const displayedLabels: LabelLayoutWithGeometry[] = [];
524
525 // TODO, render overflow visible first, put in the displayedLabels.
526 labelList.sort(function (a, b) {
527 return ((b.suggestIgnore ? 1 : 0) - (a.suggestIgnore ? 1 : 0))
528 || (b.priority - a.priority);
529 });
530
531 function hideEl(el: Element) {
532 if (!el.ignore) {
533 // Show on emphasis.
534 const emphasisState = el.ensureState('emphasis');
535 if (emphasisState.ignore == null) {
536 emphasisState.ignore = false;
537 }
538 }
539
540 el.ignore = true;
541 }
542
543 for (let i = 0; i < labelList.length; i++) {
544 const labelItem = ensureLabelLayoutWithGeometry(labelList[i]);
545
546 // The current `el.ignore` is involved, since some previous overlap
547 // resolving strategies may have set `el.ignore` to true.
548 if (labelItem.label.ignore) {
549 continue;
550 }
551
552 const label = labelItem.label;
553 const labelLine = labelItem.labelLine;
554
555 // NOTICE: even when the with/height of globalRect of a label is 0, the label line should
556 // still be displayed, since we should follow the concept of "truncation", meaning that
557 // something exists even if it cannot be fully displayed. A visible label line is necessary
558 // to allow users to get a tooltip with label info on hover.
559
560 let overlapped = false;
561 for (let j = 0; j < displayedLabels.length; j++) {
562 if (labelIntersect(labelItem, displayedLabels[j], null, {touchThreshold: 0.05})) {
563 overlapped = true;
564 break;
565 }
566 }
567
568 // TODO Callback to determine if this overlap should be handled?
569 if (overlapped) {
570 hideEl(label);
571 labelLine && hideEl(labelLine);
572 }
573 else {
574 displayedLabels.push(labelItem);
575 }
576 }
577}
578
579/**

Callers 2

layOutAxisTickLabelFunction · 0.90
layoutMethod · 0.90

Calls 3

labelIntersectFunction · 0.85
hideElFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…