A Javascript library for viewing spectra. While designed primarily for NMR spectra, it can be used for any XY plot.
For the latest documentation, download the repository and open the following file: docs/index.html
Demos of the various JSV features can be found in the demo directory.
Note, the demos may not work with Google Chrome due to a security issue opening local files. To get around this close Chrome and open it again from the command line:
# On macOS
open /Applications/Google\ Chrome.app --args --disable-web-security \
--allow-file-access-from-files
# Or use the included script
./script/open_chrome.sh
<script src='javascript/d3.v3.min.js'></script>
<script src='javascript/jspectra_viewer.js'></script>
<link rel="stylesheet" href="stylesheets/jspectra_viewer.css" />
Create a container for the viewer in HTML:
<div id='my-spectra'></div>
Create viewer:
sv = new JSV.SpectraViewer('#my-spectra', {
height: 450,
width: 850,
axis_y_lock: true,
axis_y_show: true,
axis_x_label: 'ppm'
});
sv.flash('Loading...')
See SpectraViewer for details about additional options.
Add an XY plot:
sv.add_spectrum(
{
id:'spectrum',
name: 'Spectrum',
xy_line: xy_data
},
{color: '#00F'}
);
The XY data is an object with x and y arrays:
xy_data = { x: [0, 1, 2], y: [0, 2, 4] };
Additional data formats are described in SpectraViewer.add_spectrum.
OLD FOMRAT (deprecated): The XY data is an array of xy points:
xy_data = [{x:0, y:0}, {x:1, y:2}, {x:2, y:4}];
All JSV classes and utility functions are accessed through the JSV namespace:
merged = JSV.merge({a:1, b:1}, {b:2, c:3}); // => {a:1, b:2, c:3}
If a JSV object already exists, you can use the full name of JSpectraViewer instead:
merged = JSpectraViewer.merge({a:1, b:1}, {b:2, c:3}); // => {a:1, b:2, c:3}
To ease in development, the JSV source code is broken into several files in "/dev". The compiled JSV file "/src/jspectra_viewer.js" is built using the following command:
./script/build.sh
This command will also build the help documentation in "/docs".
Action | Command |
---|---|
Zoom In/Out X Axis | Scroll wheel |
Zoom In/Out Y Axis | Alt/Option Key + Scroll wheel |
Zoom In on Area | Alt/Option Key + Click and Drag around area |
Zoom Out Completely | Alt/Option Key + Click once anywhere on viewer. |
Move Around | Click and Drag |
Action | Command |
---|---|
Move Around | Click and Drag grey selection box |
Zoom In on Area | Click on unselected region and drag around new selection |
Zoom Out Completely | Click once anywhere in unselected region |
Alter Zoomed Area | Click and Drag on sides of grey selection box |