Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Adjusted styling of legend to be similar to running-data value styling #105

Benjamin27c48be48af2
diff --git a/web/css/wv.palettes.css b/web/css/wv.palettes.css
index 554ef65fd..2021eafe5 100644
--- a/web/css/wv.palettes.css
+++ b/web/css/wv.palettes.css
@@ -162,11 +162,13 @@
.bank div .wv-palettes-panel.wv-running .wv-running-category-label {
visibility: visible;
}
-.bank div .wv-palettes-panel .wv-running .wv-running-label,
-.bank div .wv-palettes-panel .wv-running .wv-running-bar {
+.bank .wv-palettes-panel .wv-running .wv-running-label,
+.bank .wv-palettes-panel .wv-running .wv-running-bar {
visibility: visible;
}
-
+.active-lengend .wv-palettes-panel .wv-running .wv-running-bar {
+ visibility: hidden;
+}
/* FIXME: Too specific */
.bank div .wv-palettes-colorbar {
width: 100%;
@@ -208,14 +210,14 @@
text-decoration: underline;
}
-.bank div .wv-palettes-colorbar[data-type='single'] {
+/*.bank div .wv-palettes-colorbar[data-type='single'] {
width: 10px;
}
-
+*/
/* FIXME: Too specific */
-.bank div .wv-palettes-colorbar:hover {
+/*.bank div .wv-palettes-colorbar:hover {
border: 1px solid #404040;
-}
+}*/
#palette-selector-dialog .product-description {
margin-bottom: 10px;
diff --git a/web/js/layers/wv.layers.active.js b/web/js/layers/wv.layers.active.js
index 961481940..5651e7600 100644
--- a/web/js/layers/wv.layers.active.js
+++ b/web/js/layers/wv.layers.active.js
@@ -258,6 +258,7 @@ wv.layers.active = wv.layers.active || function(models, ui, config) {
config: config,
models: models,
layer: layer,
+ ui: ui
//onLoad: //adjustCategoryHeights
});
};
diff --git a/web/js/map/wv.map.runningdata.js b/web/js/map/wv.map.runningdata.js
index 671ed3a1f..abea98f8b 100644
--- a/web/js/map/wv.map.runningdata.js
+++ b/web/js/map/wv.map.runningdata.js
@@ -112,7 +112,7 @@ wv.map.runningdata = wv.map.runningdata || function(models) {
*/
self.getLabelMarginLeft = function(labelWidth, caseWidth, location) {
if(location + (labelWidth / 2) > caseWidth) {
- return (caseWidth - labelWidth);
+ return (caseWidth - labelWidth) - 2;
} else if (location - (labelWidth / 2) < 0) {
return 0;
} else {
@@ -222,7 +222,6 @@ wv.map.runningdata = wv.map.runningdata || function(models) {
map.forEachLayerAtPixel(coords, function(layer, data){
var hex;
var palette;
- var paletteInfo;
var legend;
var layerId;
if(layer.wv.def.palette) {
@@ -231,31 +230,80 @@ wv.map.runningdata = wv.map.runningdata || function(models) {
return;
}
legends = models.palettes.getLegends(layerId);
+ hex = wv.util.rgbaToHex(data[0], data[1], data[2], data[3]);
_.each(legends, function(legend){
if(legend) {
- hex = wv.util.rgbaToHex(data[0], data[1], data[2], data[3]);
- if(legend.type === 'continuous') {
- paletteInfo = self.getDataLabel(legend, hex);
- if(paletteInfo) {
- self.setLayerValue(legend.id, paletteInfo);
- self.activeLayers.push(legend.id);
- }
- } else if(legend.type === 'classification') {
- paletteInfo = self.getDataLabel(legend, hex);
- if(paletteInfo) {
- self.setCategoryValue(legend.id, paletteInfo);
- self.activeLayers.push(legend.id);
- }
- }
+ self.createRunnerFromLegend(legend, hex);
}
});
}
});
+ self.update();
+ };
+ /*
+ * Update array of current
+ * active palettes
+ *
+ * @method update
+ *
+ * @return {Void}
+ *
+ */
+ self.update = function() {
if(self.oldLayers.length) {
self.updateRunners(self.LayersToRemove(self.oldLayers, self.activeLayers));
}
self.oldLayers = self.activeLayers;
+
+ };
+ /*
+ * Initiates new legend
+ *
+ * @method newLegend
+ *
+ * @param {Array} legends - tooltip data
+ *
+ * @param {String} hex - color
+ *
+ * @return {Void}
+ *
+ */
+ self.newLegend = function(legends, hex) {
+ self.activeLayers = [legends.id];
+ $productsBox.addClass('active-lengend');
+ self.createRunnerFromLegend(legends, hex);
+ self.update();
+ };
+
+ /*
+ * Compare old and new arrays to determine which Layers need to be
+ * removed
+ *
+ * @method LayersToRemove
+ *
+ * @param {Array} coords - Array of coordinate values
+ *
+ * @param {Object} map - OpenLayers Map Object
+ *
+ * @return {Void}
+ *
+ */
+ self.createRunnerFromLegend = function(legend, hex) {
+ var paletteInfo;
+ if(legend.type === 'continuous') {
+ paletteInfo = self.getDataLabel(legend, hex);
+ if(paletteInfo) {
+ self.setLayerValue(legend.id, paletteInfo);
+ self.activeLayers.push(legend.id);
+ }
+ } else if(legend.type === 'classification') {
+ paletteInfo = self.getDataLabel(legend, hex);
+ if(paletteInfo) {
+ self.setCategoryValue(legend.id, paletteInfo);
+ self.activeLayers.push(legend.id);
+ }
+ }
};
/*
@@ -276,6 +324,7 @@ wv.map.runningdata = wv.map.runningdata || function(models) {
$palette.removeClass('wv-running');
};
self.clearAll = function() {
+ $productsBox.removeClass('active-lengend');
$('.wv-running').removeClass('wv-running');
};
/*
@@ -313,7 +362,8 @@ wv.map.runningdata = wv.map.runningdata || function(models) {
$caseWidth = $categoryPaletteCase.width();
$paletteLabel.text(data.label);
- $labelWidth = $paletteLabel.width();
+ $labelWidth = wv.util.getTextWidth(data.label, 'Lucida Sans');
+
location = ((marginLeft + squareWidth) * data.index);
labelMargin = self.getLabelMarginLeft($labelWidth, $caseWidth, location);
@@ -362,7 +412,6 @@ wv.map.runningdata = wv.map.runningdata || function(models) {
$paletteLabel.text(data.label);
labelWidth = wv.util.getTextWidth(data.label, 'Lucida Sans');
-
labelMargin = self.getLabelMarginLeft(labelWidth, $paletteWidth, location);
$paletteLabel.attr('style', 'left:' + Math.round(labelMargin) + 'px;');
diff --git a/web/js/map/wv.map.ui.js b/web/js/map/wv.map.ui.js
index 360ff46ee..e3e33bf6f 100644
--- a/web/js/map/wv.map.ui.js
+++ b/web/js/map/wv.map.ui.js
@@ -20,8 +20,8 @@ wv.map.ui = wv.map.ui || function(models, config, Rotation, DataRunner) {
var cache = new Cache(400); // Save layers from days visited
var animationDuration = 250;
var self = {};
- var rotation = new Rotation(self, models);
- var dataRunner = new DataRunner(models);
+ var rotation = self.rotate = new Rotation(self, models);
+ var dataRunner = self.runningdata = new DataRunner(models);
var hiDPI = ol.has.DEVICE_PIXEL_RATIO > 1;
var pixelRatio = hiDPI ? 2 : 1;
diff --git a/web/js/palettes/wv.palettes.legend.js b/web/js/palettes/wv.palettes.legend.js
index 2e52e5dae..4804a606d 100644
--- a/web/js/palettes/wv.palettes.legend.js
+++ b/web/js/palettes/wv.palettes.legend.js
@@ -21,6 +21,7 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
var config = spec.config;
var models = spec.models;
var model = spec.models.palettes;
+ var ui = spec.ui;
var layer = spec.layer;
var loaded = false;
var rendered = false;
@@ -75,8 +76,11 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
$colorbar = $("<canvas></canvas>")
.addClass("wv-palettes-colorbar")
.attr("id", legend.id)
- .attr("data-index", index)
- .attr("title", "X");
+ .attr("data-index", index);
+ //set fixed canvas dimensions
+ $colorbar[0].width = 230;
+ $colorbar[0].height = 12;
+
$container.append($colorbar);
var $runningDataPointBar = $("<div></div>")
@@ -93,7 +97,6 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
.addClass("wv-palettes-max");
var $title = $("<div></div>")
.addClass("wv-palettes-title");
-
$container.prepend($title);
$ranges
.append($min)
@@ -104,13 +107,7 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
.append($runningDataPointBar);
$colorbar.on("mousemove", showUnitHover);
- $colorbar.tooltip({
- position: {
- my: "left middle",
- at: "right+30 middle",
- of: $colorbar
- }
- });
+ $colorbar.on("mouseout", hideUnitsOnMouseOut);
$legendPanel.append($container);
wv.palettes.colorbar(selector + " " +
"[data-index='" + index + "'] canvas", legend.colors);
@@ -121,34 +118,30 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
var $panel = $("<div></div>")
.addClass("wv-palettes-legend")
.addClass("wv-palettes-classes")
- .attr("data-index", index)
- .attr("title", "X");
+ .attr("data-index", index);
$legendPanel
.attr("id", legend.id)
.append($panel)
.append($runningDataPointLabel);
- $panel.tooltip({
- position: {
- my: "left middle",
- at: "right+30 middle",
- of: $panel
- },
- content: "X"
- });
};
var updateClasses = function(legend, index) {
var $panel = $(selector + " [data-index='" + index + "']");
$panel.empty();
_.each(legend.colors, function(color, classIndex) {
- $panel.append($("<span></span>")
+ var $colorBox;
+ $colorBox = $("<span></span>")
.attr("data-index", index)
.attr("data-class-index", classIndex)
+ .attr("data-hex", color)
.addClass("wv-palettes-class")
.html("&nbsp;")
.css("background-color", wv.util.hexToRGB(color))
- .hover(highlightClass, unhighlightClass));
+ .hover(highlightClass, unhighlightClass);
+ $panel.append($colorBox);
+ $colorBox.on('mouseenter', showClassUnitHover);
+ $colorBox.on('mouseout', hideUnitsOnMouseOut);
});
var $detailPanel = $("<div></div>");
_.each(legend.colors, function(color, classIndex) {
@@ -157,13 +150,13 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
var $row = $("<div></div>")
.addClass("wv-palettes-class-detail")
.attr("data-class-index", classIndex);
+ $colorBox =
$row.append(
$("<span></span>")
.addClass("wv-palettes-class")
.html("&nbsp;")
.css("background-color", wv.util.hexToRGB(color)))
- .append(
- $("<span></span>")
+ .append($("<span></span>")
.addClass("wv-palettes-class-label")
.attr("data-index", index)
.attr("data-class-index", classIndex)
@@ -171,7 +164,6 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
$detailPanel.append($row);
});
if( !rendered ) {
- $panel.tooltip("option", "content", $detailPanel.html());
rendered = true;
}
};
@@ -217,33 +209,65 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
}
});
};
-
- var showUnitHover = function(event) {
+ /**
+ * get color from canvas bar and
+ * send it to data processing
+ *
+ * @method showUnitHover
+ * @static
+ * @param {MouseEvent} e
+ * @return {void}
+ */
+ var showUnitHover = function(e) {
+ var rgba;
+ var pos;
+ var x;
+ var y;
+ var id;
+ var legends;
if ( !loaded ) {
return;
}
- var index = _.parseInt($(this).attr("data-index"));
- var legend = model.getLegend(layer.id, index);
- var entry = model.get(layer.id, index).entries;
- var $colorbar = $(this);
- var x = event.pageX - $colorbar.offset().left;
- var width = $colorbar.width();
- var percent = x / width;
- var bins = legend.colors.length;
- var colorIndex = Math.floor(bins * percent);
- if (colorIndex >= bins) {
- colorIndex = bins - 1;
- }
+ legends = model.getLegends(layer.id)[0];
+ offset = $(this).offset();
+ x = e.pageX - offset.left;
+ y = e.pageY - offset.top;
+ rgba = wv.util.getCanvasPixelData(this, x, y);
+ hex = wv.util.rgbaToHex(rgba[0], rgba[1], rgba[2]);
+ ui.map.runningdata.newLegend(legends, hex);
+ };
- var color = legend.colors[colorIndex];
- var label = legend.tooltips[colorIndex];
- label = (legend.units) ? label + " " + legend.units : label;
-
- $colorbar.tooltip("option", "content",
- "<span class='wv-palettes-color-box' style='background: " +
- wv.util.hexToRGBA(color) + "'>" + "</span>" + label);
+ /**
+ * get color from data attr and
+ * send it to data processing and
+ * render legend
+ *
+ * @method showClassUnitHover
+ * @static
+ * @param {MouseEvent} e
+ * @return {void}
+ */
+ var showClassUnitHover = function(e) {
+ var hex = $(this).data('hex');
+ var legends = model.getLegends(layer.id)[0];
+ ui.map.runningdata.newLegend(legends, hex);
};
+ /**
+ * get color from data attr and
+ * send it to data processing and
+ * render legend
+ *
+ * @method showClassUnitHover
+ * @static
+ * @param {MouseEvent} e
+ * @return {void}
+ */
+ var hideUnitsOnMouseOut = function() {
+ ui.map.runningdata.clearAll();
+ };
+
+
var highlightClass = function() {
legendIndex = $(this).attr("data-index");
classIndex = $(this).attr("data-class-index");
diff --git a/web/js/util/wv.util.js b/web/js/util/wv.util.js
index 9b6c0c488..35d5782e5 100644
--- a/web/js/util/wv.util.js
+++ b/web/js/util/wv.util.js
@@ -144,7 +144,20 @@ wv.util = (function(self) {
self.parseTimestampUTC = function(str) {
return self.parseDateUTC(str);
};
-
+ /**
+ * Gets a pixel RGBA value from Canvas
+ *
+ * @method getCanvasPixelData
+ * @static
+ * @param canvas {Object} DOM canvas Element
+ * @param x {Number} X value on canvas
+ * @return y {Number} Y value on canvas
+ * @return {Object} Canvas image data.
+ */
+ self.getCanvasPixelData = function(canvas, x, y) {
+ var context = canvas.getContext("2d");
+ return context.getImageData(x, y, 1, 1).data;
+ };
/**
* Parses a UTC ISO 8601 date.
*