This section describes how to use PCScript. It is divided into the following topics:
The PCScript command syntax is similar to that of object-oriented languages such as C++ or Java*. Each command consists of three parts—an object, method, and list of parameters:
object.method(parameters)
Objects are created and named in the Image Template file. PCScript commands use the object names specified in the Image Template file. For more information on object names, see Object Names in the Corda Builder™ User Guide.
The number of parameters for each command depends on the method. Each parameter is separated by the parameters delimiter (see paramDelimiter), which is usually a comma. For example, consider the addHoverText method for graph objects. This method accepts the following arguments—two numbers and a string. An addHoverText method call appears as follows:
graph.addHoverText(1, 2, This is the Hover Text)
Note: Strings in PCScript do not have quotation marks around them. Because of this, Corda Server™ cannot properly interpret strings with commas or semi-colons. To avoid this problem, change the parameter or item delimiters using paramDelimiter or itemDelimiter.
Note: PCScript commands are not case sensitive.
To help shorten the length of the PCScript command string, many methods accept more than one set of parameters per method call. In this case, each set of parameters is separated by the item delimiter (see itemDelimiter), which is usually a semi-colon. The syntax for such statements is
object.method(parameter_list [;parameter_list]*)
For example, consider a PCScript command string that contains several graph.addHoverText method calls, as in the example below:
graph.addHoverText(1-4,1,Hello World)
graph.addHoverText(1-4,2,Foo Bar)
graph.addHoverText(1-4,3,Goodbye)
These hover text items can be specified in one method call instead of three:
graph.addHoverText(1-4,1,Hello World;1-4,2,Foo Bar;1-4,3,Goodbye)
PCScript commands are sent to Corda Server via a PCScript command string, which is a string that contains all of the PCScript commands in the order that they are to be executed.
If desired, separate the commands with white space, but not by any other character.
The two examples below demonstrate two valid PCScript command strings, both of which contain the same commands.
PCScript Command String 1
graph.setCategories(Apples)map.setValues(Background;MI,89;VA,90)textbox.setText(Apple Graph)map.setValues(Cities;Austin,64)map.setDrilldown(Background;Maine,http://maine.gov)graph.setSeries(Andy,10;Julie,14;Bryan,11)graph.addhoverText(1,1-3,Apples are Good)graph.ddEnable(1,1-3,http://www.applepies.com)
PCScript Command String 2
graph.setCategories(Apples)map.setValues(Background;MI,89;VA,90)
textbox.setText(Apple Graph)map.setValues(Cities;Austin,64)graph.series(Andy,10;Julie,14;Bryan,11)graph.addHoverText(1,1-3,Apples are Good)
graph.ddEnable(1,1-3,http://www.applepies.com)map.setDrilldown(Background;Maine,http://maine.gov)
When requesting images from Corda Server via Corda Embedder, send a PCScript command string via the pcScript attribute.
Set this attribute to the PCScript command string, as shown in the example below.
Setting the PCScript Command String in Corda Embedder
String pcscript="textbox.setText(Hello World)map.setValues(Background;MI,89;VA,90)map.setDrilldown(Background;Maine,http://maine.gov)graph.setCategories(Apple)graph.setSeries(Andy;10)setSeries(Joe;15)setSeries(Jenny;20)";
graphImage.pcScript = pcscript;
When requesting images from Corda Server via HTTP requests, send the PCScript command string to Corda Server via the @_PCSCRIPT server command.
The code below shows a complete @_PCSCRIPT server command and PCScript command string.
@_PCSCRIPTtextbox.setText(Hello World)graph.setCategories(Apple)graph.setSeries(Andy;10)setSeries(Joe;15)setSeries(Jenny;20)map.setValues(Background;MI,89;VA,90)map.setDrilldown(Background;Maine,http://maine.gov)
Assuming Corda Server is running on port 2001 on a local machine, this @_PCSCRIPT command can then be used to generate a Corda image through the following HTTP request:
http://<server_address>:2001/?@_FILEexamples/map1.itxml@_PCSCRIPTtextbox.setText(Hello World)graph.setCategories(Apple)graph.setSeries(Andy;10)setSeries(Joe;15)setSeries(Jenny;20)map.setValues(Background;MI,89;VA,90)map.setDrilldown(Background;ME,http://maine.gov)
Remember the following issues when using special characters in PCScript code.
When using a semi-colon or comma in PCScript strings (such as in hover or note text), precede it with the escape character, backslash-pipe (\|). Otherwise, Corda Server cannot interpret the string properly. For example:
graph.addHoverText(1,1,This is a hover string\|; It uses a nice feature in PCScript\|, the ability to escape characters.)
The resulting hover text is "This is a hover string; It uses a nice feature in PCScript, the ability to escape characters."
PCScript supports Unicode characters in any string. Unicode characters can be delimited in several different ways:
Use "%u" followed by the four-digit, hexadecimal Unicode value for the character. For example:
title.setText(Wow! %u00B5chips!%u00AE)
The resulting text is:
Wow! µchips!
Note: In order for certain Unicode characters to display, such as special characters for international fonts, use a font that supports those characters. For more information about fonts, see Fonts and Languages in the Corda 7 Install and Administration manual.
Use &# followed by the decimal value for the character and a semi-colon. For example, £ generates the Pound Sterling currency symbol (£). This is standard XML notation.
Use &#x followed by the hexadecimal value for the character and a semi-colon. For example, £ generates the Pound Sterling currency symbol (£). This is standard XML notation.
Note: Unicode characters can also be encoded in ITXML using any of these notations.