* Position a zr element in viewport * Group position is specified by either * {left, top}, {right, bottom} * If all properties exists, right and bottom will be igonred. * * Logic: * 1. Scale (against origin point in parent coord) * 2. Rotate (against ori
(el, positionInfo, containerRect, margin, opt)
| 16921 | */ |
| 16922 | |
| 16923 | function positionElement(el, positionInfo, containerRect, margin, opt) { |
| 16924 | var h = !opt || !opt.hv || opt.hv[0]; |
| 16925 | var v = !opt || !opt.hv || opt.hv[1]; |
| 16926 | var boundingMode = opt && opt.boundingMode || 'all'; |
| 16927 | |
| 16928 | if (!h && !v) { |
| 16929 | return; |
| 16930 | } |
| 16931 | |
| 16932 | var rect; |
| 16933 | |
| 16934 | if (boundingMode === 'raw') { |
| 16935 | rect = el.type === 'group' ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0) : el.getBoundingRect(); |
| 16936 | } else { |
| 16937 | rect = el.getBoundingRect(); |
| 16938 | |
| 16939 | if (el.needLocalTransform()) { |
| 16940 | var transform = el.getLocalTransform(); // Notice: raw rect may be inner object of el, |
| 16941 | // which should not be modified. |
| 16942 | |
| 16943 | rect = rect.clone(); |
| 16944 | rect.applyTransform(transform); |
| 16945 | } |
| 16946 | } // The real width and height can not be specified but calculated by the given el. |
| 16947 | |
| 16948 | |
| 16949 | var layoutRect = getLayoutRect(defaults({ |
| 16950 | width: rect.width, |
| 16951 | height: rect.height |
| 16952 | }, positionInfo), containerRect, margin); // Because 'tranlate' is the last step in transform |
| 16953 | // (see zrender/core/Transformable#getLocalTransform), |
| 16954 | // we can just only modify el.position to get final result. |
| 16955 | |
| 16956 | var dx = h ? layoutRect.x - rect.x : 0; |
| 16957 | var dy = v ? layoutRect.y - rect.y : 0; |
| 16958 | |
| 16959 | if (boundingMode === 'raw') { |
| 16960 | el.x = dx; |
| 16961 | el.y = dy; |
| 16962 | } else { |
| 16963 | el.x += dx; |
| 16964 | el.y += dy; |
| 16965 | } |
| 16966 | |
| 16967 | el.markRedraw(); |
| 16968 | } |
| 16969 | /** |
| 16970 | * @param option Contains some of the properties in HV_NAMES. |
| 16971 | * @param hvIdx 0: horizontal; 1: vertical. |
no test coverage detected
searching dependent graphs…