namespace Impact { export class Impact implements Structure . Tab { public people : Impact . People ; private static PRELOAD_INTERVAL = 100 ; constructor ( public svg ) { this . people = new People ( ) ; } public build ( set ) { let thresholds = [ 999 , 0 ] , canvas = Vector . sub ( Helpers . canvasDimensions ( this . svg ) , new Vector ( 0 , 20 ) ) ; this . people . clear ( ) ; set . forEach ( ( p ) => { let randomPosition = Vector . randomized ( new Vector ( 150 , 20 ) , canvas ) , impact = p . impact ; this . people . push ( new Person ( this . svg , p , randomPosition ) ) ; if ( impact < thresholds [ 0 ] ) { thresholds [ 0 ] = impact ; } else if ( impact > thresholds [ 1 ] ) { thresholds [ 1 ] = impact ; } } ) ; if ( thresholds [ 0 ] !== thresholds [ 1 ] ) { this . people . forEach ( ( p ) => p . normalizePadding ( thresholds ) ) ; } return this . built ( ) ; } public preload ( callback , iteration = 1 ) { if ( iteration < 60 ) { for ( let p of this . people . collection ) { if ( ! p . preloaded ( ) ) { setTimeout ( ( ) => this . preload ( callback , iteration + 1 ) , Impact . PRELOAD_INTERVAL ) ; return ; } } } callback ( ) ; } public execute ( overlay = false ) { $ ( "#people_list" ) . show ( ) ; this . setResolution ( "High" ) ; this . people . pack ( ( ) => { if ( overlay ) { let toHighlight = this . people . closestToCenter ( ) ; let pioneerHighlight = $ ( "#pioneer_highlight_overlay" ) ; let v = toHighlight . bottomRight ( ) ; let y = ( v . y - ( pioneerHighlight . height ( ) / 2 ) - toHighlight . radius ) + Helpers . headerOffset ( ) ; pioneerHighlight . css ( { top : y , left : v . x + 31 } ) ; Helpers . signalHighlightOverlays ( ) ; } } ) ; } public unfocus ( ) { this . people . reset ( ) ; $ ( "#people_list" ) . hide ( ) ; $ ( "#people_list ul" ) . empty ( ) ; } public resize ( w , h ) { this . people . centerize ( w , h ) ; } public built ( ) { return this . people . collection . length > 0 ; } public setResolution ( r ) { this . people . resolution = r ; } } }