1
$\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$
  • $\begingroup$ Try VertexLabels -> Table[a -> Placed[FileNameTake[a], Center], {a, VertexList[g]}]] $\endgroup$ – Szabolcs Oct 4 '16 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 Oct 4 '16 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 Oct 5 '16 at 1:27
  • $\begingroup$ @QuantumDot Thanks for your advice. $\endgroup$ – yode Oct 5 '16 at 7:00
  • $\begingroup$ @rhermans You are editting thost post one by one or you find a automatical method? $\endgroup$ – yode May 12 '17 at 15:30
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$
  • $\begingroup$ Great. You can also use VertexShapeFunction, VertexShapeFunction -> (Text[panelLabel[#2], #1 - {.02, 0}, Left] &), VertexStyle -> Black $\endgroup$ – halmir Oct 5 '16 at 13:31
  • $\begingroup$ @halmir Thanks :) $\endgroup$ – yode Oct 5 '16 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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