Interactive interface for browsing global, full-resolution satellite imagery
refactor grid range into a single component, refactor tile-rect to fix react lint errors, clean up state and props names within renders, add proptypes
Edward Plato286243ab97c8
diff --git a/web/js/components/timeline/timeline-axis/grid-range/grid-range.js b/web/js/components/timeline/timeline-axis/grid-range/grid-range.jsindex cb190aa75..4e82f74c5 100644--- a/web/js/components/timeline/timeline-axis/grid-range/grid-range.js+++ b/web/js/components/timeline/timeline-axis/grid-range/grid-range.js@@ -1,62 +1,9 @@import React, { PureComponent } from 'react';-import moment from 'moment';-+import PropTypes from 'prop-types';import TileRect from './tile-rect';import TileText from './tile-text';-// # PureComponent performs a shallow comparison of props and state - may not need shouldComponentUpdate-class GridRange extends PureComponent {- constructor(props) {- super(props);- this.state = {- // hoverLinePosition: 0- };- }-- // showHover = (e, itemDate, nextDate, index) => {- // e.preventDefault();- // e.stopPropagation();- // e.persist();- // requestAnimationFrame(() => {- // let target = e.target;- // let clientX = e.clientX;- // let boundingClientRect = target.getBoundingClientRect();- // let xHoverPositionInCurrentGrid = Math.floor(clientX) - Math.floor(boundingClientRect.left);- // let gridWidth = this.props.gridWidth;-- // let currentDateValue = moment.utc(itemDate).valueOf();- // let nextDateValue = moment.utc(nextDate).valueOf();- // let diff = nextDateValue - currentDateValue;- // let diffFactor = diff / gridWidth; // gridWidth- // let displayDate = moment.utc(currentDateValue + (xHoverPositionInCurrentGrid * diffFactor)).format();- // this.props.displayDate(displayDate, clientX);- // this.setState({- // hoverLinePosition: index * gridWidth + xHoverPositionInCurrentGrid- // })- // })- // }-- componentDidUpdate(prevProps, prevState) {- }-- render() {- let { gridWidth, transformX, timeScale, dateArray, showHover } = this.props;- return (- <g className="gridShell" transform={`translate(${transformX}, 0)`}>- <TileHolder- timeScale={timeScale}- dateArray={dateArray}- gridWidth={gridWidth}- showHover={showHover}- />- {/* <line className="svgLine" style={{display: this.props.showHoverLine ? 'block' : 'none'}}- stroke="blue" strokeWidth="2" strokeOpacity="0.48" x1="0" x2="0" y1="0" y2="63"- transform={`translate(${this.state.hoverLinePosition + 1}, 0)`} shapeRendering="optimizeSpeed"/> */}- </g>- );- }-}-+// determine if text will be renderedconst tileTextConditionOptions = {minute: (itemDateObject) => {let timeScaleUnit = itemDateObject.minutes;@@ -86,37 +33,49 @@ const tileTextConditionOptions = {}};-class TileHolder extends PureComponent {+class GridRange extends PureComponent {render() {- let { gridWidth, timeScale, dateArray, showHover } = this.props;+ let { gridWidth, transformX, timeScale, dateArray, showHover } = this.props;let tileTextCondition = tileTextConditionOptions[timeScale];return (- <React.Fragment>- {dateArray.map((item, index) => {- return (- item.withinRange- ? <React.Fragment key={index}>- <TileRect- item={item}- index={index}- gridWidth={gridWidth}- showHover={showHover}- />- {tileTextCondition(item.dateObject)- ? <TileText+ <g className="gridShell" transform={`translate(${transformX}, 0)`}>+ <React.Fragment>+ {dateArray.map((item, index) => {+ return (+ item.withinRange+ ? <React.Fragment key={index}>+ <TileRectitem={item}index={index}gridWidth={gridWidth}+ showHover={showHover}+ timeScale={timeScale}/>- : null }- </React.Fragment>- : null- );- }- )}- </React.Fragment>+ {tileTextCondition(item.dateObject)+ ? <TileText+ item={item}+ index={index}+ gridWidth={gridWidth}+ />+ : null }+ </React.Fragment>+ : null+ );+ }+ )}+ </React.Fragment>+ </g>);}}+GridRange.propTypes = {+ dateArray: PropTypes.array,+ displayDate: PropTypes.func,+ gridWidth: PropTypes.number,+ showHover: PropTypes.func,+ timeScale: PropTypes.string,+ transformX: PropTypes.number+};+export default GridRange;diff --git a/web/js/components/timeline/timeline-axis/grid-range/tile-rect.js b/web/js/components/timeline/timeline-axis/grid-range/tile-rect.jsindex 76180a992..624bb772a 100644--- a/web/js/components/timeline/timeline-axis/grid-range/tile-rect.js+++ b/web/js/components/timeline/timeline-axis/grid-range/tile-rect.js@@ -1,90 +1,162 @@import React, { PureComponent } from 'react';+import PropTypes from 'prop-types';-const axisScaleGridElement = {- minute: (gridWidth, index, item) => {- let timeScaleUnit = item.dateObject.minutes;- let lineLengthY = timeScaleUnit === 0 ||- timeScaleUnit === 15 ||- timeScaleUnit === 30 ||- timeScaleUnit === 45 ? 62 : timeScaleUnit % 5 === 0 ? 20 : 10;- let whiteLineStrokeWidth = lineLengthY !== 10 ? 2 : 1;- return (- <React.Fragment>- <rect className="grid" width={gridWidth} height={100} transform={`translate(${index * gridWidth}, 0)`} fill={item.withinRange ? 'rgba(0,0,0,0)' : 'black'} shapeRendering="optimizeSpeed"></rect>- <line stroke="black" strokeLinecap="round" strokeWidth="0.2" x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 2.2}, 0)`} />- <line stroke="#555" strokeWidth={1} x1="0" x2={gridWidth} y1="46" y2="46" transform={`translate(${index * gridWidth + 1}, 0)`} shapeRendering="optimizeSpeed" />- <line stroke="white" strokeLinecap="round" strokeWidth={whiteLineStrokeWidth} x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 1}, 0)`} />- </React.Fragment>- )- },- hour: (gridWidth, index, item) => {- let timeScaleUnit = item.dateObject.hours;- let lineLengthY = timeScaleUnit === 0 ? 62 :- timeScaleUnit === 6 ||- timeScaleUnit === 12 ||- timeScaleUnit === 18 ? 22 : 10;- let whiteLineStrokeWidth = lineLengthY !== 10 ? 2 : 1;- return (- <React.Fragment>- <rect className="grid" width={gridWidth} height={100} transform={`translate(${index * gridWidth}, 0)`} fill={item.withinRange ? 'rgba(0,0,0,0)' : 'black'} shapeRendering="optimizeSpeed"></rect>- <line stroke="black" strokeLinecap="round" strokeWidth="0.2" x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 2.2}, 0)`} />- <line stroke="#555" strokeWidth={1} x1="0" x2={gridWidth} y1="46" y2="46" transform={`translate(${index * gridWidth + 1}, 0)`} shapeRendering="optimizeSpeed" />- <line stroke="white" strokeLinecap="round" strokeWidth={whiteLineStrokeWidth} x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 1}, 0)`} />- </React.Fragment>- )+// const axisScaleGridElement = {+// minute: (gridWidth, index, item) => {+// let timeScaleUnit = item.dateObject.minutes;+// let lineLengthY = timeScaleUnit === 0 ||+// timeScaleUnit === 15 ||+// timeScaleUnit === 30 ||+// timeScaleUnit === 45 ? 62 : timeScaleUnit % 5 === 0 ? 20 : 10;+// let whiteLineStrokeWidth = lineLengthY !== 10 ? 2 : 1;+// return (+// <React.Fragment>+// <rect className="grid" width={gridWidth} height={100} transform={`translate(${index * gridWidth}, 0)`} fill={item.withinRange ? 'rgba(0,0,0,0)' : 'black'} shapeRendering="optimizeSpeed"></rect>+// <line stroke="black" strokeLinecap="round" strokeWidth="0.2" x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 2.2}, 0)`} />+// <line stroke="#555" strokeWidth={1} x1="0" x2={gridWidth} y1="46" y2="46" transform={`translate(${index * gridWidth + 1}, 0)`} shapeRendering="optimizeSpeed" />+// <line stroke="white" strokeLinecap="round" strokeWidth={whiteLineStrokeWidth} x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 1}, 0)`} />+// </React.Fragment>+// )+// },+// hour: (gridWidth, index, item) => {+// let timeScaleUnit = item.dateObject.hours;+// let lineLengthY = timeScaleUnit === 0 ? 62 :+// timeScaleUnit === 6 ||+// timeScaleUnit === 12 ||+// timeScaleUnit === 18 ? 22 : 10;+// let whiteLineStrokeWidth = lineLengthY !== 10 ? 2 : 1;+// return (+// <React.Fragment>+// <rect className="grid" width={gridWidth} height={100} transform={`translate(${index * gridWidth}, 0)`} fill={item.withinRange ? 'rgba(0,0,0,0)' : 'black'} shapeRendering="optimizeSpeed"></rect>+// <line stroke="black" strokeLinecap="round" strokeWidth="0.2" x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 2.2}, 0)`} />+// <line stroke="#555" strokeWidth={1} x1="0" x2={gridWidth} y1="46" y2="46" transform={`translate(${index * gridWidth + 1}, 0)`} shapeRendering="optimizeSpeed" />+// <line stroke="white" strokeLinecap="round" strokeWidth={whiteLineStrokeWidth} x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 1}, 0)`} />+// </React.Fragment>+// )+// },+// day: (gridWidth, index, item) => {+// let timeScaleUnit = item.dateObject.date;+// let dayOfWeek = item.dayOfWeek;+// let lineLengthY = timeScaleUnit === 1 ? 62 : dayOfWeek === 0 ? 22 : 10;+// let whiteLineStrokeWidth = lineLengthY !== 10 ? 2 : 1;+// return (+// <React.Fragment>+// <rect className="grid" width={gridWidth} height={100} transform={`translate(${index * gridWidth}, 0)`} fill={item.withinRange ? 'rgba(0,0,0,0)' : 'black'} shapeRendering="optimizeSpeed"></rect>+// <line stroke="black" strokeLinecap="round" strokeWidth="0.2" x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 2.2}, 0)`} />+// <line stroke="#555" strokeWidth={1} x1="0" x2={gridWidth} y1="46" y2="46" transform={`translate(${index * gridWidth + 1}, 0)`} shapeRendering="optimizeSpeed" />+// <line stroke="white" strokeLinecap="round" strokeWidth={whiteLineStrokeWidth} x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 1}, 0)`} />+// </React.Fragment>+// )+// },+// month: (gridWidth, index, item) => {+// let timeScaleUnit = item.dateObject.months;+// let lineLengthY = timeScaleUnit === 0 ? 62 : timeScaleUnit % 3 === 0 ? 22 : 10;+// let whiteLineStrokeWidth = lineLengthY !== 10 ? 2 : 1;+// return (+// <React.Fragment>+// <rect className="grid" width={gridWidth} height={100} transform={`translate(${index * gridWidth}, 0)`} fill={item.withinRange ? 'rgba(0,0,0,0)' : 'black'} shapeRendering="optimizeSpeed"></rect>+// <line stroke="black" strokeLinecap="round" strokeWidth="0.2" x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 2.2}, 0)`} />+// <line stroke="#555" strokeWidth={1} x1="0" x2={gridWidth} y1="46" y2="46" transform={`translate(${index * gridWidth + 1}, 0)`} shapeRendering="optimizeSpeed" />+// <line stroke="white" strokeLinecap="round" strokeWidth={whiteLineStrokeWidth} x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 1}, 0)`} />+// </React.Fragment>+// )+// },+// year: (gridWidth, index, item) => {+// let timeScaleUnit = item.dateObject.years;+// let lineLengthY = timeScaleUnit % 10 === 0 ? 62 : timeScaleUnit % 5 === 0 ? 22 : 10;+// let whiteLineStrokeWidth = lineLengthY !== 10 ? 2 : 1;+// return (+// <React.Fragment>+// <rect className="grid" width={gridWidth} height={100} transform={`translate(${index * gridWidth}, 0)`} fill={item.withinRange ? 'rgba(0,0,0,0)' : 'black'} shapeRendering="optimizeSpeed"></rect>+// <line stroke="black" strokeLinecap="round" strokeWidth="0.2" x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 2.2}, 0)`} />+// <line stroke="#555" strokeWidth={1} x1="0" x2={gridWidth} y1="46" y2="46" transform={`translate(${index * gridWidth + 1}, 0)`} shapeRendering="optimizeSpeed" />+// <line stroke="white" strokeLinecap="round" strokeWidth={whiteLineStrokeWidth} x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 1}, 0)`} />+// </React.Fragment>+// )+// },+// }++const tileRectTimeScaleOptions = {+ minute: function() {+ return {+ lineLengthY: (item) => {+ let timeScaleUnit = item.dateObject.minutes;+ let lineLengthY = timeScaleUnit === 0 ||+ timeScaleUnit === 15 ||+ timeScaleUnit === 30 ||+ timeScaleUnit === 45 ? 62 : timeScaleUnit % 5 === 0 ? 20 : 10;+ return lineLengthY;+ }+ };},- day: (gridWidth, index, item) => {- let dayOfWeek = item.dayOfWeek;- let lineLengthY = item.dateObject.date === 1 ? 62 : dayOfWeek === 0 ? 22 : 10;- let whiteLineStrokeWidth = lineLengthY !== 10 ? 2 : 1;- return (- <React.Fragment>- <rect className="grid" width={gridWidth} height={100} transform={`translate(${index * gridWidth}, 0)`} fill={item.withinRange ? 'rgba(0,0,0,0)' : 'black'} shapeRendering="optimizeSpeed"></rect>- <line stroke="black" strokeLinecap="round" strokeWidth="0.2" x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 2.2}, 0)`} />- <line stroke="#555" strokeWidth={1} x1="0" x2={gridWidth} y1="46" y2="46" transform={`translate(${index * gridWidth + 1}, 0)`} shapeRendering="optimizeSpeed" />- <line stroke="white" strokeLinecap="round" strokeWidth={whiteLineStrokeWidth} x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 1}, 0)`} />- </React.Fragment>- )+ hour: function() {+ return {+ lineLengthY: (item) => {+ let timeScaleUnit = item.dateObject.hours;+ let lineLengthY = timeScaleUnit === 0 ? 62+ : timeScaleUnit === 6 ||+ timeScaleUnit === 12 ||+ timeScaleUnit === 18 ? 22 : 10;+ return lineLengthY;+ }+ };},- month: (gridWidth, index, item) => {- let timeScaleUnit = item.dateObject.months;- let lineLengthY = timeScaleUnit === 0 ? 62 : timeScaleUnit % 3 === 0 ? 22 : 10;- let whiteLineStrokeWidth = lineLengthY !== 10 ? 2 : 1;- return (- <React.Fragment>- <rect className="grid" width={gridWidth} height={100} transform={`translate(${index * gridWidth}, 0)`} fill={item.withinRange ? 'rgba(0,0,0,0)' : 'black'} shapeRendering="optimizeSpeed"></rect>- <line stroke="black" strokeLinecap="round" strokeWidth="0.2" x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 2.2}, 0)`} />- <line stroke="#555" strokeWidth={1} x1="0" x2={gridWidth} y1="46" y2="46" transform={`translate(${index * gridWidth + 1}, 0)`} shapeRendering="optimizeSpeed" />- <line stroke="white" strokeLinecap="round" strokeWidth={whiteLineStrokeWidth} x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 1}, 0)`} />- </React.Fragment>- )+ day: function() {+ return {+ lineLengthY: (item) => {+ let timeScaleUnit = item.dateObject.date;+ let dayOfWeek = item.dayOfWeek;+ let lineLengthY = timeScaleUnit === 1 ? 62 : dayOfWeek === 0 ? 22 : 10;+ return lineLengthY;+ }+ };},- year: (gridWidth, index, item) => {- let timeScaleUnit = item.dateObject.years;- let lineLengthY = timeScaleUnit % 10 === 0 ? 62 : timeScaleUnit % 5 === 0 ? 22 : 10;- let whiteLineStrokeWidth = lineLengthY !== 10 ? 2 : 1;- return (- <React.Fragment>- <rect className="grid" width={gridWidth} height={100} transform={`translate(${index * gridWidth}, 0)`} fill={item.withinRange ? 'rgba(0,0,0,0)' : 'black'} shapeRendering="optimizeSpeed"></rect>- <line stroke="black" strokeLinecap="round" strokeWidth="0.2" x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 2.2}, 0)`} />- <line stroke="#555" strokeWidth={1} x1="0" x2={gridWidth} y1="46" y2="46" transform={`translate(${index * gridWidth + 1}, 0)`} shapeRendering="optimizeSpeed" />- <line stroke="white" strokeLinecap="round" strokeWidth={whiteLineStrokeWidth} x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 1}, 0)`} />- </React.Fragment>- )+ month: function() {+ return {+ lineLengthY: (item) => {+ let timeScaleUnit = item.dateObject.months;+ let lineLengthY = timeScaleUnit === 0 ? 62 : timeScaleUnit % 3 === 0 ? 22 : 10;+ return lineLengthY;+ }+ };},-}+ year: function() {+ return {+ lineLengthY: (item) => {+ let timeScaleUnit = item.dateObject.years;+ let lineLengthY = timeScaleUnit % 10 === 0 ? 62 : timeScaleUnit % 5 === 0 ? 22 : 10;+ return lineLengthY;+ }+ };+ }+};class TileRect extends PureComponent {render() {- let { item, gridWidth, index, showHover } = this.props;+ let { item, gridWidth, index, showHover, timeScale } = this.props;+ let tileOptions = tileRectTimeScaleOptions[timeScale]();+ let lineLengthY = tileOptions.lineLengthY(item);+ let whiteLineStrokeWidth = lineLengthY !== 10 ? 2 : 1;return (<React.Fragment><g onMouseMove={(e) => showHover(e, item.rawDate, item.rawNextDate, index)}>- { axisScaleGridElement[item.timeScale](gridWidth, index, item) }+ {/* { axisScaleGridElement[item.timeScale](gridWidth, index, item) } */}+ <rect className="grid" width={gridWidth} height={100} transform={`translate(${index * gridWidth}, 0)`} fill={item.withinRange ? 'rgba(0,0,0,0)' : 'black'} shapeRendering="optimizeSpeed"></rect>+ <line stroke="black" strokeLinecap="round" strokeWidth="0.2" x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 2.2}, 0)`} />+ <line stroke="#555" strokeWidth={1} x1="0" x2={gridWidth} y1="46" y2="46" transform={`translate(${index * gridWidth + 1}, 0)`} shapeRendering="optimizeSpeed" />+ <line stroke="white" strokeLinecap="round" strokeWidth={whiteLineStrokeWidth} x1="0" x2="0" y1="0" y2={lineLengthY} transform={`translate(${index * gridWidth + 1}, 0)`} /></g></React.Fragment>);}}+TileRect.propTypes = {+ item: PropTypes.object,+ index: PropTypes.number,+ gridWidth: PropTypes.number,+ draggerPosition: PropTypes.func,+ timeScale: PropTypes.string+};+export default TileRect;