11.3 GraphVisualizationを使用したカスタム・スタイル設定の例
この項の例では、JSONファイルからグラフ・データをロードして、機能フラグ、基準スタイルおよびルールベースのスタイルを構成し、最後にGraphVisualizationを使用してグラフを表示する方法について説明します。
ここでは、GraphVisualizationを使用した基本的な例で説明されているsample_data.jsonグラフ構成を使用しています。
from oraclegraph import GraphVisualization as Graph
import json
# Load data from JSON file
with open('sample_data.json', 'r') as f:
data = json.load(f)
data['isLastResultSet'] = True
# Configure feature flags
feature_flags = {
"exploration": {
"expand": True,
"focus": True
},
"modes": {
"interaction": True
}
}
# Define base styles
base_styles = {
"edge": {
"color": "lightgray"
},
"edge:hover": {
"color": "red",
"opacity": 0.4
},
"vertex": {
"color": "#195F74",
"label": "${properties.ID}"
}
}
# Define rule-based styles
rule_based_styles = [
{
"legendTitle": "Label - ACCOUNTS",
"stylingEnabled": True,
"component": "vertex",
"target": "vertex",
"conditions": {
"conditions": [
{
"property": "ID",
"operator": ">",
"value": 0
}
]
},
"style": {
"label": {
"text": "${properties.ID}"
}
}
}
]
# Configure additional settings
defaults = {
"interactionActive": True,
"stickyActive": True
}
# Configure settings
settings = {
"layout": "force",
"ruleBasedStyles": rule_based_styles,
"baseStyles": base_styles,
"defaults": defaults
}
# Create and display the graph
graph = Graph(data=data, feature_flags=feature_flags, settings=settings)
graph.height = 400
graph
前述のコードは、次のグラフ・ビジュアライゼーションを生成します:
