Skip to content

Commit e9be089

Browse files
committed
DM 8208
- moved getJSONFromTask to ffapi-pylaunch-test.html, added tests for image and table - updated external task launcher documentation
1 parent 98ceafb commit e9be089

File tree

4 files changed

+110
-65
lines changed

4 files changed

+110
-65
lines changed

docs/firefly-external-task-launcher.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,20 @@ A sample javascript, which builds up on the examples below is in
105105
Create an image viewer and place it into the `<div>` id `plotHere`.
106106
107107
```html
108-
<div id="plotHere" style="width: 350px; height: 350px;"></div>
108+
<div id="imageHere" style="width: 350px; height: 350px;"></div>
109109
```
110110
111111
```js
112112
function onFireflyLoaded() {
113-
var iv2= firefly.makeImageViewer("plotHere");
114-
iv2.plot({
115-
"id" :"FileFromExternalTask",
116-
"launcher" :"python",
117-
"task" :"someImageTask",
118-
"taskParams" : {"p1":1,"p2":2},
119-
"Title" :"Example FITS Image'",
120-
"ColorTable" :"16",
121-
"RangeValues":firefly.serializeRangeValues("Sigma",-2,8,"Linear")
122-
});
113+
var req = {
114+
id : 'FileFromExternalTask',
115+
launcher : 'python',
116+
task : 'someImageTask',
117+
taskParams : {p1:1,p2:2},
118+
Title : 'FITS from Python task',
119+
ColorTable : 2
120+
};
121+
firefly.showImage('imageHere', req);
123122
}
124123
```
125124
@@ -135,12 +134,11 @@ The table is plotted in the `<div>` id `tableHere`.
135134
136135
```js
137136
function onFireflyLoaded() {
138-
var tableData= { "processor" : "TableFromExternalTask",
139-
"launcher" : "python",
140-
"task" : "TestTask3",
141-
"taskParams" : { "param1" : "first arg", "param2" : "second arg" }
142-
};
143-
firefly.showTable(tableData, "tableHere");
137+
var tblReq = firefly.util.table.makeTblRequest('TableFromExternalTask', 'Table from Python task',
138+
{ launcher : 'python', task : 'TableTask', taskParams : {p1: 1, p2: 2} }, // search parameters
139+
{ pageSize: 15} // table options
140+
);
141+
firefly.showTable('tableHere', tblReq);
144142
}
145143
```
146144
@@ -157,21 +155,23 @@ In this example, we get the histogram data from an exernal task and feed them to
157155
158156
```js
159157
function onFireflyLoaded() {
160-
var launcher = 'python';
161-
var task = 'JsonTaskToGetHistogramData';
162-
var taskParams = { 'numbins': bins };
163-
firefly.getJsonFromTask(launcher, task, taskParams)
164-
.then(
165-
function (histdata) {
166-
firefly.showHistogram(
167-
{'descr' : 'Histogram data returned from python JSON task',
168-
'binColor' : '#3d3033',
169-
'height' : 350,
170-
'data': histdata}, 'chartHere');
171-
}
172-
).catch(function (reason) {
173-
console.log('Error fetching JSON data from '+launcher+' task '+task+': '+reason);
174-
}
175-
);
158+
var launcher = 'python';
159+
var task = 'JsonTaskToGetHistogramData';
160+
var taskParams = {'numbins': 10};
161+
firefly.getJsonFromTask(launcher, task, taskParams)
162+
.then(function (histdata) {
163+
console.log('Returned JSON: ' + JSON.stringify(histdata));
164+
firefly.util.renderDOM("chartHere", firefly.ui.Histogram,
165+
{
166+
desc: 'Histogram data from Python JSON task',
167+
binColor: '#3d3033',
168+
height: 350,
169+
data: histdata
170+
});
171+
})
172+
.catch(function (reason) {
173+
console.error('Error fetching JSON data from ' + launcher + ' task ' + task + ': ' + reason);
174+
document.getElementById('chartHere').innerHTML = '<p style="color:red">'+reason+'</p>';
175+
});
176176
}
177177
```

src/firefly/html/demo/ffapi-highlevel-charttest.html

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ <h2>
2727
<br/><br/>
2828
<div id="xyplotHere" style="width: 800px; height: 550px; border: solid 1px;"></div>
2929

30-
<h3>Histogram with JSON data from a Python task</h3>
31-
<div id="jsonDataHistogram" style="width: 800px; height: 350px; border: solid 1px;"></div>
32-
33-
3430
<script type="text/javascript">
3531
{
3632
onFireflyLoaded= function(firefly) {
@@ -95,31 +91,6 @@ <h3>Histogram with JSON data from a Python task</h3>
9591
};
9692
firefly.showXYPlot('xyplotHere', chartParams);
9793

98-
// show histogram, generated by firefly/python/SamplePythonLauncher.py
99-
// check console for errors, if it does not show up
100-
var launcher = 'python';
101-
var task = 'JsonTaskToGetHistogramData';
102-
var bins = 25;
103-
104-
var taskParams = {'numbins': bins};
105-
firefly.getJsonFromTask(launcher, task, taskParams)
106-
.then(function (histdata) {
107-
console.log('Returned JSON: ' + JSON.stringify(histdata));
108-
firefly.util.renderDOM("jsonDataHistogram", firefly.ui.Histogram,
109-
{
110-
'descr': 'Histogram data returned from python JSON task',
111-
'binColor': '#3d3033',
112-
'height': 350,
113-
'data': histdata
114-
});
115-
116-
}
117-
).catch(function (reason) {
118-
console.error('Error fetching JSON data from ' + launcher + ' task ' + task + ': ' + reason);
119-
document.getElementById('jsonDataHistogram').innerHTML = '<p style="color:red">'+reason+'</p>';
120-
}
121-
);
122-
12394
}
12495
}
12596

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!DOCTYPE html>
2+
3+
<!--
4+
~ License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
5+
-->
6+
7+
<!--
8+
This is a test for Python (external task) launcher.
9+
Firefly supports getting JSON data, table, or image from an external task
10+
-->
11+
<html lang="en">
12+
<head>
13+
<meta charset="UTF-8">
14+
<title>Testing getJSONFromTask</title>
15+
</head>
16+
<body>
17+
<div id="chartHere" style="display:inline-block; width: 800px; height: 350px;
18+
border: solid 1px;"></div>
19+
<br><br>
20+
<div id="tableHere" style="display:inline-block; width: 800px; height: 350px;
21+
border: solid 1px;"></div>
22+
<br><br>
23+
<div id="imageHere" style="width: 350px; height: 350px;"></div>
24+
</body>
25+
26+
<script type="text/javascript">
27+
{
28+
onFireflyLoaded = function (firefly) {
29+
30+
// json - show histogram, generated by firefly/python/SamplePythonLauncher.py
31+
var launcher = 'python';
32+
var task = 'JsonTaskToGetHistogramData';
33+
var taskParams = {'numbins': 10};
34+
firefly.getJsonFromTask(launcher, task, taskParams)
35+
.then(function (histdata) {
36+
console.log('Returned JSON: ' + JSON.stringify(histdata));
37+
firefly.util.renderDOM("chartHere", firefly.ui.Histogram,
38+
{
39+
desc: 'Histogram data returned from Python JSON task',
40+
binColor: '#3d3033',
41+
height: 350,
42+
data: histdata
43+
});
44+
})
45+
.catch(function (reason) {
46+
console.error('Error fetching JSON data from ' + launcher + ' task ' + task + ': ' + reason);
47+
document.getElementById('chartHere').innerHTML = '<p style="color:red">'+reason+'</p>';
48+
});
49+
50+
// table - show table, generated by firefly/python/SamplePythonLauncher.py
51+
var tblReq = firefly.util.table.makeTblRequest('TableFromExternalTask', 'Table from Python task',
52+
{ launcher : 'python', task : 'TableTask', taskParams : {p1: 1, p2: 2} }, // search parameters
53+
{ pageSize: 15} // table options
54+
);
55+
firefly.showTable('tableHere', tblReq);
56+
57+
// image - show FITS image, generated by firefly/python/SamplePythonLauncher.py
58+
var req = {
59+
id : 'FileFromExternalTask',
60+
launcher : 'python',
61+
task : 'someImageTask',
62+
taskParams : {p1:1,p2:2},
63+
Title : 'FITS from Python task',
64+
ColorTable : 2
65+
};
66+
firefly.showImage('imageHere', req);
67+
}
68+
}
69+
</script>
70+
71+
<script type="text/javascript" src="../firefly_loader.js"></script>
72+
73+
74+
</html>

src/firefly/js/tables/TableUtil.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const LSSTQueryPID = 'LSSTCataLogSearch';
3131
* @param {object} [params] the parameters to include with this request.
3232
* @param {TableRequest} [options] more options. see TableRequest for details.
3333
* @returns {TableRequest}
34-
* @pubic
34+
* @public
3535
* @func makeTblRequest
3636
* @memberof firefly.util.table
3737
*/
@@ -52,9 +52,9 @@ export function makeTblRequest(id, title, params={}, options={}) {
5252
* @param {string} [alt_source] use this if source does not exists.
5353
* @param {TableRequest} [options] more options. see TableRequest for details.
5454
* @returns {TableRequest}
55-
* @pubic
55+
* @public
5656
* @func makeFileRequest
57-
* @memberof firefly.util.table
57+
* @memberof firefly.util.table
5858
*/
5959
export function makeFileRequest(title, source, alt_source, options={}) {
6060
const id = 'IpacTableFromSource';

0 commit comments

Comments
 (0)