@patternfly/react-charts
Version:
This library provides a set of React chart components for use with the PatternFly reference implementation.
121 lines • 4.03 kB
JavaScript
import { __rest } from "tslib";
import { ChartBulletStyles } from '../../ChartTheme/ChartStyles';
import { getBulletComparativeErrorMeasureTheme, getBulletComparativeMeasureTheme, getBulletComparativeWarningMeasureTheme, getBulletPrimaryDotMeasureTheme, getBulletPrimarySegmentedMeasureTheme, getBulletQualitativeRangeTheme } from '../../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 = __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
*/
export const getComparativeMeasureErrorWidth = ({ height, horizontal, themeColor, width,
// destructure last
theme = getBulletComparativeErrorMeasureTheme(themeColor) }) => scaleBarWidth({
defaultSize: theme.bar.height,
height,
horizontal,
value: ChartBulletStyles.comparativeMeasureErrorWidth,
width
});
/**
* Returns comparative measure width
*
* @private Not intended as public API and subject to change
*/
export const getComparativeMeasureWidth = ({ height, horizontal, themeColor, width,
// destructure last
theme = getBulletComparativeMeasureTheme(themeColor) }) => scaleBarWidth({
defaultSize: theme.bar.height,
height,
horizontal,
value: ChartBulletStyles.comparativeMeasureWidth,
width
});
/**
* Returns comparative measure warning width
*
* @private Not intended as public API and subject to change
*/
export const getComparativeMeasureWarningWidth = ({ height, horizontal, themeColor, width,
// destructure last
theme = getBulletComparativeWarningMeasureTheme(themeColor) }) => scaleBarWidth({
defaultSize: theme.bar.height,
height,
horizontal,
value: ChartBulletStyles.comparativeMeasureWarningWidth,
width
});
/**
* Returns primary dot measure size
*
* @private Not intended as public API and subject to change
*/
export const getPrimaryDotMeasureSize = ({ height, horizontal, themeColor, width,
// destructure last
theme = getBulletPrimaryDotMeasureTheme(themeColor) }) => scaleSize({
defaultSize: theme.group.height,
height,
horizontal,
value: ChartBulletStyles.primaryDotMeasureSize,
width
});
/**
* Returns primary segmented measure width
*
* @private Not intended as public API and subject to change
*/
export const getPrimarySegmentedMeasureWidth = ({ height, horizontal, themeColor, width,
// destructure last
theme = getBulletPrimarySegmentedMeasureTheme(themeColor) }) => scaleBarWidth({
defaultSize: theme.group.height,
height,
horizontal,
scale: 0.3,
value: ChartBulletStyles.primarySegmentedMeasureWidth,
width
});
/**
* Returns qualitative range bar width
*
* @private Not intended as public API and subject to change
*/
export const getQualitativeRangeBarWidth = ({ height, horizontal, themeColor, width,
// destructure last
theme = getBulletQualitativeRangeTheme(themeColor) }) => scaleBarWidth({
defaultSize: theme.group.height,
height,
horizontal,
value: ChartBulletStyles.qualitativeRangeWidth,
width
});
//# sourceMappingURL=chart-bullet-size.js.map