Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

init global settings version

Ed Plato54f1938f05d6
diff --git a/e2e/features/ui/info-mobile-test.js b/e2e/features/ui/info-mobile-test.js
index 687b36a53..7ab727e29 100644
--- a/e2e/features/ui/info-mobile-test.js
+++ b/e2e/features/ui/info-mobile-test.js
@@ -21,26 +21,10 @@ module.exports = {
c.waitForElementVisible('#toolbar_info', TIME_LIMIT);
c.expect.element('#send_feedback_info_item').to.be.present;
- c.expect.element('#source_code_info_item').to.be.present;
- c.expect.element('#whats_new_info_item').to.be.present;
c.expect.element('#about_info_item').to.be.present;
c.expect.element('#distraction_free_info_item').to.be.present;
},
- // verify mobile source code menu item opens separate tab or window
- 'Mobile source code menu item opens separate tab or window': (c) => {
- c.windowHandles((tabs) => {
- c.assert.equal(tabs.value.length, 1);
- });
-
- c.click('#source_code_info_item');
- c.pause(500);
-
- c.windowHandles((tabs) => {
- c.assert.equal(tabs.value.length, 2);
- });
- },
-
after: (c) => {
c.end();
},
diff --git a/e2e/features/ui/info-test.js b/e2e/features/ui/info-test.js
index 8b43b05fd..bd8289a26 100644
--- a/e2e/features/ui/info-test.js
+++ b/e2e/features/ui/info-test.js
@@ -20,8 +20,6 @@ module.exports = {
c.waitForElementVisible('#toolbar_info', TIME_LIMIT);
c.expect.element('#send_feedback_info_item').to.be.present;
c.expect.element('#start_tour_info_item').to.be.present;
- c.expect.element('#source_code_info_item').to.be.present;
- c.expect.element('#whats_new_info_item').to.be.present;
c.expect.element('#about_info_item').to.be.present;
c.expect.element('#distraction_free_info_item').to.be.present;
},
diff --git a/package-lock.json b/package-lock.json
index 5e430234f..9d4fec27b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4291,6 +4291,14 @@
}
}
},
+ "@khanisak/temperature-converter": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/@khanisak/temperature-converter/-/temperature-converter-1.2.0.tgz",
+ "integrity": "sha512-pT9on/IIU4Qab3C5RAJkPR239qYL2ZBUCiEK6s27yV5pXntxceckwDFDPYTUmsC5s+ZnZYDsoV9oWrIyvJbEzw==",
+ "requires": {
+ "@types/node": "^12.7.2"
+ }
+ },
"@mapbox/jsonlint-lines-primitives": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@mapbox/jsonlint-lines-primitives/-/jsonlint-lines-primitives-2.0.2.tgz",
@@ -4622,8 +4630,7 @@
"@types/node": {
"version": "12.12.5",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.5.tgz",
- "integrity": "sha512-KEjODidV4XYUlJBF3XdjSH5FWoMCtO0utnhtdLf1AgeuZLOrRbvmU/gaRCVg7ZaQDjVf3l84egiY0mRNe5xE4A==",
- "dev": true
+ "integrity": "sha512-KEjODidV4XYUlJBF3XdjSH5FWoMCtO0utnhtdLf1AgeuZLOrRbvmU/gaRCVg7ZaQDjVf3l84egiY0mRNe5xE4A=="
},
"@types/normalize-package-data": {
"version": "2.4.0",
diff --git a/package.json b/package.json
index da7058f48..dc66a91da 100644
--- a/package.json
+++ b/package.json
@@ -174,6 +174,7 @@
"@fortawesome/free-regular-svg-icons": "^5.12.1",
"@fortawesome/free-solid-svg-icons": "^5.13.0",
"@fortawesome/react-fontawesome": "^0.1.9",
+ "@khanisak/temperature-converter": "^1.2.0",
"bluebird": "3.7.2",
"bootstrap": "4.4.1",
"cachai": "^1.0.2",
diff --git a/web/css/about.css b/web/css/about.css
index 8cab81a08..ce82ebc46 100644
--- a/web/css/about.css
+++ b/web/css/about.css
@@ -24,6 +24,13 @@
line-height: 22px;
}
+.about-page .version {
+ margin-top: 10px;
+ font-size: 12px;
+ font-weight: 100;
+ float: right;
+}
+
.about-page h1 {
font-size: 20px;
font-weight: 600;
@@ -73,6 +80,12 @@
.about-page .right {
float: right;
margin: 0.4em 0.2em 0;
+ &:first-of-type {
+ width: 100%;
+ a {
+ float: right;
+ }
+ }
&:last-of-type {
margin: 1.4em 0.2em 0;
}
@@ -141,3 +154,9 @@
display: block;
}
}
+
+@media (min-width: 576px) {
+ .about-page .version {
+ margin-top: 0;
+ }
+}
diff --git a/web/css/toolbar.css b/web/css/toolbar.css
index b892d74be..be8637375 100644
--- a/web/css/toolbar.css
+++ b/web/css/toolbar.css
@@ -148,6 +148,41 @@
width: 100%;
}
+/* Global Settings Modal */
+.global-settings-modal.modal-dialog {
+ width: 420px;
+}
+.global-settings-modal {
+ .global-setting-container {
+ margin-bottom: 16px;
+ }
+
+ .wv-header {
+ margin-bottom: 12px;
+ }
+ .temperature-unit-buttons {
+ .temperature-unit-button {
+ color: #fff;
+ background: #222;
+ &.active {
+ background: #d54e21;
+ border-color: #d54e21;
+ }
+ &:hover {
+ background: #fff;
+ color: #000;
+ }
+ }
+ }
+}
+
+@media (max-width: 576px) {
+ .global-settings-modal.modal-dialog {
+ width: 96%;
+ margin: 0;
+ }
+}
+
@media (min-width: 576px) {
.toolbar-modal:not(.toolbar-snapshot-modal) {
top: 33px;
diff --git a/web/js/components/about/about-page.js b/web/js/components/about/about-page.js
index 1f9a8ee04..982713eee 100644
--- a/web/js/components/about/about-page.js
+++ b/web/js/components/about/about-page.js
@@ -4,23 +4,35 @@ import Scrollbar from '../util/scrollbar';
export default function AboutPage() {
return (
- <Scrollbar style={{ height: 'calc(var(--vh, 1vh) * 100 - 200px)' }}>
+ <Scrollbar style={{ height: 'calc(var(--vh, 1vh) * 100 - 100px)' }}>
<div className="about-page">
<h1>
Welcome to @NAME@
- </h1>
-
- <div className="right">
- <div className="caption">
+ <span className="version">
+ {' '}
Version @BUILD_VERSION@
(
<a href="https://github.com/nasa-gibs/worldview/releases" target="_blank" rel="noopener noreferrer">Release Notes</a>
)
+ </span>
+ </h1>
+
+ <div className="right">
+ <div className="caption">
+ <a href="https://wiki.earthdata.nasa.gov/pages/viewrecentblogposts.action?key=GIBS" target="_blank" rel="noopener noreferrer">
+ {' '}
+ What&apos;s new in @NAME@!
+ {' '}
+ </a>
</div>
</div>
<p>
- This app from NASA&apos;s
+ This
+ {' '}
+ <a href="https://github.com/nasa-gibs/worldview" target="_blank" rel="noopener noreferrer">open source code</a>
+ {' '}
+ app from NASA&apos;s
{' '}
<a href="https://earthdata.nasa.gov/eosdis" target="_blank" rel="noopener noreferrer">EOSDIS</a>
{' '}
diff --git a/web/js/components/global-settings/global-settings.js b/web/js/components/global-settings/global-settings.js
new file mode 100644
index 000000000..c502ba051
--- /dev/null
+++ b/web/js/components/global-settings/global-settings.js
@@ -0,0 +1,55 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { connect } from 'react-redux';
+import TemperatureUnitButtons from './temperature-unit-buttons';
+import {
+ changeTemperatureUnit,
+} from '../../modules/global-unit/actions';
+
+class GlobalSettings extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {};
+ }
+
+ render() {
+ const {
+ globalTemperatureUnit,
+ changeTemperatureUnitAction,
+ } = this.props;
+ return (
+ <div>
+ <div className="global-setting-container">
+ <TemperatureUnitButtons
+ globalTemperatureUnit={globalTemperatureUnit}
+ changeTemperatureUnit={changeTemperatureUnitAction}
+ />
+ </div>
+ </div>
+ );
+ }
+}
+
+function mapStateToProps(state) {
+ const { globalUnit } = state;
+ const { globalTemperatureUnit } = globalUnit;
+ return {
+ globalTemperatureUnit,
+ };
+}
+
+const mapDispatchToProps = (dispatch) => ({
+ changeTemperatureUnitAction: (value) => {
+ dispatch(changeTemperatureUnit(value));
+ },
+});
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps,
+)(GlobalSettings);
+
+GlobalSettings.propTypes = {
+ changeTemperatureUnitAction: PropTypes.func,
+ globalTemperatureUnit: PropTypes.string,
+};
diff --git a/web/js/components/global-settings/temperature-unit-buttons.js b/web/js/components/global-settings/temperature-unit-buttons.js
new file mode 100644
index 000000000..4a991df03
--- /dev/null
+++ b/web/js/components/global-settings/temperature-unit-buttons.js
@@ -0,0 +1,54 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { Button, ButtonGroup } from 'reactstrap';
+
+const TemperatureUnitButtons = ({ globalTemperatureUnit, changeTemperatureUnit }) => (
+ <div className="temperature-unit-buttons settings-component">
+ <h3 className="wv-header">Temperature Unit</h3>
+ <ButtonGroup>
+ <Button
+ aria-label="Set Kelvin Unit"
+ outline
+ className="temperature-unit-button"
+ active={globalTemperatureUnit === 'Kelvin'}
+ onClick={() => changeTemperatureUnit('Kelvin')}
+ >
+ Kelvin
+ </Button>
+ <Button
+ aria-label="Set Celsius Unit"
+ outline
+ className="temperature-unit-button"
+ active={globalTemperatureUnit === 'Celsius'}
+ onClick={() => changeTemperatureUnit('Celsius')}
+ >
+ Celsius
+ </Button>
+ <Button
+ aria-label="Set Fahrenheit Unit"
+ outline
+ className="temperature-unit-button"
+ active={globalTemperatureUnit === 'Fahrenheit'}
+ onClick={() => changeTemperatureUnit('Fahrenheit')}
+ >
+ Fahrenheit
+ </Button>
+ <Button
+ aria-label="Reset to Default Unit"
+ outline
+ className="temperature-unit-button"
+ active={!globalTemperatureUnit}
+ onClick={() => changeTemperatureUnit('')}
+ >
+ Default
+ </Button>
+ </ButtonGroup>
+ </div>
+);
+
+TemperatureUnitButtons.propTypes = {
+ globalTemperatureUnit: PropTypes.string,
+ changeTemperatureUnit: PropTypes.func,
+};
+
+export default TemperatureUnitButtons;
diff --git a/web/js/components/layer/settings/layer-settings.js b/web/js/components/layer/settings/layer-settings.js
index 1405e9cc2..cf9ee070a 100644
--- a/web/js/components/layer/settings/layer-settings.js
+++ b/web/js/components/layer/settings/layer-settings.js
@@ -5,15 +5,20 @@ import {
TabContent, TabPane, Nav, NavItem, NavLink,
} from 'reactstrap';
import { connect } from 'react-redux';
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+
+import HoverTooltip from '../../util/hover-tooltip';
import Opacity from './opacity';
import Palette from './palette';
import OrbitTracks from './orbit-tracks-toggle';
import VectorStyle from './vector-style';
import PaletteThreshold from './palette-threshold';
-
import {
palettesTranslate,
} from '../../../modules/palettes/util';
+import {
+ getTemperatureUnitFromAbbrev,
+} from '../../../modules/global-unit/util';
import {
getDefaultLegend,
getCustomPalette,
@@ -63,6 +68,7 @@ class LayerSettings extends React.Component {
paletteOrder,
getDefaultLegend,
getCustomPalette,
+ globalTemperatureUnit,
setCustomPalette,
palettesTranslate,
groupName,
@@ -123,6 +129,7 @@ class LayerSettings extends React.Component {
key={`${layer.id + i}_threshold`}
legend={legend}
setRange={setThresholdRange}
+ globalTemperatureUnit={globalTemperatureUnit}
min={0}
max={max}
start={start}
@@ -172,6 +179,7 @@ class LayerSettings extends React.Component {
clearCustomPalette,
getDefaultLegend,
getCustomPalette,
+ globalTemperatureUnit,
palettesTranslate,
getPaletteLegends,
getPalette,
@@ -212,6 +220,7 @@ class LayerSettings extends React.Component {
<PaletteThreshold
key={`${layer.id}0_threshold`}
legend={legend}
+ globalTemperatureUnit={globalTemperatureUnit}
setRange={setThresholdRange}
min={0}
max={max}
@@ -271,6 +280,45 @@ class LayerSettings extends React.Component {
);
}
+ renderTemperatureUnitAndInfo() {
+ const {
+ isMobile,
+ getPaletteLegends,
+ getPaletteLegend,
+ globalTemperatureUnit,
+ layer,
+ } = this.props;
+ const paletteLegends = getPaletteLegends(layer.id);
+ if (!paletteLegends) return '';
+ const legend = getPaletteLegend(layer.id, 0);
+ const units = legend.units || '';
+
+ const temperatureUnit = getTemperatureUnitFromAbbrev(units);
+ return temperatureUnit && (
+ <div className="settings-component">
+ <div style={{ display: 'flex', justifyContent: 'space-between' }}>
+ <h2 className="wv-header">
+ {' '}
+ Temperature Unit:
+ {' '}
+ {globalTemperatureUnit
+ ? <strong>{globalTemperatureUnit}</strong>
+ : <strong>{temperatureUnit}</strong>}
+ </h2>
+ <span id="layer-settings-temperature-info" style={{ cursor: 'pointer' }} onClick={() => console.log('clicked')}>
+ <FontAwesomeIcon icon="cog" />
+ <HoverTooltip
+ isMobile={isMobile}
+ labelText="This is a setting that can be modified in the global settings panel. Click to learn more."
+ target="layer-settings-temperature-info"
+ />
+ </span>
+ </div>
+ <hr style={{ borderColor: '#666' }} />
+ </div>
+ );
+ }
+
render() {
let renderCustomizations;
const {
@@ -291,6 +339,7 @@ class LayerSettings extends React.Component {
if (!layer.id) return '';
return (
<>
+ {layer.palette && this.renderTemperatureUnitAndInfo()}
<Opacity
start={Math.ceil(layer.opacity * 100)}
setOpacity={setOpacity}
@@ -305,22 +354,24 @@ class LayerSettings extends React.Component {
function mapStateToProps(state, ownProps) {
const {
- config, palettes, compare, browser,
+ config, palettes, compare, browser, globalUnit,
} = state;
const { custom } = palettes;
const groupName = compare.activeString;
-
+ const isMobile = browser.lessThan.medium;
+ const { globalTemperatureUnit } = globalUnit;
return {
paletteOrder: config.paletteOrder,
groupName,
+ isMobile,
screenHeight: browser.screenHeight,
customPalettesIsActive: !!config.features.customPalettes,
+ globalTemperatureUnit,
palettedAllowed: isPaletteAllowed(ownProps.layer.id, config),
palettesTranslate,
getDefaultLegend: (layerId, index) => getDefaultLegend(layerId, index, state),
getCustomPalette: (id) => getCustomPalette(id, custom),
getPaletteLegend: (layerId, index) => getPaletteLegend(layerId, index, groupName, state),
-
getPaletteLegends: (layerId) => getPaletteLegends(layerId, groupName, state),
getPalette: (layerId, index) => getPalette(layerId, index, groupName, state),
getVectorStyle: (layerId, index) => getVectorStyle(layerId, index, groupName, state),
@@ -383,8 +434,10 @@ LayerSettings.propTypes = {
getPalette: PropTypes.func,
getPaletteLegend: PropTypes.func,
getPaletteLegends: PropTypes.func,
+ globalTemperatureUnit: PropTypes.string,
groupName: PropTypes.string,
layer: PropTypes.object,
+ isMobile: PropTypes.bool,
palettedAllowed: PropTypes.bool,
paletteOrder: PropTypes.array,
palettesTranslate: PropTypes.func,
diff --git a/web/js/components/layer/settings/palette-threshold.js b/web/js/components/layer/settings/palette-threshold.js
index e81e0fcb7..baa6e38a4 100644
--- a/web/js/components/layer/settings/palette-threshold.js
+++ b/web/js/components/layer/settings/palette-threshold.js
@@ -3,6 +3,9 @@ import PropTypes from 'prop-types';
import lodashDebounce from 'lodash/debounce';
import { Range as RangeInput } from 'rc-slider';
import Checkbox from '../../util/checkbox';
+import {
+ checkTemperatureUnitConversion, convertPaletteValue,
+} from '../../../modules/global-unit/util';
class ThresholdSelect extends React.Component {
constructor(props) {
@@ -40,7 +43,7 @@ class ThresholdSelect extends React.Component {
/**
* Update threshold values
- * @param {Array} thresholdArray | Array of start/end indexs for colormap
+ * @param {Array} thresholdArray | Array of start/end indexes for colormap
*/
updateThreshold(thresholdArray) {
const {
@@ -80,17 +83,30 @@ class ThresholdSelect extends React.Component {
}
render() {
- const { start, end, squashed } = this.state;
const {
- index, min, max, legend,
+ start, end, squashed,
+ } = this.state;
+ const {
+ index, min, max, legend, globalTemperatureUnit,
} = this.props;
const units = legend.units || '';
- const startLabel = start === 0 && legend.minLabel
- ? `${legend.minLabel} ${units}`
- : `${legend.tooltips[start]} ${units}`;
- const endLabel = end === legend.tooltips.length - 1 && legend.maxLabel
- ? `${legend.maxLabel} ${units}`
- : `${legend.tooltips[end]} ${units}`;
+ const { needsConversion, legendTempUnit } = checkTemperatureUnitConversion(units, globalTemperatureUnit);
+ let startLabel = start === 0 && legend.minLabel
+ ? legend.minLabel
+ : legend.tooltips[start];
+ let endLabel = end === legend.tooltips.length - 1 && legend.maxLabel
+ ? legend.maxLabel
+ : legend.tooltips[end];
+
+ if (needsConversion) {
+ const parsedMin = convertPaletteValue(startLabel, legendTempUnit, globalTemperatureUnit);
+ const parsedMax = convertPaletteValue(endLabel, legendTempUnit, globalTemperatureUnit);
+ startLabel = parsedMin;
+ endLabel = parsedMax;
+ } else {
+ startLabel += ` ${units}`;
+ endLabel += ` ${units}`;
+ }
return (
<div className="layer-threshold-select settings-component">
@@ -135,6 +151,7 @@ ThresholdSelect.propTypes = {
index: PropTypes.number,
layerId: PropTypes.string,
legend: PropTypes.object,
+ globalTemperatureUnit: PropTypes.string,
max: PropTypes.number,
min: PropTypes.number,
palette: PropTypes.object,
diff --git a/web/js/components/sidebar/paletteLegend.js b/web/js/components/sidebar/paletteLegend.js
index c8a538b25..85424b0c2 100644
--- a/web/js/components/sidebar/paletteLegend.js
+++ b/web/js/components/sidebar/paletteLegend.js
@@ -5,30 +5,16 @@ import lodashIsEqual from 'lodash/isEqual';
import { Tooltip } from 'reactstrap';
import VisibilitySensor from 'react-visibility-sensor/visibility-sensor';
import { getOrbitTrackTitle } from '../../modules/layers/util';
-import { drawSidebarPaletteOnCanvas, drawTicksOnCanvas } from '../../modules/palettes/util';
+import {
+ drawSidebarPaletteOnCanvas,
+ drawTicksOnCanvas,
+} from '../../modules/palettes/util';
+import {
+ checkTemperatureUnitConversion,
+ convertPaletteValue,
+} from '../../modules/global-unit/util';
import util from '../../util/util';
-/**
- * Find wanted legend object from Hex
- * @param {Object} legend
- * @param {String} hex
- * @param {Number} acceptableDifference
- */
-const getLegendObject = (legend, hex, acceptableDifference) => {
- const units = legend.units || '';
- for (let i = 0, len = legend.colors.length; i < len; i += 1) {
- if (util.hexColorDelta(legend.colors[i], hex) < acceptableDifference) {
- // If the two colors are close
- return {
- label: units ? `${legend.tooltips[i]} ${units}` : legend.tooltips[i],
- len,
- index: i,
- };
- }
- }
- return null;
-};
-
/**
* @param {Number} xOffset | X px Location of running-data
* @param {Number} textWidth | px width of text calculated with canvas
@@ -55,7 +41,6 @@ class PaletteLegend extends React.Component {
isRunningData: props.isRunningData,
colorHex: props.colorHex,
width: props.width,
-
scrollContainerEl: null,
};
}
@@ -184,6 +169,37 @@ class PaletteLegend extends React.Component {
});
}
+ /**
+ * Find wanted legend object from Hex
+ * @param {Object} legend
+ * @param {String} hex
+ * @param {Number} acceptableDifference
+ */
+ getLegendObject(legend, hex, acceptableDifference) {
+ const { globalTemperatureUnit } = this.props;
+ const units = legend.units || '';
+
+ const { needsConversion, legendTempUnit } = checkTemperatureUnitConversion(units, globalTemperatureUnit);
+ for (let i = 0, len = legend.colors.length; i < len; i += 1) {
+ if (util.hexColorDelta(legend.colors[i], hex) < acceptableDifference) {
+ const tooltipRange = legend.tooltips[i];
+ // If the two colors are close
+ let label;
+ if (needsConversion) {
+ label = convertPaletteValue(tooltipRange, legendTempUnit, globalTemperatureUnit);
+ } else {
+ label = units ? `${tooltipRange} ${units}` : tooltipRange;
+ }
+ return {
+ label,
+ len,
+ index: i,
+ };
+ }
+ }
+ return null;
+ }
+
/**
* Render scale-type paletteLegends
* @param {Object} legend
@@ -192,9 +208,11 @@ class PaletteLegend extends React.Component {
*/
renderScale(legend, index, isMoreThanOneColorBar) {
const {
- layer, width, getPalette, isEmbedModeActive, isMobile,
+ layer, width, getPalette, isEmbedModeActive, isMobile, globalTemperatureUnit,
} = this.props;
- const { isRunningData, colorHex, isHoveringLegend } = this.state;
+ const {
+ isRunningData, colorHex, isHoveringLegend,
+ } = this.state;
const palette = getPalette(layer.id, index);
let percent;
let textWidth;
@@ -203,7 +221,7 @@ class PaletteLegend extends React.Component {
const toolTipLength = legend.tooltips.length;
// eslint-disable-next-line react/destructuring-assignment
if (isRunningData && colorHex && this.state.width > 0) {
- legendObj = getLegendObject(legend, colorHex, 3); // {label,len,index}
+ legendObj = this.getLegendObject(legend, colorHex, 3); // {label,len,index}
if (legendObj) {
percent = this.getPercent(legendObj.len, legendObj.index);
textWidth = util.getTextWidth(legendObj.label, '10px Open Sans');
@@ -215,13 +233,21 @@ class PaletteLegend extends React.Component {
}
}
}
+
+ const units = legend.units || '';
+ const { needsConversion, legendTempUnit } = checkTemperatureUnitConversion(units, globalTemperatureUnit);
let min = legend.minLabel || legend.tooltips[0];
let max = legend.maxLabel || legend.tooltips[toolTipLength];
min = palette.min ? legend.tooltips[legend.refs.indexOf(palette.entries.refs[palette.min])] : min;
max = palette.max ? legend.tooltips[legend.refs.indexOf(palette.entries.refs[palette.max])] : max;
- min = legend.units ? `${min} ${legend.units}` : min;
- max = legend.units ? `${max} ${legend.units}` : max;
+ if (needsConversion) {
+ min = `${convertPaletteValue(min, legendTempUnit, globalTemperatureUnit)}`;
+ max = `${convertPaletteValue(max, legendTempUnit, globalTemperatureUnit)}`;
+ } else {
+ min = units ? `${min} ${units}` : min;
+ max = units ? `${max} ${units}` : max;
+ }
return (
<div
className={
@@ -298,7 +324,7 @@ class PaletteLegend extends React.Component {
const {
layer, parentLayer, compareState, getPalette,
} = this.props;
- const activeKeyObj = isRunningData && colorHex && getLegendObject(legend, colorHex, 5);
+ const activeKeyObj = isRunningData && colorHex && this.getLegendObject(legend, colorHex, 5);
const legendClass = activeKeyObj
? 'wv-running wv-palettes-legend wv-palettes-classes'
: 'wv-palettes-legend wv-palettes-classes';
@@ -413,6 +439,7 @@ PaletteLegend.propTypes = {
colorHex: PropTypes.string,
getPalette: PropTypes.func,
height: PropTypes.number,
+ globalTemperatureUnit: PropTypes.string,
isCustomPalette: PropTypes.bool,
isEmbedModeActive: PropTypes.bool,
isDistractionFreeModeActive: PropTypes.bool,
diff --git a/web/js/components/vector-metadata/table.js b/web/js/components/vector-metadata/table.js
index 021097d13..c90ea2d26 100644
--- a/web/js/components/vector-metadata/table.js
+++ b/web/js/components/vector-metadata/table.js
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import { Table } from 'reactstrap';
import VectorMetaTooltip from './tooltip';
import util from '../../util/util';
+import { checkTemperatureUnitConversion, convertPaletteValue, getAbbrevFromTemperatureUnit } from '../../modules/global-unit/util';
export default class VectorMetaTable extends React.Component {
shouldComponentUpdate(nextProps) {
@@ -14,7 +15,7 @@ export default class VectorMetaTable extends React.Component {
}
render() {
- const { metaArray } = this.props;
+ const { metaArray, globalTemperatureUnit } = this.props;
return (
<div>
@@ -34,31 +35,44 @@ export default class VectorMetaTable extends React.Component {
{metaLegend.map((properties, index) => {
const featureId = properties.Identifier;
const isIntegerToStyle = properties.Function !== 'Identify' && (properties.DataType === 'int');
- const value = properties.ValueMap
+ let value = properties.ValueMap
? properties.ValueMap[metaFeatures[featureId]]
: isIntegerToStyle ? metaFeatures[featureId].toLocaleString('en')
: metaFeatures[featureId];
const id = util.cleanId(String(`${title}-${metaIndex + index}`));
+
+ let description = properties.Description;
+ let unit = properties.Units;
+ if (value && unit) {
+ const initialUnit = unit;
+ unit = getAbbrevFromTemperatureUnit(unit) || unit;
+ const { needsConversion, legendTempUnit } = checkTemperatureUnitConversion(unit, globalTemperatureUnit);
+ if (needsConversion) {
+ value = `${convertPaletteValue(`${value}`, legendTempUnit, globalTemperatureUnit)}`;
+ description = description.replace(initialUnit, globalTemperatureUnit);
+ unit = '';
+ }
+ }
+
if (!value) return undefined;
return (
<tr key={`vector-row-${id}`}>
<td>
-
- {properties && properties.Description ? (
- <VectorMetaTooltip id={id} index={index} description={properties.Description} />
+ {description ? (
+ <VectorMetaTooltip id={id} index={index} description={description} />
) : undefined}
<div className="vector-feature-name-cell">{properties.Title ? properties.Title : featureId}</div>
</td>
<td>
<span>{value}</span>
- {properties && properties.Units ? (
+ {unit
+ && (
<span>
- {` ${properties.Units}`}
{' '}
+ {unit}
</span>
- ) : undefined}
+ )}
</td>
-
</tr>
);
})}
@@ -73,6 +87,7 @@ export default class VectorMetaTable extends React.Component {
}
VectorMetaTable.propTypes = {
id: PropTypes.number,
+ globalTemperatureUnit: PropTypes.string,
metaArray: PropTypes.array,
title: PropTypes.string,
};
diff --git a/web/js/containers/info.js b/web/js/containers/info.js
index 11de015ab..c7897be5a 100644
--- a/web/js/containers/info.js
+++ b/web/js/containers/info.js
@@ -18,11 +18,13 @@ import {
} from '../modules/tour/actions';
import { notificationsSeen } from '../modules/notifications/actions';
import Notifications from './notifications';
+import GlobalSettings from '../components/global-settings/global-settings';
function InfoList (props) {
const {
sendFeedback,
feedbackIsInitiated,
+ globalSettingsClick,
aboutClick,
config,
startTour,
@@ -101,18 +103,13 @@ function InfoList (props) {
...feedbackAction,
},
{
- text: 'Source Code',
+ text: 'Settings',
iconClass: 'ui-icon',
- iconName: 'code',
- id: 'source_code_info_item',
- href: 'https://github.com/nasa-gibs/worldview',
- },
- {
- text: 'What\'s new',
- iconClass: 'ui-icon',
- iconName: 'flag',
- id: 'whats_new_info_item',
- href: 'https://wiki.earthdata.nasa.gov/pages/viewrecentblogposts.action?key=GIBS',
+ iconName: 'cog',
+ id: 'settings_info_item',
+ onClick: () => {
+ globalSettingsClick();
+ },
},
{
text: 'About',
@@ -136,7 +133,7 @@ function InfoList (props) {
}
}
if (notifications.isActive && notifications.number > 0) {
- arr.splice(4, 0, getNotificationListItem());
+ arr.splice(2, 0, getNotificationListItem());
}
arr.push(getDistractionFreeObj());
return arr;
@@ -200,6 +197,17 @@ const mapDispatchToProps = (dispatch) => ({
dispatch(startTourAction());
}
},
+ globalSettingsClick: () => {
+ dispatch(
+ openCustomContent('GLOBAL_SETTINGS_MODAL', {
+ headerText: 'Global Settings',
+ backdrop: false,
+ bodyComponent: GlobalSettings,
+ wrapClassName: 'clickable-behind-modal',
+ modalClassName: 'global-settings-modal toolbar-info-modal toolbar-modal',
+ }),
+ );
+ },
aboutClick: () => {
// Create new functionality here that renders the about page
// inside a modal window.
@@ -220,6 +228,7 @@ export default connect(
InfoList.propTypes = {
aboutClick: PropTypes.func,
+ globalSettingsClick: PropTypes.func,
config: PropTypes.object,
feedbackIsInitiated: PropTypes.bool,
isDistractionFreeModeActive: PropTypes.bool,
diff --git a/web/js/containers/sidebar/layer-row.js b/web/js/containers/sidebar/layer-row.js
index b58f7ec14..aa817dd08 100644
--- a/web/js/containers/sidebar/layer-row.js
+++ b/web/js/containers/sidebar/layer-row.js
@@ -51,6 +51,7 @@ function LayerRow (props) {
palette,
renderedPalette,
requestPalette,
+ globalTemperatureUnit,
isCustomPalette,
isDistractionFreeModeActive,
isEmbedModeActive,
@@ -99,6 +100,7 @@ function LayerRow (props) {
isCustomPalette={isCustomPalette}
isRunningData={isRunningData}
colorHex={colorHex}
+ globalTemperatureUnit={globalTemperatureUnit}
isDistractionFreeModeActive={isDistractionFreeModeActive}
isEmbedModeActive={isEmbedModeActive}
isMobile={isMobile}
@@ -343,10 +345,11 @@ const makeMapStateToProps = () => {
compareState,
} = ownProps;
const {
- browser, palettes, config, embed, map, compare, proj, ui,
+ browser, palettes, config, embed, map, compare, proj, ui, globalUnit,
} = state;
const isMobile = browser.lessThan.medium;
const { isDistractionFreeModeActive } = ui;
+ const { globalTemperatureUnit } = globalUnit;
const hasPalette = !lodashIsEmpty(layer.palette);
const renderedPalettes = palettes.rendered;
const paletteName = lodashGet(config, `layers['${layer.id}'].palette.id`);
@@ -367,6 +370,7 @@ const makeMapStateToProps = () => {
compare,
tracksForLayer,
measurementDescriptionPath,
+ globalTemperatureUnit,
isCustomPalette,
isDistractionFreeModeActive,
isEmbedModeActive,
@@ -456,6 +460,7 @@ LayerRow.propTypes = {
compare: PropTypes.object,
getPalette: PropTypes.func,
hasPalette: PropTypes.bool,
+ globalTemperatureUnit: PropTypes.string,
hover: PropTypes.func,
index: PropTypes.number,
isCustomPalette: PropTypes.bool,
diff --git a/web/js/containers/vector-dialog.js b/web/js/containers/vector-dialog.js
index 6a0141715..86245ee6f 100644
--- a/web/js/containers/vector-dialog.js
+++ b/web/js/containers/vector-dialog.js
@@ -23,7 +23,7 @@ class VectorDialog extends React.Component {
render() {
const {
- toggleWithClose, vectorMetaObject, modalHeight, dialogKey,
+ toggleWithClose, globalTemperatureUnit, vectorMetaObject, modalHeight, dialogKey,
} = this.props;
const { activeIndex } = this.state;
const navArray = [];
@@ -62,7 +62,12 @@ class VectorDialog extends React.Component {
<ModalBody>
<Scrollbars style={{ maxHeight: `${modalHeight - 70}px` }}>
- <VectorMetaTable id={dialogKey} metaArray={activeMetaArray} title={keyArray[activeIndex]} />
+ <VectorMetaTable
+ globalTemperatureUnit={globalTemperatureUnit}
+ id={dialogKey}
+ metaArray={activeMetaArray}
+ title={keyArray[activeIndex]}
+ />
</Scrollbars>
</ModalBody>
</div>
@@ -70,8 +75,12 @@ class VectorDialog extends React.Component {
}
}
-function mapStateToProps() {
- return {};
+function mapStateToProps(state) {
+ const {
+ globalUnit,
+ } = state;
+ const { globalTemperatureUnit } = globalUnit;
+ return { globalTemperatureUnit };
}
export default connect(
mapStateToProps,
@@ -79,6 +88,7 @@ export default connect(
)(VectorDialog);
VectorDialog.propTypes = {
dialogKey: PropTypes.number,
+ globalTemperatureUnit: PropTypes.string,
modalHeight: PropTypes.number,
toggleWithClose: PropTypes.func,
vectorMetaObject: PropTypes.object,
diff --git a/web/js/font-awesome-library.js b/web/js/font-awesome-library.js
index 39c094ef3..10ed8da09 100644
--- a/web/js/font-awesome-library.js
+++ b/web/js/font-awesome-library.js
@@ -38,6 +38,7 @@ import {
faCircle,
faClock,
faCode,
+ faCog,
faCopy,
faDownload,
faEllipsisV,
@@ -106,6 +107,7 @@ library.add(
faCircle,
faClock,
faCode,
+ faCog,
faCopy,
faDownload,
faEllipsisV,
diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.js
index ed26891da..005b61673 100644
--- a/web/js/modules/combine-reducers.js
+++ b/web/js/modules/combine-reducers.js
@@ -48,6 +48,7 @@ import embedReducers from './embed/reducers';
import uiReducers from './ui/reducers';
import { alertReducer } from './alerts/reducer';
import { smartHandoffReducer } from './smart-handoff/reducer';
+import { getInitialState as globalUnitGetInitialState, globalUnitReducer } from './global-unit/reducer';
function lastAction(state = null, action) {
return action;
@@ -83,6 +84,7 @@ export function getInitialState(models, config, parameters) {
proj: getProjInitialState(config),
layers: getLayersInitialState(config),
events: getInitialEventsState(config),
+ globalUnit: globalUnitGetInitialState(),
requestedEvents: eventRequestResponse(),
requestedEventSources: eventRequestResponse(),
palettes: getInitialPaletteState(config),
@@ -131,6 +133,7 @@ const reducers = {
embed: embedReducers,
ui: uiReducers,
productPicker: productPickerReducer,
+ globalUnit: globalUnitReducer,
};
const appReducer = combineReducers(reducers);
/**
diff --git a/web/js/modules/global-unit/actions.js b/web/js/modules/global-unit/actions.js
new file mode 100644
index 000000000..65fc1a2db
--- /dev/null
+++ b/web/js/modules/global-unit/actions.js
@@ -0,0 +1,18 @@
+import {
+ CHANGE_TEMPERATURE_UNIT,
+} from './constants';
+import safeLocalStorage from '../../util/local-storage';
+
+const { GLOBAL_TEMPERATURE_UNIT } = safeLocalStorage.keys;
+// eslint-disable-next-line import/prefer-default-export
+export function changeTemperatureUnit(value) {
+ if (!value) {
+ safeLocalStorage.removeItem(GLOBAL_TEMPERATURE_UNIT);
+ } else {
+ safeLocalStorage.setItem(GLOBAL_TEMPERATURE_UNIT, value);
+ }
+ return {
+ type: CHANGE_TEMPERATURE_UNIT,
+ value,
+ };
+}
diff --git a/web/js/modules/global-unit/constants.js b/web/js/modules/global-unit/constants.js
new file mode 100644
index 000000000..f7e3c24fa
--- /dev/null
+++ b/web/js/modules/global-unit/constants.js
@@ -0,0 +1,2 @@
+// eslint-disable-next-line import/prefer-default-export
+export const CHANGE_TEMPERATURE_UNIT = 'GLOBAL_UNIT/CHANGE_TEMPERATURE_UNIT';
diff --git a/web/js/modules/global-unit/reducer.js b/web/js/modules/global-unit/reducer.js
new file mode 100644
index 000000000..57c23dce5
--- /dev/null
+++ b/web/js/modules/global-unit/reducer.js
@@ -0,0 +1,27 @@
+import safeLocalStorage from '../../util/local-storage';
+import { CHANGE_TEMPERATURE_UNIT } from './constants';
+
+const { GLOBAL_TEMPERATURE_UNIT } = safeLocalStorage.keys;
+
+export const initialState = {
+ globalTemperatureUnit: '',
+};
+
+export function getInitialState() {
+ const globalTemperatureUnit = safeLocalStorage.getItem(GLOBAL_TEMPERATURE_UNIT);
+ return {
+ globalTemperatureUnit,
+ };
+}
+
+export const globalUnitReducer = (state = initialState, action) => {
+ switch (action.type) {
+ case CHANGE_TEMPERATURE_UNIT:
+ return {
+ ...state,
+ globalTemperatureUnit: action.value,
+ };
+ default:
+ return state;
+ }
+};
diff --git a/web/js/modules/global-unit/util.js b/web/js/modules/global-unit/util.js
new file mode 100644
index 000000000..80ba8dabe
--- /dev/null
+++ b/web/js/modules/global-unit/util.js
@@ -0,0 +1,112 @@
+import tConverter from '@khanisak/temperature-converter';
+
+// fix package specific spelling
+const celsiusSpellFix = (unit) => (unit === 'Celsius' ? 'Celcius' : unit);
+
+export function getTemperatureUnitFromAbbrev(unitAbbrev) {
+ const temps = {
+ K: 'Kelvin',
+ '°C': 'Celsius',
+ '°F': 'Fahrenheit',
+ };
+ return temps[unitAbbrev];
+}
+
+export function getAbbrevFromTemperatureUnit(unit) {
+ const temps = {
+ Kelvin: 'K',
+ Celsius: '°C',
+ Fahrenheit: '°F',
+ };
+ return temps[unit];
+}
+
+export function unitConvert(value, initialUnit, targetUnit) {
+ const result = tConverter.convert(
+ value,
+ tConverter.unit[celsiusSpellFix(initialUnit)],
+ tConverter.unit[celsiusSpellFix(targetUnit)],
+ );
+ return result;
+}
+
+export function checkTemperatureUnitConversion(units, globalTemperatureUnit) {
+ let needsConversion = false;
+ const legendTempUnit = getTemperatureUnitFromAbbrev(units);
+ if (legendTempUnit && globalTemperatureUnit && legendTempUnit !== globalTemperatureUnit) {
+ needsConversion = true;
+ }
+ return {
+ needsConversion,
+ legendTempUnit,
+ };
+}
+
+/**
+ * Convert palette temperature values based on units
+ *
+ * Examples val palette value/range arguments:
+ * Base single min/max values
+ * '180.0 340.0'
+ *
+ * Base single min/max values with prefix
+ * '< 180.0 > 340.0'
+ *
+ * Double min single max
+ * '186.2 – 186.9 340.0'
+ *
+ * Single min double max
+ * '180.0 331.2 – 331.8'
+ *
+ * Double min double max
+ * '195.0 – 195.6 331.2 – 331.8'
+ *
+ * @param {String} val (ex: '≥ 32.00')
+ * @param {String} initialUnit (ex: 'Celsius')
+ * @param {String} targetUnit (ex: 'Fahrenheit')
+ *
+ * @returns {String} converted unit (ex: '39.02 – 39.29 °F')
+ */
+export function convertPaletteValue(val, initialUnit, targetUnit) {
+ const newUnitAbbrev = getAbbrevFromTemperatureUnit(targetUnit || initialUnit);
+ let prefix = '';
+ let convertedValue;
+ const isDash = val.includes(' – ');
+ const splitCharacter = isDash
+ ? '–'
+ : '';
+
+ // Range value (ex: '186.2 – 186.9')
+ if (splitCharacter) {
+ let [minRangeVal, maxRangeVal] = val.split(` ${splitCharacter} `);
+
+ let minPrefix = '';
+ let maxPrefix = '';
+ const minRangeSplit = minRangeVal.split(' ');
+ const maxRangeSplit = maxRangeVal.split(' ');
+ if (minRangeSplit.length > 1) { // (ex: '< 180.0')
+ [minPrefix, minRangeVal] = minRangeSplit;
+ minPrefix = `${minPrefix} `;
+ }
+ if (maxRangeSplit.length > 1) {
+ [maxPrefix, maxRangeVal] = maxRangeSplit;
+ maxPrefix = `${maxPrefix} `;
+ }
+
+ const minConvert = unitConvert(Number(minRangeVal), initialUnit, targetUnit).toFixed(2);
+ const maxConvert = unitConvert(Number(maxRangeVal), initialUnit, targetUnit).toFixed(2);
+ convertedValue = `${minPrefix}${minConvert} ${splitCharacter} ${maxPrefix}${maxConvert} ${newUnitAbbrev}`;
+ } else {
+ // Single value (ex: '180.0', '< 180.0')
+ const valSplit = val.split(' ');
+ let singleVal = val;
+ if (valSplit.length > 1) { // (ex: '< 180.0')
+ [prefix, singleVal] = valSplit;
+ prefix = `${prefix} `;
+ }
+
+ const valConvert = unitConvert(Number(singleVal), initialUnit, targetUnit).toFixed(2);
+ convertedValue = `${prefix}${valConvert} ${newUnitAbbrev}`;
+ }
+ return convertedValue;
+}
diff --git a/web/js/util/local-storage.js b/web/js/util/local-storage.js
index 028589122..b3c0bee73 100644
--- a/web/js/util/local-storage.js
+++ b/web/js/util/local-storage.js
@@ -23,6 +23,7 @@ export default {
DISMISSED_EVENT_VIS_ALERT: 'dismissedEventVisibilityAlert',
DISMISSED_COMPARE_ALERT: 'dismissedCompareAlert',
DISMISSED_DISTRACTION_FREE_ALERT: 'dismissedDistractionFreeAlert',
+ GLOBAL_TEMPERATURE_UNIT: 'globalTemperatureUnit',
HIDE_TOUR: 'hideTour',
HIDE_EDS_WARNING: 'hideEDS',
SIDEBAR_COLLAPSED: 'sidebarState',