(
ctx: CtxPointToData,
dimIdx: number,
dims: MatrixDimPair,
point: number[],
clamp: MatrixClampOption | NullUndefined
)
| 493 | const _tmpCtxPointToData: CtxPointToData = {x: null, y: null, point: []}; |
| 494 | |
| 495 | function 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`. |
no test coverage detected
searching dependent graphs…