@@ -847,11 +847,11 @@ export function calcLinearProgression(plots) {
847847 if ( len < 2 ) return { x1 : 0 , y1 : 0 , x2 : 0 , y2 : 0 , slope : 0 , trend : 0 } ;
848848
849849 let sx = 0 , sy = 0 , sxy = 0 , sxx = 0 ;
850- for ( const { x, y } of plots ) {
851- sx += x ;
852- sy += y ;
853- sxy += x * y ;
854- sxx += x * x ;
850+ for ( const { x, y } of plots ) {
851+ sx += x ;
852+ sy += y ;
853+ sxy += x * y ;
854+ sxx += x * x ;
855855 }
856856 const denomPx = len * sxx - sx * sx || 1 ;
857857 const slopePx = ( len * sxy - sx * sy ) / denomPx ;
@@ -863,18 +863,18 @@ export function calcLinearProgression(plots) {
863863 const y2 = slopePx * x2 + interceptPx ;
864864
865865 let vx = 0 , vy = 0 , vxy = 0 , vxx = 0 ;
866- for ( let i = 0 ; i < len ; i += 1 ) {
867- vx += i ;
868- vy += plots [ i ] . value ;
869- vxy += i * plots [ i ] . value ;
870- vxx += i * i ;
866+ for ( let i = 0 ; i < len ; i += 1 ) {
867+ vx += i ;
868+ vy += plots [ i ] . value ;
869+ vxy += i * plots [ i ] . value ;
870+ vxx += i * i ;
871871 }
872872 const denomV = len * vxx - vx * vx || 1 ;
873873 const slopeV = ( len * vxy - vx * vy ) / denomV ;
874874 const interceptV = ( vy - slopeV * vx ) / len ;
875875
876876 const vStart = interceptV ;
877- const vEnd = slopeV * ( len - 1 ) + interceptV ;
877+ const vEnd = slopeV * ( len - 1 ) + interceptV ;
878878
879879 const EPS = 1e-9 ;
880880 const scale = Math . max ( Math . abs ( vStart ) , Math . abs ( vy / len ) , Math . abs ( vEnd ) , EPS ) ;
@@ -3265,6 +3265,41 @@ export function triggerEvent(el, type, opts = {}) {
32653265 return ev ;
32663266}
32673267
3268+ export function triggerResize ( el , { delta = 1 , delay = 20 , disableTransitions = true } = { } ) {
3269+ if ( ! el || ! ( el instanceof HTMLElement ) ) return ;
3270+
3271+ const style = el . style ;
3272+
3273+ const prev = {
3274+ width : style . width ,
3275+ height : style . height ,
3276+ transition : style . transition ,
3277+ } ;
3278+
3279+ const rect = el . getBoundingClientRect ( ) ;
3280+ const w = rect . width ;
3281+ const h = rect . height ;
3282+
3283+ if ( disableTransitions ) {
3284+ style . transition = 'none' ;
3285+ }
3286+
3287+ style . width = `${ Math . max ( 0 , w + delta ) } px` ;
3288+ style . height = `${ Math . max ( 0 , h + delta ) } px` ;
3289+ el . offsetWidth ;
3290+
3291+ setTimeout ( ( ) => {
3292+ style . width = prev . width ;
3293+ style . height = prev . height ;
3294+ el . offsetWidth ;
3295+ requestAnimationFrame ( ( ) => {
3296+ if ( disableTransitions ) {
3297+ style . transition = prev . transition ;
3298+ }
3299+ } ) ;
3300+ } , delay ) ;
3301+ }
3302+
32683303const lib = {
32693304 XMLNS ,
32703305 abbreviate,
@@ -3364,6 +3399,7 @@ const lib = {
33643399 translateSize,
33653400 treeShake,
33663401 triggerEvent,
3402+ triggerResize,
33673403 wrapText
33683404} ;
33693405export default lib ;
0 commit comments