Skip to content

Commit dc77a02

Browse files
terapyonterapyon
authored andcommitted
bugfix for MIME
1 parent 416b588 commit dc77a02

File tree

4 files changed

+79
-47
lines changed

4 files changed

+79
-47
lines changed

net_vis/netvis.py

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
import json
1212
from 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
1718
from ._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

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
"ts-jest": "^29.1.2",
8686
"ts-loader": "^9.5.1",
8787
"typescript": "~5.4.0",
88+
"url-loader": "^4.1.1",
89+
"svg-url-loader": "^8.0.0",
8890
"webpack": "^5.90.0",
8991
"webpack-cli": "^5.1.4"
9092
},

webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const version = require('./package.json').version;
55
const rules = [
66
{ test: /\.ts$/, loader: 'ts-loader' },
77
{ test: /\.js$/, loader: 'source-map-loader' },
8-
{ test: /\.css$/, use: ['style-loader', 'css-loader']}
8+
{ test: /\.css$/, use: ['style-loader', 'css-loader']},
9+
{ test: /\.svg$/, loader: 'svg-url-loader' }
910
];
1011

1112
// Packages that shouldn't be bundled but loaded at runtime

yarn.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3927,6 +3927,14 @@ file-entry-cache@^6.0.1:
39273927
dependencies:
39283928
flat-cache "^3.0.4"
39293929

3930+
file-loader@~6.2.0:
3931+
version "6.2.0"
3932+
resolved "https://registry.yarnpkg.com/file-loader/-/file-loader-6.2.0.tgz#baef7cf8e1840df325e4390b4484879480eebe4d"
3933+
integrity sha512-qo3glqyTa61Ytg4u73GultjHGjdRyig3tG6lPtyX/jOEJvHif9uB0/OCI2Kif6ctF3caQTW2G5gym21oAsI4pw==
3934+
dependencies:
3935+
loader-utils "^2.0.0"
3936+
schema-utils "^3.0.0"
3937+
39303938
fill-range@^7.1.1:
39313939
version "7.1.1"
39323940
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292"
@@ -6592,6 +6600,13 @@ supports-preserve-symlinks-flag@^1.0.0:
65926600
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
65936601
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==
65946602

6603+
svg-url-loader@^8.0.0:
6604+
version "8.0.0"
6605+
resolved "https://registry.yarnpkg.com/svg-url-loader/-/svg-url-loader-8.0.0.tgz#05d57af5b19d7caa39624a88e3cd535243634991"
6606+
integrity sha512-5doSXvl18hY1fGsRLdhWAU5jgzgxJ06/gc/26cpuDnN0xOz1HmmfhkpL29SSrdIvhtxQ1UwGzmk7wTT/l48mKw==
6607+
dependencies:
6608+
file-loader "~6.2.0"
6609+
65956610
symbol-tree@^3.2.4:
65966611
version "3.2.4"
65976612
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
@@ -6879,6 +6894,15 @@ uri-js@^4.2.2:
68796894
dependencies:
68806895
punycode "^2.1.0"
68816896

6897+
url-loader@^4.1.1:
6898+
version "4.1.1"
6899+
resolved "https://registry.yarnpkg.com/url-loader/-/url-loader-4.1.1.tgz#28505e905cae158cf07c92ca622d7f237e70a4e2"
6900+
integrity sha512-3BTV812+AVHHOJQO8O5MkWgZ5aosP7GnROJwvzLS9hWDj00lZ6Z0wNak423Lp9PBZN05N+Jk/N5Si8jRAlGyWA==
6901+
dependencies:
6902+
loader-utils "^2.0.0"
6903+
mime-types "^2.1.27"
6904+
schema-utils "^3.0.0"
6905+
68826906
url-parse@^1.5.3, url-parse@~1.5.4:
68836907
version "1.5.10"
68846908
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1"

0 commit comments

Comments
 (0)