* 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
(rect, boundingRect)
| 16995 | * @return {Object} element position containing x, y, width, and height |
| 16996 | */ |
| 16997 | function centerGraphic(rect, boundingRect) { |
| 16998 | // Set rect to center, keep width / height ratio. |
| 16999 | var aspect = boundingRect.width / boundingRect.height; |
| 17000 | var width = rect.height * aspect; |
| 17001 | var height; |
| 17002 | if (width <= rect.width) { |
| 17003 | height = rect.height; |
| 17004 | } |
| 17005 | else { |
| 17006 | width = rect.width; |
| 17007 | height = width / aspect; |
| 17008 | } |
| 17009 | var cx = rect.x + rect.width / 2; |
| 17010 | var cy = rect.y + rect.height / 2; |
| 17011 | |
| 17012 | return { |
| 17013 | x: cx - width / 2, |
| 17014 | y: cy - height / 2, |
| 17015 | width: width, |
| 17016 | height: height |
| 17017 | }; |
| 17018 | } |
| 17019 | |
| 17020 | var mergePath = mergePath$1; |
| 17021 |