GUIKit の例題:GraphEditor
GUIKit の例題:GraphEditor
GUIKitで提供されていた機能は,組込みのWolfram言語にネイティブのインターフェース構造およびコントロール関数で利用できるようになった.
Needs["GUIKit`"]GraphEdit[expr_] := GUIRunModal[PrepareInterfaceReference[expr]]GraphEditNonModal[expr_] := GUIRun[PrepareInterfaceReference[expr]]PrepareInterfaceReference[expr_] := Module[{ref},
ref = GUILoad["Graph/GraphEditor"];
ref @ InvokeMethod[{"graphFrame", "pack"}];
JavaShow[ref @ WidgetReference["graphFrame"]];
ref @ SetPropertyValue[{"graphPanel", "expr"}, CreateGraphExpr[expr]];
ref]CreateGraphExpr[gr_Graph] := grCreateGraphExpr[mat_SparseArray] := ArrayRules[mat]CreateGraphExpr[mat_ ? MatrixQ] := ArrayRules[mat]CreateGraphExpr[r : {___Rule}] := rCreateGraphExpr[x___] := {}例題
この例題はWolfram言語の機能を既存のサードパーティグラフモデルと編集ライブラリを活用する GUIKit のユーザインターフェース要素で補う利点を示している.GraphEditウィジェットはCombinatorica`でサポートされているGraph式と,SparseArrayおよびArrayRulesを利用する.
グラフ編集キャンバスのユーザインターフェースを使うと以下が可能になる.
mat = {{a + b, f[x, x'], 0}, {x, Sqrt[c], (d/e)}}MatrixForm[mat]outRules = GraphEdit[mat]Normal[SparseArray[outRules]] // MatrixFormmat = SparseArray[{{i_, i_} :> -(1/i), {i_, j_} /; Mod[Abs[i - j], 5] == 1 -> 1}, {6, 6}]mat // MatrixFormoutRules = GraphEdit[mat]Normal[SparseArray[outRules]] //MatrixFormgr = GraphEdit[ Graph[{}, {}, EdgeDirection -> True]]ShowGraph[gr]次は表示されたグラフとインタラクトしたりこれに編集を加えたりできるモードレスセッションで実行された別のバージョンである.
ref = GraphEditNonModal[{{a, b, 0}, {0, c, d}}]ref @ SetPropertyValue[{"graphPanel", "expr"}, ArrayRules[{{e, f, g, n}, {h, i, j, m}}]]ref @ PropertyValue[{"graphPanel", "expr"}]