Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

JavaScript Object support#236

Open
vladko312 wants to merge 4 commits intoWestHealth:masterWestHealth/pyvis:masterfrom
vladko312:mastervladko312/pyvis:masterCopy head branch name to clipboard
Open

JavaScript Object support#236
vladko312 wants to merge 4 commits intoWestHealth:masterWestHealth/pyvis:masterfrom
vladko312:mastervladko312/pyvis:masterCopy head branch name to clipboard

Conversation

@vladko312
Copy link

This can be used to add JS code to node/edge properties.

from pyvis.JScode import JS, JSONEncoder
import json

obj = {'num': 1, 'str': 'some string', 'js': JS('alert("test")')}
js_obj = json.dumps(obj, cls=JSONEncoder)
# js_obj == '{"num": 1, "str": "some string", "js": alert("test")}'

For example, it can set ctxRenderer or apply this fix after adding the functions into the template.

Example:

from pyvis.JScode import JS

node_title = JS("""htmlTitle(
      "Go wild <'span style='display: inline-block; animation: be-tacky 5s ease-in-out alternate infinite; margin: 5px;'>!<'/span>"
    )""")
# to be used in Network.add_node()

I would also recommend adding this code somewhere in template scripts:

function preTitle(text) {
  const container = document.createElement("pre");
  container.innerText = text;
  return container;
}
function htmlTitle(html) {
  const container = document.createElement("div");
  container.innerHTML = html;
  return container;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.