rumble-charts
Version:
Truly declarative React charts components
35 lines (32 loc) • 1.79 kB
JavaScript
import { __rest } from './external/tslib/tslib.es6.js';
import React, { useMemo } from 'react';
import './helpers/colorFunc.js';
import 'd3-shape';
import 'd3-ease';
import { getCoords } from './helpers/getCoords.js';
import { normalizeNumber } from './helpers/normalizeNumber.js';
import { proxyChildren } from './helpers/proxyChildren.js';
/**
* 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 = __rest(_a, ["width", "height", "position", "layerWidth", "layerHeight", "className", "scaleX", "scaleY", "style"]);
var _width = useMemo(function () {
return normalizeNumber(width, layerWidth);
}, [width, props.layerWidth]);
var _height = useMemo(function () {
return normalizeNumber(height, layerHeight);
}, [height, props.layerHeight]);
var _e = useMemo(function () {
return getCoords(position, layerWidth, layerHeight, _width, _height);
}, [position, layerWidth, layerHeight, _width, _height]), x = _e.x, y = _e.y;
var children = proxyChildren(props.children, props, {
layerWidth: _width,
layerHeight: _height,
scaleX: scaleX,
scaleY: scaleY
});
return React.createElement("g", { className: className, transform: "translate(".concat(x, " ").concat(y, ")"), style: style }, children);
}
export { Layer };