diff --git a/notebooks/basics.html b/notebooks/basics.html index 380e176..eed236b 100644 --- a/notebooks/basics.html +++ b/notebooks/basics.html @@ -7331,7 +7331,8 @@ if (!diagrams.length) { return; } - const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.2.3/mermaid.esm.min.mjs")).default; + const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.6.0/mermaid.esm.min.mjs")).default; + const parser = new DOMParser(); mermaid.initialize({ maxTextSize: 100000, @@ -7347,39 +7348,52 @@ let _nextMermaidId = 0; function makeMermaidImage(svg) { - const img = document.createElement('img'); - const maxWidth = svg.match(/max-width: (\d+)/); - if (maxWidth && maxWidth[1]) { - const width = parseInt(maxWidth[1]); - if (width && !Number.isNaN(width) && Number.isFinite(width)) { - img.width = width; - } + const img = document.createElement("img"); + const doc = parser.parseFromString(svg, "image/svg+xml"); + const svgEl = doc.querySelector("svg"); + const { maxWidth } = svgEl?.style || {}; + const firstTitle = doc.querySelector("title"); + const firstDesc = doc.querySelector("desc"); + + img.setAttribute("src", `data:image/svg+xml,${encodeURIComponent(svg)}`); + if (maxWidth) { + img.width = parseInt(maxWidth); + } + if (firstTitle) { + img.setAttribute("alt", firstTitle.textContent); } - img.setAttribute('src', `data:image/svg+xml,${encodeURIComponent(svg)}`); - return img; + if (firstDesc) { + const caption = document.createElement("figcaption"); + caption.className = "sr-only"; + caption.textContent = firstDesc.textContent; + return [img, caption]; + } + return [img]; } async function makeMermaidError(text) { - let errorMessage = ''; + let errorMessage = ""; try { await mermaid.parse(text); } catch (err) { errorMessage = `${err}`; } - const result = document.createElement('details'); - const summary = document.createElement('summary'); - const pre = document.createElement('pre'); - const code = document.createElement('code'); + const result = document.createElement("details"); + result.className = 'jp-RenderedMermaid-Details'; + const summary = document.createElement("summary"); + summary.className = 'jp-RenderedMermaid-Summary'; + const pre = document.createElement("pre"); + const code = document.createElement("code"); code.innerText = text; pre.appendChild(code); summary.appendChild(pre); result.appendChild(summary); - const warning = document.createElement('pre'); + const warning = document.createElement("pre"); warning.innerText = errorMessage; result.appendChild(warning); - return result; + return [result]; } async function renderOneMarmaid(src) { @@ -7389,30 +7403,41 @@ const el = document.createElement("div"); el.style.visibility = "hidden"; document.body.appendChild(el); - let result = null; + let results = null; + let output = null; try { const { svg } = await mermaid.render(id, raw, el); - result = makeMermaidImage(svg); + results = makeMermaidImage(svg); + output = document.createElement("figure"); + results.map(output.appendChild, output); } catch (err) { parent.classList.add("jp-mod-warning"); - result = await makeMermaidError(raw); + results = await makeMermaidError(raw); + output = results[0]; } finally { el.remove(); } parent.classList.add("jp-RenderedMermaid"); - parent.appendChild(result); + parent.appendChild(output); } void Promise.all([...diagrams].map(renderOneMarmaid)); });
@@ -7464,7 +7504,7 @@# !pip install bigraph-schema
@@ -7505,11 +7545,10 @@ Imports¶
-In [2]:
+In [22]:
from bigraph_viz import plot_bigraph, plot_flow, plot_multitimestep, pf
-from bigraph_schema import TypeSystem
from bigraph_viz.dict_utils import replace_regex_recursive
plot_settings = {'remove_process_place_edges': True}
@@ -7522,31 +7561,6 @@ Imports¶
-
-
-
-
-
-
-Initialize Type System¶
-
-
-
-
-
-
-
-
-In [3]:
-
-
-types = TypeSystem()
-
-
-
-
-
-
-In [4]:
+In [23]:
simple_store_state = {
@@ -7590,7 +7604,7 @@ Simple stores
-In [5]:
+In [24]:
typed_store_spec = {
@@ -7633,7 +7647,7 @@ Simple stores
-Out[5]:
+Out[24]:
@@ -7656,7 +7670,7 @@ Hierarchy¶
-In [6]:
+In [25]:
hierarchy_spec = {
@@ -7682,7 +7696,7 @@ Hierarchy¶
-In [7]:
+In [26]:
process_spec = {
@@ -7741,7 +7755,7 @@ Single process
-In [8]:
+In [27]:
process_schema = {
@@ -7792,7 +7806,7 @@ Multiple processes
-Out[8]:
+Out[27]:
@@ -7815,7 +7829,7 @@ Wires¶
To connec
-In [9]:
+In [28]:
connected_process_spec = {
@@ -7849,7 +7863,7 @@ Wires¶
To connec
-In [10]:
+In [29]:
flat_composite_spec = {
@@ -7927,7 +7941,7 @@ Flat composite
-In [11]:
+In [30]:
nested_composite_spec = {
@@ -7991,7 +8005,7 @@ Nested composite
-In [12]:
+In [31]:
composite_process_spec = {
@@ -8057,7 +8071,7 @@ Composite process
-Out[12]:
+Out[31]:
@@ -8065,247 +8079,6 @@ Composite process
-
-
-
-
-
-Updates¶
-- state update
-- structure update
-
-
-
-
-
-
-
-
-
-In [13]:
-
-
-schemaa = {
- 'base': {
- 'a': {'_type': 'int'},
- },
-
- # cannot override existing keys unless it is of a subtype
- 'second': {
- 'b': {'_type': 'int'},
- '_super': 'base',
- },
-}
-
-types.type_registry.register_multiple(schemaa, force=True)
-
-
-
-
-
-
-
-
-
-
-In [14]:
-
-
-schema = {'_type': 'second'}
-state = {
- 'a': 11,
- 'b': 13,
-}
-plot_bigraph(state, show_values=True)
-
-
-
-
-
-
-
-
-
-
-Out[14]:
-
-
-
-
-
-
-
-
-
-
-
-In [15]:
-
-
-update = {
- 'b': -5
-}
-new_state = types.apply(
- schema,
- state,
- update
-)
-plot_bigraph(new_state, show_values=True)
-
-
-
-
-
-
-
-
-
-
-Out[15]:
-
-
-
-
-
-
-
-
-
-
-
-In [16]:
-
-
-update = {
- 'a': 5
-}
-new_state = types.apply(
- schema,
- new_state,
- update
-)
-plot_bigraph(new_state, show_values=True)
-
-
-
-
-
-
-
-
-
-
-Out[16]:
-
-
-
-
-
-
-
-
-
-
-
-In [17]:
-
-
-# from bigraph_schema.registry import apply_registry
-from bigraph_viz.dict_utils import deep_merge
-def apply_merge(current, update, bindings=None, types=None):
- assert isinstance(state, dict)
- assert isinstance(update, dict)
- updated = deep_merge(state, update)
- return updated
-types.apply_registry.register('merge', apply_merge, force=True)
-
-schemab = {
- 'merge_branch': {
- '_default': {'a1': 'any'},
- '_apply': 'merge',
-
- },
-
- # cannot override existing keys unless it is of a subtype
- 'second': {
- 'a1': {'a2': 'any'},
- '_super': 'merge_branch',
- },
-}
-
-types.type_registry.register_multiple(schemab, force=True)
-
-
-
-
-
-
-
-
-
-
-In [18]:
-
-
-schema = {'_type': 'merge_branch'}
-state = {
- 'a1': {'a2': 11},
-}
-plot_bigraph(state, show_values=True)
-
-
-
-
-
-
-
-
-
-
-Out[18]:
-
-
-
-
-
-
-
-
-
-
-
-In [19]:
-
-
-update = {
- 'a1': {'a3': -5},
-}
-new_state = types.apply(
- schema,
- state,
- update
-)
-# print(pf(new_state))
-plot_bigraph(new_state, show_values=True)
-
-
-
-
-
-
-
-
-
-
-Out[19]:
-
-
-
-
-
-
-
-In [20]:
+In [32]:
-In [21]:
+In [33]:
multitimestep_spec = {
@@ -8378,7 +8151,7 @@ Multi-timestepping
-Out[21]:
+Out[33]:
@@ -8401,15 +8174,10 @@ Flows¶
A directe
-In [22]:
+In [34]:
-step_schema = {
- '_depends_on': 'list[string]',
-}
-types.type_registry.register('step_process', step_schema)
-
-flow = {
+flow = {
'step1': {
'_type': 'step_process',
'_ports': {},
@@ -8443,7 +8211,7 @@ Flows¶
A directe
-In [23]:
+In [35]:
music_map = {
@@ -8538,7 +8306,7 @@ Multiscale map of a cell
-In [24]:
+In [36]:
music_map
@@ -8564,7 +8332,7 @@ Multiscale map of a cell
-Out[24]:
+Out[36]:
{'cell': {'cytoplasm': {'secretory organelles': {'transmembrane transport systems': {'ion transmembrane transport systems': {}}},
'cytoplasmic organelles': {'subgroup of cytoplasmic organelles': {'metabolic organelles': {'subgroup of metabolic organelles': {},
@@ -8596,7 +8364,7 @@ Multiscale map of a cell
-In [25]:
+In [37]:
import copy
@@ -8745,7 +8513,7 @@ Multiscale map of a cell
-In [26]:
+In [38]:
new_process = {
@@ -8766,7 +8534,7 @@ Multiscale map of a cell'1': 'Any',
'2': 'Any',
}
- }s
+ }
}
new_process = replace_regex_recursive(new_process)
@@ -8789,15 +8557,10 @@ Multiscale map of a cell
-
-
-
-
- Cell In[26], line 7
- }s
- ^
-SyntaxError: invalid syntax
-
+
+Out[38]:
+
+
@@ -8813,12 +8576,12 @@ Cell structure and function
+
-In [ ]:
+In [39]:
cell_struct_func = {
@@ -8874,6 +8637,25 @@ Cell structure and function
+
+
+
+
+
+
+Writing out/cell
+
+
+
+
+Out[39]:
+
+
+
+
+
+
@@ -8885,12 +8667,12 @@ Whole-cell E. coli model
+
-In [ ]:
+In [40]:
ecoli = {
@@ -9057,6 +8839,19 @@ Whole-cell E. coli model
+
+
+
+
+
+
+Writing out/ecoli
+
+
+
+
+