Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

start colormap ticks #67

Benjamin King9ffb026376dc
diff --git a/tasks/python3/processColormap.py b/tasks/python3/processColormap.py
index 00bf22595..efdb4ab42 100755
--- a/tasks/python3/processColormap.py
+++ b/tasks/python3/processColormap.py
@@ -132,6 +132,7 @@ def process_entries(colormap):
legends = to_list(colormap["Legend"]["LegendEntry"])
colors = []
values = []
+ ticks = []
tooltips = []
matches = []
@@ -153,6 +154,8 @@ def process_entries(colormap):
if (map_type == "continuous") or (map_type == "discrete"):
matches += [entry["@rgb"]]
tooltips += [tooltip]
+ if "@showTick" in legend:
+ ticks.append(index)
if (map_type == "continuous") or (map_type == "discrete"):
items = re.sub(r"[\(\)\[\]]", "", entry["@value"]).split(",")
try:
@@ -179,7 +182,8 @@ def process_entries(colormap):
"legend": {
"tooltips": tooltips,
"colors": colors,
- "type": map_type
+ "type": map_type,
+ "ticks": ticks
}
}
if (map_type == "continuous") or (map_type == "discrete"):
diff --git a/web/js/components/sidebar/paletteLegend.js b/web/js/components/sidebar/paletteLegend.js
index a4e7cc636..692d918a5 100644
--- a/web/js/components/sidebar/paletteLegend.js
+++ b/web/js/components/sidebar/paletteLegend.js
@@ -1,7 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import util from '../../util/util';
-import { drawPaletteOnCanvas } from '../../modules/palettes/util';
+import { drawPaletteOnCanvas, drawTicksOnCanvas } from '../../modules/palettes/util';
+import lodashIsEqual from 'lodash/isEqual';
import lodashIsNumber from 'lodash/isNumber';
class PaletteLegend extends React.Component {
@@ -136,13 +137,20 @@ class PaletteLegend extends React.Component {
// This value is needed for calculating running data offsets
this.setState({ width: newWidth });
}
+ let ctx = this[ctxStr].current.getContext('2d');
drawPaletteOnCanvas(
- this[ctxStr].current.getContext('2d'),
+ ctx,
checkerBoardPattern,
colorMap.colors,
width,
height
);
+ drawTicksOnCanvas(
+ ctx,
+ colorMap,
+ width,
+ height
+ );
}
}
});
@@ -246,8 +254,8 @@ class PaletteLegend extends React.Component {
{isMoreThanOneColorBar ? (
<div className="wv-palettes-title">{legend.title}</div>
) : (
- ''
- )}
+ ''
+ )}
<div className="colorbar-case">
<canvas
className="wv-palettes-colorbar"
@@ -347,9 +355,9 @@ class PaletteLegend extends React.Component {
{isEndOfRow ? (
<div className="wv-running-category-label-case">
{isRunningData &&
- legendObj &&
- (legendObj.index >= rowEndIndex && // legend is in this row
- legendObj.index <= index) ? (
+ legendObj &&
+ (legendObj.index >= rowEndIndex && // legend is in this row
+ legendObj.index <= index) ? (
<span
className="wv-running-category-label"
style={this.getClassLabelStyle(
@@ -367,8 +375,8 @@ class PaletteLegend extends React.Component {
)}
</div>
) : (
- ''
- )}
+ ''
+ )}
</React.Fragment>
);
})}
diff --git a/web/js/modules/palettes/util.js b/web/js/modules/palettes/util.js
index bcd77c508..f000cd96b 100644
--- a/web/js/modules/palettes/util.js
+++ b/web/js/modules/palettes/util.js
@@ -45,7 +45,7 @@ export function getCheckerboard() {
export function palettesTranslate(source, target) {
var translation = [];
- lodashEach(source, function(color, index) {
+ lodashEach(source, function (color, index) {
var sourcePercent = index / source.length;
var targetIndex = Math.floor(sourcePercent * target.length);
translation.push(target[targetIndex]);
@@ -78,9 +78,26 @@ export function drawPaletteOnCanvas(
});
}
}
+export function drawTicksOnCanvas(ctx, legend, width, height) {
+ const ticks = legend.ticks;
+ const colors = legend.colors;
+ const bins = colors.length;
+ const binWidth = width / bins;
+ const yValue = height * 0.5;
+ const drawWidth = Math.ceil(binWidth);
+
+ if (ticks && ticks.length > 0) {
+ ticks.forEach(tick => {
+ const start = Math.floor(binWidth * tick);
+ const midpoint = start + drawWidth / 2;
+ ctx.fillStyle = util.hexToRGBA('000000ff');
+ ctx.fillRect(midpoint - 0.25, yValue, 0.5, height);
+ });
+ }
+}
export function lookup(sourcePalette, targetPalette) {
var lookup = {};
- lodashEach(sourcePalette.colors, function(sourceColor, index) {
+ lodashEach(sourcePalette.colors, function (sourceColor, index) {
var source =
parseInt(sourceColor.substring(0, 2), 16) +
',' +
@@ -239,7 +256,7 @@ export function getPaletteAttributeArray(layerId, palettes, state) {
return [];
}
}
-const createPaletteAttributeObject = function(def, value, attrObj, count) {
+const createPaletteAttributeObject = function (def, value, attrObj, count) {
const key = attrObj.key;
const attrArray = attrObj.array;
let hasAtLeastOnePair = attrObj.isActive;
@@ -276,7 +293,7 @@ export function loadPalettes(permlinkState, state) {
];
}
lodashEach(stateArray, stateObj => {
- lodashEach(state.layers[stateObj.groupStr], function(layerDef) {
+ lodashEach(state.layers[stateObj.groupStr], function (layerDef) {
if (layerDef.palette) {
var layerId = layerDef.id;
var min = [];
@@ -284,7 +301,7 @@ export function loadPalettes(permlinkState, state) {
var squash = [];
var count = 0;
if (layerDef.custom) {
- lodashEach(layerDef.custom, function(value, index) {
+ lodashEach(layerDef.custom, function (value, index) {
try {
const newPalettes = setCustomSelector(
layerId,
@@ -302,7 +319,7 @@ export function loadPalettes(permlinkState, state) {
});
}
if (layerDef.min) {
- lodashEach(layerDef.min, function(value, index) {
+ lodashEach(layerDef.min, function (value, index) {
try {
min.push(
findPaletteExtremeIndex(
@@ -320,7 +337,7 @@ export function loadPalettes(permlinkState, state) {
});
}
if (layerDef.max) {
- lodashEach(layerDef.max, function(value, index) {
+ lodashEach(layerDef.max, function (value, index) {
try {
max.push(
findPaletteExtremeIndex(