source: node_modules/recharts/es6/util/YAxisUtils.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[a762898]1/**
2 * Calculates the width of the Y-axis based on the tick labels and the axis label.
3 * @param params - The parameters object.
4 * @param [params.ticks] - An array-like object of tick elements, each with a `getBoundingClientRect` method.
5 * @param [params.label] - The axis label element, with a `getBoundingClientRect` method.
6 * @param [params.labelGapWithTick=5] - The gap between the label and the tick.
7 * @param [params.tickSize=0] - The length of the tick line.
8 * @param [params.tickMargin=0] - The margin between the tick line and the tick text.
9 * @returns The calculated width of the Y-axis.
10 */
11export var getCalculatedYAxisWidth = _ref => {
12 var {
13 ticks,
14 label,
15 labelGapWithTick = 5,
16 // Default gap between label and tick
17 tickSize = 0,
18 tickMargin = 0
19 } = _ref;
20 // find the max width of the tick labels
21 var maxTickWidth = 0;
22 if (ticks) {
23 Array.from(ticks).forEach(tickNode => {
24 if (tickNode) {
25 var bbox = tickNode.getBoundingClientRect();
26 if (bbox.width > maxTickWidth) {
27 maxTickWidth = bbox.width;
28 }
29 }
30 });
31
32 // calculate width of the axis label
33 var labelWidth = label ? label.getBoundingClientRect().width : 0;
34 var tickWidth = tickSize + tickMargin;
35
36 // calculate the updated width of the y-axis
37 var updatedYAxisWidth = maxTickWidth + tickWidth + labelWidth + (label ? labelGapWithTick : 0);
38 return Math.round(updatedYAxisWidth);
39 }
40 return 0;
41};
Note: See TracBrowser for help on using the repository browser.