| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.getCalculatedYAxisWidth = void 0;
|
|---|
| 7 | /**
|
|---|
| 8 | * Calculates the width of the Y-axis based on the tick labels and the axis label.
|
|---|
| 9 | * @param params - The parameters object.
|
|---|
| 10 | * @param [params.ticks] - An array-like object of tick elements, each with a `getBoundingClientRect` method.
|
|---|
| 11 | * @param [params.label] - The axis label element, with a `getBoundingClientRect` method.
|
|---|
| 12 | * @param [params.labelGapWithTick=5] - The gap between the label and the tick.
|
|---|
| 13 | * @param [params.tickSize=0] - The length of the tick line.
|
|---|
| 14 | * @param [params.tickMargin=0] - The margin between the tick line and the tick text.
|
|---|
| 15 | * @returns The calculated width of the Y-axis.
|
|---|
| 16 | */
|
|---|
| 17 | var getCalculatedYAxisWidth = _ref => {
|
|---|
| 18 | var {
|
|---|
| 19 | ticks,
|
|---|
| 20 | label,
|
|---|
| 21 | labelGapWithTick = 5,
|
|---|
| 22 | // Default gap between label and tick
|
|---|
| 23 | tickSize = 0,
|
|---|
| 24 | tickMargin = 0
|
|---|
| 25 | } = _ref;
|
|---|
| 26 | // find the max width of the tick labels
|
|---|
| 27 | var maxTickWidth = 0;
|
|---|
| 28 | if (ticks) {
|
|---|
| 29 | Array.from(ticks).forEach(tickNode => {
|
|---|
| 30 | if (tickNode) {
|
|---|
| 31 | var bbox = tickNode.getBoundingClientRect();
|
|---|
| 32 | if (bbox.width > maxTickWidth) {
|
|---|
| 33 | maxTickWidth = bbox.width;
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | });
|
|---|
| 37 |
|
|---|
| 38 | // calculate width of the axis label
|
|---|
| 39 | var labelWidth = label ? label.getBoundingClientRect().width : 0;
|
|---|
| 40 | var tickWidth = tickSize + tickMargin;
|
|---|
| 41 |
|
|---|
| 42 | // calculate the updated width of the y-axis
|
|---|
| 43 | var updatedYAxisWidth = maxTickWidth + tickWidth + labelWidth + (label ? labelGapWithTick : 0);
|
|---|
| 44 | return Math.round(updatedYAxisWidth);
|
|---|
| 45 | }
|
|---|
| 46 | return 0;
|
|---|
| 47 | };
|
|---|
| 48 | exports.getCalculatedYAxisWidth = getCalculatedYAxisWidth; |
|---|