(
// `out` is a center in `dataRect` space.
out: number[],
viewInner: ViewInner,
centerOption: RoamOptionMixin['center']
// @return Whether a valid center is obtained.
)
| 759 | } |
| 760 | |
| 761 | function parseCenterOption( |
| 762 | // `out` is a center in `dataRect` space. |
| 763 | out: number[], |
| 764 | viewInner: ViewInner, |
| 765 | centerOption: RoamOptionMixin['center'] |
| 766 | // @return Whether a valid center is obtained. |
| 767 | ): boolean { |
| 768 | if (__DEV__) { |
| 769 | assert(viewCoordSysIsInputReady(viewInner)); |
| 770 | } |
| 771 | const dataRect = viewInner.dataRect; |
| 772 | if (!centerOption) { |
| 773 | return false; |
| 774 | } |
| 775 | // #16904 introduced percentage string here, such as '33%'. But it was based on canvas |
| 776 | // width/height, which is not reasonable - the unit may incorrect, and it is unpredictable if |
| 777 | // the `ViewInner['dataRect']` is not calculated based on the current canvas rect. Therefore the percentage |
| 778 | // value is changed to based on `ViewInner['dataRect'].width/height` since v6. Under this definition, users |
| 779 | // can use '0%' to map the top-left of `ViewInner['dataRect']` to the center of `ViewInner['viewRect']`. |
| 780 | const lgCt = viewInner.lgCt; |
| 781 | if (lgCt) { |
| 782 | vectorSet( |
| 783 | out, |
| 784 | parsePercent(centerOption[0], lgCt.w), |
| 785 | parsePercent(centerOption[1], lgCt.h) |
| 786 | ); |
| 787 | } |
| 788 | else if (dataRect) { |
| 789 | vectorSet( |
| 790 | out, |
| 791 | parsePercent(centerOption[0], dataRect.width, dataRect.x), |
| 792 | parsePercent(centerOption[1], dataRect.height, dataRect.y) |
| 793 | ); |
| 794 | } |
| 795 | return true; |
| 796 | } |
| 797 | |
| 798 | /** |
| 799 | * An inverse operation to `parseCenterOption`. |
no test coverage detected
searching dependent graphs…