sommer1991 / svnplot

Automatically exported from code.google.com/p/svnplot
0 stars 0 forks source link

SVG support #19

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
For my personal project I have adapted the plot
code to output SVG format. With recent browsers
supporting the SVG tag inline in HTML code it is
possible to create a plot without images at all.

From my modified code:
"""
from matplotlib.backends.backend_svg import FigureCanvasSVG as FigureCanvas
from matplotlib.figure import Figure

    def fileTypes(self):
        SQL = """SELECT ext, count(*)'num'
             FROM (SELECT DISTINCT path, substr(path, length(path) - 
3)'ext'
                   FROM details
                   WHERE path REGEXP '.*[.]\w+$')
             GROUP BY ext
             ORDER BY num DESC
        """
        data = tuple(self.execute(SQL))

        exts = tuple(row[0] for row in data)
        nums = tuple(row[1] for row in data)

        ind = range(len(exts))

        fig = Figure(facecolor='white', edgecolor='white')
        canvas = FigureCanvas(fig)

        ax = fig.add_subplot(111)

        ax.bar(ind, nums, width = .5, align='center')
        ax.set_xticks(ind)
        ax.set_xticklabels(exts)

        ax.set_ylabel('Count')
        ax.set_xlabel('Type')
        ax.set_title('Filetypes')

        fh = cStringIO.StringIO()
        canvas.print_svg(fh)

        return fh.getvalue()
"""

Also note the use of the REGEXP operator which must be
added manual to Sqlite.

"""
def regexp(expr, item):
    r = re.compile(expr)
    return r.match(item) is not None

# create regex function
con.create_function("regexp", 2, regexp)
"""

RuTe

Original issue reported on code.google.com by runar.te...@gmail.com on 16 Nov 2009 at 7:27

GoogleCodeExporter commented 8 years ago
Runar,

Thanks for the suggestion on SVG and sample code changes. i will add it in the 
next version.

Also I am relatively new to python and SQL. So if you see something that can be 
improved in code, please feel free to suggest the changes.

Original comment by nitinbh...@gmail.com on 19 Nov 2009 at 3:12

GoogleCodeExporter commented 8 years ago
Hi,

Some general notes to improve the readability:

Write sql query string like this

SQL = \
"""
SELECT ext, count(*)'num'
FROM (SELECT DISTINCT path, substr(path, length(path) - 3)'ext'
      FROM details
      WHERE path REGEXP '.*[.]\w+$')
GROUP BY ext
ORDER BY num DESC
"""

A common construct to extract one value from a query:

a = self.execute(SQL).next()[0]

can be replaced by:

a, = self.execute(SQL).fetchone()

where 'a,' is tuple unpacking with one value

Also I found that the method used here to find the number of
files is not correct. At least not for my adaptation of the
code. The number of files does not correspond to the number
of files in an updated working copy of the repository.
I suspect the way Subversion handles renames is the problem.
You should check this out.

Runar

Original comment by runar.te...@gmail.com on 24 Nov 2009 at 7:41

GoogleCodeExporter commented 8 years ago
Number of files and linecount related a issues are now fixed in /trunk.

Also I have added svnplot-js.py which generates graphs as client side 
javascript. Hence it doesnot have any dependency on matplotlib or numpy. I 
found this alternative to be better that SVG creation. 

Original comment by nitinbh...@gmail.com on 12 Mar 2010 at 5:00