rumble-charts
Version:
Truly declarative React charts components
43 lines (36 loc) • 2.15 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var tslib_es6 = require('./external/tslib/tslib.es6.js');
var React = require('react');
require('./helpers/colorFunc.js');
require('d3-shape');
require('d3-ease');
var getCoords = require('./helpers/getCoords.js');
var normalizeNumber = require('./helpers/normalizeNumber.js');
var proxyChildren = require('./helpers/proxyChildren.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
/**
* Creates a new layer using specific `width` and `height` at specific `position`. It's useful when
* you have two or more graphics on the same chart. Or in case you to have a margins.
*/
function Layer(_a) {
var _b = _a.width, width = _b === void 0 ? '100%' : _b, _c = _a.height, height = _c === void 0 ? '100%' : _c, _d = _a.position, position = _d === void 0 ? 'middle center' : _d, layerWidth = _a.layerWidth, layerHeight = _a.layerHeight, className = _a.className, scaleX = _a.scaleX, scaleY = _a.scaleY, style = _a.style, props = tslib_es6.__rest(_a, ["width", "height", "position", "layerWidth", "layerHeight", "className", "scaleX", "scaleY", "style"]);
var _width = React.useMemo(function () {
return normalizeNumber.normalizeNumber(width, layerWidth);
}, [width, props.layerWidth]);
var _height = React.useMemo(function () {
return normalizeNumber.normalizeNumber(height, layerHeight);
}, [height, props.layerHeight]);
var _e = React.useMemo(function () {
return getCoords.getCoords(position, layerWidth, layerHeight, _width, _height);
}, [position, layerWidth, layerHeight, _width, _height]), x = _e.x, y = _e.y;
var children = proxyChildren.proxyChildren(props.children, props, {
layerWidth: _width,
layerHeight: _height,
scaleX: scaleX,
scaleY: scaleY
});
return React__default["default"].createElement("g", { className: className, transform: "translate(".concat(x, " ").concat(y, ")"), style: style }, children);
}
exports.Layer = Layer;