1111import json
1212from typing import Dict , Any , Optional , Sequence
1313
14- from ipywidgets import DOMWidget , ValueWidget , register
15- from traitlets import Unicode , validate , TraitError
16- from ._frontend import module_name , module_version
14+ # Temporarily disable widget imports for MIME renderer migration
15+ # from traitlets import Unicode, validate, TraitError
16+ # from ipywidgets import DOMWidget, ValueWidget, register
17+ # from ._frontend import module_name, module_version
1718from ._version import __version__
1819
1920
@@ -25,44 +26,47 @@ def is_invalid_json(data):
2526 return True
2627
2728
28- @register
29- class NetVis (DOMWidget , ValueWidget ):
29+ # @register - Temporarily disabled for MIME renderer
30+ # class NetVis(DOMWidget, ValueWidget):
31+ class NetVis :
3032 """NetVis widget.
31- This widget show Network Visualization.
33+ This widget show Network Visualization using MIME renderer .
3234 """
3335
34- _model_name = Unicode ("NetVisModel" ).tag (sync = True )
35- _model_module = Unicode (module_name ).tag (sync = True )
36- _model_module_version = Unicode (module_version ).tag (sync = True )
37- _view_name = Unicode ("NetVisView" ).tag (sync = True )
38- _view_module = Unicode (module_name ).tag (sync = True )
39- _view_module_version = Unicode (module_version ).tag (sync = True )
36+ # Widget traits temporarily disabled for MIME renderer migration
37+ # _model_name = Unicode("NetVisModel").tag(sync=True)
38+ # _model_module = Unicode(module_name).tag(sync=True)
39+ # _model_module_version = Unicode(module_version).tag(sync=True)
40+ # _view_name = Unicode("NetVisView").tag(sync=True)
41+ # _view_module = Unicode(module_name).tag(sync=True)
42+ # _view_module_version = Unicode(module_version).tag(sync=True)
4043
41- value = Unicode ().tag (sync = True )
44+ # value = Unicode().tag(sync=True)
4245
43- def __init__ (self , ** kwargs ):
46+ # Using regular Python attribute for now
47+ value = ""
48+
49+ def __init__ (self , value = None , ** kwargs ):
4450 """
4551 Initialize NetVis object with graph data validation.
4652
4753 Args:
48- value (str): JSON string containing graph data with 'nodes' and 'links' (passed via kwargs)
54+ value (str): JSON string containing graph data with 'nodes' and 'links'
4955
5056 Raises:
5157 ValueError: If JSON is invalid, nodes/links are missing, or data is inconsistent
5258 """
53- # Pre-validate 'value' in kwargs to raise ValueError (not TraitError)
54- # This ensures the API contract is met
55- if 'value' in kwargs :
56- value = kwargs ['value' ]
57- if value is not None and value != "" :
59+ # Handle value parameter
60+ if value is not None :
61+ if value != "" :
5862 # Type check
5963 if not isinstance (value , str ):
6064 raise ValueError (f"Value must be a string, not { type (value ).__name__ } " )
6165 # GraphData validation
6266 self ._validate_graph_data (value )
63-
64- # Now call parent init, which will also run _valid_value validator
65- super (). __init__ ( ** kwargs )
67+ self . value = value
68+ else :
69+ self . value = ""
6670
6771 def _validate_graph_data (self , data : str ) -> None :
6872 """
@@ -159,26 +163,27 @@ def _repr_mimebundle_(
159163 'text/plain' : 'NetVis Graph'
160164 }
161165
162- @validate ("value" )
163- def _valid_value (self , proposal ):
164- _data = proposal ["value" ]
165-
166- # Type check: only string is allowed (reject dict/list)
167- if not isinstance (_data , str ):
168- raise TraitError (f"Value must be a string, not { type (_data ).__name__ } " )
169-
170- # Allow empty string (default value)
171- if _data == "" :
172- return _data
173-
174- # Validate JSON format
175- if is_invalid_json (_data ):
176- raise TraitError ("Invalid JSON value: it must be JSON string" )
177-
178- # Validate GraphData structure (convert ValueError to TraitError)
179- try :
180- self ._validate_graph_data (_data )
181- except ValueError as e :
182- raise TraitError (str (e ))
183-
184- return _data
166+ # Traitlet validator temporarily disabled for MIME renderer migration
167+ # @validate("value")
168+ # def _valid_value(self, proposal):
169+ # _data = proposal["value"]
170+ #
171+ # # Type check: only string is allowed (reject dict/list)
172+ # if not isinstance(_data, str):
173+ # raise TraitError(f"Value must be a string, not {type(_data).__name__}")
174+ #
175+ # # Allow empty string (default value)
176+ # if _data == "":
177+ # return _data
178+ #
179+ # # Validate JSON format
180+ # if is_invalid_json(_data):
181+ # raise TraitError("Invalid JSON value: it must be JSON string")
182+ #
183+ # # Validate GraphData structure (convert ValueError to TraitError)
184+ # try:
185+ # self._validate_graph_data(_data)
186+ # except ValueError as e:
187+ # raise TraitError(str(e))
188+ #
189+ # return _data
0 commit comments