|
|
@ -1,58 +1,75 @@ |
|
|
|
|
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
|
|
|
# This file is part of pygal |
|
|
|
|
|
|
|
# |
|
|
|
from math import pi, sqrt, sin, cos |
|
|
|
# A python svg graph plotting library |
|
|
|
|
|
|
|
# Copyright © 2012-2015 Kozea |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# This library is free software: you can redistribute it and/or modify it under |
|
|
|
|
|
|
|
# the terms of the GNU Lesser General Public License as published by the Free |
|
|
|
|
|
|
|
# Software Foundation, either version 3 of the License, or (at your option) any |
|
|
|
|
|
|
|
# later version. |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# This library is distributed in the hope that it will be useful, but WITHOUT |
|
|
|
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
|
|
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
|
|
|
|
|
|
# details. |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License |
|
|
|
|
|
|
|
# along with pygal. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
Solid Guage |
|
|
|
|
|
|
|
For each series a solid guage is shown on the plot area. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
from __future__ import division |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from math import pi, sqrt |
|
|
|
|
|
|
|
|
|
|
|
from pygal.graph.graph import Graph |
|
|
|
from pygal.graph.graph import Graph |
|
|
|
from pygal.util import alter, decorate |
|
|
|
from pygal.util import alter, decorate |
|
|
|
|
|
|
|
|
|
|
|
class SolidGauge(Graph): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
class SolidGauge(Graph): |
|
|
|
Solid Guage |
|
|
|
|
|
|
|
For each series a solid guage is shown on the plot area. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See http://en.wikipedia.org/wiki/##### |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gaugify(self, serie, startangle, squares, sq_dimensions, current_square): |
|
|
|
def gaugify( |
|
|
|
|
|
|
|
self, serie, startangle, squares, sq_dimensions, current_square): |
|
|
|
serie_node = self.svg.serie(serie) |
|
|
|
serie_node = self.svg.serie(serie) |
|
|
|
metadata = serie.metadata.get(0) |
|
|
|
metadata = serie.metadata.get(0) or {} |
|
|
|
if 'maxvalue' in metadata.keys(): |
|
|
|
maxvalue = metadata.get('maxvalue', 100) |
|
|
|
maxvalue = metadata['maxvalue'] |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
maxvalue = serie.values[0] * 1.5 |
|
|
|
|
|
|
|
if self.half_pie: |
|
|
|
if self.half_pie: |
|
|
|
center = ((current_square[1]*sq_dimensions[0]) - (sq_dimensions[0] / 2.), |
|
|
|
center = ( |
|
|
|
(current_square[0]*sq_dimensions[1]) - (sq_dimensions[1] / 4)) |
|
|
|
(current_square[1]*sq_dimensions[0]) - (sq_dimensions[0] / 2.), |
|
|
|
|
|
|
|
(current_square[0]*sq_dimensions[1]) - (sq_dimensions[1] / 4)) |
|
|
|
else: |
|
|
|
else: |
|
|
|
center = ((current_square[1]*sq_dimensions[0]) - (sq_dimensions[0] / 2.), |
|
|
|
center = ( |
|
|
|
(current_square[0]*sq_dimensions[1]) - (sq_dimensions[1] / 2.)) |
|
|
|
(current_square[1]*sq_dimensions[0]) - (sq_dimensions[0] / 2.), |
|
|
|
|
|
|
|
(current_square[0]*sq_dimensions[1]) - (sq_dimensions[1] / 2.)) |
|
|
|
|
|
|
|
|
|
|
|
radius = min([sq_dimensions[0]/2, sq_dimensions[1]/2]) |
|
|
|
radius = min([sq_dimensions[0]/2, sq_dimensions[1]/2]) |
|
|
|
value = serie.values[0] |
|
|
|
value = serie.values[0] |
|
|
|
ratio = value / maxvalue |
|
|
|
|
|
|
|
|
|
|
|
ratio = min(value, maxvalue) / maxvalue |
|
|
|
if self.half_pie: |
|
|
|
if self.half_pie: |
|
|
|
angle = 2 * pi * ratio / 2 |
|
|
|
angle = 2 * pi * ratio / 2 |
|
|
|
endangle = pi / 2 |
|
|
|
endangle = pi / 2 |
|
|
|
else: |
|
|
|
else: |
|
|
|
angle = 2 * pi * ratio |
|
|
|
angle = 2 * pi * ratio |
|
|
|
endangle = 2 * pi |
|
|
|
endangle = 2 * pi |
|
|
|
value = self._format(serie) |
|
|
|
value = self._format(value) |
|
|
|
|
|
|
|
|
|
|
|
gauge_ = decorate( |
|
|
|
gauge_ = decorate( |
|
|
|
self.svg, |
|
|
|
self.svg, |
|
|
|
self.svg.node(serie_node['plot'], class_="gauge"), |
|
|
|
self.svg.node(serie_node['plot'], class_="gauge"), |
|
|
|
metadata) |
|
|
|
metadata) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
big_radius = radius * .9 |
|
|
|
big_radius = radius * .9 |
|
|
|
small_radius = radius * serie.inner_radius |
|
|
|
small_radius = radius * serie.inner_radius |
|
|
|
maxvalue = Maxvalue(serie) |
|
|
|
|
|
|
|
print(maxvalue.values) |
|
|
|
|
|
|
|
alter(self.svg.solidgauge( |
|
|
|
alter(self.svg.solidgauge( |
|
|
|
serie_node, gauge_, big_radius, small_radius, |
|
|
|
serie_node, gauge_, big_radius, small_radius, |
|
|
|
angle, startangle, center, value, 0, metadata, self.half_pie, endangle, self._format(maxvalue)), metadata) |
|
|
|
angle, startangle, center, value, 0, metadata, |
|
|
|
|
|
|
|
self.half_pie, endangle, self._format(maxvalue)), metadata) |
|
|
|
|
|
|
|
|
|
|
|
def _compute_x_labels(self): |
|
|
|
def _compute_x_labels(self): |
|
|
|
pass |
|
|
|
pass |
|
|
@ -71,7 +88,8 @@ class SolidGauge(Graph): |
|
|
|
|
|
|
|
|
|
|
|
for index, serie in enumerate(self.series): |
|
|
|
for index, serie in enumerate(self.series): |
|
|
|
current_square = self._current_square(squares, index) |
|
|
|
current_square = self._current_square(squares, index) |
|
|
|
self.gaugify(serie, startangle, squares, sq_dimensions, current_square) |
|
|
|
self.gaugify( |
|
|
|
|
|
|
|
serie, startangle, squares, sq_dimensions, current_square) |
|
|
|
|
|
|
|
|
|
|
|
def _squares(self): |
|
|
|
def _squares(self): |
|
|
|
|
|
|
|
|
|
|
@ -110,20 +128,5 @@ class SolidGauge(Graph): |
|
|
|
current_square[0] += 1 |
|
|
|
current_square[0] += 1 |
|
|
|
else: |
|
|
|
else: |
|
|
|
return tuple(current_square) |
|
|
|
return tuple(current_square) |
|
|
|
return print('Something went wrong with the current square assignment.') |
|
|
|
raise Exception( |
|
|
|
|
|
|
|
'Something went wrong with the current square assignment.') |
|
|
|
class Maxvalue(SolidGauge): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, serie): |
|
|
|
|
|
|
|
self.serie = serie |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
|
|
|
def values(self): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
return [self.serie.metadata[0]['maxvalue']] |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
return [self.serie.values[0] * 1.5] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
|
|
|
def title(self): |
|
|
|
|
|
|
|
return self.serie.title |
|
|
|
|
|
|
|