diff --git a/b_asic/resources.py b/b_asic/resources.py index 667eba29bc70b263d56928f1363eee2c160a114e..d25d04939173e0cd4e0c12bcc8d68ff143f2371c 100644 --- a/b_asic/resources.py +++ b/b_asic/resources.py @@ -6,8 +6,12 @@ import networkx as nx from matplotlib.axes import Axes from matplotlib.ticker import MaxNLocator +from b_asic._preferences import LATENCY_COLOR from b_asic.process import Process +# Default latency coloring RGB tuple +_LATENCY_COLOR = tuple(c / 255 for c in LATENCY_COLOR) + # # Human-intuitive sorting: # https://stackoverflow.com/questions/2669059/how-to-sort-alpha-numeric-set-in-python @@ -129,6 +133,11 @@ class ProcessCollection: self, ax: Optional[Axes] = None, show_name: bool = True, + bar_color: Union[str, Tuple[float, ...]] = _LATENCY_COLOR, + marker_color: Union[str, Tuple[float, ...]] = "black", + marker_read: str = "X", + marker_write: str = "o", + show_markers: bool = True, ): """ Use matplotlib.pyplot to generate a process variable lifetime chart from this process collection. @@ -140,6 +149,16 @@ class ProcessCollection: this method will return a new axes object on return. show_name : bool, default: True Show name of all processes in the lifetime chart. + bar_color : color, optional + Bar color in lifetime chart. + marker_color : color, default 'black' + Color for read and write marker. + marker_write : str, default 'x' + Marker at write time in the lifetime chart. + marker_read : str, default 'o' + Marker at read time in the lifetime chart. + show_markers : bool, default True + Show markers at read and write times. Returns ------- @@ -170,39 +189,42 @@ class ProcessCollection: bar_end = ( process.start_time + process.execution_time ) % self._schedule_time - if process.execution_time == 0: - # Process has no execution time, draw a tick - _ax.scatter(x=bar_start, y=i + 1, marker='X', color='blue') - elif bar_end > bar_start: + bar_end = self._schedule_time if bar_end == 0 else bar_end + if show_markers: + _ax.scatter( + x=bar_start, + y=i + 1, + marker=marker_write, + color=marker_color, + zorder=10, + ) + _ax.scatter( + x=bar_end, + y=i + 1, + marker=marker_read, + color=marker_color, + zorder=10, + ) + if bar_end >= bar_start: _ax.broken_barh( [(PAD_L + bar_start, bar_end - bar_start - PAD_L - PAD_R)], (i + 0.55, 0.9), + color=bar_color, ) else: # bar_end < bar_start - if bar_end != 0: - _ax.broken_barh( - [ - ( - PAD_L + bar_start, - self._schedule_time - bar_start - PAD_L, - ) - ], - (i + 0.55, 0.9), - ) - _ax.broken_barh([(0, bar_end - PAD_R)], (i + 0.55, 0.9)) - else: - _ax.broken_barh( - [ - ( - PAD_L + bar_start, - self._schedule_time - - bar_start - - PAD_L - - PAD_R, - ) - ], - (i + 0.55, 0.9), - ) + _ax.broken_barh( + [ + ( + PAD_L + bar_start, + self._schedule_time - bar_start - PAD_L, + ) + ], + (i + 0.55, 0.9), + color=bar_color, + ) + _ax.broken_barh( + [(0, bar_end - PAD_R)], (i + 0.55, 0.9), color=bar_color + ) if show_name: _ax.annotate( str(process), diff --git a/test/baseline/test_draw_matrix_transposer_4.png b/test/baseline/test_draw_matrix_transposer_4.png index bc686cd9aa899577e600015b3b73c194618d5320..c8ee191a8593d0420a55a3883a76ed86290e2256 100644 Binary files a/test/baseline/test_draw_matrix_transposer_4.png and b/test/baseline/test_draw_matrix_transposer_4.png differ diff --git a/test/baseline/test_draw_process_collection.png b/test/baseline/test_draw_process_collection.png index 87a5bf7fd1ce3055f5cc993ab684c560ef06e4b5..4b82425c023beadbf4b822c9c236852738ee2fce 100644 Binary files a/test/baseline/test_draw_process_collection.png and b/test/baseline/test_draw_process_collection.png differ diff --git a/test/test_resources.py b/test/test_resources.py index 10e401adf520a9b837c864bb20ab2d2742327237..38dfc2457010954fada118827aac23682638e047 100644 --- a/test/test_resources.py +++ b/test/test_resources.py @@ -13,7 +13,7 @@ class TestProcessCollectionPlainMemoryVariable: @pytest.mark.mpl_image_compare(style='mpl20') def test_draw_process_collection(self, simple_collection): fig, ax = plt.subplots() - simple_collection.draw_lifetime_chart(ax=ax) + simple_collection.draw_lifetime_chart(ax=ax, show_markers=False) return fig def test_draw_proces_collection(self, simple_collection):