2
$\begingroup$

I want to look the local-disk-directory structrue use this code.

g = NestGraph[
   Select[FileNames["*", #], DirectoryQ] &, $InstallationDirectory, 2,
    GraphLayout -> {"LayeredEmbedding", "Orientation" -> Left, 
     "LeafDistance" -> .1}];
SetProperty[g, 
 VertexLabels -> Table[a -> FileNameTake[a], {a, VertexList[g]}]]

But I have some dissatisfaction with it.I want to put vertex name into vertex like this:

But I cannot use Placed[FileNameTake["Name"], Center].Any solution can do this?

$\endgroup$
6
  • $\begingroup$ Try VertexLabels -> Table[a -> Placed[FileNameTake[a], Center], {a, VertexList[g]}]] $\endgroup$
    – Szabolcs
    Commented Oct 4, 2016 at 20:24
  • $\begingroup$ @Szabolcs Done.Thanks.panelLabel[lbl_]:=Panel[lbl,FrameMargins->0,Background->Lighter[Yellow,0.7]];g=NestGraph[Select[FileNames["*",#],DirectoryQ]&,$InstallationDirectory,2];UndirectedGraph[g,GraphLayout->{"LayeredEmbedding","Orientation"->Left,"LeafDistance"->.1},VertexLabels->Table[a->Placed[FileNameTake[a],Center,panelLabel],{a,VertexList[g]}]] $\endgroup$
    – yode
    Commented Oct 4, 2016 at 20:38
  • $\begingroup$ Please post your comment as an answer because it is an answer, and also it is unreadable in present form. $\endgroup$
    – QuantumDot
    Commented Oct 5, 2016 at 1:27
  • $\begingroup$ @QuantumDot Thanks for your advice. $\endgroup$
    – yode
    Commented Oct 5, 2016 at 7:00
  • $\begingroup$ @rhermans You are editting thost post one by one or you find a automatical method? $\endgroup$
    – yode
    Commented May 12, 2017 at 15:30

1 Answer 1

3
$\begingroup$

Per suggestion,I post my comment as answer for reading to show your local-disk-directory structrue.If it is a directory,I will show it with yellow.

panelLabel[lbl_] := 
  Framed[FileNameTake[lbl], FrameMargins -> 1, FrameStyle -> None, 
   RoundingRadius -> 3, 
   Background -> Lighter[If[DirectoryQ[lbl], Yellow, Red], 0.5]];
g = NestGraph[FileNames["*", #] &, $InstallationDirectory, 2];
UndirectedGraph[g, 
 GraphLayout -> {"LayeredEmbedding", "Orientation" -> Left, 
   "LeafDistance" -> .1}, 
 VertexLabels -> 
  Table[a -> Placed[a, Left, panelLabel], {a, VertexList[g]}], 
 VertexSize -> 0]

http://o8aucf9ny.bkt.clouddn.com/2016-10-05-15-38-14.png

$\endgroup$
2
  • $\begingroup$ Great. You can also use VertexShapeFunction, VertexShapeFunction -> (Text[panelLabel[#2], #1 - {.02, 0}, Left] &), VertexStyle -> Black $\endgroup$
    – halmir
    Commented Oct 5, 2016 at 13:31
  • $\begingroup$ @halmir Thanks :) $\endgroup$
    – yode
    Commented Oct 5, 2016 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.