Improve graph quality with custom CSS

This commit is contained in:
nemunaire 2022-08-14 13:31:54 +02:00
commit c03e90d38a
2 changed files with 43 additions and 5 deletions

View file

@ -188,7 +188,7 @@ class WeatherRainModule:
thisdayweather = WeatherAPI().get_daily()["data"][0]
gauge = pygal.SolidGauge(half_pie=True, inner_radius=0.70, width=width, height=height*1.55, style=config.pygal_custom_style, show_legend=False, margin_top=-height*0.58, margin_left=1, margin_right=1)
gauge = pygal.SolidGauge(config.pygal_config, half_pie=True, inner_radius=0.70, width=width, height=height*1.55, style=config.pygal_custom_style, show_legend=False, margin_top=-height*0.58, margin_left=1, margin_right=1)
percent_formatter = lambda x: '{:.10g}%'.format(x)
gauge.value_formatter = percent_formatter
@ -222,17 +222,25 @@ class WeatherTemperatureModule:
else:
thisdayweather = thisdayweather[0]
line_chart = pygal.Line(interpolate='cubic', width=width, height=height, inverse_y_axis=False, x_label_rotation=45, secondary_range=(0,100) if thisdayweather["precipProbability"] > 0 else (0,10), **config.charts_opts)
line_chart.value_formatter = lambda x: "%d" % x
hours_weather = WeatherAPI().get_hourly()
hourly_min = 0
hourly_max = 0
for h in hours_weather["data"]:
if hourly_min > h["temperature"]:
hourly_min = h["temperature"]
if hourly_max < h["temperature"]:
hourly_max = h["temperature"]
line_chart = pygal.Line(config.pygal_config, interpolate='cubic', width=width+10, height=height, inverse_y_axis=False, x_label_rotation=45, range=(hourly_min, hourly_max), secondary_range=(0,100) if thisdayweather["precipProbability"] > 0 else (0,10), **config.charts_opts)
line_chart.value_formatter = lambda x: "%d" % x
line_chart.x_labels = [WeatherAPI().read_timestamp(d["time"]).strftime("%Hh") if datetime.fromtimestamp(d["time"]).hour % 2 == 0 else "" for d in hours_weather["data"][:self.limit_futur]]
line_chart.add('Températures', [d["temperature"] for d in hours_weather["data"][:self.limit_futur]], show_dots=False)
if thisdayweather["precipProbability"] > 0:
line_chart.add('Précipitations', [d["precipProbability"] * 100 for d in hours_weather["data"][:self.limit_futur]], secondary=True, show_dots=False, fill=True)
line_chart.add('Précipitations', [d["precipProbability"] * 100 for d in hours_weather["data"][:self.limit_futur]], secondary=True, show_dots=False, fill=True if hourly_min == 0 else False)
else:
line_chart.add('Index UV', [d["uvIndex"] for d in hours_weather["data"][:self.limit_futur]], secondary=True, show_dots=False)