@@ -28,15 +28,35 @@ const StreamingMarginalGraphics = () => {
2828 const [ containerRef , containerWidth ] = useContainerWidth ( )
2929
3030 useEffect ( ( ) => {
31+ // Box-Muller transform: pulls a sample from a standard normal so the
32+ // cloud has a natural Gaussian shape (dense in the middle, thinner
33+ // tails) instead of the boxy uniform-noise look the previous data
34+ // generator produced.
35+ const gauss = ( ) => {
36+ const u = 1 - Math . random ( )
37+ const v = Math . random ( )
38+ return Math . sqrt ( - 2 * Math . log ( u ) ) * Math . cos ( 2 * Math . PI * v )
39+ }
3140 const id = setInterval ( ( ) => {
32- if ( chartRef . current ) {
33- const i = indexRef . current ++
34- // Simulate a bivariate stream: x drifts with noise, y is correlated + noise
35- const x = 50 + Math . sin ( i * 0.03 ) * 30 + ( Math . random ( ) - 0.5 ) * 20
36- const y = x * 0.8 + ( Math . random ( ) - 0.5 ) * 25 + 20
37- chartRef . current . push ( { time : i , x, y } )
41+ if ( ! chartRef . current ) return
42+ // Push three samples per tick — at the configured `windowSize` of
43+ // 250 the chart keeps ~80 ticks of history (≈ 4s at the 50ms
44+ // cadence below), enough motion to see the cluster slide while
45+ // still looking like a populated cloud rather than a sparse
46+ // trail.
47+ const i = indexRef . current ++
48+ // Cluster mean drifts on a slow sine so the user can see the
49+ // distribution moving while the marginals reshape in lockstep.
50+ const cx = 50 + Math . sin ( i * 0.04 ) * 25
51+ const cy = 50 + Math . sin ( i * 0.04 + Math . PI / 3 ) * 25
52+ for ( let k = 0 ; k < 3 ; k ++ ) {
53+ const x = cx + gauss ( ) * 8
54+ // Strong positive correlation between x and y, with a small
55+ // independent residual so the cloud has visible spread.
56+ const y = cy + ( x - cx ) * 0.7 + gauss ( ) * 6
57+ chartRef . current . push ( { time : i * 3 + k , x, y } )
3858 }
39- } , 80 )
59+ } , 50 )
4060 return ( ) => clearInterval ( id )
4161 } , [ ] )
4262
@@ -67,7 +87,7 @@ The key is combining \`runtimeMode="streaming"\` with \`marginalGraphics\` on a
6787 size = { [ containerWidth , 400 ] }
6888 xAccessor = "x"
6989 yAccessor = "y"
70- windowSize = { 200 }
90+ windowSize = { 250 }
7191 pointStyle = { ( ) => ( {
7292 fill : theme [ 1 ] ,
7393 fillOpacity : 0.7 ,
0 commit comments