deno.land / x / billboardjs@3.6.0 / ChartInternal / internals / size.axis.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/** * Copyright (c) 2017 ~ present NAVER Corp. * billboard.js project is licensed under the MIT license */import type {AxisType} from "../../../types/types";
export default { /** * Get Axis size according its position * @param {string} id Axis id value - x, y or y2 * @returns {number} size Axis size value * @private */ getAxisSize(id: AxisType): number { const $$ = this; const isRotated = $$.config.axis_rotated;
return (isRotated && id === "x") || (!isRotated && /y2?/.test(id)) ? $$.getAxisWidthByAxisId(id, true) : $$.getHorizontalAxisHeight(id); },
getAxisWidthByAxisId(id: AxisType, withoutRecompute?: boolean): number { const $$ = this;
if ($$.axis) { const position = $$.axis?.getLabelPositionById(id); const width = $$.axis.getMaxTickWidth(id, withoutRecompute); const gap = width === 0 ? 0.5 : 0;
return width + ( position.isInner ? (20 + gap) : 40 ); } else { return 40; } },
getHorizontalAxisHeight(id: AxisType): number { const $$ = this; const {config, state} = $$; const {current, rotatedPadding, isLegendRight, isLegendInset} = state; const isRotated = config.axis_rotated; let h = 30;
if (id === "x" && !config.axis_x_show) { return 8; }
if (id === "x" && config.axis_x_height) { return config.axis_x_height; }
if (id === "y" && !config.axis_y_show) { return config.legend_show && !isLegendRight && !isLegendInset ? 10 : 1; }
if (id === "y2" && !config.axis_y2_show) { return rotatedPadding.top; }
const rotate = $$.getAxisTickRotate(id);
// Calculate x/y axis height when tick rotated if ( ((id === "x" && !isRotated) || (/y2?/.test(id) && isRotated)) && rotate ) { h = 30 + $$.axis.getMaxTickWidth(id) * Math.cos(Math.PI * (90 - Math.abs(rotate)) / 180);
if (!config.axis_x_tick_multiline && current.height) { if (h > current.height / 2) { h = current.height / 2; } } }
return h + ($$.axis.getLabelPositionById(id).isInner ? 0 : 10) + (id === "y2" && !isRotated ? -10 : 0); },
getEventRectWidth(): number { return Math.max(0, this.axis.x.tickInterval()); },
/** * Get axis tick test rotate value * @param {string} id Axis id * @returns {number} rotate value * @private */ getAxisTickRotate(id: AxisType): number { const $$ = this; const {axis, config, state, $el} = $$; let rotate = config[`axis_${id}_tick_rotate`];
if (id === "x") { const allowedXAxisTypes = axis.isCategorized() || axis.isTimeSeries();
if (config.axis_x_tick_fit && allowedXAxisTypes) { const xTickCount = config.axis_x_tick_count; const currentXTicksLength = state.current.maxTickWidths.x.ticks.length; let tickCount = 0;
if (xTickCount) { tickCount = xTickCount > currentXTicksLength ? currentXTicksLength : xTickCount; } else if (currentXTicksLength) { tickCount = currentXTicksLength; }
if (tickCount !== state.axis.x.tickCount) { const {targets} = $$.data;
state.axis.x.padding = $$.getXDomainPadding([ $$.getXDomainMinMax(targets, "min"), $$.getXDomainMinMax(targets, "max") ], tickCount); }
state.axis.x.tickCount = tickCount; }
if ($el.svg && config.axis_x_tick_fit && !config.axis_x_tick_multiline && !config.axis_x_tick_culling && config.axis_x_tick_autorotate && allowedXAxisTypes ) { rotate = $$.needToRotateXAxisTickTexts() ? config.axis_x_tick_rotate : 0; } }
return rotate; },
/** * Check weather axis tick text needs to be rotated * @returns {boolean} * @private */ needToRotateXAxisTickTexts(): boolean { const $$ = this; const {state: {axis, current}} = $$; const xAxisLength = current.width - $$.getCurrentPaddingLeft(false) - $$.getCurrentPaddingRight(); const tickCountWithPadding = axis.x.tickCount + axis.x.padding.left + axis.x.padding.right;
const maxTickWidth = $$.axis.getMaxTickWidth("x"); const tickLength = tickCountWithPadding ? xAxisLength / tickCountWithPadding : 0;
return maxTickWidth > tickLength; }};
billboardjs

Version Info

Tagged at
a year ago