Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] refactor data storage to allow saving on a per-window basis #862

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions example/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ def run_demo(viz, env, args):
np.random.seed(int(FLAGS.seed))

if FLAGS.run == "all":
try:
# try:
run_demo(viz, FLAGS.env if FLAGS.env else None, FLAGS.args)
except Exception as e:
print(
"The visdom experienced an exception while running: {}\n"
"The demo displays up-to-date functionality with the GitHub "
"version, which may not yet be pushed to pip. Please upgrade "
"using `pip install -e .` or `easy_install .`\n"
"If this does not resolve the problem, please open an issue on "
"our GitHub.".format(repr(e))
)
# except Exception as e:
# print(
# "The visdom experienced an exception while running: {}\n"
# "The demo displays up-to-date functionality with the GitHub "
# "version, which may not yet be pushed to pip. Please upgrade "
# "using `pip install -e .` or `easy_install .`\n"
# "If this does not resolve the problem, please open an issue on "
# "our GitHub.".format(repr(e))
# )
else:
locals()[FLAGS.run](viz, FLAGS.run + FLAGS.env_suffix if not FLAGS.env else FLAGS.env, FLAGS.args)

Expand Down
8 changes: 7 additions & 1 deletion js/TextPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TextPane extends React.Component {
switch (e.type) {
case 'keydown':
case 'keypress':
e.preventDefault();
// e.preventDefault(); /// this would prevent entering text into input box
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this was trying to prevent text panes from submitting on enter. Plus, the goal is to send keypress events to the backend, not necessarily to have them render up-front here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. I was putting forms into visdom window, and .preventDefault would make the form inputting fairly laggy, hence commented out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps there's value in a new FormPane component, likely a parent class for the PropertiesPane. This would then be able to accomplish what you're attempting in #868, but in a cleaner way

break;
case 'keyup':
this.props.appApi.sendPaneMessage({
Expand All @@ -29,6 +29,12 @@ class TextPane extends React.Component {
key_code: e.keyCode,
});
break;
case 'click':
this.props.appApi.sendPaneMessage({
event_type: 'Click',
});
break;

}
};

Expand Down
21 changes: 21 additions & 0 deletions py/visdom/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
clean:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm somewhat against adding yet another scripting flow to the visdom codebase. This should either be part of the package.json scripts, or we should be having a discussion about the alternate we should be using instead.

rm -rf ./test_data/*

serve_test:
python3 -mpdb -cc server.py -env_path test_data -eager_data_loading -logging_level 5

serve_test_jpwa:
python3 -mpdb -cc server.py -env_path test_data -eager_data_loading -logging_level 5 -cache_type JPWA

serve_test_jpe:
python3 -mpdb -cc server.py -env_path test_data -eager_data_loading -logging_level 5 -cache_type JPE

serve_test_jpw:
python3 -mpdb -cc server.py -env_path test_data -eager_data_loading -logging_level 5 -cache_type JPW


test_save.py:
python3 test_save.py
test_cache.py:
python3 test_cache.py
.PHONY: test_cache.py test_save.py
42 changes: 27 additions & 15 deletions py/visdom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
# __version__ = 'test'

import os.path
import requests
Expand Down Expand Up @@ -405,7 +406,7 @@ def __init__(
'base_url should not end with / as it is appended automatically'

self.ipv6 = ipv6
self.env = env
self.env = env
self.env_list={f'{env}'} # default env
self.send = send
self.event_handlers = {} # Haven't registered any events
Expand Down Expand Up @@ -576,12 +577,12 @@ def on_message(ws, message):
try:
handler(message)
except Exception as e:
import traceback
tbmsg = traceback.format_exc()
logger.warn(
'Visdom failed to handle a handler for {}: {}'
''.format(message, e)
'Visdom failed to handle a handler for {}: {}.'
'\n traceback:{}'.format(message, e, tbmsg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice-to-have addition

)
import traceback
traceback.print_exc()

def on_error(ws, error):
if hasattr(error, "errno") and error.errno == errno.ECONNREFUSED:
Expand Down Expand Up @@ -665,6 +666,17 @@ def _send(self, msg, endpoint='events', quiet=False, from_log=False, create=True
created with a random name. If `create=False`, `win=None` indicates the
operation should be applied to all windows.
"""
# if endpoint == 'window':
# print(f'[endpoint]{endpoint}')
# import inspect,traceback
# traceback.print_stack()
# from pprint import pprint
# # pprint(msg)
# print(msg.get('layout').__repr__()[:10])
# print(msg.get('height'))
# print(msg.get('width'))
# traceback.print_tb(inspect.currentframe())
# import pdb;pdb.set_trace()
if msg.get('eid', None) is None:
msg['eid'] = self.env
self.env_list.add(self.env)
Expand Down Expand Up @@ -801,7 +813,7 @@ def get_env_list(self):
This function returns a list of all of the env names that are currently
in the server.
"""
if self.offline:
if self.offline:
return list(self.env_list)
else:
return json.loads(self._send({}, endpoint='env_state', quiet=True))
Expand Down Expand Up @@ -889,7 +901,7 @@ def replay_log(self, log_filename):

# Content

def text(self, text, win=None, env=None, opts=None, append=False):
def text(self, text, win=None, env=None, opts=None, append=False,extra={}):
"""
This function prints text in a box. It takes as input an `text` string.
No specific `opts` are currently supported.
Expand Down Expand Up @@ -1694,7 +1706,7 @@ def line(self, Y, X=None, win=None, env=None, opts=None, update=None,
assert X.ndim == 1 or X.ndim == 2, 'X should have 1 or 2 dim'
else:
X = np.linspace(0, 1, Y.shape[0])

if Y.ndim == 2 and X.ndim == 1:
X = np.tile(X, (Y.shape[1], 1)).transpose()

Expand Down Expand Up @@ -2180,7 +2192,7 @@ def sunburst(self, labels, parents, values=None, win=None, env=None, opts=None):
line_width=opts.get("marker_width")

assert len(parents.tolist())==len(labels.tolist()), "length of parents and labels should be equal"

data_dict=[{
'labels': labels.tolist(),
"parents":parents.tolist(),
Expand All @@ -2196,7 +2208,7 @@ def sunburst(self, labels, parents, values=None, win=None, env=None, opts=None):

data_dict[0]['values']=values.tolist()

data=data_dict
data=data_dict
return self._send({
'data': data,
'win': win,
Expand Down Expand Up @@ -2397,7 +2409,7 @@ def graph(self, edges, edgeLabels = None, nodeLabels = None, opts=dict(), env=No
"""
This function draws interactive network graphs. It takes list of edges as one of the arguments.
The user can also provide custom edge Labels and node Labels in edgeLabels and nodeLabels respectively.
Along with that we have different parameters in opts for making it more user friendly.
Along with that we have different parameters in opts for making it more user friendly.

Args:
edges : list, required
Expand All @@ -2419,7 +2431,7 @@ def graph(self, edges, edgeLabels = None, nodeLabels = None, opts=dict(), env=No
except:
raise RuntimeError(
"networkx must be installed to plot Graph figures")

G = nx.Graph()
G.add_edges_from(edges)
node_data = list(G.nodes())
Expand All @@ -2434,7 +2446,7 @@ def graph(self, edges, edgeLabels = None, nodeLabels = None, opts=dict(), env=No
if nodeLabels is not None:
assert len(nodeLabels) == len(node_data),\
"length of nodeLabels does not match with the length of nodes {len1} != {len2}".format(len1 = len(nodeLabels), len2 = len(node_data))

for i in range(len(node_data)):
if i != node_data[i]:
raise RuntimeError("The nodes should be numbered from 0 to n-1 for n nodes! {} node is missing!".format(i))
Expand All @@ -2455,15 +2467,15 @@ def graph(self, edges, edgeLabels = None, nodeLabels = None, opts=dict(), env=No
edge["target"] = int(link_data[i][1])
edge["label"] = str(edgeLabels[i]) if edgeLabels is not None else str(link_data[i][0])+"-"+str(link_data[i][1])
edges.append(edge)

for i in range(len(node_data)):
node = {}
node["name"] = int(node_data[i])
node["label"] = str(nodeLabels[i]) if nodeLabels is not None else str(node_data[i])
if opts['scheme'] == 'different':
node["club"] = int(i)
nodes.append(node)


data = [{
'content': {"nodes": nodes, "edges": edges},
Expand Down
Loading