@@ -2398,6 +2398,74 @@ describe('SVG motion', () => {
23982398 frames . restore ( )
23992399 } )
24002400
2401+ it ( 'advances the crosshair spring during repeated data-frame repaints' , ( ) => {
2402+ const frames = installManagedFrames ( )
2403+ const makeScene = ( offset : number ) =>
2404+ createChartScene (
2405+ defineChart ( {
2406+ marks : [
2407+ lineY (
2408+ Array . from ( { length : 20 } , ( _ , x ) => ( { x, y : x + offset } ) ) ,
2409+ { x : 'x' , y : 'y' , key : 'x' } ,
2410+ ) ,
2411+ crosshair ( { x : true , y : false } ) ,
2412+ ] ,
2413+ scales : {
2414+ x : { scale : scaleLinear ( ) . domain ( [ 0 , 19 ] ) } ,
2415+ y : { scale : scaleLinear ( ) . domain ( [ 0 , 40 ] ) } ,
2416+ } ,
2417+ guides : false ,
2418+ } ) ,
2419+ { width : 400 , height : 200 } ,
2420+ )
2421+ const container = document . createElement ( 'div' )
2422+ const surface = motion ( {
2423+ initial : false ,
2424+ transition : { type : 'spring' , stiffness : 170 , damping : 18 } ,
2425+ } ) . mount ( container , ( ) => { } )
2426+ let unsubscribe = ( ) => { }
2427+ try {
2428+ surface . render ( makeScene ( 0 ) , { ariaLabel : 'Crosshair repaint' } )
2429+ const next = makeScene ( 5 )
2430+ surface . render ( next , { ariaLabel : 'Crosshair repaint' } )
2431+ const paint = ( index : number ) => {
2432+ const point = next . points [ index ] !
2433+ surface . paintFocus ( {
2434+ primary : point ,
2435+ group : [ point ] ,
2436+ source : 'pointer' ,
2437+ pinned : false ,
2438+ } )
2439+ }
2440+ paint ( 2 )
2441+ paint ( 15 )
2442+ const line = container . querySelector < SVGLineElement > (
2443+ '.ts-chart__focus-guide-layer line' ,
2444+ ) !
2445+ const start = Number ( line . getAttribute ( 'x1' ) )
2446+ let repaints = 0
2447+ if ( ! surface . subscribePresentationPoints ) {
2448+ throw new Error ( 'Expected motion presentation subscriptions' )
2449+ }
2450+ unsubscribe = surface . subscribePresentationPoints ( ( ) => {
2451+ repaints += 1
2452+ paint ( 15 )
2453+ } )
2454+ for ( let time = 16 ; time <= 128 ; time += 16 ) frames . runAll ( time )
2455+ expect ( repaints ) . toBe ( 8 )
2456+ expect ( Number ( line . getAttribute ( 'x1' ) ) ) . toBeGreaterThan ( start + 100 )
2457+ expect ( Number ( line . getAttribute ( 'x1' ) ) ) . toBeLessThan ( next . points [ 15 ] ! . x )
2458+ expect ( container . querySelector ( '.ts-chart__focus-guide-layer line' ) ) . toBe (
2459+ line ,
2460+ )
2461+ } finally {
2462+ unsubscribe ( )
2463+ surface . destroy ( )
2464+ expect ( frames . pending ( ) ) . toBe ( 0 )
2465+ frames . restore ( )
2466+ }
2467+ } )
2468+
24012469 it ( 'retargets a persistent crosshair spring without replacing guide elements' , ( ) => {
24022470 const transition = {
24032471 type : 'spring' as const ,
0 commit comments