amazon august
This commit is contained in:
136
include/ECM/open_flash_chart2/python-ofc-library/ofc-demo.py
Executable file
136
include/ECM/open_flash_chart2/python-ofc-library/ofc-demo.py
Executable file
@@ -0,0 +1,136 @@
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# Author: Emanuel Fonseca
|
||||
# Email: emdfonseca<at>gmail<dot>com
|
||||
# Date: 25 August 2008
|
||||
|
||||
import cherrypy
|
||||
from string import Template
|
||||
|
||||
import datetime
|
||||
|
||||
import ofc2
|
||||
from ofc2_element import Line, Bar, BarStack
|
||||
|
||||
xhtml_template = """
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
||||
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<script type="text/javascript" src="/static/swfobject.js"></script>
|
||||
<script type="text/javascript">
|
||||
$js
|
||||
</script>
|
||||
<head>
|
||||
|
||||
<title>$title</title>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
$body
|
||||
</body>
|
||||
|
||||
</html>
|
||||
"""
|
||||
|
||||
jstpl = Template('swfobject.embedSWF("/static/open-flash-chart.swf","$title", "$width", "$height", "$flash_ver", "expressInstall.swf", {"data-file": "$data_src"});\n')
|
||||
dvtpl = Template('<h1>$title</h1><div id="$title"></div><br/>\n')
|
||||
|
||||
class Chart(object):
|
||||
type = ''
|
||||
title = 'chart'
|
||||
|
||||
width=400
|
||||
height=200
|
||||
flash_ver='9.0.0'
|
||||
|
||||
data_src = None
|
||||
|
||||
chart = None
|
||||
|
||||
def index(self):
|
||||
return self.chart.encode()
|
||||
index.exposed = True
|
||||
|
||||
def __init__(self, type, name):
|
||||
self.title = name
|
||||
self.data_src='/'+name
|
||||
|
||||
def get_js(self):
|
||||
return jstpl.substitute(title=self.title, width=self.width, height=self.height, flash_ver = self.flash_ver, data_src = self.data_src)
|
||||
|
||||
def get_div(self):
|
||||
return dvtpl.substitute(title=self.title)
|
||||
|
||||
class BarChart(Chart):
|
||||
def __init__(self, type, name):
|
||||
Chart.__init__(self, type, name)
|
||||
|
||||
# create the bar element and set its values
|
||||
element = Bar(values=[9,8,7,6,5,4,3,2,1])
|
||||
|
||||
# create the chart and set its title
|
||||
self.chart = ofc2.open_flash_chart(title=str(datetime.datetime.now()))
|
||||
self.chart.add_element(element)
|
||||
|
||||
class BarStackChart(Chart):
|
||||
def __init__(self, type, name):
|
||||
Chart.__init__(self, type, name)
|
||||
|
||||
# create the bar element and set its values
|
||||
element = BarStack(values=[ [ 2.5, 5 ], [ 7.5 ], [ 5, { 'val': 5, 'colour': '#ff0000' } ], [ 2, 2, 2, 2, { "val": 2, 'colour': '#ff00ff' } ] ])
|
||||
|
||||
# create the chart and set its title
|
||||
self.chart = ofc2.open_flash_chart(title=str(datetime.datetime.now()))
|
||||
self.chart.set_y_axis(min=0, max=14, steps=7)
|
||||
self.chart.set_x_axis(labels=['a', 'b', 'c', 'd'])
|
||||
self.chart.add_element(element)
|
||||
|
||||
class LineChart(Chart):
|
||||
def __init__(self, type, name):
|
||||
Chart.__init__(self, type, name)
|
||||
|
||||
# create the bar element and set its values
|
||||
element = Line(values=[9,8,7,6,5,4,3,2,1])
|
||||
|
||||
# create the chart and set its title
|
||||
self.chart = ofc2.open_flash_chart(title=str(datetime.datetime.now()))
|
||||
self.chart.add_element(element)
|
||||
|
||||
class OFC2Demo(object):
|
||||
tpl = Template(xhtml_template)
|
||||
swfobjs = ''
|
||||
divs = ''
|
||||
|
||||
linechart = LineChart('line_chart', 'linechart') # var name must be the same as the second param
|
||||
barchart = BarChart('bar_chart', 'barchart') # var name must be the same as the second param
|
||||
barstackchart = BarStackChart('bar_stack', 'barstackchart') # var name must be the same as the second param
|
||||
|
||||
def index(self):
|
||||
self.load_charts()
|
||||
response = self.tpl.substitute(title='Open Flash Charts 2 - Python Library Demo', js=self.swfobjs, body=self.divs)
|
||||
return response
|
||||
|
||||
def load_charts(self):
|
||||
self.swfobjs = ''
|
||||
self.divs = ''
|
||||
self.add_chart(self.linechart)
|
||||
self.add_chart(self.barchart)
|
||||
self.add_chart(self.barstackchart)
|
||||
|
||||
def add_chart(self, chart):
|
||||
self.swfobjs += chart.get_js()
|
||||
self.divs += chart.get_div()
|
||||
|
||||
# Expose methods
|
||||
index.exposed = True
|
||||
|
||||
cherrypy.quickstart(OFC2Demo(), '/', 'cherrypy.conf')
|
||||
|
||||
167
include/ECM/open_flash_chart2/python-ofc-library/ofc2.py
Executable file
167
include/ECM/open_flash_chart2/python-ofc-library/ofc2.py
Executable file
@@ -0,0 +1,167 @@
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# Author: Emanuel Fonseca
|
||||
# Email: emdfonseca<at>gmail<dot>com
|
||||
# Date: 25 August 2008
|
||||
|
||||
import cjson
|
||||
|
||||
class Title(dict):
|
||||
def __init__(self, title, style=None):
|
||||
self['text'] = title
|
||||
self.set_style(style)
|
||||
|
||||
def set_style(self, style):
|
||||
if style:
|
||||
self['style'] = style
|
||||
|
||||
class y_legend(Title):
|
||||
pass
|
||||
|
||||
class x_legend(Title):
|
||||
pass
|
||||
|
||||
##########################################
|
||||
# axis classes
|
||||
class axis(dict):
|
||||
def __init__(self, stroke=None, tick_height=None, colour=None, grid_colour=None, steps=None):
|
||||
self.set_stroke(stroke)
|
||||
self.set_tick_height(tick_height)
|
||||
self.set_colour(colour)
|
||||
self.set_grid_colour(grid_colour)
|
||||
self.set_steps(steps)
|
||||
|
||||
def set_stroke(self, stroke):
|
||||
if stroke:
|
||||
self['stroke'] = stroke
|
||||
|
||||
def set_tick_height(self, tick_height):
|
||||
if tick_height:
|
||||
self['tick_height'] = tick_height
|
||||
|
||||
def set_colour(self, colour):
|
||||
if colour:
|
||||
self['colour'] = colour
|
||||
|
||||
def set_grid_colour(self, grid_colour):
|
||||
if grid_colour:
|
||||
self['grid_colour'] = grid_colour
|
||||
|
||||
def set_steps(self, steps):
|
||||
if steps:
|
||||
self['steps'] = steps
|
||||
|
||||
class x_axis(axis):
|
||||
def __init__(self, stroke=None, tick_height=None, colour=None, grid_colour=None, labels=None, steps=None):
|
||||
axis.__init__(self, stroke, tick_height, colour, grid_colour, steps)
|
||||
self.set_labels(labels)
|
||||
self['orientation'] = 2
|
||||
|
||||
def set_labels(self, labels):
|
||||
if labels:
|
||||
self['labels'] = labels
|
||||
|
||||
class y_axis(axis):
|
||||
def __init__(self, stroke=None, tick_height=None, colour=None, grid_colour=None, offset=None, max=None, min=None, steps=None):
|
||||
axis.__init__(self, stroke, tick_height, colour, grid_colour, steps)
|
||||
self.set_offset(offset)
|
||||
self.set_max(max)
|
||||
self.set_min(min)
|
||||
|
||||
def set_offset(self, offset):
|
||||
if offset:
|
||||
self['offset'] = offset
|
||||
|
||||
def set_max(self, max):
|
||||
if max:
|
||||
self['max'] = max
|
||||
|
||||
def set_min(self, min):
|
||||
if min:
|
||||
self['min'] = min
|
||||
|
||||
##########################################
|
||||
# open_flash_chart class
|
||||
class tooltip(dict):
|
||||
def __init__(self, shadow=None, stroke=None, colour=None, bg_colour=None, title_style=None, body_style=None):
|
||||
self.set_shadow(shadow)
|
||||
self.set_stroke(stroke)
|
||||
self.set_colour(colour)
|
||||
self.set_background(bg_colour)
|
||||
self.set_title(title_style)
|
||||
self.set_body(body_style)
|
||||
|
||||
def set_shadow(self, shadow):
|
||||
if shadow:
|
||||
self['shadow'] = shadow
|
||||
|
||||
def set_stroke(self, stroke):
|
||||
if stroke:
|
||||
self['stroke'] = stroke
|
||||
|
||||
def set_colour(self, colour):
|
||||
if colour:
|
||||
self['colour'] = colour
|
||||
|
||||
def set_background(self, background):
|
||||
if background:
|
||||
self['background'] = background
|
||||
|
||||
def set_title(self, title):
|
||||
if title:
|
||||
self['title'] = title
|
||||
|
||||
def set_body(self, body):
|
||||
if body:
|
||||
self['body'] = body
|
||||
|
||||
##########################################
|
||||
# open_flash_chart class
|
||||
class open_flash_chart(dict):
|
||||
def __init__(self, title, style=None):
|
||||
self['title'] = Title(title, style)
|
||||
|
||||
def set_x_legend(self, legend):
|
||||
self['x_legend'] = x_legend(legend)
|
||||
|
||||
def set_y_legend(self, legend):
|
||||
self['y_legend'] = y_legend(legend)
|
||||
|
||||
def set_x_axis(self, stroke=None, tick_height=None, colour=None, grid_colour=None, labels=None, steps=None):
|
||||
self['x_axis'] = x_axis(stroke, tick_height, colour, grid_colour, labels, steps)
|
||||
|
||||
def set_y_axis(self, stroke=None, tick_height=None, colour=None, grid_colour=None, offset=None, max=None, min=None, steps=None):
|
||||
self['y_axis'] = y_axis(stroke, tick_height, colour, grid_colour, offset, max, min, steps)
|
||||
|
||||
def set_y_axis_right(self, stroke=None, tick_height=None, colour=None, grid_colour=None, offset=None, max=None, min=None, steps=None):
|
||||
self['y_axis_right'] = y_axis(stroke, tick_height, colour, grid_colour, offset, max, min, steps)
|
||||
|
||||
def set_bg_colour(self, colour):
|
||||
self['bg_colour'] = colour
|
||||
|
||||
def set_tooltip(self, shadow=None, stroke=None, colour=None, bg_colour=None, title_style=None, body_style=None):
|
||||
self['tooltip'] = tooltip(shadow, stroke, colour, bg_colour, title_style, body_style)
|
||||
|
||||
def add_element(self, element):
|
||||
try:
|
||||
self['elements'].append(element)
|
||||
except:
|
||||
self['elements'] = [element]
|
||||
|
||||
def encode(self):
|
||||
return cjson.encode(self)
|
||||
|
||||
#ofc = open_flash_chart('Example JSON')
|
||||
#ofc.set_y_legend('Example Y Legend')
|
||||
#ofc.set_x_legend('Example X Legend')
|
||||
#ofc.set_x_axis(1, 1, '#ff0000', '#00ff00', ['sun', 'mon', 'tue'])
|
||||
#ofc.set_x_axis(labels=['sun', 'mon', 'tue'])
|
||||
|
||||
#print cjson.encode(ofc)
|
||||
57
include/ECM/open_flash_chart2/python-ofc-library/ofc2_element.py
Executable file
57
include/ECM/open_flash_chart2/python-ofc-library/ofc2_element.py
Executable file
@@ -0,0 +1,57 @@
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# Author: Emanuel Fonseca
|
||||
# Email: emdfonseca<at>gmail<dot>com
|
||||
# Date: 25 August 2008
|
||||
|
||||
class element(dict):
|
||||
def __init__(self, type=None, alpha=None, colour=None, text=None, fontsize=None, values=None):
|
||||
self.set_type(type)
|
||||
self.set_alpha(alpha)
|
||||
self.set_colour(colour)
|
||||
self.set_text(text)
|
||||
self.set_fontsize(fontsize)
|
||||
self.set_values(values)
|
||||
|
||||
def set_type(self, type):
|
||||
if type:
|
||||
self['type'] = type
|
||||
|
||||
def set_alpha(self, alpha):
|
||||
if alpha:
|
||||
self['alpha'] = alpha
|
||||
|
||||
def set_colour(self, colour):
|
||||
if colour:
|
||||
self['colour'] = colour
|
||||
|
||||
def set_text(self, text):
|
||||
if text:
|
||||
self['text'] = text
|
||||
|
||||
def set_fontsize(self, fontsize):
|
||||
if fontsize:
|
||||
self['font-size'] = fontsize
|
||||
|
||||
def set_values(self, values):
|
||||
if values:
|
||||
self['values'] = values
|
||||
|
||||
class Line(element):
|
||||
def __init__(self, type=None, alpha=None, colour=None, text=None, fontsize=None, values=None):
|
||||
element.__init__(self, 'line', alpha, colour, text, fontsize, values)
|
||||
|
||||
class Bar(element):
|
||||
def __init__(self, type=None, alpha=None, colour=None, text=None, fontsize=None, values=None):
|
||||
element.__init__(self, 'bar', alpha, colour, text, fontsize, values)
|
||||
|
||||
class BarStack(element):
|
||||
def __init__(self, type=None, alpha=None, colour=None, text=None, fontsize=None, values=None):
|
||||
element.__init__(self, 'bar_stack', alpha, colour, text, fontsize, values)
|
||||
Reference in New Issue
Block a user