"gasolin" <[EMAIL PROTECTED]> writes:

> Compare to http://code.djangoproject.com/wiki/Charts
>
> I started a rough doc that list some Server side & Client side
> solutions for ploting figures with TurboGears
> http://docs.turbogears.org/1.0/GenerateFigures
>
> I belive PlotKit plugin is broken now :P
> For Client side solutions I just found XML/SWF Charts, it is more
> powerful and prety :-)
>
> It's better if someone can point me some method to generate XML more
> gracefully.

I played with it a bit and I have a more standard approach.  This is just a
test case, so I'm not using loops or other facilities from Kid, I'm just using
it to fill a simple template.  This is a chart for packets logged from my
firewall ;-)

My template "xml_chart.kid" is:

================================================================================
<div py:strip="True" xmlns:py="http://purl.org/kid/ns#";>
  <chart>
    <chart_type>column</chart_type>
    
    <chart_value
        decimal_char=','
        separator='.'
        />
    
    <legend_transition 
        type='scale'
        delay='1'
        duration='1'
        /> 
    
    <chart_data>
      <row>
        <null/>
        <string>ETH0</string>
        <string>ETH1</string>
        <string>PPP0</string>
      </row>
      <row>
        <string>Total</string>
        <number py:content="values['total']['eth0']">10</number>
        <number py:content="values['total']['eth1']">30</number>
        <number py:content="values['total']['ppp0']">63</number>
      </row>
      <row>
        <string>TCP</string>
        <number py:content="values['tcp']['eth0']">20</number>
        <number py:content="values['tcp']['eth1']">65</number>
        <number py:content="values['tcp']['ppp0']">55</number>
      </row>
      <row>
        <string>UDP</string>
        <number py:content="values['udp']['eth0']">21</number>
        <number py:content="values['udp']['eth1']">5</number>
        <number py:content="values['udp']['ppp0']">90</number>
      </row>
      <row>
        <string>ICMP</string>
        <number py:content="values['icmp']['eth0']">21</number>
        <number py:content="values['icmp']['eth1']">5</number>
        <number py:content="values['icmp']['ppp0']">90</number>
      </row>
    </chart_data>
  </chart>
</div>
================================================================================

Here "div" can be anything.  It is just a placeholder to declare the xmlns:py
namespace so that Kid works.  This root element is removed from output leaving
just the desired XML.  The numbers filled here are there just to test the
file.  Removing the "div" element I can pass it to the flash directly to check
what output it will give.


In my controller I have:

================================================================================
    @expose(template="fwgrapher.templates.xml_chart", format="xml")
    def flash(self):

        tcp = model.Ulog.select(
            AND(model.Ulog.q.tcpSport != None,
                model.Ulog.q.tcpDport != None))

        udp = model.Ulog.select(
            AND(model.Ulog.q.udpSport != None,
                model.Ulog.q.udpDport != None))
        
        icmp = model.Ulog.select(model.Ulog.q.icmpType != None)

        values = dict()
        values['tcp'] = dict()
        values['udp'] = dict()
        values['icmp'] = dict()
        values['total'] = dict()
        for interface in ('eth0', 'eth1', 'ppp0'):
            tcp = tcp.filter(model.Ulog.q.oobIn == interface)
            udp = udp.filter(model.Ulog.q.oobIn == interface)
            icmp = icmp.filter(model.Ulog.q.oobIn == interface)
            values['tcp'][interface] = int(tcp.count())
            values['udp'][interface] = int(udp.count())
            values['icmp'][interface] = int(icmp.count())
            values['total'][interface] = (int(tcp.count()) + 
                                           int(udp.count()) + 
                                           int(icmp.count()))

        return dict(values = values)
================================================================================

What is missing here is calling the flash interactively through another
template so that one can choose what chart to generate dinamically.  Since it
was just a test I haven't bothered with that.  In my /static/flash directory I
unpacked charts.tgz and created a test.html file to use it with this code:

================================================================================
<HTML>
<BODY bgcolor="#FFFFFF">
    <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
      
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0";
 
      WIDTH="400" 
      HEIGHT="250" 
      id="charts" 
      ALIGN="">
      <PARAM NAME="movie" 
VALUE="charts.swf?library_path=charts_library&xml_source=/flash"></PARAM>
      <PARAM NAME="quality" VALUE="high"></PARAM>
      <PARAM NAME="bgcolor" VALUE="#666666"></PARAM>

      <EMBED src="charts.swf?library_path=charts_library&xml_source=/flash" 
        quality="high"
        bgcolor="#666666"
        WIDTH="400" 
        HEIGHT="250" 
        NAME="charts" 
        ALIGN="" 
        swLiveConnect="true" 
        TYPE="application/x-shockwave-flash" 
        PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer";>
      </EMBED>

    </OBJECT>
  </BODY>
</HTML>
================================================================================


This approach doesn't return neither builds a template directly on the
controller, it keeps using Kid and all of its facilities. :-)


I hope it helps to make your wiki entry a bit better.

-- 
Jorge Godoy      <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to