Insight Maker API

Functions to manipulate Insight Maker models.

Introduction

The following is a set of API functions for Insight Maker.  JavaScript is the language used for these interfaces.  In addition to the Insight Maker specific functions listed here, standard JavaScript is also supported in buttons.

There are three primary avenues for making use of this API.

  • For the “Action” of Buttons embedded within models.
  • For a parent page to manipulate an embedded IFRAME containing an Insight Maker model.
  • Using the JavaScript console of the web browser to manipulate a model.  To find the built-in JavaScript console for a web browser, see the relevant browser’s documentation.

Primitive Types

A number of the API function refer to primitives by their type.  The following are the valid types.  Types are usually quoted when used and should always be capitalized (e.g.  “Stock”).

  • Stock
  • Variable
  • Converter
  • Flow
  • Link
  • Text
  • Picture
  • Folder
  • Button
  • Ghost

Examples

The following examples illustrate the usage of the API for certain scenarios.

Using Dialogs

Ask the user to specify a URL and opens a new web page at the location.

showURL(showPrompt("What page should I open?"));

Expanding and Collapsing Folders

This example expands all the folders in the model.

expandFolder(findType("Folder"));

And this collapses them.

collapseFolder(findType("Folder"));

Notes

Show the notes for all flow and link primitives in the model.

var connectors = findType(["Flow", "Link"]);
showNote(connectors);

Using Opacity

Makes the currently selected primitives partially transparent.

setOpacity(getSelected(), 50);

Rabbit Birth Rate

This example will work with the default Insight Maker model.  It prompts the user to specify the birth rate for the rabbit population.  It then sets the relevant primitive to that value and runs the model.

var birthRate = showPrompt("Enter the birth rate for the rabbits:", 0.1);
var birthPrimitive = findName("Rabbit Birth Rate");
setValue(birthPrimitive, birthRate);
runModel();

This could also be written more compactly as

setValue(findName("Rabbit Birth Rate"), showPrompt("Enter the birth rate for the rabbits:", 0.1));
runModel();

Building a Model

This example creates a new model with two stocks connected by a flow.

clearModel();

var source = createPrimitive("Source", "Stock", [100, 50], [140, 50]);
setValue(source, 100); //Give the source an initial value of 100

var sink = createPrimitive("Sink", "Stock", [100, 300], [140, 50]);

var myFlow = createConnector("Leakage", "Flow", source, sink);
setValue(myFlow, "0.1*[Source]"); //10% of the source's volume moves to the sink each time period

Manipulating a Model in an IFRAME

To access the API of an embedded IFRAME, first give the IFRAME an “id” property.  This is not added by default in Insight Maker.  For instance change

<IFRAME SRC="...

to

<IFRAME ID="InsightMakerModel1" SRC="...

Then from the parent page you can use the following JavaScript syntax to call API functions.  This example calls the API’s clearModel function.

document.getElementById('InsightMakerModel1').contentWindow.postMessage("clearModel()", "*");
Summary
Insight Maker APIFunctions to manipulate Insight Maker models.
Dialogs and User Input
showMessageShows a message in a dialog window.
showPromptShows a prompt in a dialog window and provides a text input for the user to enter a value.
showChoiceShows a prompt in a dialog window and provides the user the option to click “OK” or “Cancel”.
showURLCreates a new web browser window and sets the URL.
downloadFileDownloads a file.
showDataCreates a display to showcase data.
frontWindowGets the front-most window (if one exists).
closeAllWindowsCloses all open windows.
openFilePrompts the user to select one or more files on their computer.
General Model Functions
runModelRuns a simulation and optionally returns the results.
saveModelSaves the model.
clearModelRemoves all primitives from the model.
layoutModelReorganizes the primitives in the model according to an algorithm.
setZoomSets the scale of the diagram display.
Simulation Settings
getTimeStepGets the time step used in the simulation.
setTimeStepSets the time step used in the simulation.
getTimeStartGets the start time for the simulation.
setTimeStartSets the start time for the simulation.
getTimeLengthGets the length of the simulation.
setTimeLengthSets the length of the simulation.
getPauseIntervalGets the intervals at which to pause the simulation.
setPauseIntervalSets the intervals at which to pause the simulation.
getTimeUnitsGets the time units of the simulation.
setTimeUnitsSets the time units of the simulation.
getAlgorithmGets the algorithm for the simulation.
setAlgorithmSets the algorithm of the simulation.
getMacrosGets the macros for the insight.
setMacrosSets the macros of the insight.
Finding and Accessing Specific Primitives
findNameFinds and returns a primitive by its name.
findAllFinds and returns all primitives in the model.
findTypeFinds and returns all primitives of a specific type.
findIDFinds and returns a primitive using its ID.
findValueFinds and returns all primitives whose values match a regular expression.
findNoteFinds and returns all primitives whose notes match a regular expression.
Create and Delete Primitives
createPrimitiveCreates a new primitive and adds it to the model.
createConnectorCreates a new connector primitive and adds it to the model.
removePrimitiveRemoves a primitive from the model.
Primitive Selections
highlightHighlights a single primitive.
getSelectedFinds and returns the currently selected primitives.
setSelectedSets the currently selected primitives.
isSelectedIndicates whether a primitive is selected.
General Primitive Functions
getIDGets the ID of the passed primitive.
getTypeGets the type of the passed primitive.
getNameGets the name of the passed primitive.
setNameSets the name of the passed primitive.
getUnitsGets the units of the passed primitive.
setUnitsSets the units of the passed primitive.
getConstraintsGets the upper and lower bounds on the passed primitive to test against during simulation.
setConstraintsSets the upper and lower bounds on the passed primitive to test against during simulation.
getNoteGets the note of the passed primitive.
setNoteSets the note of the passed primitive.
showNoteShows the note for the passed primitive.
hideNoteHides the note for the passed primitive.
showEditorShows the value editor for the passed primitive.
getValueGets the value of the passed primitive.
setValueSets the value of the passed primitive.
getSizeGets the size of the passed primitive.
getPositionGets the position of the passed primitive.
setPositionSets the position of the passed primitive.
Primitive Styling Functions
flashTemporarily changes the opacity of a primitive.
getShowSliderGets the show slider property of the passed primitive.
setShowSliderSets the show slider property of the passed primitive.
getSliderMinGets the slider min property of the passed primitive.
setSliderMinSets the slider min property of the passed primitive.
getSliderMaxGets the slider max property of the passed primitive.
setSliderMaxSets the slider max property of the passed primitive.
getSliderStepGets the slider step property of the passed primitive.
setSliderStepSets the slider step property of the passed primitive.
getOpacityGets the opacity of the passed primitive.
setOpacitySets the opacity of the passed primitive.
getLineColorGets the line color of the passed primitive.
setLineColorSets the line color of the passed primitive.
getFontColorGets the font color of the passed primitive.
setFontColorSets the font color of the passed primitive.
getFillColorGets the fill color of the passed primitive.
setFillColorSets the fill color of the passed primitive.
getImageGets the image of the passed primitive.
setImageSets the image of the passed primitive.
Stocks
getNonNegativeGets the non-negative property of stocks (also applicable to flows).
setNonNegativeSets the non-negative value of the passed stocks (also applicable to flows).
getStockTypeGets the type of the stock.
setStockTypeSets the type of the passed stock.
getDelayGets the delay length of conveyor stocks.
setDelaySets the delay length of the passed conveyor stock.
ConnectorsSee getNonNegative and setNonNegative for setting the only-positive property of flows.
getEndsGets the alpha and omega for the connector
setEndsSets the alpha and omega for a connector.
connectedDetermines two primitives are connected by a link, flow, or transition.
States
getResidencyGets the residency property of a state primitive.
setResidencySets the residency property of a state primitive.
Transitions and Actions
getTriggerTypeGets the trigger type of a transition or action.
setTriggerTypeSets the trigger type for a transition or action.
getTriggerValueGets the trigger value equation of a transition or action.
setTriggerValueSets the trigger value for a transition or action.
getTriggerRepeatGets the trigger Repeat property of a transition or action.
setTriggerRepeatSets the trigger Repeat property for a transition or action.
getTriggerRecalculateGets the trigger Recalculate property of a transition or action.
setTriggerRecalculateSets the trigger Recalculate property for a transition or action.
Converters
getDataGets the data of a converter.
setDataSets the data of a converter.
getConverterInputGets the input source of a converter.
setConverterInputSets the input source of a converter.
getInterpolationGets the interpolation mode of a converter.
setInterpolationSets the interpolation mode of a converter.
Buttons
pressButtonSimulates a press of the passed button(s) firing its action.
Agents
getPopulationSizeGets the size of the agent population.
setPopulationSizeSets the size of the agent population.
getAgentBaseGets the base agent for the population.
setAgentBaseSets the base agent for the population.
getGeometryWrapWhether the geometry should wrap across edges.
setGeometryWrapSets the wrap property for the population area geometry.
getGeometryUnitsGets the units for the population area geometry.
setGeometryUnitsSets the units for the population area geometry.
getGeometryWidthGets the width for the population area geometry.
setGeometryWidthSets the width for the population area geometry.
getGeometryHeightGets the height for the population area geometry.
setGeometryHeightSets the height for the population area geometry.
getAgentPlacementThe placement method for the agent population.
setAgentPlacementSets the placement method for the agent population.
getAgentPlacementFunctionA custom placement function for the agent population.
setAgentPlacementFunctionSets the custom placement function for the agent population.
getAgentNetworkThe network method for the agent population.
setAgentNetworkSets the network method for the agent population.
getAgentNetworkFunctionA custom network function for the agent population.
setAgentNetworkFunctionSets the custom network function for the agent population.
Folders
collapseFolderCollapses a folder or an array of folders.
expandFolderExpands a folder or an array of folders.
getCollapsedReturns whether or not a given folder is collapsed.
getParentGets the parent folder for a primitive.
setParentSets the parent folder for a primitive.
getFrozenGets the frozen state for a primitive.
setFrozenSets the frozen state for a primitive.
getChildrenReturns the children of a folder.
getFolderTypeGets the type of a folder.
setFolderTypeSets the type of a folder.
getFolderAgentParentGets the agent parent of a folder.
setFolderAgentParentSets the agent parent of a folder.
getFolderSolver
setFolderSolverSets the solver object for a folder
Utility Functions
excludeTypeRemoves a specific type of primitive from an array of primitives.
primitiveIndexLocates the index of a specific primitive in an array of primitives.
uniquePrimitivesReturns the passed array with duplicated primitives removed
setGlobalSets the value of a global variable.
getGlobalGets the value of a global variable.
Insight Maker Interface
topBarShownDetermines whether or not the Insight Maker top toolbar (which contains the Run Simulation button and other tools) is currently shown.
toggleTopBarToggles the visibility of the top toolbar.
sideBarShownDetermines whether or not the Insight Maker side panel (which contains parameter sliders and information about the selected primitive) is currently shown.
toggleSideBarToggles the visibility of the side panel.
updateSideBarRefreshes the values in the side panel to reflect any changes in the model.

Dialogs and User Input

showMessage

function showMessage(message)

Shows a message in a dialog window.

Parameters

messageThe string to show as the message.

See also

showPrompt, showChoice

showPrompt

function showPrompt(message,
defaultValue)

Shows a prompt in a dialog window and provides a text input for the user to enter a value.

Parameters

messageThe string to show as the prompt.
defaultValueThe default value for the prompt.  This parameter is optional.

Returns

The value entered by the user.

See also

showMessage, showChoice

showChoice

function showChoice(message)

Shows a prompt in a dialog window and provides the user the option to click “OK” or “Cancel”.  Returns the value the user clicked as a boolean.

Parameters

messageThe string to show as the prompt.

Returns

The value of the button clicked by the user as a boolean.  “OK” is true, “Cancel” is false.

See also

showMessage, showPrompt

showURL

function showURL(url)

Creates a new web browser window and sets the URL.

Parameters

urlThe URL to show.

downloadFile

function downloadFile(fileName,
data,
type)

Downloads a file.

Parameters

fileNameThe name of the file to download
dataThe data to download
typeThe type of file

showData

function showData(title,
tabs,
size)

Creates a display to showcase data.  Multiple tabs of data may be shown.  This function is passed an array of objects each representing an individual tab.

Parameters

titleThe title for the data window
tabsAn array of tab objects
sizeThe dimensions of the window in the form [width, height] (optional)

Tab Objects

Each tab object contains several properties.

nameThe name of the tab
typeThe tab type.  E.g.  “text”, “HTML”, “table” or “chart”
dataThe data for the tab

The different types of tabs are as follows.

Text Tab

A text tab displays a large amount of text.  For a text tab, the data property should be the text string that will be displayed.

HTML Tab

An HTML tab displays HTML content.  For an HTML tab, the data property should be the HTML content that will be displayed.

Table Tab

A table tab displays a grid of data.  For a table tab, the data object should be an array of arrays.  Each inner array represents a column in the resulting table.  The following property is also supported for tables.

headerFor a table, an array containing the titles of the columns (optional)

Returns

The window object that was created.

Example

showData("Sample Data",
 [
 {name: "I'm a Text Tab",
  type: "text",
  data: "This is a long data string..."
  },
 {name: "I'm an HTML Tab",
  type: "html",
  data: "<center><p>This is <b>HTML</b> content.</p></center>"
  },
 {name: "Here's a Grid",
  type: "table",
  data: [[1,2,3,4],[1,4,9,16]],
  header: ["Value", "Value^2"]
  }
 ]
)

frontWindow

function frontWindow()

Gets the front-most window (if one exists).

Returns

A window object.

closeAllWindows

function closeAllWindows()

Closes all open windows.

openFile

function openFile(config)

Prompts the user to select one or more files on their computer.  Information about the selected files are made available and the contents of the files are optionally read into memory.

Note that this function needs to be called as a direct result of user actions (such as the user clicking on a button).  Browser security restrictions will prevent the function from operating if it is not called in response a user actions.  Note also that this function is not supported on Internet Explorer 9.

Parameters

configA configuration object with the following optional properties:
multipleIf false, only a single file may be selected; if true, one or more files may be selected at a time.
acceptA string containing a MIME file type to filter file selection.  If defined, only files matching the specified type may be selected.  For example, “image/*” may be used to only accept image files.
readIf defined the selected files will be opened and their contents loaded.  Read may either be “binary” in which case the contents is loaded as a binary string, “text” in which case the contents is loaded as a regular text string, or “xlsx” in which case an Excel file is loaded as an object.
onCompletedA function to handle results.  The openFile function is asynchronous.  Once it completes, the callback function is called with the resulting data as a parameter.
onErrorA function to handle the occurrence of an error.
onSelectedA function fired once files have been selected but before data has been read.

Returns

The openFile function is asynchronous and returns nothing directly.  On the successful selection of files, the callback is called with the results.

If config.multiple is false, these results are a single file object.  If config.multiple is true, then these results are an array of file objects.  Each file object has the following properties

fileThe original file object.
nameThe name of the selected file.
typeThe type of the selected file.
sizeThe size of the selected file.
contentsIf config.read is true, the contents in the file is loaded with the specified type.

Examples

// Select a single text file and display its contents
openFile({
   read: "text",
   multiple: false,
   onCompleted: function(result){
       alert(result.contents);
   }
});

General Model Functions

runModel

function runModel(config)

Runs a simulation and optionally returns the results.

Parameters

configA configuration object.  For compatibility, if set to the Boolean value, equivalent to calling runModel with a configuration object with the silent property set to the boolean value.
config.silentIf false or undefined, behaves the same way as if the user clicked the run simulation button.  If true, no visible response is shown to running the simulation and the results of the simulation are returned as an object.
config.selectedDisplayThe selected tab in the display, should be a display primitive.
config.rateA multiplier to control the speed of the animation in the result window.  Use -1 to skip animation.
config.onSuccess(results)Callback called when the simulation completes successfully.
config.onError(results)Callback called when an error occurs during the simulation.
config.onPause(results)Callback called when the simulation is paused.  If this is set and a pause interval is defined for the model, then the simulation will be asynchronous and a results object will not be returned directly by the function call.

Returns

If silent is true, returns the simulation results as a results object.  If callbacks are defined, the callbacks are called with a results object.  This object contains the following properties.

timesThe times for each period of the simulation as an array.
value(primitive)A function that takes a primitive reference and returns an array of the values that primitive took on over the course of the simulation.
lastValue(primitive)A function that takes a primitive reference and returns the last value of the primitive during the simulation.
windowThe results window object (if config.silent is false).
error”none” if no simulation error occurred, otherwise an error message.
errorPrimitiveThe primitive that caused the error.
resume()If the simulation was paused, this function may be called to resume the simulation.  Please note that Insight Maker currently only supports running a single simulation at a time.  When a new simulation is started, any currently paused simulations will be terminated immediately.
setValue(primitive, value)If the simulation is paused, allows changing the value of a primitive.  Value can be any equation that does not depend on the model state.  E.g.  “{Cows: 1, Sheep: 2} * 2” is a valid Value, but “[Other Primitive] + 1” is not.
stochasticTrue if the simulation contained an element of randomness.

Examples

# Runs a simulation, and displays the average value of the Stock named "Rabbits"
runModel({
  onSuccess: function(results){
     var sum = 0;
     for(var i = 0; i < results.times.length; i++){
         sum += results.value(findName("Rabbits"))[i];
     }
     showMessage("The average value is: " + sum/results.times.length);
  }
})
# Create interactive run of the model where the primitive "Rate" is adjusted each pause interval
runModel({
  silent: true,
  onPause: function(results){
      console.log("Simulation Step");
      results.setValue(findName("Rate"), prompt("Enter New 'Rate' Value"));
      results.resume();
  },
  onSuccess: function(results){
      console.log("Simulation Done");
      console.log(results);
  },
  onError: function(){
      alert("A simulation error occurred.");
  }
});

saveModel

function saveModel(dialog)

Saves the model.

Parameters

dialogPass true to show the properties dialog (e.g. name, description, tags).  The dialog is always shown if this is the first save.

clearModel

function clearModel()

Removes all primitives from the model.

layoutModel

function layoutModel(algorithm)

Reorganizes the primitives in the model according to an algorithm.

Parameters

algorithmThe algorithm used to calculate the new positions of the primitive.  Either “organic” or “circular”.

setZoom

function setZoom(scale)

Sets the scale of the diagram display.

Parameters

scaleThe diagram scale.  If this is a number, then it determine the scale level.  1 means 100%, 0.5 means 50%, 2 means 200% and so on.  You also pass one of the following strings: “fit” to fit the model to the diagram area, “actual” to reset the scale, “in” to zoom further in based on the current scale, and “out” to further out based on the current scale.

Simulation Settings

getTimeStep

function getTimeStep()

Gets the time step used in the simulation.

Returns

The time step for the simulation as a floating point number.

See also

setTimeStep

setTimeStep

function setTimeStep(timeStep)

Sets the time step used in the simulation.

Parameters

timeStepThe time step to be used in the simulation.

See also

getTimeStep

getTimeStart

function getTimeStart()

Gets the start time for the simulation.

Returns

The start time for the simulation as a floating point number.

See also

setTimeStart

setTimeStart

function setTimeStart(timeStart)

Sets the start time for the simulation.

Parameters

timeStartThe start time for the simulation.

See also

getTimeStart

getTimeLength

function getTimeLength()

Gets the length of the simulation.

Returns

The length of the simulation as a floating point number.

See also

setTimeLength

setTimeLength

function setTimeLength(timeLength)

Sets the length of the simulation.

Parameters

timeLengthThe length of the simulation.

See also

getTimeLength

getPauseInterval

function getPauseInterval()

Gets the intervals at which to pause the simulation.

Returns

The pause interval as a floating point number.  Returns undefined if a pause interval has not been specified.

See also

setPauseInterval

setPauseInterval

function setPauseInterval(pauseInterval)

Sets the intervals at which to pause the simulation.

Parameters

pauseIntervalThe pause interval for the simulation.

See also

setPauseInterval

getTimeUnits

function getTimeUnits()

Gets the time units of the simulation.

Returns

The time units of the simulation (e.g.  “Seconds”, “Minutes”, “Days”, “Years”).

See also

setTimeUnits

setTimeUnits

function setTimeUnits(units)

Sets the time units of the simulation.

Parameters

unitsThe time units of the simulation (e.g.  “Seconds”, “Minutes”, “Days”, “Years”).

See also

getTimeUnits

getAlgorithm

function getAlgorithm()

Gets the algorithm for the simulation.

Returns

The algorithm for the simulation as a string.  “RK1” indicates Euler’s method.  “RK4” indicates a 4th order Runge-Kutta method.

See also

setAlgorithm

setAlgorithm

function setAlgorithm(algorithm)

Sets the algorithm of the simulation.

Parameters

algorithmThe algorithm for the simulation.  “RK1” indicates Euler’s method.  “RK4” indicates a 4th order Runge-Kutta method.

See also

getAlgorithm

getMacros

function getMacros()

Gets the macros for the insight.

Returns

The macros for the insight as a string.

See also

setMacros

setMacros

function setMacros(macros)

Sets the macros of the insight.

Parameters

macrosThe macros for the insight.

See also

getMacros

Finding and Accessing Specific Primitives

findName

function findName(name)

Finds and returns a primitive by its name.  If more than one primitive with the same name exists, returns an array of primitives.

Parameters

nameThe name of the primitive to return as a string.  Also accepts an array of strings in which case all the primitives named in the array will be returned.

Return

A primitive.  If multiple primitives exist with the same name, an array of primitives will be returned.  Returns null if no primitives are found.

See also

findType, findAll, findID, findNote, findValue

findAll

function findAll()

Finds and returns all primitives in the model.

Return

An array of primitives.

See also

findName, findType, findID, findNote, findValue

findType

function findType(type)

Finds and returns all primitives of a specific type.

Parameters

typeThe type of primitives to return.  For instance: “Stock”, “Flow”, “Link”, “Text”, “Button”, “Picture”, “Converter” or “Variable”.  An array of type strings may also be passed.

Return

An array of primitives of the specified type.

See also

findName, findAll, findID, findNote, findValue

findID

function findID(id)

Finds and returns a primitive using its ID.

Parameters

IDThe ID of the primitive to find.  May also be an array of IDs.

Return

A primitive.  If an array of IDs was passed, returns an array of primitives.

See also

findName, findType, findAll, findValue, findNote, getID

findValue

function findValue(search)

Finds and returns all primitives whose values match a regular expression.

Parameters

searchThe regular expression to search for.  Can also be a string in which case the primitive values will be tested for strict case-sensitive equality against the string.  May also be an array of regular expressions and strings in which case any primitive with a value that matches one element of the array will be returned.

Return

An array of primitives whose values match the regular expression.  Returns an empty array if no primitives match.

Example

// Returns all primitives that use the log function
var containingLog = findValue(/log\(/i);

// Returns all primitives whose value is strictly "1"
var isOne = findValue("1");

See also

findName, findType, findAll, findNote, getID

findNote

function findNote(search)

Finds and returns all primitives whose notes match a regular expression.

Parameters

searchThe regular expression to search for.  Can also be a string in which case the primitive notes will be tested for strict case-sensitive equality against the string.  May also be an array of regular expressions and strings in which case any primitive with a note that matches one element of the array will be returned.

Return

An array of primitives whose notes match the regular expression.  Returns an empty array if no primitives match.

See also

findName, findType, findAll, findValue, getID

Create and Delete Primitives

createPrimitive

function createPrimitive(name,
type,
position,
size)

Creates a new primitive and adds it to the model.  This function is only for node-type primitives not connectors (e.g. flows or links).

Parameters

nameThe name of the primitive to add.
typeThe type of the primitive to add.  For example, “Variable” or “Stock”.
positionThe location of the upper-left corner of the primitive in the form: [x, y].
sizeThe dimensions of the primitive in the form: [width, height].

Return

The newly created primitive.

See also

createConnector, removePrimitive

createConnector

function createConnector(name,
type,
alpha,
omega)

Creates a new connector primitive and adds it to the model.

Parameters

nameThe name of the primitive to add.
typeThe type of the primitive to add: “Link” or “Flow”.
alphaThe primitive that will be at the start of the connector.
omegaThe primitive that will be at the end of the connector.

Return

The newly created connector primitive.

See also

createPrimitive, removePrimitive

removePrimitive

function removePrimitive(primitive)

Removes a primitive from the model.  You should not attempt to access or modify a primitive once it has been removed.

Parameters

primitiveThe primitive to delete, can also be an array of primitives.

See also

createPrimitive, createConnector

Primitive Selections

highlight

function highlight(primitive)

Highlights a single primitive.  Selects the primitive, expands any collapsed folders the primitive is in, and scrolls to the position of the primitive.

Parameters

primitiveThe primitive to highlight.

getSelected

function getSelected()

Finds and returns the currently selected primitives.

Return

An array of the selected primitives.

See also

setSelected, isSelected

setSelected

function setSelected(primitives)

Sets the currently selected primitives.

Parameters

primitivesAn array of primitives to select.  Can also be a single primitive.

See also

getSelected, isSelected

isSelected

function isSelected(primitive)

Indicates whether a primitive is selected.

Parameters

primitiveA primitive to return the selection status for.  May also be an array of primitives.

Return

Whether the primitive is selected or not as a boolean.  If an array of primitives was passed to the function, an array of booleans is returned.

See also

getSelected, setSelected

General Primitive Functions

getID

function getID(primitive)

Gets the ID of the passed primitive.  The ID remains constant even if the name of a primitive changes.  The ID is a string.

Parameters

primitiveThe primitive for which the ID is requested.  May also be an array of primitives.

Return

The ID of the primitive as a string.  If an array of primitives was passed, returns an array of IDs.

See also

findID

getType

function getType(primitive)

Gets the type of the passed primitive.

Parameters

primitiveThe primitive for which the type is requested.  May also be an array of primitives.

Return

The type of the primitive as a string.  If an array of primitives was passed, returns an array of IDs.

getName

function getName(primitive)

Gets the name of the passed primitive.

Parameters

primitiveThe primitive for which the name is requested.  May also be an array of primitives.

Return

The name of the primitive as a string.  If an array of primitives was passed, returns an array of names.

See also

setName

setName

function setName(primitive,
name)

Sets the name of the passed primitive.

Parameters

primitiveThe primitive for which the name will be set.  May also be an array of primitives in which case they will all be set to the same name.
nameThe new name for the primitive.

See also

getName

getUnits

function getUnits(primitive)

Gets the units of the passed primitive.

Parameters

primitiveThe primitive for which the units are requested.  May also be an array of primitives.

Return

The units of the primitive as a string.  If an array of primitives was passed, returns an array of units.

See also

setUnits

setUnits

function setUnits(primitive,
units)

Sets the units of the passed primitive.

Parameters

primitiveThe primitive for which the units will be set.  May also be an array of primitives in which case they will all be set to the same units.
unitsThe new units for the primitive.

See also

getUnits

getConstraints

function getConstraints(primitive)

Gets the upper and lower bounds on the passed primitive to test against during simulation.

Parameters

primitiveThe primitive for which the constraints are requested.  May also be an array of primitives.

Return

The constraints of the primitive as an array.  The format is [MinimumConstraint, MinimumConstraintMode, MaximumConstraint, MaximumConstraintMode].  Constraint mode is false to disable the constraint and true to enable it.

See also

setConstraints

setConstraints

function setConstraints(primitive,
constraints)

Sets the upper and lower bounds on the passed primitive to test against during simulation.

Parameters

primitiveThe primitive for which the units will be set.  May also be an array of primitives in which case they will all be set to the same constraints.
constraintsThe constraints of the primitive as an array.  The format is [MinimumConstraint, MinimumConstraintMode, MaximumConstraint, MaximumConstraintMode].  Constraint mode is false to disable the constraint and true to enable it.

See also

getConstraints

getNote

function getNote(primitive)

Gets the note of the passed primitive.

Parameters

primitiveThe primitive for which the note is requested.  May also be an array of primitives.

Return

The note of the primitive as a string.  If an array of primitives was passed, returns an array of notes.

See also

setNote

setNote

function setNote(primitive,
note)

Sets the note of the passed primitive.

Parameters

primitiveThe primitive for which the note will be set.  May also be an array of primitives in which case they will all be set to the same note.
noteThe new note for the primitive.

See also

getNote

showNote

function showNote(primitive)

Shows the note for the passed primitive.  The note is shown as a closable tooltip next to the primitive.  If the note is empty, the note will not be shown.

Parameters

primitiveThe primitive for which the note will be shown.  May also be an array of primitives in which case they will all have their notes shown.

See also

hideNote

hideNote

function hideNote(primitive)

Hides the note for the passed primitive.  The note is shown as a closable tooltip next to the primitive.

Parameters

primitiveThe primitive for which the note will be hidden.  May also be an array of primitives in which case they will all have their notes hidden.

See also

showNote

showEditor

function showEditor(primitive,
annotations)

Shows the value editor for the passed primitive.

Parameters

primitiveThe primitive for which the editor will be shown.
annotationsAn optional array containing a list of annotations.  Only valid for primitives with equations.

Example

showEditor(primitive, [{type: "error", row: 7, text: "Incorrect syntax"}])

getValue

function getValue(primitive)

Gets the value of the passed primitive.  The value depends on the type of the primitive.  For instance, the value of stock is its initial value while the value of a flow is its rate.

Parameters

primitiveThe primitive for which the value is requested.  May also be an array of primitives.

Return

The value of the primitive as a string.  If an array of primitives was passed, returns an array of values.

See also

setValue

setValue

function setValue(primitive,
value)

Sets the value of the passed primitive.  The value depends on the type of the primitive.  For instance, the value of stock is its initial value while the value of a flow is its rate.

Parameters

primitiveThe primitive for which the value will be set.  May also be an array of primitives in which case they will all be set to the same value.
valueThe new value for the primitive.  Can be a number or a string.

See also

getValue

getSize

function getSize(primitive)

Gets the size of the passed primitive.

Parameters

primitiveThe primitive for which the position is requested.  May also be an array of primitives.

Return

The size as an array of the form: [width, height].

getPosition

function getPosition(primitive)

Gets the position of the passed primitive.

Parameters

primitiveThe primitive for which the position is requested.  May also be an array of primitives.

Return

The position as an array of the form [x, y].  The position is measured from the top-left corner of the graph.

See also

setPosition

setPosition

function setPosition(primitive,
position)

Sets the position of the passed primitive.

Parameters

primitiveThe primitive for which the position will be set.  May also be an array of primitives in which case they will all be set to the same position.
positionThe new position for the primitive in the form [x, y].  The position is measured from the top-left corner of the graph.

See also

getPosition

Primitive Styling Functions

flash

function flash(primitive,
opacity,
duration)

Temporarily changes the opacity of a primitive.  Opacity between 0 (invisible) to 100 (fully opaque).

Parameters

primitiveThe primitive which will be flashed.  May also be an array of primitives.
opacityOptional temporary opacity for the primitive.  Defaults to 0.
durationOptional duration the primitive will be at the temporary opacity in milliseconds.  Defaults to 100.

Example

flash(getSelected());

getShowSlider

function getShowSlider(primitive)

Gets the show slider property of the passed primitive.

Parameters

primitiveThe primitive for which the show slider property will be returned.  May also be an array of primitives.

Return

Whether to show the slider property of the primitive.  A boolean.

setShowSlider

function setShowSlider(primitive,
showSlider)

Sets the show slider property of the passed primitive.

Parameters

primitiveThe primitive for which the show slider property will be set.  May also be an array of primitives in which case they will all be set to the same show slider value.
showSliderBoolean whether to show the slider.

getSliderMin

function getSliderMin(primitive)

Gets the slider min property of the passed primitive.

Parameters

primitiveThe primitive for which the slider min property will be returned.  May also be an array of primitives.

Return

The minimum allowed value for the slider

setSliderMin

function setSliderMin(primitive,
sliderMin)

Sets the slider min property of the passed primitive.

Parameters

primitiveThe primitive for which the slider property will be set.  May also be an array of primitives in which case they will all be set to the same slider value.
sliderMinThe minimum value of the slider.

getSliderMax

function getSliderMax(primitive)

Gets the slider max property of the passed primitive.

Parameters

primitiveThe primitive for which the slider max property will be returned.  May also be an array of primitives.

Return

The maximum allowed value for the slider

setSliderMax

function setSliderMax(primitive,
sliderMax)

Sets the slider max property of the passed primitive.

Parameters

primitiveThe primitive for which the slider property will be set.  May also be an array of primitives in which case they will all be set to the same slider value.
sliderMaxThe maximum value of the slider.

getSliderStep

function getSliderStep(primitive)

Gets the slider step property of the passed primitive.

Parameters

primitiveThe primitive for which the slider property will be returned.  May also be an array of primitives.

Return

The step value for the slider

setSliderStep

function setSliderStep(primitive,
sliderStep)

Sets the slider step property of the passed primitive.

Parameters

primitiveThe primitive for which the slider property will be set.  May also be an array of primitives in which case they will all be set to the same slider value.
sliderStepThe step value of the slider.

getOpacity

function getOpacity(primitive)

Gets the opacity of the passed primitive.  Opacity is a value between 0 (invisible) to 100 (fully opaque).

Parameters

primitiveThe primitive for which the opacity will be returned.  May also be an array of primitives.

Return

The opacity of the primitive

setOpacity

function setOpacity(primitive,
opacity)

Sets the opacity of the passed primitive.  Opacity is a value between 0 (invisible) to 100 (fully opaque).

Parameters

primitiveThe primitive for which the opacity will be set.  May also be an array of primitives in which case they will all be set to the same opacity.
opacityThe new opacity for the primitive.

getLineColor

function getLineColor(primitive)

Gets the line color of the passed primitive.

Parameters

primitiveThe primitive for which the line color will be returned.  May also be an array of primitives.

Return

The line color of the primitive

setLineColor

function setLineColor(primitive,
lineColor)

Sets the line color of the passed primitive.

Parameters

primitiveThe primitive for which the line color will be set.  May also be an array of primitives in which case they will all be set to the same color.
lineColorThe new line color for the primitive.

getFontColor

function getFontColor(primitive)

Gets the font color of the passed primitive.

Parameters

primitiveThe primitive for which the font color will be returned.  May also be an array of primitives.

Return

The font color of the primitive

setFontColor

function setFontColor(primitive,
fontColor)

Sets the font color of the passed primitive.

Parameters

primitiveThe primitive for which the font color will be set.  May also be an array of primitives in which case they will all be set to the same color.
fontColorThe new font color for the primitive.

getFillColor

function getFillColor(primitive)

Gets the fill color of the passed primitive.

Parameters

primitiveThe primitive for which the fill color will be returned.  May also be an array of primitives.

Return

The fill color of the primitive

setFillColor

function setFillColor(primitive,
fillColor)

Sets the fill color of the passed primitive.

Parameters

primitiveThe primitive for which the fill color will be set.  May also be an array of primitives in which case they will all be set to the same color.
fillColorThe new fill color for the primitive.

getImage

function getImage(primitive)

Gets the image of the passed primitive.

Parameters

primitiveThe primitive for which the image will be returned.  May also be an array of primitives.

Return

The image of the primitive as a string

setImage

function setImage(primitive,
image)

Sets the image of the passed primitive.

Parameters

primitiveThe primitive for which the image will be set.  May also be an array of primitives in which case they will all be set to the same image.
imageThe image url or alias as a string.

Stocks

getNonNegative

function getNonNegative(primitive)

Gets the non-negative property of stocks (also applicable to flows).  A non-negative stock will never become negative.

Parameters

primitiveThe stock for which the value is requested.  May also be an array of stock.

Return

The non-negative value of the stock.  If an array of primitives was passed, returns an array of values.

See also

setNonNegative

setNonNegative

function setNonNegative(primitive,
nonNegative)

Sets the non-negative value of the passed stocks (also applicable to flows).

Parameters

primitiveThe stock for which the non-negative value will be set.  May also be an array of stocks in which case they will all be set to the same value.
nonNegativeThe new non-negative status for the stock.  Either true or false.

See also

getNonNegative

getStockType

function getStockType(primitive)

Gets the type of the stock.  The type affects the behavior of the stock and may either be “Store” (the default) or “Conveyor”.

Parameters

primitiveThe stock for which the type is requested.  May also be an array of stocks.

Return

The type of the stock as a string.  If an array of stocks was passed, returns an array of strings.

See also

setStockType

setStockType

function setStockType(primitive,
type)

Sets the type of the passed stock.

Parameters

primitiveThe stock for which the type will be set.  May also be an array of stocks in which case they will all be set to the same type.
typeThe type of the stock as a string.  Either “Store” (the default) or “Conveyor”.

See also

getStockType

getDelay

function getDelay(primitive)

Gets the delay length of conveyor stocks.

Parameters

primitiveThe stock for which the value is requested.  May also be an array of stocks.

Return

The delay length of the stock.  If an array of stocks was passed, returns an array of lengths.

See also

setDelay

setDelay

function setDelay(primitive,
delay)

Sets the delay length of the passed conveyor stock.

Parameters

primitiveThe stock for which the delay length will be set.  May also be an array of stocks in which case they will all be set to the same value.
delayThe delay length for the stock.

See also

getDelay

Connectors

See getNonNegative and setNonNegative for setting the only-positive property of flows.

getEnds

function getEnds(connector)

Gets the alpha and omega for the connector

Parameters

connectorThe connector for which the ends are requested.  Can also be an array of connectors.

Return

The alpha and omega as an array: [alpha, omega].  Array elements are returned as null if no connection exists.

See also

setEnds

setEnds

function setEnds(connector,
ends)

Sets the alpha and omega for a connector.

Parameters

connectorThe connector for which the alpha and omega will be set.  May also be an array of connectors.
endsThe new alpha and omega for the connector as an array: [alpha, omega].  Use null for either alpha or omega to disconnect an end.

See also

getEnds

connected

function connected(primitive1,
primitive2)

Determines two primitives are connected by a link, flow, or transition.  Alternatively if one of the primitives is a connector, checks if it connects directly to the other primitive.

Parameters

primitive1A primitive.
primitive2A primitive to test whether it is connected to primitive1.

Return

A boolean.  True if the primitives are connected, false otherwise.

States

getResidency

function getResidency(state)

Gets the residency property of a state primitive.

Parameters

stateThe state for which the residency property is requested.  May also be an array of states.

Return

The residency property as a string.

See also

setResidency

setResidency

function setResidency(state,
residency)

Sets the residency property of a state primitive.

Parameters

stateThe state primitive for which the residency property will be set.  May also be an array of states.
residencyThe new value for the residency property.

See also

getResidency

Transitions and Actions

getTriggerType

function getTriggerType(primitive)

Gets the trigger type of a transition or action.

Parameters

primitiveThe transition or action for which the trigger is requested.  May also be an array of transitions or actions.

Return

The trigger mode as a string.  May be “Timeout”, “Probability” or “Condition”.

See also

setTriggerType

setTriggerType

function setTriggerType(primitive,
trigger)

Sets the trigger type for a transition or action.

Parameters

primitiveThe transition or action for which the trigger will be set.  May also be an array of transitions or actions.
triggerThe new trigger for the transition or action.  May be “Timeout” “Probability” or “Condition”.

See also

getTriggerType

getTriggerValue

function getTriggerValue(primitive)

Gets the trigger value equation of a transition or action.

Parameters

primitiveThe transition or action for which the trigger value equation is requested.  May also be an array of transitions or actions.

Return

The trigger value equation as a string.

See also

setTriggerValue

setTriggerValue

function setTriggerValue(primitive,
value)

Sets the trigger value for a transition or action.

Parameters

primitiveThe transition or action for which the trigger will be set.  May also be an array of transitions or actions.
valueThe new trigger value equation as a string.

See also

getTriggerValue

getTriggerRepeat

function getTriggerRepeat(primitive)

Gets the trigger Repeat property of a transition or action.

Parameters

primitiveThe transition or action for which the property is requested.  May also be an array of transitions or actions.

Return

The trigger Repeat property as a boolean.

See also

setTriggerRepeat

setTriggerRepeat

function setTriggerRepeat(primitive,
repeat)

Sets the trigger Repeat property for a transition or action.

Parameters

primitiveThe transition or action for which the Repeat property will be set.  May also be an array of transitions or actions.
repeatA boolean determining whether to repeat the trigger

See also

getTriggerRepeat

getTriggerRecalculate

function getTriggerRecalculate(primitive)

Gets the trigger Recalculate property of a transition or action.

Parameters

primitiveThe transition or action for which the property is requested.  May also be an array of transitions or actions.

Return

The trigger Recalculate property as a boolean.

See also

setTriggerRecalculate

setTriggerRecalculate

function setTriggerRecalculate(primitive,
recalculate)

Sets the trigger Recalculate property for a transition or action.

Parameters

primitiveThe transition or action for which the Recalculate property will be set.  May also be an array of transitions or actions.
recalculateA boolean determining whether to recalculate each time step

See also

getTriggerRecalculate

Converters

getData

function getData(converter)

Gets the data of a converter.

Parameters

converterThe converter for which the data is requested.  May also be an array of Converters.

Return

The Converter data as a string.  A set of input/output pairs separated by semicolons.  Example data form: “1,1;2,4;3,9”

See also

setData

setData

function setData(converter,
data)

Sets the data of a converter.

Parameters

converterThe converter for which the data will be set.  May also be an array of Converters in which case they will all be set to the same value.
dataThe data for the converter as a string.  A set of input/output pairs separated by semicolons.  Example data form: “1,1;2,4;3,9”

See also

getData

getConverterInput

function getConverterInput(converter)

Gets the input source of a converter.

Parameters

converterThe converter for which the input source is requested.  May also be an array of Converters.

Return

The input source.  If the input source is a primitive, returns the primitive.  Otherwise returns null (indicating the use of time as the input source).

See also

<setInputSource>

setConverterInput

function setConverterInput(converter,
input)

Sets the input source of a converter.

Parameters

converterThe converter for which the input source will be set.  May also be an array of Converters in which case they will all be set to the same value.
inputThe input source.  Pass either a primitive or use null to indicate the usage of time as the input.

See also

getConverterInput

getInterpolation

function getInterpolation(converter)

Gets the interpolation mode of a converter.

Parameters

converterThe converter for which the interpolation is requested.  May also be an array of Converters.

Return

The interpolation mode as a string.  May be “Linear” or “Discrete”.

See also

setInterpolation

setInterpolation

function setInterpolation(converter,
interpolation)

Sets the interpolation mode of a converter.

Parameters

converterThe converter for which the interpolation will be set.  May also be an array of Converters in which case they will all be set to the same value.
interpolationThe interpolation mode for the converter as a string.  May either be “Linear” or “Discrete”.

See also

getInterpolation

Buttons

pressButton

function pressButton(button)

Simulates a press of the passed button(s) firing its action.  Can be useful for chaining together methods.

Parameter

buttonThe button to be pressed.  Can also be an array of buttons.

Agents

getPopulationSize

function getPopulationSize(agents)

Gets the size of the agent population.

Parameters

agentsThe agent population for which the size will be returned.  May also be an array of agent populations.

Return

The population size.

See also

setPopulationSize

setPopulationSize

function setPopulationSize(agents,
size)

Sets the size of the agent population.

Parameters

agentsThe agent population for which the size will be set.  May also be an array of agent populations.
sizeThe new population size.

See also

getPopulationSize

getAgentBase

function getAgentBase(agents)

Gets the base agent for the population.

Parameters

agentsThe agent population for which the base agent will be returned.  May also be an array of agent populations.

Return

The base agent folder.

See also

setAgentBase

setAgentBase

function setAgentBase(agents,
folder)

Sets the base agent for the population.

Parameters

agentsThe agent population for which the base agent will be set.  May also be an array of agent populations.
folderThe base agent folder.  The type for this folder should be set to “Agent”.

See also

getAgentBase

getGeometryWrap

function getGeometryWrap(agents)

Whether the geometry should wrap across edges.

Parameters

agentsThe agent population for which the geometry wrap property will be returned.  May also be an array of agent populations.

Return

The wrap property as a boolean

See also

setGeometryWrap

setGeometryWrap

function setGeometryWrap(agents,
wrap)

Sets the wrap property for the population area geometry.

Parameters

agentsThe agent population for which geometry wrap property will be set.  May also be an array of agent populations.
wrapThe wrap property for the geometry.

See also

getGeometryWrap

getGeometryUnits

function getGeometryUnits(agents)

Gets the units for the population area geometry.

Parameters

agentsThe agent population for which the units will be returned.  May also be an array of agent populations.

Return

The units as a string

See also

setGeometryUnits

setGeometryUnits

function setGeometryUnits(agents,
units)

Sets the units for the population area geometry.

Parameters

agentsThe agent population for which geometry units will be set.  May also be an array of agent populations.
unitsThe units as a string.

See also

getGeometryUnits

getGeometryWidth

function getGeometryWidth(agents)

Gets the width for the population area geometry.

Parameters

agentsThe agent population for which the width will be returned.  May also be an array of agent populations.

Return

The width of the geometry

See also

setGeometryWidth

setGeometryWidth

function setGeometryWidth(agents,
width)

Sets the width for the population area geometry.

Parameters

agentsThe agent population for which geometry width will be set.  May also be an array of agent populations.
widthThe desired width.

See also

getGeometryWidth

getGeometryHeight

function getGeometryHeight(agents)

Gets the height for the population area geometry.

Parameters

agentsThe agent population for which the height will be returned.  May also be an array of agent populations.

Return

The height of the geometry

See also

setGeometryHeight

setGeometryHeight

function setGeometryHeight(agents,
height)

Sets the height for the population area geometry.

Parameters

agentsThe agent population for which geometry height will be set.  May also be an array of agent populations.
heightThe desired height.

See also

getGeometryHeight

getAgentPlacement

function getAgentPlacement(agents)

The placement method for the agent population.

Parameters

agentsThe agent population for which the placement method will be returned.  May also be an array of agent populations.

Return

The placement method for the agent population.  One of “Random”, “Network”, “Grid” or “Custom Function”.

See also

setAgentPlacement

setAgentPlacement

function setAgentPlacement(agents,
method)

Sets the placement method for the agent population.

Parameters

agentsThe agent population for which placement method will be set.  May also be an array of agent populations.
methodThe desired placemennt method.  One of “Random”, “Network”, “Grid” or “Custom Function”.

See also

getAgentPlacement

getAgentPlacementFunction

function getAgentPlacementFunction(agents)

A custom placement function for the agent population.

Parameters

agentsThe agent population for which the custom placement function will be returned.  May also be an array of agent populations.

Return

The custom placement function for the agent population.

See also

setAgentPlacementFunction

setAgentPlacementFunction

function setAgentPlacementFunction(agents,
func)

Sets the custom placement function for the agent population.  The placement method should be set to “Custom Function” in order for this function to be used.

Parameters

agentsThe agent population for which the custom placement function will be set.  May also be an array of agent populations.
funcThe desired custom placement function.

See also

getAgentPlacementFunction

getAgentNetwork

function getAgentNetwork(agents)

The network method for the agent population.

Parameters

agentsThe agent population for which the network method will be returned.  May also be an array of agent populations.

Return

The network method for the agent population.  One of “None” or “Custom Function”.

See also

setAgentNetwork

setAgentNetwork

function setAgentNetwork(agents,
method)

Sets the network method for the agent population.

Parameters

agentsThe agent population for which network method will be set.  May also be an array of agent populations.
methodThe desired placement method.  One of “None” or “Custom Function”.

See also

getAgentNetwork

getAgentNetworkFunction

function getAgentNetworkFunction(agents)

A custom network function for the agent population.

Parameters

agentsThe agent population for which the custom network function will be returned.  May also be an array of agent populations.

Return

The custom network function for the agent population.

See also

setAgentNetworkFunction

setAgentNetworkFunction

function setAgentNetworkFunction(agents,
func)

Sets the custom network function for the agent population.  The network method should be set to “Custom Function” in order for this function to be used.

Parameters

agentsThe agent population for which the custom network function will be set.  May also be an array of agent populations.
funcThe desired custom network function.

See also

getAgentNetworkFunction

Folders

collapseFolder

function collapseFolder(folder)

Collapses a folder or an array of folders.

Parameter

folderEither a single folder primitive or an array of folder primitives.

See also

expandFolder, getCollapsed

expandFolder

function expandFolder(folder)

Expands a folder or an array of folders.

Parameter

folderEither a single folder primitive or an array of folder primitives.

See also

collapseFolder, getCollapsed

getCollapsed

function getCollapsed(folder)

Returns whether or not a given folder is collapsed.

Parameter

folderThe folder for which the collapsed state is requested.

Return

True is the folder is collapsed, false if it is expanded.

See also

collapseFolder, expandFolder

getParent

function getParent(primitive)

Gets the parent folder for a primitive.

Parameters

primitiveThe primitive for which the parent folder will be returned.  May also be an array of primitives.

Return

The parent folder.  Returns null if the primitive is not in a folder.

See also

setParent

setParent

function setParent(primitive,
parent,
preserveLoc)

Sets the parent folder for a primitive.

Parameters

primitiveThe primitive for which the parent folder will be set.  May also be an array of primitives in which case they will all be set to the same parent.
parentThe parent folder primitive.  Use null to remove the primitive from all folders.

See also

getParent

getFrozen

function getFrozen(primitive)

Gets the frozen state for a primitive.

Parameters

primitiveThe primitive for which the frozen will be returned.  May also be an array of primitives.

Return

The frozen state for the primitive.

See also

setFrozen

setFrozen

function setFrozen(primitive,
frozen)

Sets the frozen state for a primitive.

Parameters

primitiveThe primitive for which the frozen state will be set.  May also be an array of primitives in which case they will all be set to the same frozen state.
frozenThe new frozen state for the primitive.

See also

getFrozen

getChildren

function getChildren(folder,
recursive)

Returns the children of a folder.

Parameters

folderThe folder for which the children will be returned.
recursiveOptional.  Whether the children of inner folders will be returned.  Defaults to true.

Return

The children primitives of the folder.

getFolderType

function getFolderType(folder)

Gets the type of a folder.

Parameters

folderThe folder for which the type is requested.  May also be an array of folders.

Return

The type mode as a string.  May be “None” or “Agent”.

See also

setFolderType

setFolderType

function setFolderType(folder,
type)

Sets the type of a folder.

Parameters

folderThe folder for which the type will be set.  May also be an array of folders.
typeThe type mode as a string.  May be “None” or “Agent”.

See also

getFolderType

getFolderAgentParent

function getFolderAgentParent(folder)

Gets the agent parent of a folder.

Parameters

folderThe folder for which the agent parent is requested.  May also be an array of folders.

Return

The agent parent as a string.

See also

setFolderAgentParent

setFolderAgentParent

function setFolderAgentParent(folder,
agentParent)

Sets the agent parent of a folder.

Parameters

folderThe folder for which the type will be set.  May also be an array of folders.
agentParentThe agent parent as a string.

See also

getFolderAgentParent

getFolderSolver

function getFolderSolver(folder)

Gets the solver configuration for a folder.  The configuration is an object with the properties

enabledtrue is the folder should have its own solver
algorithmthe solution algorithm.  Current allowed values are “RK1” for Euler’s method and “RK4” for a fourth order Runge-Kutta method
timeStepthe time step for the folder’s solver

Parameters

folderThe folder for which the solver is requested.  May also be an array of folders.

Return

The solver object

See also

setFolderSolver

setFolderSolver

function setFolderSolver(folder,
solver)

Sets the solver object for a folder

Parameters

folderThe folder for which the solver will be set.  May also be an array of folders.
solverThe solver object

See also

getFolderSolver

Utility Functions

excludeType

function excludeType(array,
type)

Removes a specific type of primitive from an array of primitives.

Parameter

arrayAn array of primitives.
typeThe type of primitives to remove (e.g.  “Flow” or “Stock”).  May also be an array of types.

Return

A duplicate of the input array without any primitives of the specified type.

primitiveIndex

function primitiveIndex(array,
primitive)

Locates the index of a specific primitive in an array of primitives.

Parameter

arrayAn array of primitives.
primitiveThe specific primitive to find.

Return

The index of the primitive in the array.  Returns -1 if the primitive is not found.

uniquePrimitives

function uniquePrimitives(primitives)

Returns the passed array with duplicated primitives removed

Parameter

primitivesAn array of primitives.

Return

An array of primitives with any duplicated elements removed.

setGlobal

Sets the value of a global variable.  This can allow communication between buttons or the storing of some state.

Parameter

nameThe name of the global variable.
valueThe value of the global variable.

See also

getGlobal

getGlobal

function getGlobal(name)

Gets the value of a global variable.  This can allow communication between buttons or the storing of some state.

Parameter

nameThe name of the global variable for which to get the value.

Return

The value of the global variable specified by name.

Example

setGlobal("Example Var 1", 42);
setGlobal("Example Var 2", "test");
var z = getGlobal("Example Var 1"); // z is now set to 42
var y = getGlobal("Example Var 2"); // y is now set to "test"

See also

setGlobal

Insight Maker Interface

topBarShown

function topBarShown()

Determines whether or not the Insight Maker top toolbar (which contains the Run Simulation button and other tools) is currently shown.

Return

True if the top toolbar is shown, false otherwise.

See also

toggleTopBar

toggleTopBar

function toggleTopBar()

Toggles the visibility of the top toolbar.  If it is currently shown, it is hidden.  If it is currently hidden, it is shown.

See also

topBarShown

sideBarShown

function sideBarShown()

Determines whether or not the Insight Maker side panel (which contains parameter sliders and information about the selected primitive) is currently shown.

Return

True if the side panel is shown, false otherwise.

See also

toggleSideBar

toggleSideBar

function toggleSideBar()

Toggles the visibility of the side panel.  If it is currently shown, it is hidden.  If it is currently hidden, it is shown.

See also

sideBarShown

updateSideBar

function updateSideBar()

Refreshes the values in the side panel to reflect any changes in the model.

function showMessage(message)
Shows a message in a dialog window.
function showPrompt(message,
defaultValue)
Shows a prompt in a dialog window and provides a text input for the user to enter a value.
function showChoice(message)
Shows a prompt in a dialog window and provides the user the option to click “OK” or “Cancel”.
function showURL(url)
Creates a new web browser window and sets the URL.
function downloadFile(fileName,
data,
type)
Downloads a file.
function showData(title,
tabs,
size)
Creates a display to showcase data.
function frontWindow()
Gets the front-most window (if one exists).
function closeAllWindows()
Closes all open windows.
function openFile(config)
Prompts the user to select one or more files on their computer.
function runModel(config)
Runs a simulation and optionally returns the results.
function saveModel(dialog)
Saves the model.
function clearModel()
Removes all primitives from the model.
function layoutModel(algorithm)
Reorganizes the primitives in the model according to an algorithm.
function setZoom(scale)
Sets the scale of the diagram display.
function getTimeStep()
Gets the time step used in the simulation.
function setTimeStep(timeStep)
Sets the time step used in the simulation.
function getTimeStart()
Gets the start time for the simulation.
function setTimeStart(timeStart)
Sets the start time for the simulation.
function getTimeLength()
Gets the length of the simulation.
function setTimeLength(timeLength)
Sets the length of the simulation.
function getPauseInterval()
Gets the intervals at which to pause the simulation.
function setPauseInterval(pauseInterval)
Sets the intervals at which to pause the simulation.
function getTimeUnits()
Gets the time units of the simulation.
function setTimeUnits(units)
Sets the time units of the simulation.
function getAlgorithm()
Gets the algorithm for the simulation.
function setAlgorithm(algorithm)
Sets the algorithm of the simulation.
function getMacros()
Gets the macros for the insight.
function setMacros(macros)
Sets the macros of the insight.
function findName(name)
Finds and returns a primitive by its name.
function findAll()
Finds and returns all primitives in the model.
function findType(type)
Finds and returns all primitives of a specific type.
function findID(id)
Finds and returns a primitive using its ID.
function findValue(search)
Finds and returns all primitives whose values match a regular expression.
function findNote(search)
Finds and returns all primitives whose notes match a regular expression.
function createPrimitive(name,
type,
position,
size)
Creates a new primitive and adds it to the model.
function createConnector(name,
type,
alpha,
omega)
Creates a new connector primitive and adds it to the model.
function removePrimitive(primitive)
Removes a primitive from the model.
function highlight(primitive)
Highlights a single primitive.
function getSelected()
Finds and returns the currently selected primitives.
function setSelected(primitives)
Sets the currently selected primitives.
function isSelected(primitive)
Indicates whether a primitive is selected.
function getID(primitive)
Gets the ID of the passed primitive.
function getType(primitive)
Gets the type of the passed primitive.
function getName(primitive)
Gets the name of the passed primitive.
function setName(primitive,
name)
Sets the name of the passed primitive.
function getUnits(primitive)
Gets the units of the passed primitive.
function setUnits(primitive,
units)
Sets the units of the passed primitive.
function getConstraints(primitive)
Gets the upper and lower bounds on the passed primitive to test against during simulation.
function setConstraints(primitive,
constraints)
Sets the upper and lower bounds on the passed primitive to test against during simulation.
function getNote(primitive)
Gets the note of the passed primitive.
function setNote(primitive,
note)
Sets the note of the passed primitive.
function showNote(primitive)
Shows the note for the passed primitive.
function hideNote(primitive)
Hides the note for the passed primitive.
function showEditor(primitive,
annotations)
Shows the value editor for the passed primitive.
function getValue(primitive)
Gets the value of the passed primitive.
function setValue(primitive,
value)
Sets the value of the passed primitive.
function getSize(primitive)
Gets the size of the passed primitive.
function getPosition(primitive)
Gets the position of the passed primitive.
function setPosition(primitive,
position)
Sets the position of the passed primitive.
function flash(primitive,
opacity,
duration)
Temporarily changes the opacity of a primitive.
function getShowSlider(primitive)
Gets the show slider property of the passed primitive.
function setShowSlider(primitive,
showSlider)
Sets the show slider property of the passed primitive.
function getSliderMin(primitive)
Gets the slider min property of the passed primitive.
function setSliderMin(primitive,
sliderMin)
Sets the slider min property of the passed primitive.
function getSliderMax(primitive)
Gets the slider max property of the passed primitive.
function setSliderMax(primitive,
sliderMax)
Sets the slider max property of the passed primitive.
function getSliderStep(primitive)
Gets the slider step property of the passed primitive.
function setSliderStep(primitive,
sliderStep)
Sets the slider step property of the passed primitive.
function getOpacity(primitive)
Gets the opacity of the passed primitive.
function setOpacity(primitive,
opacity)
Sets the opacity of the passed primitive.
function getLineColor(primitive)
Gets the line color of the passed primitive.
function setLineColor(primitive,
lineColor)
Sets the line color of the passed primitive.
function getFontColor(primitive)
Gets the font color of the passed primitive.
function setFontColor(primitive,
fontColor)
Sets the font color of the passed primitive.
function getFillColor(primitive)
Gets the fill color of the passed primitive.
function setFillColor(primitive,
fillColor)
Sets the fill color of the passed primitive.
function getImage(primitive)
Gets the image of the passed primitive.
function setImage(primitive,
image)
Sets the image of the passed primitive.
function getNonNegative(primitive)
Gets the non-negative property of stocks (also applicable to flows).
function setNonNegative(primitive,
nonNegative)
Sets the non-negative value of the passed stocks (also applicable to flows).
function getStockType(primitive)
Gets the type of the stock.
function setStockType(primitive,
type)
Sets the type of the passed stock.
function getDelay(primitive)
Gets the delay length of conveyor stocks.
function setDelay(primitive,
delay)
Sets the delay length of the passed conveyor stock.
function getEnds(connector)
Gets the alpha and omega for the connector
function setEnds(connector,
ends)
Sets the alpha and omega for a connector.
function connected(primitive1,
primitive2)
Determines two primitives are connected by a link, flow, or transition.
function getResidency(state)
Gets the residency property of a state primitive.
function setResidency(state,
residency)
Sets the residency property of a state primitive.
function getTriggerType(primitive)
Gets the trigger type of a transition or action.
function setTriggerType(primitive,
trigger)
Sets the trigger type for a transition or action.
function getTriggerValue(primitive)
Gets the trigger value equation of a transition or action.
function setTriggerValue(primitive,
value)
Sets the trigger value for a transition or action.
function getTriggerRepeat(primitive)
Gets the trigger Repeat property of a transition or action.
function setTriggerRepeat(primitive,
repeat)
Sets the trigger Repeat property for a transition or action.
function getTriggerRecalculate(primitive)
Gets the trigger Recalculate property of a transition or action.
function setTriggerRecalculate(primitive,
recalculate)
Sets the trigger Recalculate property for a transition or action.
function getData(converter)
Gets the data of a converter.
function setData(converter,
data)
Sets the data of a converter.
function getConverterInput(converter)
Gets the input source of a converter.
function setConverterInput(converter,
input)
Sets the input source of a converter.
function getInterpolation(converter)
Gets the interpolation mode of a converter.
function setInterpolation(converter,
interpolation)
Sets the interpolation mode of a converter.
function pressButton(button)
Simulates a press of the passed button(s) firing its action.
function getPopulationSize(agents)
Gets the size of the agent population.
function setPopulationSize(agents,
size)
Sets the size of the agent population.
function getAgentBase(agents)
Gets the base agent for the population.
function setAgentBase(agents,
folder)
Sets the base agent for the population.
function getGeometryWrap(agents)
Whether the geometry should wrap across edges.
function setGeometryWrap(agents,
wrap)
Sets the wrap property for the population area geometry.
function getGeometryUnits(agents)
Gets the units for the population area geometry.
function setGeometryUnits(agents,
units)
Sets the units for the population area geometry.
function getGeometryWidth(agents)
Gets the width for the population area geometry.
function setGeometryWidth(agents,
width)
Sets the width for the population area geometry.
function getGeometryHeight(agents)
Gets the height for the population area geometry.
function setGeometryHeight(agents,
height)
Sets the height for the population area geometry.
function getAgentPlacement(agents)
The placement method for the agent population.
function setAgentPlacement(agents,
method)
Sets the placement method for the agent population.
function getAgentPlacementFunction(agents)
A custom placement function for the agent population.
function setAgentPlacementFunction(agents,
func)
Sets the custom placement function for the agent population.
function getAgentNetwork(agents)
The network method for the agent population.
function setAgentNetwork(agents,
method)
Sets the network method for the agent population.
function getAgentNetworkFunction(agents)
A custom network function for the agent population.
function setAgentNetworkFunction(agents,
func)
Sets the custom network function for the agent population.
function collapseFolder(folder)
Collapses a folder or an array of folders.
function expandFolder(folder)
Expands a folder or an array of folders.
function getCollapsed(folder)
Returns whether or not a given folder is collapsed.
function getParent(primitive)
Gets the parent folder for a primitive.
function setParent(primitive,
parent,
preserveLoc)
Sets the parent folder for a primitive.
function getFrozen(primitive)
Gets the frozen state for a primitive.
function setFrozen(primitive,
frozen)
Sets the frozen state for a primitive.
function getChildren(folder,
recursive)
Returns the children of a folder.
function getFolderType(folder)
Gets the type of a folder.
function setFolderType(folder,
type)
Sets the type of a folder.
function getFolderAgentParent(folder)
Gets the agent parent of a folder.
function setFolderAgentParent(folder,
agentParent)
Sets the agent parent of a folder.
function getFolderSolver(folder)
function setFolderSolver(folder,
solver)
Sets the solver object for a folder
function excludeType(array,
type)
Removes a specific type of primitive from an array of primitives.
function primitiveIndex(array,
primitive)
Locates the index of a specific primitive in an array of primitives.
function uniquePrimitives(primitives)
Returns the passed array with duplicated primitives removed
function getGlobal(name)
Gets the value of a global variable.
function topBarShown()
Determines whether or not the Insight Maker top toolbar (which contains the Run Simulation button and other tools) is currently shown.
function toggleTopBar()
Toggles the visibility of the top toolbar.
function sideBarShown()
Determines whether or not the Insight Maker side panel (which contains parameter sliders and information about the selected primitive) is currently shown.
function toggleSideBar()
Toggles the visibility of the side panel.
function updateSideBar()
Refreshes the values in the side panel to reflect any changes in the model.
Sets the value of a global variable.
Close