Skip to content

Commit

Permalink
Parameter Fitter: Assure some space below ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Oct 21, 2024
1 parent a5d9023 commit 42c9de4
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions Orange/widgets/evaluate/owparameterfitter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Optional, Tuple, Callable, List, Dict, Iterable
from typing import Optional, Tuple, Callable, List, Dict, Iterable, Sized

import numpy as np
from AnyQt.QtCore import QPointF, Qt
from AnyQt.QtGui import QStandardItemModel, QStandardItem
from AnyQt.QtWidgets import QGraphicsSceneHelpEvent, QToolTip
from AnyQt.QtWidgets import QGraphicsSceneHelpEvent, QToolTip, QSpinBox, \
QComboBox

import pyqtgraph as pg

Expand Down Expand Up @@ -39,7 +40,7 @@
def _validate(
data: Table,
learner: Learner,
scorer: Score
scorer: type[Score]
) -> Tuple[float, float]:
# dummy call - Validation would silence the exceptions
learner(data)
Expand All @@ -55,7 +56,7 @@ def _search(
learner: Learner,
fitted_parameter_props: Learner.FittedParameter,
initial_parameters: Dict,
steps: Iterable,
steps: Sized,
progress_callback: Callable = dummy_callback
) -> FitterResults:
progress_callback(0, "Calculating...")
Expand All @@ -76,7 +77,7 @@ def run(
learner: Learner,
fitted_parameter_props: Learner.FittedParameter,
initial_parameters: Dict,
steps: Iterable,
steps: Sized,
state: TaskState
) -> FitterResults:
def callback(i: float, status: str = ""):
Expand Down Expand Up @@ -188,6 +189,7 @@ def set_data(
):
self.__data = scores
self.clear()
self.setLabel(axis="bottom", text=" ")
self.setLabel(axis="left", text=score_name)

ticks = [[(i, f"{tick_name}[{val}]") for i, (val, _)
Expand Down Expand Up @@ -227,7 +229,7 @@ def help_event(self, ev: QGraphicsSceneHelpEvent) -> bool:
index = self.__get_index_at(pos)
text = ""
if index is not None:
value, scores = self.__data[index]
_, scores = self.__data[index]
text = f"<table align=left>" \

Check warning on line 233 in Orange/widgets/evaluate/owparameterfitter.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/evaluate/owparameterfitter.py#L228-L233

Added lines #L228 - L233 were not covered by tests
f"<tr>" \
f"<td><b>Train:</b></td>" \
Expand All @@ -246,8 +248,9 @@ def help_event(self, ev: QGraphicsSceneHelpEvent) -> bool:
def __get_index_at(self, point: QPointF) -> Optional[int]:
x = point.x()
index = round(x)

Check warning on line 250 in Orange/widgets/evaluate/owparameterfitter.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/evaluate/owparameterfitter.py#L249-L250

Added lines #L249 - L250 were not covered by tests
heights_tr = self.__bar_item_tr.opts["height"]
heights_cv = self.__bar_item_cv.opts["height"]
# pylint: disable=unsubscriptable-object
heights_tr: List = self.__bar_item_tr.opts["height"]
heights_cv: List = self.__bar_item_cv.opts["height"]
if 0 <= index < len(heights_tr) and abs(index - x) <= self.BAR_WIDTH:
if index > x and 0 <= point.y() <= heights_tr[index]:
return index
Expand Down Expand Up @@ -293,9 +296,13 @@ def __init__(self):
OWWidget.__init__(self)
ConcurrentWidgetMixin.__init__(self)
self._data: Optional[Table] = None
self._learner: Optional[PLSRegressionLearner] = None
self._learner: Optional[Learner] = None
self.graph: FitterPlot = None
self.__parameters_model = QStandardItemModel()
self.__combo: QComboBox = None
self.__spin_min: QSpinBox = None
self.__spin_max: QSpinBox = None
self.preview: str = ""

self.__pending_parameter_index = self.parameter_index \
if self.parameter_index != self.DEFAULT_PARAMETER_INDEX else None
Expand Down Expand Up @@ -387,15 +394,15 @@ def steps(self) -> Iterable[int]:

@Inputs.data
@check_multiple_targets_input
def set_data(self, data: Table):
def set_data(self, data: Optional[Table]):
self.Error.not_enough_data.clear()
self._data = data
if self._data and len(self._data) < N_FOLD:
self.Error.not_enough_data()
self._data = None

Check warning on line 402 in Orange/widgets/evaluate/owparameterfitter.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/evaluate/owparameterfitter.py#L401-L402

Added lines #L401 - L402 were not covered by tests

@Inputs.learner
def set_learner(self, learner: Learner):
def set_learner(self, learner: Optional[Learner]):
self._learner = learner

def handleNewSignals(self):
Expand Down

0 comments on commit 42c9de4

Please sign in to comment.