2022-08-11 12:46:36 +00:00
|
|
|
import os
|
2022-08-14 11:31:54 +00:00
|
|
|
from tempfile import NamedTemporaryFile
|
2022-08-11 12:46:36 +00:00
|
|
|
|
|
|
|
from PIL import Image, ImageDraw
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
if os.path.exists('/usr/share/fonts/source-pro/'):
|
|
|
|
self.fnt_R_path = "/usr/share/fonts/source-pro/SourceSansPro-Regular.otf"
|
|
|
|
self.fnt_RI_path = "/usr/share/fonts/source-pro/SourceSansPro-It.otf"
|
|
|
|
self.fnt_RB_path = "/usr/share/fonts/source-pro/SourceSansPro-Bold.otf"
|
|
|
|
elif os.path.exists('/usr/share/fonts/libertine'):
|
|
|
|
self.fnt_R_path = "/usr/share/fonts/libertine/LinBiolinum_Rah.ttf"
|
|
|
|
self.fnt_RI_path = "/usr/share/fonts/libertine/LinBiolinum_RIah.ttf"
|
|
|
|
self.fnt_RB_path = "/usr/share/fonts/libertine/LinBiolinum_RBah.ttf"
|
|
|
|
else:
|
|
|
|
self.fnt_R_path = "/usr/share/fonts/TTF/LinBiolinum_Rah.ttf"
|
|
|
|
self.fnt_RI_path = "/usr/share/fonts/TTF/LinBiolinum_RIah.ttf"
|
|
|
|
self.fnt_RB_path = "/usr/share/fonts/TTF/LinBiolinum_RBah.ttf"
|
|
|
|
|
2022-08-14 11:31:54 +00:00
|
|
|
self.css_overlay = NamedTemporaryFile()
|
|
|
|
with open(self.css_overlay.name, 'w') as f:
|
|
|
|
f.write('''
|
|
|
|
{{ id }} .bound {
|
|
|
|
font-size: 0.9em;
|
|
|
|
}
|
|
|
|
{{ id }} .gauge path {
|
|
|
|
fill-opacity: 1 !important;
|
|
|
|
}
|
|
|
|
{{ id }} .series .line {
|
|
|
|
stroke-width: 2 !important;
|
|
|
|
}
|
|
|
|
{{ id }} .x .guides .line {
|
|
|
|
stroke-width: 0 !important;
|
|
|
|
}
|
|
|
|
{{ id }} .y .guides .line {
|
|
|
|
stroke: #555;
|
|
|
|
stroke-width: 0.7;
|
|
|
|
}
|
|
|
|
{{ id }} .y .guides .line.axis {
|
|
|
|
stroke: #000;
|
|
|
|
stroke-width: 1;
|
|
|
|
}
|
|
|
|
''')
|
|
|
|
|
|
|
|
import pygal
|
|
|
|
self.pygal_config = pygal.Config()
|
|
|
|
self.pygal_config.css.append('file://' + self.css_overlay.name)
|
|
|
|
|
2022-08-11 12:46:36 +00:00
|
|
|
from pygal.style import Style
|
|
|
|
self.pygal_custom_style = Style(
|
|
|
|
background='white',
|
|
|
|
foreground='black',
|
|
|
|
font_family='Source Code Pro',
|
|
|
|
gauge_background="red",
|
|
|
|
colors=('#000', '#777'))
|
|
|
|
|
2022-08-11 13:20:48 +00:00
|
|
|
self.charts_opts = {'style': self.pygal_custom_style, 'show_legend': False, 'margin_right': 7, 'margin_left': 2, 'margin_bottom': 4, 'margin_top': 1}
|
2022-08-11 12:46:36 +00:00
|
|
|
|
|
|
|
class RuleModule:
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.coeff = 0.92
|
|
|
|
|
|
|
|
def draw_module(self, config, width, height):
|
|
|
|
image = Image.new('RGB', (width, height), 'white')
|
|
|
|
draw = ImageDraw.Draw(image)
|
|
|
|
|
|
|
|
draw.rectangle((int((1-self.coeff) * width), 0, int(self.coeff * width), height), fill="black")
|
|
|
|
|
|
|
|
return image
|