@antv/g2
Version:
the Grammar of Graphics in Javascript
48 lines • 2.03 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBBoxSize = exports.getContainerSize = void 0;
const parseInt10 = (d) => (d ? parseInt(d) : 0);
/**
* @description Get the element's bounding size.
* @param container dom element.
* @returns the element width and height
*/
function getContainerSize(container) {
// size = width/height - padding.
const style = getComputedStyle(container);
const wrapperWidth = container.clientWidth || parseInt10(style.width);
const wrapperHeight = container.clientHeight || parseInt10(style.height);
const widthPadding = parseInt10(style.paddingLeft) + parseInt10(style.paddingRight);
const heightPadding = parseInt10(style.paddingTop) + parseInt10(style.paddingBottom);
return {
width: wrapperWidth - widthPadding,
height: wrapperHeight - heightPadding,
};
}
exports.getContainerSize = getContainerSize;
/**
* @description Calculate the real canvas size by view options.
*/
function getBBoxSize(options) {
const { height, width, padding = 0, paddingLeft = padding, paddingRight = padding, paddingTop = padding, paddingBottom = padding, margin = 0, marginLeft = margin, marginRight = margin, marginTop = margin, marginBottom = margin, inset = 0, insetLeft = inset, insetRight = inset, insetTop = inset, insetBottom = inset, } = options;
// @todo Add this padding to theme.
// 30 is default size for padding, which defined in runtime.
const maybeAuto = (padding) => (padding === 'auto' ? 20 : padding);
const finalWidth = width -
maybeAuto(paddingLeft) -
maybeAuto(paddingRight) -
marginLeft -
marginRight -
insetLeft -
insetRight;
const finalHeight = height -
maybeAuto(paddingTop) -
maybeAuto(paddingBottom) -
marginTop -
marginBottom -
insetTop -
insetBottom;
return { width: finalWidth, height: finalHeight };
}
exports.getBBoxSize = getBBoxSize;
//# sourceMappingURL=size.js.map
;