<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from . . builder import create_and_build , Builder <EOL> from . . utils import ( build_wedge_source , build_wedge_text_source , <EOL> build_agg_tooltip , derive_aggregation ) <EOL> from . . attributes import ColorAttr , CatAttr <EOL> from ... models . sources import ColumnDataSource <EOL> from ... models . glyphs import AnnularWedge , Text <EOL> from ... models . renderers import GlyphRenderer <EOL> from ... models . ranges import Range1d <EOL> from . . properties import Dimension <EOL> from ... core . properties import String , Instance , Float , Color , Either , List <EOL> def Donut ( data , label = '<STR_LIT:index>' , values = None , color = None , agg = None , <EOL> hover_tool = True , hover_text = None , plot_height = <NUM_LIT> , plot_width = <NUM_LIT> , <EOL> xgrid = False , ygrid = False , ** kw ) : <EOL> """<STR_LIT>""" <EOL> kw [ '<STR_LIT:label>' ] = label <EOL> kw [ '<STR_LIT>' ] = values <EOL> kw [ '<STR_LIT>' ] = color <EOL> kw [ '<STR_LIT>' ] = xgrid <EOL> kw [ '<STR_LIT>' ] = ygrid <EOL> kw [ '<STR_LIT>' ] = plot_height <EOL> kw [ '<STR_LIT>' ] = plot_width <EOL> if agg is not None : <EOL> kw [ '<STR_LIT>' ] = agg <EOL> chart = create_and_build ( DonutBuilder , data , ** kw ) <EOL> chart . left [ <NUM_LIT:0> ] . visible = False <EOL> chart . below [ <NUM_LIT:0> ] . visible = False <EOL> values , agg = derive_aggregation ( dim_cols = label , agg_col = values , agg = agg ) <EOL> if hover_tool : <EOL> tooltip = build_agg_tooltip ( hover_text = hover_text , aggregated_col = values , <EOL> agg_text = agg ) <EOL> chart . add_tooltips ( [ tooltip ] ) <EOL> return chart <EOL> class DonutBuilder ( Builder ) : <EOL> """<STR_LIT>""" <EOL> default_attributes = { '<STR_LIT>' : ColorAttr ( ) , <EOL> '<STR_LIT:label>' : CatAttr ( ) , <EOL> '<STR_LIT>' : CatAttr ( ) } <EOL> dimensions = [ '<STR_LIT>' ] <EOL> values = Dimension ( '<STR_LIT>' ) <EOL> agg = String ( default = '<STR_LIT>' ) <EOL> chart_data = Instance ( ColumnDataSource ) <EOL> text_data = Instance ( ColumnDataSource ) <EOL> level_width = Float ( default = <NUM_LIT> ) <EOL> level_spacing = Either ( Float , List ( Float ) , default = <NUM_LIT:0.0> ) <EOL> text_font_size = String ( default = '<STR_LIT>' ) <EOL> line_color = Color ( default = '<STR_LIT>' ) <EOL> def setup ( self ) : <EOL> if self . attributes [ '<STR_LIT:label>' ] . columns is None : <EOL> self . attributes [ '<STR_LIT:label>' ] . setup ( data = self . _data . source , <EOL> columns = self . _data . df . columns [ <NUM_LIT:0> ] ) <EOL> if self . values . selection is None : <EOL> if not all ( [ name is None for name in self . _data . df . index . names ] ) : <EOL> label_cols = list ( self . _data . df . index . names ) <EOL> self . _data . _data . reset_index ( inplace = True ) <EOL> self . attributes [ '<STR_LIT:label>' ] . setup ( data = self . _data . source , <EOL> columns = label_cols ) <EOL> cols = [ col for col in self . _data . df . columns if col not in <EOL> label_cols + [ '<STR_LIT:index>' ] ] <EOL> elif self . attributes [ '<STR_LIT:label>' ] . columns [ <NUM_LIT:0> ] == '<STR_LIT:index>' : <EOL> cols = [ col for col in self . _data . df . columns if col not in [ '<STR_LIT:index>' ] ] <EOL> else : <EOL> cols = self . attributes [ '<STR_LIT:label>' ] . columns <EOL> self . values . selection = cols [ <NUM_LIT:0> ] <EOL> if self . _data . df [ self . values . selection ] . dtype . name == '<STR_LIT:object>' : <EOL> self . attributes [ '<STR_LIT:label>' ] . setup ( data = self . _data . source , <EOL> columns = cols [ <NUM_LIT:0> ] ) <EOL> self . agg = '<STR_LIT:count>' <EOL> if self . attributes [ '<STR_LIT>' ] . columns is None : <EOL> self . attributes [ '<STR_LIT>' ] . setup ( data = self . _data . source , <EOL> columns = self . attributes [ '<STR_LIT:label>' ] . columns [ <NUM_LIT:0> ] ) <EOL> if self . attributes [ '<STR_LIT>' ] . columns is None : <EOL> self . attributes [ '<STR_LIT>' ] . setup ( data = self . _data . source , <EOL> columns = self . attributes [ '<STR_LIT:label>' ] . columns [ <NUM_LIT:0> ] ) <EOL> def set_ranges ( self ) : <EOL> rng = ( max ( self . chart_data . data [ '<STR_LIT>' ] ) + <NUM_LIT> ) * self . level_width <EOL> self . x_range = Range1d ( - rng , rng ) <EOL> self . y_range = Range1d ( - rng , rng ) <EOL> def process_data ( self ) : <EOL> polar_data = build_wedge_source ( self . _data . df , <EOL> cat_cols = self . attributes [ '<STR_LIT:label>' ] . columns , <EOL> agg_col = self . values . selection , <EOL> agg = self . agg , <EOL> level_width = self . level_width , <EOL> level_spacing = self . level_spacing ) <EOL> polar_data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> for group in self . _data . groupby ( ** self . attributes ) : <EOL> polar_data . loc [ group [ '<STR_LIT>' ] , '<STR_LIT>' ] = group [ '<STR_LIT>' ] <EOL> self . chart_data = ColumnDataSource ( polar_data ) <EOL> self . text_data = build_wedge_text_source ( polar_data ) <EOL> def yield_renderers ( self ) : <EOL> aw = AnnularWedge ( x = <NUM_LIT:0> , y = <NUM_LIT:0> , inner_radius = '<STR_LIT>' , outer_radius = '<STR_LIT>' , <EOL> start_angle = '<STR_LIT:start>' , end_angle = '<STR_LIT:end>' , fill_color = '<STR_LIT>' , <EOL> fill_alpha = <NUM_LIT> , line_color = self . line_color ) <EOL> yield GlyphRenderer ( data_source = self . chart_data , glyph = aw ) <EOL> txt = Text ( x = "<STR_LIT:x>" , y = "<STR_LIT:y>" , text = "<STR_LIT:text>" , angle = "<STR_LIT>" , <EOL> text_align = "<STR_LIT>" , text_baseline = "<STR_LIT>" , <EOL> text_font_size = self . text_font_size ) <EOL> yield GlyphRenderer ( data_source = self . text_data , glyph = txt ) </s>
