UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

53 lines (51 loc) 2.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPath = createPath; exports.useCreateBarPaths = useCreateBarPaths; var _appendAtKey = require("../../internals/appendAtKey"); const MAX_POINTS_PER_PATH = 1000; function generateBarPath(x, y, width, height, topLeftBorderRadius, topRightBorderRadius, bottomRightBorderRadius, bottomLeftBorderRadius) { const tLBR = Math.min(topLeftBorderRadius, width / 2, height / 2); const tRBR = Math.min(topRightBorderRadius, width / 2, height / 2); const bRBR = Math.min(bottomRightBorderRadius, width / 2, height / 2); const bLBR = Math.min(bottomLeftBorderRadius, width / 2, height / 2); return `M${x + tLBR},${y} h${width - tLBR - tRBR} a${tRBR},${tRBR} 0 0 1 ${tRBR},${tRBR} v${height - tRBR - bRBR} a${bRBR},${bRBR} 0 0 1 -${bRBR},${bRBR} h-${width - bRBR - bLBR} a${bLBR},${bLBR} 0 0 1 -${bLBR},-${bLBR} v-${height - bLBR - tLBR} a${tLBR},${tLBR} 0 0 1 ${tLBR},-${tLBR} Z`; } function createPath(barData, borderRadius) { return generateBarPath(barData.x, barData.y, barData.width, barData.height, barData.borderRadiusSide === 'left' || barData.borderRadiusSide === 'top' ? borderRadius : 0, barData.borderRadiusSide === 'right' || barData.borderRadiusSide === 'top' ? borderRadius : 0, barData.borderRadiusSide === 'right' || barData.borderRadiusSide === 'bottom' ? borderRadius : 0, barData.borderRadiusSide === 'left' || barData.borderRadiusSide === 'bottom' ? borderRadius : 0); } /** * Hook that creates bar paths for a given series data. Used by the batch bar renderer. * @param seriesData * @param borderRadius */ function useCreateBarPaths(seriesData, borderRadius) { const paths = new Map(); const temporaryPaths = new Map(); for (let j = 0; j < seriesData.data.length; j += 1) { const barData = seriesData.data[j]; const pathString = createPath(barData, borderRadius); const tempPath = (0, _appendAtKey.appendAtKey)(temporaryPaths, barData.color, pathString); if (tempPath.length >= MAX_POINTS_PER_PATH) { (0, _appendAtKey.appendAtKey)(paths, barData.color, tempPath.join('')); temporaryPaths.delete(barData.color); } } for (const [fill, tempPath] of temporaryPaths.entries()) { if (tempPath.length > 0) { (0, _appendAtKey.appendAtKey)(paths, fill, tempPath.join('')); } } return paths; }