From 89e12d250f10c61e428273e4df83e8fdac4b07f8 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Sun, 29 Oct 2023 20:23:38 +0300 Subject: [PATCH] Fixed incorrect dimensions plotting error --- PyQt-Plotter-Dialog/parser/expression.py | 2 +- PyQt-Plotter-Dialog/plotter_dialog/dialog.py | 18 ++++++++++++++++++ PyQt-Plotter-Dialog/plotter_dialog/utils.py | 10 ++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 PyQt-Plotter-Dialog/plotter_dialog/utils.py diff --git a/PyQt-Plotter-Dialog/parser/expression.py b/PyQt-Plotter-Dialog/parser/expression.py index ebb59d0..50c579d 100644 --- a/PyQt-Plotter-Dialog/parser/expression.py +++ b/PyQt-Plotter-Dialog/parser/expression.py @@ -11,7 +11,7 @@ from .types import FunctionType, OperatorType, ValueType class Expression(abc.ABC): """ Abstract base class for a single parsed expression as a tree data - structure. It also defines its public function for triggering + structure. It also defines its public function for triggering evaluation. Each child class sets `_evaluator` property to a function that accepts variables values and produces numpy array. """ diff --git a/PyQt-Plotter-Dialog/plotter_dialog/dialog.py b/PyQt-Plotter-Dialog/plotter_dialog/dialog.py index 29a510b..ac18323 100644 --- a/PyQt-Plotter-Dialog/plotter_dialog/dialog.py +++ b/PyQt-Plotter-Dialog/plotter_dialog/dialog.py @@ -16,6 +16,7 @@ import numpy as np from .button_group import ButtonGroup from .constants import FUNCTION_NAMES from .graph_requester import GraphRequester +from .utils import size from parser import Parser @@ -189,6 +190,23 @@ class PlotterDialog(QDialog): x = Parser(x_expr).evaluate(self.variable_values) y = Parser(y_expr).evaluate(self.variable_values) + if size(x) != size(y): + dlg = QMessageBox( + QMessageBox.Critical, + "Ошибка", + "\n\n".join( + ( + "Выражения имеют разную размерность", + f'y: "{y}" -> {size(y)}', + f'x: "{x}" -> {size(x)}', + ) + ), + ) + dlg.exec() + + graph_requester.LineEditY.setFocus() + return + xs.append(x) ys.append(y) labels.append(label) diff --git a/PyQt-Plotter-Dialog/plotter_dialog/utils.py b/PyQt-Plotter-Dialog/plotter_dialog/utils.py new file mode 100644 index 0000000..07e64bc --- /dev/null +++ b/PyQt-Plotter-Dialog/plotter_dialog/utils.py @@ -0,0 +1,10 @@ +import numpy as np + +from parser.types import ValueType + + +def size(x: ValueType) -> int: + if isinstance(x, np.ndarray): + return x.size + else: + return 1