|
7 | 7 |
|
8 | 8 | from contextlib import contextmanager
|
9 | 9 | from typing import (
|
10 |
| - TYPE_CHECKING, Any, Iterable, List, Optional, |
| 10 | + TYPE_CHECKING, Any, Iterable, List, Optional, Set, |
11 | 11 | )
|
12 | 12 |
|
13 | 13 | import numpy as np
|
@@ -92,27 +92,33 @@ def diff(
|
92 | 92 | msg.add_buffer(buffer)
|
93 | 93 | return msg
|
94 | 94 |
|
95 |
| -def remove_root(obj: Model, replace: Document | None = None) -> None: |
| 95 | +def remove_root(obj: Model, replace: Document | None = None, skip: Set[Model] | None = None) -> None: |
96 | 96 | """
|
97 | 97 | Removes the document from any previously displayed bokeh object
|
98 | 98 | """
|
| 99 | + models = set() |
99 | 100 | for model in obj.select({'type': Model}):
|
| 101 | + if skip and model in skip: |
| 102 | + continue |
100 | 103 | prev_doc = model.document
|
101 | 104 | model._document = None
|
102 | 105 | if prev_doc:
|
103 | 106 | prev_doc.remove_root(model)
|
104 | 107 | if replace:
|
105 | 108 | model._document = replace
|
| 109 | + models.add(model) |
| 110 | + return models |
106 | 111 |
|
107 |
| -def add_to_doc(obj: Model, doc: Document, hold: bool = False): |
| 112 | +def add_to_doc(obj: Model, doc: Document, hold: bool = False, skip: Set[Model] | None = None): |
108 | 113 | """
|
109 | 114 | Adds a model to the supplied Document removing it from any existing Documents.
|
110 | 115 | """
|
111 | 116 | # Add new root
|
112 |
| - remove_root(obj) |
| 117 | + models = remove_root(obj, skip=skip) |
113 | 118 | doc.add_root(obj)
|
114 | 119 | if doc.callbacks.hold_value is None and hold:
|
115 | 120 | doc.hold()
|
| 121 | + return models |
116 | 122 |
|
117 | 123 | def patch_cds_msg(model, msg):
|
118 | 124 | """
|
|
0 commit comments