happyscript 0.0.45__tar.gz → 0.0.49__tar.gz

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.
Files changed (58) hide show
  1. {happyscript-0.0.45 → happyscript-0.0.49}/PKG-INFO +1 -1
  2. happyscript-0.0.49/README.md +2 -0
  3. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/__init__.py +1 -1
  4. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/charts/chart.py +229 -229
  5. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/charts/histogram_chart.py +70 -70
  6. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/charts/histogram_series.py +113 -113
  7. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/charts/matplotlib_chart.py +170 -170
  8. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/charts/panel_charts.py +242 -242
  9. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/charts/scatter_chart.py +50 -50
  10. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/charts/scatter_series.py +65 -65
  11. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/charts/time_chart.py +101 -101
  12. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/charts/time_series.py +75 -75
  13. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/forms/form_askchoice.py +76 -76
  14. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/forms/form_askimage.py +115 -115
  15. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/forms/form_main.py +376 -376
  16. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/forms/form_ontestfailure.py +66 -66
  17. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/forms/form_serials.py +218 -218
  18. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/forms/form_settings.py +94 -94
  19. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/forms/form_stop.py +29 -29
  20. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/forms/formsbase.py +2 -2
  21. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/imglib.py +1043 -1043
  22. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/inifile.py +162 -162
  23. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/modulereader.py +129 -129
  24. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/panels/panel_log.py +130 -130
  25. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/panels/panel_messages.py +103 -103
  26. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/panels/panel_scripts2.py +117 -117
  27. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/panels/panel_tests.py +389 -389
  28. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/panels/panelsbase.py +506 -506
  29. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/scriptartwork.py +75 -75
  30. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/scriptcontrol.py +100 -100
  31. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/scriptexceptions.py +18 -18
  32. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/scriptgui.py +336 -336
  33. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/scriptinfo.py +198 -170
  34. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/scriptmanager.py +51 -51
  35. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/scriptparams.py +120 -120
  36. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/scriptreader.py +135 -135
  37. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/scriptrunner.py +226 -226
  38. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/splashmenu/forms.py +69 -69
  39. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/splashmenu/splashmenuform.py +154 -154
  40. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/splashmenu/splashmenumain.py +57 -57
  41. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/staticscriptmanager.py +363 -363
  42. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/testlog/global_log_handler.py +107 -107
  43. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/testlog/log_to_text.py +92 -92
  44. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/testlog/logtoxml.py +66 -66
  45. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/testlog/printredirect.py +74 -74
  46. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/testloghandler.py +31 -31
  47. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/userpanel/userpanel.py +190 -190
  48. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/userpanel/userpanelvalue.py +50 -50
  49. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript.egg-info/PKG-INFO +1 -1
  50. {happyscript-0.0.45 → happyscript-0.0.49}/pyproject.toml +4 -1
  51. happyscript-0.0.45/README.md +0 -2
  52. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/charts/__init__.py +0 -0
  53. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript/splashmenu/exit.png +0 -0
  54. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript.egg-info/SOURCES.txt +0 -0
  55. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript.egg-info/dependency_links.txt +0 -0
  56. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript.egg-info/requires.txt +0 -0
  57. {happyscript-0.0.45 → happyscript-0.0.49}/happyscript.egg-info/top_level.txt +0 -0
  58. {happyscript-0.0.45 → happyscript-0.0.49}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: happyscript
3
- Version: 0.0.45
3
+ Version: 0.0.49
4
4
  Summary: Framework for running scripts
5
5
  Requires-Python: >=3.5
6
6
  Description-Content-Type: text/markdown
@@ -0,0 +1,2 @@
1
+
2
+ More info coming soon...
@@ -1,6 +1,6 @@
1
1
  """HappyScript - handy script launcher"""
2
2
 
3
- __version__ = "0.0.45"
3
+ __version__ = "0.0.49"
4
4
 
5
5
  # With these statements, after doing 'import happyscript' you can do 'xxx = happyscript.ScriptManager()'
6
6
  #from .scriptmanager import ScriptManager
@@ -1,229 +1,229 @@
1
- # ____ _ _
2
- # | _ \ ___| | _(_)_ __ ___ ___ Copyright | Title : Object to hold a chart shown on a panel_chart
3
- # | | | |/ _ \ |/ / | '_ ` _ \ / _ \ (c) 2020 | Project : na
4
- # | |_| | __/ <| | | | | | | (_) | Dekimo | Authors : MVR
5
- # |____/ \___|_|\_\_|_| |_| |_|\___/ Products | Created : 2/1/2022
6
- #__________________________________________________|_________________________________________________________
7
- #
8
- #
9
-
10
- import wx
11
- from wx.lib import plot as wxplot
12
-
13
- class Chart(wxplot.PlotCanvas):
14
- ''' Base object for all charts.
15
- Derived chart has to implement :
16
- * do_redraw (optionally)
17
- * do_add_series
18
- * get_data_as_text
19
- '''
20
-
21
- COLORS = ( wx.Colour(68,114,196), wx.Colour(237,125,49), wx.Colour(165,165,165), wx.Colour(255,193,4),
22
- wx.Colour(91,155,213), wx.Colour(112,173,71), wx.Colour(38,68,120), wx.Colour(158,72,14),
23
- wx.Colour(99,99,99), wx.Colour(153,115,0), wx.Colour(37,94,145), wx.Colour(67,104,43),
24
- wx.Colour(105,142,208), wx.Colour(241,151,90), wx.Colour(183,183,183), wx.Colour(255,205,51),
25
- wx.Colour(124,175,221),
26
- )
27
-
28
-
29
- def __init__(self, parent_control, name):
30
- '''
31
- Constructor
32
- '''
33
- super().__init__(parent_control, -1)
34
-
35
- self.__name = name
36
-
37
- self.enableLegend = True
38
- self.enableGrid = True
39
- self.antiAlias = False
40
-
41
- self._series = dict()
42
- self.__dirty = False
43
- self.__on_update_func = None
44
- self.__num_series_added = 0 # count num of series added, to select next color
45
-
46
- self._xrange = None
47
- self._yrange = None
48
- self.configure(title=name, x_label="", y_label="", x_log=False, y_log=False)
49
-
50
- def get_series_color(self):
51
- ''' Get next color to use for a newly added series.
52
- '''
53
- idx = self.__num_series_added % len(self.COLORS)
54
- self.__num_series_added += 1
55
- return self.COLORS[idx]
56
-
57
- @property
58
- def name(self):
59
- return self.__name
60
-
61
- def configure(self, /, x_label=None, y_label=None, title=None,
62
- y_log=None, x_log=None, x_range=None, y_range=None):
63
- '''
64
-
65
- '''
66
- if title is not None:
67
- self._title = title if isinstance(title, str) else str(title)
68
- self.enablePlotTitle = True if len(self._title)>0 else False
69
- if x_label is not None:
70
- self._xlabel = x_label if isinstance(x_label, str) else str(x_label)
71
- self.enableXAxisLabel = True if len(self._xlabel)>0 else False
72
- if y_label is not None:
73
- self._ylabel = y_label if isinstance(y_label, str) else str(y_label)
74
- self.enableYAxisLabel = True if len(self._ylabel)>0 else False
75
- if x_log is not None:
76
- self._xlog = True if x_log else False
77
- if y_log is not None:
78
- self._ylog = True if y_log else False
79
-
80
- if x_range is not None:
81
- ok = False
82
- if type(x_range) is tuple and len(x_range)==2:
83
- try:
84
- if x_range[0]+1 < x_range[1]+1:
85
- self._xrange = x_range
86
- ok = True
87
- except:
88
- pass
89
- if not ok:
90
- print(f"x_range {x_range} is invalid")
91
-
92
- if y_range is not None:
93
- ok = False
94
- if type(y_range) is tuple and len(y_range)==2:
95
- try:
96
- if y_range[0]+1 < y_range[1]+1:
97
- self._yrange = y_range
98
- ok = True
99
- except:
100
- pass
101
- if not ok:
102
- print(f"y_range {y_range} is invalid")
103
-
104
- self.logScale = (self._xlog, self._ylog)
105
- if len(self._series)>0:
106
- self.update()
107
-
108
- @property
109
- def on_update(self):
110
- ''' The callback function for when data is modified.
111
- '''
112
- return self.__on_update_func
113
-
114
- @on_update.setter
115
- def on_update(self, value):
116
- ''' Set the callback function for when data is modified.
117
- '''
118
- if value is None or callable(value):
119
- self.__on_update_func = value
120
-
121
- @property
122
- def dirty(self):
123
- ''' Returns if the chart needs updating or not.
124
- '''
125
- return self.__dirty
126
-
127
- def update(self, / , antialiasing=False):
128
- ''' Indicate that a chart should be updated. To be executed by a chart series when data is added.
129
- The internal 'dirty' flag is set.
130
- Also, the on_update callback function is called (if one is set).
131
-
132
- In a a chart panel, the callback function will set a flag to indicate that the chart must
133
- be updated.
134
- '''
135
- self.antiAlias = antialiasing
136
- self.__dirty = True
137
- if self.__on_update_func is not None:
138
- self.__on_update_func()
139
-
140
- def redraw(self):
141
- ''' Redraw the chart.
142
- Updates of the charts are 'lazy' : they are not recalculated when data is added.
143
- The GUI calls this function to ask for the chart to be redrawn.
144
- The internal 'dirty' flag is cleared.
145
- '''
146
- self.enableAntiAliasing = self.antiAlias
147
- self.antiAlias = False
148
- self.do_redraw()
149
- # print(f"redraw {self.enableAntiAliasing}")
150
- self.__dirty = False
151
-
152
-
153
- def do_redraw(self):
154
- ''' Is called when the chart must be redrawn.
155
- Standard implementation below.
156
- May be overridden for special kinds of charts.
157
- '''
158
- plot_objects = list()
159
- try:
160
- for series in self._series.values():
161
- if len(series.get_points())>0:
162
- plot_objects.append( series.get_plot_object() )
163
-
164
- except RuntimeError: # occurs sometimes when data is updated during redraw
165
- return
166
-
167
- if len(plot_objects)>0:
168
- pg = wxplot.PlotGraphics(plot_objects, self._title, self._xlabel, self._ylabel)
169
- try:
170
- self.Draw(pg, xAxis=self._xrange, yAxis=self._yrange)
171
- except:
172
- pass
173
-
174
- # def clear(self):
175
- # ''' remove all series from the chart
176
- # '''
177
- # for name in self._series.keys():
178
- # del self._series[name] # delete it
179
- # if hasattr(self, name):
180
- # delattr(self, name) # delete member variable as well
181
-
182
- def delete_series(self, name):
183
- ''' Remove a series from a chart.
184
- '''
185
- if name in self._series: # check if we have a series with that name
186
- del self._series[name] # delete it
187
- if hasattr(self, name):
188
- delattr(self, name) # delete member variable as well
189
-
190
- def add_series(self, name):
191
- ''' Create a new series for this chart.
192
- First checks if name is valid, then calls do_add_series of derived class to create the series.
193
- Series is added as attribute to the chart itself.
194
- '''
195
- if ( not name.isidentifier() or # first check if name is valid
196
- name in ['update', 'redraw', 'add_series', 'delete_series'] or
197
- ( hasattr(self, name) and name not in self._series) ):
198
- raise ValueError("Series name '%s' is invalid" % name)
199
-
200
- self.delete_series(name) # delete old series if necessary
201
-
202
- series = self.do_add_series(name) # create the series and remember it
203
-
204
- if series is not None:
205
- self._series[name] = series
206
- setattr(self, name, series) # also set it as a member variable
207
-
208
- self.update()
209
- return series
210
-
211
- def do_add_series(self, name):
212
- ''' To be implemented by derived class.
213
- '''
214
- return None
215
-
216
- def get_series(self, name):
217
- ''' Return a series by name, or None if it doesn't exist
218
- '''
219
- if name in self._series:
220
- return self._series[name]
221
- else:
222
- return None
223
-
224
- def get_data_as_text(self):
225
- ''' Returns the data of all series as text.
226
- TO BE IMPLEMENTED FOR EACH CHART TYPE
227
- Data must be separated by a tab for easy Excel import
228
- '''
229
- return ""
1
+ # ____ _ _
2
+ # | _ \ ___| | _(_)_ __ ___ ___ Copyright | Title : Object to hold a chart shown on a panel_chart
3
+ # | | | |/ _ \ |/ / | '_ ` _ \ / _ \ (c) 2020 | Project : na
4
+ # | |_| | __/ <| | | | | | | (_) | Dekimo | Authors : MVR
5
+ # |____/ \___|_|\_\_|_| |_| |_|\___/ Products | Created : 2/1/2022
6
+ #__________________________________________________|_________________________________________________________
7
+ #
8
+ #
9
+
10
+ import wx
11
+ from wx.lib import plot as wxplot
12
+
13
+ class Chart(wxplot.PlotCanvas):
14
+ ''' Base object for all charts.
15
+ Derived chart has to implement :
16
+ * do_redraw (optionally)
17
+ * do_add_series
18
+ * get_data_as_text
19
+ '''
20
+
21
+ COLORS = ( wx.Colour(68,114,196), wx.Colour(237,125,49), wx.Colour(165,165,165), wx.Colour(255,193,4),
22
+ wx.Colour(91,155,213), wx.Colour(112,173,71), wx.Colour(38,68,120), wx.Colour(158,72,14),
23
+ wx.Colour(99,99,99), wx.Colour(153,115,0), wx.Colour(37,94,145), wx.Colour(67,104,43),
24
+ wx.Colour(105,142,208), wx.Colour(241,151,90), wx.Colour(183,183,183), wx.Colour(255,205,51),
25
+ wx.Colour(124,175,221),
26
+ )
27
+
28
+
29
+ def __init__(self, parent_control, name):
30
+ '''
31
+ Constructor
32
+ '''
33
+ super().__init__(parent_control, -1)
34
+
35
+ self.__name = name
36
+
37
+ self.enableLegend = True
38
+ self.enableGrid = True
39
+ self.antiAlias = False
40
+
41
+ self._series = dict()
42
+ self.__dirty = False
43
+ self.__on_update_func = None
44
+ self.__num_series_added = 0 # count num of series added, to select next color
45
+
46
+ self._xrange = None
47
+ self._yrange = None
48
+ self.configure(title=name, x_label="", y_label="", x_log=False, y_log=False)
49
+
50
+ def get_series_color(self):
51
+ ''' Get next color to use for a newly added series.
52
+ '''
53
+ idx = self.__num_series_added % len(self.COLORS)
54
+ self.__num_series_added += 1
55
+ return self.COLORS[idx]
56
+
57
+ @property
58
+ def name(self):
59
+ return self.__name
60
+
61
+ def configure(self, /, x_label=None, y_label=None, title=None,
62
+ y_log=None, x_log=None, x_range=None, y_range=None):
63
+ '''
64
+
65
+ '''
66
+ if title is not None:
67
+ self._title = title if isinstance(title, str) else str(title)
68
+ self.enablePlotTitle = True if len(self._title)>0 else False
69
+ if x_label is not None:
70
+ self._xlabel = x_label if isinstance(x_label, str) else str(x_label)
71
+ self.enableXAxisLabel = True if len(self._xlabel)>0 else False
72
+ if y_label is not None:
73
+ self._ylabel = y_label if isinstance(y_label, str) else str(y_label)
74
+ self.enableYAxisLabel = True if len(self._ylabel)>0 else False
75
+ if x_log is not None:
76
+ self._xlog = True if x_log else False
77
+ if y_log is not None:
78
+ self._ylog = True if y_log else False
79
+
80
+ if x_range is not None:
81
+ ok = False
82
+ if type(x_range) is tuple and len(x_range)==2:
83
+ try:
84
+ if x_range[0]+1 < x_range[1]+1:
85
+ self._xrange = x_range
86
+ ok = True
87
+ except:
88
+ pass
89
+ if not ok:
90
+ print(f"x_range {x_range} is invalid")
91
+
92
+ if y_range is not None:
93
+ ok = False
94
+ if type(y_range) is tuple and len(y_range)==2:
95
+ try:
96
+ if y_range[0]+1 < y_range[1]+1:
97
+ self._yrange = y_range
98
+ ok = True
99
+ except:
100
+ pass
101
+ if not ok:
102
+ print(f"y_range {y_range} is invalid")
103
+
104
+ self.logScale = (self._xlog, self._ylog)
105
+ if len(self._series)>0:
106
+ self.update()
107
+
108
+ @property
109
+ def on_update(self):
110
+ ''' The callback function for when data is modified.
111
+ '''
112
+ return self.__on_update_func
113
+
114
+ @on_update.setter
115
+ def on_update(self, value):
116
+ ''' Set the callback function for when data is modified.
117
+ '''
118
+ if value is None or callable(value):
119
+ self.__on_update_func = value
120
+
121
+ @property
122
+ def dirty(self):
123
+ ''' Returns if the chart needs updating or not.
124
+ '''
125
+ return self.__dirty
126
+
127
+ def update(self, / , antialiasing=False):
128
+ ''' Indicate that a chart should be updated. To be executed by a chart series when data is added.
129
+ The internal 'dirty' flag is set.
130
+ Also, the on_update callback function is called (if one is set).
131
+
132
+ In a a chart panel, the callback function will set a flag to indicate that the chart must
133
+ be updated.
134
+ '''
135
+ self.antiAlias = antialiasing
136
+ self.__dirty = True
137
+ if self.__on_update_func is not None:
138
+ self.__on_update_func()
139
+
140
+ def redraw(self):
141
+ ''' Redraw the chart.
142
+ Updates of the charts are 'lazy' : they are not recalculated when data is added.
143
+ The GUI calls this function to ask for the chart to be redrawn.
144
+ The internal 'dirty' flag is cleared.
145
+ '''
146
+ self.enableAntiAliasing = self.antiAlias
147
+ self.antiAlias = False
148
+ self.do_redraw()
149
+ # print(f"redraw {self.enableAntiAliasing}")
150
+ self.__dirty = False
151
+
152
+
153
+ def do_redraw(self):
154
+ ''' Is called when the chart must be redrawn.
155
+ Standard implementation below.
156
+ May be overridden for special kinds of charts.
157
+ '''
158
+ plot_objects = list()
159
+ try:
160
+ for series in self._series.values():
161
+ if len(series.get_points())>0:
162
+ plot_objects.append( series.get_plot_object() )
163
+
164
+ except RuntimeError: # occurs sometimes when data is updated during redraw
165
+ return
166
+
167
+ if len(plot_objects)>0:
168
+ pg = wxplot.PlotGraphics(plot_objects, self._title, self._xlabel, self._ylabel)
169
+ try:
170
+ self.Draw(pg, xAxis=self._xrange, yAxis=self._yrange)
171
+ except:
172
+ pass
173
+
174
+ # def clear(self):
175
+ # ''' remove all series from the chart
176
+ # '''
177
+ # for name in self._series.keys():
178
+ # del self._series[name] # delete it
179
+ # if hasattr(self, name):
180
+ # delattr(self, name) # delete member variable as well
181
+
182
+ def delete_series(self, name):
183
+ ''' Remove a series from a chart.
184
+ '''
185
+ if name in self._series: # check if we have a series with that name
186
+ del self._series[name] # delete it
187
+ if hasattr(self, name):
188
+ delattr(self, name) # delete member variable as well
189
+
190
+ def add_series(self, name):
191
+ ''' Create a new series for this chart.
192
+ First checks if name is valid, then calls do_add_series of derived class to create the series.
193
+ Series is added as attribute to the chart itself.
194
+ '''
195
+ if ( not name.isidentifier() or # first check if name is valid
196
+ name in ['update', 'redraw', 'add_series', 'delete_series'] or
197
+ ( hasattr(self, name) and name not in self._series) ):
198
+ raise ValueError("Series name '%s' is invalid" % name)
199
+
200
+ self.delete_series(name) # delete old series if necessary
201
+
202
+ series = self.do_add_series(name) # create the series and remember it
203
+
204
+ if series is not None:
205
+ self._series[name] = series
206
+ setattr(self, name, series) # also set it as a member variable
207
+
208
+ self.update()
209
+ return series
210
+
211
+ def do_add_series(self, name):
212
+ ''' To be implemented by derived class.
213
+ '''
214
+ return None
215
+
216
+ def get_series(self, name):
217
+ ''' Return a series by name, or None if it doesn't exist
218
+ '''
219
+ if name in self._series:
220
+ return self._series[name]
221
+ else:
222
+ return None
223
+
224
+ def get_data_as_text(self):
225
+ ''' Returns the data of all series as text.
226
+ TO BE IMPLEMENTED FOR EACH CHART TYPE
227
+ Data must be separated by a tab for easy Excel import
228
+ '''
229
+ return ""
@@ -1,70 +1,70 @@
1
- # ____ _ _
2
- # | _ \ ___| | _(_)_ __ ___ ___ Copyright | Title : Object to hold a chart shown on a panel_chart
3
- # | | | |/ _ \ |/ / | '_ ` _ \ / _ \ (c) 2020 | Project : na
4
- # | |_| | __/ <| | | | | | | (_) | Dekimo | Authors : MVR
5
- # |____/ \___|_|\_\_|_| |_| |_|\___/ Products | Created : 2/1/2022
6
- #__________________________________________________|_________________________________________________________
7
- #
8
- #
9
- # https://medium.com/@maxmarkovvision/optimal-number-of-bins-for-histograms-3d7c48086fde
10
-
11
- from .histogram_series import HistogramSeries
12
- from .chart import Chart
13
-
14
- class HistogramChart(Chart):
15
-
16
- def __init__(self, parent_control, name, binsize):
17
-
18
- super().__init__(parent_control, name)
19
- self.__binsize = binsize
20
-
21
- self._xlabel = "Value"
22
- self._ylabel = "Count"
23
-
24
- def add_series(self, name:str) -> HistogramSeries:
25
- return super().add_series(name)
26
-
27
- def do_add_series(self, name:str) -> HistogramSeries:
28
- ''' Create a new series for this chart.
29
- Base class will add it to the list of series
30
- '''
31
- return HistogramSeries(self, name, self.__binsize, color=self.get_series_color() )
32
-
33
- def get_data_as_text(self) -> str:
34
- ''' Returns the data of all series as text.
35
- '''
36
- lines = "" # the resulting text
37
- data = list() # the data for each series
38
- min_x = None
39
- max_x = None
40
-
41
- line = "Value" # add line with all the names
42
- for ser in self._series:
43
- line += "\t" + ser
44
- lines += line.strip() + "\r\n"
45
-
46
- for ser in self._series.values(): # get data and min/max of all series
47
- points = ser.get_points()
48
- if min_x is None:
49
- min_x = min(points.keys())
50
- else:
51
- min_x = min( min_x, min(points.keys()))
52
-
53
- if max_x is None:
54
- max_x = max(points.keys())
55
- else:
56
- max_x = max( max_x, max(points.keys()))
57
-
58
- data.append( points )
59
-
60
- for x in range(min_x,max_x+1): # write out all the data points
61
-
62
- line = str( x * self.__binsize )
63
- for pts in data:
64
- if x in pts:
65
- line += "\t%d" % pts[x]
66
- else:
67
- line += "\t0"
68
- lines += line.strip() + "\r\n"
69
-
70
- return lines
1
+ # ____ _ _
2
+ # | _ \ ___| | _(_)_ __ ___ ___ Copyright | Title : Object to hold a chart shown on a panel_chart
3
+ # | | | |/ _ \ |/ / | '_ ` _ \ / _ \ (c) 2020 | Project : na
4
+ # | |_| | __/ <| | | | | | | (_) | Dekimo | Authors : MVR
5
+ # |____/ \___|_|\_\_|_| |_| |_|\___/ Products | Created : 2/1/2022
6
+ #__________________________________________________|_________________________________________________________
7
+ #
8
+ #
9
+ # https://medium.com/@maxmarkovvision/optimal-number-of-bins-for-histograms-3d7c48086fde
10
+
11
+ from .histogram_series import HistogramSeries
12
+ from .chart import Chart
13
+
14
+ class HistogramChart(Chart):
15
+
16
+ def __init__(self, parent_control, name, binsize):
17
+
18
+ super().__init__(parent_control, name)
19
+ self.__binsize = binsize
20
+
21
+ self._xlabel = "Value"
22
+ self._ylabel = "Count"
23
+
24
+ def add_series(self, name:str) -> HistogramSeries:
25
+ return super().add_series(name)
26
+
27
+ def do_add_series(self, name:str) -> HistogramSeries:
28
+ ''' Create a new series for this chart.
29
+ Base class will add it to the list of series
30
+ '''
31
+ return HistogramSeries(self, name, self.__binsize, color=self.get_series_color() )
32
+
33
+ def get_data_as_text(self) -> str:
34
+ ''' Returns the data of all series as text.
35
+ '''
36
+ lines = "" # the resulting text
37
+ data = list() # the data for each series
38
+ min_x = None
39
+ max_x = None
40
+
41
+ line = "Value" # add line with all the names
42
+ for ser in self._series:
43
+ line += "\t" + ser
44
+ lines += line.strip() + "\r\n"
45
+
46
+ for ser in self._series.values(): # get data and min/max of all series
47
+ points = ser.get_points()
48
+ if min_x is None:
49
+ min_x = min(points.keys())
50
+ else:
51
+ min_x = min( min_x, min(points.keys()))
52
+
53
+ if max_x is None:
54
+ max_x = max(points.keys())
55
+ else:
56
+ max_x = max( max_x, max(points.keys()))
57
+
58
+ data.append( points )
59
+
60
+ for x in range(min_x,max_x+1): # write out all the data points
61
+
62
+ line = str( x * self.__binsize )
63
+ for pts in data:
64
+ if x in pts:
65
+ line += "\t%d" % pts[x]
66
+ else:
67
+ line += "\t0"
68
+ lines += line.strip() + "\r\n"
69
+
70
+ return lines