-
Notifications
You must be signed in to change notification settings - Fork 63
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
add constructor to main widget #258
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7502e8d
add constructor to main widget (#94)
vaniisgh 459979b
add examples and docstrings
vaniisgh 17b633b
Merge branch 'master' of https://github.com/QuantStack/ipycytoscape
vaniisgh 728c500
fix imports & docstring
vaniisgh 1f0960c
fix typo in docstrings
vaniisgh 01b7827
fix py2neo optional import
ianhi 880fcea
add neo4j requirements to examples optional install
ianhi fb2a0d5
update docstring
vaniisgh File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,15 @@ | |
|
||
# Copyright (c) Mariana Meireles. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
from os import path | ||
import copy | ||
import json | ||
|
||
from spectate import mvc | ||
from traitlets import TraitType, TraitError | ||
|
||
from pandas import DataFrame | ||
|
||
from ipywidgets import DOMWidget, Widget, widget_serialization, CallbackDispatcher | ||
from traitlets import ( | ||
Unicode, | ||
|
@@ -504,11 +507,15 @@ def add_graph_from_json(self, json_file, directed=False, multiple_edges=False): | |
|
||
Parameters | ||
---------- | ||
json_file : dict | ||
json_file : dict, string | ||
vaniisgh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
directed : bool | ||
If True all edges will be given 'directed' as a class if | ||
they do not already have it. | ||
""" | ||
if path.isfile(str(json_file)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this fully protect us if the user passes in a |
||
with open(json_file) as f: | ||
json_file = json.load(f) | ||
|
||
node_list = list() | ||
for node in json_file["nodes"]: | ||
node_instance = Node() | ||
|
@@ -811,12 +818,21 @@ class CytoscapeWidget(DOMWidget): | |
|
||
graph = Instance(Graph, args=tuple()).tag(sync=True, **widget_serialization) | ||
|
||
def __init__(self, **kwargs): | ||
def __init__(self, graph_file=None, **kwargs): | ||
vaniisgh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
super(CytoscapeWidget, self).__init__(**kwargs) | ||
|
||
self.on_msg(self._handle_interaction) | ||
self.graph = Graph() | ||
|
||
if isinstance(graph_file, nx.Graph): | ||
self.graph.add_graph_from_networkx(graph_file) | ||
if isinstance(graph_file, dict): | ||
self.graph.add_graph_from_json(graph_file) | ||
if isinstance(graph_file, DataFrame): | ||
self.graph.add_graph_from_df(graph_file) | ||
if isinstance(graph_file, str): | ||
self.graph.add_graph_from_json(graph_file) | ||
|
||
vaniisgh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Make sure we have a callback dispatcher for this widget and event type; | ||
# since _interaction_handlers is synced with the frontend and changes to | ||
# mutable values don't automatically propagate, we need to explicitly set | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently don't require
pandas
so this need to either be an optional import or the check below needs to check forpandas
in thegraph.__class__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a change to fix this, but I am not sure I passed the kwargs correctly to the add_graph_from_df correctly ... cold you please let me know what the correct way to do that would be? :)