victory-native
Version:
A charting library for React Native with a focus on performance and customization.
76 lines (75 loc) • 3.56 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useHorizontalBarGroupPaths = void 0;
const React = __importStar(require("react"));
const react_native_skia_1 = require("@shopify/react-native-skia");
const createRoundedRectPath_1 = require("../../utils/createRoundedRectPath");
const CartesianChartContext_1 = require("../contexts/CartesianChartContext");
const getBarGroupDimensionsForAxis_1 = require("../utils/getBarGroupDimensionsForAxis");
const getHorizontalBarGroupRect_1 = require("../utils/getHorizontalBarGroupRect");
const useHorizontalBarGroupPaths = (points, chartBounds, betweenGroupPadding = 0, withinGroupPadding = 0, roundedCorners, customBarWidth, barCount) => {
var _a;
const numGroups = ((_a = points[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
const { xScale } = (0, CartesianChartContext_1.useCartesianChartContext)();
const { barWidth, groupWidth, gapWidth } = (0, getBarGroupDimensionsForAxis_1.getBarGroupDimensionsForAxis)({
axisStart: chartBounds.top,
axisEnd: chartBounds.bottom,
betweenGroupPadding,
withinGroupPadding,
groupCount: numGroups,
barsPerGroup: points.length,
customBarWidth,
barCount,
});
const paths = React.useMemo(() => {
const baselineX = xScale(0);
return points.map((pointSet, i) => {
const p = react_native_skia_1.Skia.Path.Make();
pointSet.forEach((point) => {
const rect = (0, getHorizontalBarGroupRect_1.getHorizontalBarGroupRect)({
point,
baselineX,
barWidth,
groupWidth,
gapWidth,
barIndex: i,
});
if (!rect)
return;
if (roundedCorners) {
const nonUniformRoundedRect = (0, createRoundedRectPath_1.createRoundedRectPath)(rect.x, rect.y, rect.width, rect.height, roundedCorners, Number(point.yValue), "horizontal");
p.addRRect(nonUniformRoundedRect);
}
else {
p.addRect(react_native_skia_1.Skia.XYWHRect(rect.x, rect.y, rect.width, rect.height));
}
});
return p;
});
}, [barWidth, gapWidth, groupWidth, points, roundedCorners, xScale]);
return { barWidth, groupWidth, gapWidth, paths };
};
exports.useHorizontalBarGroupPaths = useHorizontalBarGroupPaths;