Skip to content

Commit

Permalink
Merge pull request #50 from bartekbiz/merged-with-separate-ranges-for…
Browse files Browse the repository at this point in the history
…-every-plot

Merged with separate ranges for every plot
  • Loading branch information
bartekbiz authored Apr 22, 2024
2 parents 35baae3 + d774ab6 commit 965b8d0
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 70 deletions.
5 changes: 3 additions & 2 deletions controls/ApplyButton.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@


class ApplyButton(SmallButton):
def __init__(self, module):
def __init__(self, module, row):
super().__init__(
module.app,
text="Apply",
command=module.apply
)
self.grid(row=99, column=1, padx=10, sticky="ne")
self.grid(row=row, column=1, padx=10, sticky="ne")


# Binding Enter key to apply button
self.bind("<Return>", module.apply)
70 changes: 36 additions & 34 deletions controls/MinMaxFields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@


class XMinMaxFields:
def __init__(self, module):
self.x_min_label = XMinLabel(module)
self.x_min_entry = XMinEntry(module)
def __init__(self, module, row, text, min_value, max_value):
self.x_min_label = XMinLabel(module, row, text)
self.x_min_entry = XMinEntry(module, row, min_value)

self.x_max_label = XMaxLabel(module)
self.x_max_entry = XMaxEntry(module)
self.x_max_label = XMaxLabel(module, row+1, text)
self.x_max_entry = XMaxEntry(module, row+1, max_value)

def destroy(self):
self.x_min_label.destroy()
Expand All @@ -19,12 +19,12 @@ def destroy(self):


class YMinMaxFields:
def __init__(self, module):
self.y_min_label = YMinLabel(module)
self.y_min_entry = YMinEntry(module)
def __init__(self, module, row, text, min_value, max_value):
self.y_min_label = YMinLabel(module, row, text)
self.y_min_entry = YMinEntry(module, row, min_value)

self.y_max_label = YMaxLabel(module)
self.y_max_entry = YMaxEntry(module)
self.y_max_label = YMaxLabel(module, row+1, text)
self.y_max_entry = YMaxEntry(module, row+1, max_value)

def destroy(self):
self.y_min_label.destroy()
Expand All @@ -35,48 +35,50 @@ def destroy(self):


class XMinLabel(TextLabel):
def __init__(self, module):
super().__init__(module.app, text='Xmin')
self.grid(row=6, column=0, padx=10, sticky="nw")
def __init__(self, module, row, text):
super().__init__(module.app, text=f'Xmin for {text}')
self.grid(row=row, column=0, padx=10, sticky="nw")


class XMinEntry(TextEntry):
def __init__(self, module):
super().__init__(module.app, module.plot.x_min)
self.grid(row=6, column=1, padx=10, sticky="ne")
def __init__(self, module, row, min_value):
super().__init__(module.app, min_value) # module.plot.x_min
self.grid(row=row, column=1, padx=10, sticky="ne")


class XMaxLabel(TextLabel):
def __init__(self, module):
super().__init__(module.app, text='Xmax')
self.grid(row=7, column=0, padx=10, sticky="nw")
def __init__(self, module, row, text):
super().__init__(module.app, text=f'Xmax for {text}')
self.grid(row=row, column=0, padx=10, sticky="nw")


class XMaxEntry(TextEntry):
def __init__(self, module):
super().__init__(module.app, module.plot.x_max)
self.grid(row=7, column=1, padx=10, sticky="ne")
def __init__(self, module, row, max_value):
super().__init__(module.app, max_value) # module.plot.x_max
self.grid(row=row, column=1, padx=10, sticky="ne")


class YMinLabel(TextLabel):
def __init__(self, module):
super().__init__(module.app, text='Ymin')
self.grid(row=8, column=0, padx=10, sticky="nw")
def __init__(self, module, row, text):
super().__init__(module.app, text=f'Ymin for {text}')
self.grid(row=row, column=0, padx=10, sticky="nw")


class YMinEntry(TextEntry):
def __init__(self, module):
super().__init__(module.app, module.plot.y_min)
self.grid(row=8, column=1, padx=10, sticky="ne")
def __init__(self, module, row, min_value):
super().__init__(module.app, min_value)
self.grid(row=row, column=1, padx=10, sticky="ne")


class YMaxLabel(TextLabel):
def __init__(self, module):
super().__init__(module.app, text='Ymax')
self.grid(row=9, column=0, padx=10, sticky="nw")
def __init__(self, module, row, text):
super().__init__(module.app, text=f'Ymax for {text}')
self.grid(row=row, column=0, padx=10, sticky="nw")


class YMaxEntry(TextEntry):
def __init__(self, module):
super().__init__(module.app, module.plot.y_max)
self.grid(row=9, column=1, padx=10, sticky="ne")
def __init__(self, module, row, max_value):
super().__init__(module.app, max_value)
self.grid(row=row, column=1, padx=10, sticky="ne")


17 changes: 10 additions & 7 deletions controls/SpanField.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@


class SpanField:
def __init__(self, module):
self.span_label = SpanLabel(module)
self.span_entry = SpanEntry(module)
def __init__(self, module, row):
self.span_label = SpanLabel(module, row)
self.span_entry = SpanEntry(module, row)

def destroy(self):
self.span_label.destroy()
self.span_entry.destroy()


class SpanLabel(TextLabel):
def __init__(self, module):
def __init__(self, module, row):
super().__init__(module.app, text="Span")
self.grid(row=10, column=0, padx=10, sticky="nw")
self.grid(row=row, column=0, padx=10, sticky="nw")




class SpanEntry(TextEntry):
def __init__(self, module):
def __init__(self, module, row):
super().__init__(module.app, module.plot.custom_span)
self.grid(row=10, column=1, padx=10, sticky="ne")
self.grid(row=row, column=1, padx=10, sticky="ne")

4 changes: 2 additions & 2 deletions controls/base/TextEntry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@


class TextEntry(tk.Entry):
def __init__(self, window, textvariable, width=10):
def __init__(self, window, text_variable, width=10):
super().__init__(
window,
textvariable=textvariable,
textvariable=text_variable,
font=("Arial", 12, "normal"),
width=width,
justify="center",
Expand Down
2 changes: 1 addition & 1 deletion controls/base/TextLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class TextLabel(tk.Label):
def __init__(self, window, text, width=5):
def __init__(self, window, text, width=12):
super().__init__(
window,
text=text,
Expand Down
9 changes: 5 additions & 4 deletions modules/BaseModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def __init__(self, app):
self.under_buttons_sep = UnderButtonsSeparator(self)
self.x_minmax_fields = XMinMaxFields(self)
self.y_minmax_fields = YMinMaxFields(self)
self.apply_button = ApplyButton(self)
self.span_field = SpanField(self)
self.span_field = SpanField(self,16)
self.apply_button = ApplyButton(self, 17)
self.under_everything_sep = UnderEverythingSeparator(self)

# Device range
Expand All @@ -46,11 +46,12 @@ def get_name(self):
def close_module(self, *event):
self.plot.close_plot()


self.open_csv_button.destroy()
self.close_button.destroy()
self.under_buttons_sep.destroy()
self.x_minmax_fields.destroy()
self.y_minmax_fields.destroy()
# self.x_minmax_fields.destroy()
# self.y_minmax_fields.destroy()
self.apply_button.destroy()
self.span_field.destroy()
self.under_everything_sep.destroy()
20 changes: 19 additions & 1 deletion modules/DisplacementModule/DisplacementModule.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@

from controls.MinMaxFields import XMinMaxFields, YMinMaxFields
from modules.BaseModule import BaseModule
from enums.ModuleEnum import ModuleEnum


class DisplacementModule(BaseModule):
def __init__(self, app):
super().__init__(app)

# ranges
self.x_minmax_fields_1 = XMinMaxFields(self, row=4, text='x(t)', min_value = self.plot.x_min, max_value = self.plot.x_max)
self.y_minmax_fields_1 = YMinMaxFields(self, row=6, text='x(t)', min_value = self.plot.y_min, max_value = self.plot.y_max)
self.x_minmax_fields_2 = XMinMaxFields(self, row=8, text='v(t)', min_value = self.plot.x_min_2, max_value= self.plot.x_max_2)
self.y_minmax_fields_2 = YMinMaxFields(self, row=10, text='v(t)', min_value = self.plot.y_min_2, max_value = self.plot.y_max_2)
self.x_minmax_fields_3 = XMinMaxFields(self, row=12, text='a(t)', min_value = self.plot.x_min_3, max_value= self.plot.x_max_3)
self.y_minmax_fields_3 = YMinMaxFields(self, row=14, text='a(t)', min_value = self.plot.y_min_3, max_value = self.plot.y_max_3)

def get_name(self):
return ModuleEnum.displacement

def close_module(self, *event):
super().close_module(*event)
self.x_minmax_fields_1.destroy()
self.y_minmax_fields_1.destroy()
self.x_minmax_fields_2.destroy()
self.y_minmax_fields_2.destroy()
self.x_minmax_fields_3.destroy()
self.y_minmax_fields_3.destroy()
38 changes: 20 additions & 18 deletions plots/MainPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,40 @@ def __init__(self, app, data):
self.canvas = None
self.toolbar = None

# Ranges for 1st plot
self.x_min = tk.DoubleVar()
self.x_max = tk.DoubleVar()
self.y_min = tk.DoubleVar()
self.y_max = tk.DoubleVar()

# Ranges for 2 plot
self.x_min_2 = tk.DoubleVar()
self.x_max_2 = tk.DoubleVar()
self.y_min_2 = tk.DoubleVar()
self.y_max_2 = tk.DoubleVar()

# Ranges for 3rd plot
self.x_min_3 = tk.DoubleVar()
self.x_max_3 = tk.DoubleVar()
self.y_min_3 = tk.DoubleVar()
self.y_max_3 = tk.DoubleVar()

self.custom_span = tk.IntVar()
self.custom_span.set(30)
self.span = None
self.set_span_value()

def set_min_max_values(self):
x_min = self.x_min.get()
x_max = self.x_max.get()
self.set_axis_limits(self.ax1, self.x_min.get(), self.x_max.get(), self.y_min.get(), self.y_max.get())
self.set_axis_limits(self.ax2, self.x_min_2.get(), self.x_max_2.get(), self.y_min_2.get(), self.y_max_2.get())
self.set_axis_limits(self.ax3, self.x_min_3.get(), self.x_max_3.get(), self.y_min_3.get(), self.y_max_3.get())

def set_axis_limits(self, axis, x_min, x_max, y_min, y_max):
if x_min < x_max:
self.set_x_min_max_values(x_min, x_max)

y_min = self.y_min.get()
y_max = self.y_max.get()

axis.set_xlim(left=x_min, right=x_max)
if y_min < y_max:
self.set_y_min_max_values(y_min, y_max)

def set_x_min_max_values(self, x_min, x_max):
self.ax1.set_xlim(left=x_min, right=x_max)
self.ax2.set_xlim(left=x_min, right=x_max)
self.ax3.set_xlim(left=x_min, right=x_max)

def set_y_min_max_values(self, y_min, y_max):
self.ax1.set_ylim(bottom=y_min, top=y_max)
self.ax2.set_ylim(bottom=y_min, top=y_max)
self.ax3.set_ylim(bottom=y_min, top=y_max)
axis.set_ylim(bottom=y_min, top=y_max)
print(f"Setting x and y limits for {axis}:x({x_min}, {x_max}), y({y_min}, {y_max}")

def set_span_value(self):
if self.custom_span.get() < 1:
Expand Down
16 changes: 15 additions & 1 deletion tests/animated_plot_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from controls.MinMaxFields import XMinMaxFields
from plots.AnimatedPlot import AnimatedPlot
from app.App import App

Expand All @@ -15,10 +16,23 @@ def plot(app):
yield plot

def test_max_value(plot):
row = 2 # replace with your actual value
text = "Test" # replace with your actual value
min_value = 1 # replace with your actual value
max_value = 5 # replace with your actual value

x_min_max_fields = XMinMaxFields(plot, row, text, min_value, max_value)

plot.animated_y = [1, 2, 3, 5]
assert plot.get_max_value() == 5
assert plot.get_max_value() == 5

def test_min_value(plot):
row = 2 # replace with your actual value
text = "Test" # replace with your actual value
min_value = 1 # replace with your actual value
max_value = 5 # replace with your actual value

x_min_max_fields = XMinMaxFields(plot, row, text, min_value, max_value)
plot.animated_y = [1, 2, 3, 5]
assert plot.get_min_value() == 1

Expand Down

0 comments on commit 965b8d0

Please sign in to comment.