JSPython - trace, debug and see results
Output results to the console​
print("Hello World!") # Print to output console
# Prints current execution context to the output console
print(' * current context => ', getExecutionContext())
Assert​
Run assertions
assert("My Test 1", 5 == 10, "Testing falsy assertion")
assert("My Test 2", 5 == 5, "Testing success assertion")
return showAsserts()
Share data between calls​
session​
session You can cache values between calls in a session
variable. It has the same lifetime as window
variable in the browser
# Save and restore data between "Runs" in a session object
if session.someData == null:
session.someData = "some value" # or heavy load operation
print(session.someData)
app (localStorage)​
app
stores value in a localstorage
- so, that is available
# Save and restore data in `localStorage` object
if app.someData == null:
app.someData = "some value" # or heavy load operation
print(app.someData)
Show results​
You can visualize any variable in the Results Panel
as an interactive grid or chart
data = [
{color: "blue", value: 10},
{color: "yellow", value: 20},
{color: "red", value: 15},
{color: "black", value: 25}
]
in Object Explorer​
# Will add a tab to the results panel
showInObjectExplorer(data, "Tab title")
# or last return statement will be visualized
return data
in a Data Grid​
createGridTab("Countries table").show(data)
plot chart​
countries = "US,Canada,Mexico,Germany,UK,France,Italy,Japan,Korea,China".split(",")
data = []
for country in countries:
item = {}
item.country = country
item.sales = Math.random() * 10000 + 1000
item.expenses = Math.random() * 5000 + 1000
item.downloads = Math.round(Math.random() * 100000)
data.push(item)
# you can provide chartType for each series
# chartTypes: Column | Bar | Scatter | Line | LineSymbols | Area | Spline | SplineSymbols | SplineArea
createChartTab("Countries Chart")
.x("country")
.yAxis(
r =>
r.title = "Sales/Expenses (US$ k)"
r.format = "n0,"
)
.y("sales", r => r.chartType = "Column")
.y("expenses", r => r.chartType = "Column")
.ySecondaryAxis(
r =>
r.min = 0
r.format = "n0,"
r.title = "Downloads (k)"
)
.y("downloads", r => r.chartType = "LineSymbols")
.plot(data)
Notifications​
Different kind of notifications
notify("Notification message")
notify("Warning message", "Warning")
alert("Alert message")