MCPcopy
hub / github.com/apache/echarts / getLayoutRect

Function getLayoutRect

src/util/layout.ts:263–390  ·  view source on GitHub ↗
(
    positionInfo: BoxLayoutOptionMixin & {
        // PENDING:
        //  when width can not be decided but height can be decided and aspect is near Infinity,
        //  or when height can not be decided but width can be decided and aspect is near 0,
        //  the result width or height is near Inifity. It's logically correct, therefore
        //  currently we do not handle it, until bad cases arise.
        //
        // aspect is width / height. But this method does not preserve aspect ratio if
        // both width and height can be decided by the given left/top/bottom/right/width/height.
        // To always preserve aspect ratio, uses `applyPreserveAspect` to process the result.
        aspect?: number
    },
    containerRect: GetLayoutRectInputContainerRect,
    // This is the space from the `containerRect` to the returned bounding rect.
    // Commonly used in option `legend.padding`, `timeline.padding`, `title.padding`,
    //  `visualMap.padding`, ...
    // [NOTICE]:
    //  It's named `margin`, because it's the space that outside the bounding rect. But from
    //  the perspective of the the caller, it's commonly used as the `padding` of a component,
    //  because conventionally background color covers this space.
    // [BEHAVIOR]:
    //  - If width/height is specified, `margin` does not effect them.
    //  - Otherwise, they are calculated based on the rect that `containerRect` shrinked by `margin`.
    //  - left/right/top/bottom are based on the rect that `containerRect` shrinked by `margin`.
    margin?: number | number[]
)

Source from the content-addressed store, hash-verified

261 * Parse position info.
262 */
263export function getLayoutRect(
264 positionInfo: BoxLayoutOptionMixin & {
265 // PENDING:
266 // when width can not be decided but height can be decided and aspect is near Infinity,
267 // or when height can not be decided but width can be decided and aspect is near 0,
268 // the result width or height is near Inifity. It's logically correct, therefore
269 // currently we do not handle it, until bad cases arise.
270 //
271 // aspect is width / height. But this method does not preserve aspect ratio if
272 // both width and height can be decided by the given left/top/bottom/right/width/height.
273 // To always preserve aspect ratio, uses `applyPreserveAspect` to process the result.
274 aspect?: number
275 },
276 containerRect: GetLayoutRectInputContainerRect,
277 // This is the space from the `containerRect` to the returned bounding rect.
278 // Commonly used in option `legend.padding`, `timeline.padding`, `title.padding`,
279 // `visualMap.padding`, ...
280 // [NOTICE]:
281 // It's named `margin`, because it's the space that outside the bounding rect. But from
282 // the perspective of the the caller, it's commonly used as the `padding` of a component,
283 // because conventionally background color covers this space.
284 // [BEHAVIOR]:
285 // - If width/height is specified, `margin` does not effect them.
286 // - Otherwise, they are calculated based on the rect that `containerRect` shrinked by `margin`.
287 // - left/right/top/bottom are based on the rect that `containerRect` shrinked by `margin`.
288 margin?: number | number[]
289): LayoutRect {
290 margin = formatUtil.normalizeCssArray(margin || 0);
291
292 const containerWidth = containerRect.width;
293 const containerHeight = containerRect.height;
294
295 let left = parsePercent(positionInfo.left, containerWidth);
296 let top = parsePercent(positionInfo.top, containerHeight);
297 const right = parsePercent(positionInfo.right, containerWidth);
298 const bottom = parsePercent(positionInfo.bottom, containerHeight);
299 let width = parsePercent(positionInfo.width, containerWidth);
300 let height = parsePercent(positionInfo.height, containerHeight);
301
302 const verticalMargin = margin[2] + margin[0];
303 const horizontalMargin = margin[1] + margin[3];
304 const aspect = positionInfo.aspect;
305
306 // If width is not specified, calculate width from left and right
307 if (isNaN(width)) {
308 width = containerWidth - right - horizontalMargin - left;
309 }
310 if (isNaN(height)) {
311 height = containerHeight - bottom - verticalMargin - top;
312 }
313
314 if (aspect != null) {
315 // If width and height are not given
316 // 1. Graph should not exceeds the container
317 // 2. Aspect must be keeped
318 // 3. Graph should take the space as more as possible
319 // FIXME
320 // Margin is not considered, because there is no case that both

Callers 15

sankeyLayoutFunction · 0.90
getViewRectFunction · 0.90
commonLayoutFunction · 0.90
_updatePositionMethod · 0.90
getItemAlignFunction · 0.90
renderMethod · 0.90
_dealRenderContentMethod · 0.90
renderMethod · 0.90
renderMethod · 0.90
resizeMethod · 0.90
prepareOuterBoundsFunction · 0.90
_resizeMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…