<s> from base import BaseGraph , UnifiedGraph <EOL> from canvas import ScatterCanvas , DoubleScatterCanvas , BarCanvas , HorizontalBarCanvas , PieCanvas , LineCanvas <EOL> from axes import YAxis <EOL> from . . utils . struct import Vector as V <EOL> from . . graphics . utils import ViewBox , Translate , Rotate , addAttr , blank , boolean <EOL> from . . graphics . color import hex_to_color , Color <EOL> from . . graphics . shapes import Line , Rectangle , Text <EOL> from . . graphics . group import Group <EOL> class Graph ( BaseGraph ) : <EOL> def __init__ ( self , ** attr ) : <EOL> BaseGraph . __init__ ( self , None , ** attr ) <EOL> class ScatterPlot ( UnifiedGraph ) : <EOL> def __init__ ( self , regLine = True , settings = None ) : <EOL> UnifiedGraph . __init__ ( self , <EOL> ScatterCanvas , <EOL> regLine = regLine , <EOL> settings = settings ) <EOL> def jsLocator ( self ) : <EOL> return """<STR_LIT>""" <EOL> def jsPosition ( self ) : <EOL> return """<STR_LIT>""" <EOL> def formatSettings ( self , settings ) : <EOL> UnifiedGraph . formatSettings ( self , settings ) <EOL> addAttr ( settings , '<STR_LIT>' , float , <NUM_LIT> ) <EOL> addAttr ( settings , '<STR_LIT>' , str , '<STR_LIT>' ) <EOL> addAttr ( settings , '<STR_LIT>' , str , '<STR_LIT>' ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , hex_to_color ( '<STR_LIT>' ) ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , hex_to_color ( '<STR_LIT>' ) ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , hex_to_color ( '<STR_LIT>' ) ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , hex_to_color ( '<STR_LIT>' ) ) <EOL> addAttr ( settings , '<STR_LIT>' , float , <NUM_LIT:1.0> ) <EOL> def setColors ( self , color1 = None , color2 = None , color3 = None ) : <EOL> self . settings . color1 = color1 <EOL> self . settings . color2 = color2 <EOL> self . settings . color3 = color3 <EOL> def setProperties ( self ) : <EOL> self . xaxis = True <EOL> self . yaxis = True <EOL> self . y2axis = False <EOL> def addPoint ( self , x , y , name = None ) : <EOL> self . canvas . drawPoint ( name , x , y ) <EOL> class DoubleScatterPlot ( ScatterPlot ) : <EOL> def __init__ ( self , ** attr ) : <EOL> UnifiedGraph . __init__ ( self , DoubleScatterCanvas , ** attr ) <EOL> def jsPosition ( self ) : <EOL> return """<STR_LIT>""" <EOL> def formatSettings ( self , settings ) : <EOL> UnifiedGraph . formatSettings ( self , settings ) <EOL> addAttr ( settings , '<STR_LIT>' , str , '<STR_LIT>' ) <EOL> addAttr ( settings , '<STR_LIT>' , float , '<STR_LIT>' ) <EOL> addAttr ( settings , '<STR_LIT>' , str , '<STR_LIT>' ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , Color ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , Color ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:0> ) ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , Color ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:255> ) ) <EOL> addAttr ( settings , '<STR_LIT>' , boolean , False ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , Color ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> addAttr ( settings , '<STR_LIT>' , float , <NUM_LIT:1.0> ) <EOL> addAttr ( settings , '<STR_LIT>' , str , '<STR_LIT>' ) <EOL> addAttr ( settings , '<STR_LIT>' , float , '<STR_LIT>' ) <EOL> addAttr ( settings , '<STR_LIT>' , str , '<STR_LIT>' ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , Color ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:255> ) ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , Color ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:0> ) ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , Color ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> addAttr ( settings , '<STR_LIT>' , boolean , False ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , Color ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> addAttr ( settings , '<STR_LIT>' , float , <NUM_LIT:1.0> ) <EOL> def setColors ( self , color1 , color2 ) : <EOL> raise NotImplementedError ( ) <EOL> def setProperties ( self ) : <EOL> self . xaxis = True <EOL> self . yaxis = True <EOL> self . y2axis = True <EOL> """<STR_LIT>""" <EOL> def addPoint1 ( self , x , y , name = None ) : <EOL> self . canvas . drawPoint ( name , x , y ) <EOL> def addPoint2 ( self , x , y , name = None ) : <EOL> self . canvas . drawPoint2 ( name , x , y ) <EOL> class BarGraph ( UnifiedGraph ) : <EOL> def __init__ ( self , ** attr ) : <EOL> """<STR_LIT>""" <EOL> UnifiedGraph . __init__ ( self , None , ** attr ) <EOL> if self . settings . horizontal == True : <EOL> self . attachCanvas ( HorizontalBarCanvas ) <EOL> else : <EOL> self . attachCanvas ( BarCanvas ) <EOL> def formatSettings ( self , settings ) : <EOL> UnifiedGraph . formatSettings ( self , settings ) <EOL> addAttr ( settings , '<STR_LIT>' , hex_to_color , Color ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> addAttr ( settings , '<STR_LIT>' , float , <NUM_LIT:1.0> ) <EOL> addAttr ( settings , '<STR_LIT>' , float , <NUM_LIT> ) <EOL> addAttr ( settings , '<STR_LIT>' , float , <NUM_LIT> ) <EOL> addAttr ( settings , '<STR_LIT>' , float , <NUM_LIT:1.0> ) <EOL> addAttr ( settings , '<STR_LIT>' , boolean , False ) <EOL> def jsChangeTooltipPos ( self ) : <EOL> if not self . settings . horizontal : <EOL> return UnifiedGraph . jsChangeTooltipPos ( self ) <EOL> else : <EOL> return """<STR_LIT>""" <EOL> def setProperties ( self ) : <EOL> if self . settings . horizontal : <EOL> self . xaxis = True <EOL> self . yaxis = True <EOL> self . y2axis = False <EOL> else : <EOL> self . xaxis = True <EOL> self . yaxis = True <EOL> self . y2axis = False <EOL> def setColors ( self , colors ) : <EOL> self . canvas . colors = colors <EOL> def addSpace ( self ) : <EOL> self . canvas . addSpace ( ) <EOL> def addBar ( self , name , data , ** attr ) : <EOL> self . canvas . addBar ( name , data , ** attr ) <EOL> def addGroup ( self , name , data , url = None ) : <EOL> self . canvas . addGroup ( name , data , url ) <EOL> def createXAxisSpace ( self ) : <EOL> if self . settings . horizontal : <EOL> UnifiedGraph . createXAxisSpace ( self ) <EOL> else : <EOL> h = self . settings . xAxisTextHeight <EOL> width = [ ] <EOL> for child in self . canvas . data : <EOL> if child . xml . has_key ( '<STR_LIT:data>' ) and not child . xml [ '<STR_LIT:data>' ] is None : <EOL> w = Text . textWidth ( child . xml [ '<STR_LIT:data>' ] , h ) <EOL> width . append ( w ) <EOL> if len ( width ) > <NUM_LIT:0> : <EOL> maxWidth = max ( width ) <EOL> else : <EOL> maxWidth = <NUM_LIT:0> <EOL> delta = self . settings . xAxisSpace + maxWidth <EOL> self . canvas . move ( <NUM_LIT:0> , delta ) <EOL> self . canvas . changeSize ( <NUM_LIT:0> , - delta ) <EOL> def createYAxis ( self ) : <EOL> if not self . settings . horizontal : <EOL> UnifiedGraph . createYAxis ( self ) <EOL> else : <EOL> for child in self . canvas . data : <EOL> self . ypositions . append ( child . y + ( child . height / <NUM_LIT> ) ) <EOL> self . ylabels . append ( child . xml [ '<STR_LIT:data>' ] ) <EOL> UnifiedGraph . createYAxis ( self ) <EOL> def createXAxis ( self ) : <EOL> ax = Group ( ) <EOL> x = self . canvas . x - self . canvas . height <EOL> y = self . canvas . y + self . canvas . height <EOL> if self . settings . horizontal : <EOL> ax . appendTransform ( Rotate ( - <NUM_LIT> , self . canvas . x , y ) ) <EOL> UnifiedGraph . createXAxis ( self ) <EOL> else : <EOL> ax . appendTransform ( Rotate ( - <NUM_LIT> , self . canvas . x , self . canvas . y ) ) <EOL> textProperties = { '<STR_LIT>' : self . settings . xAxisTextHeight , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:right>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } <EOL> xaxis = YAxis ( id = '<STR_LIT>' , <EOL> inf = self . canvas . y , <EOL> sup = self . canvas . y - self . canvas . width , <EOL> x = self . canvas . x - self . settings . xAxisSpace , <EOL> lower = self . xbounds [ <NUM_LIT:0> ] , <EOL> upper = self . xbounds [ <NUM_LIT:1> ] , <EOL> textProperties = textProperties ) <EOL> sizes = [ ] <EOL> ticks = [ ] <EOL> labels = [ ] <EOL> for child in self . canvas . data : <EOL> if child . xml . has_key ( '<STR_LIT:data>' ) : <EOL> ticks . append ( child . x + child . width / <NUM_LIT> ) <EOL> labels . append ( child . xml [ '<STR_LIT:data>' ] ) <EOL> xaxis . createTicks ( ticks ) <EOL> xaxis . setText ( map ( str , labels ) ) <EOL> xaxis . drawTicks ( ) <EOL> ax . draw ( xaxis ) <EOL> self . dataGroup . drawAt ( ax , <NUM_LIT:0> ) <EOL> def setSVG ( self ) : <EOL> attr = UnifiedGraph . setSVG ( self ) <EOL> return attr <EOL> class LineChart ( UnifiedGraph ) : <EOL> def __init__ ( self , ** attr ) : <EOL> UnifiedGraph . __init__ ( self , LineCanvas , ** attr ) <EOL> def setProperties ( self ) : <EOL> self . xaxis = True <EOL> self . yaxis = True <EOL> self . y2axis = False <EOL> def setColors ( self , colorDict ) : <EOL> self . canvas . colors . update ( colorDict ) <EOL> def addSeries ( self , name , series ) : <EOL> self . canvas . addData ( name , * series ) <EOL> def setSeriesNames ( self , seriesNames ) : <EOL> self . xlabels = seriesNames <EOL> class PieChart ( BaseGraph ) : <EOL> def __init__ ( self , ** attr ) : <EOL> BaseGraph . __init__ ( self , PieCanvas ) <EOL> self . addScript ( '<STR_LIT>' ) <EOL> def addWedge ( self , name , value ) : <EOL> self . canvas . addData ( name , float ( value ) ) <EOL> def finalize ( self ) : <EOL> BaseGraph . finalize ( self ) <EOL> self . canvas . finalize ( ) </s>
