Browse Source

Changed TimeSeries test to match that of the ruby test.

Moved base Graph css into a separate file.
Incorporated cssutils for actual CSS parsing (many warnings and errors occur).
Updated dependencies.
pull/8/head
jaraco 16 years ago
parent
commit
042af6d09c
  1. 87
      lib/svg/charts/graph.css
  2. 107
      lib/svg/charts/graph.py
  3. 3
      setup.py
  4. 2
      tests/testing.py

87
lib/svg/charts/graph.css

@ -0,0 +1,87 @@
.svgBackground{
fill:#ffffff;
}
.graphBackground{
fill:#f0f0f0;
}
/* graphs titles */
.mainTitle{
text-anchor: middle;
fill: #000000;
font-size: %(title_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.subTitle{
text-anchor: middle;
fill: #999999;
font-size: %(subtitle_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.axis{
stroke: #000000;
stroke-width: 1px;
}
.guideLines{
stroke: #666666;
stroke-width: 1px;
stroke-dasharray: 5 5;
}
.xAxisLabels{
text-anchor: middle;
fill: #000000;
font-size: %(x_label_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.yAxisLabels{
text-anchor: end;
fill: #000000;
font-size: %(y_label_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.xAxisTitle{
text-anchor: middle;
fill: #ff0000;
font-size: %(x_title_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.yAxisTitle{
fill: #ff0000;
text-anchor: middle;
font-size: %(y_title_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.dataPointLabel{
fill: #000000;
text-anchor:middle;
font-size: 10px;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.staggerGuideLine{
fill: none;
stroke: #000000;
stroke-width: 0.5px;
}
.keyText{
fill: #000000;
text-anchor:start;
font-size: %(key_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}

107
lib/svg/charts/graph.py

@ -4,7 +4,8 @@
from xml.dom import minidom as dom
from operator import itemgetter
from itertools import islice
from cssutils import css, stylesheets
import cssutils
import pkg_resources
try:
import zlib
@ -642,105 +643,11 @@ class Graph(object):
self.graph_height = self.height - self.border_top - self.border_bottom
def get_style(self):
sheet = css.CSSStyleSheet()
master_bg_style = css.CSSStyleDeclaration()
master_bg_style.setProperty('fill', '#ffffff')
rule = css.CSSStyleRule(selectorText=u'.svgBackground', style=master_bg_style)
sheet.insertRule(rule)
result = sheet.cssText
result = """/* Copy from here for external style sheet */
.svgBackground{
fill:#ffffff;
}
.graphBackground{
fill:#f0f0f0;
}
/* graphs titles */
.mainTitle{
text-anchor: middle;
fill: #000000;
font-size: %(title_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.subTitle{
text-anchor: middle;
fill: #999999;
font-size: %(subtitle_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.axis{
stroke: #000000;
stroke-width: 1px;
}
.guideLines{
stroke: #666666;
stroke-width: 1px;
stroke-dasharray: 5 5;
}
.xAxisLabels{
text-anchor: middle;
fill: #000000;
font-size: %(x_label_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.yAxisLabels{
text-anchor: end;
fill: #000000;
font-size: %(y_label_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.xAxisTitle{
text-anchor: middle;
fill: #ff0000;
font-size: %(x_title_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.yAxisTitle{
fill: #ff0000;
text-anchor: middle;
font-size: %(y_title_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.dataPointLabel{
fill: #000000;
text-anchor:middle;
font-size: 10px;
font-family: "Arial", sans-serif;
font-weight: normal;
}
.staggerGuideLine{
fill: none;
stroke: #000000;
stroke-width: 0.5px;
}
%%s
.keyText{
fill: #000000;
text-anchor:start;
font-size: %(key_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
}
/* End copy for external style sheet */
""" % class_dict(self)
result = result % self.get_css()
css_stream = pkg_resources.resource_stream('svg.charts', 'graph.css')
css_string = css_stream.read()
sheet = cssutils.parseString(css_string).cssText
sheet = sheet % class_dict(self)
result = '\n'.join((sheet, self.get_css()))
return result
def _create_element(self, nodeName, attributes={}):

3
setup.py

@ -16,7 +16,8 @@ setup(name = "svg.charts",
package_dir = {'':'lib'},
install_requires=[
'python-dateutil>=1.4',
'cssutils==0.9.5',
'cssutils>=0.9.5.1',
# TODO: consider lxml
],
license = "MIT",
long_description = """\

2
tests/testing.py

@ -23,7 +23,7 @@ g = time_series.Plot({})
g.timescale_divisions = '4 hours'
g.stagger_x_labels = True
g.x_label_format = '%d-%b %H:%M'
g.max_y_value = 200
#g.max_y_value = 200
g.add_data({'data': ['2005-12-21T00:00:00', 20, '2005-12-22T00:00:00', 21], 'title': 'series 1'})

Loading…
Cancel
Save