@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular
45 lines • 2 kB
JavaScript
export function calculateViewDimensions(_a) {
var width = _a.width, height = _a.height, margins = _a.margins, _b = _a.showXAxis, showXAxis = _b === void 0 ? false : _b, _c = _a.showYAxis, showYAxis = _c === void 0 ? false : _c, _d = _a.xAxisHeight, xAxisHeight = _d === void 0 ? 0 : _d, _e = _a.yAxisWidth, yAxisWidth = _e === void 0 ? 0 : _e, _f = _a.showXLabel, showXLabel = _f === void 0 ? false : _f, _g = _a.showYLabel, showYLabel = _g === void 0 ? false : _g, _h = _a.showLegend, showLegend = _h === void 0 ? false : _h, _j = _a.legendType, legendType = _j === void 0 ? 'ordinal' : _j, _k = _a.legendPosition, legendPosition = _k === void 0 ? 'right' : _k, _l = _a.columns, columns = _l === void 0 ? 12 : _l;
var xOffset = margins[3];
var chartWidth = width;
var chartHeight = height - margins[0] - margins[2];
if (showLegend && legendPosition === 'right') {
if (legendType === 'ordinal') {
columns -= 2;
}
else {
columns -= 1;
}
}
chartWidth = chartWidth * columns / 12;
chartWidth = chartWidth - margins[1] - margins[3];
if (showXAxis) {
chartHeight -= 5;
chartHeight -= xAxisHeight;
if (showXLabel) {
// text height + spacing between axis label and tick labels
var offset = 25 + 5;
chartHeight -= offset;
}
}
if (showYAxis) {
chartWidth -= 5;
chartWidth -= yAxisWidth;
xOffset += yAxisWidth;
xOffset += 10;
if (showYLabel) {
// text height + spacing between axis label and tick labels
var offset = 25 + 5;
chartWidth -= offset;
xOffset += offset;
}
}
chartWidth = Math.max(0, chartWidth);
chartHeight = Math.max(0, chartHeight);
return {
width: Math.floor(chartWidth),
height: Math.floor(chartHeight),
xOffset: Math.floor(xOffset)
};
}
//# sourceMappingURL=view-dimensions.helper.js.map