@aiquants/period-slider 0.4.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -13
- package/dist/PeriodSlider.d.ts +1 -1
- package/dist/PeriodSlider.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1052 -1003
- package/dist/styles/period-slider.css +1 -1
- package/dist/styles/period-slider.standalone.css +1 -1
- package/package.json +1 -1
- package/src/PeriodSlider.tsx +251 -27
- package/src/styles/period-slider.css +71 -41
package/src/PeriodSlider.tsx
CHANGED
|
@@ -210,7 +210,7 @@ export interface BasePeriodSliderProps extends AccessibleSliderLabels {
|
|
|
210
210
|
tooltipStyle?: "always" | "hover" | "balloon"
|
|
211
211
|
/** Label position: "top" (default) or "bottom" / ラベル表示位置("top": 上側 [既定], "bottom": 下側) */
|
|
212
212
|
labelPosition?: PeriodSliderLabelPosition
|
|
213
|
-
/** Whether to automatically slant labels when close in range mode (default: true) / Range
|
|
213
|
+
/** Whether to automatically slant labels when a pair comes close, in range mode and on both vernier rails (default: true) / Range モードとノギスの両レールで、対が接近した時に自動斜め表示するか (既定: true) */
|
|
214
214
|
autoSlantLabels?: boolean
|
|
215
215
|
/** Renders the slider along the vertical axis (default: false) / 垂直方向レイアウト (既定: false) */
|
|
216
216
|
isVertical?: boolean
|
|
@@ -1029,6 +1029,21 @@ export const calculateLabelSlant = (lowPct: number, highPct: number, trackWidthP
|
|
|
1029
1029
|
}
|
|
1030
1030
|
}
|
|
1031
1031
|
|
|
1032
|
+
/**
|
|
1033
|
+
* Drops the push-apart of a label pair that shows only one label, keeping rotation and clearance.
|
|
1034
|
+
* ラベルが 1 枚しか見えていない対から押し退けだけを取り除き、回転とクリアランスは保持する関数。
|
|
1035
|
+
*
|
|
1036
|
+
* `calculateLabelSlant` is right to separate two labels that sit at distance 0, because both of them
|
|
1037
|
+
* are normally shown. A merged pair is the one case where they are not, and the caller — never the
|
|
1038
|
+
* pure function — knows it.
|
|
1039
|
+
* 距離 0 の 2 ラベルを押し退ける `calculateLabelSlant` の挙動は、2 枚とも表示される通常時には正しい。
|
|
1040
|
+
* 畳んだ対だけが例外であり、それを知るのは純粋関数ではなく呼び出し側。
|
|
1041
|
+
*
|
|
1042
|
+
* @param geometry - Slant geometry solved for the pair / 対に対して解決した傾斜幾何
|
|
1043
|
+
* @returns Same geometry with both horizontal offsets zeroed / 水平オフセットのみ 0 にした同一幾何
|
|
1044
|
+
*/
|
|
1045
|
+
const withoutHorizontalPush = (geometry: LabelSlantResult): LabelSlantResult => ({ ...geometry, lowOffsetX: 0, highOffsetX: 0 })
|
|
1046
|
+
|
|
1032
1047
|
/**
|
|
1033
1048
|
* Grabbable part of a vernier slider, naming both the rail and the element on it.
|
|
1034
1049
|
* ノギススライダーで掴める部位 (レールと要素の組)。
|
|
@@ -1463,6 +1478,97 @@ const useMeasuredBorderBox = (): [(element: HTMLElement | null) => void, Measure
|
|
|
1463
1478
|
return [measureRef, box]
|
|
1464
1479
|
}
|
|
1465
1480
|
|
|
1481
|
+
/**
|
|
1482
|
+
* Builds the slant geometry config of one label pair out of the two measured boxes.
|
|
1483
|
+
* 実測済みの 2 ボックスから 1 対分の傾斜幾何設定を構築する関数。
|
|
1484
|
+
*
|
|
1485
|
+
* Collision avoidance is decided by the real size of both labels: with only one of them measured the
|
|
1486
|
+
* wider one is unknown, so the push-apart would be wrong and the slanted label would cut into the
|
|
1487
|
+
* track. An unmeasured pair therefore means "no size", never an invented default.
|
|
1488
|
+
* 衝突回避は 2 枚の実寸で決まる。片方だけでは広い方が分からず押し出し量を誤ってトラックへ食い込ませる
|
|
1489
|
+
* ため、片方でも未実測なら既定値を捏造せず「寸法なし」として扱う。
|
|
1490
|
+
*
|
|
1491
|
+
* @param lowBox - Measured box of the low label, or null while unmeasured / 下限ラベルの実測ボックス (未実測時は null)
|
|
1492
|
+
* @param highBox - Measured box of the high label, or null while unmeasured / 上限ラベルの実測ボックス (未実測時は null)
|
|
1493
|
+
* @returns Config built from the larger of the pair, or undefined while either box is missing / 対の大きい方から構築した設定 (片方でも欠ければ undefined)
|
|
1494
|
+
*/
|
|
1495
|
+
const buildPairSlantConfig = (lowBox: MeasuredBoxPx | null, highBox: MeasuredBoxPx | null): LabelSlantConfig | undefined => {
|
|
1496
|
+
if (lowBox === null || highBox === null) return undefined
|
|
1497
|
+
return { estimatedWidthPx: Math.max(lowBox.widthPx, highBox.widthPx), estimatedHeightPx: Math.max(lowBox.heightPx, highBox.heightPx) }
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
/**
|
|
1501
|
+
* Placement one vernier label pair resolved, as geometry plus the inline style of each label.
|
|
1502
|
+
* ノギスの 1 対が解決した配置 (幾何と各ラベルのインラインスタイル)。
|
|
1503
|
+
*/
|
|
1504
|
+
interface VernierPairPlacement {
|
|
1505
|
+
/** Geometry solved for the pair / 対に対して解決した傾斜幾何 */
|
|
1506
|
+
slant: LabelSlantResult
|
|
1507
|
+
/** Inline placement of the low label, or undefined to keep the rail baseline / 下限ラベルのインライン配置 (undefined はレール基準配置のまま) */
|
|
1508
|
+
lowStyle: CSSProperties | undefined
|
|
1509
|
+
/** Inline placement of the high label, or undefined to keep the rail baseline / 上限ラベルのインライン配置 (undefined はレール基準配置のまま) */
|
|
1510
|
+
highStyle: CSSProperties | undefined
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* Expresses one vernier label placement as a delta from the upright baseline of its own rail.
|
|
1515
|
+
* ノギスのラベル 1 枚の配置を、自レールの直立基準からの差分として表現する関数。
|
|
1516
|
+
*
|
|
1517
|
+
* @param offsetX - Horizontal push in pixels / 水平押し出し量 (ピクセル)
|
|
1518
|
+
* @param offsetYDelta - Extra vertical push the rotation adds, in pixels / 回転により増える垂直押し出し量 (ピクセル)
|
|
1519
|
+
* @param angleDeg - Rotation in degrees / 回転角 (度)
|
|
1520
|
+
* @returns Custom properties the stylesheet substitutes into the tooltip transform / スタイルシートがツールチップの transform へ代入するカスタムプロパティ
|
|
1521
|
+
*/
|
|
1522
|
+
const buildVernierTooltipStyle = (offsetX: number, offsetYDelta: number, angleDeg: number): CSSProperties =>
|
|
1523
|
+
({
|
|
1524
|
+
"--ps-tooltip-tx": `calc(-50% + ${offsetX}px)`,
|
|
1525
|
+
"--ps-tooltip-ty": `${offsetYDelta}px`,
|
|
1526
|
+
"--ps-tooltip-rot": `${angleDeg}deg`,
|
|
1527
|
+
}) as CSSProperties
|
|
1528
|
+
|
|
1529
|
+
/**
|
|
1530
|
+
* Solves the anti-collision placement of one vernier label pair.
|
|
1531
|
+
* ノギスの 1 対分について、ラベル衝突回避の配置を解決する関数。
|
|
1532
|
+
*
|
|
1533
|
+
* The rail stylesheet already stands an upright label off its own knob (`top` / `bottom: calc(100% + 8px)`
|
|
1534
|
+
* with `--ps-tooltip-ty: 0px`), so only the extra push the rotation adds belongs inline. Taking that
|
|
1535
|
+
* extra as the difference against the upright baseline of the same label size cancels the clearance
|
|
1536
|
+
* constant, which is why this never has to know the rail gap.
|
|
1537
|
+
* レール側 CSS は直立ラベルを既につまみから離して置いているため、インラインで与えるべきは回転で増える
|
|
1538
|
+
* 分だけ。同寸法の直立基準との差を取ると離隔定数が相殺されるので、この関数はレールの隙間量を知らなくてよい。
|
|
1539
|
+
*
|
|
1540
|
+
* The vertical rails ("macro-left" / "macro-right") are excluded for the same reason vertical range is:
|
|
1541
|
+
* the geometry is X-axis only (`lowOffsetX` / `highOffsetX`, distance derived from `ratio * trackLength`),
|
|
1542
|
+
* and their CSS baseline is a different placement (`--ps-tooltip-tx: 0px` / `--ps-tooltip-ty: -50%`),
|
|
1543
|
+
* so writing this result there would displace the label instead of separating the pair.
|
|
1544
|
+
* 縦向きレール ("macro-left" / "macro-right") は縦向き Range と同じ理由で除外する。幾何が X 軸専用であり、
|
|
1545
|
+
* かつ縦レールの CSS 基準配置が別物 (tx: 0px / ty: -50%) のため、ここの結果を書くと対を離すのではなく
|
|
1546
|
+
* ラベルを移動させてしまう。
|
|
1547
|
+
*
|
|
1548
|
+
* @param lowRatio - Low handle position along the track as a 0-1 ratio / トラック上の下限つまみ位置比率 (0-1)
|
|
1549
|
+
* @param highRatio - High handle position along the track as a 0-1 ratio / トラック上の上限つまみ位置比率 (0-1)
|
|
1550
|
+
* @param trackLengthPx - Measured track length in pixels / 実測トラック長 (ピクセル)
|
|
1551
|
+
* @param labelPosition - Side of the track this rail draws its labels on / このレールがラベルを描くトラックの側
|
|
1552
|
+
* @param config - Measured geometry of this pair, or undefined while unmeasured / この対の実測幾何 (未実測時は undefined)
|
|
1553
|
+
* @param isMerged - Whether the pair holds one value and therefore shows one label / 対が同一値で 1 枚だけ見えている状態か
|
|
1554
|
+
* @param isSlantable - Whether this rail may slant at all / このレールが傾斜してよいか
|
|
1555
|
+
* @returns Geometry of the pair and the inline placement of each of its two labels / 対の幾何と 2 枚それぞれのインライン配置
|
|
1556
|
+
*/
|
|
1557
|
+
const solveVernierPairPlacement = (lowRatio: number, highRatio: number, trackLengthPx: number, labelPosition: PeriodSliderLabelPosition, config: LabelSlantConfig | undefined, isMerged: boolean, isSlantable: boolean): VernierPairPlacement => {
|
|
1558
|
+
const baseline = buildHorizontalSlantResult(labelPosition, config)
|
|
1559
|
+
|
|
1560
|
+
if (!isSlantable) return { slant: baseline, lowStyle: undefined, highStyle: undefined }
|
|
1561
|
+
|
|
1562
|
+
const solved = calculateLabelSlant(lowRatio * 100, highRatio * 100, trackLengthPx, labelPosition, config)
|
|
1563
|
+
const slant = isMerged ? withoutHorizontalPush(solved) : solved
|
|
1564
|
+
|
|
1565
|
+
return {
|
|
1566
|
+
slant,
|
|
1567
|
+
lowStyle: buildVernierTooltipStyle(slant.lowOffsetX, slant.lowOffsetY - baseline.lowOffsetY, slant.lowAngleDeg),
|
|
1568
|
+
highStyle: buildVernierTooltipStyle(slant.highOffsetX, slant.highOffsetY - baseline.highOffsetY, slant.highAngleDeg),
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1466
1572
|
/**
|
|
1467
1573
|
* What a stepper button does to the selected value.
|
|
1468
1574
|
* ステッパーボタンが選択値へ与える作用。
|
|
@@ -1680,6 +1786,11 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1680
1786
|
return encode(macroUnit, props.macroRange[1])
|
|
1681
1787
|
}, [props.mode, macroRangeEndMs, vernierMacroMaxEnc, macroUnit])
|
|
1682
1788
|
|
|
1789
|
+
// 位置と ARIA は正規化済みエンコード値、表示だけ生 prop という二重の真実を解消する。
|
|
1790
|
+
// 同じ値なら表示も一致することが構造的に保証される
|
|
1791
|
+
const vernierMacroLowDate = useMemo(() => decode(macroUnit, vernierMacroLowEnc), [macroUnit, vernierMacroLowEnc])
|
|
1792
|
+
const vernierMacroHighDate = useMemo(() => decode(macroUnit, vernierMacroHighEnc), [macroUnit, vernierMacroHighEnc])
|
|
1793
|
+
|
|
1683
1794
|
// ミクロ境界 (マクロ窓がミクロのスケール範囲)。
|
|
1684
1795
|
// マクロ窓は macroUnit 単位へ丸められるうえ末尾期間全体まで広げられるため、そのままでは定義域の外側まで伸びる。
|
|
1685
1796
|
// レール自体を [minDate, maxDate] で切り落とさないと、aria-valuemin/max もドラッグ端も定義域外の日付を指す
|
|
@@ -1725,8 +1836,8 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1725
1836
|
|
|
1726
1837
|
// 比率 (0.0 〜 1.0)。離散レールは当たり判定と同じ候補空間で描かないと、つまみがポインターから離れて飛ぶ
|
|
1727
1838
|
const macroSpan = Math.max(1, vernierMacroMaxEnc - vernierMacroMinEnc)
|
|
1728
|
-
const macroLowRatio = macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode,
|
|
1729
|
-
const macroHighRatio = Math.max(macroLowRatio, macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode,
|
|
1839
|
+
const macroLowRatio = macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode, vernierMacroLowDate) : Math.max(0, Math.min(1, (vernierMacroLowEnc - vernierMacroMinEnc) / macroSpan))
|
|
1840
|
+
const macroHighRatio = Math.max(macroLowRatio, macroIsDiscreteScale ? discreteDateToRailRatio(sortedMacroAllowedDates, macroUnit, snapMode, vernierMacroHighDate) : Math.min(1, (vernierMacroHighEnc - vernierMacroMinEnc) / macroSpan))
|
|
1730
1841
|
|
|
1731
1842
|
const microSpan = Math.max(1, vernierMicroMaxEnc - vernierMicroMinEnc)
|
|
1732
1843
|
const microLowRatio = microIsDiscreteScale ? discreteDateToRailRatio(sortedMicroAllowedDates, microUnit, snapMode, vernierMicroLowDate) : Math.max(0, Math.min(1, (vernierMicroLowEnc - vernierMicroMinEnc) / microSpan))
|
|
@@ -1942,6 +2053,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
1942
2053
|
const [lowLabelRef, lowLabelBox] = useMeasuredBorderBox()
|
|
1943
2054
|
const [highLabelRef, highLabelBox] = useMeasuredBorderBox()
|
|
1944
2055
|
|
|
2056
|
+
// ノギスの 4 枚も同じ経路で測る。マクロとミクロは書式も単位も違うため実寸も違い、片方の幅で
|
|
2057
|
+
// 他方の押し出しを決めると必ずどちらかが外れる。測っていない対は「寸法なし」= 直立のまま
|
|
2058
|
+
const [macroLowLabelRef, macroLowLabelBox] = useMeasuredBorderBox()
|
|
2059
|
+
const [macroHighLabelRef, macroHighLabelBox] = useMeasuredBorderBox()
|
|
2060
|
+
const [microLowLabelRef, microLowLabelBox] = useMeasuredBorderBox()
|
|
2061
|
+
const [microHighLabelRef, microHighLabelBox] = useMeasuredBorderBox()
|
|
2062
|
+
|
|
1945
2063
|
useEffect(() => {
|
|
1946
2064
|
const el = trackRef.current
|
|
1947
2065
|
if (!el) return
|
|
@@ -2352,6 +2470,35 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2352
2470
|
startDrag(e.pointerId, handle, pos)
|
|
2353
2471
|
}
|
|
2354
2472
|
|
|
2473
|
+
/**
|
|
2474
|
+
* Brings the focused range handle to the front so the surviving label follows the keyboard.
|
|
2475
|
+
* 焦点の当たった Range つまみを前面へ出し、生存ラベルをキーボード操作へ追従させるハンドラ生成関数。
|
|
2476
|
+
*
|
|
2477
|
+
* @param handle - Handle that received focus / 焦点を受け取ったつまみ
|
|
2478
|
+
* @returns Focus event handler for the given handle / 指定つまみ用の focus イベントハンドラ
|
|
2479
|
+
*/
|
|
2480
|
+
const handleKnobFocus = (handle: "low" | "high") => () => {
|
|
2481
|
+
// 値が重なるとラベルは前面側の 1 枚しか見えない。焦点の当たったつまみを前面へ出さないと、
|
|
2482
|
+
// Tab で到達したつまみだけが値を表示しないまま操作されることになる。
|
|
2483
|
+
// ドラッグ中に限り前面はポインターが掴んだつまみの専権事項で、focus に譲ると交差時に掴んでいない側が前面へ出る
|
|
2484
|
+
if (disabled || activeHandleRef.current !== null) return
|
|
2485
|
+
setFrontHandle(handle)
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
/**
|
|
2489
|
+
* Brings the focused Vernier handle to the front, mirroring the range-mode focus contract.
|
|
2490
|
+
* 焦点の当たったノギスつまみを前面へ出す、Range モードと同契約の focus ハンドラ生成関数。
|
|
2491
|
+
*
|
|
2492
|
+
* @param handle - Knob handle that received focus / 焦点を受け取ったつまみ
|
|
2493
|
+
* @returns Focus event handler for the given handle / 指定つまみ用の focus イベントハンドラ
|
|
2494
|
+
*/
|
|
2495
|
+
const handleVernierKnobFocus = (handle: VernierHandle) => () => {
|
|
2496
|
+
// 同値で畳んだ対は前面側の 1 枚しか見えない。Tab で到達した側を前面へ出さないと、
|
|
2497
|
+
// これから操作するつまみだけが値を表示しない状態で残る
|
|
2498
|
+
if (disabled || activeVernierHandleRef.current !== null) return
|
|
2499
|
+
setFrontVernierHandle(handle)
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2355
2502
|
const handleVernierKnobPointerDown = (handle: VernierHandle) => (e: React.PointerEvent<HTMLDivElement>) => {
|
|
2356
2503
|
if (disabled) return
|
|
2357
2504
|
e.stopPropagation()
|
|
@@ -2675,25 +2822,70 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2675
2822
|
const lowDate = valueToDate(currentLowVal)
|
|
2676
2823
|
const highDate = valueToDate(currentHighVal)
|
|
2677
2824
|
|
|
2678
|
-
//
|
|
2679
|
-
//
|
|
2825
|
+
// Point モードはラベルが 1 枚で、その 1 枚の実寸がそのまま直立基準の高さになる。
|
|
2826
|
+
// 対になる 2 枚の規則 (片方でも未実測なら寸法なし) は buildPairSlantConfig が一手に持つ
|
|
2680
2827
|
const labelSlantConfig: LabelSlantConfig | undefined = useMemo(() => {
|
|
2681
2828
|
if (isPointMode) return lowLabelBox === null ? undefined : { estimatedWidthPx: lowLabelBox.widthPx, estimatedHeightPx: lowLabelBox.heightPx }
|
|
2682
|
-
|
|
2683
|
-
return {
|
|
2684
|
-
estimatedWidthPx: Math.max(lowLabelBox.widthPx, highLabelBox.widthPx),
|
|
2685
|
-
estimatedHeightPx: Math.max(lowLabelBox.heightPx, highLabelBox.heightPx),
|
|
2686
|
-
}
|
|
2829
|
+
return buildPairSlantConfig(lowLabelBox, highLabelBox)
|
|
2687
2830
|
}, [isPointMode, lowLabelBox, highLabelBox])
|
|
2688
2831
|
|
|
2832
|
+
// 値が一致するとき 2 枚のラベルは文字列まで同一になる (valueToDate が純粋なので構造的に保証される)。
|
|
2833
|
+
// ピクセル距離では別日と区別できないため判定は必ず値で行う。
|
|
2834
|
+
// point モードは上限値を下限値へ寄せるため素の一致判定が恒真になり、!isPointMode で外さないと成立しない
|
|
2835
|
+
const isLabelMerged = !isPointMode && currentLowVal === currentHighVal
|
|
2836
|
+
|
|
2689
2837
|
const slantResult: LabelSlantResult = useMemo(() => {
|
|
2838
|
+
// 縦向きは X 軸オフセットしか返さない幾何を適用できない。Point モードは避ける相手そのものが居ない
|
|
2690
2839
|
if (isPointMode || !autoSlantLabels || isVertical) return buildHorizontalSlantResult(labelPosition, labelSlantConfig)
|
|
2691
|
-
|
|
2692
|
-
|
|
2840
|
+
|
|
2841
|
+
const solved = calculateLabelSlant(lowPct, highPct, trackLength, labelPosition, labelSlantConfig)
|
|
2842
|
+
if (!isLabelMerged) return solved
|
|
2843
|
+
|
|
2844
|
+
// 併合時に残る 1 枚は前面側であり、front は焦点・押下・交差のたび入れ替わる。押し退けを残すと
|
|
2845
|
+
// 唯一のラベルが ±shiftX の間を飛び、離す相手も居ない。角度と垂直オフセットは 90deg のラベルを
|
|
2846
|
+
// つまみから逃がすために必要なので保持し、接近から一致まで角度も位置も連続させる
|
|
2847
|
+
return withoutHorizontalPush(solved)
|
|
2848
|
+
}, [isPointMode, isLabelMerged, autoSlantLabels, isVertical, lowPct, highPct, trackLength, labelPosition, labelSlantConfig])
|
|
2693
2849
|
|
|
2694
2850
|
const isLowFront = activeHandle === "low" || (activeHandle !== "high" && frontHandle === "low")
|
|
2695
2851
|
const isHighFront = !isPointMode && (activeHandle === "high" || (activeHandle !== "low" && frontHandle === "high"))
|
|
2696
2852
|
|
|
2853
|
+
// ノギスの 2 対も Range と同じ根拠で畳む。マクロ・ミクロとも符号化値から復元した日付を整形するため、
|
|
2854
|
+
// 符号化値が一致すればラベルは文字列まで一致する。しかもノギスには押し退けが無く 2 枚が同一矩形へ
|
|
2855
|
+
// 完全に重なるため、畳まないと同じ値が二重に読み上げられるだけで視覚的な情報も増えない
|
|
2856
|
+
const isVernierMacroLabelMerged = vernierMacroLowEnc === vernierMacroHighEnc
|
|
2857
|
+
const isVernierMicroLabelMerged = vernierMicroLowEnc === vernierMicroHighEnc
|
|
2858
|
+
|
|
2859
|
+
// 生存者は対の内側だけで決める。frontVernierHandle は 4 つのつまみで 1 本しか無く、相手の対や
|
|
2860
|
+
// 連結バーを操作している間は対の両方が非 front になるため、「front でない方を隠す」では両方消える。
|
|
2861
|
+
// 下限が front のときだけ下限を残し、それ以外は上限を残す (Range の初期前面と同じ上限優先) 全域規則
|
|
2862
|
+
const isVernierMacroLowLabelDuplicate = isVernierMacroLabelMerged && frontVernierHandle !== "macro-low"
|
|
2863
|
+
const isVernierMacroHighLabelDuplicate = isVernierMacroLabelMerged && frontVernierHandle === "macro-low"
|
|
2864
|
+
const isVernierMicroLowLabelDuplicate = isVernierMicroLabelMerged && frontVernierHandle !== "micro-low"
|
|
2865
|
+
const isVernierMicroHighLabelDuplicate = isVernierMicroLabelMerged && frontVernierHandle === "micro-low"
|
|
2866
|
+
|
|
2867
|
+
// ラベルが載る面はつまみと同じ側であり、JSX の data-vernier-pos が示す面と必ず一致する
|
|
2868
|
+
const macroRailLabelPosition: PeriodSliderLabelPosition = isMacroFirstRail ? "top" : "bottom"
|
|
2869
|
+
const microRailLabelPosition: PeriodSliderLabelPosition = isMacroFirstRail ? "bottom" : "top"
|
|
2870
|
+
|
|
2871
|
+
// マクロとミクロは同じトラックの上で比率も単位空間もラベル幅も異なる。1 つの計算を共有すると
|
|
2872
|
+
// 一方の押し退け量が他方の実寸で決まってしまうため、対ごとに独立して解く
|
|
2873
|
+
const macroLabelSlantConfig = useMemo(() => buildPairSlantConfig(macroLowLabelBox, macroHighLabelBox), [macroLowLabelBox, macroHighLabelBox])
|
|
2874
|
+
const microLabelSlantConfig = useMemo(() => buildPairSlantConfig(microLowLabelBox, microHighLabelBox), [microLowLabelBox, microHighLabelBox])
|
|
2875
|
+
|
|
2876
|
+
// 傾斜可否はレール単位で決まる。縦向きノギスは縦向き Range と同じ理由で外す (solveVernierPairPlacement 参照)
|
|
2877
|
+
const isVernierSlantable = autoSlantLabels && !isVertical
|
|
2878
|
+
|
|
2879
|
+
const macroPairPlacement = useMemo(
|
|
2880
|
+
() => solveVernierPairPlacement(macroLowRatio, macroHighRatio, trackLength, macroRailLabelPosition, macroLabelSlantConfig, isVernierMacroLabelMerged, isVernierSlantable),
|
|
2881
|
+
[macroLowRatio, macroHighRatio, trackLength, macroRailLabelPosition, macroLabelSlantConfig, isVernierMacroLabelMerged, isVernierSlantable],
|
|
2882
|
+
)
|
|
2883
|
+
|
|
2884
|
+
const microPairPlacement = useMemo(
|
|
2885
|
+
() => solveVernierPairPlacement(microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isVernierSlantable),
|
|
2886
|
+
[microLowRatio, microHighRatio, trackLength, microRailLabelPosition, microLabelSlantConfig, isVernierMicroLabelMerged, isVernierSlantable],
|
|
2887
|
+
)
|
|
2888
|
+
|
|
2697
2889
|
const lowTooltipStyle: CSSProperties = useMemo(() => {
|
|
2698
2890
|
if (isVertical) {
|
|
2699
2891
|
return {
|
|
@@ -2759,6 +2951,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2759
2951
|
|
|
2760
2952
|
const hoverDate = hoverValue !== null ? valueToDate(hoverValue) : null
|
|
2761
2953
|
|
|
2954
|
+
// 追従ツールチップはつまみのラベルと同じ書式化関数を通るため、指している値が一致すれば文字列まで一致する。
|
|
2955
|
+
// 判定は畳み込みと同じく符号化値で行う (ピクセル距離では隣の値と区別できない)。
|
|
2956
|
+
// tooltipStyle="hover" ではつまみ側のラベルが 1 枚も描かれず、これが唯一の表示になるため重複には成り得ない。
|
|
2957
|
+
// point モードのつまみは 1 つで、その値は下限側が持つ (上限側のつまみは描かれない)
|
|
2958
|
+
const isHoverLabelDuplicate = tooltipStyle !== "hover" && hoverValue !== null && (hoverValue === currentLowVal || (!isPointMode && hoverValue === currentHighVal))
|
|
2959
|
+
|
|
2762
2960
|
// 離散ミクロでは先頭・末尾の候補が可動端。生の窓境界で判定すると、末尾候補を越えて候補外の日付を歩き続ける
|
|
2763
2961
|
const microStepFloorEnc = microIsDiscreteScale ? encode(microUnit, sortedMicroAllowedDates[0]) : vernierMicroMinEnc
|
|
2764
2962
|
const microStepCeilEnc = microIsDiscreteScale ? encode(microUnit, sortedMicroAllowedDates[sortedMicroAllowedDates.length - 1]) : vernierMicroMaxEnc
|
|
@@ -2903,7 +3101,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2903
3101
|
aria-valuemin={vernierMacroMinEnc}
|
|
2904
3102
|
aria-valuemax={vernierMacroHighEnc}
|
|
2905
3103
|
aria-valuenow={vernierMacroLowEnc}
|
|
2906
|
-
aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(
|
|
3104
|
+
aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(vernierMacroLowDate, macroUnit) : formatScreenReaderLabel(macroUnit, vernierMacroLowDate, formatMacroLabel, locale)}
|
|
2907
3105
|
aria-orientation={isVertical ? "vertical" : "horizontal"}
|
|
2908
3106
|
className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
|
|
2909
3107
|
isVertical
|
|
@@ -2933,6 +3131,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2933
3131
|
}
|
|
2934
3132
|
onPointerDown={handleVernierKnobPointerDown("macro-low")}
|
|
2935
3133
|
onKeyDown={handleVernierKeyDown("macro-low")}
|
|
3134
|
+
onFocus={handleVernierKnobFocus("macro-low")}
|
|
2936
3135
|
data-active={activeVernierHandle === "macro-low" ? "true" : undefined}
|
|
2937
3136
|
data-front={frontVernierHandle === "macro-low" ? "true" : undefined}
|
|
2938
3137
|
data-vernier-pos={isVertical ? (isMacroFirstRail ? "left" : "right") : isMacroFirstRail ? "top" : "bottom"}
|
|
@@ -2941,9 +3140,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2941
3140
|
{showHairline && <div className="period-slider-hairline" />}
|
|
2942
3141
|
{tooltipStyle !== "hover" && (
|
|
2943
3142
|
<div
|
|
2944
|
-
className={`period-slider-tooltip absolute whitespace-nowrap
|
|
2945
|
-
data-tooltip-style={tooltipStyle}
|
|
2946
|
-
{
|
|
3143
|
+
className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
3144
|
+
data-tooltip-style={tooltipStyle}
|
|
3145
|
+
data-duplicate={isVernierMacroLowLabelDuplicate ? "true" : undefined}
|
|
3146
|
+
data-slanted={macroPairPlacement.slant.isSlanted ? "true" : undefined}
|
|
3147
|
+
ref={macroLowLabelRef}
|
|
3148
|
+
style={macroPairPlacement.lowStyle}>
|
|
3149
|
+
{formatLabel(macroUnit, vernierMacroLowDate, formatMacroLabel, locale)}
|
|
2947
3150
|
</div>
|
|
2948
3151
|
)}
|
|
2949
3152
|
</div>
|
|
@@ -2957,7 +3160,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2957
3160
|
aria-valuemin={vernierMacroLowEnc}
|
|
2958
3161
|
aria-valuemax={vernierMacroMaxEnc}
|
|
2959
3162
|
aria-valuenow={vernierMacroHighEnc}
|
|
2960
|
-
aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(
|
|
3163
|
+
aria-valuetext={props.formatAriaValueText ? props.formatAriaValueText(vernierMacroHighDate, macroUnit) : formatScreenReaderLabel(macroUnit, vernierMacroHighDate, formatMacroLabel, locale)}
|
|
2961
3164
|
aria-orientation={isVertical ? "vertical" : "horizontal"}
|
|
2962
3165
|
className={`period-slider-handle period-slider-handle-vernier ${isVertical ? "is-vertical" : ""} group absolute touch-none ${
|
|
2963
3166
|
isVertical
|
|
@@ -2987,6 +3190,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2987
3190
|
}
|
|
2988
3191
|
onPointerDown={handleVernierKnobPointerDown("macro-high")}
|
|
2989
3192
|
onKeyDown={handleVernierKeyDown("macro-high")}
|
|
3193
|
+
onFocus={handleVernierKnobFocus("macro-high")}
|
|
2990
3194
|
data-active={activeVernierHandle === "macro-high" ? "true" : undefined}
|
|
2991
3195
|
data-front={frontVernierHandle === "macro-high" ? "true" : undefined}
|
|
2992
3196
|
data-vernier-pos={isVertical ? (isMacroFirstRail ? "left" : "right") : isMacroFirstRail ? "top" : "bottom"}
|
|
@@ -2995,9 +3199,13 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
2995
3199
|
{showHairline && <div className="period-slider-hairline" />}
|
|
2996
3200
|
{tooltipStyle !== "hover" && (
|
|
2997
3201
|
<div
|
|
2998
|
-
className={`period-slider-tooltip absolute whitespace-nowrap
|
|
2999
|
-
data-tooltip-style={tooltipStyle}
|
|
3000
|
-
{
|
|
3202
|
+
className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
3203
|
+
data-tooltip-style={tooltipStyle}
|
|
3204
|
+
data-duplicate={isVernierMacroHighLabelDuplicate ? "true" : undefined}
|
|
3205
|
+
data-slanted={macroPairPlacement.slant.isSlanted ? "true" : undefined}
|
|
3206
|
+
ref={macroHighLabelRef}
|
|
3207
|
+
style={macroPairPlacement.highStyle}>
|
|
3208
|
+
{formatLabel(macroUnit, vernierMacroHighDate, formatMacroLabel, locale)}
|
|
3001
3209
|
</div>
|
|
3002
3210
|
)}
|
|
3003
3211
|
</div>
|
|
@@ -3041,6 +3249,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3041
3249
|
}
|
|
3042
3250
|
onPointerDown={handleVernierKnobPointerDown("micro-low")}
|
|
3043
3251
|
onKeyDown={handleVernierKeyDown("micro-low")}
|
|
3252
|
+
onFocus={handleVernierKnobFocus("micro-low")}
|
|
3044
3253
|
data-active={activeVernierHandle === "micro-low" ? "true" : undefined}
|
|
3045
3254
|
data-front={frontVernierHandle === "micro-low" ? "true" : undefined}
|
|
3046
3255
|
data-vernier-pos={isVertical ? (isMacroFirstRail ? "right" : "left") : isMacroFirstRail ? "bottom" : "top"}
|
|
@@ -3049,8 +3258,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3049
3258
|
{showHairline && <div className="period-slider-hairline" />}
|
|
3050
3259
|
{tooltipStyle !== "hover" && (
|
|
3051
3260
|
<div
|
|
3052
|
-
className={`period-slider-tooltip absolute whitespace-nowrap
|
|
3053
|
-
data-tooltip-style={tooltipStyle}
|
|
3261
|
+
className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
3262
|
+
data-tooltip-style={tooltipStyle}
|
|
3263
|
+
data-duplicate={isVernierMicroLowLabelDuplicate ? "true" : undefined}
|
|
3264
|
+
data-slanted={microPairPlacement.slant.isSlanted ? "true" : undefined}
|
|
3265
|
+
ref={microLowLabelRef}
|
|
3266
|
+
style={microPairPlacement.lowStyle}>
|
|
3054
3267
|
{formatLabel(microUnit, vernierMicroLowDate, formatMicroLabel, locale)}
|
|
3055
3268
|
</div>
|
|
3056
3269
|
)}
|
|
@@ -3095,6 +3308,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3095
3308
|
}
|
|
3096
3309
|
onPointerDown={handleVernierKnobPointerDown("micro-high")}
|
|
3097
3310
|
onKeyDown={handleVernierKeyDown("micro-high")}
|
|
3311
|
+
onFocus={handleVernierKnobFocus("micro-high")}
|
|
3098
3312
|
data-active={activeVernierHandle === "micro-high" ? "true" : undefined}
|
|
3099
3313
|
data-front={frontVernierHandle === "micro-high" ? "true" : undefined}
|
|
3100
3314
|
data-vernier-pos={isVertical ? (isMacroFirstRail ? "right" : "left") : isMacroFirstRail ? "bottom" : "top"}
|
|
@@ -3103,8 +3317,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3103
3317
|
{showHairline && <div className="period-slider-hairline" />}
|
|
3104
3318
|
{tooltipStyle !== "hover" && (
|
|
3105
3319
|
<div
|
|
3106
|
-
className={`period-slider-tooltip absolute whitespace-nowrap
|
|
3107
|
-
data-tooltip-style={tooltipStyle}
|
|
3320
|
+
className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
3321
|
+
data-tooltip-style={tooltipStyle}
|
|
3322
|
+
data-duplicate={isVernierMicroHighLabelDuplicate ? "true" : undefined}
|
|
3323
|
+
data-slanted={microPairPlacement.slant.isSlanted ? "true" : undefined}
|
|
3324
|
+
ref={microHighLabelRef}
|
|
3325
|
+
style={microPairPlacement.highStyle}>
|
|
3108
3326
|
{formatLabel(microUnit, vernierMicroHighDate, formatMicroLabel, locale)}
|
|
3109
3327
|
</div>
|
|
3110
3328
|
)}
|
|
@@ -3129,9 +3347,11 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3129
3347
|
|
|
3130
3348
|
{/* トラック上のマウスホバーガイド & ツールチップ */}
|
|
3131
3349
|
{!disabled && hoverValue !== null && hoverPct !== null && activeHandle === null && hoverDate && (
|
|
3132
|
-
<div data-testid="period-slider-hover-guide" className="period-slider-hover-guide pointer-events-none absolute
|
|
3350
|
+
<div data-testid="period-slider-hover-guide" className="period-slider-hover-guide pointer-events-none absolute h-2 w-2" style={hoverGuideStyle}>
|
|
3133
3351
|
<div data-testid="period-slider-hover-dot" className="period-slider-hover-dot h-full w-full rounded-full border border-white/80 bg-[var(--aqps-accent-light)] shadow-[0_0_6px_var(--aqps-accent-glow)] dark:border-slate-800" />
|
|
3134
3352
|
<div
|
|
3353
|
+
data-testid="period-slider-hover-tooltip"
|
|
3354
|
+
data-duplicate={isHoverLabelDuplicate ? "true" : undefined}
|
|
3135
3355
|
className={`period-slider-hover-tooltip ${labelPosition === "bottom" && !isVertical ? "period-slider-hover-tooltip-bottom" : ""} rounded bg-slate-800/90 px-2 py-0.5 font-medium text-white text-xs shadow-lg backdrop-blur-xs dark:bg-slate-900/90`}>
|
|
3136
3356
|
{formatLabel(unit, hoverDate, props.formatLabel, locale)}
|
|
3137
3357
|
</div>
|
|
@@ -3153,6 +3373,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3153
3373
|
style={lowHandleStyle}
|
|
3154
3374
|
onPointerDown={handleKnobPointerDown("low")}
|
|
3155
3375
|
onKeyDown={handleKeyDown("low")}
|
|
3376
|
+
onFocus={handleKnobFocus("low")}
|
|
3156
3377
|
data-active={activeHandle === "low" ? "true" : undefined}
|
|
3157
3378
|
data-front={isLowFront ? "true" : undefined}>
|
|
3158
3379
|
<div
|
|
@@ -3161,11 +3382,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3161
3382
|
/>
|
|
3162
3383
|
{tooltipStyle !== "hover" && (
|
|
3163
3384
|
<div
|
|
3164
|
-
className={`period-slider-tooltip absolute whitespace-nowrap
|
|
3385
|
+
className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
3165
3386
|
data-tooltip-style={tooltipStyle}
|
|
3166
3387
|
data-label-position={labelPosition}
|
|
3167
3388
|
data-slanted={slantResult.isSlanted ? "true" : undefined}
|
|
3168
3389
|
data-front={isLowFront ? "true" : undefined}
|
|
3390
|
+
data-duplicate={isLabelMerged && !isLowFront ? "true" : undefined}
|
|
3169
3391
|
ref={lowLabelRef}
|
|
3170
3392
|
style={lowTooltipStyle}>
|
|
3171
3393
|
{formatLabel(unit, lowDate, props.formatLabel, locale)}
|
|
@@ -3189,6 +3411,7 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3189
3411
|
style={highHandleStyle}
|
|
3190
3412
|
onPointerDown={handleKnobPointerDown("high")}
|
|
3191
3413
|
onKeyDown={handleKeyDown("high")}
|
|
3414
|
+
onFocus={handleKnobFocus("high")}
|
|
3192
3415
|
data-active={activeHandle === "high" ? "true" : undefined}
|
|
3193
3416
|
data-front={isHighFront ? "true" : undefined}>
|
|
3194
3417
|
<div
|
|
@@ -3197,11 +3420,12 @@ const PeriodSliderComponent: React.FC<PeriodSliderProps> = (props) => {
|
|
|
3197
3420
|
/>
|
|
3198
3421
|
{tooltipStyle !== "hover" && (
|
|
3199
3422
|
<div
|
|
3200
|
-
className={`period-slider-tooltip absolute whitespace-nowrap
|
|
3423
|
+
className={`period-slider-tooltip absolute whitespace-nowrap font-medium shadow-md ${tooltipStyle === "balloon" ? "period-slider-tooltip-balloon" : ""}`}
|
|
3201
3424
|
data-tooltip-style={tooltipStyle}
|
|
3202
3425
|
data-label-position={labelPosition}
|
|
3203
3426
|
data-slanted={slantResult.isSlanted ? "true" : undefined}
|
|
3204
3427
|
data-front={isHighFront ? "true" : undefined}
|
|
3428
|
+
data-duplicate={isLabelMerged && !isHighFront ? "true" : undefined}
|
|
3205
3429
|
ref={highLabelRef}
|
|
3206
3430
|
style={highTooltipStyle}>
|
|
3207
3431
|
{formatLabel(unit, highDate, props.formatLabel, locale)}
|