MCPcopy Index your code
hub / github.com/apache/echarts / pointToDataOneDimPrepareCtx

Function pointToDataOneDimPrepareCtx

src/coord/matrix/Matrix.ts:495–572  ·  view source on GitHub ↗
(
    ctx: CtxPointToData,
    dimIdx: number,
    dims: MatrixDimPair,
    point: number[],
    clamp: MatrixClampOption | NullUndefined
)

Source from the content-addressed store, hash-verified

493const _tmpCtxPointToData: CtxPointToData = {x: null, y: null, point: []};
494
495function pointToDataOneDimPrepareCtx(
496 ctx: CtxPointToData,
497 dimIdx: number,
498 dims: MatrixDimPair,
499 point: number[],
500 clamp: MatrixClampOption | NullUndefined
501) {
502 const thisDim = dims[XY[dimIdx]];
503 const otherDim = dims[XY[1 - dimIdx]];
504
505 // Notice: considered cases: `matrix.x/y.show: false`, `matrix.x/y.data` is empty.
506 // In this cases the `layout.xy` is on the edge and `layout.wh` is `0`; they still can be
507 // use to calculate clampping.
508
509 const bodyMaxUnit = thisDim.getUnitLayoutInfo(dimIdx, thisDim.getLocatorCount(dimIdx) - 1);
510 const body0Unit = thisDim.getUnitLayoutInfo(dimIdx, 0);
511 const cornerMinUnit = otherDim.getUnitLayoutInfo(dimIdx, -otherDim.getLocatorCount(dimIdx));
512 const cornerMinus1Unit = otherDim.shouldShow() ? otherDim.getUnitLayoutInfo(dimIdx, -1) : null;
513
514 let coord = ctx.point[dimIdx] = point[dimIdx]; // Transfer the oridinal coord.
515
516 if (!body0Unit && !cornerMinus1Unit) {
517 ctx[XY[dimIdx]] = CtxPointToDataAreaType.outside;
518 return;
519 }
520
521 if (clamp === MatrixClampOption.body) {
522 if (body0Unit) {
523 ctx[XY[dimIdx]] = CtxPointToDataAreaType.inBody;
524 coord = mathMin(bodyMaxUnit.xy + bodyMaxUnit.wh, mathMax(body0Unit.xy, coord));
525 ctx.point[dimIdx] = coord;
526 }
527 else {
528 // If clamp to body, the result must not be in header.
529 ctx[XY[dimIdx]] = CtxPointToDataAreaType.outside;
530 }
531 return;
532 }
533 else if (clamp === MatrixClampOption.corner) {
534 if (cornerMinus1Unit) {
535 ctx[XY[dimIdx]] = CtxPointToDataAreaType.inCorner;
536 coord = mathMin(cornerMinus1Unit.xy + cornerMinus1Unit.wh, mathMax(cornerMinUnit.xy, coord));
537 ctx.point[dimIdx] = coord;
538 }
539 else {
540 // If clamp to corner, the result must not be in body.
541 ctx[XY[dimIdx]] = CtxPointToDataAreaType.outside;
542 }
543 return;
544 }
545
546 const pxLoc0 = body0Unit ? body0Unit.xy : cornerMinus1Unit ? cornerMinus1Unit.xy + cornerMinus1Unit.wh : NaN;
547 const pxMin = cornerMinUnit ? cornerMinUnit.xy : pxLoc0;
548 const pxMax = bodyMaxUnit ? bodyMaxUnit.xy + bodyMaxUnit.wh : pxLoc0;
549
550 if (coord < pxMin) {
551 if (!clamp) {
552 // Quick pass for later calc, since mouse event on any place will enter this method if use `pointToData`.

Callers 1

pointToDataMethod · 0.85

Calls 3

getUnitLayoutInfoMethod · 0.80
getLocatorCountMethod · 0.80
shouldShowMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…