<s> from pyjamas import DOM <EOL> from pyjamas import Window <EOL> from pyjamas . ui import Event <EOL> from pyjamas . ui . Button import Button <EOL> from pyjamas . ui . DialogBox import DialogBox <EOL> from pyjamas . ui . DockPanel import DockPanel <EOL> from pyjamas . ui . FlexTable import FlexTable <EOL> from pyjamas . ui import HasHorizontalAlignment <EOL> from pyjamas . ui . HorizontalPanel import HorizontalPanel <EOL> from pyjamas . ui . ListBox import ListBox <EOL> from pyjamas . ui . VerticalPanel import VerticalPanel <EOL> from pyjamas . chart . GChart import GChart <EOL> from pyjamas . chart import AnnotationLocation <EOL> from pyjamas . chart import SymbolType <EOL> from pyjamas . chart import TouchedPointUpdateOption <EOL> LABEL_COL = <NUM_LIT:0> ; <EOL> OBJECT_COL = <NUM_LIT:1> ; <EOL> N_COLS = <NUM_LIT:2> ; <EOL> N_SLICES = <NUM_LIT:5> <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> class ObjectSelectorDropdownList ( ListBox ) : <EOL> def __init__ ( self , labelObjectPairs ) : <EOL> ListBox . __init__ ( self ) <EOL> self . labelObjectPairs = labelObjectPairs <EOL> self . setVisibleItemCount ( <NUM_LIT:1> ) ; <EOL> for i in range ( len ( labelObjectPairs ) ) : <EOL> self . addItem ( labelObjectPairs [ i ] [ LABEL_COL ] ) <EOL> def getObject ( self , index ) : <EOL> result = self . labelObjectPairs [ index ] [ OBJECT_COL ] <EOL> return result <EOL> def getSelectedObject ( self ) : <EOL> result = self . getObject ( self . getSelectedIndex ( ) ) <EOL> return result <EOL> def setSelectedObject ( self , selectedObject ) : <EOL> for i in range ( len ( self . labelObjectPairs ) ) : <EOL> if selectedObject == self . labelObjectPairs [ i ] [ OBJECT_COL ] : <EOL> self . setSelectedIndex ( i ) <EOL> return <EOL> raise IllegalArgumentException ( <EOL> "<STR_LIT>" ) <EOL> def getNObjects ( self ) : <EOL> return len ( self . labelObjectPairs ) <EOL> class ColorSpec : <EOL> def __init__ ( self , backgroundColor , borderColor ) : <EOL> self . backgroundColor = backgroundColor <EOL> self . borderColor = borderColor <EOL> class SliceEditor ( DialogBox ) : <EOL> def __init__ ( self , chart ) : <EOL> """<STR_LIT>""" <EOL> DialogBox . __init__ ( self , autoHide = True , modal = True ) <EOL> self . chart = chart <EOL> self . isFirstTime = True <EOL> mainPanel = VerticalPanel ( ) <EOL> propertyForm = FlexTable ( ) <EOL> commandBar = DockPanel ( ) <EOL> sliceSwitcher = HorizontalPanel ( ) <EOL> self . prevSlice = Button ( "<STR_LIT>" , self ) <EOL> self . nextSlice = Button ( "<STR_LIT>" , self ) <EOL> self . closeButton = Button ( "<STR_LIT>" , self ) <EOL> self . chart . colorSelector . addChangeListener ( self ) <EOL> self . chart . sliceSizeSelector . addChangeListener ( self ) <EOL> self . chart . shadingSelector . addChangeListener ( self ) <EOL> propertyForm . setSize ( <NUM_LIT:3> , <NUM_LIT:2> ) <EOL> propertyForm . setText ( <NUM_LIT:0> , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> propertyForm . setWidget ( <NUM_LIT:0> , <NUM_LIT:1> , self . chart . colorSelector ) <EOL> propertyForm . setText ( <NUM_LIT:1> , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> propertyForm . setWidget ( <NUM_LIT:1> , <NUM_LIT:1> , self . chart . shadingSelector ) <EOL> propertyForm . setText ( <NUM_LIT:2> , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> propertyForm . setWidget ( <NUM_LIT:2> , <NUM_LIT:1> , self . chart . sliceSizeSelector ) <EOL> sliceSwitcher . add ( self . prevSlice ) <EOL> sliceSwitcher . add ( self . nextSlice ) <EOL> commandBar . add ( sliceSwitcher , DockPanel . WEST ) <EOL> commandBar . add ( self . closeButton , DockPanel . EAST ) <EOL> commandBar . setCellHorizontalAlignment ( self . closeButton , <EOL> HasHorizontalAlignment . ALIGN_RIGHT ) <EOL> commandBar . setWidth ( "<STR_LIT>" ) ; <EOL> mainPanel . add ( propertyForm ) <EOL> mainPanel . add ( commandBar ) <EOL> self . setWidget ( mainPanel ) ; <EOL> def onChange ( self , sender ) : <EOL> self . copyFormPropertiesIntoChart ( self . chart . getTouchedPoint ( ) ) <EOL> self . chart . update ( TouchedPointUpdateOption . TOUCHED_POINT_LOCKED ) <EOL> def copyChartPropertiesIntoForm ( self , p ) : <EOL> self . setText ( "<STR_LIT>" % self . chart . getCurveIndex ( p . getParent ( ) ) ) <EOL> self . chart . colorSelector . setSelectedObject ( <EOL> self . getColorSpec ( p . getParent ( ) . getSymbol ( ) . getBackgroundColor ( ) , <EOL> p . getParent ( ) . getSymbol ( ) . getBorderColor ( ) ) ) <EOL> self . chart . shadingSelector . setSelectedObject ( <EOL> p . getParent ( ) . getSymbol ( ) . getSymbolType ( ) ) <EOL> sliceSize = round ( <NUM_LIT:100> * p . getParent ( ) . getSymbol ( ) . getPieSliceSize ( ) ) <EOL> self . chart . sliceSizeSelector . setSelectedObject ( int ( sliceSize ) ) <EOL> def copyFormPropertiesIntoChart ( self , p ) : <EOL> p . getParent ( ) . getSymbol ( ) . setBackgroundColor ( <EOL> self . chart . colorSelector . getSelectedObject ( ) . backgroundColor ) <EOL> p . getParent ( ) . getSymbol ( ) . setBorderColor ( <EOL> self . chart . colorSelector . getSelectedObject ( ) . borderColor ) <EOL> p . getParent ( ) . getSymbol ( ) . setHoverSelectionBorderColor ( <EOL> self . chart . colorSelector . getSelectedObject ( ) . backgroundColor ) <EOL> p . getParent ( ) . getSymbol ( ) . setHoverSelectionBackgroundColor ( <EOL> self . chart . colorSelector . getSelectedObject ( ) . borderColor ) <EOL> p . getParent ( ) . getSymbol ( ) . setSymbolType ( <EOL> self . chart . shadingSelector . getSelectedObject ( ) ) <EOL> sliceSize = int ( self . chart . sliceSizeSelector . getSelectedObject ( ) ) <EOL> p . getParent ( ) . getSymbol ( ) . setPieSliceSize ( sliceSize / <NUM_LIT> ) <EOL> def getColorSpec ( self , backgroundColor , borderColor ) : <EOL> for i in range ( self . chart . colorSelector . getNObjects ( ) ) : <EOL> cs = self . chart . colorSelector . getObject ( i ) <EOL> if ( backgroundColor == cs . backgroundColor and <EOL> borderColor == cs . borderColor ) : <EOL> return cs <EOL> raise IllegalArgumentException ( <EOL> "<STR_LIT>" ) <EOL> def onClick ( self , sender ) : <EOL> print "<STR_LIT>" , sender <EOL> if sender == self . prevSlice : <EOL> self . chart . onClickPrevSlice ( sender ) <EOL> elif sender == self . nextSlice : <EOL> self . chart . onClickNextSlice ( sender ) <EOL> elif sender == self . closeButton : <EOL> self . onClickClose ( sender ) <EOL> else : <EOL> self . onClickDefault ( sender ) <EOL> def onClickClose ( self , event ) : <EOL> self . hide ( ) <EOL> self . chart . touch ( None ) ; <EOL> self . chart . update ( TouchedPointUpdateOption . TOUCHED_POINT_LOCKED ) <EOL> def onClickDefault ( self , sender ) : <EOL> if None == self . chart . getTouchedPoint ( ) : <EOL> return <EOL> event = DOM . eventGetCurrentEvent ( ) <EOL> self . copyChartPropertiesIntoForm ( self . chart . getTouchedPoint ( ) ) <EOL> if self . isFirstTime : <EOL> self . setPopupPosition ( <EOL> Window . getScrollLeft ( ) + DOM . eventGetClientX ( event ) , <EOL> Window . getScrollTop ( ) + DOM . eventGetClientX ( event ) ) <EOL> self . show ( ) <EOL> self . isFirstTime = False <EOL> else : <EOL> self . show ( ) <EOL> class GChartExample20 ( GChart ) : <EOL> def __init__ ( self ) : <EOL> GChart . __init__ ( self ) <EOL> self . colorSelector = ObjectSelectorDropdownList ( [ [ "<STR_LIT>" , ColorSpec ( "<STR_LIT>" , "<STR_LIT>" ) ] , <EOL> [ "<STR_LIT>" , ColorSpec ( "<STR_LIT>" , "<STR_LIT>" ) ] , <EOL> [ "<STR_LIT>" , ColorSpec ( "<STR_LIT>" , "<STR_LIT>" ) ] , <EOL> [ "<STR_LIT>" , ColorSpec ( "<STR_LIT>" , "<STR_LIT>" ) ] , <EOL> [ "<STR_LIT>" , ColorSpec ( "<STR_LIT>" , "<STR_LIT>" ) ] , <EOL> [ "<STR_LIT>" , ColorSpec ( "<STR_LIT>" , "<STR_LIT>" ) ] , <EOL> [ "<STR_LIT>" , ColorSpec ( "<STR_LIT>" , "<STR_LIT>" ) ] , <EOL> [ "<STR_LIT>" , ColorSpec ( "<STR_LIT>" , "<STR_LIT>" ) ] , <EOL> [ "<STR_LIT>" , ColorSpec ( "<STR_LIT>" , "<STR_LIT>" ) ] , <EOL> [ "<STR_LIT>" , ColorSpec ( "<STR_LIT>" , "<STR_LIT>" ) ] , <EOL> [ "<STR_LIT>" , ColorSpec ( "<STR_LIT>" , "<STR_LIT>" ) ] ] ) <EOL> self . shadingSelector = ObjectSelectorDropdownList ( [ [ "<STR_LIT>" , SymbolType . PIE_SLICE_VERTICAL_SHADING ] , <EOL> [ "<STR_LIT>" , SymbolType . PIE_SLICE_HORIZONTAL_SHADING ] , <EOL> [ "<STR_LIT>" , SymbolType . PIE_SLICE_OPTIMAL_SHADING ] ] ) <EOL> self . sliceSizeSelector = ObjectSelectorDropdownList ( [ <EOL> [ "<STR_LIT>" , int ( <NUM_LIT:0> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT:5> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT:10> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT:15> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT:20> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT:30> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT:50> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT> ) ] , <EOL> [ "<STR_LIT>" , int ( <NUM_LIT:100> ) ] ] ) <EOL> self . theSliceEditor = SliceEditor ( self ) <EOL> SOURCE_CODE_LINK = "<STR_LIT>" <EOL> self . setChartSize ( <NUM_LIT:100> , <NUM_LIT:100> ) <EOL> self . setBorderStyle ( "<STR_LIT:none>" ) <EOL> self . setChartTitle ( "<STR_LIT>" ) <EOL> self . setChartTitleThickness ( <NUM_LIT:20> ) <EOL> self . setChartFootnotes ( SOURCE_CODE_LINK ) <EOL> self . setChartFootnotesThickness ( <NUM_LIT:20> ) <EOL> initSliceSize = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.1> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . addClickListener ( self . theSliceEditor ) <EOL> for iCurve in range ( N_SLICES ) : <EOL> self . addCurve ( ) <EOL> self . getCurve ( ) . getSymbol ( ) . setBorderWidth ( <NUM_LIT:1> ) <EOL> self . getCurve ( ) . getSymbol ( ) . setFillThickness ( <NUM_LIT:4> ) <EOL> self . getCurve ( ) . getSymbol ( ) . setFillSpacing ( <NUM_LIT:4> ) <EOL> self . getCurve ( ) . getSymbol ( ) . setHoverLocation ( <EOL> AnnotationLocation . ON_PIE_ARC ) <EOL> self . getCurve ( ) . getSymbol ( ) . setBorderColor ( <EOL> self . colorSelector . getObject ( iCurve ) . borderColor ) <EOL> self . getCurve ( ) . getSymbol ( ) . setBackgroundColor ( <EOL> self . colorSelector . getObject ( iCurve ) . backgroundColor ) <EOL> self . getCurve ( ) . getSymbol ( ) . setHoverSelectionBackgroundColor ( <EOL> self . colorSelector . getObject ( iCurve ) . borderColor ) <EOL> self . getCurve ( ) . getSymbol ( ) . setHoverSelectionBorderColor ( <EOL> self . colorSelector . getObject ( iCurve ) . backgroundColor ) <EOL> self . getCurve ( ) . getSymbol ( ) . setSymbolType ( <EOL> SymbolType . PIE_SLICE_HORIZONTAL_SHADING ) <EOL> self . getCurve ( ) . getSymbol ( ) . setPieSliceSize ( initSliceSize [ iCurve ] ) <EOL> self . getCurve ( ) . getSymbol ( ) . setModelHeight ( <NUM_LIT:1.0> ) ; <EOL> self . getCurve ( ) . getSymbol ( ) . setModelWidth ( <NUM_LIT:0> ) <EOL> self . getCurve ( ) . addPoint ( <NUM_LIT:0.5> , <NUM_LIT:0.5> ) ; <EOL> self . getXAxis ( ) . setAxisMin ( <NUM_LIT:0> ) ; <EOL> self . getXAxis ( ) . setAxisMax ( <NUM_LIT:1> ) <EOL> self . getYAxis ( ) . setAxisMin ( <NUM_LIT:0> ) <EOL> self . getYAxis ( ) . setAxisMax ( <NUM_LIT:1> ) <EOL> self . getXAxis ( ) . setHasGridlines ( False ) ; <EOL> self . getXAxis ( ) . setAxisVisible ( False ) ; <EOL> self . getXAxis ( ) . setTickCount ( <NUM_LIT:0> ) <EOL> self . getYAxis ( ) . setHasGridlines ( False ) <EOL> self . getYAxis ( ) . setAxisVisible ( False ) <EOL> self . getYAxis ( ) . setTickCount ( <NUM_LIT:0> ) <EOL> self . update ( ) <EOL> def onClickPrevSlice ( self , event ) : <EOL> iCurve = self . getCurveIndex ( self . getTouchedCurve ( ) ) <EOL> if ( iCurve == <NUM_LIT:0> ) : <EOL> iPrev = self . getNCurves ( ) - <NUM_LIT:1> <EOL> else : <EOL> iPrev = ( iCurve - <NUM_LIT:1> ) <EOL> self . touch ( self . getCurve ( iPrev ) . getPoint ( <NUM_LIT:0> ) ) <EOL> self . theSliceEditor . copyChartPropertiesIntoForm ( self . getTouchedPoint ( ) ) <EOL> self . update ( TouchedPointUpdateOption . TOUCHED_POINT_LOCKED ) <EOL> def onClickNextSlice ( self , event ) : <EOL> iCurve = self . getCurveIndex ( self . getTouchedCurve ( ) ) <EOL> if ( iCurve + <NUM_LIT:1> == self . getNCurves ( ) ) : <EOL> iNext = <NUM_LIT:0> <EOL> else : <EOL> iNext = ( iCurve + <NUM_LIT:1> ) <EOL> self . touch ( self . getCurve ( iNext ) . getPoint ( <NUM_LIT:0> ) ) <EOL> self . theSliceEditor . copyChartPropertiesIntoForm ( self . getTouchedPoint ( ) ) <EOL> self . update ( TouchedPointUpdateOption . TOUCHED_POINT_LOCKED ) </s>
