Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/GAP/pkg/jupyterviz/doc/   (Algebra von RWTH Aachen Version 4.15.1©)  Datei vom 16.7.2022 mit Größe 63 kB image not shown  

Quelle  chap7_mj.html   Sprache: HTML

 
 products/sources/formale Sprachen/GAP/pkg/jupyterviz/doc/chap7_mj.html


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<script type="text/javascript"
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<title>GAP (JupyterViz) - Chapter 7: Function reference</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
<script src="manual.js" type="text/javascript"></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap7"  onload="jscontent()">


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a>  <a href="chap1_mj.html">1</a>  <a href="chap2_mj.html">2</a>  <a href="chap3_mj.html">3</a>  <a href="chap4_mj.html">4</a>  <a href="chap5_mj.html">5</a>  <a href="chap6_mj.html">6</a>  <a href="chap7_mj.html">7</a>  <a href="chapInd_mj.html">Ind</a>  </div>

<div class="chlinkprevnexttop"> <a href="chap0_mj.html">[Top of Book]</a>   <a href="chap0_mj.html#contents">[Contents]</a>    <a href="chap6_mj.html">[Previous Chapter]</a>    <a href="chapInd_mj.html">[Next Chapter]</a>   </div>

<p id="mathjaxlink" class="pcenter"><a href="chap7.html">[MathJax off]</a></p>
<p><a id="X7ECCCA82839EA283" name="X7ECCCA82839EA283"></a></p>
<div class="ChapSects"><a href="chap7_mj.html#X7ECCCA82839EA283">7 <span class="Heading">Function reference</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap7_mj.html#X80378EDF79B85A46">7.1 <span class="Heading">High-Level Public API</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X811D60857B0B2B68">7.1-1 Plot</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X7B36451A873E06B2">7.1-2 ConvertDataSeriesForTool</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X79FCD4E67FF49A5F">7.1-3 PlotGraph</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X80380CBB7E1FA082">7.1-4 ConvertGraphForTool</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X81D8CBD97B9677C0">7.1-5 PlotDisplayMethod</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X877563A087BAF265">7.1-6 PlotDisplayMethod_Jupyter</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X85332D257DD44070">7.1-7 PlotDisplayMethod_JupyterSimple</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X818039C5844E897B">7.1-8 PlotDisplayMethod_HTML</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap7_mj.html#X83E0040584EAF486">7.2 <span class="Heading">Low-Level Public API</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X78BDA43D7E633E33">7.2-1 RunJavaScript</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X81E2B3A07EA7A02B">7.2-2 LoadJavaScriptFile</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X83454CD67FF0EED7">7.2-3 InstallVisualizationTool</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X876DFB2B87FC3732">7.2-4 InstallVisualizationToolFromTemplate</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X7BFFD8B7808F5BDA">7.2-5 CreateVisualization</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap7_mj.html#X7B106BA97FD3C2BF">7.3 <span class="Heading">Internal methods</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X7FA27984822A0E5E">7.3-1 JUPVIZAbsoluteJavaScriptFilename</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X7F877B4279081217">7.3-2 JUPVIZLoadedJavaScriptCache</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X84F0A3C97FBC57EE">7.3-3 JUPVIZFillInJavaScriptTemplate</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X8603271979CCFA2A">7.3-4 JUPVIZRunJavaScriptFromTemplate</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X804379D07F29E905">7.3-5 JUPVIZRunJavaScriptUsingRunGAP</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X79B7692C7F543161">7.3-6 JUPVIZRunJavaScriptUsingLibraries</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X8620A70785F90EE6">7.3-7 JUPVIZMakePlotDataSeries</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X7B5CF2DA86E91C11">7.3-8 JUPVIZMakePlotGraphRecord</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X87B06B5C872845E9">7.3-9 JUPVIZPlotDataSeriesList</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X873A09F5852A33E9">7.3-10 JUPVIZRecordKeychainLookup</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X7C8A5FCD7B96D5DC">7.3-11 JUPVIZRecordsKeychainLookup</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X784852877814711F">7.3-12 JUPVIZFetchWithDefault</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X856669217AADA94F">7.3-13 JUPVIZFetchIfPresent</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap7_mj.html#X7CB82ABE7B3255EB">7.4 <span class="Heading">Representation wrapper</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X82269732822D224D">7.4-1 JUPVIZIsFileContents</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X84D70ACD7A72AA84">7.4-2 JUPVIZIsFileContentsRep</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap7_mj.html#X7D401DB582A5EBA2">7.4-3 JUPVIZFileContents</a></span>
</div></div>
</div>

<h3>7 <span class="Heading">Function reference</span></h3>

<p><a id="X80378EDF79B85A46" name="X80378EDF79B85A46"></a></p>

<h4>7.1 <span class="Heading">High-Level Public API</span></h4>

<p><a id="X811D60857B0B2B68" name="X811D60857B0B2B68"></a></p>

<h5>7.1-1 Plot</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Plot</code>( <var class="Arg">various</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: one of two things, documented below</p>

<p>If evaluated in a Jupyter Notebook, the result of this function, when rendered by that notebook, will run JavaScript code that generates and shows a plot in the output cell, which could be any of a wide variety of data visualizations, including bar charts, pie charts, scatterplots, etc. (To draw a vertex-and-edge graph, see <code class="func">PlotGraph</code> (<a href="chap7_mj.html#X79FCD4E67FF49A5F"><span class="RefLink">7.1-3</span></a>) instead.)</p>

<p>If evaluated outside of a Jupyter Notebook, the result of this function is the name of a temporary file stored on disk in which HTML code for such a visualization has been written, and on which <strong class="pkg">GAP</strong> has already invoked the user's default web browser. The user should see the visualization appear in the browser immediately before the return value is shown.



<p>This function can take data in a wide variety of input formats. Here is the current list of acceptable formats:</p>


<ul>
<li><p>If <code class="code">X</code> is a list of <span class="SimpleMath">\(x\)</span> values and <code class="code">Y</code> is a list of <span class="SimpleMath">\(y\)</span> values then <code class="code">Plot(X,Y)</code> plots them as ordered pairs.</p>

</li>
<li><p>If <code class="code">X</code> is a list of <span class="SimpleMath">\(x\)</span> values and <code class="code">f</code> is a <strong class="pkg">GAP</strong> function that can be applied to each <span class="SimpleMath">\(x\)</span> to yield a corresponding <span class="SimpleMath">\(y\)</span>, then <code class="code">Plot(X,f)</code> computes those corresponding <span class="SimpleMath">\(y\)</span> values and plots everything as ordered pairs.</p>

</li>
<li><p>If <code class="code">P</code> is a list of <span class="SimpleMath">\((x,y)\)</span> pairs then <code class="code">Plot(P)</code> plots those ordered pairs.</p>

</li>
<li><p>If <code class="code">Y</code> is a list of <span class="SimpleMath">\(y\)</span> values then <code class="code">Plot(Y)</code> assumes the corresponding <span class="SimpleMath">\(x\)</spanvalues are 1, 2, 3, and so on up to the length of <code class="code">Y</code>. It then plots the corresponding set of ordered pairs.</p>

</li>
<li><p>If <code class="code">f</code> is a <strong class="pkg">GAP</strong> function then <code class="code">Plot(f)</code> assumes that <code class="code">f</code> requiers integer inputs and evaluates it on a small domain (1 through 5) of <span class="SimpleMath">\(x\)</span> values and plots the resulting <span class="SimpleMath">\((x,y)\)</span> pairs.</p>

</li>
<li><p>In any of the cases above, a new, last argument may be added that is a <strong class="pkg">GAP</strong> record (call it <code class="code">R</code>) containing options for how to draw the plot, including the plot type, title, axes options, and more. Thus the forms <code class="code">Plot(X,Y,R)</code>, <code class="code">Plot(X,f,R)</code>, <code class="code">Plot(P,R)</code>, <code class="code">Plot(Y,R)</code>, and <code class="code">Plot(f,R)</code> are all acceptable. (For details, see <code class="func">ConvertDataSeriesForTool</code> (<a href="chap7_mj.html#X7B36451A873E06B2"><span class="RefLink">7.1-2</span></a>).)</p>

</li>
<li><p>If <code class="code">A1</code> is a list of arguments fitting any of the cases documented above (such as <code class="code">[X,f]</code>) and <code class="code">A2</code> is as well, and so on through <code class="code">An</code>, then <code class="code">Plot(A1,A2,...,An)</code> creates a combination plot with all of the data from each of the arguments treated as a separate data series. If the arguments contain conflicting plot options (e.g., the first requests a line plot and the second a bar chart) then the earliest option specified takes precedence.</p>

</li>
</ul>

<div class="example"><pre>
# Plot the number of small groups of order n, from n=1 to n=50:
Plot( [1..50], NrSmallGroups );
</pre></div>

<p><img width="500" src="groups-plot.png"/></p>


<div class="example"><pre>
# Plot how much Andrea has been jogging lately:
Plot( ["Jan","Feb","Mar"], [46,59,61],
      rec( title := "Andrea's Jogging", yaxis := "miles per month" ) );
</pre></div>

<p><img width="500" src="andrea-plot.png"/></p>

<p><a id="X7B36451A873E06B2" name="X7B36451A873E06B2"></a></p>

<h5>7.1-2 ConvertDataSeriesForTool</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ConvertDataSeriesForTool</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>The <strong class="pkg">JupyterViz</strong> Package has a high-level API and a low-level API. The high-level API involves functions like <code class="code">Plot</code>, which take data in a variety of convenient formats, and produce visualizations from them. The low-level API can be used to pass JSON data structures to JavaScript visualization tools in their own native formats for rendering. The high-level API is built on the low-level API, using key functions to do the conversion.</p>

<p>The conversion functions for plots are stored in a global dictionary in this variable. It is a <strong class="pkg">GAP</strong> record mapping visualization tool names (such as plotly, etc., a complete list of which appears in Section <a href="chap1_mj.html#X78E0A9867DABCE86"><span class="RefLink">1.1</span></a>) to conversion functions. Only those tools that support plotting data in the form of <span class="SimpleMath">\((x,y)\)</span> pairs should be included. (For example, tools that specialize in drawing vertex-and-edge graphs are not relevant here.)</p>

<p>Each conversion function must behave as follows. It expects its input object to be a single data series, which will be a <strong class="pkg">GAP</strong> record with three fields:</p>


<ul>
<li><p><code class="code">x</code> - a list of <span class="SimpleMath">\(x\)</span> values for the plot</p>

</li>
<li><p><code class="code">y</code> - the corresponding list of <span class="SimpleMath">\(y\)</spanvalues for the same plot</p>

</li>
<li><p><code class="code">options</code> - another (inner) <strong class="pkg">GAP</strong> record containing any of the options documented in Section <a href="chap2_mj.html#X7827F05D814CFB10"><span class="RefLink">2.2</span></a>.</p>

</li>
</ul>
<p>The output of the conversion function should be a <strong class="pkg">GAP</strong> record amenable to conversion (using <code class="code">GapToJsonString</code> from the <strong class="pkg">json</strong> package) into JSON. The format of the JSON is governed entirely by the tool that will be used to visualize it, each of which has a different data format it expects.</p>

<p>Those who wish to install new visualization tools for plots (as discussed in Chapter <a href="chap5_mj.html#X81249ADA79916213"><span class="RefLink">5</span></a>) will want to install a new function in this object corresponding to the new tool. If you plan to do so, consider the source code for the existing conversion functions, which makes use of two useful convenince methods, <code class="func">JUPVIZFetchWithDefault</code> (<a href="chap7_mj.html#X784852877814711F"><span class="RefLink">7.3-12</span></a>) and <code class="func">JUPVIZFetchIfPresent</code> (<a href="chap7_mj.html#X856669217AADA94F"><span class="RefLink">7.3-13</span></a>). Following those examples will help keep your code consistent with existing code and as concise as possible.</p>

<p><a id="X79FCD4E67FF49A5F" name="X79FCD4E67FF49A5F"></a></p>

<h5>7.1-3 PlotGraph</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PlotGraph</code>( <var class="Arg">various</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: one of two things, documented below</p>

<p>If evaluated in a Jupyter Notebook, the result of this function, when rendered by that notebook, will run JavaScript code that generates and shows a graph in the output cell, not in the sense of coordinate axes, but in the sense of vertices and edges. (To graph a function or data set on coordinate axes, use <code class="func">Plot</code> (<a href="chap7_mj.html#X811D60857B0B2B68"><span class="RefLink">7.1-1</span></a>) instead.)</p>

<p>If evaluated outside of a Jupyter Notebook, the result of this function is the name of a temporary file stored on disk in which HTML code for such a visualization has been written, and on which <strong class="pkg">GAP</strong> has already invoked the user's default web browser. The user should see the visualization appear in the browser immediately before the return value is shown.



<p>This function can take data in a wide variety of input formats. Here is the current list of acceptable formats:</p>


<ul>
<li><p>If <code class="code">V</code> is a list and <code class="code">E</code> is a list of pairs of items from <code class="code">V</code> then <code class="code">PlotGraph(V,E)</code> treats them as vertex and edge sets, respectively.</p>

</li>
<li><p>If <code class="code">V</code> is a list and <code class="code">R</code> is a <strong class="pkg">GAP</strong> function then <code class="code">PlotGraph(V,R)</code> treats <code class="code">V</code> as the vertex set and calls <code class="code">R(v1,v2)</code> for every pair of vertices (in both orders) to test whether there is an edge between them. It exepcts <code class="code">R</code> to return boolean values.</p>

</li>
<li><p>If <code class="code">E</code> is a list of pairs then <code class="code">PlotGraph(E)</code> treats <code class="code">E</code> as a list of edges, inferring the vertex set to be any vertex mentioned in any of the edges.</p>

</li>
<li><p>If <code class="code">M</code> is a square matrix then <code class="code">PlotGraph(M)</code> treats <code class="code">M</code> as an adjacency matrix whose vertices are the integers 1 through <span class="SimpleMath">\(n\)</span> (the height of the matrix) and where two vertices are connected by an edge if and only if that matrix entry is positive.</p>

</li>
<li><p>In any of the cases above, a new, last argument may be added that is a <strong class="pkg">GAP</strong> record containing options for how to draw the graph, such as the tool to use. For details on the supported options, see <code class="func">ConvertGraphForTool</code> (<a href="chap7_mj.html#X80380CBB7E1FA082"><span class="RefLink">7.1-4</span></a>).</p>

</li>
</ul>

<div class="example"><pre>
# Plot the subgroup lattice for a small group:
G := Group((1,2),(2,3));
PlotGraph( AllSubgroups(G), IsSubgroup );
</pre></div>

<p><img width="500" src="subgroup-lattice.png"/></p>


<div class="example"><pre>
# Plot a random graph on 5 vertices:
# (The results change from one run to the next, of course.)
PlotGraph( RandomMat(5,5) );
</pre></div>

<p><img width="250" src="random-graph.png"/></p>

<p><a id="X80380CBB7E1FA082" name="X80380CBB7E1FA082"></a></p>

<h5>7.1-4 ConvertGraphForTool</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ConvertGraphForTool</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>The <strong class="pkg">JupyterViz</strong> Package has a high-level API and a low-level API. The high-level API involves functions like <code class="code">PlotGraph</code>, which take data in a variety of convenient formats, and produce visualizations from them. The low-level API can be used to pass JSON data structures to JavaScript visualization tools in their own native formats for rendering. The high-level API is built on the low-level API, using key functions to do the conversion.</p>

<p>The conversion functions for graphs are stored in a global dictionary in this variable. It is a <strong class="pkg">GAP</strong> record mapping visualization tool names (such as cytoscape, a complete list of which appears in Section <a href="chap1_mj.html#X78E0A9867DABCE86"><span class="RefLink">1.1</span></a>) to conversion functions. Only those tools that support graphing vertex and edge sets should be included. (For example, tools that specialize in drawing plots of data stored as <span class="SimpleMath">\((x,y)\)</span> pairs are not relevant here.)</p>

<p>Each conversion function must behave as follows. It expects its input object to be a single graph, which will be a <strong class="pkg">GAP</strong> record with three fields:</p>


<ul>
<li><p><code class="code">vertices</code> - a list of vertex names for the graph. These can be any <strong class="pkg">GAP</strong> data structure and they will be converted to strings with <code class="code">PrintString</code>. The one exception is that you can give each vertex a position by making it a record with three entries: <code class="code">name</code>, <code class="code">x</code>, and <code class="code">y</code>. In this way, you can manually lay out a graph.</p>

</li>
<li><p><code class="code">edges</code> - a list of pairs from the <code class="code">vertices</code> list, each of which represents an edge</p>

</li>
<li><p><code class="code">options</code> - a <strong class="pkg">GAP</strong> record containing any of the options documented in Section <a href="chap2_mj.html#X8109348A84B8A4D4"><span class="RefLink">2.4</span></a>.</p>

</li>
</ul>
<p>The output of the conversion function should be a <strong class="pkg">GAP</strong> record amenable to conversion (using <code class="code">GapToJsonString</code> from the <strong class="pkg">json</strong> package) into JSON. The format of the JSON is governed entirely by the tool that will be used to visualize it, each of which has a different data format it expects.</p>

<p>Those who wish to install new visualization tools for graphs (as discussed in Chapter <a href="chap5_mj.html#X81249ADA79916213"><span class="RefLink">5</span></a>) will want to install a new function in this object corresponding to the new tool. If you plan to do so, consider the source code for the existing conversion functions, which makes use of two useful convenince methods, <code class="func">JUPVIZFetchWithDefault</code> (<a href="chap7_mj.html#X784852877814711F"><span class="RefLink">7.3-12</span></a>) and <code class="func">JUPVIZFetchIfPresent</code> (<a href="chap7_mj.html#X856669217AADA94F"><span class="RefLink">7.3-13</span></a>). Following those examples will help keep your code consistent with existing code and as concise as possible.</p>

<p><a id="X81D8CBD97B9677C0" name="X81D8CBD97B9677C0"></a></p>

<h5>7.1-5 PlotDisplayMethod</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PlotDisplayMethod</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>The <strong class="pkg">JupyterViz</strong> Package can display visualizations in three different ways, and this global variable is used to switch among those ways.</p>


<div class="example"><pre>
PlotDisplayMethod := PlotDisplayMethod_HTML;
</pre></div>

<p>Users of this package almost never need to alter the value of this variable because a sensible default is chosen at package loading time. If the <strong class="pkg">JupyterViz</strong> Package is loaded after the <strong class="pkg">JupyterKernel</strong> Package, it notices the presence of that package and leverage its tools to set up support for plotting in a Jupyter environment. Furthermore, it will initialize <code class="func">PlotDisplayMethod</code> to <code class="func">PlotDisplayMethod_Jupyter</code> (<a href="chap7_mj.html#X877563A087BAF265"><span class="RefLink">7.1-6</span></a>), which is probably what the user wants. Note that if one calls <code class="code">LoadPackage("JupyterViz");</code> from a cell in a Jupyter notebook, this is the case that applies, because clearly in such a case, the <strong class="pkg">JupyterKernel</strong> Package was already loaded.</p>

<p>If the <strong class="pkg">JupyterViz</strong> Package is loaded without the <strong class="pkg">JupyterKernel</strong> Package already loaded, then it will initialize <code class="func">PlotDisplayMethod</code> to <code class="func">PlotDisplayMethod_HTML</code> (<a href="chap7_mj.html#X818039C5844E897B"><span class="RefLink">7.1-8</span></a>), which is what the user probably wants if using <strong class="pkg">GAP</strong> from a terminal, for example. You may later assign <code class="func">PlotDisplayMethod</code> to another value, but doing so has little purpose from the REPL. You would need to first load the <strong class="pkg">JupyterKernel</strong> Package, and even then, all that would be produced by this package would be data structures that would, if evaluated in a Jupyter notebook, produce visualizations.</p>

<p><a id="X877563A087BAF265" name="X877563A087BAF265"></a></p>

<h5>7.1-6 PlotDisplayMethod_Jupyter</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PlotDisplayMethod_Jupyter</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>This global constant can be assigned to the global variable <code class="func">PlotDisplayMethod</code> (<a href="chap7_mj.html#X81D8CBD97B9677C0"><span class="RefLink">7.1-5</span></a>) as documented above. Doing so produces the following results.</p>


<ul>
<li><p>Functions such as <code class="func">Plot</code> (<a href="chap7_mj.html#X811D60857B0B2B68"><span class="RefLink">7.1-1</span></a>), <code class="func">PlotGraph</code> (<a href="chap7_mj.html#X79FCD4E67FF49A5F"><span class="RefLink">7.1-3</span></a>), and <code class="func">CreateVisualization</code> (<a href="chap7_mj.html#X7BFFD8B7808F5BDA"><span class="RefLink">7.2-5</span></a>) will return objects of type <code class="code">JupyterRenderable</code>, which is defined in the <strong class="pkg">JupyterKernel</strong> Package.</p>

</li>
<li><p>Such objects, when rendered in a Jupyter cell, will run a block of JavaScript contained within them, which will create the desired visualization.</p>

</li>
<li><p>Such scripts tend to request additional information from <strong class="pkg">GAP</strong> as they are running, by using calls to the JavaScript function <code class="code">Jupyter.kernel.execute</code> defined in the notebook. Such calls are typically to fetch JavaScript libraries needed to create the requested visualization.</p>

</li>
<li><p>Visualizations produced this way will not be visible if one later closes and then reopens the Jupyter notebook in which they are stored. To see the visualizations again, one must re-evaluate the cells that created them, so that the required libraries are re-fetched from the <strong class="pkg">GAP</strong> Jupyter kernel.</p>

</li>
</ul>
<p><a id="X85332D257DD44070" name="X85332D257DD44070"></a></p>

<h5>7.1-7 PlotDisplayMethod_JupyterSimple</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PlotDisplayMethod_JupyterSimple</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>This global constant can be assigned to the global variable <code class="func">PlotDisplayMethod</code> (<a href="chap7_mj.html#X81D8CBD97B9677C0"><span class="RefLink">7.1-5</span></a>) as documented above. Doing so produces the following results.</p>


<ul>
<li><p>Functions such as <code class="func">Plot</code> (<a href="chap7_mj.html#X811D60857B0B2B68"><span class="RefLink">7.1-1</span></a>), <code class="func">PlotGraph</code> (<a href="chap7_mj.html#X79FCD4E67FF49A5F"><span class="RefLink">7.1-3</span></a>), and <code class="func">CreateVisualization</code> (<a href="chap7_mj.html#X7BFFD8B7808F5BDA"><span class="RefLink">7.2-5</span></a>) will return objects of type <code class="code">JupyterRenderable</code>, which is defined in the <strong class="pkg">JupyterKernel</strong> Package.</p>

</li>
<li><p>Such objects, when rendered in a Jupyter cell, will run a block of JavaScript contained within them, which will create the desired visualization.</p>

</li>
<li><p>Such scripts will be entirely self-contained, and thus will not make any additional requests from the <strong class="pkg">GAP</strong> Jupyter kernel. This makes such objects larger because they must contain all the required JavaScript visualization libraries, rather than being able to request them as needed later.</p>

</li>
<li><p>Visualizations produced this way will be visible even if one later closes and then reopens the Jupyter notebook in which they are stored, because all the code needed to create them is included in the output cell itself, and is re-run upon re-opening the notebook.</p>

</li>
</ul>
<p><a id="X818039C5844E897B" name="X818039C5844E897B"></a></p>

<h5>7.1-8 PlotDisplayMethod_HTML</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PlotDisplayMethod_HTML</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>This global constant can be assigned to the global variable <code class="func">PlotDisplayMethod</code> (<a href="chap7_mj.html#X81D8CBD97B9677C0"><span class="RefLink">7.1-5</span></a>) as documented above. Doing so produces the following results.</p>


<ul>
<li><p>Functions such as <code class="func">Plot</code> (<a href="chap7_mj.html#X811D60857B0B2B68"><span class="RefLink">7.1-1</span></a>), <code class="func">PlotGraph</code> (<a href="chap7_mj.html#X79FCD4E67FF49A5F"><span class="RefLink">7.1-3</span></a>), and <code class="func">CreateVisualization</code> (<a href="chap7_mj.html#X7BFFD8B7808F5BDA"><span class="RefLink">7.2-5</span></a>) will return no value, but will instead store HTML (and JavaScript) code for the visualization in a temporary file on the filesystem, then launch the operating system's default web browser to view that file.



</li>
<li><p>Such files are entirely self-contained, and require no <strong class="pkg">GAP</strong> session to be running to continue viewing them. They can be saved anywhere the user likes for later viewing, printing, or sharing without <strong class="pkg">GAP</strong>.</p>

</li>
<li><p>Visualizations produced this way will not be visible if one later closes and then reopens the Jupyter notebook in which they are stored. To see the visualizations again, one must re-evaluate the cells that created them, so that the required libraries are re-fetched from the <strong class="pkg">GAP</strong> Jupyter kernel.</p>

</li>
</ul>
<p><a id="X83E0040584EAF486" name="X83E0040584EAF486"></a></p>

<h4>7.2 <span class="Heading">Low-Level Public API</span></h4>

<p><a id="X78BDA43D7E633E33" name="X78BDA43D7E633E33"></a></p>

<h5>7.2-1 RunJavaScript</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ RunJavaScript</code>( <var class="Arg">script</var>[, <var class="Arg">returnHTML</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: one of two things, documented below</p>

<p>If run in a Jupyter Notebook, this function returns an object that, when rendered by that notebook, will run the JavaScript code given in <var class="Arg">script</var>.</p>

<p>If run outside of a Jupyter Notebook, this function creates an HTML page containing the given <var class="Arg">script</var>, an HTML element on which that script can act, and the RequireJS library for importing other script tools. It then opens the page in the system default web browser (thus running the script) and returns the path to the temporary file in which the script is stored.</p>

<p>In this second case only, the optional second parameter (which defaults to false) can be set to true if the caller does not wish the function to open a web browser, but just wants the HTML content that would have been displayed in such a browser returned as a string instead.</p>

<p>When the given code is run, the varible <code class="code">element</code> will be defined in its environment, and will contain either the output element in the Jupyter notebook corresponding to the code that was just evaluated or, in the case outside of Jupyter, the HTML element mentioned above. The script is free to write to that element in both cases.</p>

<p><a id="X81E2B3A07EA7A02B" name="X81E2B3A07EA7A02B"></a></p>

<h5>7.2-2 LoadJavaScriptFile</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ LoadJavaScriptFile</code>( <var class="Arg">filename</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: the string contents of the file whose name is given</p>

<p>Interprets the given <var class="Arg">filename</var> relative to the <code class="file">lib/js/</code> path in the <strong class="pkg">JupyterViz</strong> package's installation folder, because that is where this package stores its JavaScript libraries. A .js extension will be added to filename iff needed. A .min.js extension will be added iff such a file exists, to prioritize minified versions of files.



<p>If the file has been loaded before in this <strong class="pkg">GAP</strong> session, it will not be reloaded, but will be returned from a cache in memory, for efficiency.</p>

<p>If no such file exists, returns <code class="keyw">fail</code> and caches nothing.</p>

<p><a id="X83454CD67FF0EED7" name="X83454CD67FF0EED7"></a></p>

<h5>7.2-3 InstallVisualizationTool</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ InstallVisualizationTool</code>( <var class="Arg">toolName</var>, <var class="Arg">script</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: boolean indicating success (true) or failure (false)</p>

<p>This function permits extending, at runtime, the set of JavaScript visualization tools beyond those that are built into the <strong class="pkg">JupyterViz</strong> package.</p>

<p>The first argument must be the name of the visualization tool (a string, which you will later use in the <code class="code">tool</code> field when calling <code class="func">CreateVisualization</code> (<a href="chap7_mj.html#X7BFFD8B7808F5BDA"><span class="RefLink">7.2-5</span></a>)). The second must be a string of JavaScript code that installs into <code class="code">window.VisualizationTools.TOOL_NAME_HERE</code> the function for creating visualizations using that tool. It can also define other helper functions or make calls to <code class="code">window.requirejs.config</code>. For examples of how to write such JavaScript code, see the chapter on extending this package in its manual.</p>

<p>This function returns false and does nothing if a tool of that name has already been installed. Otherwise, it installs the tool and returns true.</p>

<p>There is also a convenience method that calls this one on your behalf; see <code class="func">InstallVisualizationToolFromTemplate</code> (<a href="chap7_mj.html#X876DFB2B87FC3732"><span class="RefLink">7.2-4</span></a>).</p>

<p><a id="X876DFB2B87FC3732" name="X876DFB2B87FC3732"></a></p>

<h5>7.2-4 InstallVisualizationToolFromTemplate</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ InstallVisualizationToolFromTemplate</code>( <var class="Arg">toolName</var>, <var class="Arg">functionBody</var>[, <var class="Arg">CDNURL</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: boolean indicating success (true) or failure (false)</p>

<p>This function is a convenience function that makes it easier to use <code class="func">InstallVisualizationTool</code> (<a href="chap7_mj.html#X83454CD67FF0EED7"><span class="RefLink">7.2-3</span></a>); see the documentation for that function, then read on below for how this function makes it easier.</p>

<p>Most visualization tools do two things: First, they install a CDN URL into <code class="code">window.requirejs.config</code> for some external JavaScript library that must be loaded in the client to support the given type of visualization. Second, they install a function as <code class="code">window.VisualizationTools.TOOL_NAME_HERE</code> accepting parameters <code class="code">element</code>, <code class="code">json</code>, and <code class="code">callback</code>, and building the desired visualization inside the given DOM element. Such code often begins with a call to <code class="code">require(['...'],function(library}{/*...*/}))</code>, but not always.</p>

<p>This function will write for you the boiler plate code for calling <code class="code">window.requirejs.config</code> and the declaration and installation of a function into <code class="code">window.VisualizationTools.TOOL_NAME_HERE</code>. You provide the function body and optionally the CDN URL. (If you provide no CDN URL, then no external CDN will be installed into <code class="code">requirejs</code>.)</p>

<p><a id="X7BFFD8B7808F5BDA" name="X7BFFD8B7808F5BDA"></a></p>

<h5>7.2-5 CreateVisualization</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CreateVisualization</code>( <var class="Arg">data</var>[, <var class="Arg">code</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: one of two things, documented below</p>

<p>If run in a Jupyter Notebook, this function returns an object that, when rendered by that notebook, will produce the visualization specified by <var class="Arg">data</var> in the correspondinoutput cell, and will also run any given <var class="Arg">code</var> on that visualization.</p>

<p>If run outside of a Jupyter Notebook, this function creates an HTML page containing the visualization specified by <var class="Arg">data</var> and then opens the page in the system default web browser. It will also run any given <var class="Arg">code</var> as soon as the page opens. The <var class="Arg">data</var> must be a record that will be converted to JSON using <strong class="pkg">GAP</strong>'s json package.



<p>The second argument is optional, a string containing JavaScript <var class="Arg">code</var> to run once the visualization has been created. When that code is run, the variables <code class="code">element</code> and <code class="code">visualization</code> will be in its environment, the former holding the output element in the notebook containing the visualization, and the latter holding the visualization element itself.</p>

<p>The <var class="Arg">data</var> should have the following attributes.</p>


<ul>
<li><p><code class="code">tool</code> (required) - the name of the visualization tool to use. Currently supported tools are listed in Section <a href="chap1_mj.html#X8376A2517DEBB867"><span class="RefLink">1.2</span></a> and links to their documentation are given in Section <a href="chap3_mj.html#X860FD2F97E9F936B"><span class="RefLink">3.4</span></a>.</p>

</li>
<li><p><code class="code">data</code> (required) - subobject containing all options specific to the content of the visualization, often passed intact to the external JavaScript visualization library. You should prepare this data in the format required by the library specified in the <code class="code">tool</code> field, following the documentation for that library, linked to in Section <a href="chap3_mj.html#X860FD2F97E9F936B"><span class="RefLink">3.4</span></a>.</p>

</li>
<li><p><code class="code">width</code> (optional) - width to set on the output element being created</p>

</li>
<li><p><code class="code">height</code> (optional) - similar, but height</p>

</li>
</ul>

<div class="example"><pre>
CreateVisualization( rec(
    tool := "html",
    data := rec( html := "I am <i>SO</i> excited about this." )
), "console.log( 'Visualization created.' );" );
</pre></div>

<p><a id="X7B106BA97FD3C2BF" name="X7B106BA97FD3C2BF"></a></p>

<h4>7.3 <span class="Heading">Internal methods</span></h4>

<p>Using the convention common to <strong class="pkg">GAP</strong> packages, we prefix all methods not intended for public use with a sequence of characters that indicate our particular package. In this case, we use the <code class="code">JUPVIZ</code> prefix. This is a sort of "poor man's namespacing."</p>

<p><em>None of these methods should need to be called by a client of this package. We provide this documentation here for completeness, not out of necessity.</em></p>

<p><a id="X7FA27984822A0E5E" name="X7FA27984822A0E5E"></a></p>

<h5>7.3-1 JUPVIZAbsoluteJavaScriptFilename</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZAbsoluteJavaScriptFilename</code>( <var class="Arg">filename</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: a JavaScript filename to an absolute path in the package dir</p>

<p>Given a relative <var class="Arg">filename</var>, convert it into an absolute filename by prepending the path to the <code class="file">lib/js/</code> folder within the <strong class="pkg">JupyterViz</strong> package's installation folder. This is used by functions that need to find JavaScript files stored there.



<p>A <code class="file">.js</code> extension is appended if none is included in the given <var class="Arg">filename</var>.</p>

<p><a id="X7F877B4279081217" name="X7F877B4279081217"></a></p>

<h5>7.3-2 JUPVIZLoadedJavaScriptCache</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZLoadedJavaScriptCache</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>A cache of the contents of any JavaScript files that have been loaded from this package's folder. The existence of this cache means needing to go to the filesystem for these files only once per GAP session. This cache is used by LoadJavaScriptFile (7.2-2).



<p><a id="X84F0A3C97FBC57EE" name="X84F0A3C97FBC57EE"></a></p>

<h5>7.3-3 JUPVIZFillInJavaScriptTemplate</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZFillInJavaScriptTemplate</code>( <var class="Arg">filename</var>, <var class="Arg">dictionary</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: a string containing the contents of the given template file, filled in using the given dictionary</p>

<p>A template file is one containing identifiers that begin with a dollar sign (<code class="code">$</code>). For example, <code class="code">$one</code> and <code class="code">$two</code> are both identifiers. One "fills in" the template by replacing such identifiers with whatever text the caller associates with them.</p>

<p>This function loads the file specified by <var class="Arg">filename</var> by passing that argument directly to <code class="func">LoadJavaScriptFile</code> (<a href="chap7_mj.html#X81E2B3A07EA7A02B"><span class="RefLink">7.2-2</span></a>). If no such file exists, returns <code class="keyw">fail</code>. Otherwise, it proceed as follows.</p>

<p>For each key-value pair in the given <var class="Arg">dictionary</var>, prefix a <code class="code">$</code> onto the key, suffix a newline character onto the value, and then replace all occurrences of the new key with the new value. The resulting string is the result.</p>

<p>The newline character is included so that if any of the values in the <var class="Arg">dictionary</var> contains single-line JavaScript comment characters (<code class="code">//</code>) then they will not inadvertently affect later code in the template.</p>

<p><a id="X8603271979CCFA2A" name="X8603271979CCFA2A"></a></p>

<h5>7.3-4 JUPVIZRunJavaScriptFromTemplate</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZRunJavaScriptFromTemplate</code>( <var class="Arg">filename</var>, <var class="Arg">dictionary</var>[, <var class="Arg">returnHTML</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: the composition of <code class="func">RunJavaScript</code> (<a href="chap7_mj.html#X78BDA43D7E633E33"><span class="RefLink">7.2-1</span></a>) with <code class="func">JUPVIZFillInJavaScriptTemplate</code> (<a href="chap7_mj.html#X84F0A3C97FBC57EE"><span class="RefLink">7.3-3</span></a>)</p>

<p>This function is quite simple, and is just a convenience function. The optional third argument is passed on to RunJavaScript internally.</p>

<p><a id="X804379D07F29E905" name="X804379D07F29E905"></a></p>

<h5>7.3-5 JUPVIZRunJavaScriptUsingRunGAP</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZRunJavaScriptUsingRunGAP</code>( <var class="Arg">jsCode</var>[, <var class="Arg">returnHTML</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: an object that, if rendered in a Jupyter notebook, will run <var class="Arg">jsCode</var> as JavaScript after <code class="code">runGAP</code> has been defined</p>

<p>There is a JavaScript function called <code class="code">runGAP</code>, defined in the <code class="file">using-runGAP.js</code> file distributed with this package. That function makes it easy to make callbacks from JavaScript in a Jupyter notebook to the <strong class="pkg">GAP</strongkernel underneath that notebook. This <strong class="pkg">GAP</strong> function runs the given <var class="Arg">jsCode</var> in the notebook, but only after ensuring that <code class="code">runGAP</code> is defined globally in that notebook, so that <var class="Arg">jsCode</var> can call <code class="code">runGAP</code> as needed.</p>

<p>The optional third argument is passed on to RunJavaScript internally.</p>

<p>An example use, from JavaScript, of the <code class="code">runGAP</code> function appears at the end of Section <a href="chap4_mj.html#X85EA7D2579837F4D"><span class="RefLink">4.3</span></a>.</p>

<p><a id="X79B7692C7F543161" name="X79B7692C7F543161"></a></p>

<h5>7.3-6 JUPVIZRunJavaScriptUsingLibraries</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZRunJavaScriptUsingLibraries</code>( <var class="Arg">libraries</var>, <var class="Arg">jsCode</var>[, <var class="Arg">returnHTML</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: one of two things, documented below</p>

<p>If run in a Jupyter Notebook, this function returns an object that, when rendered by that notebook, will run <var class="Arg">jsCode</var> as JavaScript after all <var class="Arg">libraries</var> have been loaded (which typically happens asynchronously).</p>

<p>If run outside of a Jupyter Notebook, this function loads all the code for the given <var class="Arg">libraries</var> from disk and concatenates them (with checks to be sure no library is loaded twice) followed by <var class="Arg">jsCode</var>. It then calls <code class="func">RunJavaScript</code> (<a href="chap7_mj.html#X78BDA43D7E633E33"><span class="RefLink">7.2-1</span></a>) on the result, to form a web page and display it to the user.</p>

<p>There are a set of JavaScript libraries stored in the <code class="file">lib/js/</code> subfolder of this package's installation folder. Neither the Jupyter notebook nor the temporary HTML files created from the command line know, by default, about any of those libraries. Thus this function is necessary so that jsCode can assume the existence of the tools it needs to do its job.



<p>If the first parameter is given as a string instead of a list of strings, it is treated as a list of just one string.</p>

<p>The optional third argument is passed on to RunJavaScript internally.</p>


<div class="example"><pre>
JUPVIZRunJavaScriptUsingLibraries( [ "mylib.js" ],
    "alert( 'My Lib defines foo to be: ' + window.foo );" );
# Equivalently:
JUPVIZRunJavaScriptUsingLibraries( "mylib.js",
    "alert( 'My Lib defines foo to be: ' + window.foo );" );
</pre></div>

<p><a id="X8620A70785F90EE6" name="X8620A70785F90EE6"></a></p>

<h5>7.3-7 JUPVIZMakePlotDataSeries</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZMakePlotDataSeries</code>( <var class="Arg">series</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: a record with the appropriate fields (<code class="code">x</code>, <code class="code">y</code>, <code class="code">options</code>) that can be passed to one of the functions in <code class="func">ConvertDataSeriesForTool</code> (<a href="chap7_mj.html#X7B36451A873E06B2"><span class="RefLink">7.1-2</span></a>)</p>

<p>This function is called by <code class="func">Plot</code> (<a href="chap7_mj.html#X811D60857B0B2B68"><span class="RefLink">7.1-1</span></a>) to convert any of the wide variety of inputs that <code class="func">Plot</code> (<a href="chap7_mj.html#X811D60857B0B2B68"><span class="RefLink">7.1-1</span></a>) might receive into a single internal format. Then that internal format can be converted to the JSON format needed by any of the visualization tools supported by this package.</p>

<p>See the documentation for <code class="func">ConvertDataSeriesForTool</code> (<a href="chap7_mj.html#X7B36451A873E06B2"><span class="RefLink">7.1-2</span></a>) for more information on how that latter conversion takes place, and the format it expects.</p>

<p><a id="X7B5CF2DA86E91C11" name="X7B5CF2DA86E91C11"></a></p>

<h5>7.3-8 JUPVIZMakePlotGraphRecord</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZMakePlotGraphRecord</code>( <var class="Arg">various</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: a record with the appropriate fields (<code class="code">vertices</code>, <code class="code">edges</code>, <code class="code">options</code>) that can be passed to one of the functions in <code class="func">ConvertGraphForTool</code> (<a href="chap7_mj.html#X80380CBB7E1FA082"><span class="RefLink">7.1-4</span></a>)</p>

<p>This function is called by <code class="func">PlotGraph</code> (<a href="chap7_mj.html#X79FCD4E67FF49A5F"><span class="RefLink">7.1-3</span></a>) to convert any of the wide variety of inputs that <code class="func">PlotGraph</code> (<a href="chap7_mj.html#X79FCD4E67FF49A5F"><span class="RefLink">7.1-3</span></a>) might receive into a single internal format. Then that internal format can be converted to the JSON format needed by any of the visualization tools supported by this package.</p>

<p>See the documentation for <code class="func">ConvertGraphForTool</code> (<a href="chap7_mj.html#X80380CBB7E1FA082"><span class="RefLink">7.1-4</span></a>) for more information on how that latter conversion takes place, and the format it expects.</p>

<p><a id="X87B06B5C872845E9" name="X87B06B5C872845E9"></a></p>

<h5>7.3-9 JUPVIZPlotDataSeriesList</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZPlotDataSeriesList</code>( <var class="Arg">series1</var>, <var class="Arg">series2</var>, <var class="Arg">series3...</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: a <code class="code">JupyterRenderable</codeobject ready to be displayed in the Jupyter Notebook</p>

<p>Because the <code class="func">Plot</code> (<a href="chap7_mj.html#X811D60857B0B2B68"><span class="RefLink">7.1-1</span></a>) function can take a single data series or many data series as input, it detects which it received, then passes the resulting data series (as an array containing one or more series) to this function for collecting into a single plot.</p>

<p>It is not expected that clients of this package will need to call this internal function.</p>

<p><a id="X873A09F5852A33E9" name="X873A09F5852A33E9"></a></p>

<h5>7.3-10 JUPVIZRecordKeychainLookup</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZRecordKeychainLookup</code>( <var class="Arg">record</var>, <var class="Arg">keychain</var>, <var class="Arg">default</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: the result of looking up the chain of keys in the given record</p>

<p>In nested records, such as <code class="code">myRec:=rec(a:=rec(b:=5))</code>, it is common to write code such as <code class="code">myRec.a.b</code> to access the internal values. However when records are passed as parameters, and may not contain every key (as in the case when some default values should be filled in automatically), code like <code class="code">myRec.a.b</code> could cause an error. Thus we wish to first check before indexing a record that the key we're looking up exists. If not, we wish to return the value given as the default instead.



<p>This function accepts a <code class="code">record</code> (which may have other records inside it as values), an array of strings that describe a chain of keys to follow inward (<code class="code">["a","b"]</code> in the example just given), and a <code class="code">default</code> value to return if any of the keys do not exist.</p>

<p>It is not expected that clients of this package will need to call this internal function. It is used primarily to implement the <code class="func">JUPVIZFetchWithDefault</code> (<a href="chap7_mj.html#X784852877814711F"><span class="RefLink">7.3-12</span></a>) function, which is useful to those who wish to extend the <code class="func">ConvertDataSeriesForTool</code> (<a href="chap7_mj.html#X7B36451A873E06B2"><span class="RefLink">7.1-2</span></a>) and <code class="func">ConvertGraphForTool</code> (<a href="chap7_mj.html#X80380CBB7E1FA082"><span class="RefLink">7.1-4</span></a>) objects.</p>


<div class="example"><pre>
myRec := rec( height := 50, width := 50, title := rec(
  text := "GAP", fontSize := 20
) );
JUPVIZRecordKeychainLookup( myRec, [ "height" ], 10 );                # = 50
JUPVIZRecordKeychainLookup( myRec, [ "width" ], 10 );                 # = 50
JUPVIZRecordKeychainLookup( myRec, [ "depth" ], 10 );                 # = 10
JUPVIZRecordKeychainLookup( myRec, [ "title""text" ], "Title" );    # = "GAP"
JUPVIZRecordKeychainLookup( myRec, [ "title""color" ], "black" );   # = "black"
JUPVIZRecordKeychainLookup( myRec, [ "one""two""three" ], fail ); # = fail
</pre></div>

<p><a id="X7C8A5FCD7B96D5DC" name="X7C8A5FCD7B96D5DC"></a></p>

<h5>7.3-11 JUPVIZRecordsKeychainLookup</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZRecordsKeychainLookup</code>( <var class="Arg">records</var>, <var class="Arg">keychain</var>, <var class="Arg">default</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: the result of looking up the chain of keys in each of the given records until a lookup succeeds</p>

<p>This function is extremely similar to <code class="func">JUPVIZRecordKeychainLookup</code(<a href="chap7_mj.html#X873A09F5852A33E9"><span class="RefLink">7.3-10</span></a>) with the following difference: The first parameter is a list of records, and <code class="func">JUPVIZRecordKeychainLookup</code> (<a href="chap7_mj.html#X873A09F5852A33E9"><span class="RefLink">7.3-10</span></a>) is called on each in succession with the same <code class="code">keychain</code>. If any of the lookups succeeds, then its value is returned and no further searching through the list is done. If all of the lookups fail, the <code class="code">default</code> is returned.</p>

<p>It is not expected that clients of this package will need to call this internal function. It is used primarily to implement the <code class="func">JUPVIZFetchWithDefault</code> (<a href="chap7_mj.html#X784852877814711F"><span class="RefLink">7.3-12</span></a>) function, which is useful to those who wish to extend the <code class="func">ConvertDataSeriesForTool</code> (<a href="chap7_mj.html#X7B36451A873E06B2"><span class="RefLink">7.1-2</span></a>) and <code class="func">ConvertGraphForTool</code> (<a href="chap7_mj.html#X80380CBB7E1FA082"><span class="RefLink">7.1-4</span></a>) objects.</p>


<div class="example"><pre>
myRecs := [
  rec( height := 50, width := 50, title := rec(
    text := "GAP", fontSize := 20
  ) ),
  rec( width := 10, depth := 10, color := "blue" )
];
JUPVIZRecordsKeychainLookup( myRecs, [ "height" ], 0 );              # = 50
JUPVIZRecordsKeychainLookup( myRecs, [ "width" ], 0 );               # = 50
JUPVIZRecordsKeychainLookup( myRecs, [ "depth" ], 0 );               # = 10
JUPVIZRecordsKeychainLookup( myRecs, [ "title""text" ], "Title" ); # = "GAP"
JUPVIZRecordsKeychainLookup( myRecs, [ "color" ], "" );              # = "blue"
JUPVIZRecordsKeychainLookup( myRecs, [ "flavor" ], fail );           # = fail
</pre></div>

<p><a id="X784852877814711F" name="X784852877814711F"></a></p>

<h5>7.3-12 JUPVIZFetchWithDefault</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZFetchWithDefault</code>( <var class="Arg">record</var>, <var class="Arg">others</var>, <var class="Arg">chain</var>, <var class="Arg">default</var>, <var class="Arg">action</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: nothing</p>

<p>This function is designed to make it easier to write new entries in the <code class="func">ConvertDataSeriesForTool</code> (<a href="chap7_mj.html#X7B36451A873E06B2"><span class="RefLink">7.1-2</span></a>) and <code class="func">ConvertGraphForTool</code> (<a href="chap7_mj.html#X80380CBB7E1FA082"><span class="RefLink">7.1-4</span></a>) functions. Those functions are often processing a list of records (here called <code class="code">others</code>) sometimes with one record the most important one (here called <code class="code">record</code>) and looking up a <code class="code">chain</code> of keys (using <code class="code">default</code> just as in <code class="func">JUPVIZRecordKeychainLookup</code> (<a href="chap7_mj.html#X873A09F5852A33E9"><span class="RefLink">7.3-10</span></a>)) and then taking some <code class="code">action</code> based on the result. This function just allows all of that to be done with a single call.</p>

<p>Specifically, it considers the array of records formed by <code class="code">Concatenation([record],others)</code> and calls <code class="func">JUPVIZRecordsKeychainLookup</code> (<a href="chap7_mj.html#X7C8A5FCD7B96D5DC"><span class="RefLink">7.3-11</span></a>) on it with the given <code class="code">chain</code> and <code class="code">default</code>. (If the <code class="code">chain</code> is a string, it is automatically converted to a length-one list with the string inside.) Whatever the result, the function <code class="code">action</code> is called on it, even if it is the default.</p>


<div class="example"><pre>
# Trivial examples:
myRec := rec( a := 5 );
myRecs := [ rec( b := 3 ), rec( a := 6 ) ];
f := function ( x ) Print( x, "\n" ); end;
JUPVIZFetchWithDefault( myRec, myRecs, "a", 0, f );       # prints 5
JUPVIZFetchWithDefault( myRec, myRecs, "b", 0, f );       # prints 3
JUPVIZFetchWithDefault( myRec, myRecs, "c", 0, f );       # prints 0
JUPVIZFetchWithDefault( myRec, myRecs, ["a","b"], 0, f ); # prints 0
# Useful example:
JUPVIZFetchWithDefault( primaryRecord, secondaryRecordsList,
  [ "options""height" ], 400,
  function ( h ) myGraphJSON.height := h; end
);
</pre></div>

<p>See also <code class="func">JUPVIZFetchIfPresent</code> (<a href="chap7_mj.html#X856669217AADA94F"><span class="RefLink">7.3-13</span></a>).</p>

<p><a id="X856669217AADA94F" name="X856669217AADA94F"></a></p>

<h5>7.3-13 JUPVIZFetchIfPresent</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZFetchIfPresent</code>( <var class="Arg">record</var>, <var class="Arg">others</var>, <var class="Arg">chain</var>, <var class="Arg">action</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: nothing</p>

<p>This function is extremely similar to <code class="func">JUPVIZFetchWithDefault</code> (<a href="chap7_mj.html#X784852877814711F"><span class="RefLink">7.3-12</span></a>) with the following exception: No default value is provided, and thus if the lookup fails for all the records (including <code class="code">record</code> and everything in <code class="code">others</code>) then the <code class="code">action</code> is not called.</p>

<p>Examples:</p>


<div class="example"><pre>
myRec := rec( a := 5 );
myRecs := [ rec( b := 3 ), rec( a := 6 ) ];
f := function ( x ) Print( x, "\n" ); end;
JUPVIZFetchIfPresent( myRec, myRecs, "a", 0, f );       # prints 5
JUPVIZFetchIfPresent( myRec, myRecs, "b", 0, f );       # prints 3
JUPVIZFetchIfPresent( myRec, myRecs, "c", 0, f );       # does nothing
JUPVIZFetchIfPresent( myRec, myRecs, ["a","b"], 0, f ); # does nothing
</pre></div>

<p><a id="X7CB82ABE7B3255EB" name="X7CB82ABE7B3255EB"></a></p>

<h4>7.4 <span class="Heading">Representation wrapper</span></h4>

<p>This code is documented for completeness's sake only. It is not needed for clients of this package. Package maintainers may be interested in it in the future.



<p>The <strong class="pkg">JupyterKernel</strong> package defines a method <code class="code">JupyterRender</code> that determines how <strong class="pkg">GAP</strong> data will be shown to the user in the Jupyter notebook interface. When there is no method implemented for a specific data type, the fallback method uses the built-in <strong class="pkg">GAP</strong> method <code class="code">ViewString</code>.</p>

<p>This presents a problem, because we are often transmitting string data (the contents of JavaScript files) from the <strong class="pkg">GAP</strong> kernel to the notebook, and <code class="code">ViewString</code> is not careful about how it escapes characters such as quotation marks, which can seriously mangle code. Thus we must define our own type and <code class="code">JupyterRender</code> method for that type, to prevent the use of <code class="code">ViewString</code>.</p>

<p>The declarations documented below do just that. In the event that <code class="code">ViewString</code> were upgraded to more useful behavior, this workaround could probably be removed. Note that it is used explicitly in the <code class="file">using-library.js</code> file in this package.</p>

<p>If this package is loaded without the <strong class="pkg">JupyterKernel</strong> package having already been loaded, then the following functions and tools are not defined, because their definitions rely on global data made available by the <strong class="pkg">JupyterKernel</strong> package.</p>

<p><a id="X82269732822D224D" name="X82269732822D224D"></a></p>

<h5>7.4-1 JUPVIZIsFileContents</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZIsFileContents</code>( <var class="Arg">arg</var> )</td><td class="tdright">( filter )</td></tr></table></div>
<p>Returns: <code class="code">true</code> or <code class="code">false</code></p>

<p>The type we create is called <code class="code">FileContents</code>, because that is our purpose for it (to preserve, unaltered, the contents of a text file).</p>

<p><a id="X84D70ACD7A72AA84" name="X84D70ACD7A72AA84"></a></p>

<h5>7.4-2 JUPVIZIsFileContentsRep</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZIsFileContentsRep</code>( <var class="Arg">arg</var> )</td><td class="tdright">( filter )</td></tr></table></div>
<p>Returns: <code class="code">true</code> or <code class="code">false</code></p>

<p>The representation for the <code class="code">FileContents</code> type</p>

<p><a id="X7D401DB582A5EBA2" name="X7D401DB582A5EBA2"></a></p>

<h5>7.4-3 JUPVIZFileContents</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JUPVIZFileContents</code>( <var class="Arg">arg</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>A constructor for <code class="code">FileContents</code> objects</p>

<p>Elsewhere, the <strong class="pkg">JupyterViz</strong> package also installs a <code class="code">JupyterRender</code> method for <code class="code">FileContents</code> objects that just returns their text content untouched.</p>


<div class="chlinkprevnextbot"> <a href="chap0_mj.html">[Top of Book]</a>   <a href="chap0_mj.html#contents">[Contents]</a>    <a href="chap6_mj.html">[Previous Chapter]</a>    <a href="chapInd_mj.html">[Next Chapter]</a>   </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a>  <a href="chap1_mj.html">1</a>  <a href="chap2_mj.html">2</a>  <a href="chap3_mj.html">3</a>  <a href="chap4_mj.html">4</a>  <a href="chap5_mj.html">5</a>  <a href="chap6_mj.html">6</a>  <a href="chap7_mj.html">7</a>  <a href="chapInd_mj.html">Ind</a>  </div>

<hr />
<p class="foot">generated by <a href="http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>

Messung V0.5
C=95 H=99 G=96

¤ Dauer der Verarbeitung: 0.21 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.