import { MarkModel } from './MarkModel' ; import * as serialize from './serialize' ; export class ScatterBaseModel extends MarkModel { defaults ( ) { return { ... MarkModel . prototype . defaults ( ) , _model_name : 'ScatterBaseModel' , _view_name : 'ScatterBase' , x : [ ] , y : [ ] , color : null , opacity : null , size : null , rotation : null , hovered_point : null , scales_metadata : { x : { orientation : 'horizontal' , dimension : 'x' } , y : { orientation : 'vertical' , dimension : 'y' } , color : { dimension : 'color' } , size : { dimension : 'size' } , opacity : { dimension : 'opacity' } , rotation : { dimension : 'rotation' } , } , label_display_horizontal_offset : null , label_display_vertical_offset : null , hovered_style : { } , unhovered_style : { } , colors : [ 'steelblue' ] , opacities : [ 1.0 ] , enable_move : false , enable_delete : false , restrict_x : false , restrict_y : false , update_on_move : false , } ; } initialize ( attributes , options ) { super . initialize ( attributes , options ) ; this . on_some_change ( [ 'x' , 'y' , 'color' , 'opacity' , 'size' , 'rotation' ] , this . update_data , this ) ; this . on_some_change ( [ 'preserve_domain' ] , this . update_domains , this ) ; this . update_data ( ) ; } update_mark_data ( ) { let x_data = this . get ( 'x' ) ; const y_data = this . get ( 'y' ) ; if ( x_data . length === 0 || y_data . length === 0 ) { this . mark_data = [ ] ; } else { const min_len = Math . min ( x_data . length , y_data . length ) ; x_data = x_data . slice ( 0 , min_len ) ; const color = this . get ( 'color' ) || [ ] , size = this . get ( 'size' ) || [ ] , opacity = this . get ( 'opacity' ) || [ ] , rotation = this . get ( 'rotation' ) || [ ] ; this . mark_data = Array . prototype . map . call ( x_data , ( d , i ) => { return { x : d , y : y_data [ i ] , color : color [ i ] , size : size [ i ] , opacity : opacity [ i ] , rotation : rotation [ i ] , index : i , } ; } ) ; } } update_data ( ) { this . dirty = true ; this . update_mark_data ( ) ; this . update_unique_ids ( ) ; this . update_domains ( ) ; this . dirty = false ; this . trigger ( 'data_updated' ) ; } update_unique_ids ( ) { } get_data_dict ( data , index ) { return data ; } update_domains ( ) { if ( ! this . mark_data ) { return ; } const scales = this . getScales ( ) ; for ( const key in scales ) { if ( scales . hasOwnProperty ( key ) ) { const scale = scales [ key ] ; if ( ! this . get ( 'preserve_domain' ) [ key ] ) { scale . computeAndSetDomain ( this . mark_data . map ( ( elem ) => { return elem [ key ] ; } ) , this . model_id + key ) ; } else { scale . delDomain ( [ ] , this . model_id + key ) ; } } } } static serializers = { ... MarkModel . serializers , x : serialize . array_or_json_serializer , y : serialize . array_or_json_serializer , color : serialize . array_or_json_serializer , opacity : serialize . array_or_json_serializer , size : serialize . array_or_json_serializer , rotation : serialize . array_or_json_serializer , opacities : serialize . array_or_json_serializer , } ; }