MCPcopy
hub / github.com/apache/echarts / buildPayloadsBySeries

Function buildPayloadsBySeries

src/component/axisPointer/axisTrigger.ts:259–321  ·  view source on GitHub ↗
(value: AxisValue, axisInfo: CollectedAxisInfo)

Source from the content-addressed store, hash-verified

257}
258
259function buildPayloadsBySeries(value: AxisValue, axisInfo: CollectedAxisInfo) {
260 const axis = axisInfo.axis;
261 const dim = axis.dim;
262 let snapToValue = value;
263 const payloadBatch: BatchItem[] = [];
264 let minDist = Number.MAX_VALUE;
265 let minDiff = -1;
266
267 each(axisInfo.seriesModels, function (series, idx) {
268 const dataDim = series.getData().mapDimensionsAll(dim);
269 let seriesNestestValue;
270 let dataIndices;
271
272 if (series.getAxisTooltipData) {
273 const result = series.getAxisTooltipData(dataDim, value, axis);
274 dataIndices = result.dataIndices;
275 seriesNestestValue = result.nestestValue;
276 }
277 else {
278 dataIndices = series.indicesOfNearest(
279 dim,
280 dataDim[0],
281 value as number,
282 // Add a threshold to avoid find the wrong dataIndex
283 // when data length is not same.
284 // false,
285 axis.type === 'category' ? 0.5 : null
286 );
287 if (!dataIndices.length) {
288 return;
289 }
290 seriesNestestValue = series.getData().get(dataDim[0], dataIndices[0]);
291 }
292
293 if (!isNullableNumberFinite(seriesNestestValue)) {
294 return;
295 }
296
297 const diff = value as number - seriesNestestValue;
298 const dist = Math.abs(diff);
299 // Consider category case
300 if (dist <= minDist) {
301 if (dist < minDist || (diff >= 0 && minDiff < 0)) {
302 minDist = dist;
303 minDiff = diff;
304 snapToValue = seriesNestestValue;
305 payloadBatch.length = 0;
306 }
307 each(dataIndices, function (dataIndex) {
308 payloadBatch.push({
309 seriesIndex: series.seriesIndex,
310 dataIndexInside: dataIndex,
311 dataIndex: series.getData().getRawIndex(dataIndex)
312 });
313 });
314 }
315 });
316

Callers 1

processOnAxisFunction · 0.85

Calls 8

isNullableNumberFiniteFunction · 0.90
mapDimensionsAllMethod · 0.80
indicesOfNearestMethod · 0.80
getDataMethod · 0.65
getAxisTooltipDataMethod · 0.65
getRawIndexMethod · 0.65
eachFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…