@patternfly/react-charts
Version:
This library provides a set of React chart components for use with the PatternFly reference implementation.
86 lines • 3.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLabelTextSize = exports.getPieLabelY = exports.getPieLabelX = exports.getBulletLabelY = exports.getBulletLabelX = void 0;
const victory_core_1 = require("victory-core");
const chart_origin_1 = require("./chart-origin");
const ChartStyles_1 = require("../ChartTheme/ChartStyles");
/**
* Returns x coordinate for bullet labels
*
* @private Not intended as public API and subject to change
*/
const getBulletLabelX = ({ chartWidth, dx = 0, labelPosition }) => labelPosition === 'top' && chartWidth ? Math.round(chartWidth / 2) : dx;
exports.getBulletLabelX = getBulletLabelX;
/**
* Returns y coordinate for bullet labels
*
* @private Not intended as public API and subject to change
*/
const getBulletLabelY = ({ chartHeight, dy = 0, labelPosition }) => {
switch (labelPosition) {
case 'bottom':
return chartHeight + ChartStyles_1.ChartCommonStyles.label.margin + dy;
case 'left':
return chartHeight ? Math.round(chartHeight / 2) + dy : dy;
default:
return dy;
}
};
exports.getBulletLabelY = getBulletLabelY;
/**
* Returns x coordinate for pie labels
*
* @private Not intended as public API and subject to change
*/
const getPieLabelX = ({ dx = 0, height, labelPosition, legendPosition, padding, width }) => {
const origin = (0, chart_origin_1.getPieOrigin)({ height, padding, width });
const radius = victory_core_1.Helpers.getRadius({ height, width, padding });
switch (labelPosition) {
case 'bottom':
case 'center':
return origin.x + dx;
case 'right':
switch (legendPosition) {
case 'bottom':
return origin.x + ChartStyles_1.ChartCommonStyles.label.margin + dx + radius;
case 'right':
return origin.x + ChartStyles_1.ChartCommonStyles.label.margin + dx;
default:
return dx;
}
default:
return dx;
}
};
exports.getPieLabelX = getPieLabelX;
/**
* Returns x coordinate for pie labels
*
* @private Not intended as public API and subject to change
*/
const getPieLabelY = ({ dy = 0, height, labelPosition, padding, width }) => {
const origin = (0, chart_origin_1.getPieOrigin)({ height, padding, width });
const radius = victory_core_1.Helpers.getRadius({ height, width, padding });
switch (labelPosition) {
case 'center':
case 'right':
return origin.y + dy;
case 'bottom':
return origin.y + radius + ChartStyles_1.ChartCommonStyles.label.margin * 2 + dy;
default:
return dy;
}
};
exports.getPieLabelY = getPieLabelY;
/**
* Returns an approximate size for the give text
*
* @private Not intended as public API and subject to change
*/
const getLabelTextSize = ({ text, theme }) => {
const style = theme.legend.style.labels;
// The approximateTextSize function returns height and width, but Victory incorrectly typed it as number
return victory_core_1.TextSize.approximateTextSize(text, Object.assign({}, style));
};
exports.getLabelTextSize = getLabelTextSize;
//# sourceMappingURL=chart-label.js.map