Browse Source

Style vbar a bit

pull/8/head
Florian Mounier 13 years ago
parent
commit
e2872c01a2
  1. 4
      pygal/bar.py
  2. 17
      pygal/css/bar.css
  3. 4
      pygal/css/graph.css
  4. 27
      pygal/graph.py

4
pygal/bar.py

@ -116,9 +116,9 @@ class VerticalBar(Bar):
node(shadow, 'stop', node(shadow, 'stop',
{'offset': 0, 'stop-color': '#aaa', 'stop-opacity': 0.7}) {'offset': 0, 'stop-color': '#aaa', 'stop-opacity': 0.7})
node(shadow, 'stop', node(shadow, 'stop',
{'offset': '2%', 'stop-color': '#fff', 'stop-opacity': 0}) {'offset': '1%', 'stop-color': '#fff', 'stop-opacity': 1})
node(shadow, 'stop', node(shadow, 'stop',
{'offset': '98%', 'stop-color': '#fff', 'stop-opacity': 0}) {'offset': '99%', 'stop-color': '#fff', 'stop-opacity': 1})
node(shadow, 'stop', node(shadow, 'stop',
{'offset': '100%', 'stop-color': '#aaa', 'stop-opacity': .7}) {'offset': '100%', 'stop-color': '#aaa', 'stop-opacity': .7})

17
pygal/css/bar.css

@ -11,22 +11,23 @@
} }
.upGradientLight { .upGradientLight {
stop-opacity: 0.4; stop-opacity: 0.6;
} }
.downGradientLight { .downGradientLight {
stop-opacity: 0.7; stop-opacity: 0.9;
} }
.key, .fill { .key, .fill {
fill-opacity: 0.9; fill-opacity: 0.9;
stroke: url(#shadow); stroke: #fff;
stroke-width: 2px; stroke-width: 2px;
-webkit-transition: 250ms; -webkit-transition: 250ms;
} }
.fill:hover { .fill:hover {
fill-opacity: 0.5; stroke: #ddd;
fill-opacity: 0.7;
} }
.key1, .fill1 { .key1, .fill1 {
@ -79,19 +80,19 @@
.light1 { .light1 {
stop-color: #ff0000; stop-color: #2a4269;
} }
.light2 { .light2 {
stop-color: #0000ff; stop-color: #38588e;
} }
.light3 { .light3 {
stop-color: #00ff00; stop-color: #476fb2;
} }
.light4 { .light4 {
stop-color: #ffcc00; stop-color: #698bc3;
} }
.light5 { .light5 {

4
pygal/css/graph.css

@ -7,7 +7,7 @@
fill:#ffffff; fill:#ffffff;
} }
.graphBackground{ .graphBackground{
fill:#ffffff; fill: #e8eef6;
} }
/* graphs titles */ /* graphs titles */
@ -30,7 +30,7 @@
} }
.guideLines{ .guideLines{
stroke: #eee; stroke: #fff;
stroke-width: 1px; stroke-width: 1px;
stroke-dasharray: 5,5; stroke-dasharray: 5,5;
} }

27
pygal/graph.py

@ -117,7 +117,7 @@ class Graph(object):
def validate_data(self, conf): def validate_data(self, conf):
try: try:
assert(isinstance(conf['data'], (tuple, list))) assert(isinstance(conf['data'], (tuple, list)))
except TypeError, e: except TypeError:
raise TypeError( raise TypeError(
"conf should be dictionary with 'data' and other items") "conf should be dictionary with 'data' and other items")
except AssertionError: except AssertionError:
@ -185,8 +185,8 @@ class Graph(object):
""" """
transform = 'translate (%s %s)' % (self.border_left, self.border_top) transform = 'translate (%s %s)' % (self.border_left, self.border_top)
self.graph = node(self.root, 'g', transform=transform) self.graph = node(self.root, 'g', transform=transform)
self.back = node(self.graph, 'g', {'class': 'back'})
node(self.graph, 'rect', { node(self.back, 'rect', {
'x': 0, 'x': 0,
'y': 0, 'y': 0,
'width': self.graph_width, 'width': self.graph_width,
@ -195,12 +195,12 @@ class Graph(object):
}) })
#Axis #Axis
node(self.graph, 'path', { node(self.back, 'path', {
'd': 'M 0 0 v%s' % self.graph_height, 'd': 'M 0 0 v%s' % self.graph_height,
'class': 'axis', 'class': 'axis',
'id': 'xAxis' 'id': 'xAxis'
}) })
node(self.graph, 'path', { node(self.back, 'path', {
'd': 'M 0 %s h%s' % (self.graph_height, self.graph_width), 'd': 'M 0 %s h%s' % (self.graph_height, self.graph_width),
'class': 'axis', 'class': 'axis',
'id': 'yAxis' 'id': 'yAxis'
@ -227,6 +227,7 @@ class Graph(object):
def draw_x_labels(self): def draw_x_labels(self):
"Draw the X axis labels" "Draw the X axis labels"
if self.show_x_labels: if self.show_x_labels:
self.xlabels = node(self.graph, 'g', {'class': 'xLabels'})
labels = self.get_x_labels() labels = self.get_x_labels()
count = len(labels) count = len(labels)
@ -239,7 +240,7 @@ class Graph(object):
def draw_x_label(self, label): def draw_x_label(self, label):
label_width = self.field_width() label_width = self.field_width()
index, label = label index, label = label
text = node(self.graph, 'text', {'class': 'xAxisLabels'}) text = node(self.xlabels, 'text', {'class': 'xAxisLabels'})
text.text = label text.text = label
x = index * label_width + self.x_label_offset(label_width) x = index * label_width + self.x_label_offset(label_width)
@ -249,7 +250,7 @@ class Graph(object):
stagger = self.x_label_font_size + 5 stagger = self.x_label_font_size + 5
y += stagger y += stagger
graph_height = self.graph_height graph_height = self.graph_height
node(self.graph, 'path', { node(self.xlabels, 'path', {
'd': 'M%f %f v%d' % (x, graph_height, stagger), 'd': 'M%f %f v%d' % (x, graph_height, stagger),
'class': 'staggerGuideLine' 'class': 'staggerGuideLine'
}) })
@ -288,7 +289,7 @@ class Graph(object):
"Draw the Y axis labels" "Draw the Y axis labels"
if not self.show_y_labels: if not self.show_y_labels:
return return
self.ylabels = node(self.graph, 'g', {'class': 'yLabels'})
labels = self.get_y_labels() labels = self.get_y_labels()
count = len(labels) count = len(labels)
@ -308,7 +309,7 @@ class Graph(object):
def draw_y_label(self, label): def draw_y_label(self, label):
label_height = self.field_height() label_height = self.field_height()
index, label = label index, label = label
text = node(self.graph, 'text', {'class': 'yAxisLabels'}) text = node(self.ylabels, 'text', {'class': 'yAxisLabels'})
text.text = label text.text = label
y = self.y_offset - (label_height * index) y = self.y_offset - (label_height * index)
@ -317,7 +318,7 @@ class Graph(object):
if self.stagger_y_labels and (index % 2): if self.stagger_y_labels and (index % 2):
stagger = self.y_label_font_size + 5 stagger = self.y_label_font_size + 5
x -= stagger x -= stagger
path = node(self.graph, 'path', { node(self.ylabels, 'path', {
'd': 'M%f %f h%d' % (x, y, stagger), 'd': 'M%f %f h%d' % (x, y, stagger),
'class': 'staggerGuideLine' 'class': 'staggerGuideLine'
}) })
@ -338,11 +339,12 @@ class Graph(object):
"Draw the X-axis guidelines" "Draw the X-axis guidelines"
if not self.show_x_guidelines: if not self.show_x_guidelines:
return return
self.xguidelines = node(self.graph, 'g', {'class': 'xGuideLines'})
# skip the first one # skip the first one
for count in range(1, count): for count in range(1, count):
start = label_height * count start = label_height * count
stop = self.graph_height stop = self.graph_height
node(self.graph, 'path', { node(self.xguidelines, 'path', {
'd': 'M %s 0 v%s' % (start, stop), 'd': 'M %s 0 v%s' % (start, stop),
'class': 'guideLines'}) 'class': 'guideLines'})
@ -350,10 +352,11 @@ class Graph(object):
"Draw the Y-axis guidelines" "Draw the Y-axis guidelines"
if not self.show_y_guidelines: if not self.show_y_guidelines:
return return
self.yguidelines = node(self.graph, 'g', {'class': 'yGuideLines'})
for count in range(1, count): for count in range(1, count):
start = self.graph_height - label_height * count start = self.graph_height - label_height * count
stop = self.graph_width stop = self.graph_width
node(self.graph, 'path', { node(self.yguidelines, 'path', {
'd': 'M 0 %s h%s' % (start, stop), 'd': 'M 0 %s h%s' % (start, stop),
'class': 'guideLines'}) 'class': 'guideLines'})

Loading…
Cancel
Save