(
el: Element,
positionInfo: BoxLayoutOptionMixin,
containerRect: GetLayoutRectInputContainerRect,
margin?: number[] | number,
opt?: {
hv: [1 | 0 | boolean, 1 | 0 | boolean],
boundingMode: 'all' | 'raw'
},
out?: { x?: number, y?: number }
)
| 566 | * In this mode positionInfo.width/height can only be number. |
| 567 | */ |
| 568 | export function positionElement( |
| 569 | el: Element, |
| 570 | positionInfo: BoxLayoutOptionMixin, |
| 571 | containerRect: GetLayoutRectInputContainerRect, |
| 572 | margin?: number[] | number, |
| 573 | opt?: { |
| 574 | hv: [1 | 0 | boolean, 1 | 0 | boolean], |
| 575 | boundingMode: 'all' | 'raw' |
| 576 | }, |
| 577 | out?: { x?: number, y?: number } |
| 578 | ): boolean { |
| 579 | const h = !opt || !opt.hv || opt.hv[0]; |
| 580 | const v = !opt || !opt.hv || opt.hv[1]; |
| 581 | const boundingMode = opt && opt.boundingMode || 'all'; |
| 582 | out = out || el; |
| 583 | |
| 584 | out.x = el.x; |
| 585 | out.y = el.y; |
| 586 | |
| 587 | if (!h && !v) { |
| 588 | return false; |
| 589 | } |
| 590 | |
| 591 | let rect; |
| 592 | if (boundingMode === 'raw') { |
| 593 | rect = el.type === 'group' |
| 594 | ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0) |
| 595 | : el.getBoundingRect(); |
| 596 | } |
| 597 | else { |
| 598 | rect = el.getBoundingRect(); |
| 599 | if (el.needLocalTransform()) { |
| 600 | const transform = el.getLocalTransform(); |
| 601 | // Notice: raw rect may be inner object of el, |
| 602 | // which should not be modified. |
| 603 | rect = rect.clone(); |
| 604 | rect.applyTransform(transform); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | // The real width and height can not be specified but calculated by the given el. |
| 609 | const layoutRect = getLayoutRect( |
| 610 | zrUtil.defaults( |
| 611 | {width: rect.width, height: rect.height}, |
| 612 | positionInfo |
| 613 | ), |
| 614 | containerRect, |
| 615 | margin |
| 616 | ); |
| 617 | |
| 618 | // Because 'tranlate' is the last step in transform |
| 619 | // (see zrender/core/Transformable#getLocalTransform), |
| 620 | // we can just only modify el.position to get final result. |
| 621 | const dx = h ? layoutRect.x - rect.x : 0; |
| 622 | const dy = v ? layoutRect.y - rect.y : 0; |
| 623 | |
| 624 | if (boundingMode === 'raw') { |
| 625 | out.x = dx; |
no test coverage detected
searching dependent graphs…