|
|
@ -574,19 +574,13 @@ class Graph(object): |
|
|
|
def parse_css(self): |
|
|
|
def parse_css(self): |
|
|
|
"""Take a .css file (classes only please) and parse it into a dictionary |
|
|
|
"""Take a .css file (classes only please) and parse it into a dictionary |
|
|
|
of class/style pairs.""" |
|
|
|
of class/style pairs.""" |
|
|
|
css = self.get_style() |
|
|
|
# todo: save the prefs for use later |
|
|
|
result = {} |
|
|
|
#orig_prefs = cssutils.ser.prefs |
|
|
|
for match in re.finditer('^(?<names>\.(\w+)(?:\s*,\s*\.\w+)*)\s*\{(?<content>[^}]+)\}'): |
|
|
|
cssutils.ser.prefs.useMinified() |
|
|
|
names = match.group_dict()['names'] |
|
|
|
get_pair = lambda r: (r.selectorText, r.style.cssText) |
|
|
|
# apperantly, we're only interested in class names |
|
|
|
result = dict(map(get_pair, self.get_stylesheet())) |
|
|
|
names = filter(None, re.split('\s*,?\s*\.')) |
|
|
|
|
|
|
|
content = match.group_dict()['content'] |
|
|
|
|
|
|
|
# convert all whitespace to |
|
|
|
|
|
|
|
content = re.sub('\s+', ' ', content) |
|
|
|
|
|
|
|
for name in names: |
|
|
|
|
|
|
|
result[name] = ';'.join(result[name], content) |
|
|
|
|
|
|
|
return result |
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
def add_defs(self, defs): |
|
|
|
def add_defs(self, defs): |
|
|
|
"Override and place code to add defs here" |
|
|
|
"Override and place code to add defs here" |
|
|
|
pass |
|
|
|
pass |
|
|
@ -642,11 +636,15 @@ class Graph(object): |
|
|
|
self.graph_width = self.width - self.border_left - self.border_right |
|
|
|
self.graph_width = self.width - self.border_left - self.border_right |
|
|
|
self.graph_height = self.height - self.border_top - self.border_bottom |
|
|
|
self.graph_height = self.height - self.border_top - self.border_bottom |
|
|
|
|
|
|
|
|
|
|
|
def get_style(self): |
|
|
|
def get_stylesheet(self): |
|
|
|
cssutils.log.setLevel(99) # disable log messages |
|
|
|
cssutils.log.setLevel(99) # disable log messages |
|
|
|
css_stream = pkg_resources.resource_stream('svg.charts', 'graph.css') |
|
|
|
css_stream = pkg_resources.resource_stream('svg.charts', 'graph.css') |
|
|
|
css_string = css_stream.read() |
|
|
|
css_string = css_stream.read() |
|
|
|
sheet = cssutils.parseString(css_string).cssText |
|
|
|
sheet = cssutils.parseString(css_string) |
|
|
|
|
|
|
|
return sheet |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_style(self): |
|
|
|
|
|
|
|
sheet = self.get_stylesheet().cssText |
|
|
|
sheet = sheet % class_dict(self) |
|
|
|
sheet = sheet % class_dict(self) |
|
|
|
result = '\n'.join((sheet, self.get_css())) |
|
|
|
result = '\n'.join((sheet, self.get_css())) |
|
|
|
return result |
|
|
|
return result |
|
|
|