Skip to content

Commit

Permalink
adding formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
max-anu committed Dec 18, 2024
1 parent d18a2bb commit 66a8466
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 21 deletions.
7 changes: 5 additions & 2 deletions src/accessvis/widgets/calendar_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ def _update_mpl(self, fig, ax, date: datetime.datetime = None, show_year=True):
title = str(date.year)
else:
title = ""
fig.suptitle(title, fontsize=20, fontweight="bold", y=0.08, color=self.text_colour)
fig.suptitle(
title, fontsize=20, fontweight="bold", y=0.08, color=self.text_colour
)

if date is None:
return
else:
day_of_year = date.timetuple().tm_yday - 1
position = day_of_year / 365. * np.pi * 2.0
self.arrow = ax.arrow(position, 0, 0, 8.5, facecolor="#fff", width=0.1, head_length=2,
self.arrow = ax.arrow(position, 0, 0, 8.5,
facecolor="#fff", width=0.1, head_length=2,
edgecolor="black") # , zorder=11, width=1)

def _reset_mpl(self, fig, ax, **kwargs):
Expand Down
32 changes: 25 additions & 7 deletions src/accessvis/widgets/clock_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@


class ClockWidget(WidgetMPL):
def __init__(self, lv, text_colour="white", background="black",
show_seconds=False, show_minutes=True, show_hours=True, **kwargs):
def __init__(
self,
lv,
text_colour="white",
background="black",
show_seconds=False,
show_minutes=True,
show_hours=True,
**kwargs
):
super().__init__(lv=lv, **kwargs)
self.text_colour = text_colour
self.background = background
Expand Down Expand Up @@ -43,18 +51,28 @@ def _update_mpl(self, fig, ax, time: datetime.time = None, **kwargs):
hour = time.hour
minute = time.minute
second = time.second
angles_h = 2 * np.pi * hour / 12 + 2 * np.pi * minute / (12 * 60) + 2 * second / (12 * 60 * 60) - np.pi / 6.0
angles_m = 2 * np.pi * minute / 60 + 2 * np.pi * second / (60 * 60) - np.pi / 6.0
angles_h = (
2 * np.pi * hour / 12 + 2 * np.pi * minute / (12 * 60) + 2 * second / (12 * 60 * 60) - np.pi / 6.0
)
angles_m = (
2 * np.pi * minute / 60 + 2 * np.pi * second / (60 * 60) - np.pi / 6.0
)
angles_s = 2 * np.pi * second / 60 - np.pi / 6.0

if self.show_seconds:
lines = ax.plot([angles_s, angles_s], [0, 0.9], color=self.text_colour, linewidth=1)
lines = ax.plot(
[angles_s, angles_s], [0, 0.9], color=self.text_colour, linewidth=1
)
self.lines.extend(lines)
if self.show_minutes:
lines = ax.plot([angles_m, angles_m], [0, 0.7], color=self.text_colour, linewidth=2)
lines = ax.plot(
[angles_m, angles_m], [0, 0.7], color=self.text_colour, linewidth=2
)
self.lines.extend(lines)
if self.show_hours:
lines = ax.plot([angles_h, angles_h], [0, 0.3], color=self.text_colour, linewidth=4)
lines = ax.plot(
[angles_h, angles_h], [0, 0.3], color=self.text_colour, linewidth=4
)
self.lines.extend(lines)

def _reset_mpl(self, fig, ax, **kwargs):
Expand Down
30 changes: 23 additions & 7 deletions src/accessvis/widgets/season_widget.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import datetime

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
import numpy as np

from .widget_base import WidgetMPL


class SeasonWidget(WidgetMPL):
def __init__(self, lv, text_colour="black", hemisphere="south", **kwargs):
super().__init__(lv=lv, **kwargs)
Expand All @@ -29,10 +30,14 @@ def _make_mpl(self):
# Label Angles
if self.hemisphere == "south":
MONTH = ["Sum", "Aut", "Win", "Spr"]
cmap = LinearSegmentedColormap.from_list("custom_gradient", ["orange", "black", "blue", "black", "orange"])
cmap = LinearSegmentedColormap.from_list(
"custom_gradient", ["orange", "black", "blue", "black", "orange"]
)
else:
MONTH = ["Win", "Spr", "Sum", "Aut"]
cmap = LinearSegmentedColormap.from_list("custom_gradient", ["blue", "black", "orange", "black", "blue"])
cmap = LinearSegmentedColormap.from_list(
"custom_gradient", ["blue", "black", "orange", "black", "blue"]
)

ANGLES = np.linspace(np.pi / 4, 2 * np.pi + np.pi / 4, 4, endpoint=False)
ax.tick_params(axis="x", which="major", pad=12, labelcolor=self.text_colour)
Expand All @@ -41,7 +46,8 @@ def _make_mpl(self):
ax.spines["polar"].set_color(self.text_colour)

# Colour background based on time of year:
dec22 = np.pi * 2.0 * (datetime.date(2001, 12, 22).timetuple().tm_yday - 1) / 365 # summer solstice
dec22_doy = datetime.date(2001, 12, 22).timetuple().tm_yday - 1
dec22 = np.pi * 2.0 * dec22_doy / 365 # summer solstice
r = np.linspace(0, 10, 5)
theta = np.linspace(dec22, dec22 + 2 * np.pi, 500)
R, T = np.meshgrid(r, theta)
Expand All @@ -54,15 +60,25 @@ def _update_mpl(self, fig, ax, date: datetime.datetime = None, show_year=True):
title = str(date.year)
else:
title = ""
fig.suptitle(title, fontsize=20, fontweight="bold", y=0.08, color=self.text_colour)
fig.suptitle(
title, fontsize=20, fontweight="bold", y=0.08, color=self.text_colour
)

if date is None:
return
else:
day_of_year = date.timetuple().tm_yday - 1
position = day_of_year / 365. * np.pi * 2.0
self.arrow = ax.arrow(position, 0, 0, 8.5, facecolor="#fff", width=0.1, head_length=2,
edgecolor="black") # , zorder=11, width=1)
self.arrow = ax.arrow(
position,
0,
0,
8.5,
facecolor="#fff",
width=0.1,
head_length=2,
edgecolor="black"
) # , zorder=11, width=1)

def _reset_mpl(self, fig, ax, **kwargs):
fig.suptitle("")
Expand Down
14 changes: 12 additions & 2 deletions src/accessvis/widgets/text_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@


class TextWidget(WidgetMPL):
def __init__(self, lv, width=300, height=50, text_colour="black", background=(0, 0, 0, 0), **kwargs):
def __init__(
self,
lv,
width=300,
height=50,
text_colour="black",
background=(0, 0, 0, 0),
**kwargs
):
super().__init__(lv, **kwargs)
self.width = width
self.height = height
Expand All @@ -17,7 +25,9 @@ def _make_mpl(self):
fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
ax.set_axis_off()
fig.patch.set_facecolor(self.background)
self.text = ax.text(0.5, 0.5, "", ha="center", va="center", fontsize=20, color=self.text_colour)
self.text = ax.text(
0.5, 0.5, "", ha="center", va="center", fontsize=20, color=self.text_colour
)

return fig, ax

Expand Down
13 changes: 10 additions & 3 deletions src/accessvis/widgets/widget_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from abc import ABC, abstractmethod
from functools import cached_property
import os

import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -25,9 +25,16 @@ def make_overlay(self):
vert_path = os.path.join(Settings.INSTALL_PATH, "widgets", "screen.vert")
frag_path = os.path.join(Settings.INSTALL_PATH, "widgets", "screen.frag")

self.overlay = self.lv.screen(shaders=[vert_path, frag_path], vertices=[[0, 0, 0]], texture="blank.png")
self.overlay = self.lv.screen(
shaders=[vert_path, frag_path], vertices=[[0, 0, 0]], texture="blank.png"
)

self.lv.set_uniforms(self.overlay["name"], scale=self.scale, offset=self.offset, widthToHeight=x / y)
self.lv.set_uniforms(
self.overlay["name"],
scale=self.scale,
offset=self.offset,
widthToHeight=x / y
)
self.overlay.texture(pixels) # Clear texture with transparent image

@abstractmethod
Expand Down

0 comments on commit 66a8466

Please sign in to comment.