Skip to content

DM-7017 Firefly documentation for Camera team #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,34 @@ You may include this jar into your project to build advanced astronomy web appli

In a terminal, cd into the `firefly` directory, then run:

$ gradle :fftools:war
$ gradle :firefly:war

This generates fftools.war located at ./build/lib/.
This generates firefly.war located at ./build/lib/.
Simply drop this file into your $CATALINA_HOME/webapps/ directory to deploy it.
$CATALINA_HOME is your Tomcat server installation directory.

Goto http://localhost:8080/fftools/ to launch Firefly Viewer.
Goto http://localhost:8080/firefly/ to launch Firefly Viewer.


## More Docs

####Firefly Tools JavaScript API overview
[see fftools-api-overview.md](docs/fftools-api-overview.md)
See [firefly-api-overview.md](docs/firefly-api-overview.md)
(Deprecated [docs/fftools-api-overview.md](docs/fftools-api-overview.md))

####Firefly Tools Remote API using Python overview
[see firefly-python-wrapper.md](docs/firefly-python-wrapper.md)
See [firefly-python-wrapper.md](docs/firefly-python-wrapper.md)

####Code Examples Using Firefly Tools
[see fftools-api-code-examples.md](docs/fftools-api-code-examples.md)
See [firefly-api-code-examples.md](docs/firefly-api-code-examples.md)
(Deprecated [docs/fftools-api-code-examples.md](docs/fftools-api-code-examples.md))

####Setting up the Server correctly for FITS files
[see server-settings-for-fits-files.md](docs/server-settings-for-fits-files.md)
See [server-settings-for-fits-files.md](docs/server-settings-for-fits-files.md)

####Changing the Firefly runtime environment
[see firefly-environment.md](docs/firefly-environment.md)
See [firefly-environment.md](docs/firefly-environment.md)

####Adding external task launcher or Python Launcher to Firefly
[see firefly-python-launcher.md](docs/firefly-external-task-launcher.md)
See [firefly-python-launcher.md](docs/firefly-external-task-launcher.md)

132 changes: 132 additions & 0 deletions docs/firefly-api-code-examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
## Code Examples Using Firefly Tools

- [Image FITS Viewer](image-fits-viewer)
- [FITS Viewers in a group](fits-viewers-in-a-group)
- [Tracking the mouse](tracking-the-mouse)
- [Tracking the selection](tracking-the-selection)

###Starting Firefly Tools in JavaScript
Firefly Tools are loaded when you load`firefly_loader.js` from a server of your choice. For example, to load Firefly Tools from your local server, include the following declaration in your HTML file:

```html
<script type="text/javascript" language="javascript" src="http://localhost:8080/fftools/firefly_loader.js">
```

Your html document must define some divs, where you will load the viewer widgets, and `onFireflyLoaded()` function.

When Firefly Tools completes loading, it calls `onFireflyLoaded()` JavaScript function. This is where you create Firefly components and place them into HTML `<div>` elements with specified IDs.

The following are several examples of what can be done in the `onFireflyLoaded()` function. All test data can be found at `http://web.ipac.caltech.edu/staff/roby/demo`.

###Image FITS Viewer
Create an image viewer and place it into the `<div>` id `plotHere`.

```html
<div id="plotHere" style="width: 350px; height: 350px;"></div>
```

```js
function onFireflyLoaded() {
firefly.showImage('plotHere', {
URL : 'http://web.ipac.caltech.edu/staff/roby/demo/wise-m31-level1-3.fits',
Title : 'Example FITS Image',
ColorTable : 16,
RangeValues : firefly.util.image.RangeValues.serializeSimple('Sigma',-2,8,'Linear')
});
```


###FITS Viewers in a group
In this example, we create four image viewers. Each belong to the same group `wise-group`. We then set some global parameters so all the plots display the same. Now we plot each of the four images by specifying the URL of the FITS file. By doing this, all the plotting controls will work on all four images simultaneously.


```html
<div style="white-space: nowrap;">
<div id="w1" style="display:inline-block; width: 250px; height: 250px; border: solid 1px;"></div>
<div id="w2" style="display:inline-block; width: 250px; height: 250px; border: solid 1px;"></div>
<div id="w3" style="display:inline-block; width: 250px; height: 250px; border: solid 1px;"></div>
<div id="w4" style="display:inline-block; width: 250px; height: 250px; border: solid 1px;"></div>
</div>
```

```js
function onFireflyLoaded() {
firefly.setGlobalImageDef({ ZoomType : 'TO_WIDTH',
ColorTable : 8,
ZoomToWidth : 250 });
w1.showImage('w1', { URL : 'http://web.ipac.caltech.edu/staff/roby/demo/wise-m51-band1.fits',
Title: 'Wise band 1', plotGroupId : 'wise-group' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title: 'Wise band 1', plotGroupId : 'wise-group' });

for all the titles with WISE data, lets use all caps WISE.

w2.showImage('w2', { URL : 'http://web.ipac.caltech.edu/staff/roby/demo/wise-m51-band2.fits',
Title: 'Wise band 2', plotGroupId : 'wise-group' });
w3.showImage('w3', { URL : 'http://web.ipac.caltech.edu/staff/roby/demo/wise-m51-band3.fits',
Title: 'Wise band 3', plotGroupId : 'wise-group' });
w4.showImage('w4', { URL : 'http://web.ipac.caltech.edu/staff/roby/demo/wise-m51-band4.fits',
Title: 'Wise band 4', plotGroupId : 'wise-group' });
}
```

###Tracking the mouse

The following example will plot a fits image then add a callback to get the mouse readout and log it to the console.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following example will plot a fits image then add a callback to get the mouse readout and log it to the console.

For all the mention of FITS data, lets use all caps FITS


```html
<div id="plotHere" style="width: 500px; height: 500px;"></div>
```

```js
// callback on mouse readout
function onReadoutData(action) {
if (action.payload.hasValues) {
// readoutItems contain j2000, image, screen points and other info
console.log(action.payload.readoutItems.imagePt);
}
}
function onFireflyLoaded() {
const imageRequest = {
plotId: 'plotHere',
URL: 'http://web.ipac.caltech.edu/staff/roby/demo/wise-m51-band2.fits',
Title: 'Wise m51'
};
firefly.showImage('image_div', imageRequest);
// add a callback, which will be called for every READOUT_DATA action
// returned is the function to remove listener
const trackReadoutRemover = firefly.util.addActionListener(firefly.action.type.READOUT_DATA, onReadoutData);
}
```

###Tracking the selection

Firefly viewer allows to make the following selections:
- Area Select (square)
- Line Select
- Point Select
- Circle Select (*coming soon*)

The following example will plot a fits image then add a callback to get selection information and log it to the console.

```html
<div id="plotHere" style="width: 500px; height: 500px;"></div>
```

```js
const onPlotAttributeChange = function(action) {
console.log(action.payload.plotId);
// attribute key: 'ACTIVE_POINT','ACTIVE_DISTANCE', or 'SELECTION'
console.log(action.payload.attKey);
// value that defines the selection
console.log(action.payload.attValue);
}
function onFireflyLoaded() {
const imageRequest = {
plotId: 'plotHere',
URL: 'http://web.ipac.caltech.edu/staff/roby/demo/wise-m51-band2.fits',
Title: 'Wise m51'
};
firefly.showImage('image_div', imageRequest);
// turn on point selection
firefly.action.dispatchChangePointSelection('requester', true);
// add a callback, which will be called for every CHANGE_PLOT_ATTRIBUTE action
// returned is the function to remove listener
const trackSelectionRemover = firefly.util.addActionListener(firefly.action.type.CHANGE_PLOT_ATTRIBUTE, onPlotAttributeChange);
}
```
Loading