Skip to content

Commit

Permalink
updating formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
max-anu committed Dec 18, 2024
1 parent 77f1d24 commit d18a2bb
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/accessvis/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from .calendar_widget import CalendarWidget
from .clock_widget import ClockWidget
from .image_widget import ImageWidget
from .text_widget import TextWidget
from .text_widget import TextWidget
36 changes: 19 additions & 17 deletions src/accessvis/widgets/calendar_widget.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import numpy as np
import matplotlib.pyplot as plt
import calendar
import datetime

import numpy as np
import matplotlib.pyplot as plt

from .widget_base import WidgetMPL


class CalendarWidget(WidgetMPL):
def __init__(self,lv, text_colour='black', **kwargs):
def __init__(self, lv, text_colour="black", **kwargs):
super().__init__(lv=lv, **kwargs)
self.text_colour = text_colour
self.arrow = None

def _make_mpl(self):

plt.rc('axes', linewidth=4)
plt.rc('font', weight='bold')
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}, figsize=(5, 5))
plt.rc("axes", linewidth=4)
plt.rc("font", weight="bold")
fig, ax = plt.subplots(subplot_kw={"projection": "polar"}, figsize=(5, 5))
fig.patch.set_facecolor((0, 0, 0, 0)) # make background transparent
ax.set_facecolor('white') # adds a white ring around edge
ax.set_facecolor("white") # adds a white ring around edge

# Setting up grid
ax.set_rticks([])
ax.grid(False)
ax.set_theta_zero_location('NW')
ax.set_theta_zero_location("NW")
ax.set_theta_direction(-1)

# Label Angles
Expand All @@ -30,36 +33,35 @@ def _make_mpl(self):
MONTH.append(calendar.month_name[i][0])
MONTH = np.roll(MONTH, 2)
ANGLES = np.linspace(0.0, 2 * np.pi, 12, endpoint=False)
ax.tick_params(axis='x', which='major', pad=12, labelcolor=self.text_colour)
ax.tick_params(axis="x", which="major", pad=12, labelcolor=self.text_colour)
ax.set_xticks(ANGLES)
ax.set_xticklabels(MONTH, size=20)
ax.spines['polar'].set_color(self.text_colour)
ax.spines["polar"].set_color(self.text_colour)

# Make Colours:
ax.bar(x=0, height=10, width=np.pi * 2, color='black')
ax.bar(x=0, height=10, width=np.pi * 2, color="black")
for i in range(12):
c = 'darkorange' if i % 2 else 'darkcyan'
c = "darkorange" if i % 2 else "darkcyan"
ax.bar(x=i * np.pi / 6, height=10, width=np.pi / 6, color=c)

return fig, ax


def _update_mpl(self, fig, ax, date: datetime.datetime = None, show_year=True):
if show_year and date is not None:
title = str(date.year)
else:
title = ''
fig.suptitle(title, fontsize=20, fontweight='bold', y=0.08, color=self.text_colour)
title = ""
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):
fig.suptitle('')
fig.suptitle("")
if self.arrow is not None:
self.arrow.remove()
10 changes: 6 additions & 4 deletions src/accessvis/widgets/clock_widget.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import datetime
from .widget_base import WidgetMPL

import matplotlib.pyplot as plt
import numpy as np

from .widget_base import WidgetMPL


class ClockWidget(WidgetMPL):
def __init__(self, lv, text_colour='white', background='black',
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
Expand All @@ -23,14 +25,14 @@ def _make_mpl(self):
plt.setp(ax.get_yticklabels(), visible=False)
ax.set_xticks(np.linspace(0, 2 * np.pi, 12, endpoint=False))
ax.set_xticklabels(range(1, 13))
ax.tick_params(axis='x', which='major', labelcolor=self.text_colour)
ax.tick_params(axis="x", which="major", labelcolor=self.text_colour)
ax.set_theta_direction(-1)
ax.set_theta_offset(np.pi / 3.0)
ax.grid(False)
plt.ylim(0, 1)

ax.set_facecolor(self.background)
ax.spines['polar'].set_color(self.text_colour)
ax.spines["polar"].set_color(self.text_colour)

return fig, ax

Expand Down
1 change: 1 addition & 0 deletions src/accessvis/widgets/image_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import matplotlib.pyplot as plt

from .widget_base import Widget


Expand Down
36 changes: 19 additions & 17 deletions src/accessvis/widgets/season_widget.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,70 @@
import datetime

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

from .widget_base import WidgetMPL

class SeasonWidget(WidgetMPL):
def __init__(self, lv, text_colour='black', hemisphere='south', **kwargs):
def __init__(self, lv, text_colour="black", hemisphere="south", **kwargs):
super().__init__(lv=lv, **kwargs)
self.text_colour = text_colour
self.hemisphere = hemisphere
self.arrow = None

def _make_mpl(self):
plt.rc('axes', linewidth=4)
plt.rc('font', weight='bold')
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}, figsize=(5, 5))
plt.rc("axes", linewidth=4)
plt.rc("font", weight="bold")
fig, ax = plt.subplots(subplot_kw={"projection": "polar"}, figsize=(5, 5))
fig.patch.set_facecolor((0, 0, 0, 0)) # make background transparent
ax.set_facecolor('white') # adds a white ring around edge
ax.set_facecolor("white") # adds a white ring around edge

# Setting up grid
ax.set_rticks([])
ax.grid(False)
ax.set_theta_zero_location('N')
ax.set_theta_zero_location("N")
ax.set_theta_direction(-1)

# Label Angles
if self.hemisphere == 'south':
MONTH = ['Sum', 'Aut', 'Win', 'Spr']
if self.hemisphere == "south":
MONTH = ["Sum", "Aut", "Win", "Spr"]
cmap = LinearSegmentedColormap.from_list("custom_gradient", ["orange", "black", "blue", "black", "orange"])
else:
MONTH = ['Win', 'Spr', 'Sum', 'Aut']
MONTH = ["Win", "Spr", "Sum", "Aut"]
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)
ax.tick_params(axis="x", which="major", pad=12, labelcolor=self.text_colour)
ax.set_xticks(ANGLES)
ax.set_xticklabels(MONTH, size=20)
ax.spines['polar'].set_color(self.text_colour)
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
r = np.linspace(0, 10, 5)
theta = np.linspace(dec22, dec22 + 2 * np.pi, 500)
R, T = np.meshgrid(r, theta)
ax.pcolormesh(T, R, T, cmap=cmap, shading='gouraud')
ax.pcolormesh(T, R, T, cmap=cmap, shading="gouraud")

return fig, ax

def _update_mpl(self, fig, ax, date: datetime.datetime = None, show_year=True):
if show_year and date is not None:
title = str(date.year)
else:
title = ''
fig.suptitle(title, fontsize=20, fontweight='bold', y=0.08, color=self.text_colour)
title = ""
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):
fig.suptitle('')
fig.suptitle("")
if self.arrow is not None:
self.arrow.remove()
9 changes: 5 additions & 4 deletions src/accessvis/widgets/text_widget.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import matplotlib.pyplot as plt

from .widget_base import WidgetMPL


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 @@ -16,13 +17,13 @@ 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

def _update_mpl(self, fig, ax, text='', **kwargs):
def _update_mpl(self, fig, ax, text="", **kwargs):
self.text.set_text(text)

def _reset_mpl(self, fig, ax, **kwargs):
self.text.set_text('')
self.text.set_text("")

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

import matplotlib.pyplot as plt
import numpy as np
import os

from ..earth import Settings

Expand All @@ -22,12 +22,12 @@ def make_overlay(self):
pixels[::, ::, ::] = 0
y, x, c = np.shape(pixels)

vert_path = os.path.join(Settings.INSTALL_PATH, 'widgets', 'screen.vert')
frag_path = os.path.join(Settings.INSTALL_PATH, 'widgets', 'screen.frag')
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.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 All @@ -43,7 +43,7 @@ def update_widget(self, **kwargs):

def remove(self):
if self.overlay is not None:
self.lv.delete(self.overlay['name'])
self.lv.delete(self.overlay["name"])
self.overlay = None
self.lv = None

Expand Down

0 comments on commit d18a2bb

Please sign in to comment.