Interactive interface for browsing global, full-resolution satellite imagery
Initial work on ColorBar complete with tests and docs
Mike McGann176303d784d1
diff --git a/build.xml b/build.xmlindex 6a03e9ad6..feae3c94d 100644--- a/build.xml+++ b/build.xml@@ -64,6 +64,8 @@<arg value="-s"/><arg value="Default"/><arg value="Worldview"/>+ <arg value="-img"/>+ <arg value="doc/Images"/></exec></target>diff --git a/dev/palette/colorBar/ColorBar.html b/dev/palette/colorBar/ColorBar.htmlnew file mode 100644index 000000000..099565fa1--- /dev/null+++ b/dev/palette/colorBar/ColorBar.html@@ -0,0 +1,29 @@+<?doctype html>+<html>+ <head>+ <title>Color Bars</title>+ <link rel="stylesheet" type="text/css" href="../../../css/palette.css"/>+ <link rel="stylesheet" type="text/css" href="ColorBar.css"/>++ <script type="text/javascript" src="../../../js/ext/jquery/jquery-1.6.4.js"></script>+ <script type="text/javascript" src="../../../js/ext/handlebars-1.0.rc.2/handlebars.js"></script>+ <script type="text/javascript" src="../../../js/component.js"></script>+ <script type="text/javascript" src="../../../js/Worldview.js"></script>+ <script type="text/javascript" src="../../../js/util.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/ColorRGBA.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/ColorHSL.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/StopRGB.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/Lookup.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/Palette.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/ColorBar.js"></script>++ <script type="text/javascript" src="ColorBar.js"></script>+ </head>+ <body>+ <h1>Color Bars</h1>+ <table id="colorBars">+ </table>+ </body>+</html>+\ No newline at end of filediff --git a/dev/palette/colorBar/colorBar.html b/dev/palette/colorBar/colorBar.htmldeleted file mode 100644index dde0d4bc1..000000000--- a/dev/palette/colorBar/colorBar.html+++ /dev/null@@ -1,346 +0,0 @@-<?doctype html>-<html>- <head>- <title>Palette</title>- <link rel="stylesheet" type="text/css" href="../../../css/palette.css"/>- <link rel="stylesheet" type="text/css" href="neo.css"/>-- <script type="text/javascript" src="../../../js/ext/jquery/jquery-1.6.4.js"></script>- <script type="text/javascript" src="../../../js/component.js"></script>- <script type="text/javascript" src="../../../js/util.js"></script>- <script type="text/javascript" src="../../../js/palette.js"></script>- <script type="text/javascript" src="../../../js/colorBar.js"></script>- <script type="text/javascript" src="neo.js"></script>- </head>- <body>- <h1>Palette Demo</h1>- <table>- <tr>- <td>- <div class="layer">- <span class="name">Black to White: 2 Bins</span>- <div>- <canvas class="palette" id="b2w-2"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Black to White: 3 Bins</span>- <div>- <canvas class="palette" id="b2w-3"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Black to White: 10 Bins</span>- <div>- <canvas class="palette" id="b2w-10"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Black to White: 100 Bins</span>- <div>- <canvas class="palette" id="b2w-100"></canavs>- </div>- </div>- </td>- </tr>-- <!-- Red to Green, RGB -->- <tr>- <td>- <div class="layer">- <span class="name">Red to Green, RGB: 2 Bins</span>- <div>- <canvas class="palette" id="r2g-rgb-2"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Red to Green, RGB: 3 Bins</span>- <div>- <canvas class="palette" id="r2g-rgb-3"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Red to Green, RGB: 10 Bins</span>- <div>- <canvas class="palette" id="r2g-rgb-10"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Red to Green, RGB: 100 Bins</span>- <div>- <canvas class="palette" id="r2g-rgb-100"></canavs>- </div>- </div>- </td>- </tr>-- <tr>- <td>- <div class="layer">- <span class="name">Red to Green, HSL: 2 Bins</span>- <div>- <canvas class="palette" id="r2g-hsl-2"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Red to Green, HSL: 3 Bins</span>- <div>- <canvas class="palette" id="r2g-hsl-3"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Red to Green, HSL: 10 Bins</span>- <div>- <canvas class="palette" id="r2g-hsl-10"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Red to Green, HSL: 100 Bins</span>- <div>- <canvas class="palette" id="r2g-hsl-100"></canavs>- </div>- </div>- </td>- </tr>-- <tr>- <td>- <div class="layer">- <span class="name">Red to Green, Alpha: 2 Bins</span>- <div>- <canvas class="palette" id="r2g-alpha-2"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Red to Green, Alpha: 3 Bins</span>- <div>- <canvas class="palette" id="r2g-alpha-3"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Red to Green, Alpha: 10 Bins</span>- <div>- <canvas class="palette" id="r2g-alpha-10"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Red to Green, Alpha: 100 Bins</span>- <div>- <canvas class="palette" id="r2g-alpha-100"></canavs>- </div>- </div>- </td>- </tr>-- <tr>- <td>- <div class="layer">- <span class="name">Green to Red: 2 Bins</span>- <div>- <canvas class="palette" id="g2r-2"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Green to Red: 3 Bins</span>- <div>- <canvas class="palette" id="g2r-3"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Green to Red: 10 Bins</span>- <div>- <canvas class="palette" id="g2r-10"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Green to Red: 100 Bins</span>- <div>- <canvas class="palette" id="g2r-100"></canavs>- </div>- </div>- </td>- </tr>-- <tr>- <td>- <div class="layer">- <span class="name">B-Y-R: 2 Bins</span>- <div>- <canvas class="palette" id="b2y2r-2"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">B-Y-R: 3 Bins</span>- <div>- <canvas class="palette" id="b2y2r-3"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">B-Y-R: 10 Bins</span>- <div>- <canvas class="palette" id="b2y2r-10"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">B-Y-R: 100 Bins</span>- <div>- <canvas class="palette" id="b2y2r-100"></canavs>- </div>- </div>- </td>- </tr>-- <tr>- <td>- <div class="layer">- <span class="name">B-Y-R: 2 Bins, Weighted</span>- <div>- <canvas class="palette" id="b2y2r-right-2"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">B-Y-R: 3 Bins, Weighted</span>- <div>- <canvas class="palette" id="b2y2r-right-3"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">B-Y-R: 10 Bins, Weighted</span>- <div>- <canvas class="palette" id="b2y2r-right-10"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">B-Y-R: 100 Bins, Weighted</span>- <div>- <canvas class="palette" id="b2y2r-right-100"></canavs>- </div>- </div>- </td>- </tr>-- <tr>- <td>- <div class="layer">- <span class="name">BGYR Solid: 2 Bins</span>- <div>- <canvas class="palette" id="bgyr-solid-2"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">BGYR Solid: 3 Bins</span>- <div>- <canvas class="palette" id="bgyr-solid-3"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">BGYR Solid: 10 Bins</span>- <div>- <canvas class="palette" id="bgyr-solid-10"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">BGYR Solid: 100 Bins</span>- <div>- <canvas class="palette" id="bgyr-solid-100"></canavs>- </div>- </div>- </td>- </tr>-- <tr>- <td>- <div class="layer">- <span class="name">Indexed: 2 Bins</span>- <div>- <canvas class="palette" id="indexed-2"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Indexed: 3 Bins</span>- <div>- <canvas class="palette" id="indexed-3"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">Indexed: 10 Bins</span>- <div>- <canvas class="palette" id="indexed-10"></canavs>- </div>- </div>- </td>- <td>- <div class="layer">- <span class="name">indexed: 100 Bins</span>- <div>- <canvas class="palette" id="indexed-100"></canavs>- </div>- </div>- </td>- </tr>-- <tr>- <td>- <div class="layer">- <span class="name">Hue, 0 - 359 degrees</span>- <div>- <canvas class="palette" id="circle"></canavs>- </div>- </div>- </td>- </tr>- </table>- </body>-</html>\ No newline at end of filediff --git a/dev/palette/colorBar/colorBar.js b/dev/palette/colorBar/colorBar.jsindex fbe120387..63d122ff6 100644--- a/dev/palette/colorBar/colorBar.js+++ b/dev/palette/colorBar/colorBar.js@@ -1,37 +1,54 @@-$(function() {- var ColorBar = SOTE.widget.palette.ColorBar;+$(function() {+ var ColorBar = Worldview.Visual.ColorBar;+ var palettes = [];+ var showBins = [2, 3, 10, 100];+b2w = {+ id: "b2w",+ name: "Black to White",stops: [{ at: 0.0, r: 0x00, g: 0x00, b: 0x00 },{ at: 1.0, r: 0xff, g: 0xff, b: 0xff }]};+ palettes.push(b2w);- r2g = {+ r2g_rgb = {+ id: "r2g_rgb",+ name: "Red to Green, RGB",+ interpolate: "rgb",stops: [{ at: 0.0, r: 0xff, g: 0x00, b: 0x00 },{ at: 1.0, r: 0x00, g: 0xff, b: 0x00 }]};+ palettes.push(r2g_rgb);r2g_rgb = {- interpolate: "rgb",+ id: "r2g_hsl",+ name: "Red to Green, HSL",+ interpolate: "hsl",stops: [{ at: 0.0, r: 0xff, g: 0x00, b: 0x00 },{ at: 1.0, r: 0x00, g: 0xff, b: 0x00 }]};-- r2g_hsl = {- interpolate: "hsl",+ palettes.push(r2g_rgb);++ g2r = {+ id: "g2r",+ name: "Green to Red",stops: [- { at: 0.0, r: 0xff, g: 0x00, b: 0x00 },- { at: 1.0, r: 0x00, g: 0xff, b: 0x00 }+ { at: 0.0, r: 0x00, g: 0xff, b: 0x00 },+ { at: 1.0, r: 0xff, g: 0x00, b: 0x00 }]};+ palettes.push(g2r);r2g_alpha = {+ id: "r2g_alpha",+ name: "10% Cutoffs",min: 0.1,max: 0.9,stops: [@@ -39,263 +56,104 @@ $(function() {{ at: 1.0, r: 0x00, g: 0xff, b: 0x00 }]};-- g2r = {- stops: [- { at: 0.0, r: 0x00, g: 0xff, b: 0x00 },- { at: 1.0, r: 0xff, g: 0x00, b: 0x00 }- ]- };+ palettes.push(r2g_alpha);- b2y2r = {+ byr = {+ id: "byr",+ name: "Blue-Yellow-Red",stops: [{ at: 0.0, r: 0x00, g: 0x00, b: 0xff },{ at: 0.5, r: 0xff, g: 0xff, b: 0x00 },{ at: 1.0, r: 0xff, g: 0x00, b: 0x00 }]};-- b2y2r_right = {+ palettes.push(byr);++ byr_right = {+ id: "byr_right",+ name: "Yellow at 80%",stops: [{ at: 0.0, r: 0x00, g: 0x00, b: 0xff },{ at: 0.8, r: 0xff, g: 0xff, b: 0x00 },{ at: 1.0, r: 0xff, g: 0x00, b: 0x00 }]};+ palettes.push(byr_right);bgyr_solid = {+ id: "bgyr_solid",+ name: "BGYR Solid",type: "solid",stops: [{ at: 0.0, r: 0x00, g: 0x00, b: 0xff },{ at: 0.6, r: 0x00, g: 0xff, b: 0x00 },{ at: 0.8, r: 0xff, g: 0xff, b: 0x00 },- { at: 1.0, r: 0xff, g: 0x00, b: 0x00 }+ { at: 0.95, r: 0xff, g: 0x00, b: 0x00 }]};+ palettes.push(bgyr_solid);circle = {+ id: "circle",+ name: "Hue Shortest",stops: [{ at: 0.0, r: 0xec, g: 0x1b, b: 0x1b }, // Hue 0 degrees{ at: 1.0, r: 0xec, g: 0x1b, b: 0x1e } // Hue 359 degrees]}-- indexed = {- type: "index",- stops: [- { at: 0, r: 0x00, g: 0x00, b: 0x00 },- { at: 2, r: 0xff, g: 0x00, b: 0x00 },- { at: 5, r: 0xff, g: 0x00, b: 0xff },- { at: 9, r: 0xff, g: 0xff, b: 0xff },+ palettes.push(circle);++ classified = {+ id: "classified",+ name: "Classified",+ table: [+ { r: 0x18, g: 0x18, b: 0x80 },+ { r: 0x21, g: 0x8a, b: 0x21 },+ { r: 0x32, g: 0xcd, b: 0x31 },+ { r: 0x9a, g: 0xcd, b: 0x32 },+ { r: 0x99, g: 0xf9, b: 0x97 },+ { r: 0x90, g: 0xbb, b: 0x8e },+ { r: 0xbc, g: 0x8e, b: 0x90 },+ { r: 0xf5, g: 0xde, b: 0xb4 },+ { r: 0xda, g: 0xeb, b: 0x9d },+ { r: 0xff, g: 0xd6, b: 0x00 }]}+ palettes.push(classified);- /* Black to White */- new ColorBar({- selector: "#b2w-2",- bins: 2,- palette: b2w- });- new ColorBar({- selector: "#b2w-3",- bins: 3,- palette: b2w- });- new ColorBar({- selector: "#b2w-10",- bins: 10,- palette: b2w- });- new ColorBar({- selector: "#b2w-100",- bins: 100,- palette: b2w- });+ var template = Handlebars.compile([+ '<td>',+ '<div class="layer">',+ '<span class="name">{{name}}: {{bins}} Bins</span>',+ '<div>',+ '<canvas class="palette" id="{{id}}-{{bins}}"></canavs>',+ '</div>',+ '</div>',+ '</td>'].join("\n"));- /** Red to Green, RGB */- new ColorBar({- selector: "#r2g-rgb-2",- bins: 2,- palette: r2g_rgb- });- new ColorBar({- selector: "#r2g-rgb-3",- bins: 3,- palette: r2g_rgb- });- new ColorBar({- selector: "#r2g-rgb-10",- bins: 10,- palette: r2g_rgb- });- new ColorBar({- selector: "#r2g-rgb-100",- bins: 100,- palette: r2g_rgb- });-- /** Red to Green, HSL */- new ColorBar({- selector: "#r2g-hsl-2",- bins: 2,- palette: r2g_hsl- });- new ColorBar({- selector: "#r2g-hsl-3",- bins: 3,- palette: r2g_hsl- });- new ColorBar({- selector: "#r2g-hsl-10",- bins: 10,- palette: r2g_hsl- });- new ColorBar({- selector: "#r2g-hsl-100",- bins: 100,- palette: r2g_hsl- });-- /* Red to Green, with Alpha */- new ColorBar({- selector: "#r2g-alpha-2",- bins: 2,- palette: r2g_alpha- });- new ColorBar({- selector: "#r2g-alpha-3",- bins: 3,- palette: r2g_alpha- });- new ColorBar({- selector: "#r2g-alpha-10",- bins: 10,- palette: r2g_alpha- });- new ColorBar({- selector: "#r2g-alpha-100",- bins: 100,- palette: r2g_alpha- });--- /** Green to Red */- new ColorBar({- selector: "#g2r-2",- bins: 2,- palette: g2r- });- new ColorBar({- selector: "#g2r-3",- bins: 3,- palette: g2r- });- new ColorBar({- selector: "#g2r-10",- bins: 10,- palette: g2r- });- new ColorBar({- selector: "#g2r-100",- bins: 100,- palette: g2r- });-- /* Blue to Yellow to Red */- new ColorBar({- selector: "#b2y2r-2",- bins: 2,- palette: b2y2r- });- new ColorBar({- selector: "#b2y2r-3",- bins: 3,- palette: b2y2r- });- new ColorBar({- selector: "#b2y2r-10",- bins: 10,- palette: b2y2r- });- new ColorBar({- selector: "#b2y2r-100",- bins: 100,- palette: b2y2r- });-- /* Blue to Yellow to Red - Mid to Right */- new ColorBar({- selector: "#b2y2r-right-2",- bins: 2,- palette: b2y2r_right- });- new ColorBar({- selector: "#b2y2r-right-3",- bins: 3,- palette: b2y2r_right- });- new ColorBar({- selector: "#b2y2r-right-10",- bins: 10,- palette: b2y2r_right- });- new ColorBar({- selector: "#b2y2r-right-100",- bins: 100,- palette: b2y2r_right- });-- /* Blue-Green-Yellow-Red Solid */- new ColorBar({- selector: "#bgyr-solid-2",- bins: 2,- palette: bgyr_solid- });- new ColorBar({- selector: "#bgyr-solid-3",- bins: 3,- palette: bgyr_solid- });- new ColorBar({- selector: "#bgyr-solid-10",- bins: 10,- palette: bgyr_solid- });- new ColorBar({- selector: "#bgyr-solid-100",- bins: 100,- palette: bgyr_solid- });-- /* Indexed */- new ColorBar({- selector: "#indexed-2",- bins: 2,- palette: indexed- });- new ColorBar({- selector: "#indexed-3",- bins: 3,- palette: indexed- });- new ColorBar({- selector: "#indexed-10",- bins: 10,- palette: indexed- });- new ColorBar({- selector: "#indexed-100",- bins: 100,- palette: indexed- });-- /* Hue Circle Test */- new ColorBar({- selector: "#circle",- bins: 100,- palette: circle- });---+ for ( var iPalette = 0; iPalette < palettes.length; iPalette++ ) {+ var palette = palettes[iPalette];+ var row = "";+ for ( var iBins = 0; iBins < showBins.length; iBins++ ) {+ var bins = showBins[iBins];+ row += template({+ id: palette.id,+ name: palette.name,+ bins: bins+ });+ }+ $("#colorBars").append("<tr>" + row + "</tr>");+ }++ for ( var iPalette = 0; iPalette < palettes.length; iPalette++ ) {+ var palette = palettes[iPalette];+ for ( var iBins = 0; iBins < showBins.length; iBins++ ) {+ var bins = showBins[iBins];+ ColorBar({+ selector: "#" + palette.id + "-" + bins,+ bins: bins,+ palette: palette+ });+ }+ }});diff --git a/dev/palette/neo/neo.html b/dev/palette/neo/neo.htmlindex f0b502148..19a20a87b 100644--- a/dev/palette/neo/neo.html+++ b/dev/palette/neo/neo.html@@ -3,15 +3,21 @@<head><title>NEO Palettes</title><link rel="stylesheet" type="text/css" href="../../../css/palette.css"/>- <link rel="stylesheet" type="text/css" href="neo.css"/>+ <link rel="stylesheet" type="text/css" href="NEO.css"/><script type="text/javascript" src="../../../js/ext/jquery/jquery-1.6.4.js"></script><script type="text/javascript" src="../../../js/ext/handlebars-1.0.rc.2/handlebars.js"></script><script type="text/javascript" src="../../../js/component.js"></script><script type="text/javascript" src="../../../js/util.js"></script>- <script type="text/javascript" src="../../../js/palette.js"></script>- <script type="text/javascript" src="../../../js/colorBar.js"></script>- <script type="text/javascript" src="neo.js"></script>+ <script type="text/javascript" src="../../../js/Worldview.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/ColorRGBA.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/ColorHSL.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/StopRGB.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/Lookup.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/Palette.js"></script>+ <script type="text/javascript" src="../../../js/Worldview/Visual/ColorBar.js"></script>+ <script type="text/javascript" src="NEO.js"></script></head><body><h1>NEO Palettes</h1>diff --git a/dev/palette/neo/neo.js b/dev/palette/neo/neo.jsindex c521352ea..e0206a579 100644--- a/dev/palette/neo/neo.js+++ b/dev/palette/neo/neo.js@@ -1,5 +1,5 @@$(function() {- var ColorBar = SOTE.widget.palette.ColorBar;+ var ColorBar = Worldview.Visual.ColorBar;var onLoad = function(data, textStatus, jqXHR) {var colorBarTemplate = Handlebars.compile([@@ -17,9 +17,9 @@ $(function() {name: entry.name,id: entry.id}));- new ColorBar({+ ColorBar({selector: "#" + entry.id,- bins: 256,+ bins: 255,palette: entry});}diff --git a/doc/Images/black_to_white_color_bar.png b/doc/Images/black_to_white_color_bar.pngnew file mode 100644index 000000000..ab3358010Binary files /dev/null and b/doc/Images/black_to_white_color_bar.png differdiff --git a/doc/NaturalDocs/Menu.txt b/doc/NaturalDocs/Menu.txtindex d92b4ec63..bcae76d5d 100644--- a/doc/NaturalDocs/Menu.txt+++ b/doc/NaturalDocs/Menu.txt@@ -56,8 +56,24 @@ Group: Code Reference {File: OpenLayers.Tile.Canvas (/Users/jmcgann/Code/Aptana/worldview/js/OpenLayers/Tile/Canvas.js)File: SOTE.util (/Users/jmcgann/Code/Aptana/worldview/js/util.js)- File: SOTE.widget.palette (/Users/jmcgann/Code/Aptana/worldview/js/palette.js)- File: SOTE.widget.palette.ColorBar (no auto-title, /Users/jmcgann/Code/Aptana/worldview/js/colorBar.js)+ File: Worldview (/Users/jmcgann/Code/Aptana/worldview/js/Worldview.js)++ Group: Worldview {++ File: Visual (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual.js)++ Group: Visual {++ File: ColorBar (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual/ColorBar.js)+ File: ColorHSL (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual/ColorHSL.js)+ File: ColorRGBA (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual/ColorRGBA.js)+ File: Lookup (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual/Lookup.js)+ File: Palette (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual/Palette.js)+ File: StopRGBA (/Users/jmcgann/Code/Aptana/worldview/js/Worldview/Visual/StopRGBA.js)+ } # Group: Visual++ } # Group: Worldview+} # Group: Code ReferenceGroup: Index {@@ -66,6 +82,7 @@ Group: Index {Class Index: ClassesConstant Index: ConstantsFunction Index: Functions+ Property Index: Properties} # Group: Indexdiff --git a/js/Worldview.js b/js/Worldview.jsnew file mode 100644index 000000000..7eff65c8d--- /dev/null+++ b/js/Worldview.js@@ -0,0 +1,21 @@+/**+ * Namespace: Worldview+ */+(function(ns) {++ ns.namespace = function() {+ var obj;+ for ( var i = 0; i < arguments.length; i++ ) {+ var list=(""+arguments[i]).split(".");+ obj = Worldview;+ for ( var j = 0; j < list.length; j++ ) {+ obj[list[j]] = obj[list[j]] || {};+ obj = obj[list[j]];+ }+ }+ return obj;+ }++})(window.Worldview = window.Worldview || {});++diff --git a/js/palette.js b/js/Worldview/Visual.jssimilarity index 52%rename from js/palette.jsrename to js/Worldview/Visual.jsindex e88c3da43..1d1b2c8c1 100644--- a/js/palette.js+++ b/js/Worldview/Visual.js@@ -10,67 +10,99 @@*//**- * Namespace: SOTE.widget.palette- *- * Client side adjusting of data display palettes.+ * Namespace: Worldview.Visual+ * Visualization of science data.*/-SOTE.namespace("SOTE.widget.palette");+Worldview.namespace("Visual");$(function() {// This namespace- var ns = SOTE.widget.palette;+ var ns = Worldview.Visual;// Namespace aliasesvar util = SOTE.util;+ //-------------------------------------------------------------------------+ // Public+ //-------------------------------------------------------------------------+/*** Constant: CHECKERBOARD- *- * A canvas pattern of a gray based checkerboard used to denote- * transparency.+ * A canvas pattern of a gray checkerboard used to denote transparency.*/ns.CHECKERBOARD = null;-+/*** Function: toLookup+ * Converts a <Palette> to a <Lookup>. The lookup table is generated+ * for a certain number of equally spaced bins. Each bin is assigned+ * a distance along the range and its color is determined by the stop+ * locations in the palette. The first bin is always at 0% and the last+ * bin is always at 100%.+ *+ * If the type is gradient, the color value will be interpolated from the+ * stops that it fits within. If it is before the first stop, it will be+ * the color of the first stop. If it is after the last stop, it will be+ * the color of the last stop. Colors can be interpolated in the HSL+ * color space (by default or if type is "hsl") or in the RGB color space+ * (if the type is "rgb"). If the type is "solid", the color will be equal+ * to the stop it rounds down to.+ *+ * Alpha values in the stop definitions are ignored. If the bin is not+ * within the min and max values, the alpha is set to zero, otherwise the+ * alpha is set to 0xff.+ *+ * Parameters:+ * bins - Number of entries that the output lookup table should contain+ * palette - The <Palette> to convert+ *+ * Returns:+ * A <Lookup>.*/- ns.toLookup = function(bins, palette) {+ ns.toLookup = function(bins, palette) {var stops = palette.stops;var lut = [];++ // Each bin in the sequence must be at the current stop or later.+ // Save the current index and not iterate through each time.var currentStop = 0;var min = palette.min || 0;var max = palette.max || 1;for ( var bin = 0; bin < bins; bin++ ) {- var distance;- if ( palette.type === "index" ) {- distance = bin;- } else { // palette.positions === "percentage"- distance = bin / (bins - 1);- }+ // Percentange this bin is located at along the range.+ var distance = bin / (bins - 1);+ // If the current distance is greater than the current stop,+ // keep advancing until that is not true.for ( var i = currentStop; i < stops.length; i++ ) {if ( distance <= stops[i].at ) {break;}}- currentStop = i;+ currentStop = i;++ // The bin is between these two stopsvar end = stops[util.clampIndex(stops, i)];var begin = stops[util.clampIndex(stops, i-1)];+ // Find out how far this bin in between the stopsvar segmentLength = end.at - begin.at;var segmentDistance = (segmentLength !== 0) ?(distance - begin.at) / segmentLength : 0;+ // Witin the cutoffs?if ( distance < min || distance > max ) {- lut.push({r: 0, g: 0, b: 0, a: 0});- } else if ( palette.type === "solid" || palette.type === "index" ) {+ lut.push(ns.ColorRGBA(0, 0, 0, 0));+ } else if ( palette.type === "solid" ) {+ // For solid colors, always pick the color of the beginning+ // stop unless we are at the very end.if ( segmentDistance < 1 ) {- lut.push({r: begin.r, g: begin.g, b: begin.b, a: 0xff});+ lut.push(ns.ColorRGBA(begin.r, begin.g, begin.b));} else {- lut.push({r: end.r, g: end.g, b: end.b, a: 0xff});+ lut.push(ns.ColorRGBA(end.r, end.g, end.b));}} else if ( palette.interpolate === "rgb" ) {lut.push(ns.rgbInterpolate(segmentDistance, begin, end));@@ -81,7 +113,20 @@ $(function() {return lut;}-+ /**+ * Function: rgbInterpolate+ * Interpolates a color value between two other colors via the RGB color+ * space. Alpha values are ignored and are always set to 0xff.+ *+ * Parameters:+ * percent - The distance between the two colors as a percentage in the+ * range of [0.0, 1.0].+ * begin - The beginning <ColorRGBA>+ * end - The ending <ColorRGBA>+ *+ * Returns:+ * The interpolated color as a <ColorRGBA>.+ */ns.rgbInterpolate = function(percent, begin, end) {return {r: Math.round(begin.r + (percent * (end.r - begin.r))),@@ -91,9 +136,23 @@ $(function() {}}- ns.hslInterpolate = function(percent, rgbBegin, rgbEnd) {- var hslBegin = ns.rgb2hsl(rgbBegin.r, rgbBegin.g, rgbBegin.b);- var hslEnd = ns.rgb2hsl(rgbEnd.r, rgbEnd.g, rgbEnd.b);+ /**+ * Function: hslInterpolate+ * Interpolates a color value between two other colors via the HSL+ * color space. Alpha values are ignored and are always set to 0xff.+ *+ * Parameters:+ * percent - The distance between the two colors as a percentage in the+ * range of [0.0, 1.0].+ * rgbBegin - The beginning <ColorRGBA>+ * rgbEnd - The ending <ColorRGBA>+ *+ * Returns:+ * The interpoalted color as a <ColorRGBA>.+ */+ ns.hslInterpolate = function(percent, rgbBegin, rgbEnd) {+ var hslBegin = ns.rgb2hsl(rgbBegin);+ var hslEnd = ns.rgb2hsl(rgbEnd);// Hue is a circle. Traverse the shortest route. If the distance// between the two endpoints is more than half the circle, add one@@ -101,9 +160,9 @@ $(function() {var distance = Math.abs(hslBegin.h - hslEnd.h);if ( distance > 0.5 ) {if ( hslBegin.h < hslEnd.h ) {- hslBegin += 1.0;+ hslBegin.h += 1.0;} else {- hslEnd += 1.0;+ hslEnd.h += 1.0;}}var h = hslBegin.h + (percent * (hslEnd.h - hslBegin.h));@@ -114,35 +173,34 @@ $(function() {if ( h > 1.0 ) {h -= 1.0;}- var result = ns.hsl2rgb(h, s, l);- result.a = 0xff;- return result;+ return ns.hsl2rgb(ns.ColorHSL(h, s, l));}/*** Function: rgb2hsl- ** Converts an RGB color value to HSL. Conversion formula* adapted from http://en.wikipedia.org/wiki/HSL_color_space.- * Assumes r, g, and b are contained in the set [0, 255] and- * returns h, s, and l in the set [0, 1].** See Also:* http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript** Parameters:- * r - The red color value- * g - The green color value- * b - The blue color value+ * color - The <ColorRGBA> value to convert.** Returns:- * The HSL representation as an object with h, s, and l properties.+ * The converted <ColorHSL> value.** Example:- * > >>> SOTE.widget.palette.rgb2hsl(10, 20, 30)- * > Object { h=0.5833333333333334, s=0.5, l=0.0784313725490196}+ * (begin code)+ * >>> Worldview.Visual.rgb2hsl({r: 10, g: 20, b: 30})+ * Object { h=0.5833333333333334, s=0.5, l=0.0784313725490196}+ * (end code)*/- ns.rgb2hsl = function(r, g, b) {+ ns.rgb2hsl = function(color) {+ var r = color.r;+ var g = color.g+ var b = color.b;+r /= 255, g /= 255, b /= 255;var max = Math.max(r, g, b), min = Math.min(r, g, b);var h, s, l = (max + min) / 2;@@ -160,33 +218,34 @@ $(function() {h /= 6;}- return {h: h, s: s, l: l};+ return ns.ColorHSL(h, s, l);}/*** Function: hsl2rgb- ** Converts an HSL color value to RGB. Conversion formula* adapted from http://en.wikipedia.org/wiki/HSL_color_space.- * Assumes h, s, and l are contained in the set [0, 1] and- * returns r, g, and b in the set [0, 255].** See Also:* http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript** Parameters:- * h - The hue- * s - The saturation- * l - The lightness+ * color - The <ColorHSL> to convert.** Returns:- * The RGB representation as an object with r, g, and b properties.+ * The converted <ColorRGBA> value.** Example:- * > >>> SOTE.widget.palette.hsl2rgb(0.5833, 0.5, 0.078)- * > Object { r=10, g=20, b=30 }+ * (begin code)+ * >>> Worldview.Visual.hsl2rgb({h: 0.5833, s: 0.5, l: 0.078})+ * Object { r=10, g=20, b=30 }+ * (end code)*/- ns.hsl2rgb = function(h, s, l) {+ ns.hsl2rgb = function(color) {+ var h = color.h;+ var s = color.s;+ var l = color.l;+var r, g, b;if ( s == 0 ) {@@ -208,13 +267,17 @@ $(function() {b = hue2rgb(p, q, h - 1/3);}- return {- r: Math.round(r * 255),- g: Math.round(g * 255),- b: Math.round(b * 255)- };+ return ns.ColorRGBA(+ Math.round(r * 255),+ Math.round(g * 255),+ Math.round(b * 255));}-++ //-------------------------------------------------------------------------+ // Private+ //-------------------------------------------------------------------------++ // Draws the default checkboard patternvar drawCheckerboard = function() {var size = 2;@@ -235,11 +298,11 @@ $(function() {ns.CHECKERBOARD = g.createPattern(canvas, "repeat");}+ // Static initializationvar init = function() {drawCheckerboard();}init();-});diff --git a/js/Worldview/Visual/ColorBar.js b/js/Worldview/Visual/ColorBar.jsnew file mode 100644index 000000000..993996736--- /dev/null+++ b/js/Worldview/Visual/ColorBar.js@@ -0,0 +1,158 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */++Worldview.namespace("Visual");++/**+ * Class: Worldview.Visual.ColorBar+ * Renders a <Palette> in a canvas. Color transitions are placed along the+ * x axis.+ *+ * Example:+ * (begin code)+ * var colorBar = Worldview.Visual.ColorBar({+ * selector: "#colorBarCanvas",+ * bins: 10,+ * palette: {+ * stops: [+ * { at: 0.0, r: 0x00, g: 0x00, b: 0x00 },+ * { at: 1.0, r: 0x00, g: 0x00, b: 0x00 }+ * ]+ * }+ * });+ * (end code)+ *+ * will render in the canvas as shown in the following image+ * (see black_to_white_color_bar.png)+ *+ */+Worldview.Visual.ColorBar = function(spec) {++ // This namespace+ var ns = Worldview.Visual;++ // The canvas to render in as a jQuery object+ var $canvas = null;++ // The canvas to render in as a canvas object+ var canvas = null;++ // Graphics drawing context for the canvas+ var g = null;++ //-------------------------------------------------------------------------+ // Public+ //-------------------------------------------------------------------------+ var self = {};++ /**+ * Property: background+ *+ * Canvas pattern to use as the background. If not specified,+ * <CHECKERBOARD> is used.+ */+ self.background = spec.background || ns.CHECKERBOARD;++ /**+ * Property: bins+ *+ * Maximum number of discrete color values. For example, if this value+ * is ten, only ten color values will be shown, evenly spaced through+ * the canvas. If not specified, this value is 255.+ */+ self.bins = spec.bins || 255;++ /**+ * Property: palette+ *+ * The <Palette> or <Lookup> to render in the canvas. If not specified, this+ * value is null and no palette will be rendered.+ */+ self.palette = spec.palette;++ /**+ * Constructor: ColorBar+ * Creates a new instance.+ *+ * Parameters:+ * spec - Accepts all properties as an associative array.+ * spec.selector - jQuery selector for the canvas to render in.+ *+ * Throws:+ * An error if the canvas element could not be found.+ */+ var init = function() {+ $canvas = $(spec.selector);+ if ( $canvas.length === 0 ) {+ throw "No such canavs element (" + spec.selector ++ ") for the ColorBar";+ }+ canvas = $canvas.get(0);++ // The canavs dimensions does not equal the element dimensions! Make+ // them the same or scaling will occur.+ canvas.width = $canvas.width();+ canvas.height = $canvas.height();++ g = canvas.getContext("2d");+ self.redraw();+ }++ /**+ * Method: redraw+ * Redraws the palette in the canvas. If palette is set to null, this+ * method only draws the background.+ */+ self.redraw = function() {+ drawBackground();+ if ( !self.palette ) {+ return;+ }++ // If a lookup is provided, just use that. Otherwise, convert the+ // palette definition to a lookup table.+ var lut = ( self.palette.table )+ ? self.palette.table+ : ns.toLookup(self.bins, self.palette);++ var binWidth = canvas.width / self.bins;++ // Each drawn stripe for the bin must be at least one pixel wide or+ // the background will leak through due to rounding errors.+ var stripeWidth = ( binWidth < 1 ) ? 1 : binWidth;++ for ( var bin = 0; bin < self.bins; bin++ ) {+ // Only draw if there is a lookup entry and it is not completely+ // transparent+ if ( lut[bin] && lut[bin].a !== 0 ) {+ // Always draw with no transparency+ g.fillStyle = "rgba(" ++ [lut[bin].r, lut[bin].g, lut[bin].b, 0xff].join() + ")";+ g.fillRect(Math.floor(bin * binWidth), 0,+ stripeWidth, canvas.height);+ }+ }+ }++ //-------------------------------------------------------------------------+ // Private+ //-------------------------------------------------------------------------+ var drawBackground = function() {+ g.fillStyle = self.background;+ g.fillRect(0, 0, canvas.width, canvas.height);+ }++ // Call constructor+ init();++ // Return public variables+ return self;+}diff --git a/js/Worldview/Visual/ColorHSL.js b/js/Worldview/Visual/ColorHSL.jsnew file mode 100644index 000000000..c9879ad8d--- /dev/null+++ b/js/Worldview/Visual/ColorHSL.js@@ -0,0 +1,59 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */++Worldview.namespace("Visual");++/**+ * Class: Worldview.Visual.ColorHSL+ * Represents a color in the HSL color space.+ *+ * Example:+ * For a red color+ *+ * (begin code)+ * var color = Worldview.Visual.ColorHSL(0x00, 0xff, 0xff);+ * (end code)+ *+ * Constructor: ColorHSL+ * Creates a new instance.+ *+ * Parameters:+ * h - The hue value in the range of [0.0, 1.0]. If not specified, this+ * value is zero.+ * s - The saturation value in the range of [0.0, 1.0]. If not speecified, this+ * value is zero.+ * l - The lightness value in the range of [0.0, 1.0]. If not specified, this+ * value is zero.+ */+Worldview.Visual.ColorHSL = function(h, s, l) {++ return {+ /**+ * Property: h+ * The hue value in the range of [0.0, 1.0].+ */+ h: h || 0,++ /**+ * Property: s+ * The saturation value in the range of [0.0, 1.0].+ */+ s: s || 0,++ /**+ * Property: l+ * The lightness value in the range of [0.0, 1.0].+ */+ l: l || 0,+ }++};+diff --git a/js/Worldview/Visual/ColorRGBA.js b/js/Worldview/Visual/ColorRGBA.jsnew file mode 100644index 000000000..b27d10361--- /dev/null+++ b/js/Worldview/Visual/ColorRGBA.js@@ -0,0 +1,68 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */++Worldview.namespace("Visual");++/**+ * Class: Worldview.Visual.ColorRGBA+ * Represents a color in the RGBA color space.+ *+ * Example:+ * For a yellow color+ *+ * (begin code)+ * var color = Worldview.Visual.ColorRGBA(0xff, 0xff, 0x00, 0xff);+ * (end code)+ *+ * Constructor: ColorRGB+ * Creates a new instance.+ *+ * Parameters:+ * r - The red color value in the range of [0, 0xff]. If not specified,+ * this value is zero.+ * g - The green color value in the range of [0, 0xff]. If not specified,+ * this value is zero.+ * b - The blue color value in the range of [0, 0xff]. If not specified,+ * this value is zero.+ * a - The alpha color value in the range of [0, 0xff]. Zero is+ * transparent, 0xff is opaque. If not specified, this value is 0xff.+ */+Worldview.Visual.ColorRGBA = function(r, g, b, a) {++ return {+ /**+ * Property: r+ * Red color value in the range of [0, 0xff].+ */+ r: r || 0,++ /**+ * Property: g+ * Green color value in the range of [0, 0xff].+ */+ g: g || 0,++ /**+ * Property: b+ * Blue color value in the range of [0, 0xff].+ */+ b: b || 0,++ /**+ * Property: a+ * Alpha color value int he range of [0,0xff]. Zero is transparent,+ * 0xff is opaque.+ */+ a: ( a === undefined ) ? 0xff : a+ };+};++diff --git a/js/Worldview/Visual/Lookup.js b/js/Worldview/Visual/Lookup.jsnew file mode 100644index 000000000..3a8cb6367--- /dev/null+++ b/js/Worldview/Visual/Lookup.js@@ -0,0 +1,61 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */++Worldview.namespace("Visual");++/**+ * Class: Worldview.Visual.Lookup+ * Indexed based color lookup table.+ *+ * Constructor: Lookup+ * Creates a new instance.+ *+ * Parameters:+ * spec - Accepts all properties as an associative array.+ *+ * Example:+ * (begin code)+ * var lookup = Worldview.Visual.Lookup({+ * id: "my_lookup",+ * name: "My Lookup",+ * table: [+ * { r: 0x01, g: 0x02, b: 0x03, a: 0x04 },+ * { r: 0x05, g: 0x06, b: 0x07, a: 0x08 }+ * ]+ * });+ */+Worldview.Visual.Lookup = function(spec) {++ return {+ /**+ * Property: id+ *+ * Identifier for this lookup (optional).+ */+ id: spec.id || undefined,++ /**+ * Property: name+ *+ * Descriptive name for this lookup (optional).+ */+ name: spec.name || undefined,++ /**+ * Property: table+ *+ * Array that maps index values to <Worldview.Visual.ColorRGBA>+ * objects. For example, a value of 2 should use the color found at+ * table[2]. If not specified, this value is an empty array.+ */+ table: spec.table || [],+ }+}\ No newline at end of filediff --git a/js/Worldview/Visual/Palette.js b/js/Worldview/Visual/Palette.jsnew file mode 100644index 000000000..53368ac1b--- /dev/null+++ b/js/Worldview/Visual/Palette.js@@ -0,0 +1,113 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */++Worldview.namespace("Visual");++/**+ * Class: Worldview.Visual.Palette+ * Color palette defined by color stops. Each stop is located along the+ * available range as a percentage between zero and one.+ *+ * A gradient is applied between each stop. To use solid colors instead, set+ * the type property to solid. Gradients usually traverse through the HSL color+ * space. Set the interpolate property to rgb to go through the RGB color space+ * instead.+ *+ * Example:+ * To define a palette that is a gradient from black to white:+ * (begin code)+ * var palette = Worldview.Visual.Palette({+ * stops: [+ * { at: 0.0, r: 0x00, g: 0x00, b: 0x00 },+ * { at: 1.0, r: 0xff, g: 0xff, b: 0xff },+ * ]+ * });+ * (end code)+ *+ * To define a palette that is a gradient from red to green but passing+ * through blue half way through:+ * (begin code)+ * var palette = Worldview.Visual.Palette({+ * stops: [+ * { at: 0.0, r: 0xff, g: 0x00, b: 0x00 },+ * { at: 0.5, r: 0x00, g: 0xff, b: 0xff },+ * { at: 1.0, r: 0x00, g: 0xff, b: 0x00 },+ * ]+ * });+ * (end code)+ *+ */++Worldview.Visual.Palette = function(spec) {++ /**+ * Constructor: Worldview.Visual.Palette+ * Creates a new instance.+ *+ * Parameters:+ * spec - Accepts all properties as an associative array.+ */+ return {+ /**+ * Property: id+ * Identifier for this palette.+ */+ id: spec.id || undefined,++ /**+ * Property: name+ * Name for this palette.+ */+ name: spec.name || undefined,++ /**+ * Property: min+ * Minimum display value. Values below this percentage will be+ * transparent. Valid range is [0.0, 1.0].+ */+ min: spec.min || undefined,++ /**+ * Property: max+ * Maximum display value. Values above this percentage will be+ * transparent. Valid range is [0.0, 1.0].+ */+ max: spec.max || 1.0,++ /**+ * Property: type+ * Method used to compute colors between stops. Either "gradient" or+ * "solid". If set to "gradient", colors between each stop will+ * gradually shift color. If set to "solid", color changes+ * are absolute at each stop. If not specified, this value is set to+ * "gradient".+ */+ type: spec.type || "gradient",++ /**+ * Property: interpolate+ * Interpolation used for gradients. If set to "hsl", interpolation is+ * done in the HSL color space. If set to "rbg", interpolation is done+ * in the RGB color space. If not specified, this valueis set to "hsl".+ * This property has no effect if the type is not set to "gradient".+ */+ interpolate: spec.interpolate || "hsl",++ /**+ * Property: stops+ * Array of color stops of type <Worldview.Visual.StopRGB>. If not+ * specified, this value is set to an emtpy array.+ */+ stops: spec.stops || [],+ };++}+diff --git a/js/Worldview/Visual/StopRGBA.js b/js/Worldview/Visual/StopRGBA.jsnew file mode 100644index 000000000..e3a4f834c--- /dev/null+++ b/js/Worldview/Visual/StopRGBA.js@@ -0,0 +1,55 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */++Worldview.namespace("Visual");++/**+ * Class: Worldview.Visual.StopRGBA+ * Defines a color value at a percentage along a color range.+ *+ * Example:+ * For a red color stop at 40% along the range+ *+ * (begin code)+ * var stop = StopRGB(0.4, 0xff, 0x00, 0x00 });+ * (end code)+ *+ * Delegates to:+ * <ColorRGBA>+ *+ * Constructor: StopRGB+ * Creates a new instance.+ *+ * Parameters:+ * at - The percentage along the color range where this stop is located.+ * In the range of [0.0, 1.0].+ * r - The red color value in the range of [0, 0xff]. If not specified,+ * this value is zero.+ * g - The green color value in the range of [0, 0xff]. If not specified,+ * this value is zero.+ * b - The blue color value in the range of [0, 0xff]. If not specified,+ * this value is zero.+ * a - The alpha color value in the range of [0, 0xff]. Zero is+ * transparent, 0xff is opaque. If not specified, this value is 0xff.+ */+ Worldview.Visual.StopRGBA = function(at, r, g, b, a) {++ var self = ns.ColorRGBA(r, g, b, a);++ /**+ * Property: at+ * Percentage in the range of [0.0, 1.0]. If not defined, this value is+ * zero.+ */+ self.at = at || 0.0;++ return self;+}\ No newline at end of filediff --git a/js/colorBar.js b/js/colorBar.jsdeleted file mode 100644index 131fa1836..000000000--- a/js/colorBar.js+++ /dev/null@@ -1,77 +0,0 @@-/*- * NASA Worldview- *- * This code was originally developed at NASA/Goddard Space Flight Center for- * the Earth Science Data and Information System (ESDIS) project.- *- * Copyright (C) 2013 United States Government as represented by the- * Administrator of the National Aeronautics and Space Administration.- * All Rights Reserved.- */--/**- * Class: SOTE.widget.palette.ColorBar- *- * ColorBar class.- */-SOTE.widget.palette.ColorBar = function(spec) {-- var self = {};- var ns = SOTE.widget.palette;- var $canvas;- var canvas;- var g;-- self.checkerboard = ns.CHECKERBOARD;- self.bins = 255;- self.palette = null;-- /**- * Constructor: ColorBar- */- var init = function() {- $canvas = $(spec.selector);- if ( $canvas.length === 0 ) {- throw "No such element: " + spec.selector;- }- canvas = $canvas.get(0);- canvas.width = $canvas.width();- canvas.height = $canvas.height();-- g = canvas.getContext("2d");-- self.count = spec.count || 255;- self.checkerboard = spec.checkerboard || self.checkerboard;- self.palette = spec.palette || self.palette;- self.bins = spec.bins || self.bins;- $canvas.css("background", "#ff0000");- self.redraw();- }-- /**- * Method: redraw- */- self.redraw = function() {- drawBackground();- if ( !self.palette ) {- return;- }- var lut = ns.toLookup(self.bins, self.palette);- var binWidth = canvas.width / self.bins;- var stripeWidth = ( binWidth < 1 ) ? 1 : binWidth;- for ( var bin = 0; bin < self.bins; bin++ ) {- g.fillStyle = "rgba(" +- [lut[bin].r, lut[bin].g, lut[bin].b, lut[bin].a].join() + ")";- g.fillRect(Math.floor(bin * binWidth), 0,- stripeWidth, canvas.height);- }- }-- var drawBackground = function() {- g.fillStyle = self.checkerboard;- g.fillRect(0, 0, canvas.width, canvas.height);- }-- init();- return self;-}diff --git a/test/Worldview/Visual/testColorBar.js b/test/Worldview/Visual/testColorBar.jsnew file mode 100644index 000000000..12cec9e1d--- /dev/null+++ b/test/Worldview/Visual/testColorBar.js@@ -0,0 +1,116 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */+TestCase("Visual.ColorBar", {++ ns: null,++ width: null,+ height: null,++ canvas: null,++ g: null,+ pattern: null,++ setUp: function() {+ ns = Worldview.Visual;+ width = 10;+ height = 1;++ $(document.body).append("<canvas id='test-colorBar'></canvas>");+ $("#test-colorBar")+ .width(width)+ .height(height);++ canvas = $("#test-colorBar").get(0);+ canvas.width = width;+ canvas.height = height;++ g = canvas.getContext("2d");++ // Create a background pattern that is solid red+ $(document.body).append("<canvas id='test-background'></canvas");+ $("#test-background")+ .width(width)+ .height(height)++ var background = $("#test-background").get(0);+ background.width = width;+ background.height = height;++ bg = background.getContext("2d");+ bg.fillStyle = "rgb(255, 0, 0)";+ bg.fillRect(0, 0, width, height);++ pattern = g.createPattern(background, "repeat");+ },++ testEmpty: function() {+ var colorBar = ns.ColorBar({+ selector: "#test-colorBar",+ bins: 10,+ background: pattern+ });++ // Select a pixel in the middle and check that it is red+ var red = g.getImageData(width/2, height/2, 1, 1).data;+ assertEquals(0xff, red[0]);+ assertEquals(0x00, red[1]);+ assertEquals(0x00, red[2]);+ assertEquals(0xff, red[3]);+ },++ // Check to see that image data did get written+ testBlackToWhite: function() {+ var colorBar = ns.ColorBar({+ selector: "#test-colorBar",+ bins: 10,+ background: pattern,+ palette: {+ stops: [+ { at: 0.0, r: 0x00, g: 0x00, b: 0x00 },+ { at: 1.0, r: 0xff, g: 0xff, b: 0xff }+ ]+ }});++ var black = g.getImageData(0, 0, 1, 1).data;+ assertEquals(0x00, black[0]);+ assertEquals(0x00, black[1]);+ assertEquals(0x00, black[2]);+ assertEquals(0xff, black[3]);++ var white = g.getImageData(width - 1, 0, 1, 1).data;+ assertEquals(0xff, white[0]);+ assertEquals(0xff, white[1]);+ assertEquals(0xff, white[2]);+ assertEquals(0xff, white[3]);+ },++ // See if the background leaks through anywhere+ testLeakage: function() {+ var colorBar = ns.ColorBar({+ selector: "#test-colorBar",+ bins: 10,+ background: pattern,+ palette: {+ stops: [+ { at: 0.0, r: 0x00, g: 0x00, b: 0x00 },+ { at: 1.0, r: 0xff, g: 0xff, b: 0xff }+ ]+ }});++ var pixels = g.getImageData(0, 0, width, height).data;+ for ( var i = 0; i < pixels.length; i += 4 ) {+ assertNotEquals(0xff, pixels[0]);+ }+ },++});diff --git a/test/Worldview/Visual/testColorHSL.js b/test/Worldview/Visual/testColorHSL.jsnew file mode 100644index 000000000..b91e8363f--- /dev/null+++ b/test/Worldview/Visual/testColorHSL.js@@ -0,0 +1,35 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */+TestCase("Visual.ColorHSL", {++ ns: null,++ setUp: function() {+ ns = Worldview.Visual;+ },++ // Check that the default values are correct.+ testEmpty: function() {+ var color = ns.ColorHSL();+ assertEquals(0, color.h);+ assertEquals(0, color.s);+ assertEquals(0, color.l);+ },++ // Check that the color is correct with all values.+ testAll: function() {+ var color = ns.ColorHSL(1, 2, 3);+ assertEquals(1, color.h);+ assertEquals(2, color.s);+ assertEquals(3, color.l);+ }++});\ No newline at end of filediff --git a/test/Worldview/Visual/testColorRGBA.js b/test/Worldview/Visual/testColorRGBA.jsnew file mode 100644index 000000000..0f14180a5--- /dev/null+++ b/test/Worldview/Visual/testColorRGBA.js@@ -0,0 +1,46 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */+TestCase("Visual.ColorRGBA", {++ ns: null,++ setUp: function() {+ ns = Worldview.Visual;+ },++ // Check that the default values are correct.+ testEmpty: function() {+ var color = ns.ColorRGBA();+ assertEquals(0, color.r);+ assertEquals(0, color.g);+ assertEquals(0, color.b);+ assertEquals(0xff, color.a);+ },++ // Check that the color is correct with no alpha value.+ testNoAlpha: function() {+ var color = ns.ColorRGBA(1, 2, 3);+ assertEquals(1, color.r);+ assertEquals(2, color.g);+ assertEquals(3, color.b);+ assertEquals(0xff, color.a);+ },++ // Check that the color is correct with all values.+ testAll: function() {+ var color = ns.ColorRGBA(1, 2, 3, 4);+ assertEquals(1, color.r);+ assertEquals(2, color.g);+ assertEquals(3, color.b);+ assertEquals(4, color.a);+ }++});diff --git a/test/Worldview/Visual/testStopRGBA.js b/test/Worldview/Visual/testStopRGBA.jsnew file mode 100644index 000000000..9aca6acb0--- /dev/null+++ b/test/Worldview/Visual/testStopRGBA.js@@ -0,0 +1,39 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */+TestCase("Visual.StopRGBA", {++ ns: null,++ setUp: function() {+ ns = Worldview.Visual;+ },++ // Check that the default values are correct.+ testEmpty: function() {+ var stop = ns.StopRGBA();+ assertEquals(0, stop.at);+ assertEquals(0, stop.r);+ assertEquals(0, stop.g);+ assertEquals(0, stop.b);+ assertEquals(0xff, stop.a);+ },++ // Check that the specified values are correct.+ testAll: function() {+ var stop = ns.StopRGBA(1, 2, 3, 4, 5);+ assertEquals(1, stop.at);+ assertEquals(2, stop.r);+ assertEquals(3, stop.g);+ assertEquals(4, stop.b);+ assertEquals(5, stop.a);+ },++});\ No newline at end of filediff --git a/test/Worldview/palette/testToLookup.js b/test/Worldview/Visual/testToLookup.jssimilarity index 97%rename from test/Worldview/palette/testToLookup.jsrename to test/Worldview/Visual/testToLookup.jsindex 612fff800..ab86355f2 100644--- a/test/Worldview/palette/testToLookup.js+++ b/test/Worldview/Visual/testToLookup.js@@ -8,13 +8,13 @@* Administrator of the National Aeronautics and Space Administration.* All Rights Reserved.*/-TestCase("palette.toLookup", {+TestCase("Visual.toLookup", {ns: null,setUp: function() {// This namespace- ns = SOTE.widget.palette;+ ns = Worldview.Visual;},// Are the 2 bins the same as the begin and end stops?@@ -148,8 +148,7 @@ TestCase("palette.toLookup", {assertEquals(0x00, lut[0].a);assertEquals(0xff, lut[1].a);- assertEquals(0x00, lut[2].a);-- }+ assertEquals(0x00, lut[2].a);+ },});\ No newline at end of filediff --git a/test/Worldview/Visual/testVisual.js b/test/Worldview/Visual/testVisual.jsnew file mode 100644index 000000000..0f4f50cf9--- /dev/null+++ b/test/Worldview/Visual/testVisual.js@@ -0,0 +1,102 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */+TestCase("Visual", {++ ns: null,++ setUp: function() {+ ns = Worldview.Visual;+ },++ // Ensure the checkerboard got assigned to a value during initialization+ testCheckerboard: function() {+ assertNotUndefined(ns.CHECKERBOARD);+ assertNotNull(ns.CHECKERBOARD);+ },++ // Check that a percentage of zero is at the beginning.+ testRgbInterpolateLeft: function() {+ var result = ns.rgbInterpolate(0.0, ns.ColorRGBA(0, 0, 0),+ ns.ColorRGBA(0xff, 0xff, 0xff));+ assertEquals(0, result.r);+ assertEquals(0, result.g);+ assertEquals(0, result.b);+ assertEquals(0xff, result.a);+ },++ // Check that a percentage of one is at the end.+ testRgbInterpolateLeft: function() {+ var result = ns.rgbInterpolate(1.0, ns.ColorRGBA(0, 0, 0),+ ns.ColorRGBA(0xff, 0xff, 0xff));+ assertEquals(0xff, result.r);+ assertEquals(0xff, result.g);+ assertEquals(0xff, result.b);+ assertEquals(0xff, result.a);+ },++ // Check that a percentage of 0.5 is in the middle+ testRgbInterpolateCenter: function() {+ var result = ns.rgbInterpolate(0.5, ns.ColorRGBA(0, 0, 0),+ ns.ColorRGBA(0xff, 0xff, 0xff));+ assertEquals(0x80, result.r);+ assertEquals(0x80, result.g);+ assertEquals(0x80, result.b);+ assertEquals(0xff, result.a);+ },++ // Check that a percentage of zero is at the beginning.+ testHslInterpolateLeft: function() {+ var result = ns.hslInterpolate(0.0, ns.ColorRGBA(10, 20, 30),+ ns.ColorRGBA(40, 50, 60));+ assertEquals(10, result.r);+ assertEquals(20, result.g);+ assertEquals(30, result.b);+ assertEquals(0xff, result.a);+ },++ // Check that a percentage of one is at the end.+ testHslInterpolateRight: function() {+ var result = ns.hslInterpolate(1.0, ns.ColorRGBA(10, 20, 30),+ ns.ColorRGBA(40, 50, 60));+ assertEquals(40, result.r);+ assertEquals(50, result.g);+ assertEquals(60, result.b);+ assertEquals(0xff, result.a);+ },++ // Check that a percentage of 0.5 is in the middle.+ testHslInterpolateRight: function() {+ var result = ns.hslInterpolate(0.5, ns.ColorRGBA(10, 20, 30),+ ns.ColorRGBA(40, 50, 60));+ // Known good values+ assertEquals(23, result.r);+ assertEquals(35, result.g);+ assertEquals(47, result.b);+ assertEquals(0xff, result.a);+ },++ // Check against a known good value+ testRgbToHsl: function() {+ var result = ns.rgb2hsl({r: 10, g: 20, b: 30})+ assertTrue(Math.abs(result.h - 0.5833333) < 0.000001);+ assertTrue(Math.abs(result.s - 0.5) < 0.00001);+ assertTrue(Math.abs(result.l - 0.0784313) < 0.000001);+ },++ // Check against a known good value+ testHsltoRgb: function() {+ var result = ns.hsl2rgb({h: 0.5833333, s: 0.5, l: 0.0784313});+ assertEquals(10, result.r);+ assertEquals(20, result.g);+ assertEquals(30, result.b);+ },++});diff --git a/test/jsTestDriver.conf b/test/jsTestDriver.confindex e5c09413c..cc18689e8 100644--- a/test/jsTestDriver.conf+++ b/test/jsTestDriver.conf@@ -25,7 +25,9 @@ load:- ../js/switch.js- ../js/selector.js- ../js/sote.js- - ../js/palette.js+ - ../js/Worldview.js+ - ../js/Worldview/Visual.js+ - ../js/Worldview/Visual/*.js- jshamcrest.js- jsmockito-1.0.4.js- harness.js@@ -33,7 +35,7 @@ load:test:- OpenLayers/Tile/*.js- Worldview/*.js- - Worldview/palette/*.js+ - Worldview/Visual/*.jstimeout: 30\ No newline at end of file