MCPcopy Create free account
hub / github.com/apache/echarts / calcBandWidthForNumericAxis

Function calcBandWidthForNumericAxis

src/coord/axisBand.ts:157–209  ·  view source on GitHub ↗
(
    out: AxisBandWidthResult,
    axis: Axis,
    scaleLinearSpan: number,
    pxSpan: number,
    fromStat: CalculateBandWidthOpt['fromStat'],
)

Source from the content-addressed store, hash-verified

155}
156
157function calcBandWidthForNumericAxis(
158 out: AxisBandWidthResult,
159 axis: Axis,
160 scaleLinearSpan: number,
161 pxSpan: number,
162 fromStat: CalculateBandWidthOpt['fromStat'],
163): void {
164
165 if (__DEV__) {
166 assert(fromStat);
167 }
168
169 let onlySingular = false;
170 let bandWidthInData = -Infinity;
171 each(
172 fromStat.key
173 ? [getAxisStat(axis, fromStat.key)]
174 : getAxisStatBySeries(axis, fromStat.sers || []),
175 function (stat) {
176 const liPosMinGap = stat.liPosMinGap;
177 // NOTE: `liPosMinGap == null` may indicate that `requireAxisStatistics`
178 // is not used by any series on this axis. We should not make `bandWidth`
179 // for this case.
180 if (liPosMinGap != null) {
181 if (liPosMinGap > 0) {
182 if (liPosMinGap > bandWidthInData) {
183 bandWidthInData = liPosMinGap;
184 }
185 onlySingular = false;
186 }
187 else if (liPosMinGap === LINEAR_POSITIVE_MIN_GAP_SINGLE_VALID_VALUE) {
188 onlySingular = true;
189 }
190 }
191 }
192 );
193
194 if (isNullableNumberFinite(scaleLinearSpan) && scaleLinearSpan > 0
195 && isNullableNumberFinite(bandWidthInData)
196 ) {
197 out.w = pxSpan / scaleLinearSpan * bandWidthInData;
198 out.w2 = bandWidthInData;
199 }
200 else if (onlySingular) {
201 // This is the special handing for single value case, where min gap can not
202 // be calculated, but `w` and `w2` (for "containShape") are still needed.
203 out.w = pxSpan * FALLBACK_BAND_WIDTH_RATIO;
204 out.w2 = out.w * scaleLinearSpan / pxSpan;
205 // Consider an axis has both candlestick and bar series, where candlestick has multiple data
206 // but the bar series has no data. In this case, that bar series should be ignored; otherwise,
207 // the axis will be significantly expanded by "containShape" but no bar shape displayed.
208 }
209}

Callers 1

calcBandWidthFunction · 0.85

Calls 5

getAxisStatFunction · 0.90
getAxisStatBySeriesFunction · 0.90
isNullableNumberFiniteFunction · 0.90
assertFunction · 0.50
eachFunction · 0.50

Tested by

no test coverage detected