Skip to content

Commit

Permalink
Parsing line_by and x
Browse files Browse the repository at this point in the history
  • Loading branch information
siranipour committed Jun 10, 2021
1 parent 90e629b commit 4da660a
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions validphys2/src/validphys/plotoptions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import pandas as pd
import numbers

from validobj import ValidationError

from reportengine.floatformatting import format_number
from reportengine.compat import yaml
from reportengine.utils import get_functions, ChainMap
Expand Down Expand Up @@ -234,6 +236,31 @@ class PlottingOptions:

extra_labels: typing.Optional[typing.Mapping[str, typing.List]] = None

def parse_figure_by(self):
if self.figure_by is not None:
for el in self.figure_by:
if el in labeler_functions:
self.func_labels[el] = labeler_functions[el]

def parse_line_by(self):
if self.line_by is not None:
for el in self.line_by:
if el in labeler_functions:
self.func_labels[el] = labeler_functions[el]

def parse_x(self):
if self.x is not None and self.x not in self.all_labels:
raise ValidationError(
f"The label {self.x} is not in the set of known labels {self.all_labels}"
)


@property
def all_labels(self):
if self.extra_labels is None:
return set(default_labels)
return set(self.extra_labels.keys()).union(set(default_labels))

def __post_init__(self):
if self.kinematics_override is not None:
self.kinematics_override = transform_functions[
Expand All @@ -242,10 +269,9 @@ def __post_init__(self):
if self.result_transform is not None:
self.result_transform = result_functions[self.result_transform.name]

if self.figure_by is not None:
for el in self.figure_by:
if el in labeler_functions:
self.func_labels[el] = labeler_functions[el]
self.parse_figure_by()
self.parse_line_by()
self.parse_x()


@dataclasses.dataclass
Expand Down

0 comments on commit 4da660a

Please sign in to comment.