# visualize(Poset) -- visualizes a poset in the browser

## Synopsis

• Function: visualize
• Optional inputs:
• FixExtremeElements => ..., default value false, an option to fix extreme elements of a poset
• Verbose => ..., default value false, an to view communication between Macaulay2 server and browser
• VisPath => ..., default value null, an option to define a path to save visualizations of Posets
• VisTemplate => ..., default value /usr/share/Macaulay2/Visualize/templates/visPoset/visPoset-template.html, an option defining the template path
• Warning => ..., default value true, an option to squelch warnings

## Description

Using JavaScript, this method creates an interactive visualization of a poset in a modern browser. While viewing the poset, the user has the ability to manipulate and run various tests. Once finished, the user can export the finished result back to the Macaulay2 session.

The workflow for this package is as follows. Once we have loaded the package, we first open a port with openPort for Macaulay2 to communicate with the browser. Once a port is established, define an object to visualize. In this example we could use the command openPort"8080" before or after we define the following poset.

 i1 : P = poset {{1,2},{2,3},{3,4},{5,6},{6,7},{3,6}} o1 = P o1 : Poset

At this point we wish to visualize P. To do this simply execute H = visualize P and browser will open with interactive image. You can view this image in the link below.

Visualize Posets example

Once finished with a session, you can keep visualizing. For example if you were to say H = visualize P, once you ended the session, the last poset on the screen would be assigned to H. After running various computations on this poset, you can then visualize it once more with the visualize method. You can keep using this method until the port is closed with closePort or Macaulay2 is restarted.

## Browser Menu Options

On the side of the browser will be several options to interact with the poset using the Posets package. Below is a brief overview of the options.

• Force Variables: The 'charge' slider will force the vertices to repel or attract each other while the 'links' slider increases and decreases the length of the edges.

• Enable Editing: In the browser, you can edit the poset (add/delete vertices or edges) by clicking Enable Editing. For example, in order to remove the edge {1,2}, click on 'Enable Editing' and select the edge and press delete on the keyboard. When deleting an edge, the minimal covering relations and visual display are automatically updated to reflect the new poset structure. You may also add vertices and edges with the mouse/trackpad. When adding a new edge (relation), you must drag from the smaller vertex in the relation to the larger vertex. Each time a new edge is added, a check is performed to determine whether the new edge would violate antisymmetry, and if so then an alert is displayed. Also, each time a new edge is added, the transitive closure is computed, the rank/height of each poset element is recomputed, and the visual display of the poset is updated. When editing is enabled, you can move the vertices around by holding down the shift key.

• Hide Labels: Removes the labels from the vertices.

• Highlight comparable elements: Allows you to see the comparable elements when a vertex is selected.

• Fix extremal nodes: Forces extremal nodes to be placed at the top and bottom of the image.

• Reset Nodes: When you move a vertex, it will pin it to the canvas. If you have pinned a node to the canvas, you can undo this process by reseting the nodes. Clicking this will reset all nodes.

• Turn off force: The force is what creates the charges on the nodes. Turning this off will make the vertices not repel each other.

• Generate TikZ code: Clicking this will generate the TikZ code for a black and white version of the poset that is being viewed. You will then have to copy this to the clipboard by clicking a new button. The TeX file will only need '\usepackage{tikz}' in the preamble. If you decide you want to modify the poset, feel free. All you need do in order to get a new TikZ code is click on 'Generate TikZ code' once more, and then click the button. This button will look the same, but it will be a new code.

• Boolean tests: Clicking this will pull up a submenu of boolean tests supported by the Posets package. Clicking on these tests will send a request to Macaulay2 to calculate the answer for the current poset on the screen. Warning: If your poset is too large, clicking a menu item could take a very long time. In order to cancel the process you need to kill the session of Macaulay2 with 'Ctrl+c+c' in the instance of Macaulay2.

• Numerical invariants: Clicking this will pull up a submenu of numerical invariants supported by the Posets package. Clicking on these will send a request to Macaulay2 to calculate the answer for the current poset on the screen. Warning: If your poset is too large, clicking a menu item could take a very long time. In order to cancel the process you need to kill the session of Macaulay2 with 'Ctrl+c+c' in the instance of Macaulay2.

• End session: When you are finished editing, you can end the session and send the current poset to Macaulay2. The output of visualize P is the poset on the screen when end session is clicked.

## Caveat

When the poset is exported back to Macaulay2 after ending the visualization session, all vertices are represented as strings. To recover the values of these labels (for example, if they have numeric values or represent ring variables), use the command poset(value toString vertices P,value toString coveringRelations P).