7

I want to plot the relationship of all fucntions in Mathematica, maybe using Graph or force-directed-graph in D3.js

k = 
  DeleteCases[
    WolframLanguageData[All, {"CanonicalName", "RelatedSymbols"}], {_, _Missing}];
k = MapAt[CanonicalName, k, {All, 2}];
data = 
  DeleteDuplicates[
    Sort /@ Flatten[Thread[#[[1]] \[UndirectedEdge] #[[2]]] & /@ k]];
GraphPlot[data, VertexSize -> Tiny, ImageSize -> Full]

enter image description here

However, the figure is too big. Is there some method to zoom in on it and tooltip the vertices?

I tried Tooltip, However, it did not give a plot.

Graph[Tooltip[#, #] & /@ VertexList[data], data]

enter image description here

And how can I to use colors to distinguish these functions by catogeries such as Audio, Image and Core language?

enter image description here

Maybe I could use machine learning to distinguish these functions I tried but it didn't work out so good.

space = 
  Thread[
    VertexList[data] -> 
      DimensionReduce[
        FeatureExtract[VertexList[data], {"SegmentedWords", "TFIDF"}], 
        1]];
space[[All, 2]] = Normalize[Flatten@space[[All, 2]]];
NumberLinePlot[space[[All, 2]]]

enter image description here

UPDATE:

Version: 12.1.1

These was already a demo in the NestGraph's document.

enter image description here

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
partida
  • 6,816
  • 22
  • 48
  • 9
    This is already possible with WolframLanguageData without needing to dig up the help notebooks. There's an example of exactly what you want to do with the community graph right here: https://wolfram.com/xid/0bni7ixnhg3y6-8x6iz1 . Try this: WolframLanguageData["Sin", "RelationshipCommunityGraph"] – flinty Aug 20 '20 at 14:00
  • @flinty Wow amazing.. :) – partida Aug 20 '20 at 14:10
  • Similar question from long ago: https://mathematica.stackexchange.com/questions/4343/automatically-generating-a-dependency-graph-of-an-arbitrary-mathematica-function?noredirect=1#comment525551_4343 – berniethejet Sep 26 '20 at 13:54

2 Answers2

6

Technical support CASE:4620942 (This has been resolved in v13.3)

$Version

(* "12.1.1 for Mac OS X x86 (64-bit) (June 19, 2020)" *)

Clear["Global`*"]

As suggested by flinty, running code from the documentation

graph = WolframLanguageData["Cos", "RelationshipCommunityGraph"]

enter image description here

The labels for the vertices do not render properly

Show[graph, ImageSize -> Large]

enter image description here

As a workaround, manually fix the labels

graph /. Style[lbl_, _List] :> lbl

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
2

Define a function that can extract neighbors with radius r around vertex n:

subgraph[g_, n_, r_] := Subgraph[g, AdjacencyList[g, n, r]~Join~{n}]

Let's take a look at the neighbors whose distance to the Sin function is 2

subg = subgraph[Graph[data], "Sin", 2];
GraphPlot[HighlightGraph[subg, {"Sin"}], VertexLabels -> "Name", ImageSize -> Large]

enter image description here

Export the graph data that will use in the following HTML:

json = {"nodes" -> 
    Table[{"id" -> i, "group" -> 1}, {i, VertexList@subg}], 
        "links" -> 
    Table[{"source" -> i[[1]], "target" -> i[[2]], "value" -> 1}, {i, EdgeList@subg}]};
Export["miserables.json", json]

Download the D3.js script index.html from D3.js v4 Force Directed Graph with Labels

Then in the terminal type the following (python3): python -m http.server

Then open http://localhost:8000/ in Chrome, the figure can drag the vertex interactively

enter image description here

But for the whole big graph, the D3.js can't handle it...

partida
  • 6,816
  • 22
  • 48