-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: graph vis with dict_for_vis & Apache ECharts
- Loading branch information
Showing
5 changed files
with
4,724 additions
and
4 deletions.
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
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 |
---|---|---|
@@ -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) |
Oops, something went wrong.