Skip to content

Sigma JSON Writer

Daniel Kramp edited this page Aug 11, 2017 · 1 revision

Purpose

The file include/SigmaJSONWriter.h serves two functions: initially positioning the nodes on screen, and sending simulation data in JSON format to the cache. The following two methods are called from VASimVis.cc to achieve these purposes:

writeToJSON(Automata *a)

This method creates a JSON file to send to JavaScript that represents the automata as a graph on screen. It assigns an x and y position to every STE (see below for details) and sends its ID along with some data to be represented visually to the user.

The method calls a separate recursive function on all of the start STEs in order to place all of the children called positionChildren. The placement algorithm essentially works in this way (x increases to the right, y increases down):

  1. Start with an x and y position of (0,0) on the first start STE.
  2. Traverse down through its children, maintaining its x and increasing its y by 30 each level until it finds the leftmost child with no children. That child is placed at the current x and y position.
  3. Place all of its sibling nodes as close as possible, increasing x by 1 for each child at the same y level.
  4. Place its parent node halfway between its leftmost and rightmost child.
  5. Nodes are marked when visited for the first time as to not be placed again if it is the child of another parent.

This is done recursively to create essentially a tree layout in which a parent is centered above its children and no nodes overlap. Connections crossing becomes an onscreen issue when a graph is optimized but still functions properly. Basically, these rules are followed when placing nodes:

  • All nodes are on y levels that are multiples of 30, with start nodes being on level 0 (the highest).
  • A parent is centered between its leftmost and rightmost children. Nodes with one child are directly above that child.
  • The leftmost descendant of an nodes's immediate right sibling is 1 to the right of the node's rightmost descendant.

simulateStep(Automata *a, char symbol)

This method simulates the automata on this character and converts its activity data to JSON to load the cache with. Essentially, it prioritizes reporting STEs, then activated STEs, then enabled (since there are duplicates in each data structure). The data is compiled into one JSON object that contains the ID, activity type, and count (for heatmap) for all STEs with activity on that cycle. This method is run 100 times at once when loading the cache, and all 100 cycles are sent from the main C++ code to JavaScript to be stored in the cache.

Clone this wiki locally