Skip to content

Commit

Permalink
docs: graph vis with dict_for_vis & Apache ECharts
Browse files Browse the repository at this point in the history
  • Loading branch information
wey-gu committed Mar 16, 2024
1 parent 9f6bc54 commit 8ce2af0
Show file tree
Hide file tree
Showing 5 changed files with 4,724 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ result = session.execute(
data_for_vis = result.dict_for_vis()
```

And it looks like this:
Then, we could pass the `data_for_vis` to a front-end visualization library such as `vis.js`, `d3.js` or Apache ECharts. There is an example of Apache ECharts in [exapmple/apache_echarts.html](example/apache_echarts.html).

The dict/JSON structure with `dict_for_vis()` is as follows:

<details>
<summary>Click to expand</summary>
Expand Down
53 changes: 53 additions & 0 deletions example/GraphVis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python
# --coding:utf-8--

# Copyright (c) 2024 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.


import json
import time


from nebula3.gclient.net import ConnectionPool

if __name__ == "__main__":
client = None
try:
# init connection pool
connection_pool = ConnectionPool()
assert connection_pool.init([("127.0.0.1", 9669)])

# get session from the pool
client = connection_pool.get_session("root", "nebula")
assert client is not None

client.execute("USE nba")

result = client.execute(
'GET SUBGRAPH WITH PROP 2 STEPS FROM "player101" YIELD VERTICES AS nodes, EDGES AS relationships;'
)

assert result.is_succeeded(), result.error_msg()

data = result.dict_for_vis()

json_data = json.dumps(data, indent=2, sort_keys=True)

# save the json data to a file
with open('data.json', 'w') as f:
f.write(json_data)

# Check the data.json file to see the result

# See example/apache_echarts.html to see a reference implementation of the visualization
# using Apache ECharts

except Exception:
import traceback

print(traceback.format_exc())
if client is not None:
client.release()
exit(1)
Loading

0 comments on commit 8ce2af0

Please sign in to comment.