rephorm 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rephorm/__init__.py +19 -0
- rephorm/decorators/__init__.py +0 -0
- rephorm/decorators/settings_validation.py +49 -0
- rephorm/dict/__init__.py +1 -0
- rephorm/dict/colors.py +22 -0
- rephorm/dict/legend_positions.py +136 -0
- rephorm/dict/styles.py +206 -0
- rephorm/dict/update_layout.py +129 -0
- rephorm/dict/update_traces.py +90 -0
- rephorm/object_mappers/__init__.py +0 -0
- rephorm/object_mappers/_globals.py +16 -0
- rephorm/object_mappers/_utilities/__init__.py +0 -0
- rephorm/object_mappers/_utilities/chart_mapper_utility.py +34 -0
- rephorm/object_mappers/_utilities/grid_mapper_utility.py +11 -0
- rephorm/object_mappers/_utilities/table_mapper_utility.py +59 -0
- rephorm/object_mappers/chapter_mapper.py +82 -0
- rephorm/object_mappers/chart_mapper.py +120 -0
- rephorm/object_mappers/chart_series_mapper.py +52 -0
- rephorm/object_mappers/grid_mapper.py +106 -0
- rephorm/object_mappers/page_break_mapper.py +8 -0
- rephorm/object_mappers/report_mapper.py +76 -0
- rephorm/object_mappers/table_mapper.py +191 -0
- rephorm/object_mappers/table_section_mapper.py +41 -0
- rephorm/object_mappers/table_series_mapper.py +79 -0
- rephorm/object_mappers/text_mapper.py +36 -0
- rephorm/object_params/__init__.py +0 -0
- rephorm/object_params/settings.py +184 -0
- rephorm/objects/__init__.py +0 -0
- rephorm/objects/_utilities/__init__.py +0 -0
- rephorm/objects/_utilities/settings_container.py +8 -0
- rephorm/objects/chapter.py +44 -0
- rephorm/objects/chart.py +70 -0
- rephorm/objects/chart_series.py +40 -0
- rephorm/objects/footnote.py +13 -0
- rephorm/objects/grid.py +57 -0
- rephorm/objects/page_break.py +13 -0
- rephorm/objects/report.py +196 -0
- rephorm/objects/table.py +76 -0
- rephorm/objects/table_section.py +48 -0
- rephorm/objects/table_series.py +36 -0
- rephorm/objects/text.py +35 -0
- rephorm/utility/PDF.py +80 -0
- rephorm/utility/__init__.py +0 -0
- rephorm/utility/add_style_prefix.py +30 -0
- rephorm/utility/fonts/OpenSans-Bold.ttf +0 -0
- rephorm/utility/fonts/OpenSans-BoldItalic.ttf +0 -0
- rephorm/utility/fonts/OpenSans-Italic.ttf +0 -0
- rephorm/utility/fonts/OpenSans.ttf +0 -0
- rephorm/utility/fonts/__init__.py +0 -0
- rephorm/utility/fonts/font_loading.py +74 -0
- rephorm/utility/is_set.py +9 -0
- rephorm/utility/merge/__init__.py +0 -0
- rephorm/utility/merge/chart_properties_manager.py +80 -0
- rephorm/utility/merge/merge_settings.py +134 -0
- rephorm/utility/merge/merge_styles.py +79 -0
- rephorm/utility/merge/pdf_merger.py +29 -0
- rephorm/utility/report/__init__.py +0 -0
- rephorm/utility/report/add_footnotes.py +46 -0
- rephorm/utility/report/cleanup_utility.py +19 -0
- rephorm/utility/report/footnotes_counter.py +15 -0
- rephorm/utility/report/image_utility.py +14 -0
- rephorm/utility/report/layout_utility.py +59 -0
- rephorm/utility/report/range_utility.py +94 -0
- rephorm/utility/report/report_utility.py +93 -0
- rephorm/utility/report/resolve_color.py +39 -0
- rephorm/utility/report/table_utility.py +71 -0
- rephorm/utility/report/title_utility.py +49 -0
- rephorm/utility/unit_converter.py +12 -0
- rephorm-1.0.1.dist-info/METADATA +41 -0
- rephorm-1.0.1.dist-info/RECORD +73 -0
- rephorm-1.0.1.dist-info/WHEEL +5 -0
- rephorm-1.0.1.dist-info/licenses/LICENSE +21 -0
- rephorm-1.0.1.dist-info/top_level.txt +1 -0
rephorm/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# from .report import *
|
|
2
|
+
from rephorm.objects.report import Report
|
|
3
|
+
from rephorm.objects.table_section import TableSection
|
|
4
|
+
from rephorm.objects.table import Table
|
|
5
|
+
from rephorm.objects.page_break import PageBreak
|
|
6
|
+
from rephorm.objects.grid import Grid
|
|
7
|
+
from rephorm.objects.chart import Chart
|
|
8
|
+
from rephorm.objects.chapter import Chapter
|
|
9
|
+
from .objects.text import Text
|
|
10
|
+
from rephorm.objects.footnote import Footnote
|
|
11
|
+
from rephorm.objects.chart_series import ChartSeries
|
|
12
|
+
from rephorm.objects.table_series import TableSeries
|
|
13
|
+
|
|
14
|
+
__version__ = "1.0.1"
|
|
15
|
+
__author__ = 'OGResearch team'
|
|
16
|
+
__credits__ = 'OGResearch'
|
|
17
|
+
__license__ = 'Copyright 2025 OGResearch, all rights reserved'
|
|
18
|
+
|
|
19
|
+
|
|
File without changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
|
|
3
|
+
from rephorm.object_params.settings import object_params
|
|
4
|
+
|
|
5
|
+
def validate_kwargs(func):
|
|
6
|
+
"""
|
|
7
|
+
A decorator that validates kwargs (keys and values).
|
|
8
|
+
It uses ultimate_setting_owner dict!
|
|
9
|
+
"""
|
|
10
|
+
def wrapper(*args, **kwargs):
|
|
11
|
+
module_name = func.__module__.split('.')[-1].upper()
|
|
12
|
+
|
|
13
|
+
signature = inspect.signature(func)
|
|
14
|
+
excluded_keys = set(signature.parameters.keys())
|
|
15
|
+
|
|
16
|
+
for key, value in kwargs.items():
|
|
17
|
+
|
|
18
|
+
# Skip validation for object args/params (We want to validate only kwargs)
|
|
19
|
+
if key in excluded_keys and key not in object_params:
|
|
20
|
+
continue
|
|
21
|
+
|
|
22
|
+
# Validate key | If the key is within object_params (allowed keys)
|
|
23
|
+
if key not in object_params:
|
|
24
|
+
raise KeyError(f"{module_name}: Invalid key '{key}'. "
|
|
25
|
+
f"Allowed keys are: {list(object_params.keys())}")
|
|
26
|
+
|
|
27
|
+
# Get the expected type from ultimate_setting_owner
|
|
28
|
+
expected_type = object_params[key]["type"]
|
|
29
|
+
object_params_key = object_params[key]
|
|
30
|
+
|
|
31
|
+
# Validate value type
|
|
32
|
+
# to skip type-checking for complex types
|
|
33
|
+
if expected_type is None:
|
|
34
|
+
continue
|
|
35
|
+
if not isinstance(value, expected_type):
|
|
36
|
+
raise TypeError(
|
|
37
|
+
f"{module_name}: Argument '{key}' must be of type {expected_type.__name__}, "
|
|
38
|
+
f"got {type(value).__name__} instead."
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Validate possible values | if they are defined within the object_params
|
|
42
|
+
if "possible_values" in object_params_key and value not in object_params_key["possible_values"]:
|
|
43
|
+
possible_values = object_params_key["possible_values"]
|
|
44
|
+
raise ValueError(
|
|
45
|
+
f"{module_name}: Argument '{key}' has invalid value '{value}'. Allowed values are: {possible_values}")
|
|
46
|
+
|
|
47
|
+
return func(*args, **kwargs)
|
|
48
|
+
|
|
49
|
+
return wrapper
|
rephorm/dict/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#
|
rephorm/dict/colors.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Matlab default colors: https://nl.mathworks.com/help/matlab/creating_plots/specify-plot-colors.html
|
|
2
|
+
# Keep codes in hex format here, because FontFace do not accept rgb or rgba, (and we use it for text)
|
|
3
|
+
# for charts and plotly we do conversion to rgba in resolve_highlight_color
|
|
4
|
+
|
|
5
|
+
color_codes = {
|
|
6
|
+
"red": "#FF0000",
|
|
7
|
+
"r": "#FF0000",
|
|
8
|
+
"green": "#00FF00",
|
|
9
|
+
"g": "#00FF00",
|
|
10
|
+
"blue": "#0000FF",
|
|
11
|
+
"b": "#0000FF",
|
|
12
|
+
"cyan": "#00FFFF",
|
|
13
|
+
"c": "#00FFFF",
|
|
14
|
+
"magenta": "#FF00FF",
|
|
15
|
+
"m": "#FF00FF",
|
|
16
|
+
"yellow": "#FFFF00",
|
|
17
|
+
"y": "#FFFF00",
|
|
18
|
+
"black": "#000000",
|
|
19
|
+
"k": "#000000",
|
|
20
|
+
"white": "#FFFFFF",
|
|
21
|
+
"w": "#FFFFFF"
|
|
22
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
legend_positions = {
|
|
2
|
+
# Center positions
|
|
3
|
+
"C": { # Center (Inline)
|
|
4
|
+
"x": 0.5,
|
|
5
|
+
"y": 0.5,
|
|
6
|
+
"xanchor": "center",
|
|
7
|
+
"yanchor": "middle",
|
|
8
|
+
"yref": "paper"
|
|
9
|
+
},
|
|
10
|
+
# Inside positions
|
|
11
|
+
"N": { # North (Top-Center)
|
|
12
|
+
"x": 0.5,
|
|
13
|
+
"y": 1,
|
|
14
|
+
"xanchor": "center",
|
|
15
|
+
"yanchor": "top",
|
|
16
|
+
"yref": "paper"
|
|
17
|
+
},
|
|
18
|
+
"S": { # South (Bottom-Center)
|
|
19
|
+
"x": 0.5,
|
|
20
|
+
"y": 0,
|
|
21
|
+
"xanchor": "center",
|
|
22
|
+
"yanchor": "bottom",
|
|
23
|
+
"yref": "paper"
|
|
24
|
+
},
|
|
25
|
+
"E": { # East (Right-Center)
|
|
26
|
+
"x": 1,
|
|
27
|
+
"y": 0.5,
|
|
28
|
+
"xanchor": "right",
|
|
29
|
+
"yanchor": "middle",
|
|
30
|
+
"yref": "paper"
|
|
31
|
+
},
|
|
32
|
+
"W": { # West (Left-Center)
|
|
33
|
+
"x": 0,
|
|
34
|
+
"y": 0.5,
|
|
35
|
+
"xanchor": "left",
|
|
36
|
+
"yanchor": "middle",
|
|
37
|
+
"yref": "paper"
|
|
38
|
+
},
|
|
39
|
+
"NE": { # North-East (Top-Right)
|
|
40
|
+
"x": 1,
|
|
41
|
+
"y": 1,
|
|
42
|
+
"xanchor": "right",
|
|
43
|
+
"yanchor": "top",
|
|
44
|
+
"yref": "paper"
|
|
45
|
+
},
|
|
46
|
+
"NW": { # North-West (Top-Left)
|
|
47
|
+
"x": 0,
|
|
48
|
+
"y": 1,
|
|
49
|
+
"xanchor": "left",
|
|
50
|
+
"yanchor": "top",
|
|
51
|
+
"yref": "paper"
|
|
52
|
+
},
|
|
53
|
+
"SE": { # South-East (Bottom-Right)
|
|
54
|
+
"x": 1,
|
|
55
|
+
"y": 0,
|
|
56
|
+
"xanchor": "right",
|
|
57
|
+
"yanchor": "bottom",
|
|
58
|
+
"yref": "paper"
|
|
59
|
+
},
|
|
60
|
+
"SW": { # South-West (Bottom-Left)
|
|
61
|
+
"x": 0,
|
|
62
|
+
"y": 0,
|
|
63
|
+
"xanchor": "left",
|
|
64
|
+
"yanchor": "bottom",
|
|
65
|
+
"yref": "paper"
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
# Outside positions
|
|
69
|
+
"NO": { # North-Outside (Above Top-Center)
|
|
70
|
+
"x": 0.5,
|
|
71
|
+
"y": 0.89,
|
|
72
|
+
"xanchor": "center",
|
|
73
|
+
"yanchor": "top",
|
|
74
|
+
"yref": "container"
|
|
75
|
+
},
|
|
76
|
+
"SO": { # South-Outside (Below Bottom-Center)
|
|
77
|
+
"x": 0.5,
|
|
78
|
+
# "y": 0,
|
|
79
|
+
"xanchor": "center",
|
|
80
|
+
# "yanchor": "bottom",
|
|
81
|
+
# "yref": "container"
|
|
82
|
+
},
|
|
83
|
+
# South-Outside (ADJUSTED) Need proper testing
|
|
84
|
+
# TODO: Consider changing back to "paper" and off-setting POS using negatives.
|
|
85
|
+
# "SO": {
|
|
86
|
+
# "x": 0.5,
|
|
87
|
+
# "y": -0.15,
|
|
88
|
+
# "xanchor": "center",
|
|
89
|
+
# "yanchor": "top",
|
|
90
|
+
# "yref": "paper"
|
|
91
|
+
# },
|
|
92
|
+
"EO": { # East-Outside (Right of Chart)
|
|
93
|
+
"x": 0.8,
|
|
94
|
+
"y": 0.5,
|
|
95
|
+
"xanchor": "left",
|
|
96
|
+
"yanchor": "middle",
|
|
97
|
+
"yref": "container",
|
|
98
|
+
"xref": "container"
|
|
99
|
+
},
|
|
100
|
+
"WO": { # West-Outside (Left of Chart)
|
|
101
|
+
"x": 0,
|
|
102
|
+
"y": 0.5,
|
|
103
|
+
"xanchor": "left",
|
|
104
|
+
"yanchor": "middle",
|
|
105
|
+
"yref": "container",
|
|
106
|
+
"xref": "container"
|
|
107
|
+
},
|
|
108
|
+
"NEO": { # North-East-Outside (Above Top-Right)
|
|
109
|
+
"x": 1,
|
|
110
|
+
"y": -0.1,
|
|
111
|
+
"xanchor": "right",
|
|
112
|
+
"yanchor": "top",
|
|
113
|
+
"yref": "container"
|
|
114
|
+
},
|
|
115
|
+
"NWO": { # North-West-Outside (Above Top-Left)
|
|
116
|
+
"x": 0,
|
|
117
|
+
"y": -0.1,
|
|
118
|
+
"xanchor": "left",
|
|
119
|
+
"yanchor": "top",
|
|
120
|
+
"yref": "container"
|
|
121
|
+
},
|
|
122
|
+
"SEO": {
|
|
123
|
+
"x": 1,
|
|
124
|
+
"y": 0,
|
|
125
|
+
"xanchor": "right",
|
|
126
|
+
"yanchor": "bottom",
|
|
127
|
+
"yref": "container",
|
|
128
|
+
},
|
|
129
|
+
"SWO": { # South-West-Outside (Below Bottom-Left)
|
|
130
|
+
"x": 0,
|
|
131
|
+
"y": 0,
|
|
132
|
+
"xanchor": "left",
|
|
133
|
+
"yanchor": "bottom",
|
|
134
|
+
"yref": "container"
|
|
135
|
+
}
|
|
136
|
+
}
|
rephorm/dict/styles.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
DEFAULT_FONT_FAMILY = "Helvetica" # This was agreed upon
|
|
2
|
+
|
|
3
|
+
def default_styles(font_family=DEFAULT_FONT_FAMILY):
|
|
4
|
+
return {
|
|
5
|
+
"table": {
|
|
6
|
+
"highlight_color": "#E0E0E0",
|
|
7
|
+
"title": {
|
|
8
|
+
"font_style": "B",
|
|
9
|
+
"font_family": font_family,
|
|
10
|
+
"font_color": "#000000",
|
|
11
|
+
"font_size": 13,
|
|
12
|
+
},
|
|
13
|
+
"heading": {
|
|
14
|
+
"font_style": "",
|
|
15
|
+
"font_family": font_family,
|
|
16
|
+
"font_color": "#000000",
|
|
17
|
+
"font_size": 10,
|
|
18
|
+
"highlight_color": "#E0E0E0",
|
|
19
|
+
},
|
|
20
|
+
"series": {
|
|
21
|
+
"font_style": "",
|
|
22
|
+
"font_family": font_family,
|
|
23
|
+
"font_color": "#000000",
|
|
24
|
+
"font_size": 10,
|
|
25
|
+
"highlight_color": "#E0E0E0",
|
|
26
|
+
},
|
|
27
|
+
"section": {
|
|
28
|
+
"font_style": "",
|
|
29
|
+
"font_family": font_family,
|
|
30
|
+
"font_color": "#000000",
|
|
31
|
+
"font_size": 10,
|
|
32
|
+
"highlight_color": "#E0E0E0",
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"text": {
|
|
36
|
+
"font_style": "",
|
|
37
|
+
"font_family": font_family,
|
|
38
|
+
"font_size": 10,
|
|
39
|
+
"title": {
|
|
40
|
+
"font_style": "B",
|
|
41
|
+
"font_family": font_family,
|
|
42
|
+
"font_size": 16,
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"footnotes": {
|
|
46
|
+
"font_size": 8,
|
|
47
|
+
"font_color": "#000000",
|
|
48
|
+
"font_style": "",
|
|
49
|
+
"font_family": font_family,
|
|
50
|
+
},
|
|
51
|
+
"grid": {
|
|
52
|
+
"title": {
|
|
53
|
+
"font_style": "B",
|
|
54
|
+
"font_family": font_family,
|
|
55
|
+
"font_color": "#000000",
|
|
56
|
+
"font_size": 13,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
"chapter": {
|
|
60
|
+
"title": {
|
|
61
|
+
"font_style": "B",
|
|
62
|
+
"font_family": font_family,
|
|
63
|
+
"font_color": "#000000",
|
|
64
|
+
"font_size": 16,
|
|
65
|
+
},
|
|
66
|
+
"font_style": "",
|
|
67
|
+
"font_family": font_family,
|
|
68
|
+
"font_size": 11,
|
|
69
|
+
},
|
|
70
|
+
"chart": {
|
|
71
|
+
"highlight_color": "rgba(0, 0, 0, 0.12)",
|
|
72
|
+
"grid_color": "lightgrey",
|
|
73
|
+
"bg_color": "rgba(0, 255, 0, 0)",
|
|
74
|
+
"chart_border_color": "#000000",
|
|
75
|
+
"line_styles_order": [
|
|
76
|
+
"solid"
|
|
77
|
+
],
|
|
78
|
+
"line_color_order": [
|
|
79
|
+
"rgb(31, 119, 180)",
|
|
80
|
+
"rgb(255, 127, 14)",
|
|
81
|
+
"rgb(44, 160, 44)",
|
|
82
|
+
"rgb(214, 39, 40)",
|
|
83
|
+
"rgb(148, 103, 189)",
|
|
84
|
+
"rgb(140, 86, 75)",
|
|
85
|
+
"rgb(227, 119, 194)",
|
|
86
|
+
"rgb(127, 127, 127)",
|
|
87
|
+
"rgb(188, 189, 34)",
|
|
88
|
+
"rgb(23, 190, 207)"
|
|
89
|
+
],
|
|
90
|
+
"bar_color_order": [
|
|
91
|
+
"rgb(31, 119, 180)",
|
|
92
|
+
"rgb(255, 127, 14)",
|
|
93
|
+
"rgb(44, 160, 44)",
|
|
94
|
+
"rgb(214, 39, 40)",
|
|
95
|
+
"rgb(148, 103, 189)",
|
|
96
|
+
"rgb(140, 86, 75)",
|
|
97
|
+
"rgb(227, 119, 194)",
|
|
98
|
+
"rgb(127, 127, 127)",
|
|
99
|
+
"rgb(188, 189, 34)",
|
|
100
|
+
"rgb(23, 190, 207)"
|
|
101
|
+
],
|
|
102
|
+
"line_width_order": [1],
|
|
103
|
+
"series": {
|
|
104
|
+
"bar_edge_color": "black",
|
|
105
|
+
"bar_face_color": None,
|
|
106
|
+
"bar_edge_width": 1.0,
|
|
107
|
+
"line_width": None,
|
|
108
|
+
"line_style": None,
|
|
109
|
+
"line_color": None,
|
|
110
|
+
"marker_color": "#46b336",
|
|
111
|
+
"marker_size": 1,
|
|
112
|
+
"marker_width": 1,
|
|
113
|
+
},
|
|
114
|
+
"legend": {
|
|
115
|
+
"border_width": 0,
|
|
116
|
+
"bg_color": "rgba(255, 255, 255, 0)",
|
|
117
|
+
"font_style": "",
|
|
118
|
+
"font_family": font_family,
|
|
119
|
+
"font_color": "#000000",
|
|
120
|
+
"font_size": 8,
|
|
121
|
+
},
|
|
122
|
+
"title": {
|
|
123
|
+
"font_style": "",
|
|
124
|
+
"font_family": font_family,
|
|
125
|
+
"font_color": "#000000",
|
|
126
|
+
"font_size": 11,
|
|
127
|
+
},
|
|
128
|
+
"x_axis": {
|
|
129
|
+
"ticks": {
|
|
130
|
+
"font_size": 10,
|
|
131
|
+
"font_color": "#000000",
|
|
132
|
+
"font_family": font_family,
|
|
133
|
+
},
|
|
134
|
+
"label": {
|
|
135
|
+
"font_size": 10,
|
|
136
|
+
"font_color": "#000000",
|
|
137
|
+
"font_family": font_family,
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"y_axis": {
|
|
141
|
+
"ticks": {
|
|
142
|
+
"font_size": 10,
|
|
143
|
+
"font_color": "#000000",
|
|
144
|
+
"font_family": font_family,
|
|
145
|
+
},
|
|
146
|
+
"label": {
|
|
147
|
+
"font_size": 10,
|
|
148
|
+
"font_color": "#000000",
|
|
149
|
+
"font_family": font_family,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
"y_axis2": {
|
|
153
|
+
"ticks": {
|
|
154
|
+
"font_size": 10,
|
|
155
|
+
"font_color": "#000000",
|
|
156
|
+
"font_family": font_family,
|
|
157
|
+
|
|
158
|
+
},
|
|
159
|
+
"label": {
|
|
160
|
+
"font_size": 10,
|
|
161
|
+
"font_color": "#000000",
|
|
162
|
+
"font_family": font_family,
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
"report": {
|
|
167
|
+
# only front page title
|
|
168
|
+
"title": {
|
|
169
|
+
"font_style": "B",
|
|
170
|
+
"font_size": 25,
|
|
171
|
+
"font_color": "#000000",
|
|
172
|
+
"font_family": font_family,
|
|
173
|
+
},
|
|
174
|
+
"subtitle": {
|
|
175
|
+
"font_style": "B",
|
|
176
|
+
"font_size": 21,
|
|
177
|
+
"font_color": "#000000",
|
|
178
|
+
"font_family": font_family,
|
|
179
|
+
},
|
|
180
|
+
"abstract": {
|
|
181
|
+
"height": 50,
|
|
182
|
+
"font_size": 10,
|
|
183
|
+
"font_color": "#000000",
|
|
184
|
+
"font_family": font_family,
|
|
185
|
+
},
|
|
186
|
+
"footer": {
|
|
187
|
+
"height": 15,
|
|
188
|
+
"top_margin": 5,
|
|
189
|
+
"top_padding": 5,
|
|
190
|
+
},
|
|
191
|
+
"header": {
|
|
192
|
+
"height": 20,
|
|
193
|
+
"bottom_margin": 5,
|
|
194
|
+
},
|
|
195
|
+
"font_style": "",
|
|
196
|
+
"font_family": font_family,
|
|
197
|
+
"font_color": "#000000",
|
|
198
|
+
"page_margin_top": 10,
|
|
199
|
+
"page_margin_right": 40,
|
|
200
|
+
"page_margin_bottom": 15,
|
|
201
|
+
"page_margin_left": 40,
|
|
202
|
+
#Todo: Find a better name for it.
|
|
203
|
+
"title_bottom_padding": 10,
|
|
204
|
+
"logo_height": 15,
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
from rephorm.dict.legend_positions import legend_positions
|
|
2
|
+
from rephorm.utility.report.resolve_color import resolve_color
|
|
3
|
+
|
|
4
|
+
def update_layout(title, settings, figure, y_range = None):
|
|
5
|
+
|
|
6
|
+
# Todo: extract this, but basically this is how to get title style in plotly for chart or for label too (I guess same way for label)
|
|
7
|
+
font_style = settings.styles["chart"]["title"]["font_style"]
|
|
8
|
+
if font_style == "B":
|
|
9
|
+
formatted_title = f"<b>{title}</b>"
|
|
10
|
+
elif font_style == "I":
|
|
11
|
+
formatted_title = f"<i>{title}</i>"
|
|
12
|
+
elif font_style == "BI":
|
|
13
|
+
formatted_title = f"<b><i>{title}</i></b>"
|
|
14
|
+
else:
|
|
15
|
+
formatted_title = title
|
|
16
|
+
|
|
17
|
+
layout = {
|
|
18
|
+
"title": {
|
|
19
|
+
"text": formatted_title,
|
|
20
|
+
"yref": "container", # stop overlaps with plot area
|
|
21
|
+
"yanchor": "top", # align to top
|
|
22
|
+
"x": 0.5,
|
|
23
|
+
"automargin": True, # adjust margins
|
|
24
|
+
"pad": {"b": 5}, # Fine control
|
|
25
|
+
"font_size": settings.styles["chart"]["title"]["font_size"],
|
|
26
|
+
"font_family": settings.styles["chart"]["title"]["font_family"],
|
|
27
|
+
"font_color": resolve_color(settings.styles["chart"]["title"]["font_color"]),
|
|
28
|
+
},
|
|
29
|
+
"plot_bgcolor": resolve_color(settings.styles["chart"]["bg_color"]),
|
|
30
|
+
# paper_bgcolor is kinda useless for us now,
|
|
31
|
+
# because of PDF image choice it will not support transparent bg
|
|
32
|
+
# https://github.com/plotly/Kaleido/issues/91
|
|
33
|
+
"paper_bgcolor": 'hsla(0, 100%, 50%, 0)',
|
|
34
|
+
"margin": {"l": 0,
|
|
35
|
+
"r": 0,
|
|
36
|
+
"t": 5,
|
|
37
|
+
"b": 0
|
|
38
|
+
},
|
|
39
|
+
"xaxis": {
|
|
40
|
+
# TODO: Later on introduce this parameter, to set number of ticks manually.
|
|
41
|
+
# "nticks": settings.styles["chart"]["x_axis"]["ticks"]["nticks"],
|
|
42
|
+
"showgrid": settings.show_grid if settings.show_grid else True,
|
|
43
|
+
"gridcolor": resolve_color(settings.styles["chart"]["grid_color"]),
|
|
44
|
+
"mirror": settings.axis_border,
|
|
45
|
+
"linecolor": resolve_color(settings.styles["chart"]["chart_border_color"]),
|
|
46
|
+
"showline": True,
|
|
47
|
+
"ticks": "inside",
|
|
48
|
+
"tickcolor": "black",
|
|
49
|
+
"linewidth": 1,
|
|
50
|
+
"tickwidth": 1,
|
|
51
|
+
"griddash": "dot",
|
|
52
|
+
"gridwidth": 1,
|
|
53
|
+
"tickfont": {"size": settings.styles["chart"]["x_axis"]["ticks"]["font_size"],
|
|
54
|
+
"family": settings.styles["chart"]["x_axis"]["ticks"]["font_family"],
|
|
55
|
+
"color": settings.styles["chart"]["y_axis"]["ticks"]["font_color"]},
|
|
56
|
+
"title": {
|
|
57
|
+
"text": settings.xaxis_title,
|
|
58
|
+
"font": {
|
|
59
|
+
"size": settings.styles["chart"]["x_axis"]["label"]["font_size"],
|
|
60
|
+
"family": settings.styles["chart"]["x_axis"]["label"]["font_family"]}},
|
|
61
|
+
},
|
|
62
|
+
"yaxis": {
|
|
63
|
+
"zeroline": settings.zeroline if hasattr(settings, 'zeroline') else True,
|
|
64
|
+
"showgrid": settings.show_grid if hasattr(settings, 'show_grid') else True,
|
|
65
|
+
"gridcolor": resolve_color(settings.styles["chart"]["grid_color"]),
|
|
66
|
+
"mirror": settings.axis_border,
|
|
67
|
+
"linecolor": resolve_color(settings.styles["chart"]["chart_border_color"]),
|
|
68
|
+
"showline": True,
|
|
69
|
+
"ticks": "inside",
|
|
70
|
+
"tickcolor": "black",
|
|
71
|
+
"linewidth": 1,
|
|
72
|
+
"tickwidth": 1,
|
|
73
|
+
"griddash": "dot",
|
|
74
|
+
"gridwidth": 1,
|
|
75
|
+
"range": y_range,
|
|
76
|
+
"tickfont": {"size": settings.styles["chart"]["y_axis"]["ticks"]["font_size"],
|
|
77
|
+
"family": settings.styles["chart"]["y_axis"]["ticks"]["font_family"],
|
|
78
|
+
"color": settings.styles["chart"]["y_axis"]["ticks"]["font_color"]},
|
|
79
|
+
"title": {
|
|
80
|
+
"text": settings.yaxis_title,
|
|
81
|
+
"font": {
|
|
82
|
+
"size": settings.styles["chart"]["y_axis"]["label"]["font_size"],
|
|
83
|
+
"family": settings.styles["chart"]["y_axis"]["label"]["font_family"]}},
|
|
84
|
+
},
|
|
85
|
+
"yaxis2": {
|
|
86
|
+
"overlaying": "y",
|
|
87
|
+
"side": "right",
|
|
88
|
+
"linecolor": resolve_color(settings.styles["chart"]["chart_border_color"]),
|
|
89
|
+
"showline": True,
|
|
90
|
+
"ticks": "inside",
|
|
91
|
+
"tickcolor": "black",
|
|
92
|
+
"linewidth": 1,
|
|
93
|
+
"tickwidth": 1,
|
|
94
|
+
"range": y_range,
|
|
95
|
+
"tickfont": {"size": settings.styles["chart"]["y_axis2"]["ticks"]["font_size"],
|
|
96
|
+
"family": settings.styles["chart"]["y_axis2"]["ticks"]["font_family"],
|
|
97
|
+
"color": settings.styles["chart"]["y_axis2"]["ticks"]["font_color"]},
|
|
98
|
+
"title": {
|
|
99
|
+
"text": settings.yaxis2_title,
|
|
100
|
+
"font": {
|
|
101
|
+
"size": settings.styles["chart"]["y_axis2"]["label"]["font_size"],
|
|
102
|
+
"family": settings.styles["chart"]["y_axis2"]["label"]["font_family"]}},
|
|
103
|
+
},
|
|
104
|
+
"legend": {
|
|
105
|
+
"font": {
|
|
106
|
+
"size": settings.styles["chart"]["legend"]["font_size"],
|
|
107
|
+
"family": settings.styles["chart"]["legend"]["font_family"],
|
|
108
|
+
"color": resolve_color(settings.styles["chart"]["legend"]["font_color"])
|
|
109
|
+
},
|
|
110
|
+
"orientation": settings.legend_orientation.lower(),
|
|
111
|
+
"x": legend_positions.get(settings.legend_position.upper()).get("x"),
|
|
112
|
+
"y": legend_positions.get(settings.legend_position.upper()).get("y"),
|
|
113
|
+
"xanchor": legend_positions.get(settings.legend_position.upper()).get("xanchor"),
|
|
114
|
+
"yanchor": legend_positions.get(settings.legend_position.upper()).get("yanchor"),
|
|
115
|
+
"borderwidth": settings.styles["chart"]["legend"]["border_width"],
|
|
116
|
+
"yref": legend_positions.get(settings.legend_position.upper()).get("yref"),
|
|
117
|
+
"xref": legend_positions.get(settings.legend_position.upper()).get("xref"),
|
|
118
|
+
"bgcolor": resolve_color(settings.styles["chart"]["legend"]["bg_color"]),
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# Update conditionally only if the user explicitly specifies 'ncols'.
|
|
123
|
+
legend_ncol = settings.legend_ncol
|
|
124
|
+
if bool(legend_ncol):
|
|
125
|
+
figure.layout.legend["entrywidth"] = 1 / legend_ncol
|
|
126
|
+
figure.layout.legend["entrywidthmode"] = "fraction"
|
|
127
|
+
|
|
128
|
+
figure.update_layout(layout)
|
|
129
|
+
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Prepare shared (base-level) trace update settings for Plotly plots.
|
|
3
|
+
|
|
4
|
+
This function returns general trace configuration that applies uniformly
|
|
5
|
+
across all traces — where no fine-grained (per-trace) control is needed
|
|
6
|
+
between multivariate and single-series cases.
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
def update_base_traces(settings):
|
|
10
|
+
yaxis = getattr(settings, "yaxis", "left")
|
|
11
|
+
if settings.series_type == "line":
|
|
12
|
+
update_traces = {
|
|
13
|
+
"mode": settings.markers_mode,
|
|
14
|
+
"marker": {
|
|
15
|
+
"symbol": settings.marker_symbol,
|
|
16
|
+
"size": settings.styles["chart"]["series"]["marker_size"],
|
|
17
|
+
"line.width": settings.styles["chart"]["series"]["marker_width"],
|
|
18
|
+
"line.color": settings.styles["chart"]["series"]["marker_color"],
|
|
19
|
+
"color": settings.styles["chart"]["series"]["marker_color"],
|
|
20
|
+
},
|
|
21
|
+
"marker.color": settings.styles["chart"]["series"]["marker_color"],
|
|
22
|
+
"yaxis": "y2" if yaxis == "right" else "y1"
|
|
23
|
+
}
|
|
24
|
+
elif "bar" in settings.series_type.lower():
|
|
25
|
+
update_traces = {
|
|
26
|
+
"type": "bar",
|
|
27
|
+
"marker": {
|
|
28
|
+
"line.color": settings.styles["chart"]["series"]["bar_edge_color"],
|
|
29
|
+
"line.width": settings.styles["chart"]["series"]["bar_edge_width"],
|
|
30
|
+
},
|
|
31
|
+
"yaxis": "y2" if yaxis == "right" else "y1"
|
|
32
|
+
}
|
|
33
|
+
else: update_traces = {}
|
|
34
|
+
|
|
35
|
+
return update_traces
|
|
36
|
+
|
|
37
|
+
def apply_per_trace_styles(
|
|
38
|
+
fig,
|
|
39
|
+
line_colors=None,
|
|
40
|
+
line_widths=None,
|
|
41
|
+
line_styles=None,
|
|
42
|
+
bar_colors=None,
|
|
43
|
+
num_variants=None,
|
|
44
|
+
):
|
|
45
|
+
"""
|
|
46
|
+
Apply per-trace styling to a Plotly figure.
|
|
47
|
+
|
|
48
|
+
Supports passing a single value or a list for each style type.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
if not fig.data:
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
traces = fig.data[-num_variants:]
|
|
55
|
+
|
|
56
|
+
for idx, trace in enumerate(traces):
|
|
57
|
+
|
|
58
|
+
if trace.type == 'scatter':
|
|
59
|
+
|
|
60
|
+
color = get_value(line_colors, idx)
|
|
61
|
+
if color:
|
|
62
|
+
trace.line.color = color
|
|
63
|
+
|
|
64
|
+
width = get_value(line_widths, idx)
|
|
65
|
+
if width:
|
|
66
|
+
trace.line.width = width
|
|
67
|
+
|
|
68
|
+
dash = get_value(line_styles, idx)
|
|
69
|
+
if dash:
|
|
70
|
+
trace.line.dash = dash
|
|
71
|
+
|
|
72
|
+
elif trace.type == 'bar':
|
|
73
|
+
color = get_value(bar_colors, idx)
|
|
74
|
+
if color:
|
|
75
|
+
trace.marker.color = color
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def get_value(value, i):
|
|
79
|
+
"""
|
|
80
|
+
Function to retrieve the appropriate style value for the n-th trace.
|
|
81
|
+
Mainly used for apply_per_trace_styles()
|
|
82
|
+
|
|
83
|
+
:param value: Either a single value or a list of values.
|
|
84
|
+
:param i: trace index
|
|
85
|
+
:return: value (str)
|
|
86
|
+
"""
|
|
87
|
+
if isinstance(value, list):
|
|
88
|
+
# If a list, return value based on trace index, and cycle
|
|
89
|
+
return value[i % len(value)]
|
|
90
|
+
else: return value # bcs single value can also be passed
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# central storage for globals
|
|
2
|
+
from os.path import defpath
|
|
3
|
+
|
|
4
|
+
figure_map = []
|
|
5
|
+
|
|
6
|
+
def set_figure_map(data):
|
|
7
|
+
global figure_map
|
|
8
|
+
figure_map.append(data)
|
|
9
|
+
|
|
10
|
+
def get_figure_map():
|
|
11
|
+
global figure_map
|
|
12
|
+
return figure_map
|
|
13
|
+
|
|
14
|
+
def reset_figure_map():
|
|
15
|
+
global figure_map
|
|
16
|
+
figure_map = []
|