UNPKG

react-gifted-charts

Version:

ReactJS counterpart of react-native-gifted-charts. An intuitive charting library for Bar, Line, Area, Pie, Donut, Stacked Bar, Population Pyramid and Radar charts in React

144 lines 7.98 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { useEffect, useState } from 'react'; import Cap from '../Components/BarSpecificComponents/cap'; var Animated2DWithGradient = function (props) { var _a, _b; var barBackgroundPattern = props.barBackgroundPattern, patternId = props.patternId, bWidth = props.barWidth, barStyle = props.barStyle, item = props.item, index = props.index, opacity = props.opacity, animationDuration = props.animationDuration, noGradient = props.noGradient, noAnimation = props.noAnimation, containerHeight = props.containerHeight, maxValue = props.maxValue, // barMarginBottom, barInnerComponent = props.barInnerComponent, intactTopLabel = props.intactTopLabel, showValuesAsTopLabel = props.showValuesAsTopLabel, topLabelContainerStyle = props.topLabelContainerStyle, topLabelTextStyle = props.topLabelTextStyle, commonStyleForBar = props.commonStyleForBar, yTranslate = props.yTranslate, yAxisOffset = props.yAxisOffset; var _c = __read(useState(noAnimation ? props.height : 0.4), 2), height = _c[0], setHeight = _c[1]; // const [initialRender, setInitialRender] = useState(noAnimation ? false : true) var _d = __read(useState((_a = item.barWidth) !== null && _a !== void 0 ? _a : bWidth), 2), barWidth = _d[0], setBarWidth = _d[1]; // setting width in state for animation purpose useEffect(function () { if (!noAnimation) { setHeight(props.height); } else { setHeight(props.height); } }, [props.height]); // useEffect(() => { // if (!noAnimation) { // if (initialRender) { // setTimeout(() => layoutAppear(), 20); // } else { // elevate(); // } // } // else { // setHeight(props.height); // setBarWidth(item.barWidth ?? bWidth); // } // }, [props.height, bWidth, item.barWidth]); // const elevate = () => { // LayoutAnimation.configureNext({ // duration: animationDuration, // update: {type: 'linear', property: 'scaleXY'}, // }); // setHeight(props.height); // setBarWidth(item.barWidth ?? bWidth); // }; // const layoutAppear = () => { // LayoutAnimation.configureNext({ // duration: Platform.OS == 'ios' ? animationDuration : 20, // create: {type: 'linear', property: 'opacity'}, // update: {type: 'linear', property: 'scaleXY'}, // }); // setInitialRender(false); // setTimeout(() => elevate(), Platform.OS == 'ios' ? 10 : 100); // }; return (_jsxs(_Fragment, { children: [_jsx("div", { style: (function () { var _a, _b; var style = { position: 'absolute', bottom: 30, width: barWidth, overflow: 'hidden', transition: "height ".concat(animationDuration / 1000, "s"), height: noAnimation ? Math.max(props.minHeight, Math.abs(height)) : height }; if (item.value < 0) { style.transform = "rotate(180deg) translateY(".concat(-props.height - 1, "px)"); } if (noGradient) { style.backgroundColor = props.frontColor.toString(); } else { style.backgroundImage = "linear-gradient(".concat(item.gradientColor || props.gradientColor || 'white', ",").concat(((_a = item.frontColor) === null || _a === void 0 ? void 0 : _a.toString()) || ((_b = props.frontColor) === null || _b === void 0 ? void 0 : _b.toString()) || 'black', ")"); } return style; })(), children: _jsxs("div", { style: (function () { var style = { width: '100%', height: noAnimation ? Math.max(props.minHeight, Math.abs(height)) : height }; if (item.barStyle) { style = __assign(__assign({}, style), item.barStyle); } else { style = __assign(__assign({}, style), barStyle); } return style; })(), children: [_jsx("div", { children: props.cappedBars && item.value ? (_jsx(Cap, { capThicknessFromItem: item.capThickness, capThicknessFromProps: props.capThickness, capColorFromItem: item.capColor, capColorFromProps: props.capColor, capRadiusFromItem: item.capRadius, capRadiusFromProps: props.capRadius })) : null }), (item.barBackgroundPattern || barBackgroundPattern) && (_jsxs("svg", { children: [_jsx("defs", { children: item.barBackgroundPattern ? item.barBackgroundPattern() : barBackgroundPattern === null || barBackgroundPattern === void 0 ? void 0 : barBackgroundPattern() }), _jsx("rect", { stroke: 'none', x: '1', y: '1', width: item.barWidth || props.barWidth || 30, height: noAnimation ? Math.abs(height) : height, fill: "url(#".concat(item.patternId || patternId, ")") })] })), barInnerComponent ? (_jsx("div", { style: { height: '100%', width: '100%' }, children: barInnerComponent(item, index) })) : null] }) }), item.topLabelComponent || showValuesAsTopLabel ? (_jsx("div", { style: (function () { var style = { position: 'absolute', top: -60 - height, height: 30, width: item.barWidth || barWidth || 30, display: 'flex', justifyContent: 'center', alignItems: 'center', opacity: opacity }; if (item.value < 0) { style.transform = "translateY(".concat(height * 2 + 30, "px)"); } if (props.horizontal && !intactTopLabel) { style.transform = "rotate(270deg)"; } if (topLabelContainerStyle) { style = __assign(__assign({}, style), topLabelContainerStyle); } else { style = __assign(__assign({}, style), item.topLabelContainerStyle); } return style; })(), children: showValuesAsTopLabel ? (_jsx("div", { style: topLabelTextStyle, children: item.value + yAxisOffset })) : ((_b = item.topLabelComponent) === null || _b === void 0 ? void 0 : _b.call(item)) })) : null] })); }; export default Animated2DWithGradient; //# sourceMappingURL=Animated2DWithGradient.js.map