Skip to content
Snippets Groups Projects
Commit d3ccf421 authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Add content property to resource

parent f6210a1d
No related branches found
No related tags found
1 merge request!364Add content property to resource
Pipeline #96895 passed
......@@ -8,6 +8,7 @@ from typing import Dict, Iterable, Iterator, List, Optional, Set, Tuple, Union,
import matplotlib.pyplot as plt
from graphviz import Digraph
from b_asic.mpl_utils import FigureWrapper
from b_asic.port import InputPort, OutputPort
from b_asic.process import MemoryVariable, OperatorProcess, PlainMemoryVariable
from b_asic.resources import ProcessCollection
......@@ -174,19 +175,34 @@ class Resource(HardwareBlock):
# doc-string inherited
return self._collection.schedule_time
def show_content(self):
def plot_content(self, ax: plt.Axes) -> None:
if not self.is_assigned:
self._collection.show()
self._collection.plot(ax)
else:
fig, ax = plt.subplots()
for i, pc in enumerate(self._assignment): # type: ignore
pc.plot(ax=ax, row=i)
fig.show() # type: ignore
def show_content(self):
fig, ax = plt.subplots()
self.plot_content(ax)
fig.show() # type: ignore
@property
def is_assigned(self) -> bool:
return self._assignment is not None
@property
def content(self) -> FigureWrapper:
"""
Return a graphical representation of the content.
This is visible in enriched shells, but the object in itself has no further
meaning.
"""
fig, ax = plt.subplots()
self.plot_content(ax)
return FigureWrapper(fig)
class ProcessingElement(Resource):
"""
......
"""
B-ASIC utilities for Matplotlib integration.
"""
import io
from matplotlib.figure import Figure
class FigureWrapper:
"""Simple wrapper to display a figure inline in enriched shells."""
def __init__(self, figure: Figure):
self._figure = figure
def _repr_svg_(self):
buffer = io.StringIO()
self._figure.savefig(buffer, format="svg")
return buffer.getvalue()
......@@ -8,6 +8,7 @@ API
architecture.rst
core_operations.rst
graph_component.rst
mpl_utils.rst
operation.rst
port.rst
process.rst
......
********************
``b_asic.mpl_utils``
********************
.. automodule:: b_asic.mpl_utils
:members:
:undoc-members:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment