Interactive interface for browsing global, full-resolution satellite imagery
WV-3590 - Chart Window Additions (#6054)
christof-wittreiche811a9cac407
diff --git a/web/js/components/charting/chart-component.js b/web/js/components/charting/chart-component.jsindex 4917420f7..19abda78f 100644--- a/web/js/components/charting/chart-component.js+++ b/web/js/components/charting/chart-component.js@@ -1,15 +1,38 @@-import React from 'react';+import React, { useEffect, useRef, useState } from 'react';+import { connect } from 'react-redux';import {LineChart, Line, XAxis, YAxis, Legend, Tooltip,} from 'recharts';import PropTypes from 'prop-types';import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';+import OlMap from 'ol/Map';+import OlView from 'ol/View';+import OlLayerGroup from 'ol/layer/Group';+import OlLayerTile from 'ol/layer/Tile';+import OlFeature from 'ol/Feature';+import { fromExtent } from 'ol/geom/Polygon';+import { Vector as OlVectorLayer } from 'ol/layer';+import { Vector as OlVectorSource } from 'ol/source';+import { getCenter } from 'ol/extent';+import { inAndOut } from 'ol/easing';+import {+ Fill as OlStyleFill,+ Stroke as OlStyleStroke,+ Style as OlStyle,+} from 'ol/style';+import util from '../../util/util';function ChartComponent (props) {const {liveData,+ mapView,+ createLayer,+ overviewMapLayerDef,} = props;+ const [errorCollapsed, setErrorCollapsed] = useState(true);+ const mapInstanceRef = useRef(null);+const {data,unit,@@ -19,8 +42,13 @@ function ChartComponent (props) {isTruncated,title,numPoints,+ coordinates,+ errors,} = liveData;+ const errorDaysArr = errors?.error_days?.replaceAll(/('|\[|\])/gi, '').split(', ') || [];+ const format = util.getCoordinateFormat();+// Arbitrary array of colors to useconst lineColors = ['#A3905D', '#82CA9D', 'orange', 'pink', 'green', 'red', 'yellow', 'aqua', 'maroon'];const formattedUnit = unit ? ` (${unit})` : '';@@ -182,6 +210,75 @@ function ChartComponent (props) {);}+ useEffect(() => {+ const boxFeature = new OlFeature({+ geometry: fromExtent(coordinates),+ });+ boxFeature.setStyle(new OlStyle({+ stroke: new OlStyleStroke({+ color: 'rgba(255, 255, 255, .6)',+ width: 1,+ }),+ fill: new OlStyleFill({+ color: 'rgba(255, 255, 255, .3)',+ }),+ }));+ const boxLayer = new OlVectorLayer({+ source: new OlVectorSource({+ features: [boxFeature],+ }),+ });++ const createLayerWrapper = async () => {+ const backgroundLayerGroup = await createLayer(overviewMapLayerDef);+ backgroundLayerGroup.setVisible(true);++ const layersList = [];+ backgroundLayerGroup.getLayers().getArray().forEach((layer) => {+ layersList.push(new OlLayerTile({+ source: layer.getSource(),+ }));+ });+ const copiedLayerGroup = new OlLayerGroup({+ layers: layersList,+ });++ mapInstanceRef.current = new OlMap({+ view: new OlView({+ center: mapView.getCenter(),+ zoom: mapView.getZoom(),+ projection: mapView.getProjection(),+ }),+ layers: [copiedLayerGroup, boxLayer],+ target: 'charting-minimap-inner',+ interactions: [],+ });++ const minimapView = mapInstanceRef.current.getView();+ minimapView.fit(boxFeature.getGeometry().getExtent(), { padding: [50, 50, 50, 50] });++ mapInstanceRef.current.on('moveend', () => {+ const boxCenter = getCenter(boxFeature.getGeometry().getExtent());+ const minimapCenter = minimapView.getCenter();+ if (boxCenter[0] === minimapCenter[0] && boxCenter[1] === minimapCenter[1]) {+ return;+ }+ minimapView.animate({+ center: boxCenter,+ duration: 350,+ easing: inAndOut,+ });+ });+ };++ createLayerWrapper();++ return () => {+ mapInstanceRef.current.setTarget(null);+ mapInstanceRef.current = null;+ };+ }, [overviewMapLayerDef]);+return (<div className="charting-chart-container"><div className="charting-chart-inner">@@ -217,56 +314,141 @@ function ChartComponent (props) {</LineChart></div><div className="charting-stat-text">- <h3>- <b>- Average Statistics- {formattedUnit}- </b>- </h3>- <br />- {getQuickStatistics(data)}- </div>- </div>- <div className="charting-disclaimer">- <strong className="charting-disclaimer-pre">Note: </strong>- <span>Numerical analyses performed on imagery should only be used for initial basic exploratory purposes.</span>- {isTruncated- && (- <div className="charting-disclaimer-lower">- <FontAwesomeIcon- icon="exclamation-triangle"- className="wv-alert-icon"- size="1x"- widthAuto- />- <i className="charting-disclaimer-block">- As part of this beta feature release, the number of data points plotted between+ <div id="charting-stats-container">+ <h3><b>- {` ${startDate} `}+ Average Statistics+ {formattedUnit}</b>- and- <b>- {` ${endDate} `}- </b>- have been reduced from- <b>- {` ${numRangeDays} `}- </b>- to+ </h3>+ <br />+ {getQuickStatistics(data)}+ </div>+ <div id="charting-minimap-container">+ <div id="charting-minimap-inner" />+ </div>+ <div />+ <div id="charting-coordinates-container">+ <h3><b>- {` ${numPoints}`}+ Coordinates</b>- .- </i>+ </h3>+ <br />+ <div className="charting-coordinates-inner">+ <div />+ <div className="coordinate-center coordinate-subheader">Latitude</div>+ <div className="coordinate-center coordinate-subheader">Longitude</div>+ <div>Top Right:</div>+ <div className="coordinate-mono">{util.formatCoordinate([coordinates[2], coordinates[3]], format).split(', ')[0]}</div>+ <div className="coordinate-mono">{util.formatCoordinate([coordinates[2], coordinates[3]], format).split(', ')[1]}</div>+ <div>Bottom Left:</div>+ <div className="coordinate-mono">{util.formatCoordinate([coordinates[0], coordinates[1]], format).split(', ')[0]}</div>+ <div className="coordinate-mono">{util.formatCoordinate([coordinates[0], coordinates[1]], format).split(', ')[1]}</div>+ </div></div>- )}+ </div>+ <div className="charting-disclaimer">+ <strong className="charting-disclaimer-pre">Note: </strong>+ <span>Numerical analyses performed on imagery should only be used for initial basic exploratory purposes.</span>+ {isTruncated+ && (+ <div className="charting-disclaimer-upper">+ <FontAwesomeIcon+ icon="exclamation-triangle"+ className="wv-alert-icon"+ size="1x"+ widthAuto+ />+ <i className="charting-disclaimer-block">+ As part of this beta feature release, the number of data points plotted between+ <b>+ {` ${startDate} `}+ </b>+ and+ <b>+ {` ${endDate} `}+ </b>+ have been reduced from+ <b>+ {` ${numRangeDays} `}+ </b>+ to+ <b>+ {` ${numPoints}`}+ </b>+ .+ </i>+ </div>+ )}+ {errors && errors.error_count > 0+ && (+ <div className="charting-disclaimer-lower">+ <FontAwesomeIcon+ icon="exclamation-triangle"+ className="wv-alert-icon"+ size="1x"+ widthAuto+ />+ <i className="charting-disclaimer-block">+ {`${errors.error_count} `}+ dates requested have no data, so are not shown in the chart.+ </i>+ {!errorCollapsed+ && (+ <div className="charting-disclaimer-dates">+ <i className="charting-disclaimer-block">+ {errorDaysArr.map((date, index) => (+ <>+ {date.split('T')[0]}+ {index < errorDaysArr.length - 1 && ', '}+ + </>+ ))}+ </i>+ </div>+ )}+ <div className="error-expand-button">+ <span className="error-expand-button-inner" onClick={() => setErrorCollapsed(!errorCollapsed)}>+ {errorCollapsed ? 'more' : 'less'}+ <FontAwesomeIcon+ className="layer-group-collapse"+ icon={!errorCollapsed ? 'caret-up' : 'caret-down'}+ widthAuto+ />+ </span>+ </div>+ </div>+ )}+ </div></div></div>);}+const mapStateToProps = (state) => {+ const {+ map,+ layers,+ } = state;++ const {+ ui,+ } = map;++ const layerId = 'Coastlines_15m';++ return {+ mapView: ui.selected.getView(),+ createLayer: ui.createLayer,+ overviewMapLayerDef: layers.layerConfig[layerId],+ };+};+ChartComponent.propTypes = {liveData: PropTypes.object,};-export default ChartComponent;+export default connect(+ mapStateToProps,+)(ChartComponent);diff --git a/web/js/components/sidebar/charting-mode-options.js b/web/js/components/sidebar/charting-mode-options.jsindex 27b5bcbf7..96973cc5c 100644--- a/web/js/components/sidebar/charting-mode-options.js+++ b/web/js/components/sidebar/charting-mode-options.js@@ -88,6 +88,7 @@ function ChartingModeOptions(props) {const isMounted = useRef(false);const [isPostRender, setIsPostRender] = useState(false);+ const [doRenderChart, setDoRenderChart] = useState(false);const [mapViewChecked, setMapViewChecked] = useState(false);const [isWithinWings, setIsWithinWings] = useState(false);const [boundaries, setBoundaries] = useState({@@ -411,17 +412,23 @@ function ChartingModeOptions(props) {if (timeSpanSelection === 'range') {const rechartsData = formatGIBSDataForRecharts(dataToRender);const numRangeDays = Math.floor((Date.parse(initialEndDate) - Date.parse(initialStartDate)) / 86400000);+ const startDateFormatted = `${initialStartDate.getFullYear()}-${`0${initialStartDate.getMonth() + 1}`.slice(-2)}-${`0${initialStartDate.getDate()}`.slice(-2)}`;+ const endDateFormatted = `${initialEndDate.getFullYear()}-${`0${initialEndDate.getMonth() + 1}`.slice(-2)}-${`0${initialEndDate.getDate()}`.slice(-2)}`;const numPoints = STEP_NUM - (data?.body?.errors?.error_count > 0 ? data.body.errors.error_count : 0);displayChart({title: dataToRender.title,subtitle: dataToRender.subtitle,unit: dataToRender.unit,+ errors: dataToRender.errors,data: rechartsData,startDate: primaryDate,endDate: secondaryDate,+ startDateFormatted,+ endDateFormatted,numRangeDays,isTruncated: numRangeDays > STEP_NUM,numPoints,+ coordinates: [...bottomLeftLatLong, ...topRightLatLong],});updateChartRequestStatus(false);} else {@@ -434,13 +441,19 @@ function ChartingModeOptions(props) {}}+ useEffect(() => {+ if (doRenderChart && isPostRender) {+ onRequestChartClick();+ }+ }, [doRenderChart, isPostRender]);+useEffect(() => {const isOpen = (modalId === 'CHARTING-CHART' || modalId === 'CHARTING-STATS-MODAL') && isModalOpen;if (isChartOpen && !isOpen && Object.keys(renderedPalettes).length > 0) {const layerInfo = getActiveChartingLayer();const paletteName = layerInfo.palette.id;if (renderedPalettes[paletteName]) {- onRequestChartClick();+ setDoRenderChart(true);}}}, [isChartOpen, renderedPalettes]);@@ -845,16 +858,29 @@ const mapDispatchToProps = (dispatch) => ({displayChart: (liveData) => {dispatch(openCustomContent('CHARTING-CHART', {- headerText: `BETA | ${liveData.title} - ${liveData.subtitle}${liveData.unit ? ` (${liveData.unit})` : ''}`,+ headerText: (+ <>+ BETA |+ {` ${liveData.title} `}+ -+ {` ${liveData.subtitle}${liveData.unit ? ` (${liveData.unit})` : ''}`}+ <span className="charting-chart-subheader">+ from + {liveData.startDateFormatted}+ to + {liveData.endDateFormatted}+ </span>+ </>+ ),backdrop: false,bodyComponent: ChartComponent,wrapClassName: 'unclickable-behind-modal',modalClassName: 'chart-dialog',isDraggable: true,dragHandle: '.modal-header',- offsetLeft: 'calc(50% - 425px)',+ offsetLeft: 'calc(50% - 575px)',offsetTop: 50,- width: 850,+ width: 1150,height: 420,stayOnscreen: true,type: 'selection', // This forces the user to specifically close the modaldiff --git a/web/scss/features/sidebar.scss b/web/scss/features/sidebar.scssindex be7975733..f3e0baabd 100644--- a/web/scss/features/sidebar.scss+++ b/web/scss/features/sidebar.scss@@ -652,21 +652,34 @@ div#group-overlays-checkbox-case {}.charting-statistics-row {- margin: 0 0 1em;padding: 0.25em 0;++ &:not(:last-child) {+ margin: 0 0 0.85em;+ }}.charting-statistics-value {float: right;font-weight: bold;+ font-family: variables.$wv-monospace-font;}.recharts-legend-item {font-weight: bold;}+.charting-chart-text {+ display: inline-block;+ vertical-align: top;+ width: 55%;+}+.charting-chart-container .charting-disclaimer {padding: 18px;+ padding-bottom: 1rem;+ margin-top: -50px;+ width: calc(600px + 18%);}.charting-disclaimer {@@ -678,19 +691,146 @@ div#group-overlays-checkbox-case {margin-right: 8px;}+.charting-disclaimer-upper {+ margin-top: 18px;+ position: relative;++ .wv-alert-icon {+ margin-top: 6px;+ }++ .charting-disclaimer-block {+ line-height: 28px;+ }+}+.charting-disclaimer-lower {margin-top: 10px;+ position: relative;+}++.charting-disclaimer-dates {+ margin-left: 17px;+}++.error-expand-button {+ margin-top: -3px;+ margin-bottom: -5px;++ .error-expand-button-inner {+ cursor: pointer;+ padding: 5px;+ display: flex;+ justify-content: center;++ svg {+ margin-left: 10px;+ margin-top: 1px;+ }+ }}.wv-alert-icon {color: #d54e21;font-size: 1.4em;margin: 10px 18px 0 8px;- float: left;+ position: absolute;}.charting-disclaimer-block {- line-height: 20px;+ line-height: 35px;+ display: block;+ margin-left: 40px;+}++#charting-minimap-container {+ width: 58%;+}++#charting-minimap-inner {+ border: 1px solid rgb(150 150 150);+ width: 100%;+ height: 165px;+ margin: auto;++ .ol-zoom {+ right: 8px;+ left: auto;+ margin-top: 1px;++ .ol-zoom-in, .ol-zoom-out {+ color: #c7c7c7;+ background-color: #434343;+ border: solid .5px;+ }++ .ol-zoom-in {+ padding-bottom: 1px;+ padding-left: .5px;+ }++ .ol-zoom-out {+ margin-top: -2px;+ padding-bottom: 2px;+ padding-left: .5px;+ }+ }+}++#charting-coordinates-container {+ width: 58%;+ vertical-align: top;+}++.charting-coordinates-inner {+ display: grid;+ grid-template-columns: 1fr 1fr 1fr;++ & > div {+ margin: 0 0 .85em;+ padding: .25em 0;+ }++ .coordinate-subheader {+ margin-left: 10px;+ margin-bottom: 13px;+ }++ .coordinate-center {+ text-align: center;+ }++ .coordinate-mono {+ font-weight: bold;+ font-family: variables.$wv-monospace-font;+ text-align: right;+ margin-left: 15px;+ }+}++.charting-dates-inner {+ display: grid;+ grid-template-columns: 1fr 1fr;+ grid-template-areas: "header header";++ .charting-dates-header {+ grid-area: header;+ }++ & > div {+ margin: 0 0 .85em;+ padding: .25em 0;+ }++ .dates-center {+ text-align: center;+ }++ .dates-mono {+ font-weight: bold;+ font-family: variables.$wv-monospace-font;+ text-align: right;+ }}.charting-buttons {@@ -723,11 +863,18 @@ div#group-overlays-checkbox-case {}#charting-chart {- max-width: 850px;+ max-width: 1150px;margin: 0 !important;.modal-header {cursor: move;++ .charting-chart-subheader {+ margin-left: 20px;+ font-weight: normal;+ font-size: 90%;+ color: #c7c7c7;+ }}}@@ -749,16 +896,19 @@ button#charting-simple-stats-button {text-decoration: underline !important;}-.charting-chart-inner {- display: flex;- justify-content: space-between;+.charting-stat-text {+ display: inline-block;+ width: 45%;}-.charting-stat-text {- float: left;- margin-left: 20px;- padding: 18px;- width: 100%;+.charting-stat-text > div {+ display: inline-block;+ margin: 3%;+ width: 30%;+}++.charting-stat-text h3, .charting-stat-text2 h3 {+ text-align: center;}p.recharts-tooltip-label {