<s> """<STR_LIT>""" <EOL> from itertools import groupby , product <EOL> from collections import Counter , defaultdict <EOL> import numpy as np <EOL> import param <EOL> from . . core import OrderedDict <EOL> from . . core import util , traversal <EOL> from . . core . element import Element <EOL> from . . core . overlay import Overlay , CompositeOverlay <EOL> from . . core . layout import Empty , NdLayout , Layout <EOL> from . . core . options import Store , Compositor <EOL> from . . core . spaces import HoloMap , DynamicMap <EOL> from . . element import Table <EOL> from . util import get_dynamic_mode , initialize_sampled , dim_axis_label <EOL> class BackendError ( Exception ) : <EOL> def __init__ ( self , backend ) : <EOL> msg = "<STR_LIT>" % backend <EOL> super ( BackendError , self ) . __init__ ( msg ) <EOL> self . backend = backend <EOL> class Plot ( param . Parameterized ) : <EOL> """<STR_LIT>""" <EOL> style_opts = [ ] <EOL> _disabled_opts = [ ] <EOL> def initialize_plot ( self , ranges = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def update ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return self . state <EOL> @ property <EOL> def state ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def __len__ ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> @ classmethod <EOL> def lookup_options ( cls , obj , group ) : <EOL> return Store . lookup_options ( cls . renderer . backend , obj , group ) <EOL> class PlotSelector ( object ) : <EOL> """<STR_LIT>""" <EOL> _disabled_opts = [ ] <EOL> def __init__ ( self , selector , plot_classes , allow_mismatch = False ) : <EOL> """<STR_LIT>""" <EOL> self . selector = selector <EOL> self . plot_classes = OrderedDict ( plot_classes ) <EOL> interface = self . _define_interface ( self . plot_classes . values ( ) , allow_mismatch ) <EOL> self . style_opts , self . plot_options = interface <EOL> def _define_interface ( self , plots , allow_mismatch ) : <EOL> parameters = [ { k : v . precedence for k , v in plot . params ( ) . items ( ) <EOL> if ( ( v . precedence is None ) or ( v . precedence >= <NUM_LIT:0> ) ) } <EOL> for plot in plots ] <EOL> param_sets = [ set ( params . keys ( ) ) for params in parameters ] <EOL> if not allow_mismatch and not all ( pset == param_sets [ <NUM_LIT:0> ] for pset in param_sets ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> styles = [ plot . style_opts for plot in plots ] <EOL> if not allow_mismatch and not all ( style == styles [ <NUM_LIT:0> ] for style in styles ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return styles [ <NUM_LIT:0> ] , parameters [ <NUM_LIT:0> ] <EOL> def __call__ ( self , obj , ** kwargs ) : <EOL> key = self . selector ( obj ) <EOL> if key not in self . plot_classes : <EOL> msg = "<STR_LIT>" <EOL> raise Exception ( msg % ( key , '<STR_LIT:U+002CU+0020>' . join ( self . plot_classes . keys ( ) ) ) ) <EOL> return self . plot_classes [ key ] ( obj , ** kwargs ) <EOL> def __setattr__ ( self , label , value ) : <EOL> try : <EOL> return super ( PlotSelector , self ) . __setattr__ ( label , value ) <EOL> except : <EOL> raise Exception ( "<STR_LIT>" <EOL> % '<STR_LIT:U+002CU+0020>' . join ( str ( cls ) for cls in self . __dict__ [ '<STR_LIT>' ] . values ( ) ) ) <EOL> def params ( self ) : <EOL> return self . plot_options <EOL> class DimensionedPlot ( Plot ) : <EOL> """<STR_LIT>""" <EOL> fontsize = param . Parameter ( default = None , allow_None = True , doc = """<STR_LIT>""" ) <EOL> _fontsize_keys = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> show_title = param . Boolean ( default = True , doc = """<STR_LIT>""" ) <EOL> title_format = param . String ( default = "<STR_LIT>" , doc = """<STR_LIT>""" ) <EOL> normalize = param . Boolean ( default = True , doc = """<STR_LIT>""" ) <EOL> projection = param . Parameter ( default = None , doc = """<STR_LIT>""" ) <EOL> def __init__ ( self , keys = None , dimensions = None , layout_dimensions = None , <EOL> uniform = True , subplot = False , adjoined = None , layout_num = <NUM_LIT:0> , <EOL> style = None , subplots = None , dynamic = False , ** params ) : <EOL> self . subplots = subplots <EOL> self . adjoined = adjoined <EOL> self . dimensions = dimensions <EOL> self . layout_num = layout_num <EOL> self . layout_dimensions = layout_dimensions <EOL> self . subplot = subplot <EOL> self . keys = keys <EOL> self . uniform = uniform <EOL> self . dynamic = dynamic <EOL> self . drawn = False <EOL> self . handles = { } <EOL> self . group = None <EOL> self . label = None <EOL> self . current_frame = None <EOL> self . current_key = None <EOL> self . ranges = { } <EOL> params = { k : v for k , v in params . items ( ) <EOL> if k in self . params ( ) } <EOL> super ( DimensionedPlot , self ) . __init__ ( ** params ) <EOL> def __getitem__ ( self , frame ) : <EOL> """<STR_LIT>""" <EOL> if not self . dynamic == '<STR_LIT>' and isinstance ( frame , int ) and frame > len ( self ) : <EOL> self . warning ( "<STR_LIT>" % len ( self ) ) <EOL> if not self . drawn : self . handles [ '<STR_LIT>' ] = self . initialize_plot ( ) <EOL> if not self . dynamic == '<STR_LIT>' and not isinstance ( frame , tuple ) : <EOL> frame = self . keys [ frame ] <EOL> self . update_frame ( frame ) <EOL> return self . state <EOL> def _get_frame ( self , key ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def matches ( self , spec ) : <EOL> """<STR_LIT>""" <EOL> if callable ( spec ) and not isinstance ( spec , type ) : return spec ( self ) <EOL> elif isinstance ( spec , type ) : return isinstance ( self , spec ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def traverse ( self , fn = None , specs = None , full_breadth = True ) : <EOL> """<STR_LIT>""" <EOL> accumulator = [ ] <EOL> matches = specs is None <EOL> if not matches : <EOL> for spec in specs : <EOL> matches = self . matches ( spec ) <EOL> if matches : break <EOL> if matches : <EOL> accumulator . append ( fn ( self ) if fn else self ) <EOL> if hasattr ( self , '<STR_LIT>' ) and self . subplots : <EOL> for el in self . subplots . values ( ) : <EOL> accumulator += el . traverse ( fn , specs , full_breadth ) <EOL> if not full_breadth : break <EOL> return accumulator <EOL> def _frame_title ( self , key , group_size = <NUM_LIT:2> , separator = '<STR_LIT:\n>' ) : <EOL> """<STR_LIT>""" <EOL> if self . dynamic == '<STR_LIT>' and self . current_key : <EOL> key = self . current_key <EOL> if self . layout_dimensions is not None : <EOL> dimensions , key = zip ( * self . layout_dimensions . items ( ) ) <EOL> elif not self . dynamic and ( not self . uniform or len ( self ) == <NUM_LIT:1> ) or self . subplot : <EOL> return '<STR_LIT>' <EOL> else : <EOL> key = key if isinstance ( key , tuple ) else ( key , ) <EOL> dimensions = self . dimensions <EOL> dimension_labels = [ dim . pprint_value_string ( k ) for dim , k in <EOL> zip ( dimensions , key ) ] <EOL> groups = [ '<STR_LIT:U+002CU+0020>' . join ( dimension_labels [ i * group_size : ( i + <NUM_LIT:1> ) * group_size ] ) <EOL> for i in range ( len ( dimension_labels ) ) ] <EOL> return util . safe_unicode ( separator . join ( g for g in groups if g ) ) <EOL> def _fontsize ( self , key , label = '<STR_LIT>' , common = True ) : <EOL> if not self . fontsize : return { } <EOL> if not isinstance ( self . fontsize , dict ) : <EOL> return { label : self . fontsize } if common else { } <EOL> unknown_keys = set ( self . fontsize . keys ( ) ) - set ( self . _fontsize_keys ) <EOL> if unknown_keys : <EOL> msg = "<STR_LIT>" <EOL> self . warning ( msg % ( list ( unknown_keys ) , self . _fontsize_keys ) ) <EOL> for key in unknown_keys : self . fontsize . pop ( key , None ) <EOL> if key in self . fontsize : <EOL> return { label : self . fontsize [ key ] } <EOL> elif key in [ '<STR_LIT>' , '<STR_LIT>' ] and '<STR_LIT>' in self . fontsize : <EOL> return { label : self . fontsize [ '<STR_LIT>' ] } <EOL> else : <EOL> return { } <EOL> def compute_ranges ( self , obj , key , ranges ) : <EOL> """<STR_LIT>""" <EOL> all_table = all ( isinstance ( el , Table ) for el in obj . traverse ( lambda x : x , [ Element ] ) ) <EOL> if obj is None or not self . normalize or all_table : <EOL> return OrderedDict ( ) <EOL> ranges = self . ranges if ranges is None else dict ( ranges ) <EOL> norm_opts = self . _get_norm_opts ( obj ) <EOL> return_fn = lambda x : x if isinstance ( x , Element ) else None <EOL> for group , ( axiswise , framewise ) in norm_opts . items ( ) : <EOL> elements = [ ] <EOL> framewise = framewise or self . dynamic <EOL> if group in ranges and ( not framewise or ranges is not self . ranges ) : <EOL> continue <EOL> elif not framewise : <EOL> elements = obj . traverse ( return_fn , [ group ] ) <EOL> elif key is not None : <EOL> frame = self . _get_frame ( key ) <EOL> elements = [ ] if frame is None else frame . traverse ( return_fn , [ group ] ) <EOL> if not axiswise or ( ( not framewise or len ( elements ) == <NUM_LIT:1> ) <EOL> and isinstance ( obj , HoloMap ) ) : <EOL> self . _compute_group_range ( group , elements , ranges ) <EOL> self . ranges . update ( ranges ) <EOL> return ranges <EOL> def _get_norm_opts ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> norm_opts = { } <EOL> type_val_fn = lambda x : ( x . id , ( type ( x ) . __name__ , util . group_sanitizer ( x . group , escape = False ) , <EOL> util . label_sanitizer ( x . label , escape = False ) ) ) if isinstance ( x , Element ) else None <EOL> element_specs = { ( idspec [ <NUM_LIT:0> ] , idspec [ <NUM_LIT:1> ] ) for idspec in obj . traverse ( type_val_fn ) <EOL> if idspec is not None } <EOL> key_fn = lambda x : - <NUM_LIT:1> if x [ <NUM_LIT:0> ] is None else x [ <NUM_LIT:0> ] <EOL> id_groups = groupby ( sorted ( element_specs , key = key_fn ) , key_fn ) <EOL> for gid , element_spec_group in id_groups : <EOL> gid = None if gid == - <NUM_LIT:1> else gid <EOL> group_specs = [ el for _ , el in element_spec_group ] <EOL> backend = self . renderer . backend <EOL> optstree = Store . custom_options ( <EOL> backend = backend ) . get ( gid , Store . options ( backend = backend ) ) <EOL> for opts in optstree : <EOL> path = tuple ( opts . path . split ( '<STR_LIT:.>' ) [ <NUM_LIT:1> : ] ) <EOL> applies = any ( path == spec [ : i ] for spec in group_specs <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:4> ) ) <EOL> if applies and '<STR_LIT>' in opts . groups : <EOL> nopts = opts [ '<STR_LIT>' ] . options <EOL> if '<STR_LIT>' in nopts or '<STR_LIT>' in nopts : <EOL> norm_opts . update ( { path : ( nopts . get ( '<STR_LIT>' , False ) , <EOL> nopts . get ( '<STR_LIT>' , False ) ) } ) <EOL> element_specs = [ spec for eid , spec in element_specs ] <EOL> norm_opts . update ( { spec : ( False , False ) for spec in element_specs <EOL> if not any ( spec [ : i ] in norm_opts . keys ( ) for i in range ( <NUM_LIT:1> , <NUM_LIT:4> ) ) } ) <EOL> return norm_opts <EOL> @ staticmethod <EOL> def _compute_group_range ( group , elements , ranges ) : <EOL> elements = [ el for el in elements if el is not None ] <EOL> group_ranges = OrderedDict ( ) <EOL> for el in elements : <EOL> if isinstance ( el , ( Empty , Table ) ) : continue <EOL> for dim in el . dimensions ( label = True ) : <EOL> dim_range = el . range ( dim ) <EOL> if dim not in group_ranges : <EOL> group_ranges [ dim ] = [ ] <EOL> group_ranges [ dim ] . append ( dim_range ) <EOL> ranges [ group ] = OrderedDict ( ( k , util . max_range ( v ) ) for k , v in group_ranges . items ( ) ) <EOL> @ classmethod <EOL> def _traverse_options ( cls , obj , opt_type , opts , specs = None , keyfn = None , defaults = True ) : <EOL> """<STR_LIT>""" <EOL> def lookup ( x ) : <EOL> """<STR_LIT>""" <EOL> options = cls . lookup_options ( x , opt_type ) <EOL> selected = { o : options . options [ o ] <EOL> for o in opts if o in options . options } <EOL> if opt_type == '<STR_LIT>' and defaults : <EOL> plot = Store . registry [ cls . renderer . backend ] . get ( type ( x ) ) <EOL> selected [ '<STR_LIT>' ] = { o : getattr ( plot , o ) for o in opts <EOL> if o not in selected and hasattr ( plot , o ) } <EOL> key = keyfn ( x ) if keyfn else None <EOL> return ( key , selected ) <EOL> traversed = obj . traverse ( lookup , specs ) <EOL> options = defaultdict ( lambda : defaultdict ( list ) ) <EOL> default_opts = defaultdict ( lambda : defaultdict ( list ) ) <EOL> for key , opts in traversed : <EOL> defaults = opts . pop ( '<STR_LIT>' , { } ) <EOL> for opt , v in opts . items ( ) : <EOL> options [ key ] [ opt ] . append ( v ) <EOL> for opt , v in defaults . items ( ) : <EOL> default_opts [ key ] [ opt ] . append ( v ) <EOL> for key , opts in default_opts . items ( ) : <EOL> for opt , v in opts . items ( ) : <EOL> if opt not in options [ key ] : <EOL> options [ key ] [ opt ] = v <EOL> return options if keyfn else options [ None ] <EOL> def _get_projection ( cls , obj ) : <EOL> """<STR_LIT>""" <EOL> isoverlay = lambda x : isinstance ( x , CompositeOverlay ) <EOL> opts = cls . _traverse_options ( obj , '<STR_LIT>' , [ '<STR_LIT>' ] , <EOL> [ CompositeOverlay , Element ] , <EOL> keyfn = isoverlay ) <EOL> from_overlay = not all ( p is None for p in opts [ True ] [ '<STR_LIT>' ] ) <EOL> projections = opts [ from_overlay ] [ '<STR_LIT>' ] <EOL> custom_projs = [ p for p in projections if p is not None ] <EOL> if len ( set ( custom_projs ) ) > <NUM_LIT:1> : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return custom_projs [ <NUM_LIT:0> ] if custom_projs else None <EOL> def update ( self , key ) : <EOL> if len ( self ) == <NUM_LIT:1> and key == <NUM_LIT:0> and not self . drawn : <EOL> return self . initialize_plot ( ) <EOL> return self . __getitem__ ( key ) <EOL> def __len__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return len ( self . keys ) <EOL> class GenericElementPlot ( DimensionedPlot ) : <EOL> """<STR_LIT>""" <EOL> apply_ranges = param . Boolean ( default = True , doc = """<STR_LIT>""" ) <EOL> apply_extents = param . Boolean ( default = True , doc = """<STR_LIT>""" ) <EOL> def __init__ ( self , element , keys = None , ranges = None , dimensions = None , <EOL> overlaid = <NUM_LIT:0> , cyclic_index = <NUM_LIT:0> , zorder = <NUM_LIT:0> , style = None , overlay_dims = { } , <EOL> ** params ) : <EOL> self . zorder = zorder <EOL> self . cyclic_index = cyclic_index <EOL> self . overlaid = overlaid <EOL> self . overlay_dims = overlay_dims <EOL> if not isinstance ( element , ( HoloMap , DynamicMap ) ) : <EOL> self . hmap = HoloMap ( initial_items = ( <NUM_LIT:0> , element ) , <EOL> kdims = [ '<STR_LIT>' ] , id = element . id ) <EOL> else : <EOL> self . hmap = element <EOL> self . style = self . lookup_options ( self . hmap . last , '<STR_LIT>' ) if style is None else style <EOL> dimensions = self . hmap . kdims if dimensions is None else dimensions <EOL> keys = keys if keys else list ( self . hmap . data . keys ( ) ) <EOL> plot_opts = self . lookup_options ( self . hmap . last , '<STR_LIT>' ) . options <EOL> dynamic = False if not isinstance ( element , DynamicMap ) or element . sampled else element . mode <EOL> super ( GenericElementPlot , self ) . __init__ ( keys = keys , dimensions = dimensions , <EOL> dynamic = dynamic , <EOL> ** dict ( params , ** plot_opts ) ) <EOL> def _get_frame ( self , key ) : <EOL> if isinstance ( self . hmap , DynamicMap ) and self . overlaid and self . current_frame : <EOL> self . current_key = key <EOL> return self . current_frame <EOL> elif self . dynamic : <EOL> key , frame = util . get_dynamic_item ( self . hmap , self . dimensions , key ) <EOL> if not isinstance ( key , tuple ) : key = ( key , ) <EOL> if not key in self . keys : <EOL> self . keys . append ( key ) <EOL> self . current_frame = frame <EOL> self . current_key = key <EOL> return frame <EOL> if isinstance ( key , int ) : <EOL> key = self . hmap . keys ( ) [ min ( [ key , len ( self . hmap ) - <NUM_LIT:1> ] ) ] <EOL> if key == self . current_key : <EOL> return self . current_frame <EOL> else : <EOL> self . current_key = key <EOL> if self . uniform : <EOL> if not isinstance ( key , tuple ) : key = ( key , ) <EOL> kdims = [ d . name for d in self . hmap . kdims ] <EOL> if self . dimensions is None : <EOL> dimensions = kdims <EOL> else : <EOL> dimensions = [ d . name for d in self . dimensions ] <EOL> if kdims == [ '<STR_LIT>' ] and kdims != dimensions : <EOL> select = dict ( Frame = <NUM_LIT:0> ) <EOL> else : <EOL> select = { d : key [ dimensions . index ( d ) ] <EOL> for d in kdims } <EOL> else : <EOL> select = dict ( zip ( self . hmap . dimensions ( '<STR_LIT:key>' , label = True ) , key ) ) <EOL> try : <EOL> selection = self . hmap . select ( ( HoloMap , DynamicMap ) , ** select ) <EOL> except KeyError : <EOL> selection = None <EOL> selection = selection . last if isinstance ( selection , HoloMap ) else selection <EOL> self . current_frame = selection <EOL> return selection <EOL> def get_extents ( self , view , ranges ) : <EOL> """<STR_LIT>""" <EOL> ndims = len ( view . dimensions ( ) ) <EOL> num = <NUM_LIT:6> if self . projection == '<STR_LIT>' else <NUM_LIT:4> <EOL> if self . apply_ranges : <EOL> if ranges : <EOL> dims = view . dimensions ( ) <EOL> x0 , x1 = ranges [ dims [ <NUM_LIT:0> ] . name ] <EOL> if ndims > <NUM_LIT:1> : <EOL> y0 , y1 = ranges [ dims [ <NUM_LIT:1> ] . name ] <EOL> else : <EOL> y0 , y1 = ( np . NaN , np . NaN ) <EOL> if self . projection == '<STR_LIT>' : <EOL> if len ( dims ) > <NUM_LIT:2> : <EOL> z0 , z1 = ranges [ dims [ <NUM_LIT:2> ] . name ] <EOL> else : <EOL> z0 , z1 = np . NaN , np . NaN <EOL> else : <EOL> x0 , x1 = view . range ( <NUM_LIT:0> ) <EOL> y0 , y1 = view . range ( <NUM_LIT:1> ) if ndims > <NUM_LIT:1> else ( np . NaN , np . NaN ) <EOL> if self . projection == '<STR_LIT>' : <EOL> z0 , z1 = view . range ( <NUM_LIT:2> ) <EOL> if self . projection == '<STR_LIT>' : <EOL> range_extents = ( x0 , y0 , z0 , x1 , y1 , z1 ) <EOL> else : <EOL> range_extents = ( x0 , y0 , x1 , y1 ) <EOL> else : <EOL> range_extents = ( np . NaN , ) * num <EOL> if self . apply_extents : <EOL> norm_opts = self . lookup_options ( view , '<STR_LIT>' ) . options <EOL> if norm_opts . get ( '<STR_LIT>' , False ) or self . dynamic : <EOL> extents = view . extents <EOL> else : <EOL> extent_list = self . hmap . traverse ( lambda x : x . extents , [ Element ] ) <EOL> extents = util . max_extents ( extent_list , self . projection == '<STR_LIT>' ) <EOL> else : <EOL> extents = ( np . NaN , ) * num <EOL> return tuple ( l1 if l2 is None or not np . isfinite ( l2 ) else <EOL> l2 for l1 , l2 in zip ( range_extents , extents ) ) <EOL> def _get_axis_labels ( self , dimensions , xlabel = None , ylabel = None , zlabel = None ) : <EOL> if dimensions and xlabel is None : <EOL> xlabel = dim_axis_label ( dimensions [ <NUM_LIT:0> ] ) <EOL> if len ( dimensions ) >= <NUM_LIT:2> and ylabel is None : <EOL> ylabel = dim_axis_label ( dimensions [ <NUM_LIT:1> ] ) <EOL> if self . projection == '<STR_LIT>' and len ( dimensions ) >= <NUM_LIT:3> and zlabel is None : <EOL> zlabel = dim_axis_label ( dimensions [ <NUM_LIT:2> ] ) <EOL> return xlabel , ylabel , zlabel <EOL> def _format_title ( self , key , separator = '<STR_LIT:\n>' ) : <EOL> frame = self . _get_frame ( key ) <EOL> if frame is None : return None <EOL> type_name = type ( frame ) . __name__ <EOL> group = frame . group if frame . group != type_name else '<STR_LIT>' <EOL> label = frame . label <EOL> dim_title = self . _frame_title ( key , separator = separator ) <EOL> if self . layout_dimensions : <EOL> title = dim_title <EOL> else : <EOL> title_format = util . safe_unicode ( self . title_format ) <EOL> title = title_format . format ( label = util . safe_unicode ( label ) , <EOL> group = util . safe_unicode ( group ) , <EOL> type = type_name , <EOL> dimensions = dim_title ) <EOL> return title . strip ( '<STR_LIT>' ) <EOL> def update_frame ( self , key , ranges = None ) : <EOL> """<STR_LIT>""" <EOL> class GenericOverlayPlot ( GenericElementPlot ) : <EOL> """<STR_LIT>""" <EOL> show_legend = param . Boolean ( default = False , doc = """<STR_LIT>""" ) <EOL> style_grouping = param . Integer ( default = <NUM_LIT:2> , <EOL> doc = """<STR_LIT>""" ) <EOL> _passed_handles = [ ] <EOL> def __init__ ( self , overlay , ranges = None , ** params ) : <EOL> super ( GenericOverlayPlot , self ) . __init__ ( overlay , ranges = ranges , ** params ) <EOL> self . hmap = Compositor . collapse ( self . hmap , None , mode = '<STR_LIT:data>' ) <EOL> self . hmap = self . _apply_compositor ( self . hmap , ranges , self . keys ) <EOL> self . subplots = self . _create_subplots ( ranges ) <EOL> def _apply_compositor ( self , holomap , ranges = None , keys = None , dimensions = None ) : <EOL> """<STR_LIT>""" <EOL> defaultdim = holomap . ndims == <NUM_LIT:1> and holomap . kdims [ <NUM_LIT:0> ] . name != '<STR_LIT>' <EOL> if keys and ranges and dimensions and not defaultdim : <EOL> dim_inds = [ dimensions . index ( d ) for d in holomap . kdims ] <EOL> sliced_keys = [ tuple ( k [ i ] for i in dim_inds ) for k in keys ] <EOL> frame_ranges = OrderedDict ( [ ( slckey , self . compute_ranges ( holomap , key , ranges [ key ] ) ) <EOL> for key , slckey in zip ( keys , sliced_keys ) if slckey in holomap . data . keys ( ) ] ) <EOL> else : <EOL> mapwise_ranges = self . compute_ranges ( holomap , None , None ) <EOL> frame_ranges = OrderedDict ( [ ( key , self . compute_ranges ( holomap , key , mapwise_ranges ) ) <EOL> for key in holomap . keys ( ) ] ) <EOL> ranges = frame_ranges . values ( ) <EOL> return Compositor . collapse ( holomap , ( ranges , frame_ranges . keys ( ) ) , mode = '<STR_LIT>' ) <EOL> def _create_subplots ( self , ranges ) : <EOL> subplots = OrderedDict ( ) <EOL> length = self . style_grouping <EOL> ordering = util . layer_sort ( self . hmap ) <EOL> keys , vmaps = self . hmap . split_overlays ( ) <EOL> group_fn = lambda x : ( x . type . __name__ , x . last . group , x . last . label ) <EOL> map_lengths = Counter ( ) <EOL> for m in vmaps : <EOL> map_lengths [ group_fn ( m ) [ : length ] ] += <NUM_LIT:1> <EOL> zoffset = <NUM_LIT:0> <EOL> overlay_type = <NUM_LIT:1> if self . hmap . type == Overlay else <NUM_LIT:2> <EOL> group_counter = Counter ( ) <EOL> for ( key , vmap ) in zip ( keys , vmaps ) : <EOL> vtype = type ( vmap . last ) <EOL> plottype = Store . registry [ self . renderer . backend ] . get ( vtype , None ) <EOL> if plottype is None : <EOL> self . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( vtype . __name__ , self . renderer . backend ) ) <EOL> continue <EOL> if self . hmap . type == Overlay : <EOL> style_key = ( vmap . type . __name__ , ) + key <EOL> else : <EOL> if not isinstance ( key , tuple ) : key = ( key , ) <EOL> style_key = group_fn ( vmap ) + key <EOL> group_key = style_key [ : length ] <EOL> zorder = ordering . index ( style_key ) + zoffset <EOL> cyclic_index = group_counter [ group_key ] <EOL> group_counter [ group_key ] += <NUM_LIT:1> <EOL> group_length = map_lengths [ group_key ] <EOL> opts = { } <EOL> if overlay_type == <NUM_LIT:2> : <EOL> opts [ '<STR_LIT>' ] = OrderedDict ( zip ( self . hmap . last . kdims , key ) ) <EOL> if issubclass ( plottype , GenericOverlayPlot ) : <EOL> opts [ '<STR_LIT>' ] = self . show_legend <EOL> style = self . lookup_options ( vmap . last , '<STR_LIT>' ) . max_cycles ( group_length ) <EOL> plotopts = dict ( opts , keys = self . keys , style = style , cyclic_index = cyclic_index , <EOL> zorder = self . zorder + zorder , ranges = ranges , overlaid = overlay_type , <EOL> layout_dimensions = self . layout_dimensions , <EOL> show_title = self . show_title , dimensions = self . dimensions , <EOL> uniform = self . uniform , <EOL> ** { k : v for k , v in self . handles . items ( ) if k in self . _passed_handles } ) <EOL> if not isinstance ( key , tuple ) : key = ( key , ) <EOL> subplots [ key ] = plottype ( vmap , ** plotopts ) <EOL> if not isinstance ( plottype , PlotSelector ) and issubclass ( plottype , GenericOverlayPlot ) : <EOL> zoffset += len ( set ( [ k for o in vmap for k in o . keys ( ) ] ) ) - <NUM_LIT:1> <EOL> if not subplots : <EOL> raise BackendError ( self . renderer . backend ) <EOL> return subplots <EOL> def get_extents ( self , overlay , ranges ) : <EOL> extents = [ ] <EOL> items = overlay . items ( ) <EOL> for key , subplot in self . subplots . items ( ) : <EOL> layer = overlay . data . get ( key , None ) <EOL> found = False <EOL> if isinstance ( self . hmap , DynamicMap ) and layer is None : <EOL> for i , ( k , layer ) in enumerate ( items ) : <EOL> if isinstance ( layer , subplot . hmap . type ) : <EOL> found = True <EOL> break <EOL> if not found : <EOL> layer = None <EOL> if layer and subplot . apply_ranges : <EOL> if isinstance ( layer , CompositeOverlay ) : <EOL> sp_ranges = ranges <EOL> else : <EOL> sp_ranges = util . match_spec ( layer , ranges ) if ranges else { } <EOL> extents . append ( subplot . get_extents ( layer , sp_ranges ) ) <EOL> return util . max_extents ( extents , self . projection == '<STR_LIT>' ) <EOL> class GenericCompositePlot ( DimensionedPlot ) : <EOL> def _get_frame ( self , key ) : <EOL> """<STR_LIT>""" <EOL> layout_frame = self . layout . clone ( shared_data = False ) <EOL> keyisint = isinstance ( key , int ) <EOL> if not isinstance ( key , tuple ) : key = ( key , ) <EOL> nthkey_fn = lambda x : zip ( tuple ( x . name for x in x . kdims ) , <EOL> list ( x . data . keys ( ) ) [ min ( [ key [ <NUM_LIT:0> ] , len ( x ) - <NUM_LIT:1> ] ) ] ) <EOL> if key == self . current_key : <EOL> return self . current_frame <EOL> else : <EOL> self . current_key = key <EOL> for path , item in self . layout . items ( ) : <EOL> if self . dynamic == '<STR_LIT>' : <EOL> if keyisint : <EOL> counts = item . traverse ( lambda x : x . counter , ( DynamicMap , ) ) <EOL> if key [ <NUM_LIT:0> ] >= counts [ <NUM_LIT:0> ] : <EOL> item . traverse ( lambda x : next ( x ) , ( DynamicMap , ) ) <EOL> dim_keys = item . traverse ( nthkey_fn , ( DynamicMap , ) ) [ <NUM_LIT:0> ] <EOL> else : <EOL> dim_keys = zip ( [ d . name for d in self . dimensions <EOL> if d in item . dimensions ( '<STR_LIT:key>' ) ] , key ) <EOL> self . current_key = tuple ( k [ <NUM_LIT:1> ] for k in dim_keys ) <EOL> elif self . uniform : <EOL> dim_keys = zip ( [ d . name for d in self . dimensions <EOL> if d in item . dimensions ( '<STR_LIT:key>' ) ] , key ) <EOL> else : <EOL> dim_keys = item . traverse ( nthkey_fn , ( HoloMap , ) ) [ <NUM_LIT:0> ] <EOL> if dim_keys : <EOL> obj = item . select ( ( HoloMap , ) , ** dict ( dim_keys ) ) <EOL> if isinstance ( obj , HoloMap ) and len ( obj ) == <NUM_LIT:0> : <EOL> continue <EOL> else : <EOL> layout_frame [ path ] = obj <EOL> else : <EOL> layout_frame [ path ] = item <EOL> self . current_frame = layout_frame <EOL> return layout_frame <EOL> def __len__ ( self ) : <EOL> return len ( self . keys ) <EOL> def _format_title ( self , key , separator = '<STR_LIT:\n>' ) : <EOL> dim_title = self . _frame_title ( key , <NUM_LIT:3> , separator ) <EOL> layout = self . layout <EOL> type_name = type ( self . layout ) . __name__ <EOL> group = util . safe_unicode ( layout . group if layout . group != type_name else '<STR_LIT>' ) <EOL> label = util . safe_unicode ( layout . label ) <EOL> title = util . safe_unicode ( self . title_format ) . format ( label = label , <EOL> group = group , <EOL> type = type_name , <EOL> dimensions = dim_title ) <EOL> return title . strip ( '<STR_LIT>' ) <EOL> class GenericLayoutPlot ( GenericCompositePlot ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , layout , ** params ) : <EOL> if not isinstance ( layout , ( NdLayout , Layout ) ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( layout . values ( ) ) == <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . layout = layout <EOL> self . subplots = { } <EOL> self . rows , self . cols = layout . shape <EOL> self . coords = list ( product ( range ( self . rows ) , <EOL> range ( self . cols ) ) ) <EOL> dynamic , sampled = get_dynamic_mode ( layout ) <EOL> dimensions , keys = traversal . unique_dimkeys ( layout ) <EOL> if sampled : <EOL> initialize_sampled ( layout , dimensions , keys [ <NUM_LIT:0> ] ) <EOL> uniform = traversal . uniform ( layout ) <EOL> plotopts = self . lookup_options ( layout , '<STR_LIT>' ) . options <EOL> super ( GenericLayoutPlot , self ) . __init__ ( keys = keys , dimensions = dimensions , <EOL> uniform = uniform , dynamic = dynamic , <EOL> ** dict ( plotopts , ** params ) ) </s>
