Browse Source

Restuctured the way stylesheets are loaded so they can be more easily customized by subclasses and so they're less dependent on the class names

pull/8/head
jaraco 15 years ago
parent
commit
99d3b41088
  1. 2
      svg/charts/bar.py
  2. 34
      svg/charts/graph.py
  3. 2
      svg/charts/line.py
  4. 2
      svg/charts/plot.py
  5. 2
      svg/charts/schedule.py

2
svg/charts/bar.py

@ -18,7 +18,7 @@ class Bar(Graph):
scale_divisions = None
css_file = 'bar.css'
stylesheet_names = Graph.stylesheet_names + ['bar.css']
def __init__(self, fields, *args, **kargs):
self.fields = fields

34
svg/charts/graph.py

@ -3,12 +3,13 @@
from operator import itemgetter
from itertools import islice
import cssutils
import pkg_resources
import functools
import cssutils
from lxml import etree
from svg.charts import css # causes the profile to be loaded
from svg.charts import css # causes the SVG profile to be loaded
try:
import zlib
@ -85,6 +86,8 @@ class Graph(object):
compress = False
stylesheet_names = ['graph.css']
def __init__(self, config = {}):
"""Initialize the graph object with the graph settings."""
if self.__class__ is Graph:
@ -660,22 +663,21 @@ class Graph(object):
sheet = cssutils.parseString(css_string)
return sheet
def get_stylesheet(self):
cssutils.log.setLevel(30) # disable INFO log messages
# allow css to include class variables:
def get_stylesheet_resources(self):
"Get the stylesheets for this instance"
# allow css to include class variables
class_vars = class_dict(self)
sheet = self.load_resource_stylesheet('graph.css', class_vars)
child_sheet = self.load_resource_stylesheet(self.css_file, class_vars)
map(sheet.add, child_sheet)
return sheet
#deprecated
def get_style(self):
return self.get_stylesheet().cssText
loader = functools.partial(self.load_resource_stylesheet,
subs=class_vars)
sheets = map(loader, self.stylesheet_names)
return sheets
@property
def css_file(self):
return self.__class__.__name__.lower() + '.css'
def get_stylesheet(self):
cssutils.log.setLevel(30) # disable INFO log messages
def merge_sheets(s1, s2):
map(s1.add, s2)
return s1
return reduce(merge_sheets, self.get_stylesheet_resources())
class class_dict(object):
"Emulates a dictionary, but retrieves class attributes"

2
svg/charts/line.py

@ -90,7 +90,7 @@ class Line(Graph):
#override some defaults
top_align = top_font = right_align = right_font = True
css_file = 'plot.css'
stylesheet_names = Graph.stylesheet_names + ['plot.css']
def max_value(self):
data = map(itemgetter('data'), self.data)

2
svg/charts/plot.py

@ -126,6 +126,8 @@ class Plot(Graph):
stacked = False
stylesheet_names = Graph.stylesheet_names + ['plot.css']
@apply
def scale_x_divisions():
doc = """Determines the scaling for the X axis divisions.

2
svg/charts/schedule.py

@ -116,7 +116,7 @@ class Schedule(Graph):
scale_x_integers = False
bar_gap = True
css_file = 'bar.css'
stylesheet_names = Graph.stylesheet_names + ['bar.css']
def add_data(self, data):
"""

Loading…
Cancel
Save