Yar*_*tov 7 wolfram-mathematica graph
我有时遇到TreeForm中的标签因重叠而无法读取的问题.下面是一个例子,任何人都可以看到摆脱重叠的方法吗?
{{4, 5, 6}, {{{2, 4, 5, 6}, {{{1, 2, 4}, {}}, {{2, 3, 6}, {}}}}, {{4, 5, 6, 8}, {{{4, 7, 8}, {}}, {{6, 8, 9}, {}}}}}} // TreeForm
http://yaroslavvb.com/upload/treeform1.png
Belisarius的解决方案有助于重叠,但丢失工具提示,即与之比较
TreeForm[Hold[ GraphPlotHighlight[edges : {((_ -> _) | {_ -> _, _}) ...}, hl : {___} : {}, opts : OptionsPattern[]] := Module[{verts, coords, g, sub}, 5]]]
http://yaroslavvb.com/upload/mathematica-tooltip.png
回答更新11/12 我最终使用下面的代码(belisarius'代码带有小修正)
myTreeForm[exp_] :=
Module[{tooltipText, i},
tooltipText =
Cases[Cases[MakeBoxes[TreeForm@exp, StandardForm],
TooltipBox[x__] -> x, 7, Heads -> True],
TagBox[x__, y__] -> DisplayForm[First@{x}], Heads -> True];
i = 0;
TreeForm[exp,
VertexRenderingFunction -> ({Tooltip[
Inset[Rasterize[Text[" " <> ToString@#2 <> " "],
Background -> LightBlue], #1], tooltipText[[i++]]]} &)]];
Run Code Online (Sandbox Code Playgroud)
我之前做过这个,但从未概括过结果.
rectOffset = {.25,.1};
fontSize = 10
TreeForm[list,
VertexRenderingFunction -> ({White, EdgeForm[Black],
Rectangle[#1 - rectOffset, #1 + rectOffset], Black,
Text[ Style[#2, fontSize], #1]} &)]
Run Code Online (Sandbox Code Playgroud)
使用工具提示 编辑
使用"不同的方法"
代码很脏,抱歉没时间立即清理它
rectOffset = {.33, .1};
fontSize = 9;
p = Cases[
Cases[MakeBoxes[TreeForm@list, StandardForm], TooltipBox[x__] -> x,
7, Heads -> True], TagBox[x__, y__] -> DisplayForm[First@{x}],
Heads -> True];
i = 0;
TreeForm[list,
VertexRenderingFunction -> ({White, EdgeForm[Black],
Rectangle[#1 - rectOffset, #1 + rectOffset], Black,
Tooltip[Text[Style[#2, fontSize], #1], p[[i++]]]} &)]
Run Code Online (Sandbox Code Playgroud)
产量
编辑2
我认为这个版本更好:
Clear["Global`*"];
list = Hold[
GraphPlotHighlight[edges : {((_ -> _) | {_ -> _, _}) ...},
hl : {___} : {}, opts : OptionsPattern[]] :=
Module[{verts, coords, g, sub}, 5]];
myTreeForm[exp_] :=
Module[{ps, tooltipText, i},
ps[text_] := Rasterize[Text[Style[text]], "RasterSize"];
tooltipText =
Cases[Cases[MakeBoxes[TreeForm@list, StandardForm],
TooltipBox[x__] -> x, 7, Heads -> True],
TagBox[x__, y__] -> DisplayForm[First@{x}], Heads -> True];
i = 0;
TreeForm[list,
EdgeRenderingFunction -> ({Red, Line[#1]} &),
VertexRenderingFunction -> ({White, EdgeForm[Black], {}, Black,
Tooltip[
Inset[Rasterize[Text[" " <> ToString@#2 <> " "],
Background -> LightBlue], #1], tooltipText[[i++]]]} &)]
];
list // myTreeForm
Run Code Online (Sandbox Code Playgroud)
输出:
编辑4 ...和最后一个
清理代码,删除虚假函数和变量,只是为了使事情复杂化:
myTreeForm[list_] := Module[{tooltipText, i},
tooltipText =
Cases[Cases[MakeBoxes[TreeForm@list, StandardForm],
TooltipBox[x__] -> x, 7, Heads -> True],
TagBox[x__, y__] -> DisplayForm[First@{x}], Heads -> True];
i = 0;
TreeForm[list,
VertexRenderingFunction ->
({Tooltip[Inset[Rasterize[Text[" " <> ToString@#2 <> " "],
Background -> LightBlue], #1], tooltipText[[i++]]]} &)
]
];
Run Code Online (Sandbox Code Playgroud)
HTH!
归档时间: |
|
查看次数: |
449 次 |
最近记录: |