def _create_viewport(self): # Create a container and add our plots canvas = PlotCanvas() canvas.range_controller = RangeController(cavas = canvas) toolbar = make_toolbar(canvas) toolbar.component = canvas canvas.overlays.append(toolbar) viewport = Viewport(component=canvas) if MULTITOUCH: viewport.tools.append(MPViewportPanTool(viewport)) else: viewport.tools.append(ViewportPanTool(viewport, drag_button="right")) return viewport
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ # Make sure the model we'll be editing exists: object = self.object model = getattr(object, '_hidden_model', None) if model is None: object._hidden_model = model = NumericObjectModel(object) # Get the list of traits to plot: factory = self.factory type = factory.type index = factory.index names = factory.names if len(names) == 0: names = [ name for name in object.trait_names() if object.base_trait(name).array ] idx = getattr(object, index, None) if idx is None: plot_index = PlotValue(arange(0.0, len(model.model_indices))) selection_index = None else: plot_index = PlotValue(ModelData(model=model).set(name=index)) selection_index = PlotValue( SelectionData(model=model).set(name=index)) canvas = PlotCanvas(plot_type=factory.type, bg_color=BGColor) canvas.axis_index = PlotAxis() if idx is not None: canvas.axis_index.title = index if len(names) == 1: canvas.axis = PlotAxis(title=names[0]) for name in names: canvas.add( PlotValue(ModelData(model=model).set(name=name), index=plot_index, plot_type=type, size='small')) if selection_index is not None: plot_value = PlotValue( SelectionData(model=model).set(name=name), index=selection_index, plot_type='scatter', fill_color='red', size='small') canvas.add(plot_value) # Set up the interactive data filters: if selection_index is not None: canvas.interaction = ia = \ NumericModelExplorerInteraction( value = plot_value ) ia._filters = filters = [] for name in names: sm = model.get_selection_model() sm.model_filter = PolygonFilter(x_value=index, y_value=name) filters.append(sm.model_filter) ia.on_trait_change(self.interaction_complete, 'points') self.control = Window( parent, component=PlotComponent(component=canvas)).control
def init ( self, parent ): """ Finishes initializing the editor by creating the underlying toolkit widget. """ # Make sure the model we'll be editing exists: object = self.object model = getattr( object, '_hidden_model', None ) if model is None: object._hidden_model = model = NumericObjectModel( object ) # Get the list of traits to plot: factory = self.factory type = factory.type index = factory.index names = factory.names if len( names ) == 0: names = [ name for name in object.trait_names() if object.base_trait( name ).array ] idx = getattr( object, index, None ) if idx is None: plot_index = PlotValue( arange( 0.0, len( model.model_indices ) ) ) selection_index = None else: plot_index = PlotValue( ModelData( model = model ).set( name = index ) ) selection_index = PlotValue( SelectionData( model = model ).set( name = index ) ) canvas = PlotCanvas( plot_type = factory.type, bg_color = BGColor ) canvas.axis_index = PlotAxis() if idx is not None: canvas.axis_index.title = index if len( names ) == 1: canvas.axis = PlotAxis( title = names[0] ) for name in names: canvas.add( PlotValue( ModelData( model = model ).set( name = name ), index = plot_index, plot_type = type, size = 'small' ) ) if selection_index is not None: plot_value = PlotValue( SelectionData( model = model ).set( name = name ), index = selection_index, plot_type = 'scatter', fill_color = 'red', size = 'small' ) canvas.add( plot_value ) # Set up the interactive data filters: if selection_index is not None: canvas.interaction = ia = \ NumericModelExplorerInteraction( value = plot_value ) ia._filters = filters = [] for name in names: sm = model.get_selection_model() sm.model_filter = PolygonFilter( x_value = index, y_value = name ) filters.append( sm.model_filter ) ia.on_trait_change( self.interaction_complete, 'points' ) self.control = Window( parent, component = PlotComponent( component = canvas ) ).control
def create_plot ( parent, editor ): """ Creates a data explorer plot. """ try: nmep = editor.object model = nmep.model items = nmep.plot_items if len( items ) == 0: return wx.Panel( parent, -1 ) index = nmep.plot_index if index is None: plot_index = PlotValue( arange( 0.0, len( model.model_indices ) ) ) selection_index = None else: plot_index = PlotValue( ModelData( model = model, name = index.name ) ) selection_index = PlotValue( SelectionData( model = model, name = index.name ) ) canvas = PlotCanvas( plot_type = items[0].plot_type, plot_bg_color = items[0].canvas_color ) canvas.axis_index = PlotAxis() if index is not None: canvas.axis_index.title = index.label if len( items ) == 1: canvas.axis = PlotAxis( title = items[0].label ) else: canvas.add( PlotGroup( overlay = True, position = 'top right', *[ PlotOverlay( legend_color = item.line_color, text = item.label, border_size = 0, bg_color = transparent, margin = 0, padding = 2 ) for item in items ] ) ) for item in items: canvas.add( PlotValue( ModelData( model = model ).set( name = item.name ), index = plot_index, plot_type = item.plot_type, line_weight = item.line_weight, line_color = item.line_color, fill_color = item.fill_color, outline_color = item.outline_color, size = 'small' ) ) if selection_index is not None: plot_value = PlotValue( SelectionData( model = model ).set( name = item.name ), index = selection_index, plot_type = 'scatter', size = item.selection_size, fill_color = item.selection_color ) canvas.add( plot_value ) # Set up the interactive data filters: if selection_index is not None: canvas.interaction = nmep._interaction = ia = \ NumericModelExplorerInteraction( value = plot_value ) nmep._selection_models = sms = [] ia._filters = filters = [] for item in items: sm = model.get_selection_model() sms.append( sm ) sm.model_filter = PolygonFilter( x_value = index.name, y_value = item.name ) filters.append( sm.model_filter ) ia.on_trait_change( editor.ui.handler.interaction_complete, 'points' ) if len( nmep.polygon ) > 0: do_later( ia.set_selection, nmep.polygon ) return Window( parent, component = PlotComponent( component = canvas ) ).control except: import traceback traceback.print_exc() raise
def create_plot(parent, editor): """ Creates a data explorer plot. """ try: nmep = editor.object model = nmep.model items = nmep.plot_items if len(items) == 0: return wx.Panel(parent, -1) index = nmep.plot_index if index is None: plot_index = PlotValue(arange(0.0, len(model.model_indices))) selection_index = None else: plot_index = PlotValue(ModelData(model=model, name=index.name)) selection_index = PlotValue( SelectionData(model=model, name=index.name)) canvas = PlotCanvas(plot_type=items[0].plot_type, plot_bg_color=items[0].canvas_color) canvas.axis_index = PlotAxis() if index is not None: canvas.axis_index.title = index.label if len(items) == 1: canvas.axis = PlotAxis(title=items[0].label) else: canvas.add( PlotGroup(overlay=True, position='top right', *[ PlotOverlay(legend_color=item.line_color, text=item.label, border_size=0, bg_color=transparent, margin=0, padding=2) for item in items ])) for item in items: canvas.add( PlotValue(ModelData(model=model).set(name=item.name), index=plot_index, plot_type=item.plot_type, line_weight=item.line_weight, line_color=item.line_color, fill_color=item.fill_color, outline_color=item.outline_color, size='small')) if selection_index is not None: plot_value = PlotValue( SelectionData(model=model).set(name=item.name), index=selection_index, plot_type='scatter', size=item.selection_size, fill_color=item.selection_color) canvas.add(plot_value) # Set up the interactive data filters: if selection_index is not None: canvas.interaction = nmep._interaction = ia = \ NumericModelExplorerInteraction( value = plot_value ) nmep._selection_models = sms = [] ia._filters = filters = [] for item in items: sm = model.get_selection_model() sms.append(sm) sm.model_filter = PolygonFilter(x_value=index.name, y_value=item.name) filters.append(sm.model_filter) ia.on_trait_change(editor.ui.handler.interaction_complete, 'points') if len(nmep.polygon) > 0: do_later(ia.set_selection, nmep.polygon) return Window(parent, component=PlotComponent(component=canvas)).control except: import traceback traceback.print_exc() raise