@@ -191,6 +191,9 @@ export default function ChartPathProvider({
191
191
proceededData,
192
192
} = useContext ( ChartContext ) || generateValues ( ) ;
193
193
194
+ const height = rest . height || layoutSize . value . height ;
195
+ const width = rest . width || layoutSize . value . width ;
196
+
194
197
const prevData = useSharedValue ( valuesStore . current . prevData , 'prevData' ) ;
195
198
const currData = useSharedValue ( valuesStore . current . currData , 'currData' ) ;
196
199
const curroriginalData = useSharedValue (
@@ -287,16 +290,12 @@ export default function ChartPathProvider({
287
290
}
288
291
isStarted . value = true ;
289
292
290
- const eventX = positionXWithMargin (
291
- event . x ,
292
- hitSlopValue . value ,
293
- layoutSize . value . width
294
- ) ;
293
+ const eventX = positionXWithMargin ( event . x , hitSlopValue . value , width ) ;
295
294
296
295
let idx = 0 ;
297
296
const ss = smoothingStrategy ;
298
297
for ( let i = 0 ; i < currData . value . length ; i ++ ) {
299
- if ( getValue ( currData , i , ss ) . x > eventX / layoutSize . value . width ) {
298
+ if ( getValue ( currData , i , ss ) . x > eventX / width ) {
300
299
idx = i ;
301
300
break ;
302
301
}
@@ -308,38 +307,32 @@ export default function ChartPathProvider({
308
307
if (
309
308
ss . value === 'bezier' &&
310
309
currData . value . length > 30 &&
311
- eventX / layoutSize . value . width >=
312
- currData . value [ currData . value . length - 2 ] . x
310
+ eventX / width >= currData . value [ currData . value . length - 2 ] . x
313
311
) {
314
312
const prevLastY = currData . value [ currData . value . length - 2 ] . y ;
315
313
const prevLastX = currData . value [ currData . value . length - 2 ] . x ;
316
314
const lastY = currData . value [ currData . value . length - 1 ] . y ;
317
315
const lastX = currData . value [ currData . value . length - 1 ] . x ;
318
- const progress =
319
- ( eventX / layoutSize . value . width - prevLastX ) / ( lastX - prevLastX ) ;
320
- positionY . value =
321
- ( prevLastY + progress * ( lastY - prevLastY ) ) *
322
- layoutSize . value . height ;
316
+ const progress = ( eventX / width - prevLastX ) / ( lastX - prevLastX ) ;
317
+ positionY . value = ( prevLastY + progress * ( lastY - prevLastY ) ) * height ;
323
318
} else if ( idx === 0 ) {
324
- positionY . value =
325
- getValue ( currData , idx , ss ) . y * layoutSize . value . height ;
319
+ positionY . value = getValue ( currData , idx , ss ) . y * height ;
326
320
} else {
327
321
// prev + diff over X
328
322
positionY . value =
329
323
( getValue ( currData , idx - 1 , ss ) . y +
330
324
( getValue ( currData , idx , ss ) . y -
331
325
getValue ( currData , idx - 1 , ss ) . y ) *
332
- ( ( eventX / layoutSize . value . width -
333
- getValue ( currData , idx - 1 , ss ) . x ) /
326
+ ( ( eventX / width - getValue ( currData , idx - 1 , ss ) . x ) /
334
327
( getValue ( currData , idx , ss ) . x -
335
328
getValue ( currData , idx - 1 , ss ) . x ) ) ) *
336
- layoutSize . value . height ;
329
+ height ;
337
330
}
338
331
339
332
setoriginalXYAccordingToPosition (
340
333
originalX ,
341
334
originalY ,
342
- eventX / layoutSize . value . width ,
335
+ eventX / width ,
343
336
curroriginalData
344
337
) ;
345
338
positionX . value = eventX ;
@@ -425,17 +418,13 @@ export default function ChartPathProvider({
425
418
}
426
419
isStarted . value = true ;
427
420
428
- const eventX = positionXWithMargin (
429
- event . x ,
430
- hitSlopValue . value ,
431
- layoutSize . value . width
432
- ) ;
421
+ const eventX = positionXWithMargin ( event . x , hitSlopValue . value , width ) ;
433
422
434
423
progress . value = 1 ;
435
424
let idx = 0 ;
436
425
const ss = smoothingStrategy ;
437
426
for ( let i = 0 ; i < currData . value . length ; i ++ ) {
438
- if ( getValue ( currData , i , ss ) . x > eventX / layoutSize . value . width ) {
427
+ if ( getValue ( currData , i , ss ) . x > eventX / width ) {
439
428
idx = i ;
440
429
break ;
441
430
}
@@ -447,38 +436,32 @@ export default function ChartPathProvider({
447
436
if (
448
437
ss . value === 'bezier' &&
449
438
currData . value . length > 30 &&
450
- eventX / layoutSize . value . width >=
451
- currData . value [ currData . value . length - 2 ] . x
439
+ eventX / width >= currData . value [ currData . value . length - 2 ] . x
452
440
) {
453
441
const prevLastY = currData . value [ currData . value . length - 2 ] . y ;
454
442
const prevLastX = currData . value [ currData . value . length - 2 ] . x ;
455
443
const lastY = currData . value [ currData . value . length - 1 ] . y ;
456
444
const lastX = currData . value [ currData . value . length - 1 ] . x ;
457
- const progress =
458
- ( eventX / layoutSize . value . width - prevLastX ) / ( lastX - prevLastX ) ;
459
- positionY . value =
460
- ( prevLastY + progress * ( lastY - prevLastY ) ) *
461
- layoutSize . value . height ;
445
+ const progress = ( eventX / width - prevLastX ) / ( lastX - prevLastX ) ;
446
+ positionY . value = ( prevLastY + progress * ( lastY - prevLastY ) ) * height ;
462
447
} else if ( idx === 0 ) {
463
- positionY . value =
464
- getValue ( currData , idx , ss ) . y * layoutSize . value . height ;
448
+ positionY . value = getValue ( currData , idx , ss ) . y * height ;
465
449
} else {
466
450
// prev + diff over X
467
451
positionY . value =
468
452
( getValue ( currData , idx - 1 , ss ) . y +
469
453
( getValue ( currData , idx , ss ) . y -
470
454
getValue ( currData , idx - 1 , ss ) . y ) *
471
- ( ( eventX / layoutSize . value . width -
472
- getValue ( currData , idx - 1 , ss ) . x ) /
455
+ ( ( eventX / width - getValue ( currData , idx - 1 , ss ) . x ) /
473
456
( getValue ( currData , idx , ss ) . x -
474
457
getValue ( currData , idx - 1 , ss ) . x ) ) ) *
475
- layoutSize . value . height ;
458
+ height ;
476
459
}
477
460
478
461
setoriginalXYAccordingToPosition (
479
462
originalX ,
480
463
originalY ,
481
- eventX / layoutSize . value . width ,
464
+ eventX / width ,
482
465
curroriginalData
483
466
) ;
484
467
positionX . value = eventX ;
@@ -506,7 +489,6 @@ export default function ChartPathProvider({
506
489
data,
507
490
dotStyle,
508
491
extremes,
509
- layoutSize,
510
492
onLongPressGestureEvent,
511
493
originalX,
512
494
originalY,
@@ -542,7 +524,6 @@ function ChartPath({
542
524
currSmoothing,
543
525
pathOpacity,
544
526
progress,
545
- layoutSize,
546
527
__disableRendering,
547
528
children,
548
529
...props
@@ -553,10 +534,6 @@ function ChartPath({
553
534
const selectedStrokeWidthValue = useSharedValue ( selectedStrokeWidth ) ;
554
535
const strokeWidthValue = useSharedValue ( strokeWidth ) ;
555
536
556
- useEffect ( ( ) => {
557
- layoutSize . value = { height, width } ;
558
- } , [ height , layoutSize , width ] ) ;
559
-
560
537
const path = useDerivedValue ( ( ) => {
561
538
let fromValue = prevData . value ;
562
539
let toValue = currData . value ;
@@ -605,16 +582,16 @@ function ChartPath({
605
582
606
583
res = fromValue . map ( ( { x, y } , i ) => {
607
584
const { x : nX , y : nY } = toValue [ i ] ;
608
- const mX = ( x + ( nX - x ) * progress . value ) * layoutSize . value . width ;
609
- const mY = ( y + ( nY - y ) * progress . value ) * layoutSize . value . height ;
585
+ const mX = ( x + ( nX - x ) * progress . value ) * width ;
586
+ const mY = ( y + ( nY - y ) * progress . value ) * height ;
610
587
return { x : mX , y : mY } ;
611
588
} ) ;
612
589
} else {
613
590
smoothing = currSmoothing . value ;
614
591
res = toValue . map ( ( { x, y } ) => {
615
592
return {
616
- x : x * layoutSize . value . width ,
617
- y : y * layoutSize . value . height ,
593
+ x : x * width ,
594
+ y : y * height ,
618
595
} ;
619
596
} ) ;
620
597
}
@@ -632,7 +609,7 @@ function ChartPath({
632
609
{ x : - res [ 4 ] . x , y : res [ 0 ] . y } ,
633
610
] . concat ( res ) ;
634
611
}
635
- if ( lastValue . x === layoutSize . value . width && strategy !== 'bezier' ) {
612
+ if ( lastValue . x === width && strategy !== 'bezier' ) {
636
613
// extrapolate the last points
637
614
res [ res . length - 1 ] . x = lastValue . x + 20 ;
638
615
if ( res . length > 2 ) {
@@ -656,7 +633,7 @@ function ChartPath({
656
633
} )
657
634
. join ( ' ' )
658
635
. replace ( 'L' , 'M' ) ;
659
- } ) ;
636
+ } , [ currData . value , prevData . value , smoothingStrategy . value , width , height ] ) ;
660
637
661
638
const animatedProps = useAnimatedStyle ( ( ) => {
662
639
const props = {
0 commit comments