API Docs for:
Show:

xh Class

Defined in: XholonJsApi.js:15
Module: XholonJsApi

These methods apply to the top level of the Xholon application. All of the methods in this class MUST be preceeded by "$wnd.xh." (ex: "$wnd.xh.app();") if they are run from within the Xholon application. The "$wnd." is a GWT requirement. They MUST be preceeded by "xh." (ex: "xh.app();") if they are run using a developer's tool such as Firebug or Developer Tools.

Constructor

xh

()

Defined in XholonJsApi.js:15

Methods

app

() IApplication

Defined in XholonJsApi.js:29

Get the single app-specific IApplication instance.

Returns:

IApplication:

An instance of a subclass of org.primordion.xholon.app.Application.

Example:

var app = $wnd.xh.app();

attrs

(
  • node
)

Defined in XholonJsApi.js:51

Log all attribute name/value pairs (JavaScript properties) of a node to the browser console. This is mostly intended for debugging.

Parameters:

  • node IXholon

    An IXholon node.

Example:

var node = $wnd.xh.root();
$wnd.xh.attrs(node);

avatar

(
  • newAvatar
)
Avatar

Defined in XholonJsApi.js:325

Get or set the system Avatar. Note: Avatar extends AbstractAvatar, which extends XholonWithPorts.

Parameters:

  • newAvatar Avatar

    Optional new system Avatar.

Returns:

Avatar:

An IXholon (Avatar) node, or null.

Example:

const ava = $wnd.xh.avatar();
ava.action("where;look");
$wnd.xh.avatar(newAvatar);

avatarKeyMap

(
  • keyMap
)
String

Defined in XholonJsApi.js:346

Get or set the Avatar key map.

Parameters:

  • keyMap String

    Optional new key map.

Returns:

String:

Current key map, or null.

Example:

const akmStr = xh.avatarKeyMap();
console.log(akmStr);
var json = xh.avatarKeyMap();
var obj = JSON.parse(json);
obj.X = "build Cat role Licorice";
obj.Y = "build Dog role Fido";
obj["1"] = "take *cat";
var newJson = JSON.stringify(obj);
$wnd.xh.avatarKeyMap(newJson);

css.style

(
  • content
)

Defined in XholonJsApi.js:259

Set styles for elements in the HTML page.

Parameters:

  • content Strong

Example:

$wnd.xh.css.style(".d3cpnode circle {stroke-width: 0px;}");

html.popup

(
  • title
  • htmlText
  • autoHide
  • modal
  • left
  • top
)

Defined in XholonJsApi.js:221

Generate a popup on the browser HTML page.

Parameters:

  • title String
  • htmlText String
  • autoHide Boolean
  • modal Boolean
  • left Intger
  • top Integer

Returns:

Example:

$wnd.xh.html.popup("Title", "<div><p>Hello Popup</p></div>");

html.toggle

(
  • elementId
)

Defined in XholonJsApi.js:198

Toggle the visibility of an existing HTML element, typically a div that starts with "xh".

Parameters:

  • elementId String

    An HTML element id.

Example:

$wnd.xh.html.toggle("xhgui");

html.urlparam

(
  • a
)
String

Defined in XholonJsApi.js:236

Get a URL search param from the browser. For example, if the URL line includes the text "&one=two", then asking for param "one" will return "two".

Parameters:

  • a String

    URL param

Returns:

String:

a value, or null

Example:

console.log($wnd.xh.html.urlparam("one")); // "two"

html.xhElements

() String

Defined in XholonJsApi.js:209

Get an array of top-level "xh" element id's.

Returns:

String:

a comma-delimited list (ex: "xhtop,xhgui,xhappspecific,xhconsole,xhtabs,xhchart,xhcanvas,xhgraph,xhsvg,xhimg").

Example:

$wnd.xh.html.xhElements();

isXholonNode

(
  • obj
)
Boolean

Defined in XholonJsApi.js:406

Determine if obj is an instance of a Java class that descends from Xholon.java.

Parameters:

  • obj Object

    Any JS object.

Returns:

Boolean:

true or false

Example:

$wnd.xh.isXholonNode(xh.root());  //returns true
$wnd.xh.isXholonNode(13);         //returns false

isXholonNodeCanonical

(
  • obj
)
Boolean

Defined in XholonJsApi.js:419

Determine if obj is an instance of a Java class that descends from Xholon.java.

Parameters:

  • obj Object

    Any JS object.

Returns:

Boolean:

true or false

Example:

$wnd.xh.isXholonNodeCanonical(xh.root());  //returns true
$wnd.xh.isXholonNodeCanonical(13);         //returns false

matchGraph

(
  • graphStr
  • subgraphStr
  • separator
)

Defined in XholonJsApi.js:454

Match graph

Parameters:

  • graphStr String
  • subgraphStr String
  • separator String

Returns:

Example:

// TODO

param

(
  • pName
  • [pValue]
)
String

Defined in XholonJsApi.js:131

Get or set the value of an application parameter.

Parameters:

  • pName String

    The name of the parameter.

  • [pValue] String optional

    The value of the parameter.

Returns:

String:

The value of the parameter, or null, or undefined.

Example:

// set the interval between time steps as 200 milliseconds
// show the before and after values in the browser console
console.log($wnd.xh.param("TimeStepInterval"));
$wnd.xh.param("TimeStepInterval", "200");
console.log($wnd.xh.param("TimeStepInterval"));

random

() Number

Defined in XholonJsApi.js:432

replacement for Javascript Math.random(), with a seed

Returns:

Number:

a random real number between 0 and 1

Example:

console.log($wnd.xh.random()); // 0.0138649232303234

require

(
  • scriptName
  • [scriptPath]
)

Defined in XholonJsApi.js:166

Require a single named JavaScript library. If the script is located in the Xholon application library, then only the scriptName needs to be provided.

Parameters:

  • scriptName String

    The name of a script.

  • [scriptPath] String optional

    The URL for the script.

Example:

$wnd.xh.require("d3.v2.min.js");
$wnd.xh.require("three.min.js", "http://threejs.org/build/");

root

() IXholon

Defined in XholonJsApi.js:40

Get the app-specific root of the composite structure hierarchy.

Returns:

IXholon:

An instance of a subclass of org.primordion.xholon.base.Xholon.

Example:

var root = $wnd.xh.root();

seed

(
  • An
)

Defined in XholonJsApi.js:443

Seed the random number generator

Parameters:

  • An Number

    integer. example $wnd.xh.seed(5297);

selectTab

(
  • index
)

Defined in XholonJsApi.js:247

Select a tab in #xhtabs .

Parameters:

  • index Number

    the XXholon tab index

Returns:

Example:

$wnd.xh.html.selectTab(0); // "out"
$wnd.xh.html.selectTab(1); // "clipboard"
$wnd.xh.html.selectTab(2); // "notes"

service

(
  • serviceName
)
IXholon

Defined in XholonJsApi.js:107

Get a Xholon Service.

Parameters:

  • serviceName String

    The name of a service (ex: "TimelineService").

Returns:

IXholon:

An IXholon node, or null.

Example:

var service = $wnd.xh.service("TimelineService");
console.log(service);

services

()

Defined in XholonJsApi.js:120

Display a list of names of services and their activation status, in the out tab.

Example:

$wnd.xh.services();

showLocalStorage

()

Defined in XholonJsApi.js:395

Show contents of browser local storage. It prints this to the Xholon GUI out tab.

Returns:

null

Example:

var locstor = $wnd.xh.showLocalStorage();
console.log(locstor);

speechRecognition

(
  • lang
)

Defined in XholonJsApi.js:372

Set up speech recognition.

Parameters:

  • lang String

    (ex: "en-GB")

Returns:

state

(
  • controllerState
)

Defined in XholonJsApi.js:153

Set controller state. The example below sets the controller state to CS_STEPPING, which causes the app to move forward one timestep, and then go into CS_PAUSE state.

Parameters:

  • controllerState Number

    5 is currently the only useful value.

Example:

$wnd.xh.state(5);

test

()

Defined in XholonJsApi.js:182

Run the Xholon JavaScript API unit tests, using QUnit. The tests are intended to run inside the Furcifer app: http://www.primordion.com/Xholon/gwt/XholonQUnit.html?app=Furcifer&gui=clsc See also the Information page for the Furcifer app (Help > Information).

Example:

$wnd.xh.test();

webRTC

(
  • id
  • key
  • debug
)

Defined in XholonJsApi.js:380

Enable external access through a new Avatar, using WebRTC PeerJS. This would typically be used from PeerjsChat.html

Parameters:

  • id String

    optional

  • key String

    peerjs demo API key, or other

  • debug Number

    debug level (0 - 3)

Returns:

null

Example:

xh.webRTC();
xh.webRTC("Alligator", undefined, 3);

xpath

(
  • expression
  • node
)
IXholon

Defined in XholonJsApi.js:73

Evaluate an XPath 1.0 expression.

Parameters:

  • expression String

    An XPath 1.0 String expression (ex: "ancestor::HelloWorldSystem/World");

  • node IXholon

    An IXholon node.

Returns:

IXholon:

An IXholon node, or null.

Example:

var node = $wnd.xh.root().first(); // get the Hello node
$wnd.xh.xpath("ancestor::HelloWorldSystem/World", node);

xpathExpr

(
  • descendant
  • ancestor
)
String

Defined in XholonJsApi.js:89

Get an XPath 1.0 compliant expression that uniquely identifies a path from an ancestor node to a descendant node.

Parameters:

  • descendant IXholon

    A Xholon node that is a descendant of ancestor.

  • ancestor IXholon

    A Xholon node that is an ancestor of descendant.

Returns:

String:

Example:

console.log(xh.xpathExpr($wnd.xh.root().first(), xh.root())); // "HelloWorldSystem/Hello"
var ancestor = $wnd.xh.root().first().first(); // City
var descendant = ancestor.xpath("School[@roleName='Hilson']");
$wnd.console.log($wnd.xh.xpathExpr(descendant, ancestor)); // "City/School[@roleName='Hilson']"

xport

(
  • formatName
  • node
  • [efParams]
)

Defined in XholonJsApi.js:268

Export a node and its subtree to an external format. Because "export" is a JS keyword, we use "xport" instead.

Parameters:

  • formatName String

    The name of an external format (ex: "MindMap").

  • node IXholon

    An IXholon node.

  • [efParams] String optional

    A JSON-formatted string containing one or more key/value pairs. To determine the possible parameters for a given external format, look at the efParams object in each ef source file.

Example:

var root = $wnd.xh.root();
$wnd.xh.xport("MindMap", root);
$wnd.xh.xport("Yaml", root);
$wnd.xh.xport("_other,Newick", root);
$wnd.xh.xport("_xholon,Xhn", root);
$wnd.xh.xport("_d3,CirclePack", root);
$wnd.xh.xport("Graphviz", root, '{"layout":"neato"}');

xports

() Array

Defined in XholonJsApi.js:298

Get an array of external format names.

Returns:

Array:

An array of strings. Example: Csv GraphML Graphviz MindMap Yaml _other,ChapNetwork,ChapTree,Newick _xholon,Cd,Csh,Ih,Xhn _d3,CirclePack

Example:

var root = $wnd.xh.root();
var formatNamesArr = $wnd.xh.xports();
for (var i = 0; i < formatNamesArr.length; i++) {
  root.println(formatNamesArr[i]);
}