import { Animation } from "../animations/animation" ; import { FadeOut } from "../animations/fadeOut" ; import { svgWidth , svgHeight , TYPES } from "../cubicons/constants" ; import { Cubicon } from "../cubicons/cubicon" ; import { Scene } from "./scene" ; /**
 * The dad/mom object of every pack of objects in the visualization.
 *
 * Please see the Quick Start page in official documentation for clearer understanding about this `Group` term.
 */ export class Group { /**
     * The scene that this group belongs to.
     */ scene : Scene ; /**
     * The `<svg/>` element that represents this group.
     */ svg_group : any ; /**
     * Name of this group.
     */ name : string ; /**
     * Cubicons included in this group.
     */ cubicons : Cubicon [ ] ; /**
     * Animations played in this group.
     */ animations : Animation [ ] ; /**
     * The total time to finish playing all animations in the current queue (will be override when the next queue is called). (in milliseconds)
     */ queueElapsed : number ; /**
     * The time passed by since this group was created. (in milliseconds)
     *
     * > (aka the total time of all the animations **called** in this group)
     */ groupElapsed : number ; /**
     * The total time before this group is created. (in milliseconds)
     *
     * > (aka the total time of all the animations **called** in **other** groups in the same scene)
     */ sleepTime : number ; param groupName param scene constructor ( groupName , scene ) { this . scene = scene ; this . svg_group = ! scene . svg_scene . select ( `#${ groupName }` ) . empty ( ) ? scene . svg_scene . select ( `#${ groupName }` ) : scene . svg_scene . append ( "svg" ) . attr ( "id" , `${ groupName }` ) . attr ( "class" , "group" ) . attr ( "viewBox" , `${ - svgWidth / 2 } ${ - svgHeight / 2 } ${ svgWidth } ${ svgHeight }` ) ; this . name = groupName ; this . cubicons = [ ] ; this . animations = [ ] ; this . queueElapsed = 0 ; this . groupElapsed = 0 ; this . sleepTime = 0 ; } param cubicons render ( ... cubicons ) { cubicons . forEach ( ( cubicon ) => { cubicon . render ( ) ; } ) ; } param anims play ( anims ) { anims . forEach ( ( anim ) => { anim . cubicon . elapsedTime = this . queueElapsed ; if ( typeof anim . projectors !== "undefined" ) { anim . projectors . forEach ( ( p ) => ( p . elapsedTime = this . queueElapsed ) ) ; } } ) ; anims . forEach ( ( anim ) => { this . addAnimation ( anim ) ; try { anim . play ( this . sleepTime ) ; } catch ( err ) { } this . sleepTime = 0 ; } ) ; this . queueElapsed = Math . max ( ... anims . map ( ( anim ) => anim . cubicon . elapsedTime ) ) ; anims . forEach ( ( a ) => { a . cubicon . elapsedTime = this . queueElapsed ; } ) ; this . groupElapsed = this . queueElapsed ; } param milliseconds sleep ( milliseconds ) { this . sleepTime = milliseconds ; } private addAnimation ( anim ) { this . animations . push ( anim ) ; } deprecated add ( cubicon ) { this . cubicons . push ( cubicon ) ; } param cubicon remove ( cubicon ) { if ( cubicon . cubType === "geometry" ) { cubicon . group . play ( [ new FadeOut ( { cubicon : cubicon } ) ] ) ; } cubicon . def_cubiconBase . transition ( ) . delay ( cubicon . elapsedTime + this . groupElapsed ) . duration ( 0 ) . remove ( ) ; } param delay destroy ( delay ) { this . svg_group . transition ( ) . delay ( this . groupElapsed + delay ) . duration ( 500 ) . style ( "opacity" , 0 ) . remove ( ) ; } }