Moinmoin chart should use the gdchart v2 libraries.

The statistics chart (chart_options) of moinmoin are implemented using python/gdchart v1 libraries, but that library is superseded by gdchart version 2.

The modules MoinMoin/stats/chart.py should be upgraded to use that library.

For reference :

Problems:

(!) Maybe we better use some other gfx/charting lib.

Solved (at least a temporary fix for those having python-gdchart2 installed on their machine):

and run
diff -p1 < moinmoin_stats.patch

Thanks for the patches, I'll have a look at them soon. -- ThomasWaldmann 2009-05-28 14:40:28

Can you please provide some API documentation for the gdchart2 code you used. Every time I try to find something on the net, I stumble over 404 links and ancient crap. Also I get the impression, that all this gdchart stuff is disorganized or dead. If nobody convinces me else, I am rather killing all that code relying on it than upgrading it to some gdchart2 stuff that seems to be dead / unmaintained, too. -- ThomasWaldmann 2009-05-28 18:25:54

Yes Thomas, sure, I've tar-gzipped the /usr/share/doc/python-gdchart2-doc/ directory of my debian distribution and attached the file here: python-gdchart2-doc.tgz. For convenience, I've also put the MoinMoin/stats/ directory here in case the patch I provide is difficult to apply (I'm using MoinMoin 1.8.3): stats.tgz. -- JeanMichelRouet 2009-05-28 17:25:24

I've had a look. That docs also look old and abandoned. It's from 2003, it points to 404 internet pages (and even when manually searching on nullcube's site, you find nothing). That pretty much looks like a dead horse. So I guess we rather use something else... -- ThomasWaldmann 2009-06-06 17:17:50

Thank you for this patch. I've applied it to Moin 1.9.8 and it works with python-gdchart2 installed via apt-get. I've been going around and around with this 'til my head spins. I had a gdchart 0.6 package which I built on CentOS 5 (32 bit) and it was fine, but I've been unsuccessful at making it work on 64 bit Ubuntu 14.0.4. It builds OK, but the charts (even in the test suite) are all grey scale - no color - which makes pie charts in particular unreadable. These patches allow Moin to create readable charts with pygdchart2. I agree it would be better to teach Moin to use a better supported/newer charting package, but until then, I'm happy with this patch and gdchart2. -- MarkSapiro 2015-05-14 22:34:38

Only in stats.old: chart.py
diff -x '*.pyc' -u stats.old/hitcounts.py stats/hitcounts.py
--- stats.old/hitcounts.py      2009-05-28 09:45:06.000000000 +0200
+++ stats/hitcounts.py  2009-05-28 16:11:58.000000000 +0200
@@ -194,7 +194,7 @@

 def draw(pagename, request):
     import shutil, cStringIO
-    from MoinMoin.stats.chart import Chart, ChartData, Color
+    import gdchart

     _ = request.getText

@@ -219,9 +219,12 @@

     # create image
     image = cStringIO.StringIO()
-    c = Chart()
-    c.addData(ChartData(views, color='green'))
-    c.addData(ChartData(edits, color='red'))
+    c = gdchart.Line()
+    c.bg_color= 0xffffff
+    c.line_color = 0x000000
+
+    c.setData((views),(edits))
+    c.ext_color=['green']*len(views) + ['red']*len(edits)
     chart_title = ''
     if request.cfg.sitename:
         chart_title = "%s: " % request.cfg.sitename
@@ -231,26 +234,24 @@
             'chart_title': chart_title,
             'filterpage': filterpage,
         }
-    chart_title = "%s\n%sx%d" % (chart_title, _("green=view\nred=edit"), scalefactor)
-    c.option(
-        title=chart_title.encode('iso-8859-1', 'replace'), # gdchart can't do utf-8
-        xtitle=(_('date') + ' (Server)').encode('iso-8859-1', 'replace'),
-        ytitle=_('# of hits').encode('iso-8859-1', 'replace'),
-        title_font=c.GDC_GIANT,
-        #thumblabel = 'THUMB', thumbnail = 1, thumbval = 10,
-        #ytitle_color = Color('green'),
-        #yaxis2 = 1,
-        #ytitle2 = '# of edits',
-        #ytitle2_color = Color('red'),
-        #ylabel2_color = Color('black'),
-        #interpolations = 0,
-        threed_depth=1.0,
-        requested_yinterval=1.0,
-        stack_type=c.GDC_STACK_BESIDE
-    )
-    c.draw(c.GDC_LINE,
-        (request.cfg.chart_options['width'], request.cfg.chart_options['height']),
-        image, days)
+    chart_title = "%s\n%s x %d" % (chart_title, _("green=view\nred=edit"), scalefactor)
+    c.title=chart_title.encode('iso-8859-1', 'replace') # gdchart can't do utf-8
+    c.xtitle=(_('date') + ' (Server)').encode('iso-8859-1', 'replace')
+    c.ytitle=_('# of hits').encode('iso-8859-1', 'replace')
+    c.title_font_size='GIANT'
+    c.threeD_depth=1.0
+    c.requested_yinterval=1.0
+    c.stack_type='BESIDE'
+    c.width=request.cfg.chart_options['width']
+    c.height=request.cfg.chart_options['height']
+    c.setLabels(days)
+
+    import tempfile
+    f = tempfile.NamedTemporaryFile(suffix=".gif")
+    c.draw(f.file)
+    f.file.seek(0)
+    image.write(f.file.read())
+    f.close()

     headers = [
         "Content-Type: image/gif",
diff -x '*.pyc' -u stats.old/pagesize.py stats/pagesize.py
--- stats.old/pagesize.py       2009-05-28 09:45:06.000000000 +0200
+++ stats/pagesize.py   2009-05-28 16:08:31.000000000 +0200
@@ -51,10 +51,10 @@

 def draw(pagename, request):
     import bisect, shutil, cStringIO
-    from MoinMoin.stats.chart import Chart, ChartData, Color
+    import gdchart
+    from MoinMoin.util.web import Color

     _ = request.getText
-    style = Chart.GDC_3DBAR

     # get data
     pages = request.rootpage.getPageDict()
@@ -72,11 +72,11 @@
     if upper_bound >= 65536:
         bounds.extend([s*65536 for s in range(2, 9)])

-    data = [None] * len(bounds)
+    data = [0] * len(bounds)
     for size, name in sizes:
         idx = bisect.bisect(bounds, size)
         ##idx = int((size / upper_bound) * classes)
-        data[idx] = (data[idx] or 0) + 1
+        data[idx] = data[idx] + 1

     labels = ["%d" % b for b in bounds]

@@ -87,31 +87,35 @@

     # create image
     image = cStringIO.StringIO()
-    c = Chart()
-    ##c.addData(ChartData(data, 'magenta'))
-    c.addData(ChartData(_slice(data, 0, 7), 'blue'))
-    if upper_bound >= 1024:
-        c.addData(ChartData(_slice(data, 7, 14), 'green'))
-    if upper_bound >= 8192:
-        c.addData(ChartData(_slice(data, 14, 21), 'red'))
-    if upper_bound >= 65536:
-        c.addData(ChartData(_slice(data, 21, 28), 'magenta'))
+    c = gdchart.Bar3D()
+    c.bg_color= 0xffffff
+    c.line_color = 0x000000
+
+    c.setData(data)
+    c.ext_color= []
+    for x in ['blue', 'green', 'red', 'magenta']:
+        c.ext_color = c.ext_color + [ Color(x) ] * 8
     title = ''
     if request.cfg.sitename: title = "%s: " % request.cfg.sitename
-    title = title + _('Page Size Distribution')
-    c.option(
-        annotation=(bisect.bisect(bounds, upper_bound), Color('black'), "%d %s" % sizes[-1]),
-        title=title.encode('iso-8859-1', 'replace'), # gdchart can't do utf-8
-        xtitle=_('page size upper bound [bytes]').encode('iso-8859-1', 'replace'),
-        ytitle=_('# of pages of this size').encode('iso-8859-1', 'replace'),
-        title_font=c.GDC_GIANT,
-        threed_depth=2.0,
-        requested_yinterval=1.0,
-        stack_type=c.GDC_STACK_LAYER,
-    )
-    c.draw(style,
-        (request.cfg.chart_options['width'], request.cfg.chart_options['height']),
-        image, labels)
+    c.title = title.encode('iso-8859-1','replace') + _('Page Size Distribution').encode('iso-8859-1', 'replace')
+    c.width=request.cfg.chart_options['width']
+    c.height=request.cfg.chart_options['height']
+    c.xtitle=_('page size upper bound [bytes]').encode('iso-8859-1', 'replace')
+    c.ytitle=_('# of pages of this size').encode('iso-8859-1', 'replace')
+    #c.annotate(point=bisect.bisect(bounds, upper_bound), color='black', note="%d %s" % sizes[-1])
+    c.title_font_size="GIANT"
+    c.stack_type="LAYER"
+    c.threeD_depth=2.0
+    c.requested_yinterval=1.0
+    c.setLabels(labels)
+
+    import tempfile
+    f = tempfile.NamedTemporaryFile(suffix=".gif")
+    c.draw(f.file)
+    f.file.seek(0)
+    image.write(f.file.read())
+    f.close()
+

     headers = [
         "Content-Type: image/gif",
diff -x '*.pyc' -u stats.old/useragents.py stats/useragents.py
--- stats.old/useragents.py     2009-05-28 09:45:06.000000000 +0200
+++ stats/useragents.py 2009-05-28 16:11:41.000000000 +0200
@@ -120,12 +120,11 @@

 def draw(pagename, request):
     import shutil, cStringIO
-    from MoinMoin.stats.chart import Chart, ChartData, Color
+    import gdchart
+    from MoinMoin.util.web import Color

     _ = request.getText

-    style = Chart.GDC_3DPIE
-
     # get data
     colors = ['red', 'mediumblue', 'yellow', 'deeppink', 'aquamarine', 'purple', 'beige',
               'blue', 'forestgreen', 'orange', 'cyan', 'fuchsia', 'lime']
@@ -152,26 +151,34 @@

     # create image
     image = cStringIO.StringIO()
-    c = Chart()
-    c.addData(data)
+    c = gdchart.Pie3D()
+    c.bg_color= 0xffffff
+    c.line_color = 0x000000
+    c.setData(*data)

     title = ''
     if request.cfg.sitename: title = "%s: " % request.cfg.sitename
     title = title + _('Distribution of User-Agent Types')
-    c.option(
-        pie_color=colors,
-        label_font=Chart.GDC_SMALL,
-        label_line=1,
-        label_dist=20,
-        threed_depth=20,
-        threed_angle=225,
-        percent_labels=Chart.GDCPIE_PCT_RIGHT,
-        title_font=c.GDC_GIANT,
-        title=title.encode('iso-8859-1', 'replace')) # gdchart can't do utf-8
+    c.color=colors
+    c.label_font_size=0 #'SMALL'
+    c.label_line=1
+    c.label_dist=20
+    c.threeD_depth=20
+    c.threeD_angle=225
+    c.percent_labels='RIGHT'
+    c.title_font_size=2 #"GIANT"
+    c.title=title.encode('iso-8859-1', 'replace') # gdchart can't do utf-8
     labels = [label.encode('iso-8859-1', 'replace') for label in labels]
-    c.draw(style,
-        (request.cfg.chart_options['width'], request.cfg.chart_options['height']),
-        image, labels)
+    c.setLabels( labels )
+    c.width = request.cfg.chart_options['width']
+    c.height = request.cfg.chart_options['height']
+
+    import tempfile
+    f = tempfile.NamedTemporaryFile(suffix=".gif")
+    c.draw(f.file)
+    f.file.seek(0)
+    image.write(f.file.read())
+    f.close()

     headers = [
         "Content-Type: image/gif",


CategoryFeatureRequest

MoinMoin: FeatureRequests/SupportGdchart2 (last edited 2015-05-14 22:34:39 by MarkSapiro)