Ejemplo n.º 1
0
def draw_svg(filename, size=(800, 600)):
    from chaco.svg_graphics_context import SVGGraphicsContext
    container = create_plot()
    container.bounds = list(size)
    container.do_layout(force=True)
    gc = SVGGraphicsContext(size)
    gc.render_component(container)
    gc.save(filename)
Ejemplo n.º 2
0
    def _svg_export_fired(self):
        outfileName = self._getFilePath(defFileName=self.__DEF_FILE_NAME + '.svg')

        if outfileName != None:
            from chaco.svg_graphics_context import SVGGraphicsContext
            container = self.plot
            tempSize = copy.deepcopy( container.outer_bounds )
            container.outer_bounds = list((self.width,self.height))
            container.do_layout(force=True)
            gc = SVGGraphicsContext((self.width,self.height))
            gc.render_component(container)
            gc.save( outfileName )
            container.outer_bounds = tempSize
            self.plot.request_redraw()
Ejemplo n.º 3
0
def draw_svg(filename, size=(800, 600)):
    from chaco.svg_graphics_context import SVGGraphicsContext
    container = create_plot()
    container.bounds = list(size)
    container.do_layout(force=True)
    gc = SVGGraphicsContext(size)
    gc.render_component(container)
    gc.save(filename)
Ejemplo n.º 4
0
def export_plot_svg(parent):
    dlg = wx.FileDialog(parent, "Export plot as SVG", 
                        parent.config.get_path("SVG"), "",
                        "SVG file"+" (*.svg)|*.svg",
                        wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
    if dlg.ShowModal() == wx.ID_OK:
        path = dlg.GetPath().encode("utf-8")
        if not path.endswith(".svg"):
            path += ".svg"
        parent.config.set_path(os.path.dirname(path), "SVG")
        container = parent.PlotArea.mainplot.container

        retol = hide_scatter_inspector(container)
       
        container.do_layout(force=True)
        plot = container.components[0]
        gc = SVGGraphicsContext(plot.outer_bounds)
        gc.render_component(plot.components[-1])
        #Start a new page for subsequent draw commands.
        gc.save(path)

        if retol is not None:
            retol.visible = True
Ejemplo n.º 5
0
def export_plot_svg(parent):
    dlg = wx.FileDialog(parent, "Export plot as SVG",
                        parent.config.get_path("SVG"), "",
                        "SVG file" + " (*.svg)|*.svg",
                        wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
    if dlg.ShowModal() == wx.ID_OK:
        path = dlg.GetPath().encode("utf-8")
        if not path.endswith(".svg"):
            path += ".svg"
        parent.config.set_path(os.path.dirname(path), "SVG")
        container = parent.PlotArea.mainplot.container

        retol = hide_scatter_inspector(container)

        container.do_layout(force=True)
        plot = container.components[0]
        gc = SVGGraphicsContext(plot.outer_bounds)
        gc.render_component(plot.components[-1])
        #Start a new page for subsequent draw commands.
        gc.save(path)

        if retol is not None:
            retol.visible = True
Ejemplo n.º 6
0
def save_pdf(component,
             path=None,
             default_directory=None,
             view=False,
             options=None):
    if default_directory is None:
        default_directory = os.path.join(os.path.expanduser('~'), 'Documents')

    ok = True
    if options is None:
        ok = False
        options = FigurePDFOptions()
        options.load()
        dlg = SavePDFDialog(model=options)
        info = dlg.edit_traits(kind='livemodal')
        # path = '/Users/ross/Documents/pdftest.pdf'
        if info.result:
            options.dump()
            ok = True
    if ok:
        if path is None:
            dlg = FileDialog(action='save as',
                             default_directory=default_directory)

            if dlg.open() == OK:
                path = dlg.path

        if path:
            use_ps = False
            use_svg = False
            if use_ps:
                path = add_extension(path, '.ps')
                gc = PSGC(component.bounds)
                component.draw(gc)
                gc.save(path)
            elif use_svg:
                path = add_extension(path, '.svg')
                gc = SVGGraphicsContext(component.bounds)
                obackbuffer = component.use_backbuffer
                component.use_backbuffer = False
                gc.render_component(component)
                gc.save(path)
                component.use_backbuffer = obackbuffer

            else:
                path = add_extension(path, '.pdf')
                gc = myPdfPlotGraphicsContext(filename=path,
                                              dest_box=options.dest_box,
                                              pagesize=options.page_size)

                obounds = component.bounds
                # size = None
                if not obounds[0] and not obounds[1]:
                    size = options.bounds
                    component.do_layout(size=size, force=True)

                if options.fit_to_page:
                    size = options.bounds
                    component.do_layout(size=size, force=True)

                gc.render_component(component, valign='center')
                gc.save()
                if view:
                    view_file(path)

                if options.fit_to_page:
                    component.do_layout(size=obounds, force=True)
Ejemplo n.º 7
0
def save_plot_svg(component, filename, size):
    from chaco.svg_graphics_context import SVGGraphicsContext

    gc = SVGGraphicsContext(size)
    gc.render_component(component)
    gc.save(filename)