11.4 GraphVisualizationを使用したプログラムによるスタイル適用の例
この項の例では、機能フラグ、ルールベースのスタイル、基準スタイルおよびその他の設定オプションを、プログラムで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
},
"displaySizeControl": 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
}
# Create a graph widget
graph = Graph()
# Assign data
graph.data = data
# Set Feature Flags Programmatically
graph.set_feature_flag("featureFlags", feature_flags)
# Configure Settings Programmatically
graph.set_setting("layout", "force")
graph.set_setting("ruleBasedStyles", rule_based_styles)
graph.set_setting("baseStyles", base_styles)
graph.set_setting("defaults", defaults)
graph.height = 400
graph
前述のコードでは、図11-2に示すような出力が生成されます。