openFlashChart.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # This program is free software; you can redistribute it and/or modify
  2. # it under the terms of the GNU General Public License as published by
  3. # the Free Software Foundation; version 2 of the License.
  4. #
  5. # This program is distributed in the hope that it will be useful,
  6. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. # GNU General Public License for more details.
  9. #
  10. # Author: Emanuel Fonseca
  11. # Email: emdfonseca<at>gmail<dot>com
  12. # Date: 25 August 2008
  13. #
  14. # Author: Eugene Kin Chee Yip
  15. # Date: 7 Nov 2008
  16. import cjson
  17. from openFlashChart_elements import (title,
  18. x_legend,
  19. y_legend,
  20. x_axis,
  21. y_axis,
  22. radar_axis,
  23. tooltip)
  24. def flashHTML(width, height, url, ofc_base_url="/flashes/", ofc_swf="OFC.swf" ):
  25. return (
  26. """
  27. <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
  28. codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0"
  29. width="%(width)s" height="%(height)s" id="chart" align="middle">
  30. <param name="allowScriptAccess" value="sameDomain"/>
  31. <param name="movie" value="%(ofc_base_url)s%(ofc_swf)s"/>
  32. <param name="FlashVars" value="data-file=%(url)s"/>
  33. <param name="quality" value="high"/>
  34. <param name="bgcolor" value="#FFFFFF"/>
  35. <embed src="%(ofc_base_url)s%(ofc_swf)s" FlashVars="data-file=%(url)s" quality="high" bgcolor="#FFFFFF"
  36. width=%(width)s height=%(height)s name="chart" align="middle" allowScriptAccess="sameDomain"
  37. type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/>
  38. </object>
  39. """) % locals()
  40. class template(dict):
  41. def __init__(self, title_string, style = None):
  42. self['title'] = title(title_string, style)
  43. def set_x_legend(self, legend, style):
  44. self['x_legend'] = x_legend(legend, style)
  45. def set_y_legend(self, legend, style):
  46. self['y_legend'] = y_legend(legend, style)
  47. def set_x_axis(self, stroke = None, tick_height = None, colour = None, grid_colour = None, labels = None, three_d = None, max = None, min = None, steps = None, offset = None):
  48. self['x_axis'] = x_axis(stroke, tick_height, colour, grid_colour, labels, three_d, max, min, steps, offset)
  49. def set_y_axis(self, stroke = None, tick_length = None, colour = None, grid_colour = None, labels = None, max = None, min = None, steps = None, offset = None):
  50. self['y_axis'] = y_axis(stroke, tick_length, colour, grid_colour, labels, max, min, steps, offset)
  51. def set_y_axis_right(self, stroke = None, tick_length = None, colour = None, grid_colour = None, labels = None, max = None, min = None, steps = None, offset = None):
  52. self['y_axis_right'] = y_axis(stroke, tick_length, colour, grid_colour, labels, max, min, steps, offset)
  53. def set_radar_axis(self, stroke = None, tick_height = None, colour = None, grid_colour = None, labels = None, max = None, min = None, steps = None, spoke_labels = None):
  54. self['radar_axis'] = radar_axis(stroke, tick_height, colour, grid_colour, labels, max, min, steps, spoke_labels)
  55. def set_bg_colour(self, colour):
  56. self['bg_colour'] = colour
  57. def set_tooltip(self, shadow = None, stroke = None, colour = None, bg_colour = None, title_style = None, body_style = None, behaviour = None):
  58. self['tooltip'] = tooltip(shadow, stroke, colour, bg_colour, title_style, body_style, behaviour)
  59. def add_element(self, element):
  60. try:
  61. self['elements'].append(element)
  62. except:
  63. self['elements'] = [element]
  64. def encode(self):
  65. return cjson.encode(self)