UNPKG

@patternfly/react-charts

Version:

This library provides a set of React chart components for use with the PatternFly reference implementation.

130 lines 4.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getQualitativeRangeBarWidth = exports.getPrimarySegmentedMeasureWidth = exports.getPrimaryDotMeasureSize = exports.getComparativeMeasureWarningWidth = exports.getComparativeMeasureWidth = exports.getComparativeMeasureErrorWidth = void 0; const tslib_1 = require("tslib"); const ChartStyles_1 = require("../../ChartTheme/ChartStyles"); const chart_theme_types_1 = require("../../ChartUtils/chart-theme-types"); /** * Scale dimensions * * @private Not intended as public API and subject to change */ const scaleDimensions = ({ defaultSize, height, horizontal = true, scale = 1, value, width }) => { if (horizontal && height > defaultSize) { return value + (height - defaultSize) * scale; } else if (horizontal) { return value - (defaultSize - height) * scale; } else if (width > defaultSize) { return value + (width - defaultSize) * scale; } return value - (defaultSize - width) * scale; }; /** * Scale bar width per the given size properties * * @private Not intended as public API and subject to change */ const scaleBarWidth = (props) => Math.max(scaleDimensions(props), 0); /** * Scale size per the given size properties * * @private Not intended as public API and subject to change */ const scaleSize = (_a) => { var { value } = _a, rest = tslib_1.__rest(_a, ["value"]); return Math.round(scaleDimensions(Object.assign({ scale: 1 / value, value }, rest))); }; /** * Scale size per the given size properties * * @private Not intended as public API and subject to change */ const getComparativeMeasureErrorWidth = ({ height, horizontal, themeColor, width, // destructure last theme = (0, chart_theme_types_1.getBulletComparativeErrorMeasureTheme)(themeColor) }) => scaleBarWidth({ defaultSize: theme.bar.height, height, horizontal, value: ChartStyles_1.ChartBulletStyles.comparativeMeasureErrorWidth, width }); exports.getComparativeMeasureErrorWidth = getComparativeMeasureErrorWidth; /** * Returns comparative measure width * * @private Not intended as public API and subject to change */ const getComparativeMeasureWidth = ({ height, horizontal, themeColor, width, // destructure last theme = (0, chart_theme_types_1.getBulletComparativeMeasureTheme)(themeColor) }) => scaleBarWidth({ defaultSize: theme.bar.height, height, horizontal, value: ChartStyles_1.ChartBulletStyles.comparativeMeasureWidth, width }); exports.getComparativeMeasureWidth = getComparativeMeasureWidth; /** * Returns comparative measure warning width * * @private Not intended as public API and subject to change */ const getComparativeMeasureWarningWidth = ({ height, horizontal, themeColor, width, // destructure last theme = (0, chart_theme_types_1.getBulletComparativeWarningMeasureTheme)(themeColor) }) => scaleBarWidth({ defaultSize: theme.bar.height, height, horizontal, value: ChartStyles_1.ChartBulletStyles.comparativeMeasureWarningWidth, width }); exports.getComparativeMeasureWarningWidth = getComparativeMeasureWarningWidth; /** * Returns primary dot measure size * * @private Not intended as public API and subject to change */ const getPrimaryDotMeasureSize = ({ height, horizontal, themeColor, width, // destructure last theme = (0, chart_theme_types_1.getBulletPrimaryDotMeasureTheme)(themeColor) }) => scaleSize({ defaultSize: theme.group.height, height, horizontal, value: ChartStyles_1.ChartBulletStyles.primaryDotMeasureSize, width }); exports.getPrimaryDotMeasureSize = getPrimaryDotMeasureSize; /** * Returns primary segmented measure width * * @private Not intended as public API and subject to change */ const getPrimarySegmentedMeasureWidth = ({ height, horizontal, themeColor, width, // destructure last theme = (0, chart_theme_types_1.getBulletPrimarySegmentedMeasureTheme)(themeColor) }) => scaleBarWidth({ defaultSize: theme.group.height, height, horizontal, scale: 0.3, value: ChartStyles_1.ChartBulletStyles.primarySegmentedMeasureWidth, width }); exports.getPrimarySegmentedMeasureWidth = getPrimarySegmentedMeasureWidth; /** * Returns qualitative range bar width * * @private Not intended as public API and subject to change */ const getQualitativeRangeBarWidth = ({ height, horizontal, themeColor, width, // destructure last theme = (0, chart_theme_types_1.getBulletQualitativeRangeTheme)(themeColor) }) => scaleBarWidth({ defaultSize: theme.group.height, height, horizontal, value: ChartStyles_1.ChartBulletStyles.qualitativeRangeWidth, width }); exports.getQualitativeRangeBarWidth = getQualitativeRangeBarWidth; //# sourceMappingURL=chart-bullet-size.js.map