src/util/graphic.js
function centerGraphic(rect, boundingRect) {
    // Set rect to center, keep width / height ratio.
    var aspect = boundingRect.width / boundingRect.height;
    var width = rect.height * aspect;
    var height;
    if (width <= rect.width) {
        height = rect.height;
    }
    else {
        width = rect.width;
        height = width / aspect;
    }
    var cx = rect.x + rect.width / 2;
    var cy = rect.y + rect.height / 2;

    return {
        x: cx - width / 2,
        y: cy - height / 2,
        width: width,
        height: height
    };
}
function centerGraphic(rect, boundingRect) {
    // Set rect to center, keep width / height ratio.
    var aspect = boundingRect.width / boundingRect.height;
    var width = rect.height * aspect;
    var height;
    if (width <= rect.width) {
        height = rect.height;
    }
    else {
        width = rect.width;
        height = width / aspect;
    }
    var cx = rect.x + rect.width / 2;
    var cy = rect.y + rect.height / 2;

    return {
        x: cx - width / 2,
        y: cy - height / 2,
        width: width,
        height: height
    };
}
function centerGraphic ( rect , boundingRect ) { // Set rect to center, keep width / height ratio. var aspect = boundingRect . width / boundingRect . height ; var width = rect . height * aspect ; var height ; if ( width <= rect . width ) { height = rect . height ; } else { width = rect . width ; height = width / aspect ; } var cx = rect . x + rect . width / 2 ; var cy = rect . y + rect . height / 2 ; return { x : cx - width / 2 , y : cy - height / 2 , width : width , height : height } ; }
Get position of centered element in bounding box.

@param  {Object} rect         element local bounding box
@param  {Object} boundingRect constraint bounding box
@return {Object} element position containing x, y, width, and height
Get position of centered element in bounding box .