Browse Source

Label rotation

pull/8/head
Florian Mounier 13 years ago
parent
commit
65c45f7670
  1. 27
      pygal/bar.css
  2. 1
      pygal/graph.css
  3. 35
      pygal/graph.py

27
pygal/bar.css

@ -2,6 +2,7 @@
fill-opacity: 0;
-webkit-transition: 250ms;
}
.bar:hover .dataPointLabel {
fill-opacity: 0.9;
fill: #000000;
@ -14,54 +15,54 @@
-webkit-transition: 250ms;
}
.fill:hover{
.fill:hover {
fill-opacity: 0.25;
}
.key1,.fill1{
.key1, .fill1 {
fill: #ff0000;
}
.key2,.fill2{
.key2, .fill2 {
fill: #0000ff;
}
.key3,.fill3{
.key3, .fill3 {
fill: #00ff00;
}
.key4,.fill4{
.key4, .fill4 {
fill: #ffcc00;
}
.key5,.fill5{
.key5, .fill5 {
fill: #00ccff;
}
.key6,.fill6{
.key6, .fill6 {
fill: #ff00ff;
}
.key7,.fill7{
.key7, .fill7 {
fill: #00ffff;
}
.key8,.fill8{
.key8, .fill8 {
fill: #ffff00;
}
.key9,.fill9{
.key9, .fill9 {
fill: #cc6666;
}
.key10,.fill10{
.key10, .fill10 {
fill: #663399;
}
.key11,.fill11{
.key11, .fill11 {
fill: #339900;
}
.key12,.fill12{
.key12, .fill12 {
fill: #9966FF;
}

1
pygal/graph.css

@ -44,7 +44,6 @@ Base styles for pygal.Graph
font-size: %(x_label_font_size)dpx;
font-family: "Arial", sans-serif;
font-weight: normal;
transform: rotate(45deg);
}
.yAxisLabels{

35
pygal/graph.py

@ -11,7 +11,7 @@ from operator import itemgetter
from itertools import islice
import pkg_resources
import functools
import math
import cssutils
from lxml import etree
@ -24,6 +24,14 @@ except ImportError:
zlib = None
def cos(angle):
return math.cos(angle * math.pi / 180)
def sin(angle):
return math.sin(angle * math.pi / 180)
def sort_multiple(arrays):
"sort multiple lists (of equal size) "
"using the first list for the sort keys"
@ -59,7 +67,7 @@ class Graph(object):
min_scale_value = None
show_x_labels = True
stagger_x_labels = False
rotate_x_labels = False
x_label_rotation = 0
step_x_labels = 1
step_include_first_x_label = True
show_y_labels = True
@ -287,7 +295,7 @@ class Graph(object):
bb += 10
if self.show_x_labels:
max_x_label_height_px = self.x_label_font_size
if self.rotate_x_labels:
if self.x_label_rotation:
label_lengths = map(len, self.get_x_labels())
max_x_label_len = reduce(max, label_lengths)
max_x_label_height_px *= 0.6 * max_x_label_len
@ -374,7 +382,7 @@ class Graph(object):
y = self.graph_height + self.x_label_font_size + 3
t = 0 - (self.font_size / 2)
if self.stagger_x_labels and (index % 2):
if self.stagger_x_labels and (index % 2):
stagger = self.x_label_font_size + 5
y += stagger
graph_height = self.graph_height
@ -386,11 +394,12 @@ class Graph(object):
text.set('x', str(x))
text.set('y', str(y))
if self.rotate_x_labels:
transform = 'rotate(90 %d %d) translate(0 -%d)' % \
(x, y - self.x_label_font_size, self.x_label_font_size / 4)
if self.x_label_rotation:
transform = 'rotate(%d %d %d) translate(0 -%d)' % \
(-self.x_label_rotation, x, y - self.x_label_font_size,
self.x_label_font_size / 4)
text.set('transform', transform)
text.set('style', 'text-anchor: start')
text.set('style', 'text-anchor: end')
else:
text.set('style', 'text-anchor: middle')
@ -585,10 +594,10 @@ class Graph(object):
y_offset = self.border_top + self.graph_height + 5
if self.show_x_labels:
max_x_label_height_px = self.x_label_font_size
if self.rotate_x_labels:
if self.x_label_rotation:
longest_label_length = max(map(len, self.get_x_labels()))
# I think 0.6 is the ratio of width to height of characters
max_x_label_height_px *= longest_label_length * 0.6
max_x_label_height_px *= longest_label_length
max_x_label_height_px *= sin(self.x_label_rotation)
y_offset += max_x_label_height_px
if self.stagger_x_labels:
y_offset += max_x_label_height_px + 5
@ -651,8 +660,8 @@ class Graph(object):
self.root.addprevious(pi)
comment_strings = (
u'Generatel with pygal ©Kozea 2011',
' Based upon SVG.Graph by Jason R. Coombs ',
u'Generated with pygal ©Kozea 2011',
'Based upon SVG.Graph by Jason R. Coombs',
)
map(self.root.append, map(etree.Comment, comment_strings))

Loading…
Cancel
Save