Browse Source

Fixes

pull/8/head
Florian Mounier 13 years ago
parent
commit
eb260b90e6
  1. 5
      demo/simple_test.py
  2. 20
      pygal/css/graph.css
  3. 2
      pygal/graph/bar.py
  4. 2
      pygal/graph/line.py
  5. 13
      pygal/js/graph.coffee
  6. 20
      pygal/js/graph.js
  7. 2
      pygal/style.py
  8. 6
      pygal/svg.py

5
demo/simple_test.py

@ -29,6 +29,7 @@ bar.add('test1', rng)
bar.add('test2', map(abs, rng)) bar.add('test2', map(abs, rng))
bar.x_labels = map(str, rng) bar.x_labels = map(str, rng)
bar.title = "Bar test" bar.title = "Bar test"
bar.fill = True
with open('out-bar.svg', 'w') as f: with open('out-bar.svg', 'w') as f:
f.write(bar.render()) f.write(bar.render())
@ -71,8 +72,8 @@ hstackedbar.add('--->', rng3)
with open('out-horizontalstackedbar.svg', 'w') as f: with open('out-horizontalstackedbar.svg', 'w') as f:
f.write(hstackedbar.render()) f.write(hstackedbar.render())
line = Line(Config(y_scale=.0005, fill=True, style=NeonStyle, line = Line(Config(y_scale=.0005, style=NeonStyle,
interpolate='univariate', show_dots=False)) interpolate='univariate'))
rng = range(-30, 31, 10) rng = range(-30, 31, 10)
line.add('test1', [cos(x / 10.) for x in rng]) line.add('test1', [cos(x / 10.) for x in rng])
line.add('test2', [sin(x / 10.) for x in rng]) line.add('test2', [sin(x / 10.) for x in rng])

20
pygal/css/graph.css

@ -91,7 +91,10 @@ svg * {
opacity: 0; opacity: 0;
} }
.axis.y .guides:hover .guide.line, .Line .axis.x .guides:hover .guide.line, .XY .axis.x .guides:hover .guide.line { .axis.y .guides:hover .guide.line,
.Line .axis.x .guides:hover .guide.line,
.StackedLine .axis.x .guides:hover .guide.line,
.XY .axis.x .guides:hover .guide.line {
stroke: {{ style.foreground_light }}; stroke: {{ style.foreground_light }};
opacity: 1; opacity: 1;
} }
@ -101,14 +104,19 @@ svg * {
opacity: 1; opacity: 1;
} }
.series .dots .dot circle { .dot circle {
stroke-width: 1px; stroke-width: 1px;
fill-opacity: 1;
} }
.series .dots .dot:hover circle { .dot circle.active {
stroke-width: 5px; stroke-width: 5px;
} }
.nofill {
fill: none;
}
.reactive { .reactive {
fill-opacity: {{ style.opacity }}; fill-opacity: {{ style.opacity }};
} }
@ -130,11 +138,5 @@ svg * {
opacity: 1; opacity: 1;
} }
/* .series .line { */
/* fill-opacity: {{ fill_opacity }}; */
/* } */
{{ style.colors }} {{ style.colors }}

2
pygal/graph/bar.py

@ -81,7 +81,7 @@ class Bar(Graph):
else: else:
y += height / 2 + .3 * self.values_font_size y += height / 2 + .3 * self.values_font_size
self.svg.transposable_node( self.svg.transposable_node(
bar, 'text', serie_node['overlay'], 'text',
x=x + bar_inner_width / 2, x=x + bar_inner_width / 2,
y=y - shift, y=y - shift,
id="reactive-%s" % tag, id="reactive-%s" % tag,

2
pygal/graph/line.py

@ -65,7 +65,7 @@ class Line(Graph):
view_values = self._fill(view_values) view_values = self._fill(view_values)
self.svg.line( self.svg.line(
serie_node['plot'], view_values, serie_node['plot'], view_values,
class_='line reactive') class_='line reactive' + (' nofill' if not self.fill else ''))
def _compute(self): def _compute(self):
self._x_pos = [x / float(self._len - 1) for x in range(self._len) self._x_pos = [x / float(self._len - 1) for x in range(self._len)

13
pygal/js/graph.coffee

@ -23,17 +23,18 @@ deactivate = (elements...) ->
for element in elements for element in elements
rm_class(element, 'active') rm_class(element, 'active')
Function.prototype.bind = (scope) ->
_fun = @
->
_fun.apply(scope, arguments)
reactive = (element) -> document.getElementById('re' + element.id) reactive = (element) -> document.getElementById('re' + element.id)
active = (element) -> document.getElementById(element.id.replace(/re/, '')) active = (element) -> document.getElementById(element.id.replace(/re/, ''))
hover = (elts, over, out) -> hover = (elts, over, out) ->
for elt in elts for elt in elts
elt.addEventListener('mouseover', elt.addEventListener('mouseover', over.bind(elt) , false)
((elt) -> (-> over.call(elt)))(elt) elt.addEventListener('mouseout', out.bind(elt) , false)
, false)
elt.addEventListener('mouseout',
((elt) -> (-> out.call(elt)))(elt)
, false)
@svg_load = -> @svg_load = ->
hover _('.reactive-text'), (-> activate(@, active(@))), (-> deactivate(@, active(@))) hover _('.reactive-text'), (-> activate(@, active(@))), (-> deactivate(@, active(@)))

20
pygal/js/graph.js

@ -49,6 +49,14 @@
return _results; return _results;
}; };
Function.prototype.bind = function(scope) {
var _fun;
_fun = this;
return function() {
return _fun.apply(scope, arguments);
};
};
reactive = function(element) { reactive = function(element) {
return document.getElementById('re' + element.id); return document.getElementById('re' + element.id);
}; };
@ -62,16 +70,8 @@
_results = []; _results = [];
for (_i = 0, _len = elts.length; _i < _len; _i++) { for (_i = 0, _len = elts.length; _i < _len; _i++) {
elt = elts[_i]; elt = elts[_i];
elt.addEventListener('mouseover', (function(elt) { elt.addEventListener('mouseover', over.bind(elt), false);
return function() { _results.push(elt.addEventListener('mouseout', out.bind(elt), false));
return over.call(elt);
};
})(elt), false);
_results.push(elt.addEventListener('mouseout', (function(elt) {
return function() {
return out.call(elt);
};
})(elt), false));
} }
return _results; return _results;
}; };

2
pygal/style.py

@ -26,7 +26,7 @@ class Style(object):
foreground_light='#eee', foreground_light='#eee',
foreground_dark='#555', foreground_dark='#555',
opacity='.8', opacity='.8',
opacity_hover='1', opacity_hover='.3',
transition='250ms', transition='250ms',
colors=( colors=(
'#ff5995', '#b6e354', '#feed6c', '#8cedff', '#9e6ffe', '#ff5995', '#b6e354', '#feed6c', '#8cedff', '#9e6ffe',

6
pygal/svg.py

@ -52,11 +52,7 @@ class Svg(object):
f.read(), f.read(),
style=self.graph.style, style=self.graph.style,
font_sizes=self.graph.font_sizes, font_sizes=self.graph.font_sizes,
hidden='y' if self.graph._horizontal else 'x', hidden='y' if self.graph._horizontal else 'x')
fill_opacity=self.graph.style.opacity
if self.graph.fill else .4,
fill_opacity_hover=self.graph.style.opacity_hover
if self.graph.fill else .6)
style.text = templ.decode('utf-8') style.text = templ.decode('utf-8')
def add_script(self, js): def add_script(self, js):

Loading…
Cancel
Save