Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Feat] Add Trip Layer - Final (#699)

Shan He241143f6999f
diff --git a/.prettierrc b/.prettierrc
index 7c721411d..38f9643f5 100644
--- a/.prettierrc
+++ b/.prettierrc
@@ -2,5 +2,6 @@
"bracketSpacing": false,
"singleQuote": true,
"trailingComma": "none",
- "semi": true
+ "semi": true,
+ "printWidth": 80
}
diff --git a/docs/user-guides/c-types-of-layers/k.trip.md b/docs/user-guides/c-types-of-layers/k.trip.md
new file mode 100644
index 000000000..581018ab4
--- /dev/null
+++ b/docs/user-guides/c-types-of-layers/k.trip.md
@@ -0,0 +1,67 @@
+# Trip layer
+
+![Trip layer](https://d1a3f4spazzrp4.cloudfront.net/kepler.gl/documentation/k-trip.gif 'Grid layer')
+Trip layer can display animated path.
+
+### How to use trip layer to animate path
+
+**Data format**
+Currently trip layer support a special `geoJSON` format where the coordinate `linestring` has a 4th element denoting timestamp.
+
+In order to animate the path, the `geoJSON` data needs to contain `LineString` in its features' geometry, and the coordinates in the `LineString` need to have 4 elements in the format of `[longitude, latitude, altitude, timestamp]`, with the last element being a timestamp. Valid timestamp formats include unix in seconds such as `1564184363` or in milliseconds such as `1564184363000`.
+
+**Sample data**
+
+```
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {
+ "vendor": "A"
+ },
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [-74.20986, 40.81773, 0, 1564184363],
+ [-74.20987, 40.81765, 0, 1564184396],
+ [-74.20998, 40.81746, 0, 1564184409]
+ ]
+ }
+ }
+ ]
+}
+```
+
+**Note** Support for more data formats such as csv will be added in future releases.
+
+**Layer attributes**
+
+- Color
+
+ The path can be colored by an attribute from the properties.
+ <img src="https://d1a3f4spazzrp4.cloudfront.net/kepler.gl/documentation/k-trip-attribute-colors.png" width="256" title="Color Attribute">
+
+- Stroke Width
+ Stroke width can be set by an attribute from the properties.
+
+- Trail Length
+
+ Trail length determines how long it takes for a path to completely fade out. This can be adjusted using the slider. Short trail length retains few historical locations while long trail length retain more and show a longer tail.
+
+- Animation speed
+ Animation speed can be adjusted using the animation control at the bottom.
+
+**When there are multiple layers**
+
+- Multiple trip layers
+ When you add multiple trip layers, the time range from all the layers will be combined and the animation control will span the entire time range of those layers.
+
+- Multiple layers containing trip layer and other layers
+ Other static layers can be added besides the trip layers. Upon hiding the trip layer, its animation control will also hide, giving place to the filter control.
+
+**Export**
+To export an animated map, you can use a screen recording or gif capture tool.
+
+[Back to table of contents](../a-introduction.md)
diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.js
index 0a325a03d..e7901aa5f 100644
--- a/examples/demo-app/src/app.js
+++ b/examples/demo-app/src/app.js
@@ -50,6 +50,7 @@ import sampleGeojson from './data/sample-small-geojson';
import sampleGeojsonPoints from './data/sample-geojson-points';
import sampleGeojsonConfig from './data/sample-geojson-config';
import sampleH3Data, {config as h3MapConfig} from './data/sample-hex-id-csv';
+import sampleAnimateTrip from './data/sample-animate-trip-data';
import sampleIconCsv, {config as savedMapConfig} from './data/sample-icon-csv';
import {addDataToMap, addNotification} from 'kepler.gl/actions';
import {processCsvData, processGeojson} from 'kepler.gl/processors';
@@ -161,13 +162,15 @@ class App extends Component {
}
_loadSampleData() {
- this._loadTripData();
+ this._loadPointData();
+ // this._loadGeojsonData();
+ this._loadTripGeoJson();
// this._loadIconData();
// this._loadGeojsonData();
// this._loadH3HexagonData();
}
- _loadTripData() {
+ _loadPointData() {
this.props.dispatch(
addDataToMap({
datasets: {
@@ -203,6 +206,19 @@ class App extends Component {
);
}
+ _loadTripGeoJson() {
+ this.props.dispatch(
+ addDataToMap({
+ datasets: [
+ {
+ info: {label: 'Trip animation'},
+ data: processGeojson(sampleAnimateTrip)
+ }
+ ]
+ })
+ );
+ }
+
_loadGeojsonData() {
// load geojson
this.props.dispatch(
@@ -336,9 +352,7 @@ class App extends Component {
getState={state => state.demo.keplerGl}
width={width}
height={height - (showBanner ? BannerHeight : 0)}
- onSaveMap={
- this._isCloudStorageEnabled() && this._toggleCloudModal
- }
+ onSaveMap={this._isCloudStorageEnabled() && this._toggleCloudModal}
/>
)}
</AutoSizer>
diff --git a/examples/demo-app/src/data/sample-animate-trip-data.js b/examples/demo-app/src/data/sample-animate-trip-data.js
new file mode 100644
index 000000000..679ad6891
--- /dev/null
+++ b/examples/demo-app/src/data/sample-animate-trip-data.js
@@ -0,0 +1,414 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+export default {
+ type: 'FeatureCollection',
+ features: [
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-73.78966, 40.6429, 0, 1565578338],
+ [-73.7895, 40.64267, 0, 1565578346],
+ [-73.78923, 40.6424, 0, 1565578356],
+ [-73.78905, 40.64222, 0, 1565578364],
+ [-73.7889, 40.64209, 0, 1565578365],
+ [-73.78859, 40.64191, 0, 1565578367],
+ [-73.78836, 40.64181, 0, 1565578368],
+ [-73.78793, 40.6417, 0, 1565578371],
+ [-73.78756, 40.64163, 0, 1565578373],
+ [-73.78707, 40.64159, 0, 1565578375],
+ [-73.78674, 40.64161, 0, 1565578377],
+ [-73.78659, 40.64166, 0, 1565578378],
+ [-73.78646, 40.64172, 0, 1565578379],
+ [-73.78633, 40.64182, 0, 1565578380],
+ [-73.78612, 40.6422, 0, 1565578382],
+ [-73.78607, 40.64244, 0, 1565578384],
+ [-73.7861, 40.64263, 0, 1565578385],
+ [-73.78621, 40.64305, 0, 1565578388],
+ [-73.78621, 40.64323, 0, 1565578390],
+ [-73.78619, 40.64337, 0, 1565578391],
+ [-73.78612, 40.6435, 0, 1565578392],
+ [-73.78586, 40.64382, 0, 1565578394],
+ [-73.78583, 40.64388, 0, 1565578395],
+ [-73.78582, 40.64397, 0, 1565578395],
+ [-73.78585, 40.64404, 0, 1565578396],
+ [-73.78655, 40.64488, 0, 1565578403],
+ [-73.78666, 40.64505, 0, 1565578404],
+ [-73.78685, 40.64546, 0, 1565578407],
+ [-73.7869, 40.64571, 0, 1565578409],
+ [-73.7869, 40.64592, 0, 1565578410],
+ [-73.78687, 40.64619, 0, 1565578412],
+ [-73.78677, 40.64634, 0, 1565578413],
+ [-73.78668, 40.64643, 0, 1565578414],
+ [-73.78658, 40.64649, 0, 1565578415],
+ [-73.78645, 40.64655, 0, 1565578416],
+ [-73.78629, 40.64657, 0, 1565578416],
+ [-73.78613, 40.64656, 0, 1565578417],
+ [-73.786, 40.64653, 0, 1565578418],
+ [-73.78588, 40.64647, 0, 1565578419],
+ [-73.78578, 40.6464, 0, 1565578419],
+ [-73.7857, 40.6463, 0, 1565578420],
+ [-73.78566, 40.64622, 0, 1565578421],
+ [-73.78565, 40.64607, 0, 1565578422],
+ [-73.78574, 40.64584, 0, 1565578423],
+ [-73.78588, 40.64565, 0, 1565578425],
+ [-73.78611, 40.64547, 0, 1565578427],
+ [-73.78638, 40.64534, 0, 1565578428],
+ [-73.78677, 40.6452, 0, 1565578431],
+ [-73.78702, 40.64514, 0, 1565578432],
+ [-73.78744, 40.64505, 0, 1565578434],
+ [-73.7878, 40.645, 0, 1565578436],
+ [-73.78831, 40.64496, 0, 1565578439],
+ [-73.79014, 40.64495, 0, 1565578449]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'B'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-74.33223, 40.64375, 0, 1565578213],
+ [-74.33242, 40.64353, 0, 1565578217],
+ [-74.33001, 40.64222, 0, 1565578243],
+ [-74.32882, 40.64154, 0, 1565578256],
+ [-74.32682, 40.64039, 0, 1565578278],
+ [-74.32589, 40.63985, 0, 1565578288],
+ [-74.31725, 40.63485, 0, 1565578382],
+ [-74.31404, 40.63302, 0, 1565578417],
+ [-74.30616, 40.6283, 0, 1565578504],
+ [-74.30592, 40.62814, 0, 1565578506],
+ [-74.3056, 40.62783, 0, 1565578511],
+ [-74.30549, 40.62763, 0, 1565578513],
+ [-74.30536, 40.62722, 0, 1565578518],
+ [-74.30524, 40.62704, 0, 1565578521],
+ [-74.30511, 40.62689, 0, 1565578523],
+ [-74.30447, 40.62623, 0, 1565578532],
+ [-74.30409, 40.62652, 0, 1565578536],
+ [-74.30374, 40.62689, 0, 1565578541],
+ [-74.30328, 40.62753, 0, 1565578549],
+ [-74.30297, 40.6279, 0, 1565578553],
+ [-74.30174, 40.6292, 0, 1565578570],
+ [-74.29912, 40.63154, 0, 1565578585],
+ [-74.29855, 40.63202, 0, 1565578588],
+ [-74.29796, 40.63249, 0, 1565578591],
+ [-74.29508, 40.63461, 0, 1565578606],
+ [-74.29448, 40.63508, 0, 1565578610],
+ [-74.29409, 40.6354, 0, 1565578612],
+ [-74.29373, 40.63575, 0, 1565578614],
+ [-74.29322, 40.63626, 0, 1565578617],
+ [-74.29209, 40.63753, 0, 1565578624],
+ [-74.29086, 40.63902, 0, 1565578633],
+ [-74.28998, 40.64015, 0, 1565578639],
+ [-74.28944, 40.64091, 0, 1565578644],
+ [-74.28908, 40.64151, 0, 1565578647],
+ [-74.2888, 40.64201, 0, 1565578649],
+ [-74.2883, 40.64303, 0, 1565578655],
+ [-74.28789, 40.64408, 0, 1565578660],
+ [-74.28762, 40.64494, 0, 1565578664],
+ [-74.28745, 40.6457, 0, 1565578668],
+ [-74.28733, 40.64636, 0, 1565578671],
+ [-74.28723, 40.64724, 0, 1565578676],
+ [-74.28717, 40.64812, 0, 1565578680],
+ [-74.28712, 40.65661, 0, 1565578721],
+ [-74.28709, 40.66022, 0, 1565578739],
+ [-74.28705, 40.6611, 0, 1565578743],
+ [-74.28698, 40.66175, 0, 1565578746],
+ [-74.28687, 40.6624, 0, 1565578750],
+ [-74.28667, 40.66327, 0, 1565578754],
+ [-74.28642, 40.6641, 0, 1565578758],
+ [-74.28619, 40.66472, 0, 1565578761],
+ [-74.28573, 40.66576, 0, 1565578766],
+ [-74.2853, 40.66657, 0, 1565578771],
+ [-74.28506, 40.66697, 0, 1565578773],
+ [-74.28434, 40.66804, 0, 1565578779],
+ [-74.28077, 40.67287, 0, 1565578806]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-73.87893, 40.64672, 0, 1565578095],
+ [-73.87969, 40.64624, 0, 1565578123],
+ [-73.87976, 40.64619, 0, 1565578125],
+ [-73.88064, 40.64697, 0, 1565578156],
+ [-73.88138, 40.64765, 0, 1565578181],
+ [-73.88234, 40.64849, 0, 1565578214],
+ [-73.883, 40.64911, 0, 1565578237],
+ [-73.88338, 40.64943, 0, 1565578250],
+ [-73.88349, 40.64941, 0, 1565578252],
+ [-73.88411, 40.64995, 0, 1565578273],
+ [-73.8848, 40.65076, 0, 1565578302],
+ [-73.88624, 40.6527, 0, 1565578367],
+ [-73.88632, 40.65281, 0, 1565578371],
+ [-73.88747, 40.65232, 0, 1565578386],
+ [-73.88798, 40.6521, 0, 1565578393],
+ [-73.88896, 40.65341, 0, 1565578430],
+ [-73.88978, 40.65306, 0, 1565578442],
+ [-73.89059, 40.65271, 0, 1565578454],
+ [-73.89413, 40.65747, 0, 1565578588],
+ [-73.89424, 40.65762, 0, 1565578593],
+ [-73.89595, 40.65786, 0, 1565578627],
+ [-73.89613, 40.65785, 0, 1565578630],
+ [-73.89616, 40.65796, 0, 1565578633],
+ [-73.898, 40.65768, 0, 1565578661],
+ [-73.8988, 40.65753, 0, 1565578673],
+ [-73.89955, 40.65738, 0, 1565578684],
+ [-73.90021, 40.65728, 0, 1565578695],
+ [-73.90039, 40.65724, 0, 1565578698],
+ [-73.90051, 40.65719, 0, 1565578700],
+ [-73.90063, 40.65712, 0, 1565578703],
+ [-73.90076, 40.65702, 0, 1565578706],
+ [-73.90118, 40.6566, 0, 1565578717],
+ [-73.90135, 40.65646, 0, 1565578721],
+ [-73.90282, 40.65553, 0, 1565578751],
+ [-73.90299, 40.65544, 0, 1565578755],
+ [-73.90319, 40.65536, 0, 1565578758],
+ [-73.90321, 40.65546, 0, 1565578761],
+ [-73.90337, 40.65542, 0, 1565578765],
+ [-73.90616, 40.65501, 0, 1565578836]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-74.18572, 40.68929, 0, 1565577803],
+ [-74.1858, 40.68924, 0, 1565577808],
+ [-74.18564, 40.68909, 0, 1565577821],
+ [-74.18529, 40.68929, 0, 1565577830],
+ [-74.18486, 40.68954, 0, 1565577841],
+ [-74.18482, 40.68982, 0, 1565577849],
+ [-74.18481, 40.691, 0, 1565577882],
+ [-74.18484, 40.69121, 0, 1565577888],
+ [-74.18487, 40.6913, 0, 1565577891],
+ [-74.18494, 40.69143, 0, 1565577895],
+ [-74.18506, 40.69157, 0, 1565577900],
+ [-74.18531, 40.69177, 0, 1565577907],
+ [-74.18612, 40.69232, 0, 1565577931],
+ [-74.18633, 40.69247, 0, 1565577937],
+ [-74.18641, 40.69259, 0, 1565577941],
+ [-74.18643, 40.69267, 0, 1565577943],
+ [-74.18644, 40.69272, 0, 1565577944],
+ [-74.18641, 40.69288, 0, 1565577946],
+ [-74.18636, 40.69297, 0, 1565577947],
+ [-74.18582, 40.69346, 0, 1565577954],
+ [-74.18532, 40.69402, 0, 1565577961],
+ [-74.18499, 40.6945, 0, 1565577967]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'B'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-74.00823, 40.71351, 0, 1565577838],
+ [-74.00884, 40.7138, 0, 1565577867],
+ [-74.00668, 40.71653, 0, 1565577947],
+ [-74.00625, 40.71708, 0, 1565577962],
+ [-74.00753, 40.71766, 0, 1565577996],
+ [-74.00888, 40.71827, 0, 1565578032],
+ [-74.00869, 40.71929, 0, 1565578060],
+ [-74.00858, 40.71996, 0, 1565578077],
+ [-74.01191, 40.72029, 0, 1565578205],
+ [-74.01204, 40.72031, 0, 1565578210],
+ [-74.01097, 40.72554, 0, 1565578295],
+ [-74.01078, 40.72677, 0, 1565578315],
+ [-74.01008, 40.73394, 0, 1565578431],
+ [-74.00983, 40.73694, 0, 1565578480],
+ [-74.00979, 40.73746, 0, 1565578488],
+ [-74.00989, 40.73851, 0, 1565578505],
+ [-74.0099, 40.73899, 0, 1565578513],
+ [-74.00985, 40.73929, 0, 1565578518],
+ [-74.0098, 40.73942, 0, 1565578520],
+ [-74.00967, 40.73971, 0, 1565578525],
+ [-74.00928, 40.74033, 0, 1565578536],
+ [-74.00913, 40.74065, 0, 1565578541],
+ [-74.00906, 40.74081, 0, 1565578544],
+ [-74.00887, 40.74154, 0, 1565578556],
+ [-74.00871, 40.74219, 0, 1565578567],
+ [-74.00868, 40.74235, 0, 1565578569],
+ [-74.00837, 40.74395, 0, 1565578595],
+ [-74.00803, 40.74588, 0, 1565578625],
+ [-74.00773, 40.7475, 0, 1565578651],
+ [-74.00769, 40.74775, 0, 1565578654],
+ [-74.00762, 40.74845, 0, 1565578668],
+ [-74.00768, 40.7487, 0, 1565578672],
+ [-74.00777, 40.74892, 0, 1565578677],
+ [-74.00811, 40.74959, 0, 1565578690],
+ [-74.0082, 40.7498, 0, 1565578694],
+ [-74.00825, 40.75003, 0, 1565578699],
+ [-74.00827, 40.75029, 0, 1565578703],
+ [-74.00825, 40.75055, 0, 1565578708],
+ [-74.00699, 40.75388, 0, 1565578773],
+ [-74.00664, 40.75442, 0, 1565578784],
+ [-74.00336, 40.75891, 0, 1565578881]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-73.97301, 40.67601, 0, 1565578666],
+ [-73.97161, 40.67546, 0, 1565578694],
+ [-73.97142, 40.67575, 0, 1565578712],
+ [-73.9719, 40.67641, 0, 1565578732],
+ [-73.97244, 40.67716, 0, 1565578756],
+ [-73.97234, 40.67744, 0, 1565578778],
+ [-73.96917, 40.67678, 0, 1565578836]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-74.03806, 40.74578, 0, 1565578252],
+ [-74.03893, 40.74289, 0, 1565578322],
+ [-74.03934, 40.74158, 0, 1565578354],
+ [-74.0384, 40.74142, 0, 1565578376],
+ [-74.03746, 40.74126, 0, 1565578399],
+ [-74.03824, 40.73872, 0, 1565578465],
+ [-74.03878, 40.73693, 0, 1565578511],
+ [-74.03893, 40.73693, 0, 1565578513],
+ [-74.03974, 40.73704, 0, 1565578524],
+ [-74.03979, 40.7369, 0, 1565578528],
+ [-74.03964, 40.73677, 0, 1565578531],
+ [-74.03916, 40.73685, 0, 1565578538],
+ [-74.03881, 40.73686, 0, 1565578546],
+ [-74.03854, 40.73684, 0, 1565578553],
+ [-74.03864, 40.73655, 0, 1565578562],
+ [-74.03879, 40.73571, 0, 1565578589],
+ [-74.03943, 40.73155, 0, 1565578722],
+ [-74.03954, 40.7308, 0, 1565578746],
+ [-74.03791, 40.73066, 0, 1565578753],
+ [-74.03782, 40.73065, 0, 1565578754],
+ [-74.03789, 40.73024, 0, 1565578763],
+ [-74.03795, 40.72999, 0, 1565578769],
+ [-74.03797, 40.72988, 0, 1565578770],
+ [-74.03798, 40.7298, 0, 1565578771],
+ [-74.0368, 40.7298, 0, 1565578784],
+ [-74.03646, 40.72977, 0, 1565578788],
+ [-74.03613, 40.72971, 0, 1565578791],
+ [-74.03604, 40.72969, 0, 1565578792],
+ [-74.03222, 40.72883, 0, 1565578822]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'B'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-73.79007, 40.64681, 0, 1565577697],
+ [-73.79092, 40.64643, 0, 1565577720],
+ [-73.79108, 40.64631, 0, 1565577726],
+ [-73.7912, 40.64613, 0, 1565577732],
+ [-73.79121, 40.64597, 0, 1565577737],
+ [-73.79116, 40.64581, 0, 1565577743],
+ [-73.79106, 40.6457, 0, 1565577747],
+ [-73.79094, 40.64557, 0, 1565577749],
+ [-73.79072, 40.64542, 0, 1565577751],
+ [-73.79057, 40.64534, 0, 1565577753],
+ [-73.7904, 40.64527, 0, 1565577754],
+ [-73.79022, 40.64522, 0, 1565577755],
+ [-73.78974, 40.64522, 0, 1565577758],
+ [-73.78916, 40.64528, 0, 1565577760],
+ [-73.78889, 40.64534, 0, 1565577762],
+ [-73.78855, 40.64545, 0, 1565577764],
+ [-73.78827, 40.64558, 0, 1565577765],
+ [-73.78818, 40.6456, 0, 1565577766],
+ [-73.788, 40.64562, 0, 1565577767],
+ [-73.78793, 40.64561, 0, 1565577767],
+ [-73.7878, 40.64556, 0, 1565577768],
+ [-73.78772, 40.64545, 0, 1565577769],
+ [-73.78771, 40.64534, 0, 1565577769],
+ [-73.78775, 40.64524, 0, 1565577770],
+ [-73.78784, 40.64518, 0, 1565577771],
+ [-73.78799, 40.64513, 0, 1565577771],
+ [-73.78984, 40.64512, 0, 1565577781],
+ [-73.79041, 40.64509, 0, 1565577784],
+ [-73.79124, 40.64508, 0, 1565577788],
+ [-73.79167, 40.64506, 0, 1565577790],
+ [-73.79193, 40.64508, 0, 1565577791],
+ [-73.79313, 40.64494, 0, 1565577797],
+ [-73.79412, 40.64485, 0, 1565577802],
+ [-73.79437, 40.64481, 0, 1565577804],
+ [-73.79472, 40.64474, 0, 1565577805],
+ [-73.79569, 40.64469, 0, 1565577808],
+ [-73.79623, 40.64469, 0, 1565577810],
+ [-73.79671, 40.64472, 0, 1565577811],
+ [-73.79722, 40.64478, 0, 1565577813],
+ [-73.79768, 40.64486, 0, 1565577814],
+ [-73.79813, 40.64496, 0, 1565577816],
+ [-73.79865, 40.64511, 0, 1565577817],
+ [-73.79896, 40.64522, 0, 1565577818],
+ [-73.79953, 40.64545, 0, 1565577820],
+ [-73.80022, 40.64582, 0, 1565577823],
+ [-73.80062, 40.64606, 0, 1565577824],
+ [-73.80102, 40.64636, 0, 1565577826],
+ [-73.80178, 40.64703, 0, 1565577829],
+ [-73.80245, 40.64766, 0, 1565577832],
+ [-73.80314, 40.64837, 0, 1565577836],
+ [-73.80379, 40.64909, 0, 1565577839],
+ [-73.80479, 40.65031, 0, 1565577845],
+ [-73.80528, 40.65096, 0, 1565577848],
+ [-73.80578, 40.65166, 0, 1565577851],
+ [-73.80623, 40.65236, 0, 1565577854],
+ [-73.80658, 40.65294, 0, 1565577856],
+ [-73.80681, 40.65342, 0, 1565577858],
+ [-73.80702, 40.65396, 0, 1565577860],
+ [-73.80718, 40.65449, 0, 1565577862],
+ [-73.8073, 40.65502, 0, 1565577864],
+ [-73.80738, 40.6557, 0, 1565577867],
+ [-73.80731, 40.65585, 0, 1565577868],
+ [-73.80719, 40.65642, 0, 1565577873],
+ [-73.8071, 40.6567, 0, 1565577876],
+ [-73.807, 40.65692, 0, 1565577878],
+ [-73.80687, 40.6571, 0, 1565577880],
+ [-73.80672, 40.65725, 0, 1565577881],
+ [-73.80641, 40.65752, 0, 1565577884],
+ [-73.80622, 40.65766, 0, 1565577886],
+ [-73.80606, 40.65781, 0, 1565577887],
+ [-73.80593, 40.65799, 0, 1565577888]
+ ]
+ }
+ }
+ ]
+};
diff --git a/examples/demo-app/src/store.js b/examples/demo-app/src/store.js
index ca1fd544a..98138c01a 100644
--- a/examples/demo-app/src/store.js
+++ b/examples/demo-app/src/store.js
@@ -41,7 +41,7 @@ export const enhancers = [applyMiddleware(...middlewares)];
const initialState = {};
-// add redux devtools
+// add redux devtools
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
export default createStore(
diff --git a/jsconfig.json b/jsconfig.json
index 738e8a465..e34e8f744 100644
--- a/jsconfig.json
+++ b/jsconfig.json
@@ -1,5 +1,9 @@
{
"compilerOptions": {
"baseUrl": "./src"
- }
+ },
+ "include": [
+ "src/**/*",
+ "test/**/*"
+ ]
}
diff --git a/package.json b/package.json
index e546c659b..2debf8a4c 100644
--- a/package.json
+++ b/package.json
@@ -70,9 +70,9 @@
],
"dependencies": {
"@mapbox/geo-viewport": "^0.2.2",
- "@mapbox/geojson-extent": "^0.3.2",
"@mapbox/geojson-normalize": "0.0.1",
"@mapbox/vector-tile": "^1.3.1",
+ "@turf/bbox": "^6.0.1",
"classnames": "^2.2.1",
"colorbrewer": "^1.0.0",
"d3-array": "^1.2.0",
diff --git a/src/actions/vis-state-actions.js b/src/actions/vis-state-actions.js
index fd26460df..c91242153 100644
--- a/src/actions/vis-state-actions.js
+++ b/src/actions/vis-state-actions.js
@@ -311,7 +311,7 @@ export function updateVisData(datasets, options, config) {
* @returns {{type: ActionTypes.TOGGLE_FILTER_ANIMATION, idx: idx}}
* @public
*/
-export function toggleAnimation(idx) {
+export function toggleFilterAnimation(idx) {
return {
type: ActionTypes.TOGGLE_FILTER_ANIMATION,
idx
@@ -326,7 +326,7 @@ export function toggleAnimation(idx) {
* @returns {{type: ActionTypes.UPDATE_FILTER_ANIMATION_SPEED, idx: idx, speed: speed}}
* @public
*/
-export function updateAnimationSpeed(idx, speed) {
+export function updateFilterAnimationSpeed(idx, speed) {
return {
type: ActionTypes.UPDATE_FILTER_ANIMATION_SPEED,
idx,
@@ -334,6 +334,34 @@ export function updateAnimationSpeed(idx, speed) {
};
}
+/**
+ * Reset animation
+ * @memberof visStateActions
+ * @param {Number} value - Current value of the slider
+ * @returns {{type: ActionTypes.RESET_ANIMATION, value: value}}
+ * @public
+ */
+export function updateAnimationTime(value) {
+ return {
+ type: ActionTypes.UPDATE_ANIMATION_TIME,
+ value
+ };
+}
+
+/**
+ * update trip layer animation speed
+ * @memberof visStateActions
+ * @param {Number} speed - `speed` to change it to. `speed` is a multiplier
+ * @returns {{type: ActionTypes.UPDATE_LAYER_ANIMATION_SPEED, speed: speed}}
+ * @public
+ */
+export function updateLayerAnimationSpeed(speed) {
+ return {
+ type: ActionTypes.UPDATE_LAYER_ANIMATION_SPEED,
+ speed
+ };
+}
+
/**
* Show larger time filter at bottom for time playback (apply to time filter only)
* @memberof visStateActions
diff --git a/src/components/bottom-widget.js b/src/components/bottom-widget.js
index d0955d46e..3a59a3c9f 100644
--- a/src/components/bottom-widget.js
+++ b/src/components/bottom-widget.js
@@ -19,13 +19,18 @@
// THE SOFTWARE.
import React from 'react';
+import styled from 'styled-components';
import PropTypes from 'prop-types';
import TimeWidgetFactory from './filters/time-widget';
+import AnimationControlFactory from './common/animation-control/animation-control';
+import {FILTER_TYPES} from 'utils/filter-utils';
const propTypes = {
filters: PropTypes.arrayOf(PropTypes.object),
datasets: PropTypes.object,
uiState: PropTypes.object,
+ layers: PropTypes.arrayOf(PropTypes.object),
+ animationConfig: PropTypes.object,
visStateActions: PropTypes.object,
sidePanelWidth: PropTypes.number,
containerW: PropTypes.number
@@ -33,44 +38,81 @@ const propTypes = {
const maxWidth = 1080;
-BottomWidgetFactory.deps = [TimeWidgetFactory];
+BottomWidgetFactory.deps = [TimeWidgetFactory, AnimationControlFactory];
-export default function BottomWidgetFactory(TimeWidget) {
+const BottomWidgetContainer = styled.div`
+ position: absolute;
+ display: flex;
+ flex-direction: column;
+ padding-top: ${props => props.theme.sidePanel.margin.top}px;
+ padding-right: ${props => props.theme.sidePanel.margin.right}px;
+ padding-bottom: ${props => props.theme.sidePanel.margin.bottom}px;
+ padding-left: ${props => props.theme.sidePanel.margin.left}px;
+ width: ${props => props.width}px;
+ bottom: 0;
+ right: 0;
+ z-index: 1;
+`;
- const BottomWidget = (props) => {
+export default function BottomWidgetFactory(TimeWidget, AnimationControl) {
+ const BottomWidget = props => {
const {
datasets,
filters,
+ animationConfig,
visStateActions,
containerW,
uiState,
- sidePanelWidth
+ sidePanelWidth,
+ layers
} = props;
+
const {activeSidePanel, readOnly} = uiState;
const isOpen = Boolean(activeSidePanel);
- const enlargedFilterIdx = filters.findIndex(f => f.enlarged);
+ const enlargedFilterIdx = filters.findIndex(f => f.enlarged && f.type === FILTER_TYPES.timeRange);
const isAnyFilterAnimating = filters.some(f => f.isAnimating);
- const enlargedFilterWidth = isOpen ? containerW - sidePanelWidth : containerW;
+ const enlargedFilterWidth = isOpen
+ ? containerW - sidePanelWidth
+ : containerW;
- if (enlargedFilterIdx < 0) {
- return null;
- }
+ // show playback control if layers contain trip layer & at least one trip layer is visible
+ const animatedLayer = layers.filter(
+ l =>
+ l.config.animation && l.config.animation.enabled && l.config.isVisible
+ );
+ const readToAnimation = Array.isArray(animationConfig.domain) && animationConfig.currentTime;
+ // if animation control is showing, hide time display in time slider
+ const showFloatingTimeDisplay = !animatedLayer.length;
return (
- <TimeWidget
- fields={datasets[filters[enlargedFilterIdx].dataId].fields}
- setFilterPlot={visStateActions.setFilterPlot}
- setFilter={visStateActions.setFilter}
- toggleAnimation={visStateActions.toggleAnimation}
- updateAnimationSpeed={visStateActions.updateAnimationSpeed}
- enlargeFilter={visStateActions.enlargeFilter}
+ <BottomWidgetContainer
width={Math.min(maxWidth, enlargedFilterWidth)}
- isAnyFilterAnimating={isAnyFilterAnimating}
- enlargedIdx={enlargedFilterIdx}
- filter={filters[enlargedFilterIdx]}
- readOnly={readOnly}
- />
+ className="bottom-widget--container"
+ >
+ {animatedLayer.length && readToAnimation ? (
+ <AnimationControl
+ animationConfig={animationConfig}
+ updateAnimationTime={visStateActions.updateAnimationTime}
+ updateAnimationSpeed={visStateActions.updateLayerAnimationSpeed}
+ />
+ ) : null}
+ {enlargedFilterIdx > -1 ? (
+ <TimeWidget
+ filter={filters[enlargedFilterIdx]}
+ index={enlargedFilterIdx}
+ isAnyFilterAnimating={isAnyFilterAnimating}
+ datasets={datasets}
+ readOnly={readOnly}
+ showTimeDisplay={showFloatingTimeDisplay}
+ setFilterPlot={visStateActions.setFilterPlot}
+ setFilter={visStateActions.setFilter}
+ toggleAnimation={visStateActions.toggleFilterAnimation}
+ updateAnimationSpeed={visStateActions.updateFilterAnimationSpeed}
+ enlargeFilter={visStateActions.enlargeFilter}
+ />
+ ) : null}
+ </BottomWidgetContainer>
);
};
diff --git a/src/components/common/animation-control/animation-control.js b/src/components/common/animation-control/animation-control.js
new file mode 100644
index 000000000..cad5bb0ad
--- /dev/null
+++ b/src/components/common/animation-control/animation-control.js
@@ -0,0 +1,197 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import React, {Component} from 'react';
+import styled from 'styled-components';
+import moment from 'moment';
+import {requestAnimationFrame, cancelAnimationFrame} from 'global/window';
+
+import Slider from 'components/common/slider/slider';
+import {BottomWidgetInner} from 'components/common/styled-components';
+import SpeedControlFactory from './speed-control';
+import AnimationPlaybacksFactory from './playback-controls';
+import FloatingTimeDisplayFactory from './floating-time-display';
+import {BASE_SPEED} from 'constants/default-settings';
+
+const SliderWrapper = styled.div`
+ display: flex;
+ position: relative;
+ flex-grow: 1;
+ margin-right: 24px;
+ margin-left: 24px;
+`;
+
+const AnimationWidgetInner = styled.div`
+ position: relative;
+ display: flex;
+ align-items: center;
+ height: 32px;
+
+ .animation-control__speed-control {
+ margin-right: -10px;
+
+ .animation-control__speed-slider {
+ right: calc(0% - 10px);
+ }
+ }
+`;
+
+const StyledDomain = styled.div`
+ color: ${props => props.theme.titleTextColor};
+ font-weight: 400;
+ font-size: 10px;
+`;
+
+const defaultTimeFormat = 'MM/DD/YY hh:mm:ss';
+const BUTTON_HEIGHT = '18px';
+
+AnimationControlFactory.deps = [
+ SpeedControlFactory,
+ AnimationPlaybacksFactory,
+ FloatingTimeDisplayFactory
+];
+
+function AnimationControlFactory(
+ SpeedControl,
+ AnimationPlaybacks,
+ FloatingTimeDisplay
+) {
+ class AnimationControl extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ isAnimating: false,
+ width: 288,
+ showSpeedControl: false
+ };
+ this._animation = null;
+ }
+
+ componentDidUpdate() {
+ if (!this._animation && this.state.isAnimating) {
+ this._animation = requestAnimationFrame(this._nextFrame);
+ }
+ }
+
+ onSlider1Change = val => {
+ const {domain} = this.props.animationConfig;
+ if (val >= domain[0] && val <= domain[1]) {
+ this.props.updateAnimationTime(val);
+ }
+ };
+
+ _updateAnimationTime = () => {
+ const {domain} = this.props.animationConfig;
+ this.props.updateAnimationTime(domain[0]);
+ this._startAnimation();
+ };
+
+ _startAnimation = () => {
+ this._pauseAnimation();
+ this.setState({isAnimating: true});
+ };
+
+ _nextFrame = () => {
+ this._animation = null;
+ const {currentTime, domain, speed} = this.props.animationConfig;
+ const adjustedSpeed = ((domain[1] - domain[0]) / BASE_SPEED) * speed;
+ const nextTime =
+ currentTime + speed > domain[1]
+ ? domain[0]
+ : currentTime + adjustedSpeed;
+ this.props.updateAnimationTime(nextTime);
+ };
+
+ _pauseAnimation = () => {
+ if (this._animation) {
+ cancelAnimationFrame(this._animation);
+ this._animation = null;
+ }
+ this.setState({isAnimating: false});
+ };
+
+ toggleSpeedControl = () => {
+ this.setState({showSpeedControl: !this.state.showSpeedControl});
+ };
+
+ onChange = () => {
+ this.toggleSpeedControl();
+ };
+
+ render() {
+ const {currentTime, domain, speed} = this.props.animationConfig;
+ const {showSpeedControl} = this.state;
+
+ return (
+ <BottomWidgetInner className="bottom-widget--inner">
+ <AnimationWidgetInner className="animation-widget--inner">
+ <div style={{marginLeft: '-10px'}}>
+ <AnimationPlaybacks
+ className="animation-control-playpause"
+ startAnimation={this._startAnimation}
+ isAnimating={this.state.isAnimating}
+ pauseAnimation={this._pauseAnimation}
+ resetAnimation={this._resetAnimation}
+ buttonHeight={BUTTON_HEIGHT}
+ buttonStyle="link"
+ />
+ </div>
+ <StyledDomain className="animation-control__time-domain">
+ <span>{moment.utc(domain[0]).format(defaultTimeFormat)}</span>
+ </StyledDomain>
+ <SliderWrapper className="animation-control__slider">
+ <Slider
+ showValues={false}
+ isRanged={false}
+ minValue={domain ? domain[0] : 0}
+ maxValue={domain ? domain[1] : 1}
+ value1={currentTime}
+ onSlider1Change={this.onSlider1Change}
+ enableBarDrag={true}
+ />
+ </SliderWrapper>
+ <StyledDomain className="animation-control__time-domain">
+ <span>{moment.utc(domain[1]).format(defaultTimeFormat)}</span>
+ </StyledDomain>
+ <div className="animation-control__speed-control">
+ <SpeedControl
+ onClick={this.toggleSpeedControl}
+ showSpeedControl={showSpeedControl}
+ updateAnimationSpeed={this.props.updateAnimationSpeed}
+ speed={speed}
+ buttonHeight={BUTTON_HEIGHT}
+ />
+ </div>
+ </AnimationWidgetInner>
+ <FloatingTimeDisplay currentTime={currentTime} />
+ </BottomWidgetInner>
+ );
+ }
+ }
+
+ AnimationControl.defaultProps = {
+ sliderHandleWidth: 12,
+ onChange: () => {}
+ };
+
+ return AnimationControl;
+}
+
+export default AnimationControlFactory;
diff --git a/src/components/filters/animation-speed-toggle.js b/src/components/common/animation-control/animation-speed-slider.js
similarity index 62%
rename from src/components/filters/animation-speed-toggle.js
rename to src/components/common/animation-control/animation-speed-slider.js
index edf4263a3..b1f2dd4c0 100644
--- a/src/components/filters/animation-speed-toggle.js
+++ b/src/components/common/animation-control/animation-speed-slider.js
@@ -20,49 +20,54 @@
import React, {Component} from 'react';
import styled from 'styled-components';
-import Slider from 'components/common/slider/slider';
+import RangeSlider from 'components/common/range-slider';
import onClickOutside from 'react-onclickoutside';
+import {SPEED_CONTROL_RANGE} from 'constants/default-settings';
const SliderWrapper = styled.div`
position: relative;
- width: 20px;
- height: 120px;
- flex-direction: column;
- display: flex;
`;
-const VerticalSliderContainer = styled.div`
+const SpeedSliderContainer = styled.div`
position: absolute;
- right: 96px;
- bottom: 10px;
- width: 40px;
- padding-left: 18px;
+ bottom: 50px;
+ right: calc(0% - 32px);
+ width: 180px;
+ padding: 2px 8px 2px 12px;
+ background-color: ${props => props.theme.panelBackground};
+ box-shadow: -2px -2px 0 0 rgba(0,0,0,0.10);
+ .kg-range-slider__input {
+ width: 36px;
+ }
`;
-class AnimationSpeedToggle extends Component {
+class AnimationSpeedSlider extends Component {
handleClickOutside = e => {
this.props.onHide();
};
+ _onChange = v => this.props.updateAnimationSpeed(v[1]);
+
render() {
- const {updateAnimationSpeed, speed} = this.props;
return (
- <VerticalSliderContainer>
+ <SpeedSliderContainer className="animation-control__speed-slider">
<SliderWrapper>
- <Slider
- minValue={0}
- maxValue={10}
- step={0.1}
- value1={speed}
- onSlider1Change={updateAnimationSpeed}
+ <RangeSlider
+ range={SPEED_CONTROL_RANGE}
+ step={0.01}
+ value0={0}
+ value1={this.props.speed}
+ onChange={this._onChange}
isRanged={false}
- vertical
showTooltip
+ showInput
+ inputTheme="secondary"
+ inputSize="tiny"
/>
</SliderWrapper>
- </VerticalSliderContainer>
+ </SpeedSliderContainer>
);
}
}
-export default onClickOutside(AnimationSpeedToggle);
+export default onClickOutside(AnimationSpeedSlider);
diff --git a/src/components/common/animation-control/floating-time-display.js b/src/components/common/animation-control/floating-time-display.js
new file mode 100644
index 000000000..16a5fbb3e
--- /dev/null
+++ b/src/components/common/animation-control/floating-time-display.js
@@ -0,0 +1,187 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import React, {PureComponent} from 'react';
+import styled from 'styled-components';
+import moment from 'moment';
+import {createSelector} from 'reselect';
+import {Minus} from 'components/common/icons';
+import {DEFAULT_TIME_FORMAT} from 'constants/default-settings';
+import {CenterFlexbox} from 'components/common/styled-components';
+
+const StyledTimeDisplay = styled.div`
+ background-color: ${props => props.theme.panelBackground};
+ border-radius: ${props => props.theme.timeDisplayBorderRadius}px;
+ bottom: ${props => `calc(100% + ${props.theme.bottomPanelGap}px)`};
+ color: ${props => props.theme.titleTextColor};
+ display: flex;
+ height: ${props => props.theme.timeDisplayHeight}px;
+ justify-content: center;
+ left: calc(50% - 88px);
+ min-width: ${props => props.theme.timeDisplayMinWidth}px;
+ opacity: ${props => props.theme.timeDisplayOpacity};
+ padding: ${props => props.theme.timeDisplayPadding};
+ position: absolute;
+`;
+
+const StyledTimeDisplayGroups = styled.div`
+ align-items: center;
+ display: flex;
+ flex-direction: row;
+`;
+
+const StyledTimeDisplayRows = styled.div`
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+`;
+
+const StyledTimeDisplayTop = styled.div.attrs({
+ className: 'animation-control__time-display__top'
+})`
+ color: ${props => props.theme.textColor};
+ display: flex;
+ font-size: 12px;
+ font-weight: 500;
+ justify-content: center;
+`;
+
+const StyledTimeDisplayBottom = styled.div.attrs({
+ className: 'animation-control__time-display__bottom'
+})`
+ color: ${props => props.theme.titleTextColor};
+ display: flex;
+ font-size: 14px;
+ font-weight: 500;
+ justify-content: center;
+`;
+
+const StyledTimeValueGroup = styled.div.attrs({
+ className: 'animation-control__time-value-group'
+})`
+ display: flex;
+ flex-direction: column;
+`;
+
+const StyledHorizontalBar = styled.div.attrs({
+ className: 'animation-control__horizontal-bar'
+})`
+ margin: 0 12px;
+`;
+
+const TimeDivider = () => (
+ <StyledHorizontalBar>
+ <Minus height="12px" />
+ </StyledHorizontalBar>
+);
+
+const TimeDisplayRow = ({timeValues = []}) => (
+ <CenterFlexbox>
+ <div>{timeValues[0]}</div>
+ {timeValues[1] ? <TimeDivider /> : null}
+ {timeValues[1] ? <div>{timeValues[1]}</div> : null}
+ </CenterFlexbox>
+);
+
+export default function FloatingTimeDisplayFactory() {
+ class FloatingTimeDisplay extends PureComponent {
+ timeSelector = props => props.currentTime;
+ formatSelector = props => props.format;
+ displayTimeSelector = createSelector(
+ this.timeSelector,
+ this.formatSelector,
+ (currentTime, format) => {
+ const groupTime = Array.isArray(currentTime)
+ ? currentTime
+ : [currentTime];
+ return groupTime.reduce(
+ (accu, curr) => {
+ const displayDateTime = moment.utc(curr).format(format);
+ const [displayDate, displayTime] = displayDateTime.split(' ');
+
+ if (!accu.displayDate.includes(displayDate)) {
+ accu.displayDate.push(displayDate);
+ }
+ accu.displayTime.push(displayTime);
+
+ return accu;
+ },
+ {displayDate: [], displayTime: []}
+ );
+ }
+ );
+
+ render() {
+ const {displayDate, displayTime} = this.displayTimeSelector(this.props);
+ const twoGroups = displayDate.length === 2 && displayTime.length === 2;
+ const bottomRow = displayTime.length
+ ? displayTime
+ : displayDate.length
+ ? displayDate
+ : null;
+ const topRow =
+ displayDate.length && displayTime.length ? displayDate : null;
+
+ return (
+ <StyledTimeDisplay className="animation-control__time-display">
+ {twoGroups ? (
+ <StyledTimeDisplayGroups>
+ <StyledTimeValueGroup>
+ {/* Time Start */}
+ <StyledTimeDisplayTop>{displayDate[0]}</StyledTimeDisplayTop>
+ <StyledTimeDisplayBottom>
+ {displayTime[0]}
+ </StyledTimeDisplayBottom>
+ </StyledTimeValueGroup>
+ <TimeDivider />
+ <StyledTimeValueGroup>
+ {/* Time End */}
+ <StyledTimeDisplayTop>{displayDate[1]}</StyledTimeDisplayTop>
+ <StyledTimeDisplayBottom>
+ {displayTime[1]}
+ </StyledTimeDisplayBottom>
+ </StyledTimeValueGroup>
+ </StyledTimeDisplayGroups>
+ ) : (
+ <StyledTimeDisplayRows>
+ {topRow ? (
+ <StyledTimeDisplayTop>
+ <TimeDisplayRow timeValues={topRow} />
+ </StyledTimeDisplayTop>
+ ) : null}
+ {bottomRow ? (
+ <StyledTimeDisplayBottom>
+ <TimeDisplayRow timeValues={bottomRow} />
+ </StyledTimeDisplayBottom>
+ ) : null}
+ </StyledTimeDisplayRows>
+ )}
+ </StyledTimeDisplay>
+ );
+ }
+ }
+
+ FloatingTimeDisplay.defaultProps = {
+ format: DEFAULT_TIME_FORMAT,
+ currentTime: null
+ };
+
+ return FloatingTimeDisplay;
+}
diff --git a/src/components/common/animation-control/playback-controls.js b/src/components/common/animation-control/playback-controls.js
new file mode 100644
index 000000000..9d678f85f
--- /dev/null
+++ b/src/components/common/animation-control/playback-controls.js
@@ -0,0 +1,89 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import React from 'react';
+import styled from 'styled-components';
+import classnames from 'classnames';
+
+import {ButtonGroup, Button} from 'components/common/styled-components';
+import {Play, Reset, Pause} from 'components/common/icons';
+
+const StyledAnimationControls = styled.div`
+ display: flex;
+ margin-right: 12px;
+
+ &.disabled {
+ opacity: 0.4;
+ pointer-events: none;
+ }
+`;
+
+const IconButton = styled(Button)`
+ padding: 6px 4px;
+ svg {
+ margin: 0 6px;
+ }
+`;
+
+function nop() {};
+const DEFAULT_BUTTON_HEIGHT = '18px';
+
+function AnimationPlaybacksFactory() {
+ const AnimationPlaybacks = ({
+ isAnimatable,
+ isAnimating,
+ buttonStyle,
+ pauseAnimation = nop,
+ updateAnimationTime = nop,
+ startAnimation = nop,
+ buttonHeight = DEFAULT_BUTTON_HEIGHT
+ }) => {
+ const btnStyle = buttonStyle ? {[buttonStyle]: true} : {};
+ return (
+ <StyledAnimationControls
+ className={classnames('time-range-slider__control', {
+ disabled: !isAnimatable
+ })}
+ >
+ <ButtonGroup>
+ <IconButton className="playback-control-button"
+ {...btnStyle}
+ onClick={updateAnimationTime}>
+ <Reset height={buttonHeight} />
+ </IconButton>
+ <IconButton
+ {...btnStyle}
+ className={classnames('playback-control-button', {active: isAnimating})}
+ onClick={isAnimating ? pauseAnimation : startAnimation}
+ >
+ {isAnimating ? (
+ <Pause height={buttonHeight} />
+ ) : (
+ <Play height={buttonHeight} />
+ )}
+ </IconButton>
+ </ButtonGroup>
+ </StyledAnimationControls>
+ );
+ };
+ return AnimationPlaybacks;
+}
+
+export default AnimationPlaybacksFactory;
diff --git a/src/components/common/animation-control/speed-control.js b/src/components/common/animation-control/speed-control.js
new file mode 100644
index 000000000..75e746611
--- /dev/null
+++ b/src/components/common/animation-control/speed-control.js
@@ -0,0 +1,64 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import React from 'react';
+import styled from 'styled-components';
+import AnimationSpeedSlider from './animation-speed-slider';
+import {Button, CenterFlexbox} from 'components/common/styled-components';
+import {Rocket} from 'components/common/icons';
+
+const StyledSpeedToggle = styled.div`
+ display: flex;
+ flex-grow: 0;
+ color: ${props => props.theme.textColor};
+ position: relative;
+`;
+
+const StyledSpeedText = styled.div`
+ display: inline-block;
+ width: 24px;
+ text-align: left;
+`;
+
+function SpeedControlFactory() {
+ const SpeedControl = ({onClick, updateAnimationSpeed, speed, showSpeedControl, buttonHeight='18px'}) => (
+ <StyledSpeedToggle className="animation-control__speed-control">
+ <Button link width="80px" onClick={onClick}>
+ <CenterFlexbox className="bottom-widget__icon speed">
+ <Rocket height={buttonHeight} />
+ </CenterFlexbox>
+ <StyledSpeedText
+ style={{visibility: !showSpeedControl ? 'visible' : 'hidden'}}
+ >
+ {speed}x
+ </StyledSpeedText>
+ </Button>
+ {showSpeedControl ? (
+ <AnimationSpeedSlider
+ onHide={onClick}
+ updateAnimationSpeed={updateAnimationSpeed}
+ speed={speed}
+ />
+ ) : null}
+ </StyledSpeedToggle>
+ );
+ return SpeedControl;
+}
+export default SpeedControlFactory;
diff --git a/src/components/common/field-selector.js b/src/components/common/field-selector.js
index b0d39cdcc..b80ea3f6d 100644
--- a/src/components/common/field-selector.js
+++ b/src/components/common/field-selector.js
@@ -128,7 +128,7 @@ export default class FieldSelector extends Component {
render() {
return (
- <div>
+ <div className="field-selector">
<ItemSelector
getOptionValue={d => d}
closeOnSelect={this.props.closeOnSelect}
diff --git a/src/components/common/range-plot.js b/src/components/common/range-plot.js
index f97df3bba..e606fcaa4 100644
--- a/src/components/common/range-plot.js
+++ b/src/components/common/range-plot.js
@@ -31,9 +31,9 @@ import classnames from 'classnames';
import RangeBrush from './range-brush';
import {getTimeWidgetHintFormatter} from 'utils/filter-utils';
-const chartMargin = {top: 18, bottom: 0, left: 0, right: 0};
+const chartMargin = {top: 8, bottom: 0, left: 0, right: 0};
const chartH = 52;
-const containerH = 78;
+const containerH = 68;
const histogramStyle = {
highlightW: 0.7,
unHighlightedW: 0.4
diff --git a/src/components/common/range-slider.js b/src/components/common/range-slider.js
index 30f8dd1b3..5b0467198 100644
--- a/src/components/common/range-slider.js
+++ b/src/components/common/range-slider.js
@@ -29,15 +29,14 @@ import {Input} from 'components/common/styled-components';
import {roundValToStep} from 'utils/data-utils';
const SliderInput = styled(Input)`
- height: ${props => props.theme.sliderInputHeight}px;
width: ${props => props.theme.sliderInputWidth}px;
- padding: 4px 6px;
- margin-left: ${props => props.flush ? 0 : 24}px;
+ margin-left: ${props => (props.flush ? 0 : props.size === 'tiny' ? 12 : 18)}px;
`;
const SliderWrapper = styled.div`
display: flex;
position: relative;
+ align-items: center;
`;
const RangeInputWrapper = styled.div`
@@ -57,6 +56,7 @@ export default class RangeSlider extends Component {
isEnlarged: PropTypes.bool,
showInput: PropTypes.bool,
inputTheme: PropTypes.string,
+ inputSize: PropTypes.string,
step: PropTypes.number,
sliderHandleWidth: PropTypes.number,
xAxis: PropTypes.func
@@ -67,6 +67,8 @@ export default class RangeSlider extends Component {
isRanged: true,
showInput: true,
sliderHandleWidth: 12,
+ inputTheme: '',
+ inputSize: 'small',
onChange: () => {}
};
@@ -172,6 +174,7 @@ export default class RangeSlider extends Component {
}}
onBlur={update}
flush={key === 'value0'}
+ size={this.props.inputSize}
secondary={this.props.inputTheme === 'secondary'}
/>
);
@@ -195,11 +198,12 @@ export default class RangeSlider extends Component {
const height = isRanged && showInput ? '16px' : '24px';
const {width} = this.state;
- const plotWidth = width - sliderHandleWidth;
+ const plotWidth = width - sliderHandleWidth;
return (
<div
- className="kg-range-slider" style={{width: '100%', padding: `0 ${sliderHandleWidth / 2}px`}}
+ className="kg-range-slider"
+ style={{width: '100%', padding: `0 ${sliderHandleWidth / 2}px`}}
ref={this.sliderContainer}
>
{histogram && histogram.length ? (
@@ -209,20 +213,17 @@ export default class RangeSlider extends Component {
plotType={plotType}
isEnlarged={isEnlarged}
onBrush={(val0, val1) => {
- onChange([
- this._roundValToStep(val0),
- this._roundValToStep(val1)
- ]);
+ onChange([this._roundValToStep(val0), this._roundValToStep(val1)]);
}}
range={range}
value={[value0, value1]}
width={plotWidth}
/>
) : null}
- <SliderWrapper
- style={{height}}
- className="kg-range-slider__slider">
- {this.props.xAxis ? <this.props.xAxis width={plotWidth} domain={range}/> : null}
+ <SliderWrapper style={{height}} className="kg-range-slider__slider">
+ {this.props.xAxis ? (
+ <this.props.xAxis width={plotWidth} domain={range} />
+ ) : null}
<Slider
showValues={false}
isRanged={isRanged}
@@ -241,11 +242,13 @@ export default class RangeSlider extends Component {
/>
{!isRanged && showInput ? this._renderInput('value1') : null}
</SliderWrapper>
- {isRanged && showInput ? <RangeInputWrapper className="range-slider__input-group">
- {this._renderInput('value0')}
- {this._renderInput('value1')}
- </RangeInputWrapper> : null}
+ {isRanged && showInput ? (
+ <RangeInputWrapper className="range-slider__input-group">
+ {this._renderInput('value0')}
+ {this._renderInput('value1')}
+ </RangeInputWrapper>
+ ) : null}
</div>
);
}
-};
+}
diff --git a/src/components/common/slider/slider.js b/src/components/common/slider/slider.js
index 199f8451b..799d6622a 100644
--- a/src/components/common/slider/slider.js
+++ b/src/components/common/slider/slider.js
@@ -40,7 +40,10 @@ const StyledRangeSlider = styled.div`
const SliderWrapper = styled.div`
flex-grow: 1;
- margin-top: ${props => (props.isRanged ? 0 : 10)}px;
+ margin-top: ${props =>
+ props.isRanged
+ ? props.theme.sliderMarginTopIsRange
+ : props.theme.sliderMarginTop}px;
`;
export default class Slider extends Component {
@@ -85,7 +88,9 @@ export default class Slider extends Component {
ref = createRef();
_getBaseDistance() {
- return this.props.vertical ? this.ref.current.offsetHeight : this.ref.current.offsetWidth;
+ return this.props.vertical
+ ? this.ref.current.offsetHeight
+ : this.ref.current.offsetWidth;
}
_getValDelta(x) {
@@ -96,7 +101,7 @@ export default class Slider extends Component {
_getValue(val, offset) {
const delta = this._getValDelta(offset);
- const rawValue = this.props.vertical ? val - delta : val + delta;
+ const rawValue = this.props.vertical ? val - delta : val + delta;
return this._roundValToStep(rawValue);
}
@@ -153,6 +158,7 @@ export default class Slider extends Component {
render() {
const {
classSet,
+ disabled,
isRanged,
maxValue,
minValue,
@@ -165,11 +171,12 @@ export default class Slider extends Component {
const currValDelta = value1 - value0;
const maxDelta = maxValue - minValue;
const width = (currValDelta / maxDelta) * 100;
+
const v0Left = ((value0 - minValue) / maxDelta) * 100;
return (
<SliderWrapper
- className={classnames('kg-slider', {...classSet})}
+ className={classnames('kg-slider', {...classSet, disabled})}
ref={this.ref}
isRanged={isRanged}
vertical={vertical}
diff --git a/src/components/common/styled-components.js b/src/components/common/styled-components.js
index d6ed42ebf..3f6bdf9ca 100644
--- a/src/components/common/styled-components.js
+++ b/src/components/common/styled-components.js
@@ -64,11 +64,11 @@ export const SpaceBetweenFlexbox = styled.div`
display: flex;
align-items: space-between;
margin-left: -16px;
-`
+`;
export const SBFlexboxItem = styled.div`
flex-grow: 1;
margin-left: 16px;
-`
+`;
export const PanelLabel = styled.label.attrs({
className: 'side-panel-panel__label'
@@ -182,34 +182,29 @@ export const Button = styled.div.attrs({
props.negative
? props.theme.negativeBtnBgd
: props.secondary
- ? props.theme.secondaryBtnBgd
- : props.link ? props.theme.linkBtnBgd : props.theme.primaryBtnBgd};
+ ? props.theme.secondaryBtnBgd
+ : props.link
+ ? props.theme.linkBtnBgd
+ : props.theme.primaryBtnBgd};
border-radius: ${props => props.theme.primaryBtnRadius};
color: ${props =>
props.negative
? props.theme.negativeBtnColor
: props.secondary
- ? props.theme.secondaryBtnColor
- : props.link ? props.theme.linkBtnColor : props.theme.primaryBtnColor};
+ ? props.theme.secondaryBtnColor
+ : props.link
+ ? props.theme.linkBtnColor
+ : props.theme.primaryBtnColor};
cursor: pointer;
display: inline-flex;
- font-size: ${props =>
- props.large ?
- '14px'
- : props.small
- ? '10px'
- : '11px'};
+ font-size: ${props => (props.large ? '14px' : props.small ? '10px' : '11px')};
font-weight: 500;
justify-content: center;
letter-spacing: 0.3px;
line-height: 14px;
outline: 0;
padding: ${props =>
- props.large ?
- '14px 32px'
- : props.small
- ? '6px 9px'
- : '9px 12px'};
+ props.large ? '14px 32px' : props.small ? '6px 9px' : '9px 12px'};
text-align: center;
transition: ${props => props.theme.transition};
vertical-align: middle;
@@ -225,18 +220,18 @@ export const Button = styled.div.attrs({
props.negative
? props.theme.negativeBtnBgdHover
: props.secondary
- ? props.theme.secondaryBtnBgdHover
- : props.link
- ? props.theme.linkBtnActBgdHover
- : props.theme.primaryBtnBgdHover};
+ ? props.theme.secondaryBtnBgdHover
+ : props.link
+ ? props.theme.linkBtnActBgdHover
+ : props.theme.primaryBtnBgdHover};
color: ${props =>
props.negative
? props.theme.negativeBtnActColor
: props.secondary
- ? props.theme.secondaryBtnActColor
- : props.link
- ? props.theme.linkBtnActColor
- : props.theme.primaryBtnActColor};
+ ? props.theme.secondaryBtnActColor
+ : props.link
+ ? props.theme.linkBtnActColor
+ : props.theme.primaryBtnActColor};
}
svg {
@@ -311,13 +306,20 @@ export const DatasetSquare = styled.div`
width: 8px;
height: 8px;
background-color: rgb(${props => props.color.join(',')});
- margin-right: 12px
+ margin-right: 12px;
`;
export const SelectionButton = styled.div`
border-radius: 2px;
- border: 1px solid ${props => props.selected ? props.theme.primaryBtnBgd : props.theme.selectBorderColorLT};
- color: ${props => props.selected ? props.theme.primaryBtnBgd : props.theme.selectBorderColorLT};
+ border: 1px solid
+ ${props =>
+ props.selected
+ ? props.theme.primaryBtnBgd
+ : props.theme.selectBorderColorLT};
+ color: ${props =>
+ props.selected
+ ? props.theme.primaryBtnBgd
+ : props.theme.selectBorderColorLT};
cursor: pointer;
font-weight: 500;
margin-right: 6px;
@@ -343,10 +345,10 @@ export const Table = styled.table`
}
tbody {
- tr td {
- border-bottom: ${props => props.theme.panelBorderLT};
- padding: 12px;
- }
+ tr td {
+ border-bottom: ${props => props.theme.panelBorderLT};
+ padding: 12px;
+ }
}
`;
@@ -416,34 +418,22 @@ export const StyledExportSection = styled.div`
width: 250px;
height: 36px;
- background-image:
- linear-gradient(45deg, transparent 50%, gray 50%),
+ background-image: linear-gradient(45deg, transparent 50%, gray 50%),
linear-gradient(135deg, gray 50%, transparent 50%),
linear-gradient(to right, #ccc, #ccc);
- background-position:
- calc(100% - 20px) calc(1em + 2px),
- calc(100% - 15px) calc(1em + 2px),
- calc(100% - 2.5em) 4.5em;
- background-size:
- 5px 5px,
- 5px 5px,
- 1px 1.5em;
+ background-position: calc(100% - 20px) calc(1em + 2px),
+ calc(100% - 15px) calc(1em + 2px), calc(100% - 2.5em) 4.5em;
+ background-size: 5px 5px, 5px 5px, 1px 1.5em;
background-repeat: no-repeat;
}
select:focus {
- background-image:
- linear-gradient(45deg, green 50%, transparent 50%),
+ background-image: linear-gradient(45deg, green 50%, transparent 50%),
linear-gradient(135deg, transparent 50%, green 50%),
linear-gradient(to right, #ccc, #ccc);
- background-position:
- calc(100% - 15px) 1em,
- calc(100% - 20px) 1em,
+ background-position: calc(100% - 15px) 1em, calc(100% - 20px) 1em,
calc(100% - 2.5em) 4.5em;
- background-size:
- 5px 5px,
- 5px 5px,
- 1px 1.5em;
+ background-size: 5px 5px, 5px 5px, 1px 1.5em;
background-repeat: no-repeat;
border-color: green;
outline: 0;
@@ -454,7 +444,11 @@ export const StyledExportSection = styled.div`
export const StyledFilteredOption = styled.div`
align-items: center;
border-radius: 2px;
- border: 1px solid ${props => props.selected ? props.theme.primaryBtnBgd : props.theme.selectBorderColorLT};
+ border: 1px solid
+ ${props =>
+ props.selected
+ ? props.theme.primaryBtnBgd
+ : props.theme.selectBorderColorLT};
cursor: pointer;
display: flex;
flex-direction: column;
@@ -481,8 +475,15 @@ export const StyledFilteredOption = styled.div`
export const StyledType = styled.div`
border-radius: 2px;
- border: 1px solid ${props => props.selected ? props.theme.primaryBtnBgd : props.theme.selectBorderColorLT};
- color: ${props => props.selected ? props.theme.primaryBtnBgd : props.theme.selectBorderColorLT};
+ border: 1px solid
+ ${props =>
+ props.selected
+ ? props.theme.primaryBtnBgd
+ : props.theme.selectBorderColorLT};
+ color: ${props =>
+ props.selected
+ ? props.theme.primaryBtnBgd
+ : props.theme.selectBorderColorLT};
cursor: pointer;
font-weight: 500;
height: 100px;
@@ -495,3 +496,15 @@ export const StyledType = styled.div`
border: 1px solid ${props => props.available && props.theme.primaryBtnBgd};
}
`;
+
+export const WidgetContainer = styled.div`
+ z-index: 1;
+`;
+
+export const BottomWidgetInner = styled.div`
+ background-color: ${props => props.theme.panelBackground};
+ padding: ${props =>
+ `${props.theme.bottomInnerPdVert}px ${props.theme.bottomInnerPdSide}px`};
+ position: relative;
+ margin-top: ${props => props.theme.bottomPanelGap}px;
+`;
diff --git a/src/components/common/time-range-slider.js b/src/components/common/time-range-slider.js
index 18a3d9547..d375f5624 100644
--- a/src/components/common/time-range-slider.js
+++ b/src/components/common/time-range-slider.js
@@ -22,161 +22,222 @@ import React, {Component} from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import {requestAnimationFrame, cancelAnimationFrame} from 'global/window';
-import classnames from 'classnames';
import throttle from 'lodash.throttle';
import styled from 'styled-components';
import {createSelector} from 'reselect';
-import {Play, Reset, Pause, Minus} from 'components/common/icons';
-import {SelectTextBold, SelectText, Button, ButtonGroup} from 'components/common/styled-components';
-import {getTimeWidgetTitleFormatter, BASE_SPEED} from 'utils/filter-utils';
-import RangeSlider from './range-slider';
-import TimeSliderMarker from './time-slider-marker';
-const defaultTimeFormat = val => moment.utc(val).format('MM/DD/YY hh:mma');
+import {Minus} from 'components/common/icons';
+import {SelectTextBold, SelectText} from 'components/common/styled-components';
+import RangeSlider from 'components/common/range-slider';
+import TimeSliderMarker from 'components/common/time-slider-marker';
+import PlaybackControlsFactory from 'components/common/animation-control/playback-controls';
+import {BASE_SPEED, DEFAULT_TIME_FORMAT} from 'constants/default-settings';
+
const animationControlWidth = 140;
const StyledSliderContainer = styled.div`
- margin-top: ${props => props.isEnlarged ? '12px' : '0px'};
align-items: flex-end;
display: flex;
flex-direction: row;
justify-content: space-between;
+
+ .time-range-slider__control {
+ margin-bottom: 12px;
+ margin-right: 30px;
+ }
+
+ .playback-control-button {
+ padding: 9px 12px;
+ }
`;
-export default class TimeRangeSlider extends Component {
- static propTypes = {
- onChange: PropTypes.func.isRequired,
- domain: PropTypes.arrayOf(PropTypes.number).isRequired,
- value: PropTypes.arrayOf(PropTypes.number).isRequired,
- step: PropTypes.number.isRequired,
- plotType: PropTypes.string,
- histogram: PropTypes.arrayOf(PropTypes.any),
- lineChart: PropTypes.object,
- toggleAnimation: PropTypes.func.isRequired,
- isAnimatable: PropTypes.bool,
- isEnlarged: PropTypes.bool,
- speed: PropTypes.number
- };
+TimeRangeSliderFactory.deps = [PlaybackControlsFactory];
- constructor(props) {
- super(props);
- this.state = {
- isAnimating: false,
- width: 288
+export default function TimeRangeSliderFactory(PlaybackControls) {
+ class TimeRangeSlider extends Component {
+ static propTypes = {
+ onChange: PropTypes.func.isRequired,
+ domain: PropTypes.arrayOf(PropTypes.number).isRequired,
+ value: PropTypes.arrayOf(PropTypes.number).isRequired,
+ step: PropTypes.number.isRequired,
+ plotType: PropTypes.string,
+ histogram: PropTypes.arrayOf(PropTypes.any),
+ lineChart: PropTypes.object,
+ toggleAnimation: PropTypes.func.isRequired,
+ isAnimatable: PropTypes.bool,
+ isEnlarged: PropTypes.bool,
+ speed: PropTypes.number,
+ timeFormat: PropTypes.string,
+ hideTimeTitle: PropTypes.bool
};
- this._animation = null;
- this._sliderThrottle = throttle((...value) => this.props.onChange(...value), 20);
- }
- componentDidUpdate() {
- if (!this._animation && this.state.isAnimating) {
- this._animation = requestAnimationFrame(this._nextFrame);
+ constructor(props) {
+ super(props);
+ this.state = {
+ isAnimating: false,
+ width: 288
+ };
+ this._animation = null;
+ this._sliderThrottle = throttle(
+ (...value) => this.props.onChange(...value),
+ 20
+ );
}
- }
- domainSelector = props => props.domain;
- titleFormatter = createSelector(this.domainSelector, domain =>
- getTimeWidgetTitleFormatter(domain)
- );
+ componentDidUpdate() {
+ if (!this._animation && this.state.isAnimating) {
+ this._animation = requestAnimationFrame(this._nextFrame);
+ }
+ }
- _sliderUpdate = args => {
- this._sliderThrottle.cancel();
- this._sliderThrottle(args);
- };
+ timeSelector = props => props.currentTime;
+ formatSelector = props => props.format;
+ displayTimeSelector = createSelector(
+ this.timeSelector,
+ this.formatSelector,
+ (currentTime, format) => {
+ const groupTime = Array.isArray(currentTime)
+ ? currentTime
+ : [currentTime];
+ return groupTime.reduce(
+ (accu, curr) => {
+ const displayDateTime = moment.utc(curr).format(format);
+ const [displayDate, displayTime] = displayDateTime.split(' ');
- _resetAnimation = () => {
- const {domain, value} = this.props;
- const value0 = domain[0];
- const value1 = value0 + value[1] - value[0];
- this.props.onChange([value0, value1]);
- };
+ if (!accu.displayDate.includes(displayDate)) {
+ accu.displayDate.push(displayDate);
+ }
+ accu.displayTime.push(displayTime);
- _startAnimation = () => {
- this._pauseAnimation();
- this.props.toggleAnimation();
- this.setState({isAnimating: true});
- };
+ return accu;
+ },
+ {displayDate: [], displayTime: []}
+ );
+ }
+ );
+
+ _sliderUpdate = args => {
+ this._sliderThrottle.cancel();
+ this._sliderThrottle(args);
+ };
- _pauseAnimation = () => {
- if (this._animation) {
- cancelAnimationFrame(this._animation);
+ _resetAnimation = () => {
+ const {domain, value} = this.props;
+ const value0 = domain[0];
+ const value1 = value0 + value[1] - value[0];
+ this.props.onChange([value0, value1]);
+ };
+
+ _startAnimation = () => {
+ this._pauseAnimation();
this.props.toggleAnimation();
+ this.setState({isAnimating: true});
+ };
+
+ _pauseAnimation = () => {
+ if (this._animation) {
+ cancelAnimationFrame(this._animation);
+ this.props.toggleAnimation();
+ this._animation = null;
+ }
+ this.setState({isAnimating: false});
+ };
+
+ _nextFrame = () => {
this._animation = null;
- }
- this.setState({isAnimating: false});
- };
- _nextFrame = () => {
- this._animation = null;
+ const {domain, value} = this.props;
+ const speed = ((domain[1] - domain[0]) / BASE_SPEED) * this.props.speed;
- const {domain, value} = this.props;
- const speed = ((domain[1] - domain[0]) / BASE_SPEED) * this.props.speed;
+ // loop when reaches the end
+ const value0 =
+ value[1] + speed > domain[1] ? domain[0] : value[0] + speed;
+ const value1 = value0 + value[1] - value[0];
+ this.props.onChange([value0, value1]);
+ };
- // loop when reaches the end
- const value0 = value[1] + speed > domain[1] ? domain[0] : value[0] + speed;
- const value1 = value0 + value[1] - value[0];
- this.props.onChange([value0, value1]);
- };
+ render() {
+ const {domain, value, isEnlarged, hideTimeTitle} = this.props;
+ const {isAnimating} = this.state;
- render() {
- const {domain, value, isEnlarged} = this.props;
- const {isAnimating} = this.state;
-
- return (
- <div className="time-range-slider">
- <TimeTitle
- timeFormat={this.titleFormatter(this.props)}
- value={value}
- isEnlarged={isEnlarged}
- />
- <StyledSliderContainer
- className="time-range-slider__container"
- isEnlarged={isEnlarged}>
- {isEnlarged ? <AnimationControls
- isAnimatable={this.props.isAnimatable}
- isEnlarged={isEnlarged}
- isAnimating={isAnimating}
- pauseAnimation={this._pauseAnimation}
- resetAnimation={this._resetAnimation}
- startAnimation={this._startAnimation}
- /> : null}
- <div style={{width: isEnlarged ? `calc(100% - ${animationControlWidth}px)` : '100%'}}>
- <RangeSlider
- range={domain}
- value0={value[0]}
- value1={value[1]}
- histogram={this.props.histogram}
- lineChart={this.props.lineChart}
- plotType={this.props.plotType}
+ return (
+ <div className="time-range-slider">
+ {!hideTimeTitle ? (
+ <TimeTitle
+ timeFormat={this.props.timeFormat}
+ value={value}
isEnlarged={isEnlarged}
- showInput={false}
- step={this.props.step}
- onChange={this._sliderUpdate}
- xAxis={TimeSliderMarker}
/>
- </div>
- </StyledSliderContainer>
- </div>
- );
+ ) : null}
+ <StyledSliderContainer
+ className="time-range-slider__container"
+ isEnlarged={isEnlarged}
+ >
+ {isEnlarged ? (
+ <PlaybackControls
+ isAnimatable={this.props.isAnimatable}
+ isEnlarged={isEnlarged}
+ isAnimating={isAnimating}
+ pauseAnimation={this._pauseAnimation}
+ resetAnimation={this._resetAnimation}
+ startAnimation={this._startAnimation}
+ buttonHeight="12px"
+ buttonStyle="secondary"
+ />
+ ) : null}
+ <div
+ style={{
+ width: isEnlarged
+ ? `calc(100% - ${animationControlWidth}px)`
+ : '100%'
+ }}
+ >
+ <RangeSlider
+ range={domain}
+ value0={value[0]}
+ value1={value[1]}
+ histogram={this.props.histogram}
+ lineChart={this.props.lineChart}
+ plotType={this.props.plotType}
+ isEnlarged={isEnlarged}
+ showInput={false}
+ step={this.props.step}
+ onChange={this._sliderUpdate}
+ xAxis={TimeSliderMarker}
+ />
+ </div>
+ </StyledSliderContainer>
+ </div>
+ );
+ }
}
+
+ TimeRangeSlider.defaultProps = {
+ timeFormat: DEFAULT_TIME_FORMAT
+ };
+
+ return TimeRangeSlider;
}
const TimeValueWrapper = styled.div`
display: flex;
- height: 32px;
align-items: center;
font-size: 11px;
- justify-content: ${props => props.isEnlarged ? 'center' : 'space-between'};
- color: ${props => props.theme.textColorHl};
+ justify-content: ${props => (props.isEnlarged ? 'center' : 'space-between')};
.horizontal-bar {
padding: 0 12px;
+ color: ${props => props.theme.titleTextColor};
}
.time-value {
display: flex;
- flex-direction: ${props => props.isEnlarged ? 'row' : 'column'};
+ flex-direction: ${props => (props.isEnlarged ? 'row' : 'column')};
align-items: flex-start;
+
+ span {
+ color: ${props => props.theme.titleTextColor};
+ }
}
.time-value:last-child {
@@ -184,65 +245,46 @@ const TimeValueWrapper = styled.div`
}
`;
-const TimeTitle = ({value, isEnlarged, timeFormat = defaultTimeFormat}) => (
- <TimeValueWrapper isEnlarged={isEnlarged}>
- <TimeValue key={0} value={moment.utc(value[0]).format(timeFormat)} split={!isEnlarged}/>
+const TimeTitle = ({value, isEnlarged, timeFormat = DEFAULT_TIME_FORMAT}) => (
+ <TimeValueWrapper
+ isEnlarged={isEnlarged}
+ className="time-range-slider__time-title"
+ >
+ <TimeValue
+ key={0}
+ value={moment.utc(value[0]).format(timeFormat)}
+ split={!isEnlarged}
+ />
{isEnlarged ? (
<div className="horizontal-bar">
- <Minus height="12px"/>
+ <Minus height="12px" />
</div>
) : null}
- <TimeValue key={1} value={moment.utc(value[1]).format(timeFormat)} split={!isEnlarged}/>
+ <TimeValue
+ key={1}
+ value={moment.utc(value[1]).format(timeFormat)}
+ split={!isEnlarged}
+ />
</TimeValueWrapper>
);
const TimeValue = ({value, split}) => (
// render two lines if not enlarged
<div className="time-value">
- {split ? value.split(' ').map((v, i) => (
- <div key={i}>
- {i === 0 ? <SelectText>{v}</SelectText> :
- <SelectTextBold>{v}</SelectTextBold>}
- </div>
- )) : <SelectTextBold>{value}</SelectTextBold>}
+ {split ? (
+ value
+ .split(' ')
+ .map((v, i) => (
+ <div key={i}>
+ {i === 0 ? (
+ <SelectText>{v}</SelectText>
+ ) : (
+ <SelectTextBold>{v}</SelectTextBold>
+ )}
+ </div>
+ ))
+ ) : (
+ <SelectTextBold>{value}</SelectTextBold>
+ )}
</div>
);
-
-const StyledAnimationControls = styled.div`
- margin-bottom: 12px;
- margin-right: 42px;
-
- &.disabled {
- opacity: 0.4;
- pointer-events: none;
- }
-`;
-
-const IconButton = styled(Button)`
- svg {
- margin: 0 6px;
- }
-`;
-
-const AnimationControls = ({
- isAnimatable,
- isAnimating,
- pauseAnimation,
- resetAnimation,
- startAnimation
-}) => (
- <StyledAnimationControls
- className={classnames('time-range-slider__control', {disabled: !isAnimatable})}
- >
- <ButtonGroup>
- <IconButton className="playback-control-button"
- onClick={resetAnimation} secondary>
- <Reset height="12px"/>
- </IconButton>
- <IconButton className={classnames('playback-control-button', {active: isAnimating})}
- onClick={isAnimating ? pauseAnimation : startAnimation} secondary>
- {isAnimating ? <Pause height="12px"/> : <Play height="12px"/>}
- </IconButton>
- </ButtonGroup>
- </StyledAnimationControls>
-);
diff --git a/src/components/filters/index.js b/src/components/filters/index.js
index 83d4fc56e..5d6ed7e59 100644
--- a/src/components/filters/index.js
+++ b/src/components/filters/index.js
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-export {default as SingleSelectFilter} from './single-select-filter';
-export {default as MultiSelectFilter} from './multi-select-filter';
-export {default as TimeRangeFilter} from './time-range-filter';
-export {default as RangeFilter} from './range-filter';
+export {default as SingleSelectFilterFactory} from './single-select-filter';
+export {default as MultiSelectFilterFactory} from './multi-select-filter';
+export {default as TimeRangeFilterFactory} from './time-range-filter';
+export {default as RangeFilterFactory} from './range-filter';
diff --git a/src/components/filters/multi-select-filter.js b/src/components/filters/multi-select-filter.js
index 7cf8ce27c..f4fb470d1 100644
--- a/src/components/filters/multi-select-filter.js
+++ b/src/components/filters/multi-select-filter.js
@@ -22,15 +22,16 @@ import React from 'react';
import ItemSelector from '../common/item-selector/item-selector';
import {PanelLabel} from '../common/styled-components';
-const MultiSelectFilter = ({filter, setFilter}) => (
- <div>
- <PanelLabel htmlFor={`filter-${filter.id}`}>Values in</PanelLabel>
- <ItemSelector
- options={filter.domain}
- selectedItems={filter.value}
- onChange={setFilter}
- />
- </div>
-);
-
-export default MultiSelectFilter;
+export default function MultiSelectFilterFactory() {
+ const MultiSelectFilter = ({filter, setFilter}) => (
+ <div>
+ <PanelLabel htmlFor={`filter-${filter.id}`}>Values in</PanelLabel>
+ <ItemSelector
+ options={filter.domain}
+ selectedItems={filter.value}
+ onChange={setFilter}
+ />
+ </div>
+ );
+ return MultiSelectFilter;
+}
diff --git a/src/components/filters/range-filter.js b/src/components/filters/range-filter.js
index 88c7c0c0b..87a622633 100644
--- a/src/components/filters/range-filter.js
+++ b/src/components/filters/range-filter.js
@@ -21,19 +21,21 @@
import React from 'react';
import RangeSlider from 'components/common/range-slider';
-const RangeFilter = ({filter, setFilter}) => (
- <div>
- <RangeSlider
- range={filter.domain}
- value0={filter.value[0]}
- value1={filter.value[1]}
- step={filter.step}
- histogram={filter.histogram}
- isEnlarged={filter.isEnlarged}
- onChange={setFilter}
- inputTheme="secondary"
- />
- </div>
-);
+export default function RangeFilterFactory() {
+ const RangeFilter = ({filter, setFilter}) => (
+ <div>
+ <RangeSlider
+ range={filter.domain}
+ value0={filter.value[0]}
+ value1={filter.value[1]}
+ step={filter.step}
+ histogram={filter.histogram}
+ isEnlarged={filter.isEnlarged}
+ onChange={setFilter}
+ inputTheme="secondary"
+ />
+ </div>
+ );
-export default RangeFilter;
+ return RangeFilter;
+}
diff --git a/src/components/filters/single-select-filter.js b/src/components/filters/single-select-filter.js
index 98e8bb21a..a957b6b6f 100644
--- a/src/components/filters/single-select-filter.js
+++ b/src/components/filters/single-select-filter.js
@@ -22,21 +22,23 @@ import React from 'react';
import ItemSelector from '../common/item-selector/item-selector';
import {PanelLabel, SidePanelSection} from '../common/styled-components';
-const SingleSelectFilter = ({filter, setFilter}) => (
- <SidePanelSection>
- <PanelLabel>Value equals</PanelLabel>
- <ItemSelector
- selectedItems={filter.value}
- placeholder="Select a Value"
- options={filter.domain}
- multiSelect={false}
- searchable={false}
- displayOption={d => String(d)}
- getOptionValue={d => d}
- onChange={setFilter}
- inputTheme="secondary"
- />
- </SidePanelSection>
-);
+export default function SingleSelectFilterFactory() {
+ const SingleSelectFilter = ({filter, setFilter}) => (
+ <SidePanelSection>
+ <PanelLabel>Value equals</PanelLabel>
+ <ItemSelector
+ selectedItems={filter.value}
+ placeholder="Select a Value"
+ options={filter.domain}
+ multiSelect={false}
+ searchable={false}
+ displayOption={d => String(d)}
+ getOptionValue={d => d}
+ onChange={setFilter}
+ inputTheme="secondary"
+ />
+ </SidePanelSection>
+ );
-export default SingleSelectFilter;
+ return SingleSelectFilter;
+}
diff --git a/src/components/filters/time-range-filter.js b/src/components/filters/time-range-filter.js
index 7ad39dde3..d52da5006 100644
--- a/src/components/filters/time-range-filter.js
+++ b/src/components/filters/time-range-filter.js
@@ -19,18 +19,22 @@
// THE SOFTWARE.
import React from 'react';
-import TimeRangeSlider from 'components/common/time-range-slider';
+import TimeRangeSliderFactory from 'components/common/time-range-slider';
/*
* TimeRangeFilter -> TimeRangeSlider -> RangeSlider
*/
-const TimeRangeFilter = ({
- filter,
- setFilter,
- isAnyFilterAnimating,
- toggleAnimation
-}) => (
- <div>
+
+TimeRangeFilterFactory.deps = [TimeRangeSliderFactory];
+
+function TimeRangeFilterFactory(TimeRangeSlider) {
+ const TimeRangeFilter = ({
+ filter,
+ setFilter,
+ isAnimatable,
+ toggleAnimation,
+ hideTimeTitle
+ }) => (
<TimeRangeSlider
domain={filter.domain}
value={filter.value}
@@ -38,13 +42,18 @@ const TimeRangeFilter = ({
lineChart={filter.lineChart}
step={filter.step}
speed={filter.speed}
- histogram={filter.enlarged ? filter.enlargedHistogram : filter.histogram}
+ histogram={
+ filter.enlarged ? filter.enlargedHistogram : filter.histogram
+ }
onChange={setFilter}
toggleAnimation={toggleAnimation}
- isAnimatable={!isAnyFilterAnimating || filter.isAnimating}
+ isAnimatable={isAnimatable}
isEnlarged={filter.enlarged}
+ hideTimeTitle={hideTimeTitle}
/>
- </div>
-);
+ );
+
+ return TimeRangeFilter;
+}
-export default TimeRangeFilter;
+export default TimeRangeFilterFactory;
diff --git a/src/components/filters/time-widget.js b/src/components/filters/time-widget.js
index 2cea289e4..4d0c7df56 100644
--- a/src/components/filters/time-widget.js
+++ b/src/components/filters/time-widget.js
@@ -23,38 +23,26 @@ import styled from 'styled-components';
import {createSelector} from 'reselect';
import FieldSelector from 'components/common/field-selector';
-import {Button, SelectTextBold, IconRoundSmall, CenterFlexbox} from 'components/common/styled-components';
-import TimeRangeFilter from 'components/filters/time-range-filter';
-import {Close, Clock, LineChart, Rocket} from 'components/common/icons';
-import AnimationSpeedToggle from './animation-speed-toggle';
-
-const innerPdSide = 32;
-
-const WidgetContainer = styled.div`
- position: absolute;
- padding-top: ${props => props.theme.sidePanel.margin.top}px;
- padding-right: ${props => props.theme.sidePanel.margin.right}px;
- padding-bottom: ${props => props.theme.sidePanel.margin.bottom}px;
- padding-left: ${props => props.theme.sidePanel.margin.left}px;
- bottom: 0;
- right: 0;
- z-index: 1;
- width: ${props => props.width}px;
-
- .bottom-widget--inner {
- background-color: ${props => props.theme.sidePanelBg};
- padding: 6px ${innerPdSide}px 10px ${innerPdSide}px;
- position: relative;
- }
-`;
+
+import {
+ SelectTextBold,
+ IconRoundSmall,
+ CenterFlexbox,
+ BottomWidgetInner
+} from 'components/common/styled-components';
+import {Close, Clock, LineChart} from 'components/common/icons';
+import SpeedControlFactory from 'components/common/animation-control/speed-control';
+import TimeRangeFilterFactory from 'components/filters/time-range-filter';
+import FloatingTimeDisplayFactory from 'components/common/animation-control/floating-time-display';
+
+const TOP_SECTION_HEIGHT = '36px';
const TopSectionWrapper = styled.div`
- position: absolute;
display: flex;
justify-content: space-between;
width: 100%;
- padding-right: ${innerPdSide * 2}px;
color: ${props => props.theme.labelColor};
+ height: ${TOP_SECTION_HEIGHT};
.bottom-widget__y-axis {
flex-grow: 1;
@@ -85,37 +73,21 @@ const TopSectionWrapper = styled.div`
.item-selector__dropdown__value {
color: ${props =>
- props.hoverColor
- ? props.theme[props.hoverColor]
- : props.theme.textColorHl};
+ props.hoverColor
+ ? props.theme[props.hoverColor]
+ : props.theme.textColorHl};
}
}
}
-`;
-/* eslint-disable no-unused-vars */
-const Tabs = styled.div`
- padding-right: 76px;
-`;
+ .animation-control__speed-control {
+ margin-right: -12px;
-const Tab = styled.div`
- border-bottom: 1px solid
- ${props => (props.active ? props.theme.textColorHl : 'transparent')};
- color: ${props =>
- props.active ? props.theme.textColorHl : props.theme.labelColor};
- display: inline-block;
- font-size: 12px;
- height: 24px;
- margin-right: 4px;
- text-align: center;
- width: 24px;
- line-height: 24px;
-
- :hover {
- cursor: pointer;
+ .animation-control__speed-slider {
+ right: calc(0% - 48px);
+ }
}
`;
-/* eslint-enable no-unused-vars */
const StyledTitle = styled(CenterFlexbox)`
flex-grow: 0;
@@ -130,57 +102,71 @@ const StyledTitle = styled(CenterFlexbox)`
}
`;
-export class TimeWidget extends Component {
- state = {
- showSpeedControl: false
- };
-
- _toggleSpeedControl = () => {
- this.setState({showSpeedControl: !this.state.showSpeedControl})
- };
-
- fieldSelector = props => props.fields;
- yAxisFieldsSelector = createSelector(this.fieldSelector, fields =>
- fields.filter(f => f.type === 'integer' || f.type === 'real')
- );
-
- render() {
- const {
- enlargedIdx,
- enlargeFilter,
- filter,
- isAnyFilterAnimating,
- setFilter,
- setFilterPlot,
- toggleAnimation,
- updateAnimationSpeed,
- width,
- readOnly
- } = this.props;
-
- const {showSpeedControl} = this.state;
- return (
- <WidgetContainer width={width}>
- <div className="bottom-widget--inner">
+TimeWidgetFactory.deps = [
+ SpeedControlFactory,
+ TimeRangeFilterFactory,
+ FloatingTimeDisplayFactory
+];
+
+function TimeWidgetFactory(SpeedControl, TimeRangeFilter, FloatingTimeDisplay) {
+ class TimeWidget extends Component {
+ state = {
+ showSpeedControl: false
+ };
+
+ fieldSelector = props => props.fields;
+ yAxisFieldsSelector = createSelector(
+ this.fieldSelector,
+ fields => fields.filter(f => f.type === 'integer' || f.type === 'real')
+ );
+
+ _updateAnimationSpeed = speed =>
+ this.props.updateAnimationSpeed(this.props.index, speed);
+
+ _toggleSpeedControl = () =>
+ this.setState({showSpeedControl: !this.state.showSpeedControl});
+
+ _setFilterPlotYAxis = value =>
+ this.props.setFilterPlot(this.props.index, {yAxis: value});
+
+ _updateAnimationSpeed = speed =>
+ this.props.updateAnimationSpeed(this.props.index, speed);
+
+ _toggleAnimation = () => this.props.toggleAnimation(this.props.index);
+
+ _onClose = () => this.props.enlargeFilter(this.props.index);
+
+ render() {
+ const {
+ datasets,
+ filter,
+ index,
+ readOnly,
+ setFilter,
+ showTimeDisplay
+ } = this.props;
+
+ const {showSpeedControl} = this.state;
+ return (
+ <BottomWidgetInner className="bottom-widget--inner">
<TopSectionWrapper>
<StyledTitle className="bottom-widget__field">
<CenterFlexbox className="bottom-widget__icon">
- <Clock height="15px"/>
+ <Clock height="15px" />
</CenterFlexbox>
<SelectTextBold>{filter.name}</SelectTextBold>
</StyledTitle>
<StyledTitle className="bottom-widget__y-axis">
<CenterFlexbox className="bottom-widget__icon">
- <LineChart height="15px"/>
+ <LineChart height="15px" />
</CenterFlexbox>
<div className="bottom-widget__field-select">
<FieldSelector
- fields={this.yAxisFieldsSelector(this.props)}
+ fields={this.yAxisFieldsSelector(datasets[filter.dataId])}
placement="top"
id="selected-time-widget-field"
value={filter.yAxis ? filter.yAxis.name : null}
- onSelect={value => setFilterPlot(enlargedIdx, {yAxis: value})}
- inputTheme="secondary"
+ onSelect={this._setFilterPlotYAxis}
placeholder="Y Axis"
erasable
showToken={false}
@@ -188,41 +174,36 @@ export class TimeWidget extends Component {
</div>
</StyledTitle>
<StyledTitle className="bottom-widget__speed">
- <Button link width="80px" onClick={this._toggleSpeedControl}>
- <CenterFlexbox className="bottom-widget__icon speed">
- <Rocket height="15px"/>
- </CenterFlexbox>
- <div style={{
- visibility: !showSpeedControl ? 'visible' : 'hidden',
- display: 'inline-block',
- width: '27px'
- }}>{filter.speed}x</div>
- </Button>
- {showSpeedControl ? <AnimationSpeedToggle
- onHide={this._toggleSpeedControl}
- updateAnimationSpeed={(speed) => updateAnimationSpeed(enlargedIdx, speed)}
- speed={filter.speed}/> : null}
+ <SpeedControl
+ onClick={this._toggleSpeedControl}
+ showSpeedControl={showSpeedControl}
+ updateAnimationSpeed={this._updateAnimationSpeed}
+ speed={filter.speed}
+ />
</StyledTitle>
{!readOnly ? (
<CenterFlexbox>
<IconRoundSmall>
- <Close height="12px" onClick={() => enlargeFilter(enlargedIdx)} />
+ <Close height="12px" onClick={this._onClose} />
</IconRoundSmall>
</CenterFlexbox>
) : null}
</TopSectionWrapper>
<TimeRangeFilter
filter={filter}
- setFilter={value => setFilter(enlargedIdx, 'value', value)}
- isAnyFilterAnimating={isAnyFilterAnimating}
- updateAnimationSpeed={(speed) => updateAnimationSpeed(enlargedIdx, speed)}
- toggleAnimation={() => toggleAnimation(enlargedIdx)}
+ setFilter={value => setFilter(index, 'value', value)}
+ toggleAnimation={this._toggleAnimation}
+ hideTimeTitle={showTimeDisplay}
+ isAnimatable
/>
- </div>
- </WidgetContainer>
- );
+ {showTimeDisplay ? (
+ <FloatingTimeDisplay currentTime={filter.value} />
+ ) : null}
+ </BottomWidgetInner>
+ );
+ }
}
+ return TimeWidget;
}
-const TimeWidgetFactory = () => TimeWidget;
export default TimeWidgetFactory;
diff --git a/src/components/index.js b/src/components/index.js
index 99c3a297a..f72dca8e1 100644
--- a/src/components/index.js
+++ b/src/components/index.js
@@ -18,6 +18,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+import TimeRangeSliderFactory from './common/time-range-slider';
+
// Components
export {default as KeplerGl, default, injectComponents} from './container';
@@ -76,8 +78,19 @@ export {default as ExportImageModalFactory} from './modals/export-image-modal';
export {default as ExportDataModalFactory} from './modals/export-data-modal';
export {default as AddMapStyleModalFactory} from './modals/add-map-style-modal';
-// // Bottom widget factory
+// // common factory
+export {default as AnimationControlFactory} from './common/animation-control/animation-control';
+export {default as SpeedControlFactory} from './common/animation-control/speed-control';
+export {default as AnimationPlaybacksFactory} from './common/animation-control/playback-controls';
+export {default as FloatingTimeDisplayFactory} from './common/animation-control/floating-time-display';
+
+// // Filters
export {default as TimeWidgetFactory} from './filters/time-widget';
+export {default as SingleSelectFilterFactory} from './filters/single-select-filter';
+export {default as MultiSelectFilterFactory} from './filters/multi-select-filter';
+export {default as TimeRangeFilterFactory} from './filters/time-range-filter';
+
+export {default as RangeFilterFactory} from './filters/range-filter';
// Injector
export {
@@ -90,10 +103,12 @@ export {default as FileUpload} from './common/file-uploader/file-upload';
export {default as ItemSelector} from './common/item-selector/item-selector';
export {default as FieldSelector} from './common/field-selector';
export {default as RangeSlider} from './common/range-slider';
-export {default as TimeRangeSlider} from './common/time-range-slider';
export {default as Modal, ModalFooter, ModalTitle} from './common/modal';
export {default as AppLogo} from './common/logo';
export {default as Switch} from './common/switch';
export {default as LoadingSpinner} from './common/loading-spinner';
export * from './common/styled-components';
export * as Icons from './common/icons';
+
+export const TimeRangeSlider = TimeRangeSliderFactory();
+export {TimeRangeSliderFactory};
diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.js
index cf58276ae..d0ee59f07 100644
--- a/src/components/kepler-gl.js
+++ b/src/components/kepler-gl.js
@@ -21,7 +21,7 @@
import React, {Component, createRef} from 'react';
import {console as Console} from 'global/window';
import {bindActionCreators} from 'redux';
-import styled, {ThemeProvider, withTheme} from 'styled-components';
+import styled, {ThemeProvider, withTheme} from 'styled-components';
import {createSelector} from 'reselect';
import {connect as keplerGlConnect} from 'connect/keplergl-connect';
@@ -30,8 +30,13 @@ import * as MapStateActions from 'actions/map-state-actions';
import * as MapStyleActions from 'actions/map-style-actions';
import * as UIStateActions from 'actions/ui-state-actions';
-import {EXPORT_IMAGE_ID, DIMENSIONS,
- KEPLER_GL_NAME, KEPLER_GL_VERSION, THEME} from 'constants/default-settings';
+import {
+ EXPORT_IMAGE_ID,
+ DIMENSIONS,
+ KEPLER_GL_NAME,
+ KEPLER_GL_VERSION,
+ THEME
+} from 'constants/default-settings';
import {MISSING_MAPBOX_TOKEN} from 'constants/user-feedbacks';
import SidePanelFactory from './side-panel';
@@ -131,10 +136,15 @@ function KeplerGlFactory(
themeSelector = props => props.theme;
availableThemeSelector = createSelector(
this.themeSelector,
- theme => typeof theme === 'object' ? ({
- ...basicTheme,
- ...theme
- }) : theme === THEME.light ? themeLT : theme
+ theme =>
+ typeof theme === 'object'
+ ? {
+ ...basicTheme,
+ ...theme
+ }
+ : theme === THEME.light
+ ? themeLT
+ : theme
);
_validateMapboxToken() {
@@ -163,12 +173,14 @@ function KeplerGlFactory(
id: ms.id || generateHashId()
}));
- const allStyles = [...customStyles, ...defaultStyles].reduce((accu, style) => {
+ const allStyles = [...customStyles, ...defaultStyles].reduce(
+ (accu, style) => {
const hasStyleObject = style.style && typeof style.style === 'object';
accu[hasStyleObject ? 'toLoad' : 'toRequest'][style.id] = style;
return accu;
- }, {toLoad: {}, toRequest: {}}
+ },
+ {toLoad: {}, toRequest: {}}
);
this.props.mapStyleActions.loadMapStyles(allStyles.toLoad);
@@ -214,7 +226,8 @@ function KeplerGlFactory(
layerData,
hoverInfo,
clicked,
- mousePos
+ mousePos,
+ animationConfig
} = visState;
const notificationPanelFields = {
@@ -261,7 +274,8 @@ function KeplerGlFactory(
onViewStateChange,
uiStateActions,
visStateActions,
- mapStateActions
+ mapStateActions,
+ animationConfig
};
const isSplit = splitMaps && splitMaps.length > 1;
@@ -286,7 +300,6 @@ function KeplerGlFactory(
));
const isExporting = uiState.currentModal === EXPORT_IMAGE_ID;
-
const theme = this.availableThemeSelector(this.props);
return (
@@ -306,7 +319,7 @@ function KeplerGlFactory(
<div className="maps" style={{display: 'flex'}}>
{mapContainers}
</div>
- {isExporting &&
+ {isExporting && (
<PlotContainer
width={width}
height={height}
@@ -317,17 +330,22 @@ function KeplerGlFactory(
setExportImageDataUri={uiStateActions.setExportImageDataUri}
setExportImageError={uiStateActions.setExportImageError}
/>
- }
+ )}
<BottomWidget
filters={filters}
datasets={datasets}
uiState={uiState}
+ layers={layers}
+ animationConfig={animationConfig}
visStateActions={visStateActions}
sidePanelWidth={
- uiState.readOnly ? 0 : this.props.sidePanelWidth + DIMENSIONS.sidePanel.margin.left
+ uiState.readOnly
+ ? 0
+ : this.props.sidePanelWidth + DIMENSIONS.sidePanel.margin.left
}
containerW={containerW}
/>
+
<ModalWrapper
mapStyle={mapStyle}
visState={visState}
@@ -348,10 +366,12 @@ function KeplerGlFactory(
}
}
- return keplerGlConnect(mapStateToProps, makeMapDispatchToProps)(withTheme(KeplerGL));
+ return keplerGlConnect(mapStateToProps, makeMapDispatchToProps)(
+ withTheme(KeplerGL)
+ );
}
-function mapStateToProps(state, props) {
+function mapStateToProps(state = {}, props) {
return {
...props,
visState: state.visState,
@@ -362,19 +382,14 @@ function mapStateToProps(state, props) {
}
const defaultUserActions = {};
-const getDispatch = (dispatch) => dispatch
+const getDispatch = dispatch => dispatch;
const getUserActions = (dispatch, props) => props.actions || defaultUserActions;
function makeGetActionCreators() {
return createSelector(
[getDispatch, getUserActions],
(dispatch, userActions) => {
- const [
- visStateActions,
- mapStateActions,
- mapStyleActions,
- uiStateActions
- ] = [
+ const [visStateActions, mapStateActions, mapStyleActions, uiStateActions] = [
VisStateActions,
MapStateActions,
MapStyleActions,
@@ -403,7 +418,7 @@ function makeMapDispatchToProps() {
...groupedActionCreators,
dispatch
};
- }
+ };
return mapDispatchToProps;
}
diff --git a/src/components/map-container.js b/src/components/map-container.js
index 6cd5f7a19..cb5db8db4 100644
--- a/src/components/map-container.js
+++ b/src/components/map-container.js
@@ -46,7 +46,9 @@ const MAP_STYLE = {
position: 'relative'
},
top: {
- position: 'absolute', top: '0px', pointerEvents: 'none'
+ position: 'absolute',
+ top: '0px',
+ pointerEvents: 'none'
}
};
@@ -54,9 +56,7 @@ const MAPBOXGL_STYLE_UPDATE = 'style.load';
const MAPBOXGL_RENDER = 'render';
const TRANSITION_DURATION = 0;
-MapContainerFactory.deps = [
- MapPopoverFactory, MapControlFactory
-];
+MapContainerFactory.deps = [MapPopoverFactory, MapControlFactory];
export default function MapContainerFactory(MapPopover, MapControl) {
class MapContainer extends Component {
@@ -168,7 +168,6 @@ export default function MapContainerFactory(MapPopover, MapControl) {
_setMapboxMap = mapbox => {
if (!this._map && mapbox) {
-
this._map = mapbox.getMap();
// i noticed in certain context we don't access the actual map element
if (!this._map) {
@@ -178,7 +177,6 @@ export default function MapContainerFactory(MapPopover, MapControl) {
this._map.on(MAPBOXGL_STYLE_UPDATE, this._onMapboxStyleUpdate);
this._map.on(MAPBOXGL_RENDER, () => {
-
if (typeof this.props.onMapRender === 'function') {
this.props.onMapRender(this._map);
}
@@ -234,19 +232,21 @@ export default function MapContainerFactory(MapPopover, MapControl) {
layer.getHoverData &&
layersToRender[layer.id]
) {
-
// if layer is visible and have hovered data
- const {config: {dataId}} = layer;
+ const {
+ config: {dataId}
+ } = layer;
const {allData, fields} = datasets[dataId];
const data = layer.getHoverData(object, allData);
- const fieldsToShow = interactionConfig.tooltip.config.fieldsToShow[dataId];
+ const fieldsToShow =
+ interactionConfig.tooltip.config.fieldsToShow[dataId];
layerHoverProp = {
data,
fields,
fieldsToShow,
layer
- }
+ };
}
}
@@ -261,7 +261,10 @@ export default function MapContainerFactory(MapPopover, MapControl) {
<MapPopover
{...position}
layerHoverProp={layerHoverProp}
- coordinate={interactionConfig.coordinate.enabled && ((pinned || {}).coordinate || coordinate)}
+ coordinate={
+ interactionConfig.coordinate.enabled &&
+ ((pinned || {}).coordinate || coordinate)
+ }
freezed={Boolean(clicked || pinned)}
onClose={this._onCloseMapPopover}
mapW={mapState.width}
@@ -274,7 +277,8 @@ export default function MapContainerFactory(MapPopover, MapControl) {
/* eslint-enable complexity */
_getHoverXY(viewport, lngLat) {
- const screenCoord = !viewport || !lngLat ? null : viewport.project(lngLat);
+ const screenCoord =
+ !viewport || !lngLat ? null : viewport.project(lngLat);
return screenCoord && {x: screenCoord[0], y: screenCoord[1]};
}
@@ -287,7 +291,8 @@ export default function MapContainerFactory(MapPopover, MapControl) {
clicked,
mapState,
interactionConfig,
- mousePos
+ mousePos,
+ animationConfig
} = this.props;
const layer = layers[idx];
const data = layerData[idx];
@@ -310,7 +315,8 @@ export default function MapContainerFactory(MapPopover, MapControl) {
objectHovered,
mapState,
interactionConfig,
- layerCallbacks
+ layerCallbacks,
+ animationConfig
});
return overlays.concat(layerOverlay || []);
@@ -386,22 +392,31 @@ export default function MapContainerFactory(MapPopover, MapControl) {
}
}
- _onViewportChange = (viewState) => {
+ _onViewportChange = viewState => {
if (typeof this.props.onViewStateChange === 'function') {
this.props.onViewStateChange(viewState);
}
this.props.mapStateActions.updateMap(viewState);
- }
+ };
render() {
const {
- mapState, mapStyle, mapStateActions, mapLayers, layers, MapComponent,
- datasets, mapboxApiAccessToken, mapboxApiUrl, mapControls, toggleMapControl
+ mapState,
+ mapStyle,
+ mapStateActions,
+ mapLayers,
+ layers,
+ MapComponent,
+ datasets,
+ mapboxApiAccessToken,
+ mapboxApiUrl,
+ mapControls,
+ toggleMapControl
} = this.props;
const layersToRender = this.layersToRenderSelector(this.props);
if (!mapStyle.bottomMapStyle) {
// style not yet loaded
- return <div/>;
+ return <div />;
}
const mapProps = {
diff --git a/src/components/modals/export-data-modal.js b/src/components/modals/export-data-modal.js
index 47aa45dbd..f155798c5 100644
--- a/src/components/modals/export-data-modal.js
+++ b/src/components/modals/export-data-modal.js
@@ -39,8 +39,7 @@ const propTypes = {
onClose: PropTypes.func.isRequired,
onChangeExportSelectedDataset: PropTypes.func.isRequired,
onChangeExportDataType: PropTypes.func.isRequired,
- onChangeExportFiltered: PropTypes.func.isRequired,
- onChangeExportConfig: PropTypes.func.isRequired
+ onChangeExportFiltered: PropTypes.func.isRequired
};
const getDataRowCount = (datasets, selectedDataset, filtered) => {
diff --git a/src/components/side-panel.js b/src/components/side-panel.js
index a1b9ff1f8..a66508bb4 100644
--- a/src/components/side-panel.js
+++ b/src/components/side-panel.js
@@ -81,7 +81,6 @@ export default function SidePanelFactory(
InteractionManager,
MapManager
) {
-
return class SidePanel extends PureComponent {
static propTypes = {
filters: PropTypes.arrayOf(PropTypes.any).isRequired,
@@ -153,7 +152,7 @@ export default function SidePanelFactory(
layerColorUIChange: visStateActions.layerColorUIChange,
layerTextLabelChange: visStateActions.layerTextLabelChange,
layerVisualChannelConfigChange:
- visStateActions.layerVisualChannelConfigChange,
+ visStateActions.layerVisualChannelConfigChange,
layerTypeChange: visStateActions.layerTypeChange,
layerVisConfigChange: visStateActions.layerVisConfigChange,
updateLayerBlending: visStateActions.updateLayerBlending,
@@ -171,7 +170,7 @@ export default function SidePanelFactory(
setFilter: visStateActions.setFilter,
showDatasetTable: this._showDatasetTable,
showAddDataModal: this._showAddDataModal,
- toggleAnimation: visStateActions.toggleAnimation,
+ toggleAnimation: visStateActions.toggleFilterAnimation,
enlargeFilter: visStateActions.enlargeFilter
};
diff --git a/src/components/side-panel/common/source-data-selector.js b/src/components/side-panel/common/source-data-selector.js
index 3333c44bd..b8e26fac9 100644
--- a/src/components/side-panel/common/source-data-selector.js
+++ b/src/components/side-panel/common/source-data-selector.js
@@ -71,7 +71,7 @@ export default function SourceDataSelectorFactory(DatasetTag) {
multiSelect={false}
onChange={onSelect}
placeholder={defaultValue}
- disabled={disabled}
+ disabled={Boolean(disabled)}
displayOption={'label'}
DropDownLineItemRenderComponent={DatasetItem}
/>
diff --git a/src/components/side-panel/filter-panel/filter-panel.js b/src/components/side-panel/filter-panel/filter-panel.js
index 52e6a551a..aa5bc8207 100644
--- a/src/components/side-panel/filter-panel/filter-panel.js
+++ b/src/components/side-panel/filter-panel/filter-panel.js
@@ -27,8 +27,11 @@ import FieldSelector from 'components/common/field-selector';
import {Trash, Clock} from 'components/common/icons';
import SourceDataSelectorFactory from 'components/side-panel/common/source-data-selector';
import {StyledPanelHeader} from 'components/common/styled-components';
-import * as Filters from 'components/filters';
+import SingleSelectFilterFactory from 'components/filters/single-select-filter';
+import MultiSelectFilterFactory from 'components/filters/multi-select-filter';
+import TimeRangeFilterFactory from 'components/filters/time-range-filter';
+import RangeFilterFactory from 'components/filters/range-filter';
import {FILTER_TYPES, FILTER_COMPONENTS} from 'utils/filter-utils';
import {ALL_FIELD_TYPES} from 'constants/default-settings';
@@ -44,6 +47,10 @@ const StyledFilterPanel = styled.div`
const StyledFilterHeader = styled(StyledPanelHeader)`
cursor: pointer;
padding: 10px 12px;
+
+ .field-selector {
+ width: calc(100% - 58px);
+ }
`;
const StyledFilterContent = styled.div`
@@ -51,9 +58,28 @@ const StyledFilterContent = styled.div`
padding: 12px;
`;
-FilterPanelFactory.deps = [SourceDataSelectorFactory];
+FilterPanelFactory.deps = [
+ SourceDataSelectorFactory,
+ SingleSelectFilterFactory,
+ MultiSelectFilterFactory,
+ TimeRangeFilterFactory,
+ RangeFilterFactory
+];
+
+function FilterPanelFactory(
+ SourceDataSelector,
+ SingleSelectFilter,
+ MultiSelectFilter,
+ TimeRangeFilter,
+ RangeFilter
+) {
+ const FilterComponents = {
+ SingleSelectFilter,
+ MultiSelectFilter,
+ TimeRangeFilter,
+ RangeFilter
+ };
-function FilterPanelFactory(SourceDataSelector) {
return class FilterPanel extends Component {
static propTypes = {
idx: PropTypes.number,
@@ -103,22 +129,21 @@ function FilterPanelFactory(SourceDataSelector) {
toggleAnimation
} = this.props;
const {name, enlarged, type, dataId} = filter;
- const FilterComponent = type && Filters[FILTER_COMPONENTS[type]];
+
+ const FilterComponent = type && FilterComponents[FILTER_COMPONENTS[type]];
const allAvailableFields = this.availableFieldsSelector(this.props);
return (
<StyledFilterPanel className="filter-panel">
<StyledFilterHeader className="filter-panel__header"
labelRCGColorValues={datasets[dataId].color}>
- <div style={{flexGrow: 1}}>
- <FieldSelector
- inputTheme="secondary"
- fields={allAvailableFields}
- value={name}
- erasable={false}
- onSelect={value => setFilter(idx, 'name', value.name)}
- />
- </div>
+ <FieldSelector
+ inputTheme="secondary"
+ fields={allAvailableFields}
+ value={name}
+ erasable={false}
+ onSelect={value => setFilter(idx, 'name', value.name)}
+ />
<PanelHeaderAction
id={filter.id}
tooltip="delete"
diff --git a/src/components/side-panel/layer-manager.js b/src/components/side-panel/layer-manager.js
index b443a6b46..35b6a4e50 100644
--- a/src/components/side-panel/layer-manager.js
+++ b/src/components/side-panel/layer-manager.js
@@ -82,13 +82,9 @@ const SortableStyledItem = styled.div`
export function AddDataButtonFactory() {
const AddDataButton = ({onClick, isInactive}) => (
- <Button
- onClick={onClick}
- isInactive={!isInactive}
- width="105px"
- secondary
- >
- <Add height="12px" />Add Data
+ <Button onClick={onClick} isInactive={!isInactive} width="105px" secondary>
+ <Add height="12px" />
+ Add Data
</Button>
);
@@ -145,21 +141,25 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
layerClassSelector = props => props.layerClasses;
layerTypeOptionsSelector = createSelector(
this.layerClassSelector,
- layerClasses => Object.keys(layerClasses).map(key => {
- const layer = new layerClasses[key]();
- return {
- id: key,
- label: layer.name,
- icon: layer.layerIcon
- };
- }));
+ layerClasses =>
+ Object.keys(layerClasses).map(key => {
+ const layer = new layerClasses[key]();
+ return {
+ id: key,
+ label: layer.name,
+ icon: layer.layerIcon
+ };
+ })
+ );
_addEmptyNewLayer = () => {
this.props.addLayer();
};
_handleSort = ({oldIndex, newIndex}) => {
- this.props.updateLayerOrder(arrayMove(this.props.layerOrder, oldIndex, newIndex));
+ this.props.updateLayerOrder(
+ arrayMove(this.props.layerOrder, oldIndex, newIndex)
+ );
this.setState({isSorting: false});
};
@@ -177,7 +177,12 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
}
render() {
- const {layers, datasets, layerOrder, openModal} = this.props;
+ const {
+ layers,
+ datasets,
+ layerOrder,
+ openModal
+ } = this.props;
const defaultDataset = Object.keys(datasets)[0];
const layerTypeOptions = this.layerTypeOptionsSelector(this.props);
@@ -191,7 +196,11 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
removeLayer: this.props.removeLayer
};
- const panelProps = {datasets, openModal, layerTypeOptions};
+ const panelProps = {
+ datasets,
+ openModal,
+ layerTypeOptions
+ };
return (
<div className="layer-manager">
@@ -236,7 +245,8 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
<SidePanelSection>
{defaultDataset ? (
<Button onClick={this._addEmptyNewLayer} width="105px">
- <Add height="12px" />Add Layer
+ <Add height="12px" />
+ Add Layer
</Button>
) : null}
</SidePanelSection>
@@ -247,7 +257,7 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
</div>
);
}
- }
+ };
}
export default LayerManagerFactory;
diff --git a/src/components/side-panel/layer-panel/layer-config-group.js b/src/components/side-panel/layer-panel/layer-config-group.js
index cf18e3197..ed12750be 100644
--- a/src/components/side-panel/layer-panel/layer-config-group.js
+++ b/src/components/side-panel/layer-panel/layer-config-group.js
@@ -22,18 +22,24 @@ import React, {Component} from 'react';
import styled from 'styled-components';
import classnames from 'classnames';
import Switch from 'components/common/switch';
+import InfoHelper from 'components/common/info-helper';
import {VertThreeDots} from 'components/common/icons';
export const StyledLayerConfigGroupLabel = styled.div`
border-left: 2px solid ${props => props.theme.labelColor};
- color: ${props => props.theme.textColor};
- font-size: 12px;
- font-weight: 500;
line-height: 12px;
margin-left: -12px;
padding-left: 10px;
- text-transform: capitalize;
- letter-spacing: 0.2px;
+ display: flex;
+ align-items: center;
+
+ span {
+ color: ${props => props.theme.textColor};
+ font-size: 12px;
+ font-weight: 500;
+ letter-spacing: 0.2px;
+ text-transform: capitalize;
+ }
`;
export const StyledLayerConfigGroupAction = styled.div`
@@ -111,7 +117,8 @@ export default class LayerConfigGroup extends Component {
static defaultProps = {
collapsible: false,
expanded: false,
- onChange: () => {}
+ onChange: () => {},
+ description: null
};
state = {
@@ -140,7 +147,8 @@ export default class LayerConfigGroup extends Component {
property,
layer,
onChange,
- collapsible
+ collapsible,
+ description
} = this.props;
const {collapsed} = this.state;
@@ -154,7 +162,13 @@ export default class LayerConfigGroup extends Component {
onClick={() => this.setState({collapsed: !this.state.collapsed})}
>
<StyledLayerConfigGroupLabel className="layer-config-group__label">
- {label}
+ <span>{label}</span>
+ {description && (
+ <InfoHelper
+ description={description}
+ id={label}
+ />
+ )}
</StyledLayerConfigGroupLabel>
<StyledLayerConfigGroupAction className="layer-config-group__action">
{property ? (
diff --git a/src/components/side-panel/layer-panel/layer-configurator.js b/src/components/side-panel/layer-panel/layer-configurator.js
index 8ae7687a4..94976dedc 100644
--- a/src/components/side-panel/layer-panel/layer-configurator.js
+++ b/src/components/side-panel/layer-panel/layer-configurator.js
@@ -39,9 +39,7 @@ import ColorSelector from './color-selector';
import SourceDataSelectorFactory from 'components/side-panel/common/source-data-selector';
import VisConfigSwitch from './vis-config-switch';
import VisConfigSlider from './vis-config-slider';
-import LayerConfigGroup, {
- ConfigGroupCollapsibleContent
-} from './layer-config-group';
+import LayerConfigGroup, {ConfigGroupCollapsibleContent} from './layer-config-group';
import TextLabelPanel from './text-label-panel';
import {LAYER_VIS_CONFIGS} from 'layers/layer-factory';
@@ -244,9 +242,7 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {
channel={layer.visualChannels.color}
{...layerChannelConfigProps}
/>
- {layer.visConfigSettings.colorAggregation.condition(
- layer.config
- ) ? (
+ {layer.visConfigSettings.colorAggregation.condition(layer.config) ? (
<AggregationTypeSelector
{...layer.visConfigSettings.colorAggregation}
{...layerChannelConfigProps}
@@ -332,8 +328,7 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {
const {
visConfig: {enable3d}
} = config;
- const elevationByDescription =
- 'When off, height is based on count of points';
+ const elevationByDescription = 'When off, height is based on count of points';
const colorByDescription = 'When off, color is based on count of points';
return (
@@ -350,13 +345,11 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {
channel={layer.visualChannels.color}
{...layerChannelConfigProps}
/>
- {layer.visConfigSettings.colorAggregation.condition(
- layer.config
- ) ? (
+ {layer.visConfigSettings.colorAggregation.condition(layer.config) ? (
<AggregationTypeSelector
{...layer.visConfigSettings.colorAggregation}
{...layerChannelConfigProps}
- descreiption={colorByDescription}
+ description={colorByDescription}
channel={layer.visualChannels.color}
/>
) : null}
@@ -414,9 +407,7 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {
description={elevationByDescription}
disabled={!enable3d}
/>
- {layer.visConfigSettings.sizeAggregation.condition(
- layer.config
- ) ? (
+ {layer.visConfigSettings.sizeAggregation.condition(layer.config) ? (
<AggregationTypeSelector
{...layer.visConfigSettings.sizeAggregation}
{...layerChannelConfigProps}
@@ -574,6 +565,82 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {
);
}
+ _renderTripLayerConfig({
+ layer,
+ visConfiguratorProps,
+ layerConfiguratorProps,
+ layerChannelConfigProps
+ }) {
+ const {
+ meta: {featureTypes = {}}
+ } = layer;
+
+ return (
+ <StyledLayerVisualConfigurator>
+ {/* Color */}
+ <LayerConfigGroup label={'color'} collapsible>
+ {layer.config.colorField ? (
+ <LayerColorRangeSelector {...visConfiguratorProps} />
+ ) : (
+ <LayerColorSelector {...layerConfiguratorProps} />
+ )}
+ <ConfigGroupCollapsibleContent>
+ <ChannelByValueSelector
+ channel={layer.visualChannels.color}
+ {...layerChannelConfigProps}
+ />
+ <VisConfigSlider
+ {...LAYER_VIS_CONFIGS.opacity}
+ {...visConfiguratorProps}
+ />
+ </ConfigGroupCollapsibleContent>
+ </LayerConfigGroup>
+
+ {/* Stroke Width */}
+ <LayerConfigGroup
+ {...visConfiguratorProps}
+ label="Stroke Width"
+ collapsible
+ >
+ {layer.config.sizeField ? (
+ <VisConfigSlider
+ {...LAYER_VIS_CONFIGS.strokeWidthRange}
+ {...visConfiguratorProps}
+ label={false}
+ />
+ ) : (
+ <VisConfigSlider
+ {...LAYER_VIS_CONFIGS.thickness}
+ {...visConfiguratorProps}
+ label={false}
+ />
+ )}
+
+ <ConfigGroupCollapsibleContent>
+ <ChannelByValueSelector
+ channel={layer.visualChannels.size}
+ {...layerChannelConfigProps}
+ />
+ </ConfigGroupCollapsibleContent>
+ </LayerConfigGroup>
+
+ {/* Trail Length*/}
+ <LayerConfigGroup
+ {...visConfiguratorProps}
+ {...(featureTypes.polygon ? LAYER_VIS_CONFIGS.stroked : {})}
+ label="Trail Length"
+ description="Number of seconds for a path to completely fade out"
+ >
+ <VisConfigSlider
+ {...LAYER_VIS_CONFIGS.trailLength}
+ {...visConfiguratorProps}
+ label={false}
+ />
+ </LayerConfigGroup>
+ </StyledLayerVisualConfigurator>
+ );
+ }
+
_renderGeojsonLayerConfig({
layer,
visConfiguratorProps,
@@ -901,8 +968,7 @@ export const ArcLayerColorSelector = ({
label: 'Source'
},
{
- selectedColor:
- layer.config.visConfig.targetColor || layer.config.color,
+ selectedColor: layer.config.visConfig.targetColor || layer.config.color,
setColor: rgbValue => onChangeVisConfig({targetColor: rgbValue}),
label: 'Target'
}
diff --git a/src/components/side-panel/layer-panel/layer-panel.js b/src/components/side-panel/layer-panel/layer-panel.js
index 691ccb05b..5553d1cfa 100644
--- a/src/components/side-panel/layer-panel/layer-panel.js
+++ b/src/components/side-panel/layer-panel/layer-panel.js
@@ -50,11 +50,12 @@ function LayerPanelFactory(LayerConfigurator) {
openModal: PropTypes.func.isRequired,
removeLayer: PropTypes.func.isRequired,
onCloseConfig: PropTypes.func,
-
layerTypeOptions: PropTypes.arrayOf(PropTypes.any),
layerVisConfigChange: PropTypes.func.isRequired,
layerVisualChannelConfigChange: PropTypes.func.isRequired,
- layerColorUIChange: PropTypes.func.isRequired
+ layerColorUIChange: PropTypes.func.isRequired,
+ updateAnimationTime: PropTypes.func,
+ updateLayerAnimationSpeed: PropTypes.func
};
updateLayerConfig = newProp => {
@@ -98,7 +99,11 @@ function LayerPanelFactory(LayerConfigurator) {
_toggleEnableConfig = e => {
e.stopPropagation();
- const {layer: {config: {isConfigActive}}} = this.props;
+ const {
+ layer: {
+ config: {isConfigActive}
+ }
+ } = this.props;
this.updateLayerConfig({isConfigActive: !isConfigActive});
};
diff --git a/src/constants/action-types.js b/src/constants/action-types.js
index f2e49f73a..c1f7e4956 100644
--- a/src/constants/action-types.js
+++ b/src/constants/action-types.js
@@ -81,6 +81,10 @@ const ActionTypes = keyMirror({
UPDATE_VIS_DATA: null,
TOGGLE_FILTER_ANIMATION: null,
UPDATE_FILTER_ANIMATION_SPEED: null,
+ PLAY_ANIMATION: null,
+ UPDATE_ANIMATION_TIME: null,
+ UPDATE_ANIMATION_SPEED: null,
+ UPDATE_LAYER_ANIMATION_SPEED: null,
TOGGLE_LAYER_CONFIG_ACTIVE: null,
ENLARGE_FILTER: null,
SET_VISIBLE_LAYERS_FOR_MAP: null,
diff --git a/src/constants/default-settings.js b/src/constants/default-settings.js
index f50c53c01..b663f3dfd 100644
--- a/src/constants/default-settings.js
+++ b/src/constants/default-settings.js
@@ -536,15 +536,6 @@ export const DEFAULT_LAYER_COLOR = {
// let user pass in default tooltip fields
export const DEFAULT_TOOLTIP_FIELDS = [];
-export const DEFAULT_LIGHT_SETTINGS = {
- lightsPosition: [-122.45, 37.66, 8000, -122.0, 38.0, 8000],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0.0, 0.8, 0.0],
- numberOfLights: 2
-};
-
export const NO_VALUE_COLOR = [0, 0, 0, 0];
export const LAYER_BLENDINGS = {
@@ -702,3 +693,8 @@ export const DEFAULT_NOTIFICATION_TOPICS = keyMirror({
export const TOKEN_MISUSE_WARNING = '* If you do not provide your own token, the map may fail to display at any time when we replace ours to avoid misuse. ';
export const DISCLAIMER = 'You can change the Mapbox token later using the following instructions: ';
export const MAP_CONFIG_DESCRIPTION = 'Map config will be included in the Json file. If you are using kepler.gl in your own app. You can copy this config and pass it to ';
+
+// Animation
+export const BASE_SPEED = 600;
+export const DEFAULT_TIME_FORMAT = 'MM/DD/YY HH:mm:ssa';
+export const SPEED_CONTROL_RANGE = [0, 10];
diff --git a/src/constants/index.js b/src/constants/index.js
index 884e47714..5f293762d 100644
--- a/src/constants/index.js
+++ b/src/constants/index.js
@@ -51,6 +51,7 @@ export {
EXPORT_DATA_TYPE_OPTIONS,
DEFAULT_NOTIFICATION_TYPES,
DEFAULT_NOTIFICATION_TOPICS,
+ DEFAULT_COLOR_RANGE,
PANELS
} from './default-settings';
export {VizColorPalette, DataVizColors} from './custom-color-ranges';
diff --git a/src/deckgl-layers/3d-building-layer/3d-building-layer.js b/src/deckgl-layers/3d-building-layer/3d-building-layer.js
index 1d9f35544..69bad09a5 100644
--- a/src/deckgl-layers/3d-building-layer/3d-building-layer.js
+++ b/src/deckgl-layers/3d-building-layer/3d-building-layer.js
@@ -43,10 +43,7 @@ export default class ThreeDBuildingLayer extends CompositeLayer {
filled: true,
getElevation: (feature) => feature.properties.height || 0,
getPolygon: (feature) => feature.coordinates,
- getFillColor: this.props.threeDBuildingColor,
- lightSetting: {
- ambientRatio: 0.2
- }
+ getFillColor: this.props.threeDBuildingColor
});
}
diff --git a/src/layers/aggregation-layer.js b/src/layers/aggregation-layer.js
index cfc369038..9335507be 100644
--- a/src/layers/aggregation-layer.js
+++ b/src/layers/aggregation-layer.js
@@ -207,10 +207,7 @@ export default class AggregationLayer extends Layer {
// get bounds from points
const bounds = this.getPointsBounds(allData, getPosition);
- // get lightSettings from points
- const lightSettings = this.getLightSettingsFromBounds(bounds);
-
- this.updateMeta({bounds, lightSettings});
+ this.updateMeta({bounds});
}
formatLayerData(_, allData, filteredIndex, oldLayerData, opt = {}) {
diff --git a/src/layers/arc-layer/arc-layer-icon.js b/src/layers/arc-layer/arc-layer-icon.js
index c2d378d11..e85a5b459 100644
--- a/src/layers/arc-layer/arc-layer-icon.js
+++ b/src/layers/arc-layer/arc-layer-icon.js
@@ -62,6 +62,6 @@ class ArcLayerIcon extends Component {
</Base>
);
}
-};
+}
export default ArcLayerIcon;
diff --git a/src/layers/arc-layer/arc-layer.js b/src/layers/arc-layer/arc-layer.js
index 0a4d9403d..d4429fc02 100644
--- a/src/layers/arc-layer/arc-layer.js
+++ b/src/layers/arc-layer/arc-layer.js
@@ -87,8 +87,9 @@ export default class ArcLayer extends Layer {
static findDefaultLayerProps({fieldPairs = []}) {
if (fieldPairs.length < 2) {
- return [];
+ return {props: []};
}
+
const props = {
color: hexToRgb(DEFAULT_LAYER_COLOR.tripArc)
};
@@ -100,11 +101,9 @@ export default class ArcLayer extends Layer {
lat1: fieldPairs[1].pair.lat,
lng1: fieldPairs[1].pair.lng
};
- props.label = `${fieldPairs[0].defaultName} -> ${
- fieldPairs[1].defaultName
- } arc`;
+ props.label = `${fieldPairs[0].defaultName} -> ${fieldPairs[1].defaultName} arc`;
- return props;
+ return {props: [props]};
}
// TODO: fix complexity
@@ -170,15 +169,17 @@ export default class ArcLayer extends Layer {
}, []);
}
- const getStrokeWidth = sScale ? d =>
- this.getEncodedChannelValue(sScale, d.data, sizeField, 0) : 1;
+ const getStrokeWidth = sScale
+ ? d => this.getEncodedChannelValue(sScale, d.data, sizeField, 0)
+ : 1;
- const getColor = cScale ? d =>
- this.getEncodedChannelValue(cScale, d.data, colorField) : color;
+ const getColor = cScale
+ ? d => this.getEncodedChannelValue(cScale, d.data, colorField)
+ : color;
- const getTargetColor = cScale ? d =>
- this.getEncodedChannelValue(cScale, d.data, colorField)
- : targetColor || color;
+ const getTargetColor = cScale
+ ? d => this.getEncodedChannelValue(cScale, d.data, colorField)
+ : targetColor || color;
return {
data,
@@ -271,18 +272,18 @@ export default class ArcLayer extends Layer {
}),
// hover layer
...(this.isLayerHovered(objectHovered)
- ? [
- new ArcBrushingLayer({
- id: `${this.id}-hovered`,
- data: [objectHovered.object],
- strokeScale: this.config.visConfig.thickness,
- getSourceColor: this.config.highlightColor,
- getTargetColor: this.config.highlightColor,
- getWidth: data.getWidth,
- pickable: false
- })
- ]
- : [])
+ ? [
+ new ArcBrushingLayer({
+ id: `${this.id}-hovered`,
+ data: [objectHovered.object],
+ strokeScale: this.config.visConfig.thickness,
+ getSourceColor: this.config.highlightColor,
+ getTargetColor: this.config.highlightColor,
+ getWidth: data.getWidth,
+ pickable: false
+ })
+ ]
+ : [])
];
}
}
diff --git a/src/layers/base-layer.js b/src/layers/base-layer.js
index eaf3366e3..aaf8a9b90 100644
--- a/src/layers/base-layer.js
+++ b/src/layers/base-layer.js
@@ -24,7 +24,6 @@ import DefaultLayerIcon from './default-layer-icon';
import {
ALL_FIELD_TYPES,
- DEFAULT_LIGHT_SETTINGS,
NO_VALUE_COLOR,
SCALE_TYPES,
CHANNEL_SCALES,
@@ -204,12 +203,12 @@ export default class Layer {
return null;
}
/*
- * Given a dataset, automatically create layers based on it
- * and return the props
+ * Given a dataset, automatically find props to create layer based on it
+ * and return the props and previous found layers.
* By default, no layers will be found
*/
- static findDefaultLayerProps(fieldPairs, dataId) {
- return null;
+ static findDefaultLayerProps(dataset, foundLayers) {
+ return {props: [], foundLayers};
}
/**
@@ -316,7 +315,8 @@ export default class Layer {
colorUI: {
color: DEFAULT_COLOR_UI,
colorRange: DEFAULT_COLOR_UI
- }
+ },
+ animation: {enabled: false}
};
}
@@ -428,14 +428,15 @@ export default class Layer {
*/
assignConfigToLayer(configToCopy, visConfigSettings) {
// don't deep merge visualChannel field
- const notToDeepMerge = Object.values(this.visualChannels).map(v => v.field);
-
// don't deep merge color range, reversed: is not a key by default
- notToDeepMerge.push('colorRange', 'strokeColorRange');
-
- // don't copy over domain
- const notToCopy = Object.values(this.visualChannels).map(v => v.domain);
+ const shallowCopy = ['colorRange', 'strokeColorRange'].concat(
+ Object.values(this.visualChannels).map(v => v.field)
+ );
+ // don't copy over domain and animation
+ const notToCopy = ['animation'].concat(
+ Object.values(this.visualChannels).map(v => v.domain)
+ );
// if range is for the same property group copy it, otherwise, not to copy
Object.values(this.visualChannels).forEach(v => {
if (
@@ -450,7 +451,7 @@ export default class Layer {
// don't copy over visualChannel range
const currentConfig = this.config;
const copied = this.copyLayerConfig(currentConfig, configToCopy, {
- notToDeepMerge,
+ shallowCopy,
notToCopy
});
@@ -467,28 +468,31 @@ export default class Layer {
* make sure to only copy over value to existing keys
* @param {object} currentConfig - existing config to be override
* @param {object} configToCopy - new Config to copy over
- * @param {string[]} notToDeepMerge - array of properties to not to be deep copied
+ * @param {string[]} shallowCopy - array of properties to not to be deep copied
* @param {string[]} notToCopy - array of properties not to copy
* @returns {object} - copied config
*/
copyLayerConfig(
currentConfig,
configToCopy,
- {notToDeepMerge = [], notToCopy = []} = {}
+ {shallowCopy = [], notToCopy = []} = {}
) {
const copied = {};
Object.keys(currentConfig).forEach(key => {
if (
isPlainObject(currentConfig[key]) &&
isPlainObject(configToCopy[key]) &&
- !notToDeepMerge.includes(key) &&
+ !shallowCopy.includes(key) &&
!notToCopy.includes(key)
) {
// recursively assign object value
copied[key] = this.copyLayerConfig(
currentConfig[key],
configToCopy[key],
- {notToDeepMerge, notToCopy}
+ {
+ shallowCopy,
+ notToCopy
+ }
);
} else if (
notNullorUndefined(configToCopy[key]) &&
@@ -761,20 +765,6 @@ export default class Layer {
return [lngBounds[0], latBounds[0], lngBounds[1], latBounds[1]];
}
- getLightSettingsFromBounds(bounds) {
- return Array.isArray(bounds) && bounds.length >= 4
- ? {
- ...DEFAULT_LIGHT_SETTINGS,
- lightsPosition: [
- ...bounds.slice(0, 2),
- DEFAULT_LIGHT_SETTINGS.lightsPosition[2],
- ...bounds.slice(2, 4),
- DEFAULT_LIGHT_SETTINGS.lightsPosition[5]
- ]
- }
- : DEFAULT_LIGHT_SETTINGS;
- }
-
getEncodedChannelValue(
scale,
data,
@@ -897,11 +887,9 @@ export default class Layer {
updateLayerVisualChannel(dataset, channel) {
const visualChannel = this.visualChannels[channel];
-
this.validateVisualChannel(channel);
// calculate layer channel domain
const updatedDomain = this.calculateLayerDomain(dataset, visualChannel);
-
this.updateLayerConfig({[visualChannel.domain]: updatedDomain});
}
diff --git a/src/layers/geojson-layer/geojson-layer.js b/src/layers/geojson-layer/geojson-layer.js
index 16c9ea09c..9fdc0b775 100644
--- a/src/layers/geojson-layer/geojson-layer.js
+++ b/src/layers/geojson-layer/geojson-layer.js
@@ -28,10 +28,14 @@ import {hexToRgb} from 'utils/color-utils';
import {
getGeojsonDataMaps,
getGeojsonBounds,
- featureToDeckGlGeoType
+ getGeojsonFeatureTypes
} from './geojson-utils';
import GeojsonLayerIcon from './geojson-layer-icon';
-import {GEOJSON_FIELDS, HIGHLIGH_COLOR_3D, CHANNEL_SCALES} from 'constants/default-settings';
+import {
+ GEOJSON_FIELDS,
+ HIGHLIGH_COLOR_3D,
+ CHANNEL_SCALES
+} from 'constants/default-settings';
export const geojsonVisConfigs = {
opacity: 'opacity',
@@ -68,7 +72,7 @@ export default class GeoJsonLayer extends Layer {
constructor(props) {
super(props);
- this.dataToFeature = {};
+ this.dataToFeature = [];
this.registerVisConfig(geojsonVisConfigs);
this.getFeature = memoize(featureAccessor, featureResolver);
}
@@ -133,10 +137,8 @@ export default class GeoJsonLayer extends Layer {
return this.getFeature(this.config.columns);
}
- static findDefaultLayerProps({label, fields}) {
- const geojsonColumns = fields
- .filter(f => f.type === 'geojson')
- .map(f => f.name);
+ static findDefaultLayerProps({label, fields = []}) {
+ const geojsonColumns = fields.filter(f => f.type === 'geojson').map(f => f.name);
const defaultColumns = {
geojson: uniq([...GEOJSON_FIELDS.geojson, ...geojsonColumns])
@@ -144,14 +146,17 @@ export default class GeoJsonLayer extends Layer {
const foundColumns = this.findDefaultColumnField(defaultColumns, fields);
if (!foundColumns || !foundColumns.length) {
- return [];
+ return {props: []};
}
- return foundColumns.map(columns => ({
- label: typeof label === 'string' && label.replace(/\.[^/.]+$/, '') || this.type,
- columns,
- isVisible: true
- }));
+ return {
+ props: foundColumns.map(columns => ({
+ label:
+ (typeof label === 'string' && label.replace(/\.[^/.]+$/, '')) || this.type,
+ columns,
+ isVisible: true
+ }))
+ };
}
getDefaultLayerConfig(props = {}) {
@@ -235,9 +240,7 @@ export default class GeoJsonLayer extends Layer {
geojsonData = oldLayerData.data;
} else {
// filteredIndex is a reference of index in allData which can map to feature
- geojsonData = filteredIndex
- .map(i => this.dataToFeature[i])
- .filter(d => d);
+ geojsonData = filteredIndex.map(i => this.dataToFeature[i]).filter(d => d);
}
// fill color
@@ -271,8 +274,7 @@ export default class GeoJsonLayer extends Layer {
// point radius
const rScale =
- radiusField &&
- this.getVisChannelScale(radiusScale, radiusDomain, radiusRange);
+ radiusField && this.getVisChannelScale(radiusScale, radiusDomain, radiusRange);
return {
data: geojsonData,
@@ -325,40 +327,27 @@ export default class GeoJsonLayer extends Layer {
/* eslint-enable complexity */
updateLayerMeta(allData) {
+
const getFeature = this.getPositionAccessor();
this.dataToFeature = getGeojsonDataMaps(allData, getFeature);
- // calculate layer meta
- const allFeatures = Object.values(this.dataToFeature);
-
// get bounds from features
- const bounds = getGeojsonBounds(allFeatures);
-
- // get lightSettings from points
- const lightSettings = this.getLightSettingsFromBounds(bounds);
+ const bounds = getGeojsonBounds(this.dataToFeature);
// if any of the feature has properties.radius set to be true
const fixedRadius = Boolean(
- allFeatures.find(d => d && d.properties && d.properties.radius)
+ this.dataToFeature.find(d => d && d.properties && d.properties.radius)
);
// keep a record of what type of geometry the collection has
- const featureTypes = allFeatures.reduce((accu, f) => {
- const geoType = featureToDeckGlGeoType(
- f && f.geometry && f.geometry.type
- );
+ const featureTypes = getGeojsonFeatureTypes(this.dataToFeature);
- if (geoType) {
- accu[geoType] = true;
- }
- return accu;
- }, {});
-
- this.updateMeta({bounds, lightSettings, fixedRadius, featureTypes});
+ this.updateMeta({bounds, fixedRadius, featureTypes});
}
setInitialLayerConfig(allData) {
this.updateLayerMeta(allData);
+
const {featureTypes} = this.meta;
// default settings is stroke: true, filled: false
if (featureTypes && featureTypes.polygon) {
@@ -376,14 +365,8 @@ export default class GeoJsonLayer extends Layer {
return this;
}
- renderLayer({
- data,
- idx,
- objectHovered,
- mapState,
- interactionConfig
- }) {
- const {lightSettings, fixedRadius} = this.meta;
+ renderLayer({data, idx, objectHovered, mapState, interactionConfig}) {
+ const {fixedRadius} = this.meta;
const radiusScale = this.getRadiusScaleByZoom(mapState, fixedRadius);
const zoomFactor = this.getZoomFactor(mapState);
const {visConfig} = this.config;
@@ -391,7 +374,6 @@ export default class GeoJsonLayer extends Layer {
const layerProps = {
// multiplier applied just so it being consistent with previously saved maps
lineWidthScale: visConfig.thickness * zoomFactor * 8,
- lineWidthMinPixels: 1,
elevationScale: visConfig.elevationScale,
pointRadiusScale: radiusScale,
lineMiterLimit: 4
@@ -441,7 +423,9 @@ export default class GeoJsonLayer extends Layer {
highlightColor: HIGHLIGH_COLOR_3D,
autoHighlight: visConfig.enable3d,
// parameters
- parameters: {depthTest: Boolean(visConfig.enable3d || mapState.dragRotate)},
+ parameters: {
+ depthTest: Boolean(visConfig.enable3d || mapState.dragRotate)
+ },
opacity: visConfig.opacity,
stroked: visConfig.stroked,
filled: visConfig.filled,
@@ -449,7 +433,6 @@ export default class GeoJsonLayer extends Layer {
wireframe: visConfig.wireframe,
lineMiterLimit: 2,
rounded: true,
- lightSettings,
updateTriggers
}),
...(this.isLayerHovered(objectHovered) && !visConfig.enable3d
diff --git a/src/layers/geojson-layer/geojson-utils.js b/src/layers/geojson-layer/geojson-utils.js
index 7e9eee331..d5eb6e24a 100644
--- a/src/layers/geojson-layer/geojson-utils.js
+++ b/src/layers/geojson-layer/geojson-utils.js
@@ -18,19 +18,48 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import geojsonExtent from '@mapbox/geojson-extent';
import wktParser from 'wellknown';
import normalize from '@mapbox/geojson-normalize';
+import bbox from '@turf/bbox';
import {getSampleData} from 'utils/data-utils';
+export function parseGeoJsonRawFeature(rawFeature) {
+ if (typeof rawFeature === 'object') {
+ // Support GeoJson feature as object
+ // probably need to normalize it as well
+ const normalized = normalize(rawFeature);
+ if (!normalized || !Array.isArray(normalized.features)) {
+ // fail to normalize GeoJson
+ return null;
+ }
+
+ return normalized.features[0];
+ } else if (typeof rawFeature === 'string') {
+
+ return parseGeometryFromString(rawFeature);
+ } else if (Array.isArray(rawFeature)) {
+ // Support GeoJson LineString as an array of points
+ return {
+ type: 'Feature',
+ geometry: {
+ // why do we need to flip it...
+ coordinates: rawFeature.map(pts => [pts[1], pts[0]]),
+ type: 'LineString'
+ }
+ };
+ }
+
+ return null;
+}
/**
- * Parse raw data to geojson feature
+ * Parse raw data to GeoJson feature
* @param allData
* @param getFeature
* @returns {{}}
*/
export function getGeojsonDataMaps(allData, getFeature) {
+
const acceptableTypes = [
'Point',
'MultiPoint',
@@ -41,38 +70,10 @@ export function getGeojsonDataMaps(allData, getFeature) {
'GeometryCollection'
];
- const dataToFeature = {};
-
- allData.forEach((d, index) => {
- dataToFeature[index] = null;
- const rawFeature = getFeature(d);
-
- let feature = null;
-
- // parse feature from field
- if (Array.isArray(rawFeature)) {
- // Support geojson as an array of points
- feature = {
- type: 'Feature',
- geometry: {
- // why do we need to flip it...
- coordinates: rawFeature.map(pts => [pts[1], pts[0]]),
- type: 'LineString'
- }
- };
- } else if (typeof rawFeature === 'string') {
- feature = parseGeometryFromString(rawFeature);
- } else if (typeof rawFeature === 'object') {
- // Support geojson feature as object
- // probably need to normalize it as well
- const normalized = normalize(rawFeature);
- if (!normalized || !Array.isArray(normalized.features)) {
- // fail to normalize geojson
- return null;
- }
+ const dataToFeature = [];
- feature = normalized.features[0];
- }
+ for (let index = 0; index < allData.length; index++) {
+ const feature = parseGeoJsonRawFeature(getFeature(allData[index]));
if (
feature &&
@@ -87,7 +88,8 @@ export function getGeojsonDataMaps(allData, getFeature) {
dataToFeature[index] = feature;
}
- });
+
+ }
return dataToFeature;
}
@@ -132,10 +134,11 @@ export function parseGeometryFromString(geoString) {
}
export function getGeojsonBounds(features = []) {
- // calculate feature bounds is computation heavy
+ // 70 ms for 10,000 polygons
// here we only pick couple
+ const maxCount = 10000;
const samples =
- features.length > 500 ? getSampleData(features, 500) : features;
+ features.length > maxCount ? getSampleData(features, maxCount) : features;
const nonEmpty = samples.filter(
d =>
@@ -143,7 +146,7 @@ export function getGeojsonBounds(features = []) {
);
try {
- return geojsonExtent({
+ return bbox({
type: 'FeatureCollection',
features: nonEmpty
});
@@ -152,21 +155,32 @@ export function getGeojsonBounds(features = []) {
}
}
-export function featureToDeckGlGeoType(type) {
- switch (type) {
- case 'Point':
- case 'MultiPoint':
- return 'point';
-
- case 'LineString':
- case 'MultiLineString':
- return 'line';
-
- case 'Polygon':
- case 'MultiPolygon':
- return 'polygon';
+export const featureToDeckGlGeoType = {
+ Point: 'point',
+ MultiPoint: 'point',
+ LineString: 'line',
+ MultiLineString: 'line',
+ Polygon: 'polygon',
+ MultiPolygon: 'polygon'
+};
- default:
- return null;
+/**
+ * Parse geojson from string
+ * @param {Array<Object>} allFeatures
+ * @returns {Object} mapping of feature type existence
+ */
+export function getGeojsonFeatureTypes(allFeatures) {
+ const featureTypes = {};
+ for (let f = 0; f < allFeatures.length; f++) {
+ const feature = allFeatures[f];
+ const geoType =
+ featureToDeckGlGeoType[
+ feature && feature.geometry && feature.geometry.type
+ ];
+ if (geoType) {
+ featureTypes[geoType] = true;
+ }
}
+
+ return featureTypes;
}
diff --git a/src/layers/h3-hexagon-layer/h3-hexagon-layer.js b/src/layers/h3-hexagon-layer/h3-hexagon-layer.js
index a7d421f9a..b0bde03a3 100644
--- a/src/layers/h3-hexagon-layer/h3-hexagon-layer.js
+++ b/src/layers/h3-hexagon-layer/h3-hexagon-layer.js
@@ -97,17 +97,19 @@ export default class HexagonIdLayer extends Layer {
};
}
- static findDefaultLayerProps({fields}) {
+ static findDefaultLayerProps({fields = []}) {
const foundColumns = this.findDefaultColumnField(HEXAGON_ID_FIELDS, fields);
if (!foundColumns || !foundColumns.length) {
- return null;
+ return {props: []};
}
- return foundColumns.map(columns => ({
- isVisible: true,
- label: 'H3 Hexagon',
- columns
- }));
+ return {
+ props: foundColumns.map(columns => ({
+ isVisible: true,
+ label: 'H3 Hexagon',
+ columns
+ }))
+ };
}
getDefaultLayerConfig(props = {}) {
@@ -154,7 +156,8 @@ export default class HexagonIdLayer extends Layer {
// coverage
const coScale =
- coverageField && this.getVisChannelScale(coverageScale, coverageDomain, coverageRange, 0);
+ coverageField &&
+ this.getVisChannelScale(coverageScale, coverageDomain, coverageRange, 0);
const getHexId = this.getHexId(columns);
@@ -189,14 +192,17 @@ export default class HexagonIdLayer extends Layer {
}, []);
}
- const getElevation = sScale ? d =>
- this.getEncodedChannelValue(sScale, d.data, sizeField, 0) : 0;
+ const getElevation = sScale
+ ? d => this.getEncodedChannelValue(sScale, d.data, sizeField, 0)
+ : 0;
- const getColor = cScale ? d =>
- this.getEncodedChannelValue(cScale, d.data, colorField) : color;
+ const getColor = cScale
+ ? d => this.getEncodedChannelValue(cScale, d.data, colorField)
+ : color;
- const getCoverage = coScale ? d =>
- this.getEncodedChannelValue(coScale, d.data, coverageField, 0) : 1;
+ const getCoverage = coScale
+ ? d => this.getEncodedChannelValue(coScale, d.data, coverageField, 0)
+ : 1;
// const layerData = {
return {
@@ -225,7 +231,7 @@ export default class HexagonIdLayer extends Layer {
// only need 1 instance of hexagonVertices
if (!hexagonVertices) {
hexagonVertices = id && getVertices({id});
- hexagonCenter = id && getCentroid({id})
+ hexagonCenter = id && getCentroid({id});
}
// save a reference of centroids to dataToFeature
@@ -234,10 +240,8 @@ export default class HexagonIdLayer extends Layer {
});
const bounds = this.getPointsBounds(Object.values(centroids), d => d);
- const lightSettings = this.getLightSettingsFromBounds(bounds);
-
this.dataToFeature = {hexagonVertices, hexagonCenter, centroids};
- this.updateMeta({bounds, lightSettings});
+ this.updateMeta({bounds});
}
renderLayer({
@@ -313,9 +317,7 @@ export default class HexagonIdLayer extends Layer {
? [
new GeoJsonLayer({
id: `${this.id}-hovered`,
- data: [
- idToPolygonGeo(objectHovered)
- ],
+ data: [idToPolygonGeo(objectHovered)],
getLineColor: config.highlightColor,
lineWidthScale: 8 * zoomFactor
})
diff --git a/src/layers/icon-layer/icon-layer.js b/src/layers/icon-layer/icon-layer.js
index d67c0aa83..90990f4af 100644
--- a/src/layers/icon-layer/icon-layer.js
+++ b/src/layers/icon-layer/icon-layer.js
@@ -35,8 +35,7 @@ export const iconPosAccessor = ({lat, lng}) => d => [
d.data[lat.fieldIdx]
];
-export const iconPosResolver = ({lat, lng}) =>
- `${lat.fieldIdx}-${lng.fieldIdx}`;
+export const iconPosResolver = ({lat, lng}) => `${lat.fieldIdx}-${lng.fieldIdx}`;
export const iconAccessor = ({icon}) => d => d.data[icon.fieldIdx];
export const iconResolver = ({icon}) => icon.fieldIdx;
@@ -129,9 +128,10 @@ export default class IconLayer extends Layer {
}
}
- static findDefaultLayerProps({fieldPairs, fields}) {
- if (!fieldPairs.length) {
- return [];
+ static findDefaultLayerProps({fieldPairs = [], fields = []}) {
+ const notFound = {props: []};
+ if (!fieldPairs.length || !fields.length) {
+ return notFound;
}
const iconFields = fields.filter(({name}) =>
@@ -143,7 +143,7 @@ export default class IconLayer extends Layer {
);
if (!iconFields.length) {
- return [];
+ return notFound;
}
// create icon layers for first point pair
@@ -162,7 +162,7 @@ export default class IconLayer extends Layer {
isVisible: true
}));
- return props;
+ return {props};
}
// TODO: fix complexity
@@ -267,53 +267,55 @@ export default class IconLayer extends Layer {
...(this.config.visConfig.fixedRadius ? {} : {radiusMaxPixels: 500})
};
- return !this.iconGeometry ? [] : [
- new SvgIconLayer({
- ...layerProps,
- ...data,
- ...layerInteraction,
- id: this.id,
- idx,
- opacity: this.config.visConfig.opacity,
- getIconGeometry: id => this.iconGeometry[id],
-
- // picking
- autoHighlight: true,
- highlightColor: this.config.highlightColor,
- pickable: true,
-
- // parameters
- parameters: {depthTest: mapState.dragRotate},
-
- // update triggers
- updateTriggers: {
- getRadius: {
- sizeField: this.config.colorField,
- radiusRange: this.config.visConfig.radiusRange,
- sizeScale: this.config.sizeScale
- },
- getColor: {
- color: this.config.color,
- colorField: this.config.colorField,
- colorRange: this.config.visConfig.colorRange,
- colorScale: this.config.colorScale
- }
- }
- }),
- ...(this.isLayerHovered(objectHovered)
- ? [
+ return !this.iconGeometry
+ ? []
+ : [
new SvgIconLayer({
...layerProps,
- id: `${this.id}-hovered`,
- data: [objectHovered.object],
- getPosition: data.getPosition,
- getRadius: data.getRadius,
- getColor: this.config.highlightColor,
+ ...data,
+ ...layerInteraction,
+ id: this.id,
+ idx,
+ opacity: this.config.visConfig.opacity,
getIconGeometry: id => this.iconGeometry[id],
- pickable: false
- })
- ]
- : [])
- ];
+
+ // picking
+ autoHighlight: true,
+ highlightColor: this.config.highlightColor,
+ pickable: true,
+
+ // parameters
+ parameters: {depthTest: mapState.dragRotate},
+
+ // update triggers
+ updateTriggers: {
+ getRadius: {
+ sizeField: this.config.colorField,
+ radiusRange: this.config.visConfig.radiusRange,
+ sizeScale: this.config.sizeScale
+ },
+ getColor: {
+ color: this.config.color,
+ colorField: this.config.colorField,
+ colorRange: this.config.visConfig.colorRange,
+ colorScale: this.config.colorScale
+ }
+ }
+ }),
+ ...(this.isLayerHovered(objectHovered)
+ ? [
+ new SvgIconLayer({
+ ...layerProps,
+ id: `${this.id}-hovered`,
+ data: [objectHovered.object],
+ getPosition: data.getPosition,
+ getRadius: data.getRadius,
+ getColor: this.config.highlightColor,
+ getIconGeometry: id => this.iconGeometry[id],
+ pickable: false
+ })
+ ]
+ : [])
+ ];
}
}
diff --git a/src/layers/index.js b/src/layers/index.js
index b20b64c9a..1eb2c2954 100644
--- a/src/layers/index.js
+++ b/src/layers/index.js
@@ -29,6 +29,7 @@ import {default as IconLayer} from './icon-layer/icon-layer';
import {default as HeatmapLayer} from './heatmap-layer/heatmap-layer';
import {default as H3Layer} from './h3-hexagon-layer/h3-hexagon-layer';
import {default as ScenegraphLayer} from './scenegraph-layer/scenegraph-layer';
+import {default as TripLayer} from './trip-layer/trip-layer';
// base layer
export {default as Layer} from './base-layer';
@@ -45,7 +46,8 @@ export const KeplerGlLayers = {
IconLayer,
HeatmapLayer,
H3Layer,
- ScenegraphLayer
+ ScenegraphLayer,
+ TripLayer
};
export const LayerClasses = {
@@ -59,5 +61,6 @@ export const LayerClasses = {
icon: IconLayer,
heatmap: HeatmapLayer,
hexagonId: H3Layer,
- '3D': ScenegraphLayer
+ '3D': ScenegraphLayer,
+ trip: TripLayer
};
diff --git a/src/layers/layer-factory.js b/src/layers/layer-factory.js
index 6e2bd364e..f3caf69e8 100644
--- a/src/layers/layer-factory.js
+++ b/src/layers/layer-factory.js
@@ -34,6 +34,42 @@ export const PROPERTY_GROUPS = keyMirror({
precision: null
});
+export const DEFAULT_LAYER_OPACITY = 0.8;
+
+export const DEFAULT_TEXT_LABEL = {
+ field: null,
+ color: [255, 255, 255],
+ size: 18,
+ offset: [0, 0],
+ anchor: 'start',
+ alignment: 'center'
+};
+
+export const DEFAULT_COLOR_RANGE = DefaultColorRange;
+
+export const DEFAULT_CUSTOM_PALETTE = {
+ name: 'Custom Palette',
+ type: 'custom',
+ category: 'Custom',
+ colors: []
+}
+
+export const DEFAULT_COLOR_UI = {
+ // customPalette in edit
+ customPalette: DEFAULT_CUSTOM_PALETTE,
+ // show color sketcher modal
+ showSketcher: false,
+ // show color range selection panel
+ showDropdown: false,
+ // color range selector config
+ colorRangeConfig: {
+ type: 'all',
+ steps: 6,
+ reversed: false,
+ custom: false
+ }
+};
+
export const LAYER_VIS_CONFIGS = {
thickness: {
type: 'number',
@@ -55,6 +91,16 @@ export const LAYER_VIS_CONFIGS = {
group: PROPERTY_GROUPS.stroke,
property: 'sizeRange'
},
+ trailLength: {
+ type: 'number',
+ defaultValue: 180,
+ label: 'Stroke Width',
+ isRanged: false,
+ range: [1, 1000],
+ step: 1,
+ group: PROPERTY_GROUPS.stroke,
+ property: 'trailLength'
+ },
// radius is actually radiusScale in deck.gl
radius: {
type: 'number',
@@ -106,7 +152,7 @@ export const LAYER_VIS_CONFIGS = {
},
opacity: {
type: 'number',
- defaultValue: 0.8,
+ defaultValue: DEFAULT_LAYER_OPACITY,
label: 'Opacity',
isRanged: false,
range: [0, 1],
@@ -213,7 +259,8 @@ export const LAYER_VIS_CONFIGS = {
group: PROPERTY_GROUPS.height,
property: 'elevationPercentile',
// percentile filter only makes sense with linear aggregation
- condition: config => config.visConfig.enable3d && (config.colorField || config.sizeField)
+ condition: config =>
+ config.visConfig.enable3d && (config.colorField || config.sizeField)
},
resolution: {
type: 'number',
@@ -377,35 +424,3 @@ export const LAYER_TEXT_CONFIGS = {
searchable: false
}
};
-
-export const DEFAULT_TEXT_LABEL = {
- field: null,
- color: [255, 255, 255],
- size: 18,
- offset: [0, 0],
- anchor: 'start',
- alignment: 'center'
-};
-
-export const DEFAULT_CUSTOM_PALETTE = {
- name: 'Custom Palette',
- type: 'custom',
- category: 'Custom',
- colors: []
-}
-
-export const DEFAULT_COLOR_UI = {
- // customPalette in edit
- customPalette: DEFAULT_CUSTOM_PALETTE,
- // show color sketcher modal
- showSketcher: false,
- // show color range selection panel
- showDropdown: false,
- // color range selector config
- colorRangeConfig: {
- type: 'all',
- steps: 6,
- reversed: false,
- custom: false
- }
-};
diff --git a/src/layers/line-layer/line-layer-icon.js b/src/layers/line-layer/line-layer-icon.js
index b3842c40c..bc6e10fe8 100644
--- a/src/layers/line-layer/line-layer-icon.js
+++ b/src/layers/line-layer/line-layer-icon.js
@@ -66,4 +66,4 @@ export default class LineLayerIcon extends Component {
</Base>
);
}
-};
+}
diff --git a/src/layers/line-layer/line-layer.js b/src/layers/line-layer/line-layer.js
index 1b520a285..700ad8db8 100644
--- a/src/layers/line-layer/line-layer.js
+++ b/src/layers/line-layer/line-layer.js
@@ -31,9 +31,9 @@ export default class LineLayer extends ArcLayer {
return LineLayerIcon;
}
- static findDefaultLayerProps({fieldPairs}) {
+ static findDefaultLayerProps({fieldPairs = []}) {
if (fieldPairs.length < 2) {
- return [];
+ return {props: []};
}
const props = {};
@@ -46,9 +46,9 @@ export default class LineLayer extends ArcLayer {
};
props.label = `${fieldPairs[0].defaultName} -> ${
fieldPairs[1].defaultName
- } line`;
+ } line`;
- return props;
+ return {props: [props]};
}
renderLayer({
@@ -106,18 +106,18 @@ export default class LineLayer extends ArcLayer {
}),
// hover layer
...(this.isLayerHovered(objectHovered)
- ? [
- new DeckGLLineLayer({
- id: `${this.id}-hovered`,
- data: [objectHovered.object],
- strokeScale: this.config.visConfig.thickness,
- getColor: this.config.highlightColor,
- getTargetColor: this.config.highlightColor,
- getWidth: data.getWidth,
- pickable: false
- })
- ]
- : [])
+ ? [
+ new DeckGLLineLayer({
+ id: `${this.id}-hovered`,
+ data: [objectHovered.object],
+ strokeScale: this.config.visConfig.thickness,
+ getColor: this.config.highlightColor,
+ getTargetColor: this.config.highlightColor,
+ getWidth: data.getWidth,
+ pickable: false
+ })
+ ]
+ : [])
];
}
}
diff --git a/src/layers/point-layer/point-layer.js b/src/layers/point-layer/point-layer.js
index 7ce802067..f8e0dbe42 100644
--- a/src/layers/point-layer/point-layer.js
+++ b/src/layers/point-layer/point-layer.js
@@ -35,7 +35,6 @@ export const pointPosAccessor = ({lat, lng, altitude}) => d => [
d.data[lng.fieldIdx],
// lat
d.data[lat.fieldIdx],
- // altitude
altitude && altitude.fieldIdx > -1 ? d.data[altitude.fieldIdx] : 0
];
@@ -169,7 +168,7 @@ export default class PointLayer extends Layer {
props.push(prop);
});
- return props;
+ return {props};
}
getDefaultLayerConfig(props = {}) {
@@ -332,11 +331,7 @@ export default class PointLayer extends Layer {
const xMult =
config.anchor === 'middle' ? 0 : config.anchor === 'start' ? 1 : -1;
const yMult =
- config.alignment === 'center'
- ? 0
- : config.alignment === 'bottom'
- ? 1
- : -1;
+ config.alignment === 'center' ? 0 : config.alignment === 'bottom' ? 1 : -1;
const sizeOffset =
config.alignment === 'center'
diff --git a/src/layers/trip-layer/trip-info-modal.js b/src/layers/trip-layer/trip-info-modal.js
new file mode 100644
index 000000000..c59df3e0f
--- /dev/null
+++ b/src/layers/trip-layer/trip-info-modal.js
@@ -0,0 +1,81 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import React from 'react';
+import styled from 'styled-components';
+
+const StyledCode = styled.code`
+ color: ${props => props.theme.titleColorLT};
+`;
+
+const StyledTitle = styled.div`
+ font-size: 20px;
+ letter-spacing: 1.25px;
+ margin: 18px 0 14px 0;
+ color: ${props => props.theme.titleColorLT};
+`;
+
+const TripInfoModalFactory = (svgIcons = []) => {
+ const TripInfoModal = () => (
+ <div className="trip-info-modal">
+ <div className="trip-info-modal__description">
+ <p>
+ In order to animate the path, the geoJSON data needs to contain
+ `LineString` in its feature geometry, and the coordinates in the LineString
+ need to have 4 elements in the formats of
+ <code> [longitude, latitude, altitude, timestamp] </code>
+ with the last element being a timestamp. Valid timestamp formats include
+ unix in seconds such as `1564184363` or in milliseconds such as
+ `1564184363000`.
+ </p>
+ </div>
+ <div className="trip-info-modal__example">
+ <StyledTitle>Example:</StyledTitle>
+ <pre>
+ <StyledCode>
+ {`
+ {
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": { "vendor": "A",
+ "vol":20},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [-74.20986, 40.81773, 0, 1564184363],
+ [-74.20987, 40.81765, 0, 1564184396],
+ [-74.20998, 40.81746, 0, 1564184409]
+ ]
+ }
+ }
+ ]
+ }
+ `}
+ </StyledCode>
+ </pre>
+ </div>
+ </div>
+ );
+ return TripInfoModal;
+};
+
+export default TripInfoModalFactory;
diff --git a/src/layers/trip-layer/trip-layer-icon.js b/src/layers/trip-layer/trip-layer-icon.js
new file mode 100644
index 000000000..504ca01d4
--- /dev/null
+++ b/src/layers/trip-layer/trip-layer-icon.js
@@ -0,0 +1,62 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import React, {Component} from 'react';
+import PropTypes from 'prop-types';
+import Base from 'components/common/icons/base';
+
+export default class TripLayerIcon extends Component {
+ static propTypes = {
+ /** Set the height of the icon, ex. '16px' */
+ height: PropTypes.string,
+ colors: PropTypes.arrayOf(PropTypes.string)
+ };
+
+ static defaultProps = {
+ size: 'tiny',
+ height: '16px',
+ predefinedClassName: 'trip-layer-icon'
+ };
+
+ render() {
+ return (
+ <Base {...this.props}>
+ <g clipPath="url(#clip0)" className="cr1">
+ <path d="M53.025 4.85005C50.25 2.07505 45.75 2.07505 42.975 4.85005C40.2 7.62505 40.2 12.2 42.975 14.975L48 20L53.025 14.9C55.8 12.2 55.8 7.62505 53.025 4.85005ZM48 11.375C47.175 11.375 46.5 10.7 46.5 9.87505C46.5 9.05005 47.175 8.37505 48 8.37505C48.825 8.37505 49.5 9.05005 49.5 9.87505C49.5 10.7 48.825 11.375 48 11.375Z" />
+ </g>
+ <g clipPath="url(#clip1)" className="cr2">
+ <path d="M20.025 36.85C17.25 34.075 12.75 34.075 9.97502 36.85C7.20002 39.625 7.20002 44.2 9.97502 46.975L15 52L20.025 46.9C22.8 44.2 22.8 39.625 20.025 36.85ZM15 43.375C14.175 43.375 13.5 42.7 13.5 41.875C13.5 41.05 14.175 40.375 15 40.375C15.825 40.375 16.5 41.05 16.5 41.875C16.5 42.7 15.825 43.375 15 43.375Z" />
+ </g>
+ <path
+ className="cr3"
+ d="M45.9943 19.8697C46.0661 20.6951 45.4552 21.4223 44.6299 21.4941L34.782 22.3504L38.1515 40.1604L17.8748 54.7185C17.2019 55.2016 16.2647 55.0478 15.7815 54.3748C15.2984 53.7019 15.4522 52.7647 16.1252 52.2815L34.8483 38.8389L31.2177 19.6491L44.37 18.5053C45.1953 18.4336 45.9225 19.0444 45.9943 19.8697Z"
+ />
+ <defs>
+ <clipPath id="clip0">
+ <rect width="18" height="18" transform="translate(39 2)" />
+ </clipPath>
+ <clipPath id="clip1">
+ <rect width="18" height="18" transform="translate(6 34)" />
+ </clipPath>
+ </defs>
+ </Base>
+ );
+ }
+}
diff --git a/src/layers/trip-layer/trip-layer.js b/src/layers/trip-layer/trip-layer.js
new file mode 100644
index 000000000..0fbbfa4a8
--- /dev/null
+++ b/src/layers/trip-layer/trip-layer.js
@@ -0,0 +1,341 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import memoize from 'lodash.memoize';
+import uniq from 'lodash.uniq';
+import Layer from '../base-layer';
+import {TripsLayer as DeckGLTripsLayer} from 'deck.gl';
+
+import {GEOJSON_FIELDS} from 'constants/default-settings';
+import TripLayerIcon from './trip-layer-icon';
+
+import {
+ getGeojsonDataMaps,
+ getGeojsonBounds,
+ getGeojsonFeatureTypes
+} from 'layers/geojson-layer/geojson-utils';
+
+import {
+ isTripGeoJsonField,
+ parseTripGeoJsonTimestamp
+} from './trip-utils';
+
+import {hexToRgb} from 'utils/color-utils';
+import TripInfoModalFactory from './trip-info-modal';
+
+export const tripVisConfigs = {
+ opacity: 'opacity',
+ thickness: {
+ type: 'number',
+ defaultValue: 0.5,
+ label: 'Stroke Width',
+ isRanged: false,
+ range: [0, 100],
+ step: 0.1,
+ group: 'stroke',
+ property: 'thickness'
+ },
+ colorRange: 'colorRange',
+ trailLength: 'trailLength',
+ sizeRange: 'strokeWidthRange'
+};
+
+export const geoJsonRequiredColumns = ['geojson'];
+export const featureAccessor = ({geojson}) => d => d[geojson.fieldIdx];
+export const featureResolver = ({geojson}) => geojson.fieldIdx;
+
+export default class TripLayer extends Layer {
+ constructor(props) {
+ super(props);
+
+ this.dataToFeature = [];
+ this.dataToTimeStamp = [];
+ this.registerVisConfig(tripVisConfigs);
+ this.getFeature = memoize(featureAccessor, featureResolver);
+ this._layerInfoModal = TripInfoModalFactory();
+ }
+
+ get type() {
+ return 'trip';
+ }
+
+ get name() {
+ return 'Trip';
+ }
+
+ get layerIcon() {
+ return TripLayerIcon;
+ }
+
+ get requiredLayerColumns() {
+ return geoJsonRequiredColumns;
+ }
+
+ get visualChannels() {
+ return {
+ ...super.visualChannels,
+
+ size: {
+ ...super.visualChannels.size,
+ property: 'stroke',
+ condition: config => config.visConfig.stroked
+ }
+ };
+ }
+
+ get animationDomain() {
+ return this.config.animation.domain;
+ }
+
+ get layerInfoModal() {
+ return {
+ id: 'iconInfo',
+ template: this._layerInfoModal,
+ modalProps: {
+ title: 'How to enable trip animation'
+ }
+ };
+ }
+
+ getPositionAccessor() {
+ return this.getFeature(this.config.columns);
+ }
+
+ static findDefaultLayerProps({label, fields = [], allData = [], id}, foundLayers) {
+ const geojsonColumns = fields
+ .filter(f => f.type === 'geojson')
+ .map(f => f.name);
+
+ const defaultColumns = {
+ geojson: uniq([...GEOJSON_FIELDS.geojson, ...geojsonColumns])
+ };
+
+ const geoJsonColumns = this.findDefaultColumnField(defaultColumns, fields);
+
+ const tripColumns = (geoJsonColumns || []).filter(col =>
+ isTripGeoJsonField(allData, fields[col.geojson.fieldIdx])
+ );
+
+ if (!tripColumns.length) {
+ return {props: []};
+ }
+
+ return {
+ props: tripColumns.map(columns => ({
+ label:
+ (typeof label === 'string' && label.replace(/\.[^/.]+$/, '')) ||
+ this.type,
+ columns,
+ isVisible: true
+ })),
+
+ // if a geojson layer is created from this column, delete it
+ foundLayers: foundLayers.filter(
+ prop =>
+ prop.type !== 'geojson' ||
+ prop.dataId !== id ||
+ !tripColumns.find(c => prop.columns.geojson.name === c.geojson.name)
+ )
+ };
+ }
+
+ getDefaultLayerConfig(props) {
+ return {
+ ...super.getDefaultLayerConfig(props),
+ animation: {
+ enabled: true,
+ domain: null
+ }
+ };
+ }
+
+ getHoverData(object, allData) {
+ // index of allData is saved to feature.properties
+ return allData[object.properties.index];
+ }
+
+ // TODO: fix complexity
+ /* eslint-disable complexity */
+ formatLayerData(_, allData, filteredIndex, oldLayerData, opt = {}) {
+ // to-do: parse segment from allData
+ const {
+ colorScale,
+ colorField,
+ colorDomain,
+ color,
+ sizeScale,
+ sizeDomain,
+ sizeField,
+ visConfig
+ } = this.config;
+
+ const {stroked, colorRange, sizeRange} = visConfig;
+
+ const getFeature = this.getPositionAccessor(this.config.column);
+
+ // geojson feature are object, if doesn't exists
+ // create it and save to layer
+ if (!oldLayerData || oldLayerData.getFeature !== getFeature) {
+ this.updateLayerMeta(allData, getFeature);
+ }
+
+ let geojsonData;
+
+ if (
+ oldLayerData &&
+ oldLayerData.data &&
+ opt.sameData &&
+ oldLayerData.getFeature === getFeature
+ ) {
+ // no need to create a new array of data
+ // use updateTriggers to selectively re-calculate attributes
+ geojsonData = oldLayerData.data;
+ } else {
+ // filteredIndex is a reference of index in allData which can map to feature
+ geojsonData = filteredIndex
+ .map(i => this.dataToFeature[i])
+ .filter(d => d && d.geometry.type === 'LineString');
+ }
+
+ // color
+ const cScale =
+ colorField &&
+ this.getVisChannelScale(
+ colorScale,
+ colorDomain,
+ colorRange.colors.map(hexToRgb)
+ );
+
+ // calculate stroke scale - if stroked = true
+ const sScale =
+ sizeField &&
+ stroked &&
+ this.getVisChannelScale(sizeScale, sizeDomain, sizeRange);
+
+ return {
+ data: geojsonData,
+ getPath: d => d.geometry.coordinates,
+ getTimestamps: d => this.dataToTimeStamp[d.properties.index],
+ getColor: d =>
+ cScale
+ ? this.getEncodedChannelValue(
+ cScale,
+ allData[d.properties.index],
+ colorField
+ )
+ : d.properties.fillColor || color,
+ getWidth: d =>
+ sScale
+ ? this.getEncodedChannelValue(
+ sScale,
+ allData[d.properties.index],
+ sizeField,
+ 0
+ )
+ : d.properties.lineWidth || 1
+ };
+ }
+ /* eslint-enable complexity */
+
+ updateAnimationDomain(domain) {
+ this.updateLayerConfig({
+ animation: {
+ ...this.config.animation,
+ domain
+ }
+ });
+ }
+
+ updateLayerMeta(allData) {
+ const getFeature = this.getPositionAccessor();
+ if (getFeature === this.meta.getFeature) {
+ // TODO: revisit this after gpu filtering
+ return;
+ }
+
+ this.dataToFeature = getGeojsonDataMaps(allData, getFeature);
+
+ const {dataToTimeStamp, animationDomain} =
+ parseTripGeoJsonTimestamp(this.dataToFeature);
+
+ this.dataToTimeStamp = dataToTimeStamp;
+ this.updateAnimationDomain(animationDomain);
+
+ // get bounds from features
+ const bounds = getGeojsonBounds(this.dataToFeature);
+
+ // keep a record of what type of geometry the collection has
+ const featureTypes = getGeojsonFeatureTypes(this.dataToFeature);
+
+ this.updateMeta({bounds, featureTypes, getFeature});
+ }
+
+ setInitialLayerConfig(allData) {
+ this.updateLayerMeta(allData);
+ return this;
+ }
+
+ renderLayer({data, idx, mapState, animationConfig}) {
+ const {visConfig} = this.config;
+ const zoomFactor = this.getZoomFactor(mapState);
+
+ const updateTriggers = {
+ getColor: {
+ color: this.config.color,
+ colorField: this.config.colorField,
+ colorRange: visConfig.colorRange,
+ colorScale: this.config.colorScale
+ },
+ getWidth: {
+ sizeField: this.config.sizeField,
+ sizeRange: visConfig.sizeRange
+ },
+ getTimestamps: {
+ columns: this.config.columns,
+ domain0: animationConfig.domain[0]
+ }
+ };
+
+ return [
+ new DeckGLTripsLayer({
+ id: this.id,
+ idx,
+ data: data.data,
+ getPath: data.getPath,
+ getColor: data.getColor,
+ getTimestamps: d =>
+ data.getTimestamps(d).map(ts => ts - animationConfig.domain[0]),
+ opacity: this.config.visConfig.opacity,
+ widthScale: this.config.visConfig.thickness * zoomFactor * 8,
+ highlightColor: this.config.highlightColor,
+
+ getWidth: data.getWidth,
+ rounded: true,
+ pickable: true,
+ autoHighlight: true,
+ parameters: {depthTest: mapState.dragRotate},
+
+ trailLength: visConfig.trailLength * 1000,
+ currentTime: animationConfig.currentTime - animationConfig.domain[0],
+ updateTriggers
+ })
+ ];
+ }
+}
diff --git a/src/layers/trip-layer/trip-utils.js b/src/layers/trip-layer/trip-utils.js
new file mode 100644
index 000000000..afa700c5d
--- /dev/null
+++ b/src/layers/trip-layer/trip-utils.js
@@ -0,0 +1,173 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import {Analyzer} from 'type-analyzer';
+
+import {
+ getSampleData,
+ timeToUnixMilli,
+ notNullorUndefined
+} from 'utils/data-utils';
+
+import {
+ parseGeoJsonRawFeature,
+ getGeojsonFeatureTypes
+} from 'layers/geojson-layer/geojson-utils';
+
+/**
+ * Parse geojson from string
+ * @param {array} geojson feature object values
+ * @returns {boolean} whether the geometry coordinates has length of 4
+ */
+export function coordHasLength4(samples) {
+ let hasLength4 = true;
+ for (let i = 0; i < samples.length; i += 1) {
+ hasLength4 = !samples[i].geometry.coordinates.find(c => c.length < 4);
+ if (!hasLength4) {
+ break;
+ }
+ }
+ return hasLength4;
+}
+
+/**
+ * Check whether geojson linestring's 4th coordinate is 1) not timestamp 2) unix time stamp 3) real date time
+ * @param {array} data array to be tested if its elements are timestamp
+ * @returns {string} the type of timestamp: unix/datetime/invalid(not timestamp)
+ */
+
+export function containValidTime(timestamps) {
+ const formattedTimeStamps = timestamps.map(ts => ({ts}));
+ const analyzedType = Analyzer.computeColMeta(formattedTimeStamps)[0];
+
+ if (!analyzedType || analyzedType.category !== 'TIME') {
+ return false;
+ }
+ return analyzedType;
+}
+
+/**
+ * Check if geojson features are trip layer animatable by meeting 3 conditions
+ * @param {array} features array of geojson feature objects
+ * @returns {boolean} whether it is trip layer animatable
+ */
+export function isTripGeoJsonField(allData = [], field) {
+ if (!allData.length) {
+ return false;
+ }
+ const getValue = d => d[field.tableFieldIndex - 1];
+ const maxCount = 10000;
+ const sampleRawFeatures =
+ allData.length > maxCount ? getSampleData(allData, maxCount, getValue) : allData.map(getValue);
+
+ const features = sampleRawFeatures.map(parseGeoJsonRawFeature);
+
+ const featureTypes = getGeojsonFeatureTypes(features);
+
+ // condition 1: contain line string
+ if (!featureTypes.line) {
+ return false;
+ }
+
+ // condition 2:sample line strings contain 4 coordinates
+ if (!coordHasLength4(features)) {
+ return false;
+ }
+
+ // condition 3:the 4th coordinate of the first feature line strings is valid time
+ const tsHolder = features[0].geometry.coordinates.map(
+ coord => coord[3]
+ );
+
+ return Boolean(containValidTime(tsHolder));
+}
+
+/**
+ * Get unix timestamp from animatable geojson for deck.gl trip layer
+ * @param {Array<Object>} dataToFeature array of geojson feature objects, can be null
+ * @returns {Array<Number>} unix timestamp in milliseconds
+ */
+export function parseTripGeoJsonTimestamp(dataToFeature) {
+ // Analyze type based on coordinates of the 1st lineString
+ // select a sample trip to analyze time format
+ const empty = {dataToTimeStamp: [], animationDomain: null};
+ const sampleTrip = dataToFeature.find(
+ f =>
+ f &&
+ f.geometry &&
+ f.geometry.coordinates &&
+ f.geometry.coordinates.length >= 3
+ );
+
+ // if no valid geometry
+ if (!sampleTrip) {
+ return empty;
+ }
+
+ const analyzedType = containValidTime(
+ sampleTrip.geometry.coordinates.map(coord => coord[3])
+ );
+
+ if (!analyzedType) {
+ return empty;
+ }
+
+ const {format} = analyzedType;
+ const getTimeValue = coord =>
+ coord && notNullorUndefined(coord[3])
+ ? timeToUnixMilli(coord[3], format)
+ : null;
+
+ const dataToTimeStamp = dataToFeature.map(f =>
+ f && f.geometry && Array.isArray(f.geometry.coordinates)
+ ? f.geometry.coordinates.map(getTimeValue)
+ : null
+ );
+
+ const animationDomain = getAnimationDomainFromTimestamps(dataToTimeStamp);
+
+ return {dataToTimeStamp, animationDomain};
+}
+
+function findMinFromSorted(list = []) {
+ return list.find(notNullorUndefined) || null;
+}
+
+function findMaxFromSorted(list = []) {
+ let i = list.length - 1;
+ while (i > 0) {
+ if (notNullorUndefined(list[i])) {
+ return list[i]
+ }
+ i--;
+ }
+ return null;
+}
+
+export function getAnimationDomainFromTimestamps(dataToTimeStamp = []) {
+ return dataToTimeStamp.reduce(
+ (accu, tss) => {
+ accu[0] = Math.min(accu[0], findMinFromSorted(tss));
+ accu[1] = Math.max(accu[1], findMaxFromSorted(tss));
+ return accu;
+ },
+ [Infinity, -Infinity]
+ );
+}
diff --git a/src/processors/data-processor.js b/src/processors/data-processor.js
index bbd75f1ad..87fb0135b 100644
--- a/src/processors/data-processor.js
+++ b/src/processors/data-processor.js
@@ -24,8 +24,8 @@ import {console as globalConsole} from 'global/window';
import assert from 'assert';
import {Analyzer, DATA_TYPES as AnalyzerDATA_TYPES} from 'type-analyzer';
import normalize from '@mapbox/geojson-normalize';
-import {ALL_FIELD_TYPES, GEOJSON_FIELDS} from 'constants/default-settings';
-import {notNullorUndefined} from 'utils/data-utils';
+import {ALL_FIELD_TYPES} from 'constants/default-settings';
+import {notNullorUndefined, parseFieldValue} from 'utils/data-utils';
import KeplerGlSchema from 'schemas';
// if any of these value occurs in csv, parse it to null;
@@ -423,9 +423,9 @@ export function processGeojson(rawData) {
const allData = normalizedGeojson.features.reduce((accu, f, i) => {
if (f.geometry) {
// check if properties contains object and stringfy this
- if(typeof f.properties === 'object' && f.properties !== null){
+ if (typeof f.properties === 'object' && f.properties !== null) {
Object.keys(f.properties).forEach(key => {
- if(typeof f.properties[key] === 'object'){
+ if (typeof f.properties[key] === 'object') {
f.properties[key] = JSON.stringify(f.properties[key]);
}
});
@@ -457,8 +457,8 @@ export function processGeojson(rawData) {
}
});
});
-
- return processRowObject(allData);
+ const processRow = processRowObject(allData);
+ return processRow;
}
/**
@@ -473,12 +473,7 @@ export function formatCsv(data, fields) {
// parse geojson object as string
data.forEach(row => {
- formattedData.push(
- row.map(
- (d, i) => d && GEOJSON_FIELDS.geojson.includes(fields[i].name) ?
- JSON.stringify(d) : d
- )
- )
+ formattedData.push(row.map((d, i) => parseFieldValue(d, fields[i].type)));
});
return csvFormatRows(formattedData);
@@ -545,7 +540,10 @@ export function validateInputData(data) {
// if any field has missing type, recalculate it for everyone
// because we simply lost faith in humanity
- const sampleData = getSampleForTypeAnalyze({fields: fields.map(f => f.name), allData: rows});
+ const sampleData = getSampleForTypeAnalyze({
+ fields: fields.map(f => f.name),
+ allData: rows
+ });
const fieldOrder = fields.map(f => f.name);
const meta = getFieldsFromData(sampleData, fieldOrder);
const updatedFields = fields.map((f, i) => ({
@@ -572,9 +570,7 @@ export function validateInputData(data) {
* dispatch(addDataToMap(processKeplerglJSON(keplerGlJson)));
*/
export function processKeplerglJSON(rawData) {
- return rawData
- ? KeplerGlSchema.load(rawData.datasets, rawData.config)
- : null;
+ return rawData ? KeplerGlSchema.load(rawData.datasets, rawData.config) : null;
}
export const Processors = {
@@ -585,4 +581,4 @@ export const Processors = {
analyzerTypeToFieldType,
getFieldsFromData,
parseCsvRowsByFieldType
-}
+};
diff --git a/src/reducers/ui-state-updaters.js b/src/reducers/ui-state-updaters.js
index 661f13c76..876095954 100644
--- a/src/reducers/ui-state-updaters.js
+++ b/src/reducers/ui-state-updaters.js
@@ -69,7 +69,7 @@ export const DEFAULT_MODAL = ADD_DATA_ID;
* export default composedReducer;
*/
/* eslint-disable no-unused-vars */
- const uiStateUpdaters = null;
+const uiStateUpdaters = null;
/* eslint-enable no-unused-vars */
/**
@@ -266,7 +266,7 @@ export const showExportDropdownUpdater = (state, {payload: id}) => ({
* @returns {Object} nextState
* @public
*/
-export const hideExportDropdownUpdater = (state) => ({
+export const hideExportDropdownUpdater = state => ({
...state,
visibleDropdown: null
});
@@ -300,10 +300,7 @@ export const toggleMapControlUpdater = (state, {payload: panelId}) => ({
* @returns {Object} nextState
* @public
*/
-export const openDeleteModalUpdater = (
- state,
- {payload: datasetKeyToRemove}
-) => ({
+export const openDeleteModalUpdater = (state, {payload: datasetKeyToRemove}) => ({
...state,
currentModal: DELETE_DATA_ID,
datasetKeyToRemove
@@ -495,7 +492,10 @@ export const setExportDataUpdater = state => ({
* @returns {Object} nextState
* @public
*/
-export const setUserMapboxAccessTokenUpdater = (state, {payload: userMapboxToken}) => ({
+export const setUserMapboxAccessTokenUpdater = (
+ state,
+ {payload: userMapboxToken}
+) => ({
...state,
exportMap: {
...state.exportMap,
@@ -538,20 +538,17 @@ export const setExportMapHTMLMode = (state, {payload: mode}) => ({
});
/**
-* Add a notification to be displayed
-* @memberof uiStateUpdaters
-* @param {Object} state `uiState`
-* @param {Object} action
-* @param {Object} action.payload
-* @returns {Object} nextState
-* @public
-*/
+ * Add a notification to be displayed
+ * @memberof uiStateUpdaters
+ * @param {Object} state `uiState`
+ * @param {Object} action
+ * @param {Object} action.payload
+ * @returns {Object} nextState
+ * @public
+ */
export const addNotificationUpdater = (state, {payload}) => ({
...state,
- notifications: [
- ...(state.notifications || []),
- createNotification(payload)
- ]
+ notifications: [...(state.notifications || []), createNotification(payload)]
});
/**
diff --git a/src/reducers/vis-state-merger.js b/src/reducers/vis-state-merger.js
index 2c49e8992..1a2704845 100644
--- a/src/reducers/vis-state-merger.js
+++ b/src/reducers/vis-state-merger.js
@@ -293,6 +293,25 @@ export function mergeLayerBlending(state, layerBlending) {
return state;
}
+/**
+ * Merge animation config
+ * @param {Object} state
+ * @param {Object} animation
+ */
+export function mergeAnimationConfig(state, animation) {
+ if (animation && animation.currentTime) {
+ return {
+ ...state,
+ animationConfig: {
+ domain: null,
+ currentTime: animation.currentTime
+ }
+ }
+ }
+
+ return state;
+}
+
/**
* Validate saved layer columns with new data,
* update fieldIdx based on new fields
@@ -461,7 +480,7 @@ export function validateLayerWithData(
const visConfig = newLayer.copyLayerConfig(
newLayer.config.visConfig,
savedLayer.config.visConfig || {},
- {notToDeepMerge: ['colorRange', 'strokeColorRange']}
+ {shallowCopy: ['colorRange', 'strokeColorRange']}
);
newLayer.updateLayerConfig({
diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.js
index ade720692..7f9d56373 100644
--- a/src/reducers/vis-state-updaters.js
+++ b/src/reducers/vis-state-updaters.js
@@ -30,16 +30,14 @@ import {loadFilesErr} from 'actions/vis-state-actions';
import {addDataToMap} from 'actions';
// Utils
-import {
- getDefaultInteraction,
- findFieldsToShow
-} from 'utils/interaction-utils';
+import {getDefaultInteraction, findFieldsToShow} from 'utils/interaction-utils';
import {
getDefaultFilter,
getFilterProps,
getFilterPlot,
getDefaultFilterPlotType,
- filterData
+ filterData,
+ isInRange
} from 'utils/filter-utils';
import {createNewDataEntry} from 'utils/dataset-utils';
@@ -53,7 +51,8 @@ import {
mergeLayers,
mergeInteractions,
mergeLayerBlending,
- mergeSplitMaps
+ mergeSplitMaps,
+ mergeAnimationConfig
} from './vis-state-merger';
import {
@@ -110,6 +109,12 @@ disableStackCapturing();
const visStateUpdaters = null;
/* eslint-enable no-unused-vars */
+export const defaultAnimationConfig = {
+ domain: null,
+ currentTime: null,
+ speed: 1
+};
+
/**
* Default initial `visState`
* @memberof visStateUpdaters
@@ -128,9 +133,12 @@ const visStateUpdaters = null;
* @property {string} layerBlending
* @property {Object} hoverInfo
* @property {Object} clicked
+ * @property {Object} mousePos
* @property {boolean} fileLoading
* @property {*} fileLoadingErr
* @property {Array} splitMaps - a list of objects of layer availabilities and visibilities for each map
+ * @property {Object} layerClasses
+ * @property {Object} animationConfig
* @public
*/
export const INITIAL_VIS_STATE = {
@@ -170,9 +178,13 @@ export const INITIAL_VIS_STATE = {
// }
// ]
],
-
+ //
// defaults layer classes
- layerClasses: LayerClasses
+ layerClasses: LayerClasses,
+
+ // default animation
+ // time in unix timestamp (milliseconds) (the number of seconds since the Unix Epoch)
+ animationConfig: defaultAnimationConfig
};
function updateStateWithLayerAndData(state, {layerData, layer, idx}) {
@@ -185,60 +197,90 @@ function updateStateWithLayerAndData(state, {layerData, layer, idx}) {
};
}
- /**
- * Update layer base config: dataId, label, column, isVisible
- * @memberof visStateUpdaters
- * @param {Object} state `visState`
- * @param {Object} action action
- * @param {Object} action.oldLayer layer to be updated
- * @param {Object} action.newConfig new config
- * @returns {Object} nextState
- */
+export function updateStateOnLayerVisibilityChange(state, layer) {
+ let newState = state;
+ if (state.splitMaps.length) {
+ newState = {
+ ...state,
+ splitMaps: layer.config.isVisible
+ ? addNewLayersToSplitMap(state.splitMaps, layer)
+ : removeLayerFromSplitMaps(state.splitMaps, layer)
+ };
+ }
+
+ if (layer.config.animation.enabled) {
+ newState = updateAnimationDomain(state);
+ }
+
+ return newState;
+}
+
+/**
+ * Update layer base config: dataId, label, column, isVisible
+ * @memberof visStateUpdaters
+ * @param {Object} state `visState`
+ * @param {Object} action action
+ * @param {Object} action.oldLayer layer to be updated
+ * @param {Object} action.newConfig new config
+ * @returns {Object} nextState
+ */
export function layerConfigChangeUpdater(state, action) {
const {oldLayer} = action;
const idx = state.layers.findIndex(l => l.id === oldLayer.id);
const props = Object.keys(action.newConfig);
- const newLayer = oldLayer.updateLayerConfig(action.newConfig);
+ let newLayer = oldLayer.updateLayerConfig(action.newConfig);
+
+ let layerData;
+
+ // let newLayer;
if (newLayer.shouldCalculateLayerData(props)) {
const oldLayerData = state.layerData[idx];
- const {layerData, layer} = calculateLayerData(
+ const updateLayerDataResult = calculateLayerData(
newLayer,
state,
oldLayerData,
- {sameData: true}
+ {
+ sameData: true
+ }
);
- return updateStateWithLayerAndData(state, {layerData, layer, idx});
+
+ layerData = updateLayerDataResult.layerData;
+ newLayer = updateLayerDataResult.layer;
}
let newState = state;
- if ('isVisible' in action.newConfig && state.splitMaps.length) {
- newState = {
- ...state,
- splitMaps: action.newConfig.isVisible ?
- addNewLayersToSplitMap(state.splitMaps, newLayer) :
- removeLayerFromSplitMaps(state.splitMaps, newLayer)
- };
+ if ('isVisible' in action.newConfig) {
+ newState = updateStateOnLayerVisibilityChange(state, newLayer);
}
- return updateStateWithLayerAndData(newState, {layer: newLayer, idx});
+ return updateStateWithLayerAndData(newState, {
+ layer: newLayer,
+ layerData,
+ idx
+ });
}
function addOrRemoveTextLabels(newFields, textLabel) {
let newTextLabel = textLabel.slice();
- const currentFields = textLabel.map(tl => tl.field && tl.field.name).filter(d => d);
+ const currentFields = textLabel
+ .map(tl => tl.field && tl.field.name)
+ .filter(d => d);
const addFields = newFields.filter(f => !currentFields.includes(f.name));
- const deleteFields = currentFields
- .filter(f => !newFields.find(fd => fd.name === f));
+ const deleteFields = currentFields.filter(
+ f => !newFields.find(fd => fd.name === f)
+ );
// delete
- newTextLabel = newTextLabel.filter(tl => tl.field && !deleteFields.includes(tl.field.name));
+ newTextLabel = newTextLabel.filter(
+ tl => tl.field && !deleteFields.includes(tl.field.name)
+ );
newTextLabel = !newTextLabel.length ? [DEFAULT_TEXT_LABEL] : newTextLabel;
// add
newTextLabel = [
- ...(newTextLabel.filter(tl => tl.field)),
+ ...newTextLabel.filter(tl => tl.field),
...addFields.map(af => ({
...DEFAULT_TEXT_LABEL,
field: af
@@ -249,13 +291,17 @@ function addOrRemoveTextLabels(newFields, textLabel) {
}
function updateTextLabelPropAndValue(idx, prop, value, textLabel) {
+ if (!textLabel[idx].hasOwnProperty(prop)) {
+ return textLabel;
+ }
+
let newTextLabel = textLabel.slice();
if (prop && (value || textLabel.length === 1)) {
newTextLabel = textLabel.map((tl, i) =>
- i === idx ? {...tl, [prop]: value} : tl);
+ i === idx ? {...tl, [prop]: value} : tl
+ );
} else if (prop === 'field' && value === null && textLabel.length > 1) {
-
// remove label when field value is set to null
newTextLabel.splice(idx, 1);
}
@@ -268,23 +314,22 @@ export function layerTextLabelChangeUpdater(state, action) {
const {textLabel} = oldLayer.config;
let newTextLabel = textLabel.slice();
+ if (!textLabel[idx] && idx === textLabel.length) {
+ // if idx is set to length, add empty text label
+ newTextLabel = [...textLabel, DEFAULT_TEXT_LABEL];
+ }
if (idx === 'all' && prop === 'fields') {
newTextLabel = addOrRemoveTextLabels(value, textLabel);
- }
-
- // if idx is set to length, add empty text label
- if (!textLabel[idx] && idx === textLabel.length) {
- newTextLabel = [
- ...textLabel,
- DEFAULT_TEXT_LABEL
- ];
+ } else {
+ newTextLabel = updateTextLabelPropAndValue(idx, prop, value, newTextLabel);
}
// update text label prop and value
- newTextLabel = updateTextLabelPropAndValue(idx, prop, value, newTextLabel);
-
- return layerConfigChangeUpdater(state, {oldLayer, newConfig: {textLabel: newTextLabel}});
+ return layerConfigChangeUpdater(state, {
+ oldLayer,
+ newConfig: {textLabel: newTextLabel}
+ });
}
/**
@@ -299,6 +344,9 @@ export function layerTextLabelChangeUpdater(state, action) {
*/
export function layerTypeChangeUpdater(state, action) {
const {oldLayer, newType} = action;
+ if (!oldLayer) {
+ return state;
+ }
const oldId = oldLayer.id;
const idx = state.layers.findIndex(l => l.id === oldId);
@@ -320,27 +368,32 @@ export function layerTypeChangeUpdater(state, action) {
}
const {layerData, layer} = calculateLayerData(newLayer, state);
+ let newState = updateStateWithLayerAndData(state, {layerData, layer, idx});
- let newState = state;
+ if (layer.config.animation.enabled || oldLayer.config.animation.enabled) {
+ newState = updateAnimationDomain(newState);
+ }
// update splitMap layer id
if (state.splitMaps.length) {
newState = {
- ...state,
- splitMaps: state.splitMaps.map(settings => {
+ ...newState,
+ splitMaps: newState.splitMaps.map(settings => {
const {[oldId]: oldLayerMap, ...otherLayers} = settings.layers;
- return oldId in settings.layers ? {
- ...settings,
- layers: {
- ...otherLayers,
- [layer.id]: oldLayerMap
- }
- } : settings;
+ return oldId in settings.layers
+ ? {
+ ...settings,
+ layers: {
+ ...otherLayers,
+ [layer.id]: oldLayerMap
+ }
+ }
+ : settings;
})
};
}
- return updateStateWithLayerAndData(newState, {layerData, layer, idx});
+ return newState;
}
/**
@@ -399,7 +452,9 @@ export function layerVisConfigChangeUpdater(state, action) {
newLayer,
state,
oldLayerData,
- {sameData: true}
+ {
+ sameData: true
+ }
);
return updateStateWithLayerAndData(state, {layerData, layer, idx});
}
@@ -430,7 +485,11 @@ export function interactionConfigChangeUpdater(state, action) {
// but coordinates can be shown at all time
const contradict = ['brush', 'tooltip'];
- if (contradict.includes(config.id) && config.enabled && !state.interactionConfig[config.id].enabled) {
+ if (
+ contradict.includes(config.id) &&
+ config.enabled &&
+ !state.interactionConfig[config.id].enabled
+ ) {
// only enable one interaction at a time
contradict.forEach(k => {
if (k !== config.id) {
@@ -621,8 +680,8 @@ export const layerColorUIChangeUpdater = (state, {oldLayer, prop, newConfig}) =>
*/
export const toggleFilterAnimationUpdater = (state, action) => ({
...state,
- filters: state.filters.map(
- (f, i) => (i === action.idx ? {...f, isAnimating: !f.isAnimating} : f)
+ filters: state.filters.map((f, i) =>
+ i === action.idx ? {...f, isAnimating: !f.isAnimating} : f
)
});
@@ -636,13 +695,53 @@ export const toggleFilterAnimationUpdater = (state, action) => ({
* @returns {Object} nextState
* @public
*/
-export const updateAnimationSpeedUpdater = (state, action) => ({
+export const updateFilterAnimationSpeedUpdater = (state, action) => ({
...state,
- filters: state.filters.map(
- (f, i) => (i === action.idx ? {...f, speed: action.speed} : f)
+ filters: state.filters.map((f, i) =>
+ i === action.idx ? {...f, speed: action.speed} : f
)
});
+/**
+ * Reset animation config current time to a specified value
+ * @memberof visStateUpdaters
+ * @param {Object} state `visState`
+ * @param {Object} action action
+ * @param {Number} action.value the value current time will be set to
+ * @returns {Object} nextState
+ * @public
+ *
+ */
+
+export const updateAnimationTimeUpdater = (state, {value}) => ({
+ ...state,
+ animationConfig: {
+ ...state.animationConfig,
+ currentTime: value
+ }
+});
+
+/**
+ * Update animation speed with the vertical speed slider
+ * @memberof visStateUpdaters
+ * @param {Object} state `visState`
+ * @param {Object} action action
+ * @param {Number} action.speed the updated speed of the animation
+ * @returns {Object} nextState
+ * @public
+ *
+ */
+
+export const updateLayerAnimationSpeedUpdater = (state, {speed}) => {
+ return {
+ ...state,
+ animationConfig: {
+ ...state.animationConfig,
+ speed
+ }
+ };
+};
+
/**
* Show larger time filter at bottom for time playback (apply to time filter only)
* @memberof visStateUpdaters
@@ -738,7 +837,7 @@ export const removeLayerUpdater = (state, {idx}) => {
const layerToRemove = state.layers[idx];
const newMaps = removeLayerFromSplitMaps(state.splitMaps, layerToRemove);
- return {
+ const newState = {
...state,
layers: [...layers.slice(0, idx), ...layers.slice(idx + 1, layers.length)],
layerData: [
@@ -752,6 +851,8 @@ export const removeLayerUpdater = (state, {idx}) => {
hoverInfo: layerToRemove.isLayerHovered(hoverInfo) ? undefined : hoverInfo,
splitMaps: newMaps
};
+
+ return updateAnimationDomain(newState);
};
/**
@@ -869,7 +970,7 @@ export const showDatasetTableUpdater = (state, action) => {
* @returns {Object} nextState
* @public
*/
-export const resetMapConfigUpdater = (state) => ({
+export const resetMapConfigUpdater = state => ({
...INITIAL_VIS_STATE,
...state.initialState,
initialState: state.initialState
@@ -886,7 +987,10 @@ export const resetMapConfigUpdater = (state) => ({
* @returns {Object} nextState
* @public
*/
-export const receiveMapConfigUpdater = (state, {payload: {config = {}, options = {}}}) => {
+export const receiveMapConfigUpdater = (
+ state,
+ {payload: {config = {}, options = {}}}
+) => {
if (!config.visState) {
return state;
}
@@ -896,7 +1000,8 @@ export const receiveMapConfigUpdater = (state, {payload: {config = {}, options =
layers,
interactionConfig,
layerBlending,
- splitMaps
+ splitMaps,
+ animationConfig
} = config.visState;
const {keepExistingConfig} = options;
@@ -908,6 +1013,7 @@ export const receiveMapConfigUpdater = (state, {payload: {config = {}, options =
mergedState = mergeInteractions(mergedState, interactionConfig);
mergedState = mergeLayerBlending(mergedState, layerBlending);
mergedState = mergeSplitMaps(mergedState, splitMaps);
+ mergedState = mergeAnimationConfig(mergedState, animationConfig);
return mergedState;
};
@@ -937,10 +1043,12 @@ export const layerHoverUpdater = (state, action) => ({
*/
export const layerClickUpdater = (state, action) => ({
...state,
- mousePos: state.interactionConfig.coordinate.enabled ? {
- ...state.mousePos,
- pinned: state.mousePos.pinned ? null : cloneDeep(state.mousePos)
- } : state.mousePos,
+ mousePos: state.interactionConfig.coordinate.enabled
+ ? {
+ ...state.mousePos,
+ pinned: state.mousePos.pinned ? null : cloneDeep(state.mousePos)
+ }
+ : state.mousePos,
clicked: action.info && action.info.picked ? action.info : null
});
@@ -951,15 +1059,14 @@ export const layerClickUpdater = (state, action) => ({
* @returns {Object} nextState
* @public
*/
-export const mapClickUpdater = (state) => {
+export const mapClickUpdater = state => {
return {
- ...state,
- clicked: null
-}
+ ...state,
+ clicked: null
+ };
};
export const mouseMoveUpdater = (state, {evt}) => {
-
if (Object.values(state.interactionConfig).some(config => config.enabled)) {
return {
...state,
@@ -972,7 +1079,7 @@ export const mouseMoveUpdater = (state, {evt}) => {
}
return state;
-}
+};
/**
* Toggle visibility of a layer for a split map
* @memberof visStateUpdaters
@@ -1007,14 +1114,18 @@ export const toggleLayerForMapUpdater = (state, {mapIndex, layerId}) => {
return {
...state,
- splitMaps: splitMaps.map((sm, i) => i === mapIndex ? {
- ...splitMaps[i],
- layers: {
- ...splitMaps[i].layers,
- // if layerId not in layers, set it to visible
- [layerId]: !splitMaps[i].layers[layerId]
- }
- } : sm)
+ splitMaps: splitMaps.map((sm, i) =>
+ i === mapIndex
+ ? {
+ ...splitMaps[i],
+ layers: {
+ ...splitMaps[i].layers,
+ // if layerId not in layers, set it to visible
+ [layerId]: !splitMaps[i].layers[layerId]
+ }
+ }
+ : sm
+ )
};
};
@@ -1053,15 +1164,16 @@ export const updateVisDataUpdater = (state, action) => {
}),
{}
);
-
if (!Object.keys(newDateEntries).length) {
return state;
}
// apply config if passed from action
- const previousState = config ? receiveMapConfigUpdater(state, {
- payload: {config, options}
- }) : state;
+ const previousState = config
+ ? receiveMapConfigUpdater(state, {
+ payload: {config, options}
+ })
+ : state;
const stateWithNewData = {
...previousState,
@@ -1081,8 +1193,10 @@ export const updateVisDataUpdater = (state, action) => {
// merge state with saved filters
let mergedState = mergeFilters(stateWithNewData, filterToBeMerged);
+
// merge state with saved layers
mergedState = mergeLayers(mergedState, layerToBeMerged);
+
// merge state with saved splitMaps
mergedState = mergeSplitMaps(mergedState, splitMapsToBeMerged);
@@ -1092,15 +1206,16 @@ export const updateVisDataUpdater = (state, action) => {
if (!newLayers.length) {
// no layer merged, find defaults
- mergedState = addDefaultLayers(mergedState, newDateEntries);
+ const result = addDefaultLayers(mergedState, newDateEntries);
+ mergedState = result.state;
+ newLayers = result.newLayers;
}
if (mergedState.splitMaps.length) {
+ // if map is split, add new layers to splitMaps
newLayers = mergedState.layers.filter(
l => l.config.dataId in newDateEntries
);
-
- // if map is split, add new layers to splitMaps
mergedState = {
...mergedState,
splitMaps: addNewLayersToSplitMap(mergedState.splitMaps, newLayers)
@@ -1119,7 +1234,15 @@ export const updateVisDataUpdater = (state, action) => {
}
});
- return updateAllLayerDomainData(mergedState, Object.keys(newDateEntries));
+ let updatedState = updateAllLayerDomainData(
+ mergedState,
+ Object.keys(newDateEntries)
+ );
+
+ // register layer animation domain,
+ // need to be called after layer data is calculated
+ updatedState = updateAnimationDomain(updatedState);
+ return updatedState;
};
/* eslint-enable max-statements */
@@ -1140,11 +1263,12 @@ function closeSpecificMapAtIndex(state, action) {
// update layer visibility
const newLayers = layers.map(layer =>
- !mapLayers[layer.id] && layer.config.isVisible ?
- layer.updateLayerConfig({
- // if layer.id is not in mapLayers, it should be inVisible
- isVisible: false
- }) : layer
+ !mapLayers[layer.id] && layer.config.isVisible
+ ? layer.updateLayerConfig({
+ // if layer.id is not in mapLayers, it should be inVisible
+ isVisible: false
+ })
+ : layer
);
// delete map
@@ -1166,23 +1290,24 @@ function closeSpecificMapAtIndex(state, action) {
*/
export const loadFilesUpdater = (state, action) => {
const {files} = action;
-
const filesToLoad = files.map(fileBlob => processFileToLoad(fileBlob));
-
// reader -> parser -> augment -> receiveVisData
const loadFileTasks = [
Task.all(filesToLoad.map(LOAD_FILE_TASK)).bimap(
results => {
- const data = results.reduce((f, c) => ({
- // using concat here because the current datasets could be an array or a single item
- datasets: f.datasets.concat(c.datasets),
- // we need to deep merge this thing unless we find a better solution
- // this case will only happen if we allow to load multiple keplergl json files
- config: {
- ...f.config,
- ...(c.config || {})
- }
- }), {datasets: [], config: {}, options: {centerMap: true}});
+ const data = results.reduce(
+ (f, c) => ({
+ // using concat here because the current datasets could be an array or a single item
+ datasets: f.datasets.concat(c.datasets),
+ // we need to deep merge this thing unless we find a better solution
+ // this case will only happen if we allow to load multiple keplergl json files
+ config: {
+ ...f.config,
+ ...(c.config || {})
+ }
+ }),
+ {datasets: [], config: {}, options: {centerMap: true}}
+ );
return addDataToMap(data);
},
error => loadFilesErr(error)
@@ -1228,14 +1353,18 @@ export function addDefaultLayers(state, datasets) {
],
[]
);
+
return {
- ...state,
- layers: [...state.layers, ...defaultLayers],
- layerOrder: [
- // put new layers on top of old ones
- ...defaultLayers.map((_, i) => state.layers.length + i),
- ...state.layerOrder
- ]
+ state: {
+ ...state,
+ layers: [...state.layers, ...defaultLayers],
+ layerOrder: [
+ // put new layers on top of old ones
+ ...defaultLayers.map((_, i) => state.layers.length + i),
+ ...state.layerOrder
+ ]
+ },
+ newLayers: defaultLayers
};
}
@@ -1303,9 +1432,48 @@ export function updateAllLayerDomainData(state, dataId, newFilter) {
}
});
- return {
+ const newState = {
...state,
layers: newLayers,
layerData: newLayerDatas
};
+
+ return newState;
+}
+
+export function updateAnimationDomain(state) {
+ // merge all animatable layer domain and update global config
+ const animatableLayers = state.layers.filter(
+ l =>
+ l.config.isVisible &&
+ l.config.animation &&
+ l.config.animation.enabled &&
+ Array.isArray(l.animationDomain)
+ );
+
+ if (!animatableLayers.length) {
+ return {
+ ...state,
+ animationConfig: defaultAnimationConfig
+ };
+ }
+
+ const mergedDomain = animatableLayers.reduce(
+ (accu, layer) => [
+ Math.min(accu[0], layer.animationDomain[0]),
+ Math.max(accu[1], layer.animationDomain[1])
+ ],
+ [Number(Infinity), -Infinity]
+ );
+
+ return {
+ ...state,
+ animationConfig: {
+ ...state.animationConfig,
+ currentTime: isInRange(state.animationConfig.currentTime, mergedDomain)
+ ? state.animationConfig.currentTime
+ : mergedDomain[0],
+ domain: mergedDomain
+ }
+ };
}
diff --git a/src/reducers/vis-state.js b/src/reducers/vis-state.js
index 1efc483ab..1f0c35bcf 100644
--- a/src/reducers/vis-state.js
+++ b/src/reducers/vis-state.js
@@ -75,11 +75,17 @@ const actionHandler = {
[ActionTypes.SET_FILTER_PLOT]: visStateUpdaters.setFilterPlotUpdater,
+ [ActionTypes.SET_VISIBLE_LAYERS_FOR_MAP]: visStateUpdaters.setVisibleLayersForMapUpdater,
+
[ActionTypes.SHOW_DATASET_TABLE]: visStateUpdaters.showDatasetTableUpdater,
[ActionTypes.TOGGLE_FILTER_ANIMATION]: visStateUpdaters.toggleFilterAnimationUpdater,
- [ActionTypes.UPDATE_FILTER_ANIMATION_SPEED]: visStateUpdaters.updateAnimationSpeedUpdater,
+ [ActionTypes.UPDATE_FILTER_ANIMATION_SPEED]: visStateUpdaters.updateFilterAnimationSpeedUpdater,
+
+ [ActionTypes.UPDATE_ANIMATION_TIME]: visStateUpdaters.updateAnimationTimeUpdater,
+
+ [ActionTypes.UPDATE_LAYER_ANIMATION_SPEED]: visStateUpdaters.updateLayerAnimationSpeedUpdater,
[ActionTypes.TOGGLE_LAYER_FOR_MAP]: visStateUpdaters.toggleLayerForMapUpdater,
diff --git a/src/schemas/vis-state-schema.js b/src/schemas/vis-state-schema.js
index 52b6827c7..70294a626 100644
--- a/src/schemas/vis-state-schema.js
+++ b/src/schemas/vis-state-schema.js
@@ -684,6 +684,13 @@ export const propertiesV1 = {
splitMaps: new SplitMapsSchema({
key: 'splitMaps',
version: VERSIONS.v1
+ }),
+ animationConfig: new Schema({
+ version: VERSIONS.v1,
+ properties: {
+ currentTime: null
+ },
+ key: 'animationConfig'
})
};
diff --git a/src/styles/base.js b/src/styles/base.js
index 575f04195..f18ba29b0 100644
--- a/src/styles/base.js
+++ b/src/styles/base.js
@@ -83,8 +83,13 @@ export const negativeBtnActColor = '#FFFFFF';
// Input
export const inputBoxHeight = '34px';
+export const inputBoxHeightSmall = '24px';
+export const inputBoxHeightTiny = '18px';
export const inputPadding = '4px 10px';
+export const inputPaddingSmall = '4px 6px';
+export const inputPaddingTiny = '2px 4px';
export const inputFontSize = '11px';
+export const inputFontSizeSmall = '10px';
export const inputFontWeight = 500;
export const inputBgd = '#29323C';
export const inputBgdHover = '#3A414C';
@@ -97,7 +102,6 @@ export const inputBorderRadius = '1px';
export const inputPlaceholderColor = '#6A7485';
export const inputPlaceholderFontWeight = 400;
-export const secondaryInputHeight = '28px';
export const secondaryInputBgd = '#242730';
export const secondaryInputBgdHover = '#3A414C';
export const secondaryInputBgdActive = '#3A414C';
@@ -187,6 +191,11 @@ export const mapPanelHeaderBackgroundColor = '#29323C';
export const tooltipBg = '#F8F8F9';
export const tooltipColor = '#333334';
+// Bottom Panel
+export const bottomInnerPdSide = 32;
+export const bottomInnerPdVert = 6;
+export const bottomPanelGap = 20;
+
// Modal
export const modalTitleColor = '#3A414C';
export const modalTitleFontSize = '24px';
@@ -220,7 +229,9 @@ export const sliderHandleColor = '#D3D8E0';
export const sliderHandleHoverColor = '#FFFFFF';
export const sliderHandleShadow = '0 2px 4px 0 rgba(0,0,0,0.40)';
export const sliderInputHeight = 24;
-export const sliderInputWidth = 50;
+export const sliderInputWidth = 56;
+export const sliderMarginTopIsRange = 0;
+export const sliderMarginTop = 12;
// Plot
export const rangeBrushBgd = '#3A414C';
@@ -248,6 +259,13 @@ const extendColumnWidth = 2 * columnWidth;
const gridDefaultWidth = 800;
const gridDefaultHeight = 600;
+// Floating Time display
+const timeDisplayBorderRadius = 32;
+const timeDisplayHeight = 64;
+const timeDisplayMinWidth = 176;
+const timeDisplayOpacity = 0.8;
+const timeDisplayPadding = '0 24px';
+
export const textTruncate = {
maxWidth: '100%',
overflow: 'hidden',
@@ -273,18 +291,33 @@ const input = css`
${props =>
props.active
? props.theme.inputBorderActiveColor
- : props.error ? props.theme.errorColor : props.theme.inputBgd};
+ : props.error
+ ? props.theme.errorColor
+ : props.theme.inputBgd};
border-radius: 2px;
caret-color: ${props => props.theme.inputBorderActiveColor};
color: ${props => props.theme.inputColor};
display: flex;
- font-size: ${props => props.theme.inputFontSize};
+ font-size: ${props =>
+ ['small', 'tiny'].includes(props.size)
+ ? props.theme.inputFontSizeSmall
+ : props.theme.inputFontSize};
font-weight: ${props => props.theme.inputFontWeight};
- height: ${props => props.theme.inputBoxHeight};
+ height: ${props =>
+ props.size === 'small'
+ ? props.theme.inputBoxHeightSmall
+ : props.size === 'tiny'
+ ? props.theme.inputBoxHeightTiny
+ : props.theme.inputBoxHeight};
justify-content: space-between;
outline: none;
overflow: hidden;
- padding: ${props => props.theme.inputPadding};
+ padding: ${props =>
+ props.size === 'small'
+ ? props.theme.inputPaddingSmall
+ : props.size === 'tiny'
+ ? props.theme.inputPaddingTiny
+ : props.theme.inputPadding};
text-overflow: ellipsis;
transition: ${props => props.theme.transition};
white-space: nowrap;
@@ -294,7 +327,7 @@ const input = css`
opacity: ${props => (props.disabled ? 0.5 : 1)};
:hover {
- cursor: ${props => props.type === 'number' ? 'text' : 'pointer'};
+ cursor: ${props => (props.type === 'number' ? 'text' : 'pointer')};
background-color: ${props =>
props.active ? props.theme.inputBgdActive : props.theme.inputBgdHover};
border-color: ${props =>
@@ -353,11 +386,10 @@ const inputLT = css`
:hover {
background-color: ${props => props.theme.selectBackgroundLT};
- cursor: ${props => ['number', 'text'].includes(props.type) ? 'text' : 'pointer'};
+ cursor: ${props =>
+ ['number', 'text'].includes(props.type) ? 'text' : 'pointer'};
border-color: ${props =>
- props.active
- ? props.theme.textColorLT
- : props.theme.subtextColor};
+ props.active ? props.theme.textColorLT : props.theme.subtextColor};
}
`;
@@ -365,11 +397,9 @@ const secondaryInput = css`
${props => props.theme.input}
color: ${props => props.theme.secondaryInputColor};
background-color: ${props => props.theme.secondaryInputBgd};
- height: ${props => props.theme.secondaryInputHeight};
border: 1px solid
- ${props => props.error
- ? props.theme.errorColor
- : props.theme.secondaryInputBorderColor};
+ ${props =>
+ props.error ? props.theme.errorColor : props.theme.secondaryInputBorderColor};
:hover {
cursor: pointer;
@@ -438,9 +468,7 @@ const inlineInput = css`
const switchTrack = css`
background: ${props =>
- props.checked
- ? props.theme.switchTrackBgdActive
- : props.theme.switchTrackBgd};
+ props.checked ? props.theme.switchTrackBgdActive : props.theme.switchTrackBgd};
position: absolute;
top: 0;
left: ${props => -props.theme.switchLabelMargin}px;
@@ -455,13 +483,15 @@ const switchButton = css`
transition: ${props => props.theme.transition};
position: absolute;
top: 0;
- left: ${props => (props.checked ? props.theme.switchWidth / 2 : -1) - props.theme.switchLabelMargin}px;
+ left: ${props =>
+ (props.checked ? props.theme.switchWidth / 2 : -1) -
+ props.theme.switchLabelMargin}px;
content: '';
display: block;
height: ${props => props.theme.switchBtnHeight};
width: ${props => props.theme.switchBtnWidth};
- background: ${props => props.checked ?
- props.theme.switchBtnBgdActive : props.theme.switchBtnBgd};
+ background: ${props =>
+ props.checked ? props.theme.switchBtnBgdActive : props.theme.switchBtnBgd};
box-shadow: ${props => props.theme.switchBtnBoxShadow};
`;
@@ -496,8 +526,13 @@ const checkboxBox = css`
left: 0;
width: ${props => props.theme.checkboxWidth}px;
height: ${props => props.theme.checkboxHeight}px;
- background: ${props => props.checked ? props.theme.checkboxBoxBgdChecked : props.theme.checkboxBoxBgd};
- border: 1px solid ${props => props.checked ? props.theme.checkboxBoxBgdChecked : props.theme.checkboxBorderColor};
+ background: ${props =>
+ props.checked ? props.theme.checkboxBoxBgdChecked : props.theme.checkboxBoxBgd};
+ border: 1px solid
+ ${props =>
+ props.checked
+ ? props.theme.checkboxBoxBgdChecked
+ : props.theme.checkboxBorderColor};
border-radius: 2px;
content: '';
`;
@@ -512,8 +547,8 @@ const checkboxCheck = css`
transform: rotate(-45deg);
display: block;
position: absolute;
- opacity: ${props => props.checked ? 1 : 0};
- content: "";
+ opacity: ${props => (props.checked ? 1 : 0)};
+ content: '';
`;
const inputCheckbox = css`
@@ -529,7 +564,7 @@ const inputCheckbox = css`
margin-left: -${props => props.theme.switchLabelMargin}px;
:before {
- ${props => props.theme.checkboxBox};
+ ${props => props.theme.checkboxBox};
}
:after {
@@ -541,16 +576,17 @@ const secondarySwitch = css`
${props => props.theme.inputSwitch}
:before {
${props => props.theme.switchTrack} background: ${props =>
- props.checked
- ? props.theme.switchTrackBgdActive
- : props.theme.secondarySwitchTrackBgd};
+ props.checked
+ ? props.theme.switchTrackBgdActive
+ : props.theme.secondarySwitchTrackBgd};
}
:after {
${props => props.theme.switchButton}
- background: ${props => props.checked
- ? props.theme.switchBtnBgdActive
- : props.theme.secondarySwitchBtnBgd};
+ background: ${props =>
+ props.checked
+ ? props.theme.switchBtnBgdActive
+ : props.theme.secondarySwitchBtnBgd};
}
`;
@@ -685,7 +721,7 @@ const panelDropdownScrollBar = css`
background: ${props => props.theme.labelColor};
cursor: pointer;
}
- };
+ }
`;
const scrollBar = css`
@@ -827,13 +863,18 @@ export const theme = {
inputBgdHover,
inputBgdActive,
inputBoxHeight,
+ inputBoxHeightSmall,
+ inputBoxHeightTiny,
inputBorderColor,
inputBorderActiveColor,
inputBorderHoverColor,
inputBorderRadius,
inputColor,
inputPadding,
+ inputPaddingSmall,
+ inputPaddingTiny,
inputFontSize,
+ inputFontSizeSmall,
inputFontWeight,
inputPlaceholderColor,
inputPlaceholderFontWeight,
@@ -841,7 +882,6 @@ export const theme = {
secondaryInputBgd,
secondaryInputBgdHover,
secondaryInputBgdActive,
- secondaryInputHeight,
secondaryInputColor,
secondaryInputBorderColor,
secondaryInputBorderActiveColor,
@@ -960,6 +1000,11 @@ export const theme = {
tooltipBg,
tooltipColor,
+ // Bottom Panel
+ bottomInnerPdSide,
+ bottomInnerPdVert,
+ bottomPanelGap,
+
// Slider
sliderBarColor,
sliderBarBgd,
@@ -973,6 +1018,8 @@ export const theme = {
sliderHandleShadow,
sliderInputHeight,
sliderInputWidth,
+ sliderMarginTopIsRange,
+ sliderMarginTop,
// Plot
rangeBrushBgd,
@@ -994,6 +1041,12 @@ export const theme = {
gridDefaultWidth,
gridDefaultHeight,
+ // time display
+ timeDisplayBorderRadius,
+ timeDisplayHeight,
+ timeDisplayMinWidth,
+ timeDisplayOpacity,
+ timeDisplayPadding,
// Breakpoints
breakPoints
};
diff --git a/src/utils/data-utils.js b/src/utils/data-utils.js
index 8cf1ded87..78ceccd42 100644
--- a/src/utils/data-utils.js
+++ b/src/utils/data-utils.js
@@ -98,25 +98,33 @@ export function clamp([min, max], val) {
return val <= min ? min : val >= max ? max : val;
};
-export function getSampleData(data, sampleSize = 500) {
+export function getSampleData(data, sampleSize = 500, getValue = d => d) {
const sampleStep = Math.max(Math.floor(data.length / sampleSize), 1);
const output = [];
for (let i = 0; i < data.length; i += sampleStep) {
- output.push(data[i]);
+ output.push(getValue(data[i]));
}
return output;
}
+/**
+ * Convert different time format to unix milliseconds
+ * @param {*} value
+ * @param {*} format
+ */
+export function timeToUnixMilli(value, format) {
+ if (notNullorUndefined(value)) {
+ return typeof value === 'string'
+ ? moment.utc(value, format).valueOf()
+ : format === 'x' ? value * 1000 : value;
+ }
+ return null;
+}
+
export function maybeToDate(isTime, fieldIdx, format, d) {
if (isTime) {
- if (notNullorUndefined(d[fieldIdx])) {
- return typeof d[fieldIdx] === 'string'
- ? moment.utc(d[fieldIdx], format).valueOf()
- : format === 'x' ? d[fieldIdx] * 1000 : d[fieldIdx];
- }
-
- return null;
+ return timeToUnixMilli(d[fieldIdx], format);
}
return d[fieldIdx];
diff --git a/src/utils/filter-utils.js b/src/utils/filter-utils.js
index 382d6e705..4bbe092f7 100644
--- a/src/utils/filter-utils.js
+++ b/src/utils/filter-utils.js
@@ -79,26 +79,6 @@ export const FILTER_COMPONENTS = {
[FILTER_TYPES.range]: 'RangeFilter'
};
-export const BASE_SPEED = 600;
-export const TIME_ANIMATION_SPEED = [
- {
- label: '0.5x',
- value: 0.5
- },
- {
- label: '1x',
- value: 1
- },
- {
- label: '2x',
- value: 2
- },
- {
- label: '4x',
- value: 4
- }
-];
-
export function getDefaultFilter(dataId) {
return {
// link to dataset Id
@@ -348,9 +328,8 @@ export function adjustValueToFilterDomain(value, {domain, type}) {
return domain.map(d => d);
}
- return value.map(
- (d, i) =>
- notNullorUndefined(d) && isInRange(d, domain) ? d : domain[i]
+ return value.map((d, i) =>
+ notNullorUndefined(d) && isInRange(d, domain) ? d : domain[i]
);
case FILTER_TYPES.multiSelect:
@@ -498,8 +477,8 @@ export function getTimeWidgetTitleFormatter(domain) {
return diff > durationYear
? 'MM/DD/YY'
: diff > durationDay
- ? 'MM/DD hha'
- : 'MM/DD hh:mma';
+ ? 'MM/DD/YY hh:mma'
+ : 'MM/DD/YY hh:mm:ssa';
}
export function getTimeWidgetHintFormatter(domain) {
@@ -511,12 +490,12 @@ export function getTimeWidgetHintFormatter(domain) {
return diff > durationYear
? 'MM/DD/YY'
: diff > durationWeek
- ? 'MM/DD'
- : diff > durationDay
- ? 'MM/DD hha'
- : diff > durationHour
- ? 'hh:mma'
- : 'hh:mm:ssa';
+ ? 'MM/DD'
+ : diff > durationDay
+ ? 'MM/DD hha'
+ : diff > durationHour
+ ? 'hh:mma'
+ : 'hh:mm:ssa';
}
/**
diff --git a/src/utils/layer-utils/layer-utils.js b/src/utils/layer-utils/layer-utils.js
index be295dccb..400e1b056 100644
--- a/src/utils/layer-utils/layer-utils.js
+++ b/src/utils/layer-utils/layer-utils.js
@@ -18,8 +18,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import {DEFAULT_LIGHT_SETTINGS} from 'constants/default-settings';
-
/**
* Find default layers from fields
*
@@ -27,29 +25,35 @@ import {DEFAULT_LIGHT_SETTINGS} from 'constants/default-settings';
* @param {Object} layerClasses
* @returns {Array} found layers
*/
-export function findDefaultLayer(dataset, layerClasses) {
+export function findDefaultLayer(dataset, layerClasses = {}) {
if (!dataset) {
return [];
}
+ const layerProps = Object.keys(layerClasses).reduce((previous, lc) => {
+ const result =
+ typeof layerClasses[lc].findDefaultLayerProps === 'function'
+ ? layerClasses[lc].findDefaultLayerProps(dataset, previous)
+ : {props: []};
- let layers = [];
- Object.keys(layerClasses).forEach(lc => {
- const layerProps = layerClasses[lc].findDefaultLayerProps(dataset);
- if (layerProps) {
- const newLayers = (Array.isArray(layerProps) ? layerProps : [layerProps])
- .map(props => {
- const layer = new layerClasses[lc]({...props, dataId: dataset.id});
+ const props = Array.isArray(result) ? result : result.props || [];
+ const foundLayers = result.foundLayers || previous;
- return typeof layer.setInitialLayerConfig === 'function'
- ? layer.setInitialLayerConfig(dataset.allData)
- : layer
- });
+ return foundLayers.concat(
+ props.map(p => ({
+ ...p,
+ type: lc,
+ dataId: dataset.id
+ }))
+ );
+ }, []);
- layers = layers.concat(newLayers);
- }
+ // go through all layerProps to create layer
+ return layerProps.map(props => {
+ const layer = new layerClasses[props.type](props);
+ return typeof layer.setInitialLayerConfig === 'function'
+ ? layer.setInitialLayerConfig(dataset.allData)
+ : layer;
});
-
- return layers;
}
/**
@@ -80,17 +84,3 @@ export function calculateLayerData(layer, state, oldLayerData, opt = {}) {
);
return {layerData, layer};
}
-
-export function getLightSettingsFromBounds(bounds) {
- return Array.isArray(bounds) && bounds.length >= 4
- ? {
- ...DEFAULT_LIGHT_SETTINGS,
- lightsPosition: [
- ...bounds.slice(0, 2),
- DEFAULT_LIGHT_SETTINGS.lightsPosition[2],
- ...bounds.slice(2, 4),
- DEFAULT_LIGHT_SETTINGS.lightsPosition[5]
- ]
- }
- : DEFAULT_LIGHT_SETTINGS;
-}
diff --git a/test/fixtures/geojson.js b/test/fixtures/geojson.js
index 7310f2cf6..4ea660da4 100644
--- a/test/fixtures/geojson.js
+++ b/test/fixtures/geojson.js
@@ -308,18 +308,3 @@ export const geoBounds = [
-122.39166672864975,
37.79427854456892
];
-export const geoLightSettings = {
- lightsPosition: [
- -122.40115971858505,
- 37.78202426695214,
- 8000,
- -122.39166672864975,
- 37.79427854456892,
- 8000
- ],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0, 0.8, 0],
- numberOfLights: 2
-};
diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.js
index b03df5beb..6fb0b3666 100644
--- a/test/fixtures/state-saved-v0.js
+++ b/test/fixtures/state-saved-v0.js
@@ -1063,22 +1063,7 @@ mergedLayer0.config = {
};
mergedLayer0.meta = {
- bounds: [-122.4784396, 37.78188901, -121.3686062, 38.5590766],
- lightSettings: {
- lightsPosition: [
- -122.4784396,
- 37.78188901,
- 8000,
- -121.3686062,
- 38.5590766,
- 8000
- ],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0, 0.8, 0],
- numberOfLights: 2
- }
+ bounds: [-122.4784396, 37.78188901, -121.3686062, 38.5590766]
};
const mergedLayer1 = new ArcLayer({
@@ -1209,26 +1194,12 @@ mergedLayer2.config = {
strokeColor: [218, 112, 191],
fixedRadius: false,
radiusRange: [1, 854.16]
- }
+ },
+ animation: {enabled: false}
};
mergedLayer2.meta = {
- bounds: [-122.4761712, 37.6169644, -121.7922809, 38.4163786],
- lightSettings: {
- lightsPosition: [
- -122.4761712,
- 37.6169644,
- 8000,
- -121.7922809,
- 38.4163786,
- 8000
- ],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0, 0.8, 0],
- numberOfLights: 2
- }
+ bounds: [-122.4761712, 37.6169644, -121.7922809, 38.4163786]
};
const mergedLayer3 = new HexagonLayer({
@@ -1287,26 +1258,12 @@ mergedLayer3.config = {
percentile: [0, 100],
elevationPercentile: [0, 100],
elevationScale: 10
- }
+ },
+ animation: {enabled: false}
};
mergedLayer3.meta = {
- bounds: [-122.4761712, 37.6169644, -121.7922809, 38.4163786],
- lightSettings: {
- lightsPosition: [
- -122.4761712,
- 37.6169644,
- 8000,
- -121.7922809,
- 38.4163786,
- 8000
- ],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0, 0.8, 0],
- numberOfLights: 2
- }
+ bounds: [-122.4761712, 37.6169644, -121.7922809, 38.4163786]
};
const mergedLayer4 = new GeojsonLayer({id: 'vta'});
@@ -1411,7 +1368,8 @@ mergedLayer4.config = {
filled: true,
enable3d: false,
wireframe: false
- }
+ },
+ animation: {enabled: false}
};
mergedLayer4.dataToFeature = {
@@ -1490,21 +1448,6 @@ mergedLayer4.meta = {
-122.39989147796784,
37.787534455433345
],
- lightSettings: {
- lightsPosition: [
- -122.50828762723958,
- 37.733266432915535,
- 8000,
- -122.39989147796784,
- 37.787534455433345,
- 8000
- ],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0, 0.8, 0],
- numberOfLights: 2
- },
featureTypes: {polygon: true},
fp64: false,
fixedRadius: false
diff --git a/test/fixtures/state-saved-v1-1.js b/test/fixtures/state-saved-v1-1.js
index fedc64628..571d8bda8 100644
--- a/test/fixtures/state-saved-v1-1.js
+++ b/test/fixtures/state-saved-v1-1.js
@@ -962,19 +962,12 @@ mergedLayer0.config = {
strokeColor: [181, 18, 65],
enable3d: true,
wireframe: false
- }
+ },
+ animation: {enabled: false}
};
mergedLayer0.meta = {
bounds: [-75.135531, 40.213125, -73.949229, 41.172585],
- lightSettings: {
- lightsPosition: [-75.135531, 40.213125, 8000, -73.949229, 41.172585, 8000],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0, 0.8, 0],
- numberOfLights: 2
- },
fixedRadius: false,
featureTypes: {polygon: true}
};
@@ -2750,19 +2743,12 @@ mergedLayer1.config = {
enable3d: false,
wireframe: false,
strokeColor: [221, 178, 124]
- }
+ },
+ animation: {enabled: false}
};
mergedLayer1.meta = {
bounds: [-75.135531, 40.213125, -73.949229, 41.172585],
- lightSettings: {
- lightsPosition: [-75.135531, 40.213125, 8000, -73.949229, 41.172585, 8000],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0, 0.8, 0],
- numberOfLights: 2
- },
fixedRadius: false,
featureTypes: {
polygon: true
diff --git a/test/fixtures/state-saved-v1-3.js b/test/fixtures/state-saved-v1-3.js
index a16e3fda8..fd9705b3f 100644
--- a/test/fixtures/state-saved-v1-3.js
+++ b/test/fixtures/state-saved-v1-3.js
@@ -440,7 +440,8 @@ mergedLayer0.config = {
},
radiusRange: [0, 50],
strokeColor: [18, 147, 154]
- }
+ },
+ animation: {enabled: false}
};
const mergedLayer1 = new HexagonLayer({
@@ -494,7 +495,8 @@ mergedLayer1.config = {
colorAggregation: 'average',
sizeAggregation: 'average',
enable3d: false
- }
+ },
+ animation: {enabled: false}
};
export const mergedLayers = [mergedLayer0, mergedLayer1];
diff --git a/test/fixtures/state-saved-v1-4.js b/test/fixtures/state-saved-v1-4.js
index 9a7bbfff7..52634566f 100644
--- a/test/fixtures/state-saved-v1-4.js
+++ b/test/fixtures/state-saved-v1-4.js
@@ -285,7 +285,8 @@ mergedLayer0.config = {
},
strokeColor: [23, 184, 190, 255],
radiusRange: [0, 50]
- }
+ },
+ animation: {enabled: false}
};
export const mergedLayers = [mergedLayer0];
diff --git a/test/fixtures/state-saved-v1-5.js b/test/fixtures/state-saved-v1-5.js
new file mode 100644
index 000000000..7137a77fd
--- /dev/null
+++ b/test/fixtures/state-saved-v1-5.js
@@ -0,0 +1,293 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import tripGeojson, {
+ timeStampDomain,
+ tripBounds,
+ dataToTimeStamp,
+ dataToFeature
+} from 'test/fixtures/trip-geojson';
+import {
+ DEFAULT_TEXT_LABEL,
+ DEFAULT_COLOR_RANGE,
+ DEFAULT_LAYER_OPACITY,
+ DEFAULT_COLOR_UI
+} from 'layers/layer-factory';
+import {KeplerGlLayers} from 'layers';
+const {TripLayer} = KeplerGlLayers;
+
+export const savedStateV1TripGeoJson = {
+ datasets: [
+ {
+ version: 'v1',
+ data: {
+ id: 'trip_data',
+ label: 'Trip Data',
+ color: [162, 212, 171],
+ allData: [
+ [
+ {
+ type: 'Feature',
+ properties: {
+ vendor: 'A',
+ index: 0
+ },
+ geometry: tripGeojson.features[0].geometry
+ },
+ 'A'
+ ],
+ [
+ {
+ type: 'Feature',
+ properties: {
+ vendor: 'B',
+ index: 1
+ },
+ geometry: tripGeojson.features[1].geometry
+ },
+ 'B'
+ ],
+ [
+ {
+ type: 'Feature',
+ properties: {
+ vendor: 'A',
+ index: 2
+ },
+ geometry: tripGeojson.features[2].geometry
+ },
+ 'A'
+ ],
+ [
+ {
+ type: 'Feature',
+ properties: {
+ vendor: 'A',
+ index: 3
+ },
+ geometry: tripGeojson.features[3].geometry
+ },
+ 'A'
+ ],
+ [
+ {
+ type: 'Feature',
+ properties: {
+ vendor: 'A',
+ index: 4
+ },
+ geometry: tripGeojson.features[4].geometry
+ },
+ 'A'
+ ],
+ [
+ {
+ type: 'Feature',
+ properties: {
+ vendor: 'A',
+ index: 5
+ },
+ geometry: tripGeojson.features[5].geometry
+ },
+ 'A'
+ ],
+ [
+ {
+ type: 'Feature',
+ properties: {
+ vendor: 'B',
+ index: 6
+ },
+ geometry: tripGeojson.features[6].geometry
+ },
+ 'B'
+ ],
+ [
+ {
+ type: 'Feature',
+ properties: {
+ vendor: 'A',
+ index: 7
+ },
+ geometry: tripGeojson.features[7].geometry
+ },
+ 'A'
+ ],
+ [
+ {
+ type: 'Feature',
+ properties: {
+ vendor: 'A',
+ index: 8
+ },
+ geometry: tripGeojson.features[8].geometry
+ },
+ 'A'
+ ]
+ ],
+ fields: [
+ {
+ name: '_geojson',
+ type: 'geojson',
+ format: ''
+ },
+ {
+ name: 'vendor',
+ type: 'string',
+ format: ''
+ }
+ ]
+ }
+ }
+ ],
+ config: {
+ version: 'v1',
+ config: {
+ visState: {
+ filters: [],
+ layers: [
+ {
+ id: 'trip-0',
+ type: 'trip',
+ config: {
+ dataId: 'trip_data',
+ label: 'Trip Data',
+ color: [0, 0, 0],
+ columns: {
+ geojson: '_geojson'
+ },
+ isVisible: true,
+ visConfig: {
+ opacity: 0.8,
+ thickness: 0.5,
+ colorRange: {
+ name: 'Global Warming',
+ type: 'sequential',
+ category: 'Uber',
+ colors: [
+ '#5A1846',
+ '#900C3F',
+ '#C70039',
+ '#E3611C',
+ '#F1920E',
+ '#FFC300'
+ ]
+ },
+ trailLength: 180,
+ sizeRange: [0, 10]
+ },
+ textLabel: [
+ {
+ field: null,
+ color: [255, 255, 255],
+ size: 18,
+ offset: [0, 0],
+ anchor: 'start',
+ alignment: 'center'
+ }
+ ]
+ },
+ visualChannels: {
+ colorField: null,
+ colorScale: 'quantile',
+ sizeField: null,
+ sizeScale: 'linear'
+ }
+ }
+ ],
+ interactionConfig: {
+ tooltip: {
+ fieldsToShow: {
+ trip_data: ['vendor']
+ },
+ enabled: true
+ },
+ brush: {
+ size: 0.5,
+ enabled: false
+ }
+ },
+ layerBlending: 'normal',
+ splitMaps: [],
+ animationConfig: {
+ currentTime: 1565577261000
+ }
+ },
+ mapState: {
+ bearing: 0,
+ dragRotate: false,
+ latitude: 37.75043,
+ longitude: -122.34679,
+ pitch: 0,
+ zoom: 9,
+ isSplit: false
+ },
+ mapStyle: {
+ styleType: 'dark',
+ topLayerGroups: {},
+ visibleLayerGroups: {},
+ threeDBuildingColor: [209, 206, 199],
+ mapStyles: {}
+ }
+ }
+ },
+ info: {
+ app: 'kepler.gl',
+ created_at: 'Sun Sep 15 2019 18:49:29 GMT-0700 (PDT)'
+ }
+};
+
+export const mergedLayer0 = new TripLayer({
+ id: 'trip-0'
+});
+
+mergedLayer0.config = {
+ dataId: 'trip_data',
+ label: 'Trip Data',
+ color: [0, 0, 0],
+ columns: {geojson: {value: '_geojson', fieldIdx: 0}},
+ isVisible: true,
+ isConfigActive: false,
+ highlightColor: [252, 242, 26, 255],
+ colorField: null,
+ colorDomain: [0, 1],
+ colorScale: 'quantile',
+ sizeDomain: [0, 1],
+ sizeScale: 'linear',
+ sizeField: null,
+ colorUI: {
+ color: DEFAULT_COLOR_UI,
+ colorRange: DEFAULT_COLOR_UI
+ },
+ visConfig: {
+ opacity: DEFAULT_LAYER_OPACITY,
+ thickness: 0.5,
+ colorRange: DEFAULT_COLOR_RANGE,
+ trailLength: 180,
+ sizeRange: [0, 10]
+ },
+ textLabel: [DEFAULT_TEXT_LABEL],
+ animation: {enabled: true, domain: timeStampDomain}
+};
+
+mergedLayer0.dataToFeature = dataToFeature;
+mergedLayer0.dataToTimeStamp = dataToTimeStamp;
+mergedLayer0.meta.bounds = tripBounds;
+mergedLayer0.meta.featureTypes = {line: true};
diff --git a/test/fixtures/test-csv-data.js b/test/fixtures/test-csv-data.js
index 7b8c758e2..c99fd2444 100644
--- a/test/fixtures/test-csv-data.js
+++ b/test/fixtures/test-csv-data.js
@@ -966,21 +966,6 @@ export const updatedLayerV2 = {
meta: {
featureTypes: {polygon: true},
bounds: [-74.593264, 40.632238, -74.148473, 41.091647],
- lightSettings: {
- lightsPosition: [
- -74.593264,
- 40.632238,
- 8000,
- -74.148473,
- 41.091647,
- 8000
- ],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0, 0.8, 0],
- numberOfLights: 2
- },
fixedRadius: false
}
};
@@ -1072,23 +1057,7 @@ export const updatedLayerSimplifiedShape = {
meta: {
featureTypes: {polygon: true},
bounds: [-74.593264, 40.630453, -74.158491, 41.105958],
- lightSettings: {
- lightsPosition: [
- -74.593264,
- 40.630453,
- 8000,
- -74.158491,
- 41.105958,
- 8000
- ],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0, 0.8, 0],
- numberOfLights: 2
- },
fixedRadius: false
}
};
-
/* eslint-enable max-lens */
diff --git a/test/fixtures/test-hex-id-data.js b/test/fixtures/test-hex-id-data.js
index 5db6a9526..02b22531d 100644
--- a/test/fixtures/test-hex-id-data.js
+++ b/test/fixtures/test-hex-id-data.js
@@ -279,6 +279,9 @@ mergedH3Layer.config = {
colorUI: {
color: DEFAULT_COLOR_UI,
colorRange: DEFAULT_COLOR_UI
+ },
+ animation: {
+ enabled: false
}
};
diff --git a/test/fixtures/trip-geojson.js b/test/fixtures/trip-geojson.js
new file mode 100644
index 000000000..af4636d78
--- /dev/null
+++ b/test/fixtures/trip-geojson.js
@@ -0,0 +1,329 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+export const tripDataInfo = {
+ id: 'trip_data',
+ label: 'Trip Data'
+};
+
+const tripGeoJson = {
+ type: 'FeatureCollection',
+ features: [
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-73.78966, 40.6429, 0, 1565578338],
+ [-73.7895, 40.64267, 0, 1565578346],
+ [-73.78923, 40.6424, 0, 1565578356],
+ [-73.78905, 40.64222, 0, 1565578364],
+ [-73.7889, 40.64209, 0, 1565578365],
+ [-73.78859, 40.64191, 0, 1565578367],
+ [-73.78836, 40.64181, 0, 1565578368],
+ [-73.78793, 40.6417, 0, 1565578371],
+ [-73.78756, 40.64163, 0, 1565578373],
+ [-73.78707, 40.64159, 0, 1565578375]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'B'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-74.33223, 40.64375, 0, 1565578213],
+ [-74.33242, 40.64353, 0, 1565578217],
+ [-74.33001, 40.64222, 0, 1565578243],
+ [-74.32882, 40.64154, 0, 1565578256],
+ [-74.32682, 40.64039, 0, 1565578278],
+ [-74.32589, 40.63985, 0, 1565578288],
+ [-74.31725, 40.63485, 0, 1565578382],
+ [-74.31404, 40.63302, 0, 1565578417],
+ [-74.30616, 40.6283, 0, 1565578504]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-73.87893, 40.64672, 0, 1565578095],
+ [-73.87969, 40.64624, 0, 1565578123],
+ [-73.87976, 40.64619, 0, 1565578125],
+ [-73.88064, 40.64697, 0, 1565578156],
+ [-73.88138, 40.64765, 0, 1565578181],
+ [-73.88234, 40.64849, 0, 1565578214],
+ [-73.883, 40.64911, 0, 1565578237],
+ [-73.88338, 40.64943, 0, 1565578250]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-74.18532, 40.69402, 0, 1565577961],
+ [-74.18499, 40.6945, 0, 1565577967],
+ [-74.18472, 40.69501, 0, 1565577973],
+ [-74.1846, 40.69533, 0, 1565577976],
+ [-74.18415, 40.69665, 0, 1565577991],
+ [-74.18391, 40.6975, 0, 1565578000],
+ [-74.18372, 40.6983, 0, 1565578008],
+ [-74.18364, 40.69882, 0, 1565578014],
+ [-74.18354, 40.6994, 0, 1565578018]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-73.97301, 40.67601, 0, 1565578666],
+ [-73.97161, 40.67546, 0, 1565578694],
+ [-73.97142, 40.67575, 0, 1565578712],
+ [-73.9719, 40.67641, 0, 1565578732],
+ [-73.97244, 40.67716, 0, 1565578756],
+ [-73.97234, 40.67744, 0, 1565578778],
+ [-73.96917, 40.67678, 0, 1565578836]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-74.03806, 40.74578, 0, 1565578252],
+ [-74.03893, 40.74289, 0, 1565578322],
+ [-74.03934, 40.74158, 0, 1565578354],
+ [-74.0384, 40.74142, 0, 1565578376],
+ [-74.03746, 40.74126, 0, 1565578399],
+ [-74.03824, 40.73872, 0, 1565578465],
+ [-74.03878, 40.73693, 0, 1565578511],
+ [-74.03893, 40.73693, 0, 1565578513],
+ [-74.03974, 40.73704, 0, 1565578524],
+ [-74.03979, 40.7369, 0, 1565578528],
+ [-74.03964, 40.73677, 0, 1565578531]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'B'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-73.79007, 40.64681, 0, 1565577697],
+ [-73.79092, 40.64643, 0, 1565577720],
+ [-73.79108, 40.64631, 0, 1565577726],
+ [-73.7912, 40.64613, 0, 1565577732],
+ [-73.79121, 40.64597, 0, 1565577737],
+ [-73.79116, 40.64581, 0, 1565577743],
+ [-73.79106, 40.6457, 0, 1565577747],
+ [-73.79094, 40.64557, 0, 1565577749],
+ [-73.79072, 40.64542, 0, 1565577751],
+ [-73.79057, 40.64534, 0, 1565577753]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-73.87815, 40.88362, 0, 1565577773],
+ [-73.87772, 40.88345, 0, 1565577786],
+ [-73.87812, 40.88215, 0, 1565577814],
+ [-73.87467, 40.88156, 0, 1565577872],
+ [-73.87479, 40.88007, 0, 1565577904],
+ [-73.87494, 40.87994, 0, 1565577907],
+ [-73.87307, 40.88013, 0, 1565577938],
+ [-73.87191, 40.88023, 0, 1565577957],
+ [-73.87254, 40.87874, 0, 1565577974],
+ [-73.87159, 40.87864, 0, 1565577993],
+ [-73.87133, 40.8786, 0, 1565577999],
+ [-73.87046, 40.87838, 0, 1565578017],
+ [-73.87029, 40.87834, 0, 1565578020]
+ ]
+ }
+ },
+ {
+ type: 'Feature',
+ properties: {vendor: 'A'},
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-74.00227, 40.62526, 0, 1565577261],
+ [-74.00272, 40.62482, 0, 1565577277],
+ [-74.00052, 40.62348, 0, 1565577315],
+ [-74.01522, 40.60935, 0, 1565577685],
+ [-74.01697, 40.60769, 0, 1565577728],
+ [-74.01623, 40.60723, 0, 1565577750],
+ [-74.01549, 40.60684, 0, 1565577771],
+ [-74.0173, 40.60513, 0, 1565577796],
+ [-74.01746, 40.60496, 0, 1565577799],
+ [-74.01788, 40.60471, 0, 1565577802],
+ [-74.01826, 40.60455, 0, 1565577805],
+ [-74.01855, 40.6044, 0, 1565577807],
+ [-74.01874, 40.60428, 0, 1565577809]
+ ]
+ }
+ }
+ ]
+};
+
+const fts = tripGeoJson.features;
+export const dataToFeature = [
+ {type: 'Feature', properties: {...fts[0].properties, index: 0}, geometry: fts[0].geometry},
+ {type: 'Feature', properties: {...fts[1].properties, index: 1}, geometry: fts[1].geometry},
+ {type: 'Feature', properties: {...fts[2].properties, index: 2}, geometry: fts[2].geometry},
+ {type: 'Feature', properties: {...fts[3].properties, index: 3}, geometry: fts[3].geometry},
+ {type: 'Feature', properties: {...fts[4].properties, index: 4}, geometry: fts[4].geometry},
+ {type: 'Feature', properties: {...fts[5].properties, index: 5}, geometry: fts[5].geometry},
+ {type: 'Feature', properties: {...fts[6].properties, index: 6}, geometry: fts[6].geometry},
+ {type: 'Feature', properties: {...fts[7].properties, index: 7}, geometry: fts[7].geometry},
+ {type: 'Feature', properties: {...fts[8].properties, index: 8}, geometry: fts[8].geometry}
+];
+
+export const dataToTimeStamp = [
+ [
+ 1565578338000,
+ 1565578346000,
+ 1565578356000,
+ 1565578364000,
+ 1565578365000,
+ 1565578367000,
+ 1565578368000,
+ 1565578371000,
+ 1565578373000,
+ 1565578375000
+ ],
+ [
+ 1565578213000,
+ 1565578217000,
+ 1565578243000,
+ 1565578256000,
+ 1565578278000,
+ 1565578288000,
+ 1565578382000,
+ 1565578417000,
+ 1565578504000
+ ],
+ [
+ 1565578095000,
+ 1565578123000,
+ 1565578125000,
+ 1565578156000,
+ 1565578181000,
+ 1565578214000,
+ 1565578237000,
+ 1565578250000
+ ],
+ [
+ 1565577961000,
+ 1565577967000,
+ 1565577973000,
+ 1565577976000,
+ 1565577991000,
+ 1565578000000,
+ 1565578008000,
+ 1565578014000,
+ 1565578018000
+ ],
+ [
+ 1565578666000,
+ 1565578694000,
+ 1565578712000,
+ 1565578732000,
+ 1565578756000,
+ 1565578778000,
+ 1565578836000
+ ],
+ [
+ 1565578252000,
+ 1565578322000,
+ 1565578354000,
+ 1565578376000,
+ 1565578399000,
+ 1565578465000,
+ 1565578511000,
+ 1565578513000,
+ 1565578524000,
+ 1565578528000,
+ 1565578531000
+ ],
+ [
+ 1565577697000,
+ 1565577720000,
+ 1565577726000,
+ 1565577732000,
+ 1565577737000,
+ 1565577743000,
+ 1565577747000,
+ 1565577749000,
+ 1565577751000,
+ 1565577753000
+ ],
+ [
+ 1565577773000,
+ 1565577786000,
+ 1565577814000,
+ 1565577872000,
+ 1565577904000,
+ 1565577907000,
+ 1565577938000,
+ 1565577957000,
+ 1565577974000,
+ 1565577993000,
+ 1565577999000,
+ 1565578017000,
+ 1565578020000
+ ],
+ [
+ 1565577261000,
+ 1565577277000,
+ 1565577315000,
+ 1565577685000,
+ 1565577728000,
+ 1565577750000,
+ 1565577771000,
+ 1565577796000,
+ 1565577799000,
+ 1565577802000,
+ 1565577805000,
+ 1565577807000,
+ 1565577809000
+ ]
+];
+export const timeStampDomain = [1565577261000, 1565578836000];
+export const tripBounds = [-74.33242, 40.60428, -73.78707, 40.88362];
+
+export default tripGeoJson;
diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.js
index 197a4edcf..2c465f797 100644
--- a/test/helpers/mock-state.js
+++ b/test/helpers/mock-state.js
@@ -27,7 +27,7 @@ import * as VisStateActions from 'actions/vis-state-actions';
import * as MapStyleActions from 'actions/map-style-actions';
import * as MapStateActions from 'actions/map-state-actions';
import {addDataToMap} from 'actions/actions';
-import {DEFAULT_TEXT_LABEL} from 'layers/layer-factory';
+import {DEFAULT_TEXT_LABEL, DEFAULT_COLOR_RANGE, DEFAULT_LAYER_OPACITY} from 'layers/layer-factory';
// fixtures
import {testFields, testAllData} from 'test/fixtures/test-csv-data';
@@ -38,6 +38,8 @@ import {
config as tripConfig,
dataId as tripDataId
} from 'test/fixtures/test-trip-data';
+import tripGeojson, {tripDataInfo} from 'test/fixtures/trip-geojson';
+import {processGeojson} from 'processors/data-processor';
const geojsonFields = cloneDeep(fields);
const geojsonRows = cloneDeep(rows);
@@ -105,6 +107,28 @@ function mockStateWithFileUpload() {
return updatedState;
}
+function mockStateWithTripGeojson() {
+ const initialState = cloneDeep(InitialState);
+
+ // load csv and geojson
+ const updatedState = applyActions(keplerGlReducer, initialState, [
+ {
+ action: VisStateActions.updateVisData,
+ payload: [
+ [{info: tripDataInfo, data: processGeojson(cloneDeep(tripGeojson))}]
+ ]
+ }
+ ]);
+
+ // replace layer id and color with controlled value for testing
+ updatedState.visState.layers.forEach((l, i) => {
+ l.id = `${l.type}-${i}`;
+ l.config.color = [i, i, i];
+ });
+
+ return updatedState;
+}
+
function mockStateWithFilters(state) {
const initialState = state || mockStateWithFileUpload();
@@ -315,22 +339,10 @@ export const expectedSavedLayer0 = {
},
isVisible: true,
visConfig: {
- opacity: 0.8,
+ opacity: DEFAULT_LAYER_OPACITY,
worldUnitSize: 1,
resolution: 8,
- colorRange: {
- name: 'Global Warming',
- type: 'sequential',
- category: 'Uber',
- colors: [
- '#5A1846',
- '#900C3F',
- '#C70039',
- '#E3611C',
- '#F1920E',
- '#FFC300'
- ]
- },
+ colorRange: DEFAULT_COLOR_RANGE,
coverage: 1,
sizeRange: [0, 500],
percentile: [0, 100],
@@ -363,22 +375,10 @@ export const expectedLoadedLayer0 = {
},
isVisible: true,
visConfig: {
- opacity: 0.8,
+ opacity: DEFAULT_LAYER_OPACITY,
worldUnitSize: 1,
resolution: 8,
- colorRange: {
- name: 'Global Warming',
- type: 'sequential',
- category: 'Uber',
- colors: [
- '#5A1846',
- '#900C3F',
- '#C70039',
- '#E3611C',
- '#F1920E',
- '#FFC300'
- ]
- },
+ colorRange: DEFAULT_COLOR_RANGE,
coverage: 1,
sizeRange: [0, 500],
percentile: [0, 100],
@@ -422,7 +422,7 @@ export const expectedSavedLayer1 = {
visConfig: {
radius: 10,
fixedRadius: false,
- opacity: 0.8,
+ opacity: DEFAULT_LAYER_OPACITY,
outline: false,
filled: true,
thickness: 2,
@@ -432,19 +432,7 @@ export const expectedSavedLayer1 = {
category: 'Uber',
colors: ['#E6FAFA', '#AAD7DA', '#68B4BB', '#00939C']
},
- strokeColorRange: {
- name: 'Global Warming',
- type: 'sequential',
- category: 'Uber',
- colors: [
- '#5A1846',
- '#900C3F',
- '#C70039',
- '#E3611C',
- '#F1920E',
- '#FFC300'
- ]
- },
+ strokeColorRange: DEFAULT_COLOR_RANGE,
strokeColor: null,
radiusRange: [0, 50]
}
@@ -478,7 +466,7 @@ export const expectedLoadedLayer1 = {
visConfig: {
radius: 10,
fixedRadius: false,
- opacity: 0.8,
+ opacity: DEFAULT_LAYER_OPACITY,
outline: false,
thickness: 2,
colorRange: {
@@ -487,19 +475,7 @@ export const expectedLoadedLayer1 = {
category: 'Uber',
colors: ['#E6FAFA', '#AAD7DA', '#68B4BB', '#00939C']
},
- strokeColorRange: {
- name: 'Global Warming',
- type: 'sequential',
- category: 'Uber',
- colors: [
- '#5A1846',
- '#900C3F',
- '#C70039',
- '#E3611C',
- '#F1920E',
- '#FFC300'
- ]
- },
+ strokeColorRange: DEFAULT_COLOR_RANGE,
filled: true,
strokeColor: null,
radiusRange: [0, 50]
@@ -538,34 +514,10 @@ export const expectedSavedLayer2 = {
},
isVisible: true,
visConfig: {
- opacity: 0.8,
+ opacity: DEFAULT_LAYER_OPACITY,
thickness: 0.5,
- colorRange: {
- name: 'Global Warming',
- type: 'sequential',
- category: 'Uber',
- colors: [
- '#5A1846',
- '#900C3F',
- '#C70039',
- '#E3611C',
- '#F1920E',
- '#FFC300'
- ]
- },
- strokeColorRange: {
- name: 'Global Warming',
- type: 'sequential',
- category: 'Uber',
- colors: [
- '#5A1846',
- '#900C3F',
- '#C70039',
- '#E3611C',
- '#F1920E',
- '#FFC300'
- ]
- },
+ colorRange: DEFAULT_COLOR_RANGE,
+ strokeColorRange: DEFAULT_COLOR_RANGE,
strokeColor: [11, 11, 11],
radius: 10,
sizeRange: [0, 10],
@@ -605,34 +557,10 @@ export const expectedLoadedLayer2 = {
},
isVisible: true,
visConfig: {
- opacity: 0.8,
+ opacity: DEFAULT_LAYER_OPACITY,
thickness: 0.5,
- colorRange: {
- name: 'Global Warming',
- type: 'sequential',
- category: 'Uber',
- colors: [
- '#5A1846',
- '#900C3F',
- '#C70039',
- '#E3611C',
- '#F1920E',
- '#FFC300'
- ]
- },
- strokeColorRange: {
- name: 'Global Warming',
- type: 'sequential',
- category: 'Uber',
- colors: [
- '#5A1846',
- '#900C3F',
- '#C70039',
- '#E3611C',
- '#F1920E',
- '#FFC300'
- ]
- },
+ colorRange: DEFAULT_COLOR_RANGE,
+ strokeColorRange: DEFAULT_COLOR_RANGE,
strokeColor: [11, 11, 11],
radius: 10,
sizeRange: [0, 10],
@@ -667,3 +595,32 @@ export const StateWFilesFiltersLayerColor = mockStateWithLayerDimensions(
export const StateWCustomMapStyle = mockStateWithCustomMapStyle();
export const StateWSplitMaps = mockStateWithSplitMaps();
export const StateWTrips = mockStateWithTripData();
+export const StateWTripGeojson = mockStateWithTripGeojson();
+
+export const expectedSavedTripLayer = {
+ id: 'trip-0',
+ type: 'trip',
+ config: {
+ dataId: 'trip_data',
+ label: 'Trip Data',
+ color: [0, 0, 0],
+ columns: {
+ geojson: '_geojson'
+ },
+ isVisible: true,
+ visConfig: {
+ opacity: DEFAULT_LAYER_OPACITY,
+ thickness: 0.5,
+ colorRange: DEFAULT_COLOR_RANGE,
+ trailLength: 180,
+ sizeRange: [0, 10]
+ },
+ textLabel: [DEFAULT_TEXT_LABEL]
+ },
+ visualChannels: {
+ colorField: null,
+ colorScale: 'quantile',
+ sizeField: null,
+ sizeScale: 'linear'
+ }
+};
diff --git a/test/node/layer-tests/grid-layer-specs.js b/test/node/layer-tests/grid-layer-specs.js
index 3869a7b43..0ca43185d 100644
--- a/test/node/layer-tests/grid-layer-specs.js
+++ b/test/node/layer-tests/grid-layer-specs.js
@@ -63,22 +63,7 @@ test('#GridLayer -> formatLayerData', t => {
const allDataWithNull = [[null, null, '12']].concat(rows);
const expectedLayerMeta = {
- bounds: [31.2148748, 29.9870074, 31.2590542, 30.0614122],
- lightSettings: {
- lightsPosition: [
- 31.2148748,
- 29.9870074,
- 8000,
- 31.2590542,
- 30.0614122,
- 8000
- ],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0, 0.8, 0],
- numberOfLights: 2
- }
+ bounds: [31.2148748, 29.9870074, 31.2590542, 30.0614122]
};
const TEST_CASES = [
diff --git a/test/node/layer-tests/hexagon-layer-specs.js b/test/node/layer-tests/hexagon-layer-specs.js
index 9d00cc7dc..468281ae8 100644
--- a/test/node/layer-tests/hexagon-layer-specs.js
+++ b/test/node/layer-tests/hexagon-layer-specs.js
@@ -63,22 +63,7 @@ test('#HexagonLayer -> formatLayerData', async t => {
const allDataWithNull = [[null, null, '12']].concat(rows);
const expectedLayerMeta = {
- bounds: [31.2148748, 29.9870074, 31.2590542, 30.0614122],
- lightSettings: {
- lightsPosition: [
- 31.2148748,
- 29.9870074,
- 8000,
- 31.2590542,
- 30.0614122,
- 8000
- ],
- ambientRatio: 0.4,
- diffuseRatio: 0.6,
- specularRatio: 0.3,
- lightsStrength: [0.9, 0, 0.8, 0],
- numberOfLights: 2
- }
+ bounds: [31.2148748, 29.9870074, 31.2590542, 30.0614122]
};
const TEST_CASES = [
diff --git a/test/node/reducers/vis-state-merger-test.js b/test/node/reducers/vis-state-merger-test.js
index 05c8a5c90..d606a48f0 100644
--- a/test/node/reducers/vis-state-merger-test.js
+++ b/test/node/reducers/vis-state-merger-test.js
@@ -31,9 +31,11 @@ import {
import SchemaManager from 'schemas';
import visStateReducer from 'reducers/vis-state';
+import coreReducer from 'reducers/core';
import {updateVisData} from 'actions/vis-state-actions';
-import {receiveMapConfig} from 'actions/actions';
+import {receiveMapConfig, addDataToMap} from 'actions/actions';
import {getDefaultInteraction} from 'utils/interaction-utils';
+import {processKeplerglJSON} from 'processors/data-processor';
// fixtures
import {
@@ -58,6 +60,11 @@ import {
mergedLayers as mergedLayersV1Label
} from 'test/fixtures/state-saved-v1-4';
+import {
+ savedStateV1TripGeoJson,
+ mergedLayer0 as mergedTripLayer
+} from 'test/fixtures/state-saved-v1-5';
+
// helpers
import {cmpFilters, cmpLayers} from 'test/helpers/comparison-utils';
@@ -1053,3 +1060,46 @@ test('VisStateMerger - mergeSplitMaps', t => {
t.end();
});
+
+test('VisStateMerger - mergeTripGeojson', t => {
+ const initialState = cloneDeep(InitialState);
+
+ // processKeplerglJSON
+ const result = processKeplerglJSON(savedStateV1TripGeoJson)
+ const updatedCore = coreReducer(initialState, addDataToMap(result));
+
+ const mergedVieState = updatedCore.visState;
+
+ t.equal(mergedVieState.layers.length, 1, 'should create 1 layer');
+ const tripLayer = mergedVieState.layers[0];
+
+ t.equal(tripLayer.type, 'trip', 'should create 1 trip layer');
+
+ cmpLayers(t, tripLayer, mergedTripLayer, {id: true, color: true});
+
+ t.deepEqual(
+ tripLayer.dataToFeature,
+ mergedTripLayer.dataToFeature,
+ 'dataToFeature should be correct'
+ );
+
+ t.deepEqual(
+ tripLayer.dataToTimeStamp,
+ mergedTripLayer.dataToTimeStamp,
+ 'dataToTimeStamp should be correct'
+ );
+
+ t.deepEqual(
+ tripLayer.meta.bounds,
+ mergedTripLayer.meta.bounds,
+ 'meta.bounds should be correct'
+ );
+
+ t.deepEqual(
+ tripLayer.meta.featureTypes,
+ mergedTripLayer.meta.featureTypes,
+ 'meta.featureTypes should be correct'
+ );
+
+ t.end();
+});
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index ffb5edd42..c3b019e3a 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -26,24 +26,34 @@ import * as VisStateActions from 'actions/vis-state-actions';
import * as MapStateActions from 'actions/map-state-actions';
import reducer from 'reducers/vis-state';
-import {INITIAL_VIS_STATE} from 'reducers/vis-state-updaters';
+import {
+ INITIAL_VIS_STATE,
+ defaultAnimationConfig
+} from 'reducers/vis-state-updaters';
-import {getLightSettingsFromBounds} from 'utils/layer-utils/layer-utils';
import {filterData, getDefaultFilter} from 'utils/filter-utils';
+import {getDefaultInteraction} from 'utils/interaction-utils';
import {createNewDataEntry} from 'utils/dataset-utils';
import {processCsvData, processGeojson} from 'processors/data-processor';
import {Layer, KeplerGlLayers} from 'layers';
-const {ArcLayer, PointLayer, GeojsonLayer, LineLayer} = KeplerGlLayers;
+const {
+ ArcLayer,
+ PointLayer,
+ GeojsonLayer,
+ LineLayer,
+ TripLayer
+} = KeplerGlLayers;
// fixtures
import testData, {testFields, testAllData} from 'test/fixtures/test-csv-data';
import {
geojsonData,
geoBounds,
- geoLghtSettings,
fields as geojsonFields
} from 'test/fixtures/geojson';
+import tripGeojson, {timeStampDomain} from 'test/fixtures/trip-geojson';
+
// test helpers
import {
cmpFilters,
@@ -51,8 +61,14 @@ import {
cmpDatasets,
cmpDataset
} from 'test/helpers/comparison-utils';
-import {applyActions} from 'test/helpers/mock-state';
-import {LAYER_VIS_CONFIGS, DEFAULT_COLOR_UI} from 'layers/layer-factory';
+import {
+ applyActions,
+ StateWTripGeojson,
+ StateWSplitMaps,
+ StateWFilters,
+ StateWFiles
+} from 'test/helpers/mock-state';
+import {LAYER_VIS_CONFIGS, DEFAULT_TEXT_LABEL, DEFAULT_COLOR_UI} from 'layers/layer-factory';
import {getNextColorMakerValue} from 'test/helpers/layer-utils';
import {StateWFilesFiltersLayerColor} from 'test/helpers/mock-state';
@@ -258,6 +274,29 @@ test('#visStateReducer -> ADD_LAYER.1', t => {
t.end();
});
+test('#visStateReducer -> LAYER_TYPE_CHANGE.0', t => {
+ const layer = new Layer({id: 'blue'});
+
+ const oldState = {
+ ...InitialVisState
+ };
+ const nextState = reducer(oldState, VisStateActions.layerTypeChange());
+
+ t.equal(oldState, nextState, 'should return state when no argument is given');
+
+ const nextState2 = reducer(
+ oldState,
+ VisStateActions.layerTypeChange(layer, 'no_type')
+ );
+ t.equal(
+ oldState,
+ nextState2,
+ 'should return state when pass a none existing type'
+ );
+
+ t.end();
+});
+
test('#visStateReducer -> LAYER_TYPE_CHANGE.1', t => {
const layer = new Layer({id: 'more_layer'});
const oldState = {
@@ -478,6 +517,294 @@ test('#visStateReducer -> LAYER_TYPE_CHANGE.2', t => {
t.end();
});
+test('#visStateReducer -> LAYER_TYPE_CHANGE.3 -> animationConfig', t => {
+ const layer = new GeojsonLayer({
+ label: 'taro and blue',
+ dataId: 'taro',
+ columns: {geojson: {fieldIdx: 0, value: '_geojson'}},
+ isVisible: true,
+ color: [1, 1, 1],
+ id: 'taro'
+ });
+
+ const dataset = createNewDataEntry({
+ info: {id: 'taro'},
+ data: processGeojson(tripGeojson)
+ });
+
+ const oldState = {
+ ...InitialVisState,
+ datasets: dataset,
+ layers: [layer],
+ layerData: [{}],
+ layerOrder: [0]
+ };
+
+ // change GeoJson layer to Trip layer
+ const nextState = reducer(
+ oldState,
+ VisStateActions.layerTypeChange(layer, 'trip')
+ );
+
+ const foundLayer = nextState.layers[0];
+ const foundLayerId = foundLayer.id;
+ t.ok(foundLayerId !== 'taro', 'should update layer id');
+ t.equal(foundLayer.type, 'trip', 'should update type to trip');
+ t.deepEqual(
+ foundLayer.config.animation,
+ {enabled: true, domain: timeStampDomain},
+ 'should set correct animation domain'
+ );
+
+ t.deepEqual(
+ nextState.animationConfig,
+ {
+ ...defaultAnimationConfig,
+ domain: timeStampDomain,
+ currentTime: timeStampDomain[0]
+ },
+ 'should update visState.animationConfig'
+ );
+
+ // change Trip layer to Geojson layer
+ const nextState2 = reducer(
+ oldState,
+ VisStateActions.layerTypeChange(foundLayer, 'geojson')
+ );
+ const foundLayer2 = nextState2.layers[0];
+ t.ok(foundLayer2.id !== foundLayerId, 'should update layer id');
+ t.equal(foundLayer2.type, 'geojson', 'should update type to trip');
+
+ t.deepEqual(
+ foundLayer2.config.animation,
+ {enabled: false},
+ 'should set correct animation domain fro Geojson layer'
+ );
+
+ t.deepEqual(
+ nextState2.animationConfig,
+ defaultAnimationConfig,
+ 'should set animationConfig to default'
+ );
+
+ t.end();
+});
+
+test('#visStateReducer -> LAYER_CONFIG_CHANGE -> isVisible -> animationConfig', t => {
+ const initialState = StateWTripGeojson;
+ const layer = initialState.visState.layers[0];
+
+ // change Trip layer isVisible
+ const nextState = reducer(
+ StateWTripGeojson.visState,
+ VisStateActions.layerConfigChange(layer, {isVisible: false})
+ );
+
+ t.deepEqual(
+ nextState.animationConfig,
+ defaultAnimationConfig,
+ 'should set animationConfig to default'
+ );
+
+ const nextState2 = reducer(
+ nextState,
+ VisStateActions.layerConfigChange(nextState.layers[0], {isVisible: true})
+ );
+
+ t.deepEqual(
+ nextState2.animationConfig,
+ {
+ ...nextState2.animationConfig,
+ domain: timeStampDomain,
+ currentTime: timeStampDomain[0]
+ },
+ 'should set animationConfig domain and currentTime'
+ );
+
+ t.end();
+});
+
+test('#visStateReducer -> LAYER_CONFIG_CHANGE -> isVisible -> splitMaps', t => {
+ const initialState = StateWSplitMaps.visState;
+ const layer = initialState.layers[0];
+
+ const initialSplitMaps = [
+ {layers: {'point-0': false, 'geojson-1': true}},
+ {layers: {'point-0': true, 'geojson-1': true}}
+ ];
+ const expectedSplitMaps = [
+ {layers: {'geojson-1': true}},
+ {layers: {'geojson-1': true}}
+ ];
+ t.deepEqual(
+ initialState.splitMaps,
+ initialSplitMaps,
+ 'should has the same initial splitMaps'
+ );
+
+ const nextState = reducer(
+ initialState,
+ VisStateActions.layerConfigChange(layer, {isVisible: false})
+ );
+
+ t.equal(
+ nextState.layers[0].config.isVisible,
+ false,
+ 'should set layer 0 visibility to false'
+ );
+ t.equal(
+ initialState.layerData[0],
+ nextState.layerData[0],
+ 'should not update layerData'
+ );
+ t.deepEqual(
+ nextState.splitMaps,
+ expectedSplitMaps,
+ 'should remove layer from splitMaps'
+ );
+
+ const nextState2 = reducer(
+ nextState,
+ VisStateActions.layerConfigChange(layer, {isVisible: true})
+ );
+
+ const initialSplitMaps2 = [
+ {layers: {'point-0': true, 'geojson-1': true}},
+ {layers: {'point-0': true, 'geojson-1': true}}
+ ];
+ t.deepEqual(
+ nextState2.splitMaps,
+ initialSplitMaps2,
+ 'should add layer to splitMaps'
+ );
+
+ t.end();
+});
+
+test('#visStateReducer -> LAYER_VIS_CONFIG_CHANGE -> opacity', t => {
+ const initialState = StateWFiles.visState;
+ const layer = initialState.layers[0];
+
+ const nextState = reducer(initialState,
+ VisStateActions.layerVisConfigChange(layer, {opacity: 0.3}));
+
+ t.equal(nextState.layers[0].config.visConfig.opacity, 0.3, 'should update layer opacity');
+ t.end();
+});
+
+test('#visStateReducer -> LAYER_TEXT_LABEL_CHANGE', t => {
+ const initialState = StateWFiles.visState;
+ // point layer
+ const layer = initialState.layers[0];
+
+ t.deepEqual(layer.config.textLabel, [DEFAULT_TEXT_LABEL], 'should set initial textLabel');
+
+ const nextState = reducer(initialState,
+ VisStateActions.layerTextLabelChange(layer, 0, 'random', 1));
+
+ t.equal(
+ nextState.layers[0].config.textLabel,
+ layer.config.textLabel,
+ 'should not update textLabel if prop is not in textLabel'
+ );
+
+ const nextState2 = reducer(nextState,
+ VisStateActions.layerTextLabelChange(nextState.layers[0], 0, 'anchor', 'start'));
+
+ t.deepEqual(
+ nextState2.layers[0].config.textLabel[0],
+ {...DEFAULT_TEXT_LABEL, anchor: 'start'},
+ 'should start text label prop'
+ );
+
+ // set text label field
+ const nextState3 = reducer(nextState2,
+ VisStateActions.layerTextLabelChange(nextState2.layers[0], 0, 'field', {name: 'taro'}));
+
+ const expectedTextLabel1 = {
+ ...DEFAULT_TEXT_LABEL,
+ anchor: 'start',
+ field: {name: 'taro'}
+ };
+
+ t.deepEqual(
+ nextState3.layers[0].config.textLabel[0],
+ expectedTextLabel1,
+ 'should set text field'
+ );
+
+ // add empty field
+ const nextState4 = reducer(nextState3,
+ VisStateActions.layerTextLabelChange(nextState3.layers[0], 1));
+ t.deepEqual(
+ nextState4.layers[0].config.textLabel,
+ [expectedTextLabel1, DEFAULT_TEXT_LABEL],
+ 'should add text label'
+ );
+
+ // add or remove labels
+ const nextState5 = reducer(nextState4,
+ VisStateActions.layerTextLabelChange(
+ nextState4.layers[0], 'all', 'fields', [{name: 'blue'}, {name: 'taro'}]
+ ));
+ const expected5 = [
+ expectedTextLabel1,
+ {...DEFAULT_TEXT_LABEL, field: {name: 'blue'}}
+ ]
+ t.deepEqual(
+ nextState5.layers[0].config.textLabel,
+ expected5,
+ 'should add text label taro'
+ );
+
+ // add 1 more label
+ const nextState6 = reducer(nextState5,
+ VisStateActions.layerTextLabelChange(
+ nextState5.layers[0], 2, 'field', {name: 'cat'}
+ ));
+ const expected6 = [
+ expectedTextLabel1,
+ {...DEFAULT_TEXT_LABEL, field: {name: 'blue'}},
+ {...DEFAULT_TEXT_LABEL, field: {name: 'cat'}}
+ ];
+ t.deepEqual(
+ nextState6.layers[0].config.textLabel,
+ expected6,
+ 'should add text label cat'
+ );
+
+ // remove label
+ const nextState7 = reducer(nextState6,
+ VisStateActions.layerTextLabelChange(
+ nextState6.layers[0], 2, 'field', null
+ ));
+ const expected7 = [
+ expectedTextLabel1,
+ {...DEFAULT_TEXT_LABEL, field: {name: 'blue'}}
+ ];
+ t.deepEqual(
+ nextState7.layers[0].config.textLabel,
+ expected7,
+ 'should remove text label cat'
+ );
+
+ // remove label with all
+ const nextState8 = reducer(nextState7,
+ VisStateActions.layerTextLabelChange(
+ nextState7.layers[0], 'all', 'fields', [{name: 'blue'}]
+ ));
+ const expected8 = [
+ {...DEFAULT_TEXT_LABEL, field: {name: 'blue'}}
+ ];
+ t.deepEqual(
+ nextState8.layers[0].config.textLabel,
+ expected8,
+ 'should remove text label blue'
+ );
+
+ t.end();
+});
+
test('#visStateReducer -> REORDER_LAYER', t => {
const newReducer = reducer(
{layers: [], layerOrder: [0, 1, 2]},
@@ -598,7 +925,8 @@ test('#visStateReducer -> REMOVE_LAYER', t => {
layer: {props: {id: 'a'}},
picked: true
},
- splitMaps: []
+ splitMaps: [],
+ animationConfig: defaultAnimationConfig
};
const newReducer = reducer(oldState, VisStateActions.removeLayer(1));
@@ -614,11 +942,13 @@ test('#visStateReducer -> REMOVE_LAYER', t => {
layer: {props: {id: 'a'}},
picked: true
},
- splitMaps: []
+ splitMaps: [],
+ animationConfig: defaultAnimationConfig
},
'should remove layer and layerData'
);
+ // test remove
t.end();
});
@@ -766,8 +1096,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA.2 -> to empty state', t => {
});
expectedPointLayer1.meta = {
- bounds: [35.2, 12.25, 37.75, 12.29],
- lightSettings: getLightSettingsFromBounds([35.2, 12.25, 37.75, 12.29])
+ bounds: [35.2, 12.25, 37.75, 12.29]
};
const expectedPointLayer2 = new PointLayer({
@@ -781,8 +1110,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA.2 -> to empty state', t => {
});
expectedPointLayer2.meta = {
- bounds: [21.3, 33.1, 100.12, 46.21],
- lightSettings: getLightSettingsFromBounds([21.3, 33.1, 100.12, 46.21])
+ bounds: [21.3, 33.1, 100.12, 46.21]
};
const expectedLayers = [
@@ -1016,7 +1344,6 @@ test('#visStateReducer -> UPDATE_VIS_DATA.4.Geojson -> geojson data', t => {
expectedLayer.dataToFeature = dataToFeature;
expectedLayer.meta = {
bounds: geoBounds,
- lightSettings: geoLghtSettings,
fixedRadius: false,
featureTypes: {
polygon: true
@@ -1362,7 +1689,7 @@ test('#visStateReducer -> UPDATE_VIS_DATA.SPLIT_MAPS', t => {
t.end();
});
-test('#visStateReducer -> setFilter', t => {
+test('#visStateReducer -> SET_FILTER', t => {
// get test data
const {fields, rows} = processCsvData(testData);
const payload = [
@@ -1393,13 +1720,7 @@ test('#visStateReducer -> setFilter', t => {
});
expectedLayer1.meta = {
- bounds: [31.2148748, 29.9870074, 31.2590542, 30.0614122],
- lightSettings: getLightSettingsFromBounds([
- 31.2148748,
- 29.9870074,
- 31.2590542,
- 30.0614122
- ])
+ bounds: [31.2148748, 29.9870074, 31.2590542, 30.0614122]
};
const expectedLayers = [expectedLayer1];
@@ -1649,7 +1970,7 @@ test('#visStateReducer -> setFilter', t => {
t.end();
});
-test('#visStateReducer -> setFilter', t => {
+test('#visStateReducer -> SET_FILTER', t => {
const {fields, rows} = processGeojson(CloneDeep(geojsonData));
const payload = [
{
@@ -1962,7 +2283,24 @@ test('#visStateReducer -> setFilter', t => {
});
/* eslint-enable max-statements */
-test('#visStateReducer -> setFilter.fixedDomain', t => {
+test('#visStateReducer -> UPDATE_FILTER_ANIMATION_SPEED', t => {
+ const initialState = StateWFilters.visState;
+
+ const nextState = reducer(
+ initialState,
+ VisStateActions.updateFilterAnimationSpeed(0, 4)
+ );
+
+ t.equal(
+ nextState.filters[0].speed,
+ 4,
+ 'should update filter animation speed'
+ );
+
+ t.end();
+});
+
+test('#visStateReducer -> SET_FILTER.fixedDomain', t => {
// get test data
const {fields, rows} = processCsvData(testData);
const payload = [
@@ -2130,7 +2468,7 @@ test('#visStateReducer -> setFilter.fixedDomain', t => {
t.end();
});
-test('#visStateReducer -> setFilterPlot', t => {
+test('#visStateReducer -> SET_FILTER_PLOT', t => {
// get test data
const {fields, rows} = processCsvData(testData);
const payload = [
@@ -2252,6 +2590,51 @@ test('#visStateReducer -> setFilterPlot', t => {
t.end();
});
+test('#visStateReducer -> TOGGLE_FILTER_ANIMATION', t => {
+ const initialState = StateWFilters.visState;
+
+ const nextState = reducer(initialState, VisStateActions.toggleFilterAnimation(0));
+ t.equal(
+ nextState.filters[0].isAnimating,
+ true, 'should set filter to isAnimating: true');
+
+ t.end();
+});
+
+test('#visStateReducer -> ENLARGE_FILTER', t => {
+ const initialState = StateWFilters.visState;
+
+ const nextState = reducer(initialState, VisStateActions.enlargeFilter(0));
+
+ t.equal(
+ nextState.filters[0].enlarged,
+ false,
+ 'should toggle time filter enlarged to be false'
+ );
+
+ const nextState2 = reducer(nextState, VisStateActions.enlargeFilter(0));
+
+ t.equal(
+ nextState2.filters[0].enlarged,
+ true,
+ 'should toggle time filter enlarged to be true'
+ );
+
+ t.end();
+});
+
+test('#visStateReducer -> REMOVE_DATASET', t => {
+ const initialState = StateWFilters.visState;
+ const nextState = reducer(initialState, VisStateActions.removeDataset('not_me'));
+
+ t.equal(
+ initialState,
+ nextState,
+ 'should return state if datasetKey doesnot exist'
+ );
+ t.end();
+});
+
test('#visStateReducer -> REMOVE_DATASET', t => {
const layer0 = new ArcLayer({id: 'a', dataId: 'puppy_0'});
const layer1 = new PointLayer({id: 'b', dataId: 'puppy_0'});
@@ -2281,7 +2664,8 @@ test('#visStateReducer -> REMOVE_DATASET', t => {
},
hoverInfo: undefined,
clicked: undefined,
- splitMaps: []
+ splitMaps: [],
+ animationConfig: defaultAnimationConfig
};
const newReducer = reducer(
@@ -2312,7 +2696,8 @@ test('#visStateReducer -> REMOVE_DATASET', t => {
},
hoverInfo: undefined,
clicked: undefined,
- splitMaps: []
+ splitMaps: [],
+ animationConfig: defaultAnimationConfig
},
'should remove dataset, layer and layerData'
);
@@ -2379,7 +2764,8 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_LAYER', t => {
b: true
}
}
- ]
+ ],
+ animationConfig: defaultAnimationConfig
};
const newReducer = reducer(oldState, VisStateActions.removeLayer(1));
@@ -2406,7 +2792,8 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_LAYER', t => {
a: true
}
}
- ]
+ ],
+ animationConfig: defaultAnimationConfig
},
'should remove layer and layerData in split mode'
);
@@ -2414,6 +2801,61 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_LAYER', t => {
t.end();
});
+test('#visStateReducer -> SPLIT_MAP: REMOVE_LAYER', t => {
+ const layer1 = new PointLayer({id: 'a'});
+ const layer2 = new PointLayer({id: 'b'});
+ const layer3 = new TripLayer({id: 't1', isVisible: true});
+ const layer4 = new TripLayer({id: 't2', isVisible: true});
+
+ layer3.updateAnimationDomain([1568502710000, 1568502960000]);
+ layer4.updateAnimationDomain([1568502810000, 1568503060000]);
+
+ const oldState = {
+ layers: [layer1, layer2, layer3, layer4],
+ layerData: [{data: 1}, {data: 2}, {data: 3}, {data: 4}],
+ layerOrder: [1, 0, 2, 3],
+ hoverInfo: null,
+ clicked: null,
+ splitMaps: [],
+ animationConfig: {
+ domain: [1568502710000, 1568503060000],
+ currentTime: 1568502970000
+ }
+ };
+
+ const newReducer = reducer(oldState, VisStateActions.removeLayer(2));
+ const expectedAnimationConfig = {
+ domain: [1568502810000, 1568503060000],
+ currentTime: 1568502970000
+ };
+
+ t.deepEqual(
+ newReducer.animationConfig,
+ expectedAnimationConfig,
+ 'should remove animation layer and adjust animation domain'
+ );
+
+ const newReducer2 = reducer(oldState, VisStateActions.removeLayer(3));
+ const expectedAnimationConfig2 = {
+ domain: [1568502710000, 1568502960000],
+ currentTime: 1568502710000
+ };
+ t.deepEqual(
+ newReducer2.animationConfig,
+ expectedAnimationConfig2,
+ 'should remove animation layer and adjust animation domain'
+ );
+
+ const newReducer3 = reducer(newReducer2, VisStateActions.removeLayer(2));
+ t.deepEqual(
+ newReducer3.animationConfig,
+ defaultAnimationConfig,
+ 'remove last animation layer and set animation config to default'
+ );
+
+ t.end();
+});
+
test('#visStateReducer -> SPLIT_MAP: REMOVE_DATASET', t => {
const layer0 = new ArcLayer({id: 'a', dataId: 'puppy_0'});
const layer1 = new PointLayer({id: 'b', dataId: 'puppy_0'});
@@ -2460,7 +2902,8 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_DATASET', t => {
d: true
}
}
- ]
+ ],
+ animationConfig: defaultAnimationConfig
};
const newReducer = reducer(
@@ -2504,7 +2947,8 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_DATASET', t => {
d: true
}
}
- ]
+ ],
+ animationConfig: defaultAnimationConfig
};
t.deepEqual(
@@ -2671,12 +3115,120 @@ test('#visStateReducer -> SPLIT_MAP: HIDE LAYER', t => {
t.end();
});
+test('#visStateReducer -> UPDATE_ANIMATION_TIME', t => {
+ const initialState = StateWTripGeojson;
+ const newState = reducer(initialState, VisStateActions.updateAnimationTime(1000));
+
+ t.equal(newState.animationConfig.currentTime, 1000, 'should update animation time');
+ t.end();
+});
+
+test('#visStateReducer -> UPDATE_LAYER_ANIMATION_SPEED', t => {
+ const initialState = StateWTripGeojson;
+ const newState = reducer(initialState, VisStateActions.updateLayerAnimationSpeed(1.23));
+
+ t.equal(newState.animationConfig.speed, 1.23, 'should update animation speed');
+
+ t.end();
+});
+
+test('#visStateReducer -> INTERACTION_CONFIG_CHANGE', t => {
+ const defaultInteractionConfig = getDefaultInteraction();
+
+ const brushConfig = {
+ ...defaultInteractionConfig.brush,
+ enabled: true
+ };
+
+ const expectedConfig = {
+ ...defaultInteractionConfig,
+ brush: brushConfig,
+ tooltip: {
+ ...defaultInteractionConfig.tooltip,
+ enabled: false
+ }
+ };
+
+ const nextState = reducer(INITIAL_VIS_STATE,
+ VisStateActions.interactionConfigChange(brushConfig));
+
+ t.deepEqual(nextState.interactionConfig, expectedConfig, 'should disable tooltip');
+
+ t.end();
+});
+
+test('#visStateReducer -> SHOW_DATASET_TABLE', t => {
+ const initialState = StateWFiles.visState;
+ const nextState = reducer(initialState,
+ VisStateActions.showDatasetTable('abc'));
+
+ t.equal(nextState.editingDataset, 'abc', 'should set editingDataset');
+ t.end();
+});
+
+test('#visStateReducer -> MAP_CLICK', t => {
+ const initialState = StateWFiles.visState;
+ const nextState = reducer(initialState,
+ VisStateActions.onLayerClick({picked: true, object: 'he'}));
+
+ t.deepEqual(
+ nextState,
+ {...nextState, clicked: {picked: true, object: 'he'}},
+ 'should set clicked'
+ );
+
+ const nextState2 = reducer(nextState,
+ VisStateActions.onMapClick());
+
+ t.equal(nextState2.clicked, null, 'should unset clicked');
+
+ t.end();
+});
+
+test('#visStateReducer -> MOUSE_MOVE', t => {
+ const defaultInteractionConfig = getDefaultInteraction();
+ const initialState = StateWFiles.visState;
+ const evt = {
+ point: [10, 20],
+ lngLat: [37, -122]
+ };
+
+ const nextState = reducer(initialState,
+ VisStateActions.onMouseMove(evt));
+
+ t.deepEqual(nextState.mousePos,
+ {
+ ...initialState.mousePos,
+ mousePosition: [10, 20],
+ coordinate: [37, -122]
+ }, 'should set mousePos');
+
+ // disable tooltip
+ const tooltipConfig = {
+ ...defaultInteractionConfig.tooltip,
+ enabled: false
+ };
+
+ const nextState1 = reducer(nextState,
+ VisStateActions.interactionConfigChange(tooltipConfig));
+
+ const nextState2 = reducer(nextState1,
+ VisStateActions.onMouseMove({point: [1, 2], lngLat: [90, 90]}));
+
+ t.deepEqual(nextState2.mousePos,
+ {
+ ...initialState.mousePos,
+ mousePosition: [10, 20],
+ coordinate: [37, -122]
+ }, 'should not set mousePos');
+
+ t.end();
+});
test('#visStateReducer -> LAYER_COLOR_UI_CHANGE. show dropdown', t => {
const initialState = CloneDeep(StateWFilesFiltersLayerColor.visState);
const pointLayer = initialState.layers[0];
const oldColorRange = CloneDeep(pointLayer.config.visConfig.colorRange);
-
// show dropdown
const nextState = reducer(
initialState,
diff --git a/test/node/schemas/vis-state-schema-test.js b/test/node/schemas/vis-state-schema-test.js
index 0b3aa42f3..31289ce1a 100644
--- a/test/node/schemas/vis-state-schema-test.js
+++ b/test/node/schemas/vis-state-schema-test.js
@@ -23,13 +23,16 @@ import cloneDeep from 'lodash.clonedeep';
import {cmpFilters, cmpSavedLayers} from 'test/helpers/comparison-utils';
import SchemaManager from 'schemas';
-import {StateWFilesFiltersLayerColor,
+import {
+ StateWFilesFiltersLayerColor,
expectedSavedLayer0,
expectedLoadedLayer0,
expectedSavedLayer1,
expectedLoadedLayer1,
expectedSavedLayer2,
- expectedLoadedLayer2
+ expectedLoadedLayer2,
+ StateWTripGeojson,
+ expectedSavedTripLayer
} from 'test/helpers/mock-state';
test('#visStateSchema -> v1 -> save layers', t => {
@@ -39,7 +42,7 @@ test('#visStateSchema -> v1 -> save layers', t => {
const vsToSave = SchemaManager.getConfigToSave(initialState).config.visState;
t.deepEqual(Object.keys(vsToSave),
- ['filters', 'layers', 'interactionConfig', 'layerBlending', 'splitMaps'],
+ ['filters', 'layers', 'interactionConfig', 'layerBlending', 'splitMaps', 'animationConfig'],
'visState should have all 5 entries');
const exptectedSavedLayers = [
@@ -62,7 +65,7 @@ test('#visStateSchema -> v1 -> load layers', t => {
const vsLoaded = SchemaManager.parseSavedConfig(savedState).visState;
t.deepEqual(Object.keys(vsLoaded),
- ['filters', 'layers', 'interactionConfig', 'layerBlending', 'splitMaps'],
+ ['filters', 'layers', 'interactionConfig', 'layerBlending', 'splitMaps', 'animationConfig'],
'visState should have all 5 entries');
const loadedLayers = vsLoaded.layers;
@@ -164,3 +167,21 @@ test('#visStateSchema -> v1 -> save load layerBlending', t => {
t.end();
});
+
+test('#visStateSchema -> v1 -> save animation', t => {
+ const initialState = cloneDeep(StateWTripGeojson);
+
+ // save state
+ const vsToSave = SchemaManager.getConfigToSave(initialState).config.visState;
+
+ t.deepEqual(Object.keys(vsToSave),
+ ['filters', 'layers', 'interactionConfig', 'layerBlending', 'splitMaps', 'animationConfig'],
+ 'visState should have all 5 entries');
+
+ const expectedSavedLayers = [expectedSavedTripLayer];
+ const expectedAnimationConfig = {currentTime: 1565577261000};
+ cmpSavedLayers(t, expectedSavedLayers, vsToSave.layers);
+
+ t.deepEqual(vsToSave.animationConfig, expectedAnimationConfig, 'should save animationConfig');
+ t.end();
+});
diff --git a/test/node/utils/layer-utils-test.js b/test/node/utils/layer-utils-test.js
index d97b1c7fa..f101cd516 100644
--- a/test/node/utils/layer-utils-test.js
+++ b/test/node/utils/layer-utils-test.js
@@ -20,22 +20,18 @@
import test from 'tape';
import {findDefaultLayer} from 'utils/layer-utils/layer-utils';
-
-import {findPointFieldPairs} from 'utils/dataset-utils';
-import {processCsvData} from 'processors/data-processor';
+import {findPointFieldPairs, createNewDataEntry} from 'utils/dataset-utils';
+import {processCsvData, processGeojson} from 'processors/data-processor';
import {GEOJSON_FIELDS} from 'constants/default-settings';
-import {KeplerGlLayers} from 'layers';
+import {LayerClasses, KeplerGlLayers} from 'layers';
+import {StateWTripGeojson} from 'test/helpers/mock-state';
-const {
- PointLayer,
- ArcLayer,
- GeojsonLayer,
- LineLayer
-} = KeplerGlLayers;
+const {PointLayer, ArcLayer, GeojsonLayer, LineLayer} = KeplerGlLayers;
import {wktCsv} from 'test/fixtures/test-csv-data';
import {cmpLayers} from 'test/helpers/comparison-utils';
import {getNextColorMakerValue} from 'test/helpers/layer-utils';
+import tripGeojson, {timeStampDomain, tripBounds} from 'test/fixtures/trip-geojson';
test('layerUtils -> findDefaultLayer.1', t => {
const inputFields = [
@@ -244,7 +240,7 @@ test('layerUtils -> findDefaultLayer.1', t => {
const fieldPairs = findPointFieldPairs(inputFields);
const layers = findDefaultLayer(
{fields: inputFields, fieldPairs, id: dataId},
- KeplerGlLayers
+ LayerClasses
);
t.equal(layers.length, outputLayers.length, 'number of layers found');
@@ -556,7 +552,11 @@ test('layerUtils -> findDefaultLayer:GeojsonLayer', t => {
const [layer1Color, layer2Color, layer2Stroke] = getNextColorMakerValue(3);
expected1.updateLayerVisConfig({filled: true, stroked: false});
- expected2.updateLayerVisConfig({filled: true, stroked: true, strokeColor: layer2Stroke});
+ expected2.updateLayerVisConfig({
+ filled: true,
+ stroked: true,
+ strokeColor: layer2Stroke
+ });
const geojsonLayers = findDefaultLayer(
{
@@ -611,9 +611,22 @@ test('layerUtils -> findDefaultLayer:GeojsonLayer.wkt', t => {
geojson: {value: 'simplified_shape', fieldIdx: 2}
}
});
- const [layer1Color, strokeColor1, layer2Color, strokeColor2] = getNextColorMakerValue(4);
- expected1.updateLayerVisConfig({filled: true, stroked: true, strokeColor: strokeColor1});
- expected2.updateLayerVisConfig({filled: true, stroked: true, strokeColor: strokeColor2});
+ const [
+ layer1Color,
+ strokeColor1,
+ layer2Color,
+ strokeColor2
+ ] = getNextColorMakerValue(4);
+ expected1.updateLayerVisConfig({
+ filled: true,
+ stroked: true,
+ strokeColor: strokeColor1
+ });
+ expected2.updateLayerVisConfig({
+ filled: true,
+ stroked: true,
+ strokeColor: strokeColor2
+ });
const geojsonLayers = findDefaultLayer(
{fields, id: dataId, label, fieldPairs: [], allData: rows},
@@ -694,3 +707,102 @@ test('layerUtils -> findDefaultLayer:IconLayer', t => {
t.end();
});
+
+test('layerUtils -> findDefaultLayer: TripLayer', t => {
+ const stateWTrip = StateWTripGeojson;
+ t.equal(stateWTrip.visState.layers.length, 1, 'should find one layer');
+ const foundLayer = stateWTrip.visState.layers[0];
+
+ t.equal(foundLayer.type, 'trip', 'should find a trip layer');
+ t.deepEqual(
+ foundLayer.config.animation,
+ {enabled: true, domain: timeStampDomain},
+ 'should set correct animation domain'
+ );
+
+ t.deepEqual(
+ foundLayer.meta.bounds,
+ tripBounds,
+ 'should set correct bounds'
+ );
+
+ t.deepEqual(
+ foundLayer.meta.featureTypes,
+ {line: true},
+ 'should set correct bounds'
+ );
+
+ t.end();
+});
+
+test('layerUtils -> findDefaultLayer: TripLayer.1 -> no ts', t => {
+ // change 3rd coordinate to string
+ const modified = tripGeojson.features.map(f => ({
+ ...f,
+ geometry: {
+ ...f.geometry,
+ coordinates: f.geometry.coordinates.map(coord => ([...coord.slice(0, 3), 'hello']))
+ }
+ }));
+
+ const noTripGeojson = {
+ type: 'FeatureCollection',
+ features: modified
+ };
+
+ const dataset = createNewDataEntry({
+ info: {id: 'taro'},
+ data: processGeojson(noTripGeojson)
+ });
+
+ const layers = findDefaultLayer(
+ dataset.taro,
+ LayerClasses
+ );
+
+ t.equal(layers.length, 1, 'should find 1 layer');
+ const foundLayer = layers[0];
+ t.equal(foundLayer.type, 'geojson', 'should find a geojson layer');
+ t.end();
+});
+
+test('layerUtils -> findDefaultLayer: TripLayer.1 -> ts as string', t => {
+ const tripData = {
+ type: 'FeatureCollection',
+ features: [
+ {
+ type: 'Feature',
+ geometry: {
+ type: 'LineString',
+ coordinates: [
+ [-73.78966, 40.6429, 0, '2018-09-01 11:00'],
+ [-73.7895, 40.64267, 0, '2018-09-01 11:01'],
+ [-73.78923, 40.6424, 0, '2018-09-01 11:02'],
+ [-73.78905, 40.64222, 0, '2018-09-01 11:03']
+ ]
+ }
+ }
+ ]
+ };
+
+ const dataset = createNewDataEntry({
+ info: {id: 'taro'},
+ data: processGeojson(tripData)
+ });
+
+ const layers = findDefaultLayer(
+ dataset.taro,
+ LayerClasses
+ );
+
+ t.equal(layers.length, 1, 'should find 1 layer');
+ const foundLayer = layers[0];
+ t.equal(foundLayer.type, 'trip', 'should find a geojson layer');
+
+ t.deepEqual(
+ foundLayer.config.animation,
+ {enabled: true, domain: [1535799600000, 1535799780000]},
+ 'should set correct animation domain'
+ );
+ t.end();
+});
diff --git a/yarn.lock b/yarn.lock
index cb241d51d..94ecf6c6d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1056,10 +1056,6 @@
"@luma.gl/webgl2-polyfill" "7.2.0"
probe.gl "^3.0.2"
-"@mapbox/[email protected]":
- version "0.4.0"
- resolved "https://registry.yarnpkg.com/@mapbox/extent/-/extent-0.4.0.tgz#3e591f32e1f0c3981c864239f7b0ac06e610f8a9"
-
"@mapbox/geo-viewport@^0.2.2":
version "0.2.2"
resolved "https://registry.yarnpkg.com/@mapbox/geo-viewport/-/geo-viewport-0.2.2.tgz#93206c044238c21a60fca7e9064c8ce63e8027b4"
@@ -1072,22 +1068,6 @@
dependencies:
wgs84 "0.0.0"
-"@mapbox/[email protected]":
- version "0.0.0"
- resolved "https://registry.yarnpkg.com/@mapbox/geojson-coords/-/geojson-coords-0.0.0.tgz#4847a5b96059666e527a2139e75e35d84fd58f50"
- dependencies:
- "@mapbox/geojson-normalize" "0.0.1"
- geojson-flatten "~0.2.1"
-
-"@mapbox/geojson-extent@^0.3.2":
- version "0.3.2"
- resolved "https://registry.yarnpkg.com/@mapbox/geojson-extent/-/geojson-extent-0.3.2.tgz#a1bdb2015afd0e031c18c3f29f7eb229e4e1950f"
- dependencies:
- "@mapbox/extent" "0.4.0"
- "@mapbox/geojson-coords" "0.0.0"
- rw "~0.1.4"
- traverse "~0.6.6"
-
"@mapbox/[email protected]":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@mapbox/geojson-normalize/-/geojson-normalize-0.0.1.tgz#1da1e6b3a7add3ad29909b30f438f60581b7cd80"
@@ -1148,6 +1128,23 @@
probe.gl "3.0.3"
puppeteer "^1.16.0"
+"@turf/bbox@^6.0.1":
+ version "6.0.1"
+ resolved "https://registry.yarnpkg.com/@turf/bbox/-/bbox-6.0.1.tgz#b966075771475940ee1c16be2a12cf389e6e923a"
+ dependencies:
+ "@turf/helpers" "6.x"
+ "@turf/meta" "6.x"
+
+ version "6.1.4"
+ resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-6.1.4.tgz#d6fd7ebe6782dd9c87dca5559bda5c48ae4c3836"
+
+ version "6.0.2"
+ resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-6.0.2.tgz#eb92951126d24a613ac1b7b99d733fcc20fd30cf"
+ dependencies:
+ "@turf/helpers" "6.x"
+
"@types/events@*":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
@@ -4239,13 +4236,6 @@ gauge@~2.7.3:
strip-ansi "^3.0.1"
wide-align "^1.1.0"
-geojson-flatten@~0.2.1:
- version "0.2.4"
- resolved "https://registry.yarnpkg.com/geojson-flatten/-/geojson-flatten-0.2.4.tgz#8f3396f31a0f5b747e39c9e6a14088f43ba4ecfb"
- dependencies:
- get-stdin "^6.0.0"
- minimist "1.2.0"
-
geojson-vt@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/geojson-vt/-/geojson-vt-3.2.1.tgz#f8adb614d2c1d3f6ee7c4265cad4bbf3ad60c8b7"
@@ -8183,10 +8173,6 @@ rw@1, rw@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/rw/-/rw-1.3.3.tgz#3f862dfa91ab766b14885ef4d01124bfda074fb4"
-rw@~0.1.4:
- version "0.1.4"
- resolved "https://registry.yarnpkg.com/rw/-/rw-0.1.4.tgz#4903cbd80248ae0ede685bf58fd236a7a9b29a3e"
-
rxjs@^6.4.0:
version "6.5.3"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.3.tgz#510e26317f4db91a7eb1de77d9dd9ba0a4899a3a"
@@ -9198,10 +9184,6 @@ tr46@^1.0.1:
dependencies:
punycode "^2.1.0"
-traverse@~0.6.6:
- version "0.6.6"
- resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137"
-
trim-lines@^1.0.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/trim-lines/-/trim-lines-1.1.2.tgz#c8adbdbdae21bb5c2766240a661f693afe23e59b"