1e9cd2f5c6
closes https://github.com/twentyhq/core-team-issues/issues/2055 https://github.com/user-attachments/assets/7a19066f-e891-4dfa-92ee-b85690765e60
29 lines
851 B
TypeScript
29 lines
851 B
TypeScript
import { COMMON_CHART_CONSTANTS } from '@/page-layout/widgets/graph/constants/CommonChartConstants';
|
|
import { estimateLineHeight } from '@/page-layout/widgets/graph/utils/estimateLineHeight';
|
|
|
|
export const estimateRotatedHeight = (
|
|
maxLength: number,
|
|
fontSize: number,
|
|
rotationDegrees: number,
|
|
) => {
|
|
if (rotationDegrees === 0 || maxLength <= 0) {
|
|
return 0;
|
|
}
|
|
|
|
const labelWidth =
|
|
maxLength *
|
|
fontSize *
|
|
COMMON_CHART_CONSTANTS.ROTATED_TICK_LABEL_WIDTH_ESTIMATE_RATIO;
|
|
if (labelWidth <= 0) {
|
|
return 0;
|
|
}
|
|
|
|
const labelHeight = estimateLineHeight(fontSize);
|
|
const rotationRadians = (Math.abs(rotationDegrees) * Math.PI) / 180;
|
|
const projectedHeight =
|
|
Math.abs(labelWidth * Math.sin(rotationRadians)) +
|
|
Math.abs(labelHeight * Math.cos(rotationRadians));
|
|
|
|
return Math.max(labelHeight, projectedHeight);
|
|
};
|