{"id":4886,"date":"2017-04-24T07:17:17","date_gmt":"2017-04-24T07:17:17","guid":{"rendered":"https:\/\/www.dyalog.com\/blog\/?p=4886"},"modified":"2017-04-24T10:37:51","modified_gmt":"2017-04-24T10:37:51","slug":"displaying-cross-references-with-sharpplot-2","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2017\/04\/displaying-cross-references-with-sharpplot-2\/","title":{"rendered":"Displaying cross-references with SharpPlot"},"content":{"rendered":"<p>Requirements: Update SharpPlot to v3.37 from <a title=\"my.dyalog.com\" href=\"http:\/\/my.dyalog.com\" target=\"_blank\">my.dyalog.com<\/a> &gt; Downloads &gt; Tools &amp; Interfaces &gt; GUI Tools &gt; SharpPlot<\/p>\n<p>SharpPlot v3.37 introduces <a href=\"http:\/\/www.sharpplot.com\/SharpPlot-DrawNetworkMap.htm\" target=\"_blank\">Network Maps<\/a> as a new chart type, and we&#8217;re going to use it to display the output of the <code class=\"language-apl\">]XRef<\/code> user command, which displays cross-references between all kinds of APL names :<\/p>\n<pre><code class=\"language-apl\">      ]XRef \u2395SE.Parser\r\n             DDEEEFLLMMNNPPPPPPPPPPPQQSSSTUaaaabbbcdddddddfffiilmmmmmmnnnnnnppppqqqqrrrsssssssssstttttuvvvxx\u2206\u2375\u237a \r\n             EeRnrOOSAOAsRrsssssssss.uwwwrPrrrr:alu.aaaeee.ei.fq.aeioo.adeop.Daa.1mq.et:eipqtwwww:aqwxp.an.C... \r\n             LlRd:RW.XDRwEo:.eeeeeee.oDTiaPgggg:d.t.tttQff.ax.:..smndd..awv..art..:..qb:t.lzr.imp:b.vtp.lc.u... \r\n             I.OT:CE.APGiFp:Pttttttt.t.atpE.psv:....aaau.i.tC.:..k.lei..:....tm...:....:..i.:.tao:l...e....t... \r\n             M.Rr:ER.ROStIa:a........e.bc.R.o.a:....:..o.n.ua.:....elf..:....as...:....:..t.:..ts:e...r....:... \r\n             I.0a:S..GS.cXg:r.Samnpu.s.lh.:.s.l:....:ASt.e.rs.:....n.i..:....:....:....:..P.:....:....C....:... \r\n             T..p:P..S:.h.a:s.wloarp.:.e..:...u:....:rwe.d.ee.:....:.e..:....:....:....:..a.:....:....a....:... \r\n             E...:A...:.e.t:e.ildrep.:....:...e:....:gD..:.s..:....:.r..:....:....:....:..r.:....:....s....:... \r\n             R...:C...:.s.e:..toigfe.:....:...s:....:u...:....:....:.s..:....:....:....:..m.:....:....e....:... \r\n             ....:E...:....:..cwfsir.:....:....:....:m...:....:....:....:....:....:....:..s.:....:....:....:... \r\n             ....:....:....:..hni.x..:....:....:....:e...:....:....:....:....:....:....:....:....:....:....:... \r\n             ....:....:....:...oe....:....:....:....:n...:....:....:....:....:....:....:....:....:....:....:... \r\n             ....:....:....:...sr....:....:....:....:t...:....:....:....:....:....:....:....:....:....:....:... \r\n             ....:....:....:...ps....:....:....:....:s...:....:....:....:....:....:....:....:....:....:....:... \r\n             ....:....:....:...a:....:....:....:....:....:....:....:....:....:....:....:....:....:....:....:... \r\n             ....:....:....:...c:....:....:....:....:....:....:....:....:....:....:....:....:....:....:....:... \r\n             ....:....:....:...e:....:....:....:....:....:....:....:....:....:....:....:....:....:....:....:... \r\n [FNS]        - - - - : - - - - : - - - - : - - - - : - - - - : - - - - : - - - - : - - - - : - - - - : - - - - \r\n Parse       G.GG\u25cbG G GGGG. . . : . \u25cbF.G.G:\u25cb\u25cb\u25cb\u25cb\u25cb! . \u25cbGGF.\u25cb. .\u25cbF \u25cb .\u25cb. . \u25cb!\u25cb\u25cb\u25cbG\u25cb\u25cb! : .\u25cb\u25cb\u25cb\u25cb F :\u25cb\u25cb\u25cb\u25cb\u25cb\u25cb \u25cb : \u25cb\u25cb.F! . \r\n Propagate    \u25cb . . . : . . . . : . . G . : . .\u25cb. . : . . . . : . . .\u25cb. : . . . . : . . .\u25cb. \u25cb\u25cb. . . . :\u25cb. . . . \r\n Quotes       . . . . : . . . . : . \u25cb . . : . . . . : . . . .\u25cb: .\u25cb. . \u25cb : . . . . \u25cb . . . . \u25cb . . .\u25cb. : . . . . \r\n Switch       . G . . : . . . . : . . G .G: . . . . : . \u25cb . . : . . . . : . . . . : \u25cb .\u25cb. . : . . . . :\u25cb. . . . \r\n deQuote      . . . . : . . . . : . . . . : . . . . : . . . . :\u25cb\u25cb . . . : . . . . : . . . . \u25cb . . . . : . . . . \r\n fixCase      . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . .\u25cb. \r\n if           . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . . . \r\n init        G.G. G GGGGGGFGGGGGGGGG.F.GF :\u25cb. .\u25cb. \u25cb : . . \u25cb\u25cbF F . \u25cb \u25cb \u25cb\u25cb: . .G. . : . . . .F: . . . . F . GF. . \r\n splitParms   . . . . : . . . . : . \u25cb . . : . . .\u25cb.\u25cb: . . . . : . . . \u25cb : .\u25cb\u25cb \u25cb \u25cb\u25cb:\u25cb. .\u25cb. . : . .\u25cb. .\u25cb: . . . . \r\n sqz          . . . . : . . . . : . . . . : . .\u25cb. . : . . . . : . . . . : . . . . : . .\u25cb. . : . . . . : . . .\u25cb. \r\n upperCase    . . .G. : . . . . : . . . . G . .\u25cb. . : . . . .\u25cb: . . . . : . . . . : . .\u25cb. . : . . . . : . . .\u25cb. \r\n xCut         . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . . . : . . .\u25cb\u25cb \r\n<\/code><\/pre>\n<p>We can capture the output of the user command by doing either<br \/>\n<code class=\"language-apl\">]mat\u2190XRef \u2395SE.Parser<\/code> (from session)<br \/>\nor<br \/>\n<code class=\"language-apl\">mat\u2190\u2395SE.UCMD']XRef \u2395SE.Parser'<\/code> (from code)<\/p>\n<p>Until Dyalog v16.0 (which has <code class=\"language-apl\">]XRef -raw<\/code>), we need to parse the output of <code class=\"language-apl\">]XRef<\/code> to get a square link matrix, along with the full list of nodes (in row\/column order of the matrix) and list of original rows (functions).<\/p>\n<pre><code class=\"language-apl\">    \u2207 (mat nodes rows)\u2190GetMatrix mat;nodelabs;rows;cols;labs;cat;diag\r\n      (rows mat)\u21902\u2191(1,2&lt;\/\u2227\u233fmat=&#039; &#039;)\u2282[2]mat        \u235d cut at empty column\r\n      (cols mat)\u21902\u2191(1,2&lt;\u233f\u2227\/mat\u220a&#039; -:&#039;)\u2282[1]mat      \u235d cut at - - - - : - - - -\r\n      mat\u21901\u2193[1](&#039; &#039;\u2228.\u2260mat)\/mat                    \u235d trim first row and empty columns\r\n      rows\u2190~\u2218&#039; &#039;\u00a8\u2193(-1\u2283\u2374mat)\u2191[1]rows               \u235d row titles (list of strings)\r\n      cols\u2190~\u2218&#039; .:&#039;\u00a8\u2193(-2\u2283\u2374mat)\u2191[1]\u2349cols            \u235d col titles (list of strings)\r\n      nodes\u2190rows\u222acols                             \u235d all titles\r\n      mat\u2190((mat,&#039; &#039;)\u236a&#039; &#039;)[rows\u2373nodes;cols\u2373nodes]  \u235d square matrix of nodes\r\n    \u2207<\/code><\/pre>\n<p>Now let&#8217;s wrap the SharpPlot initialisation into a single function that uses the .NET version if available and falls back to the cross-platform APL workspace if not:<\/p>\n<pre><code class=\"language-apl\">    \u2207 {dotnet}\u2190Init\r\n      :If dotnet\u2190(,'W')\u22613\u2283'.'\u2395WG'APLVersion'\r\n          \u235d .Net assembly (windows only)\r\n          \u2395USING\u2190',sharpplot.dll' ',system.drawing.dll'\r\n      :Else\r\n          \u235d APL workspace (all platforms)\r\n          :If 0=\u2395NC'Causeway'   \u235d copy workspace only once\r\n              (System.Drawing\u2190System\u2190\u234e'Causeway'\u2395NS'').(\u2395CY'sharpplot.dws')\r\n          :EndIf \r\n      :EndIf\r\n    \u2207<\/code><\/pre>\n<p>Then we can write a platform-independent function that returns the SharpPlot instance with the chart drawn on it. We <a href=\"http:\/\/sharpplot.com\/SharpPlot-SplitBy.htm\" target=\"_blank\">split<\/a> nodes into two categories, functions and globals (ignoring locals and labels) and split links by destination node. By default, DrawNetworkMap lays out node categories on co-centric circles. Also, because the graph is uni-directional, we can afford to use straight links without damaging readability:<\/p>\n<pre><code class=\"language-apl\">    \u2207 sp\u2190name Plot(mat nodes rows);catlabs;nodecat\r\n      sp\u2190\u2395NEW Causeway.SharpPlot\r\n     \r\n      catlabs\u2190'Function' 'Global'    \u235d links are split by destination node\r\n      nodecat\u2190(\u2262nodes)\u23740             \u235d ignored by default\r\n      ((\u2228\u233fmat\u220a'FR*')\/nodecat)\u21901      \u235d functions\r\n      ((\u2228\u233fmat\u220a'G')\/nodecat)\u21902        \u235d globals\r\n      ((nodes\u220arows)\/nodecat)\u21901       \u235d caller functions\r\n     \r\n      sp.Heading\u2190name\r\n      sp.HeadingStyle\u2190Causeway.HeadingStyles.Left\r\n      sp.SetMargins 40 30 30 30\r\n      sp.KeyStyle\u2190Causeway.KeyStyles.(BottomAlign+RightAlign)\r\n      sp.SetILabels\u2282nodes\r\n      sp.SetILabelFont'Arial' 6 System.Drawing.FontStyle.Bold System.Drawing.Color.Black\r\n      sp.SetColors\u2282System.Drawing.Color.(SkyBlue LightCoral)\r\n      sp.SetMarkers Causeway.Marker.Ball\r\n      sp.SetMarkerScales 2\r\n      sp.SetLineStyles Causeway.LineStyle.Solid\r\n      sp.SetPenWidths 0.5\r\n      sp.NetworkMapStyle\u2190Causeway.NetworkMapStyles.(SplitByDestination+Dissected+ArrowLines+FixedArcs+NoAxes+NoLinkKey)\r\n      sp.SetNetworkMapLinkArc 0         \u235d straight lines\r\n      sp.SetArrowStyle 5                \u235d fixed-size arrows\r\n     \r\n      sp.SplitBy nodecat catlabs\r\n      sp.DrawNetworkMap\u2282\u2193(mat\u220a'GFR*')   \u235d use a single width for all valid links\r\n    \u2207<\/code><\/pre>\n<p>We can then save the graph as SVG to a file (here we use the <a href=\"http:\/\/sharpplot.com\/SvgMode.htm\" target=\"_blank\">SvgMode<\/a> that scales the SVG to fit its container):<br \/>\n<code class=\"language-apl\">sp.SaveSvg 'XRef.svg' Causeway.SvgMode.FixedAspect<\/code><\/p>\n<p>Or, if feeding a web server or renderer, we can grab the SVG as a single string without writing to disk:<br \/>\n<code class=\"language-apl\">svg\u2190sp.RenderSvg Causeway.SvgMode.FixedAspect<\/code><\/p>\n<p>Windows users will be able to use the SharpPlot Viewer:<br \/>\n<code class=\"language-apl\">vw\u2190\u2395NEW Causeway.SharpPlotViewer sp<br \/>\nvw.Show \u236c<\/code><\/p>\n<p><a href=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2017\/03\/XRef.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2017\/03\/XRef.png\" alt=\"XRef\" width=\"864\" height=\"648\" class=\"aligncenter size-full wp-image-4877\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2017\/03\/XRef.png 864w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2017\/03\/XRef-300x225.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2017\/03\/XRef-400x300.png 400w\" sizes=\"auto, (max-width: 864px) 100vw, 864px\" \/><\/a><\/p>\n<p>More examples of Network Maps can be found on the SharpPlot.com website in the <a href=\"http:\/\/www.sharpplot.com\/NetworkMap.htm\" target=\"_blank\">Network Map Tutorials<\/a>. To translate C# examples into APL, you can refer to the <a href=\"http:\/\/www.sharpplot.com\/Languages.htm\" target=\"_blank\">SharpPlot Rosetta Stone<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Requirements: Update SharpPlot to v3.37 from my.dyalog.com &gt; Downloads &gt; Tools &amp; Interfaces &gt; GUI Tools &gt; SharpPlot SharpPlot v3.37 introduces Network Maps as a new chart type, and we&#8217;re going to use it to display the output of the &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2017\/04\/displaying-cross-references-with-sharpplot-2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":22,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,19],"tags":[],"class_list":["post-4886","post","type-post","status-publish","format-standard","hentry","category-sharpplot","category-tools"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/4886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=4886"}],"version-history":[{"count":13,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/4886\/revisions"}],"predecessor-version":[{"id":4892,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/4886\/revisions\/4892"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=4886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=4886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=4886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}