Skip to content

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

[feat] Effect manager - UI improvements (timezone, time slider, time dropdown) (#2433)

Igor Dykhtaee6f0754f1ed
diff --git a/src/components/src/common/icons/globe.tsx b/src/components/src/common/icons/globe.tsx
new file mode 100644
index 000000000..2e2bbfc40
--- /dev/null
+++ b/src/components/src/common/icons/globe.tsx
@@ -0,0 +1,30 @@
+import React, {Component} from 'react';
+import PropTypes from 'prop-types';
+import Base, {BaseProps} from './base';
+
+export default class Globe extends Component<Partial<BaseProps>> {
+ static propTypes = {
+ /** Set the height of the icon, ex. '16px' */
+ height: PropTypes.string
+ };
+
+ static defaultProps = {
+ height: '16px',
+ viewBox: '0 0 16 16',
+ predefinedClassName: 'data-ex-icons-globe'
+ };
+
+ render() {
+ return (
+ <Base {...this.props}>
+ <svg width="16" height="17" viewBox="0 0 16 17" xmlns="http://www.w3.org/2000/svg">
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M6.38584 1.68702C6.90402 1.56472 7.44445 1.5 8 1.5C9.23055 1.5 10.3869 1.81752 11.3917 2.37511C12.4112 2.94093 13.2749 3.75396 13.9013 4.73321C14.4377 5.5719 14.6851 6.188 14.7456 6.62353C14.9114 7.22072 15 7.85001 15 8.5C15 10.527 14.1385 12.3527 12.7616 13.631C11.9832 14.3623 10.9811 14.9754 9.75268 15.2788C9.19254 15.4232 8.60524 15.5 8 15.5C4.63461 15.5 1.82391 13.1251 1.15243 9.95976C1.05442 9.54484 1 9.06056 1 8.5C1 8.49999 1 8.50001 1 8.5C1 5.19522 3.29014 2.42529 6.36999 1.69074C6.37528 1.68948 6.38056 1.68824 6.38584 1.68702ZM14 8.5C14 9.08044 13.9176 9.64163 13.7638 10.1725C12.755 9.00544 10.8189 8.33275 9.51221 8.62684C7.80468 9.01112 7.72976 10.9923 8.46642 12.0631C8.83704 12.6018 8.91074 13.1143 8.98743 13.6476C9.02242 13.891 9.05804 14.1387 9.12278 14.3951C8.75907 14.464 8.38374 14.5 8 14.5C6.01503 14.5 4.2552 13.5361 3.16302 12.0508C3.96089 12.1461 4.82827 11.8298 5.48008 11.2844C6.69976 10.2638 6.57435 9.20516 6.44788 8.13751C6.40898 7.80916 6.36999 7.47997 6.36999 7.15077C6.36999 6.39461 6.69305 5.95645 7.06097 5.45747C7.37404 5.03287 7.71959 4.56422 7.92621 3.81811C8.07377 3.28525 8.08049 2.84344 7.9823 2.50003C7.9882 2.50001 7.9941 2.5 8 2.5C8.67572 2.5 9.32534 2.6117 9.93142 2.81764C9.29673 3.3956 9.1115 4.40569 9.43855 5.14271C9.79682 5.95012 10.3908 6.13003 10.9903 6.31161C11.2417 6.38774 11.494 6.46415 11.7303 6.58722C12.5302 7.00383 13.1339 7.29592 13.9013 7.47784L13.9138 7.48073C13.9705 7.81201 14 8.15256 14 8.5ZM6.62925 2.65729C6.77252 2.62674 6.8659 2.63612 6.91413 2.64841C6.95864 2.65974 6.97132 2.67386 6.97807 2.68199C6.98858 2.69464 7.1408 2.9073 6.96248 3.55123C6.80646 4.11462 6.56084 4.44896 6.24765 4.87526L6.17228 4.97803C5.80911 5.47481 5.36999 6.12055 5.36999 7.15077C5.36999 7.54169 5.41575 7.92659 5.45353 8.24443L5.46209 8.31662C5.50393 8.67118 5.53234 8.9484 5.52363 9.2086C5.50906 9.64448 5.39669 10.0503 4.83835 10.5175C4.22693 11.0291 3.48249 11.1744 2.9997 10.9895C2.7365 10.8887 2.35103 10.6037 2.14406 9.81283C2.04975 9.3903 2 8.95096 2 8.5C2 8.49353 2.00001 8.48706 2.00003 8.48059C2.00034 8.38358 2.00295 8.28711 2.00781 8.19124C2.1449 5.48676 4.07275 3.25474 6.62925 2.65729ZM13.3119 11.2912C13.0234 11.834 12.6167 12.3926 12.0926 12.8876C11.5179 13.4239 10.8378 13.8485 10.0867 14.1272C10.0403 13.9356 10.0098 13.7315 9.97582 13.4953L9.97119 13.4631C9.89588 12.9383 9.79404 12.2285 9.29027 11.4963C9.07472 11.183 8.96775 10.6974 9.05201 10.2901C9.12368 9.94368 9.31182 9.69695 9.73177 9.60244C10.2869 9.47751 11.1638 9.61414 11.9811 10.0425C12.6583 10.3974 13.1122 10.8535 13.3119 11.2912ZM11.1022 3.36315C12.235 4.04873 13.1228 5.09845 13.6033 6.35005C13.1774 6.20083 12.7565 5.99418 12.1922 5.70029C11.9064 5.55147 11.6211 5.45906 11.4003 5.39112C11.351 5.37595 11.3054 5.36211 11.2629 5.34919C11.0939 5.29784 10.9724 5.26095 10.8505 5.21158C10.622 5.11901 10.4782 5.02021 10.3526 4.73711C10.2389 4.48099 10.2524 4.0818 10.4376 3.76614C10.5684 3.5432 10.7707 3.37786 11.1022 3.36315Z"
+ />
+ </svg>
+ </Base>
+ );
+ }
+}
diff --git a/src/components/src/common/icons/index.tsx b/src/components/src/common/icons/index.tsx
index dafb7d662..f2e3b806b 100644
--- a/src/components/src/common/icons/index.tsx
+++ b/src/components/src/common/icons/index.tsx
@@ -99,6 +99,11 @@ export {default as CursorPoint} from './cursor-point';
export {default as Pin} from './pin';
export {default as Calendar} from './calendar';
export {default as LocationMarker} from './location-marker';
+export {default as Globe} from './globe';
+export {default as Sun} from './sun';
+export {default as Sunrise} from './sunrise';
+export {default as Sunset} from './sunset';
+export {default as Moon} from './moon';
export {default as ArrowDownSmall} from './arrow-down-small';
export {default as MagicWand} from './effects/magic-wand';
export {default as LightAndShadowEffectIcon} from './effects/light-and-shadow';
diff --git a/src/components/src/common/icons/moon.tsx b/src/components/src/common/icons/moon.tsx
new file mode 100644
index 000000000..dc8059a74
--- /dev/null
+++ b/src/components/src/common/icons/moon.tsx
@@ -0,0 +1,33 @@
+import React, {Component} from 'react';
+import PropTypes from 'prop-types';
+import Base from './base';
+
+export default class Moon extends Component {
+ static propTypes = {
+ /** Set the height of the icon, ex. '16px' */
+ height: PropTypes.string
+ };
+
+ static defaultProps = {
+ height: '16px',
+ viewBox: '0 0 16 16',
+ predefinedClassName: 'data-ex-icons-moon'
+ };
+
+ render() {
+ return (
+ <Base {...this.props}>
+ <svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
+ <g clipPath="url(#clip0_85_57878)">
+ <path d="M6.75138 2.7068C6.52216 3.68541 6.49097 4.69999 6.65965 5.69083C6.82833 6.68168 7.19347 7.62878 7.73358 8.47643C8.2737 9.32407 8.97788 10.0551 9.80471 10.6266C10.6315 11.1981 11.5643 11.5984 12.5481 11.8041C12.0309 12.3392 11.4113 12.765 10.7264 13.0561C10.0414 13.3472 9.30494 13.4977 8.56068 13.4987C8.49143 13.4987 8.42158 13.5013 8.35178 13.4987C7.05611 13.4529 5.81743 12.9547 4.85087 12.0906C3.88431 11.2265 3.25093 10.0512 3.06075 8.76875C2.87057 7.48629 3.13559 6.17773 3.80979 5.07034C4.48399 3.96295 5.52478 3.12669 6.75138 2.7068ZM7.49013 1.5C7.46086 1.50005 7.43165 1.50266 7.40283 1.5078C5.81071 1.79059 4.37954 2.65251 3.38498 3.92753C2.39042 5.20254 1.90282 6.80048 2.0161 8.41355C2.12938 10.0266 2.83552 11.5407 3.99852 12.6642C5.16152 13.7877 6.69911 14.4412 8.31513 14.4986C8.39718 14.5016 8.47923 14.4986 8.56058 14.4986C9.60999 14.4992 10.6441 14.2471 11.5755 13.7636C12.5069 13.2801 13.3082 12.5794 13.9116 11.7208C13.9605 11.6469 13.9891 11.5613 13.9944 11.4728C13.9997 11.3842 13.9816 11.2958 13.9419 11.2165C13.9022 11.1372 13.8423 11.0698 13.7682 11.021C13.6941 10.9722 13.6085 10.9438 13.5199 10.9386C12.521 10.851 11.5556 10.5349 10.6984 10.0146C9.84118 9.49439 9.11506 8.784 8.57617 7.93837C8.03728 7.09274 7.70006 6.13452 7.59057 5.13777C7.48108 4.14102 7.60226 3.13245 7.94473 2.19C7.97387 2.1146 7.98457 2.03332 7.97594 1.95295C7.96731 1.87257 7.93961 1.79542 7.89514 1.72792C7.85066 1.66042 7.79071 1.60452 7.72026 1.56487C7.64981 1.52523 7.57091 1.50299 7.49013 1.5Z" />
+ </g>
+ <defs>
+ <clipPath id="clip0_85_57878">
+ <rect width="16" height="16" />
+ </clipPath>
+ </defs>
+ </svg>
+ </Base>
+ );
+ }
+}
diff --git a/src/components/src/common/icons/sun.tsx b/src/components/src/common/icons/sun.tsx
new file mode 100644
index 000000000..103454920
--- /dev/null
+++ b/src/components/src/common/icons/sun.tsx
@@ -0,0 +1,41 @@
+import React, {Component} from 'react';
+import PropTypes from 'prop-types';
+import Base from './base';
+
+export default class Sun extends Component {
+ static propTypes = {
+ /** Set the height of the icon, ex. '16px' */
+ height: PropTypes.string
+ };
+
+ static defaultProps = {
+ height: '16px',
+ viewBox: '0 0 16 16',
+ predefinedClassName: 'data-ex-icons-sun'
+ };
+
+ render() {
+ return (
+ <Base {...this.props}>
+ <svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
+ <g clipPath="url(#clip0_85_57860)">
+ <path d="M8 6.00244C8.39556 6.00244 8.78224 6.11974 9.11114 6.3395C9.44004 6.55927 9.69639 6.87162 9.84776 7.23707C9.99914 7.60253 10.0387 8.00466 9.96157 8.39262C9.8844 8.78058 9.69392 9.13695 9.41421 9.41665C9.13451 9.69636 8.77814 9.88684 8.39018 9.96401C8.00222 10.0412 7.60009 10.0016 7.23463 9.8502C6.86918 9.69883 6.55683 9.44248 6.33706 9.11358C6.1173 8.78468 6 8.398 6 8.00244C6.0006 7.47219 6.2115 6.96383 6.58645 6.58889C6.96139 6.21394 7.46975 6.00304 8 6.00244ZM8 5.00244C7.40666 5.00244 6.82664 5.17839 6.33329 5.50803C5.83994 5.83768 5.45543 6.30621 5.22836 6.85439C5.0013 7.40257 4.94189 8.00577 5.05765 8.58771C5.1734 9.16966 5.45912 9.7042 5.87868 10.1238C6.29824 10.5433 6.83279 10.829 7.41473 10.9448C7.99667 11.0606 8.59987 11.0011 9.14805 10.7741C9.69623 10.547 10.1648 10.1625 10.4944 9.66915C10.8241 9.1758 11 8.59579 11 8.00244C11 7.20679 10.6839 6.44373 10.1213 5.88112C9.55871 5.31851 8.79565 5.00244 8 5.00244Z" />
+ <path d="M3.40381 2.69921L2.69678 3.40625L4.4497 5.15917L5.15673 4.45213L3.40381 2.69921Z" />
+ <path d="M3.5 7.50244H1V8.50244H3.5V7.50244Z" />
+ <path d="M4.4497 10.8457L2.69678 12.5986L3.40381 13.3057L5.15673 11.5528L4.4497 10.8457Z" />
+ <path d="M8.5 12.5024H7.5V15.0024H8.5V12.5024Z" />
+ <path d="M11.5503 10.8457L10.8433 11.5527L12.5962 13.3057L13.3032 12.5986L11.5503 10.8457Z" />
+ <path d="M15 7.50244H12.5V8.50244H15V7.50244Z" />
+ <path d="M12.5962 2.69923L10.8433 4.45215L11.5503 5.15918L13.3032 3.40627L12.5962 2.69923Z" />
+ <path d="M8.5 1.00244H7.5V3.50244H8.5V1.00244Z" />
+ </g>
+ <defs>
+ <clipPath id="clip0_85_57860">
+ <rect width="16" height="16" />
+ </clipPath>
+ </defs>
+ </svg>
+ </Base>
+ );
+ }
+}
diff --git a/src/components/src/common/icons/sunrise.tsx b/src/components/src/common/icons/sunrise.tsx
new file mode 100644
index 000000000..726d63e68
--- /dev/null
+++ b/src/components/src/common/icons/sunrise.tsx
@@ -0,0 +1,39 @@
+import React, {Component} from 'react';
+import PropTypes from 'prop-types';
+import Base from './base';
+
+export default class Sunrise extends Component {
+ static propTypes = {
+ /** Set the height of the icon, ex. '12px' */
+ height: PropTypes.string
+ };
+
+ static defaultProps = {
+ height: '12px',
+ viewBox: '0 0 12 12',
+ predefinedClassName: 'data-ex-icons-sunrise'
+ };
+
+ render() {
+ return (
+ <Base {...this.props}>
+ <svg width="12" height="12" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
+ <g clipPath="url(#clip0_85_57889)">
+ <path d="M11.2494 10.125H0.75V10.875H11.2494V10.125Z" />
+ <path d="M6 7.5C6.39769 7.50045 6.77896 7.65863 7.06017 7.93983C7.34137 8.22104 7.49955 8.60231 7.5 9H8.25C8.25 8.40326 8.01295 7.83097 7.59099 7.40901C7.16903 6.98705 6.59674 6.75 6 6.75C5.40326 6.75 4.83097 6.98705 4.40901 7.40901C3.98705 7.83097 3.75 8.40326 3.75 9H4.5C4.50045 8.60231 4.65863 8.22104 4.93983 7.93983C5.22104 7.65863 5.60231 7.50045 6 7.5Z" />
+ <path d="M11.25 8.25H9.375V9H11.25V8.25Z" />
+ <path d="M9.44701 5.02259L8.13232 6.33728L8.6626 6.86756L9.97729 5.55287L9.44701 5.02259Z" />
+ <path d="M6 1.5L4.125 3.375L4.65375 3.90375L5.625 2.93625V3V5.625H6.375V3V2.93625L7.34625 3.90375L7.875 3.375L6 1.5Z" />
+ <path d="M2.55274 5.02258L2.02246 5.55286L3.33715 6.86754L3.86743 6.33727L2.55274 5.02258Z" />
+ <path d="M2.625 8.25H0.75V9H2.625V8.25Z" />
+ </g>
+ <defs>
+ <clipPath id="clip0_85_57889">
+ <rect width="12" height="12" />
+ </clipPath>
+ </defs>
+ </svg>
+ </Base>
+ );
+ }
+}
diff --git a/src/components/src/common/icons/sunset.tsx b/src/components/src/common/icons/sunset.tsx
new file mode 100644
index 000000000..4c53d2fd6
--- /dev/null
+++ b/src/components/src/common/icons/sunset.tsx
@@ -0,0 +1,39 @@
+import React, {Component} from 'react';
+import PropTypes from 'prop-types';
+import Base from './base';
+
+export default class Sunset extends Component {
+ static propTypes = {
+ /** Set the height of the icon, ex. '12px' */
+ height: PropTypes.string
+ };
+
+ static defaultProps = {
+ height: '12px',
+ viewBox: '0 0 12 12',
+ predefinedClassName: 'data-ex-icons-sunset'
+ };
+
+ render() {
+ return (
+ <Base {...this.props}>
+ <svg width="12" height="12" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
+ <g clipPath="url(#clip0_85_57899)">
+ <path d="M11.2494 10.1268H0.75V10.8768H11.2494V10.1268Z" />
+ <path d="M6 7.50183C6.39769 7.50228 6.77896 7.66046 7.06017 7.94166C7.34137 8.22287 7.49955 8.60414 7.5 9.00183H8.25C8.25 8.40509 8.01295 7.8328 7.59099 7.41084C7.16903 6.98888 6.59674 6.75183 6 6.75183C5.40326 6.75183 4.83097 6.98888 4.40901 7.41084C3.98705 7.8328 3.75 8.40509 3.75 9.00183H4.5C4.50045 8.60414 4.65863 8.22287 4.93983 7.94166C5.22104 7.66046 5.60231 7.50228 6 7.50183Z" />
+ <path d="M11.25 8.25183H9.375V9.00183H11.25V8.25183Z" />
+ <path d="M9.44701 5.02442L8.13232 6.33911L8.6626 6.86939L9.97729 5.5547L9.44701 5.02442Z" />
+ <path d="M7.34625 3.59808L6.375 4.56558V1.50183H5.625V4.56558L4.65375 3.59808L4.125 4.12683L6 6.00183L7.875 4.12683L7.34625 3.59808Z" />
+ <path d="M2.55274 5.02441L2.02246 5.55469L3.33715 6.86938L3.86743 6.3391L2.55274 5.02441Z" />
+ <path d="M2.625 8.25183H0.75V9.00183H2.625V8.25183Z" />
+ </g>
+ <defs>
+ <clipPath id="clip0_85_57899">
+ <rect width="12" height="12" />
+ </clipPath>
+ </defs>
+ </svg>
+ </Base>
+ );
+ }
+}
diff --git a/src/components/src/common/item-selector/item-selector.tsx b/src/components/src/common/item-selector/item-selector.tsx
index 6b1330d39..6c4a074bd 100644
--- a/src/components/src/common/item-selector/item-selector.tsx
+++ b/src/components/src/common/item-selector/item-selector.tsx
@@ -143,6 +143,7 @@ export type ItemSelectorProps = {
isError?: boolean;
multiSelect?: boolean;
inputTheme?: string;
+ onOpen?: () => void;
size?: string;
onBlur?: () => void;
placeholder?: string;
@@ -269,6 +270,9 @@ class ItemSelectorUnmemoized extends Component<ItemSelectorProps> {
_showTypeahead: MouseEventHandler = e => {
e.stopPropagation();
if (!this.props.disabled) {
+ if (this.props.onOpen) {
+ this.props.onOpen();
+ }
this.setState({
showTypeahead: true
});
diff --git a/src/components/src/common/styled-components.tsx b/src/components/src/common/styled-components.tsx
index 0b87c5aad..c7a7812ab 100644
--- a/src/components/src/common/styled-components.tsx
+++ b/src/components/src/common/styled-components.tsx
@@ -831,6 +831,7 @@ export const StyledTimePicker = styled(TimePicker)`
color: ${props => props.theme.effectPanelTextMain};
font-family: ${props => props.theme.fontFamily};
font-size: ${props => props.theme.inputFontSize};
+ font-weight: 400;
}
.react-time-picker__inputGroup__input {
min-width: 0.54em;
@@ -864,6 +865,7 @@ export const StyledTimePicker = styled(TimePicker)`
.react-time-picker__inputGroup__amPm {
max-width: 37px;
font: inherit;
+ font-weight: 400;
-webkit-appearance: menulist;
-moz-appearance: menulist;
appearance: menulist;
@@ -901,15 +903,11 @@ export const StyledDatePicker = styled(DatePicker)`
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
- .react-date-picker--disabled {
- background-color: #f0f0f0;
- color: #6d6d6d;
- }
.react-date-picker__wrapper {
display: flex;
flex-grow: 1;
flex-shrink: 0;
- width: 110px;
+ width: 108px;
white-space: nowrap;
border-radius: 4px;
}
@@ -922,7 +920,8 @@ export const StyledDatePicker = styled(DatePicker)`
display: flex;
justify-content: end;
align-items: center;
- height: 24px;
+ height: 22px;
+ border: 1px solid ${props => props.theme.inputBgd};
border-radius: 4px;
}
@@ -975,6 +974,7 @@ export const StyledDatePicker = styled(DatePicker)`
max-width: 100vw;
z-index: 11;
color: ${props => props.theme.effectPanelTextSecondary1};
+ inset: auto !important;
}
.react-date-picker__calendar--closed {
display: none;
diff --git a/src/components/src/effects/effect-configurator.tsx b/src/components/src/effects/effect-configurator.tsx
index 3781f6951..5aac5ec00 100644
--- a/src/components/src/effects/effect-configurator.tsx
+++ b/src/components/src/effects/effect-configurator.tsx
@@ -170,17 +170,14 @@ export default function EffectConfiguratorFactory(
});
}, [effect.id, parameters, updateEffectConfig]);
- const onDateTimeChange = useCallback(
- value => {
- updateEffectConfig(null, effect.id, {parameters: {timestamp: value}});
- },
- [effect.id, updateEffectConfig]
- );
-
- const onTimeModeChange = useCallback(
- value => {
+ const onTimeParametersChanged = useCallback(
+ parameters => {
updateEffectConfig(null, effect.id, {
- parameters: {timeMode: value}
+ parameters: {
+ ...(parameters.timestamp ? {timestamp: parameters.timestamp} : null),
+ ...(parameters.timezone ? {timezone: parameters.timezone} : null),
+ ...(parameters.timeMode ? {timeMode: parameters.timeMode} : null)
+ }
});
},
[effect.id, updateEffectConfig]
@@ -207,9 +204,9 @@ export default function EffectConfiguratorFactory(
</PanelLabelWrapper>
<EffectTimeConfigurator
timestamp={parameters.timestamp}
- onDateTimeChange={onDateTimeChange}
+ timezone={parameters.timezone}
timeMode={parameters.timeMode}
- onTimeModeChange={onTimeModeChange}
+ onChange={onTimeParametersChanged}
/>
<StyledVerticalSeparator />
diff --git a/src/components/src/effects/effect-list.tsx b/src/components/src/effects/effect-list.tsx
index c49f88b8f..f884eb2ce 100644
--- a/src/components/src/effects/effect-list.tsx
+++ b/src/components/src/effects/effect-list.tsx
@@ -28,6 +28,7 @@ const SortableStyledItem = styled.div<SortableStyledItemProps>`
z-index: ${props => props.theme.dropdownWrapperZ + 1};
transition: ${props => props.transition};
transform: ${props => props.transform};
+ outline: none;
&.sorting {
opacity: 0.3;
pointer-events: none;
diff --git a/src/components/src/effects/effect-manager.tsx b/src/components/src/effects/effect-manager.tsx
index b6eecaec7..5ac46b580 100644
--- a/src/components/src/effects/effect-manager.tsx
+++ b/src/components/src/effects/effect-manager.tsx
@@ -1,4 +1,4 @@
-import React, {useMemo, useCallback} from 'react';
+import React, {useMemo, useState, useCallback} from 'react';
import styled from 'styled-components';
import {injectIntl, IntlShape} from 'react-intl';
@@ -52,9 +52,12 @@ const StyledEffectPanelHeader = styled.div`
min-width: ${({theme}) => theme.effectPanelWidth}px;
`;
-const StyledEffectPanelContent = styled.div`
+type StyledEffectPanelContentProps = {
+ extended?: boolean;
+};
+const StyledEffectPanelContent = styled.div<StyledEffectPanelContentProps>`
${props => props.theme.sidePanelScrollBar};
- padding: 10px 0;
+ padding: ${props => (props.extended ? '32px' : '10px')};
overflow: overlay;
display: flex;
flex-direction: column;
@@ -70,6 +73,8 @@ function EffectManagerFactory(
const EffectManager = (props: EffectManagerWithIntlProp & EffectManagerState) => {
const {intl, visStateActions, effects, effectOrder, children} = props;
+ const [typeSelectorOpened, setTypeSelectorOpened] = useState(false);
+
// Prevent shadow effect from being added multiple times
const effectOptions = useMemo(() => {
const hasShadow = effects.some(effect => {
@@ -88,6 +93,14 @@ function EffectManagerFactory(
visStateActions.addEffect({type});
}, []);
+ const onTypeSelectOpen = useCallback(() => {
+ setTypeSelectorOpened(true);
+ }, []);
+
+ const onTypeSelectClose = useCallback(() => {
+ setTypeSelectorOpened(false);
+ }, []);
+
return (
<StyledEffectPanelContainer className="effect-manager">
<StyledEffectPanel>
@@ -96,11 +109,16 @@ function EffectManagerFactory(
className="effect-manager-title"
title={intl.formatMessage({id: 'effectManager.effects'})}
>
- <EffectTypeSelector options={effectOptions} onSelect={onAddEffect} />
+ <EffectTypeSelector
+ options={effectOptions}
+ onSelect={onAddEffect}
+ onOpen={onTypeSelectOpen}
+ onBlur={onTypeSelectClose}
+ />
</SidePanelTitle>
</StyledEffectPanelHeader>
- <StyledEffectPanelContent>
+ <StyledEffectPanelContent extended={typeSelectorOpened && effects.length === 0}>
<EffectList
effects={effects}
effectOrder={effectOrder}
diff --git a/src/components/src/effects/effect-panel-header.tsx b/src/components/src/effects/effect-panel-header.tsx
index 9165b7413..bac64930d 100644
--- a/src/components/src/effects/effect-panel-header.tsx
+++ b/src/components/src/effects/effect-panel-header.tsx
@@ -8,9 +8,10 @@ import {
POSTPROCESSING_EFFECTS
} from '@kepler.gl/constants';
-import PanelHeaderActionFactory from '../side-panel/panel-header-action';
+import PanelHeaderActionFactory, {PanelHeaderActionIcon} from '../side-panel/panel-header-action';
import {
ArrowDown,
+ ArrowUp,
EyeSeen,
EyeUnseen,
Trash,
@@ -35,6 +36,16 @@ import {
} from '../common/icons';
import {StyledPanelHeader} from '../common/styled-components';
+export type ActionItem = {
+ key: string;
+ isHidden?: boolean;
+ tooltip: string;
+ classNames?: Record<string, boolean>;
+ icon: PanelHeaderActionIcon;
+ tooltipType?: 'error';
+ onClick: () => void;
+};
+
export type EffectPanelHeaderProps = {
type: string;
listeners: any;
@@ -52,14 +63,9 @@ export type EffectPanelHeaderProps = {
visible: React.ComponentType<Partial<BaseProps>>;
hidden: React.ComponentType<Partial<BaseProps>>;
enableConfig: React.ComponentType<Partial<BaseProps>>;
+ disableConfig: React.ComponentType<Partial<BaseProps>>;
};
- actionItems?: {
- key: string;
- isHidden?: boolean;
- tooltip: string;
- classNames?: Record<string, boolean>;
- icon: React.ElementType;
- }[];
+ actionItems?: ActionItem[];
};
export const defaultProps = {
@@ -70,7 +76,8 @@ const defaultActionIcons = {
remove: Trash,
visible: EyeSeen,
hidden: EyeUnseen,
- enableConfig: ArrowDown
+ enableConfig: ArrowDown,
+ disableConfig: ArrowUp
};
const defaultEffectIcons = {
@@ -185,13 +192,14 @@ export function EffectPanelHeaderActionSectionFactory(
actionIcons = defaultActionIcons
} = props;
- const effectActionItems = useMemo(
+ const effectActionItems: ActionItem[] = useMemo(
() =>
actionItems ?? [
{
key: 'remove-effect',
isHidden: true,
tooltip: 'tooltip.removeEffect',
+ tooltipType: 'error',
onClick: onRemoveEffect,
icon: actionIcons.remove
},
@@ -216,9 +224,8 @@ export function EffectPanelHeaderActionSectionFactory(
<HeaderActionSection className="effect-panel__header__actions">
<StyledPanelHeaderHiddenActions isConfigActive={isConfigActive}>
{effectActionItems
- // @ts-expect-error typed in follow up
- .filter(item => Boolean(item.isHidden))
- .map((item, i) => (
+ .filter((item: ActionItem) => Boolean(item.isHidden))
+ .map((item: ActionItem, i) => (
<PanelHeaderAction
key={item.key}
className={`effect__${item.key}`}
@@ -226,15 +233,14 @@ export function EffectPanelHeaderActionSectionFactory(
id={effectId}
tooltip={item.tooltip}
onClick={item.onClick}
- tooltipType="error"
+ tooltipType={item.tooltipType}
IconComponent={item.icon}
/>
))}
</StyledPanelHeaderHiddenActions>
{effectActionItems
- // @ts-expect-error typed in follow up
- .filter(item => !item.isHidden)
- .map((item, i) => (
+ .filter((item: ActionItem) => !item.isHidden)
+ .map((item: ActionItem, i) => (
<PanelHeaderAction
key={item.key}
className={classnames(`effect__${item.key}`, item.classNames)}
@@ -242,7 +248,7 @@ export function EffectPanelHeaderActionSectionFactory(
id={effectId}
tooltip={item.tooltip}
onClick={item.onClick}
- tooltipType="error"
+ tooltipType={item.tooltipType}
IconComponent={item.icon}
/>
))}
diff --git a/src/components/src/effects/effect-panel.tsx b/src/components/src/effects/effect-panel.tsx
index f34892bfd..919eb47d7 100644
--- a/src/components/src/effects/effect-panel.tsx
+++ b/src/components/src/effects/effect-panel.tsx
@@ -30,12 +30,12 @@ export type PanelWrapperProps = {
const PanelWrapper = styled.div<PanelWrapperProps>`
font-size: 12px;
border-radius: 1px;
- margin-bottom: 8px;
z-index: 1000;
&.dragging {
cursor: move;
}
- margin: 3px 25px;
+ margin: 3px auto 3px 25px;
+ max-width: 275px;
`;
EffectPanelFactory.deps = [EffectPanelHeaderFactory, EffectConfiguratorFactory];
diff --git a/src/components/src/effects/effect-time-configurator.tsx b/src/components/src/effects/effect-time-configurator.tsx
index 7bfb3ffba..efbc90294 100644
--- a/src/components/src/effects/effect-time-configurator.tsx
+++ b/src/components/src/effects/effect-time-configurator.tsx
@@ -1,27 +1,39 @@
import React, {useCallback, useMemo} from 'react';
import {injectIntl, IntlShape} from 'react-intl';
import styled from 'styled-components';
+import moment from 'moment-timezone';
+import SunCalc from 'suncalc';
+import {MapState} from '@kepler.gl/types';
import {FormattedMessage} from '@kepler.gl/localization';
import {clamp} from '@kepler.gl/utils';
import {
LIGHT_AND_SHADOW_EFFECT_TIME_MODES,
- LightAndShadowEffectTimeMode
+ LightAndShadowEffectTimeMode,
+ DEFAULT_TIMEZONE
} from '@kepler.gl/constants';
+import {mapStateLens} from '@kepler.gl/reducers';
-import {StyledTimePicker, StyledDatePicker, Tooltip} from '../common/styled-components';
-import RangeSliderFactory from '../common/range-slider';
+import {withState} from '../injector';
+import {StyledDatePicker as DatePicker, Tooltip} from '../common/styled-components';
import Checkbox from '../common/checkbox';
import Button from '../common/data-table/button';
-import {LocationMarker, Calendar, Clock} from '../common/icons';
+import {LocationMarker, Calendar, Clock, Globe} from '../common/icons';
+import TimezoneSelectorFactory from './timezone-selector';
+import EffectTimeSliderFactory from './effect-time-slider';
+import EffectTimeSelectorFactory from './effect-time-selector';
-const DAY_SLIDER_RANGE = 1000 * 60 * 60 * 24;
+const DAY_MILISECONDS = 1000 * 60 * 60 * 24;
export type EffectTimeConfiguratorProps = {
- timestamp: string;
- onDateTimeChange: (time: number) => void;
+ timestamp: number;
+ timezone: string;
timeMode: LightAndShadowEffectTimeMode;
- onTimeModeChange: (newMode: LightAndShadowEffectTimeMode) => void;
+ onChange: (parameters: {
+ timestamp?: number | null;
+ timezone?: string;
+ timeMode?: LightAndShadowEffectTimeMode;
+ }) => void;
};
type StyledWrapperProps = {disabled?: boolean; marginBottom?: number};
@@ -36,20 +48,8 @@ const StyledWrapper = styled.div<StyledWrapperProps>`
type SliderWrapperProps = {disabled?: boolean};
const SliderWrapper = styled.div<SliderWrapperProps>`
margin-top: 13px;
- margin-bottom: 17px;
+ margin-bottom: 12px;
${props => (props.hidden ? 'display: none;' : '')}
-
- .kg-range-slider__input {
- height: 32px;
- text-align: center;
- padding: 3px 6px;
- }
- .kg-slider {
- padding-left: 6px;
- }
- .kg-range-slider {
- padding: 0px !important;
- }
`;
const StyledButton = styled(Button)`
@@ -88,8 +88,36 @@ const StyledEffectTimeConfigurator = styled.div`
margin-top: 3px;
`;
-const WithIconWrapper = styled.div`
+const StyledDatePicker = styled.div`
+ .react-date-picker--open .react-date-picker__wrapper .react-date-picker__inputGroup {
+ border: 1px solid ${props => props.theme.activeColor};
+ border-radius: 4px 4px 0px 0px !important;
+ }
+ .react-calendar__navigation__prev2-button,
+ .react-calendar__navigation__next2-button {
+ display: none;
+ }
+ .react-calendar__navigation__label {
+ position: absolute;
+ top: 20px;
+ }
+ .react-calendar__navigation__arrow {
+ position: absolute;
+ top: 18px;
+ font-size: 16px;
+ }
+ .react-calendar__navigation__prev-button {
+ right: 36px;
+ }
+ .react-calendar__navigation__next-button {
+ right: 12px;
+ }
+`;
+
+type WithIconWrapperProps = {width?: string};
+const WithIconWrapper = styled.div<WithIconWrapperProps>`
position: relative;
+ ${props => (props.width ? 'width: ' + props.width : '')}
`;
const StyledExtraIcon = styled.div`
@@ -103,7 +131,7 @@ const StyledExtraIcon = styled.div`
`;
type TextBlockProps = {
- width: string;
+ width?: string;
};
const TextBlock = styled.div<TextBlockProps>`
color: ${props => props.theme.effectPanelTextSecondary2};
@@ -111,71 +139,137 @@ const TextBlock = styled.div<TextBlockProps>`
font-size: ${props => props.theme.inputFontSize};
`;
-EffectTimeConfiguratorFactory.deps = [RangeSliderFactory];
+/**
+ * Converts date, time and timezone into a UTC timestamp.
+ * @param dateStr Date string in YYYY-MM-DD format.
+ * @param timeStr Time string in HH:MM format.
+ * @param timezone Timezone name.
+ * @returns Timestamp or null if case of bad inputs.
+ */
+const getTimestamp = (dateStr: string, timeStr: string, timezone: string): number | null => {
+ let timestamp: number | null = null;
+ const curr = moment.tz(`${dateStr}T${timeStr}:00`, timezone);
+ if (curr.isValid()) {
+ timestamp = curr.utc().valueOf();
+ }
+ return timestamp;
+};
+
+/**
+ * Converts time of the day into [0, 1] range
+ * @param date
+ * @returns
+ */
+const getDayRatio = (date: moment.Moment) => {
+ return ((date.hours() * 60 + date.minutes()) * 60 * 1000) / DAY_MILISECONDS;
+};
+
+EffectTimeConfiguratorFactory.deps = [
+ TimezoneSelectorFactory,
+ EffectTimeSliderFactory,
+ EffectTimeSelectorFactory
+];
export default function EffectTimeConfiguratorFactory(
- RangeSlider: ReturnType<typeof RangeSliderFactory>
+ TimezoneSelector: ReturnType<typeof TimezoneSelectorFactory>,
+ EffectTimeSlider: ReturnType<typeof EffectTimeSliderFactory>,
+ EffectTimeSelector: ReturnType<typeof EffectTimeSelectorFactory>
): React.FC<EffectTimeConfiguratorProps> {
const EffectTimeConfigurator = ({
timestamp,
- onDateTimeChange,
+ timezone: _timezone,
timeMode,
- onTimeModeChange,
+ onChange: onTimeParametersChanged,
+ mapState,
intl
- }: EffectTimeConfiguratorProps & {intl: IntlShape}) => {
- const [dateOnly, selectedTimeString] = useMemo(() => {
- const date = new Date(timestamp);
+ }: EffectTimeConfiguratorProps & {intl: IntlShape; mapState: MapState}) => {
+ const timezone = useMemo(() => {
+ return moment.tz.names().includes(_timezone) ? _timezone : DEFAULT_TIMEZONE;
+ }, [_timezone]);
+
+ const [
+ datePickerDate,
+ fullDate,
+ formattedTime,
+ formattedDate,
+ dayTimeProgress
+ ] = useMemo(() => {
+ const currentMoment = moment.tz(timestamp, timezone);
+
+ // Slider value from 0 to 1
+ const dayProgress = getDayRatio(currentMoment);
- const h = date.getUTCHours();
- const m = date.getUTCMinutes();
- const timeString = `${h < 10 ? `0${h}` : `${h}`}:${m < 10 ? `0${m}` : `${m}`}`;
+ // Date picker always renders Date in local timezone
+ const date = new Date();
+ date.setFullYear(currentMoment.year(), currentMoment.month(), currentMoment.date());
+ date.setHours(0, 0, 0, 0);
- date.setUTCHours(0, 0, 0);
- return [date, timeString];
- }, [timestamp]);
+ return [
+ date,
+ currentMoment.toDate(),
+ currentMoment.format('HH:mm'),
+ currentMoment.format('YYYY-MM-DD'),
+ dayProgress
+ ];
+ }, [timestamp, timezone]);
- const timeSliderValue = useMemo(() => {
- const base = dateOnly.valueOf();
- return clamp([0, 1], (parseInt(timestamp) - base) / DAY_SLIDER_RANGE);
- }, [timestamp, dateOnly]);
+ const timeSliderConfig = useMemo(() => {
+ const times = SunCalc.getTimes(fullDate, mapState.latitude, mapState.longitude);
+ const {dawn, sunrise, sunset, dusk} = times;
- const timeSliderProps = useMemo(() => {
return {
- label: 'value',
- value1: timeSliderValue,
- step: 0.001,
- range: [0, 1],
- value0: 0,
- onChange: value => {
- const start = new Date(timestamp).setUTCHours(0, 0, 0).valueOf();
- onDateTimeChange(Math.floor(start + DAY_SLIDER_RANGE * clamp([0, 0.9999], value[1])));
- },
- showInput: false,
- isRanged: false
+ dawn: getDayRatio(moment.tz(dawn.valueOf(), timezone)),
+ sunrise: getDayRatio(moment.tz(sunrise.valueOf(), timezone)),
+ sunset: getDayRatio(moment.tz(sunset.valueOf(), timezone)),
+ dusk: getDayRatio(moment.tz(dusk.valueOf(), timezone)),
+ sunriseTime: moment.tz(sunrise.valueOf(), timezone).format('hh:mm A'),
+ sunsetTime: moment.tz(sunset.valueOf(), timezone).format('hh:mm A')
};
- }, [timeSliderValue, timestamp, onDateTimeChange]);
+ }, [fullDate, timezone, mapState.latitude, mapState.longitude]);
+
+ const onTimeSliderChange = useCallback(
+ value => {
+ const hours = clamp([0, 23], Math.floor(value[1] * 24));
+ const minutes = clamp([0, 59], Math.floor((value[1] * 24 - hours) * 60));
+
+ const newFormattedTime = `${hours < 10 ? '0' + hours : hours}:${
+ minutes < 10 ? '0' + minutes : minutes
+ }`;
+ const newTimestamp = getTimestamp(formattedDate, newFormattedTime, timezone);
+ onTimeParametersChanged({timestamp: newTimestamp});
+ },
+ [formattedDate, timezone, onTimeParametersChanged]
+ );
const setDate = useCallback(
newDate => {
- const adjustedTime = newDate.valueOf() - newDate.getTimezoneOffset() * 1000 * 60;
- const newTimestamp = Math.floor(adjustedTime + DAY_SLIDER_RANGE * timeSliderValue);
- onDateTimeChange(newTimestamp);
+ const newFormattedDate = moment(newDate).format('YYYY-MM-DD');
+ const newTimestamp = getTimestamp(newFormattedDate, formattedTime, timezone);
+ onTimeParametersChanged({timestamp: newTimestamp});
},
- [timeSliderValue, onDateTimeChange]
+ [formattedTime, timezone, onTimeParametersChanged]
);
const setTime = useCallback(
- time => {
- const conf = time.split(':');
- const start = new Date(timestamp).setUTCHours(conf[0], conf[1]).valueOf();
- onDateTimeChange(start);
+ newTime => {
+ const newTimestamp = getTimestamp(formattedDate, newTime, timezone);
+ onTimeParametersChanged({timestamp: newTimestamp});
+ },
+ [formattedDate, timezone, onTimeParametersChanged]
+ );
+
+ const setTimezone = useCallback(
+ newTimezone => {
+ const newTimestamp = getTimestamp(formattedDate, formattedTime, newTimezone);
+ // date and time are adjusted to have the same value but in the new timezone
+ onTimeParametersChanged({timestamp: newTimestamp, timezone: newTimezone});
},
- [timestamp, onDateTimeChange]
+ [formattedDate, formattedTime, onTimeParametersChanged]
);
const setCurrentDateTime = useCallback(() => {
- onDateTimeChange(new Date().valueOf());
- }, [onDateTimeChange]);
+ onTimeParametersChanged({timestamp: new Date().valueOf()});
+ }, [onTimeParametersChanged]);
const formatShortWeekday = useCallback((locale, date) => {
return ['S', 'M', 'T', 'W', 'T', 'F', 'S'][date.getDay()];
@@ -194,13 +288,17 @@ export default function EffectTimeConfiguratorFactory(
id: 'effectManager.pickDateTime'
})}
onChange={() => {
- onTimeModeChange(LIGHT_AND_SHADOW_EFFECT_TIME_MODES.pick);
+ onTimeParametersChanged({timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.pick});
}}
/>
</StyledWrapper>
<SliderWrapper hidden={disableDateTimePick}>
- <RangeSlider {...timeSliderProps} />
+ <EffectTimeSlider
+ value={dayTimeProgress}
+ onChange={onTimeSliderChange}
+ config={timeSliderConfig}
+ />
</SliderWrapper>
<StyledWrapper hidden={disableDateTimePick} marginBottom={2}>
@@ -213,7 +311,7 @@ export default function EffectTimeConfiguratorFactory(
</TextBlock>
</StyledWrapper>
- <StyledWrapper hidden={disableDateTimePick} marginBottom={24}>
+ <StyledWrapper hidden={disableDateTimePick} marginBottom={16}>
<StyledButton onClick={setCurrentDateTime} data-for="pick-time-button" data-tip>
<LocationMarker height="16px" />
<Tooltip id="pick-time-button" effect="solid" place="top" delayShow={500}>
@@ -221,29 +319,41 @@ export default function EffectTimeConfiguratorFactory(
</Tooltip>
</StyledButton>
<WithIconWrapper>
- <StyledDatePicker
- value={dateOnly}
- onChange={setDate}
- minDetail={'month'}
- formatShortWeekday={formatShortWeekday}
- />
+ <StyledDatePicker>
+ <DatePicker
+ value={datePickerDate}
+ onChange={setDate}
+ minDetail={'month'}
+ formatShortWeekday={formatShortWeekday}
+ />
+ </StyledDatePicker>
<StyledExtraIcon>
<Calendar width="16px" height="32px" />
</StyledExtraIcon>
</WithIconWrapper>
<WithIconWrapper>
- <StyledTimePicker
- value={selectedTimeString}
- onChange={setTime}
- disableClock={true}
- format={'hh:mm a'}
- />
+ <EffectTimeSelector value={formattedTime} onChange={setTime} />
<StyledExtraIcon>
<Clock width="16px" height="32px" />
</StyledExtraIcon>
</WithIconWrapper>
</StyledWrapper>
+ <StyledWrapper hidden={disableDateTimePick} marginBottom={2}>
+ <TextBlock>
+ <FormattedMessage id={'effectManager.timezone'} />
+ </TextBlock>
+ </StyledWrapper>
+
+ <StyledWrapper hidden={disableDateTimePick} marginBottom={24}>
+ <WithIconWrapper width={'100%'}>
+ <TimezoneSelector selected={timezone} onSelect={setTimezone} />
+ <StyledExtraIcon>
+ <Globe width="16px" height="32px" />
+ </StyledExtraIcon>
+ </WithIconWrapper>
+ </StyledWrapper>
+
<StyledWrapper marginBottom={16}>
<StyledRadio
type="radio"
@@ -253,7 +363,7 @@ export default function EffectTimeConfiguratorFactory(
id: 'effectManager.currentTime'
})}
onChange={() => {
- onTimeModeChange(LIGHT_AND_SHADOW_EFFECT_TIME_MODES.current);
+ onTimeParametersChanged({timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.current});
}}
/>
</StyledWrapper>
@@ -265,7 +375,7 @@ export default function EffectTimeConfiguratorFactory(
id={`effect-time-toggle-use-animation-time`}
label={'Animation time'}
onChange={() => {
- onTimeModeChange(LIGHT_AND_SHADOW_EFFECT_TIME_MODES.animation);
+ onTimeParametersChanged({timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.animation});
}}
/>
</StyledWrapper>
@@ -273,5 +383,6 @@ export default function EffectTimeConfiguratorFactory(
);
};
- return injectIntl(EffectTimeConfigurator);
+ // @ts-expect-error how to properly type?
+ return withState([mapStateLens])(injectIntl(EffectTimeConfigurator));
}
diff --git a/src/components/src/effects/effect-time-selector.tsx b/src/components/src/effects/effect-time-selector.tsx
new file mode 100644
index 000000000..7e0e9d66a
--- /dev/null
+++ b/src/components/src/effects/effect-time-selector.tsx
@@ -0,0 +1,182 @@
+import React, {useMemo, useCallback} from 'react';
+import styled, {withTheme} from 'styled-components';
+import classNames from 'classnames';
+import moment from 'moment-timezone';
+
+import ItemSelector from '../common/item-selector/item-selector';
+import {StyledTimePicker} from '../common/styled-components';
+import {classList} from '../common/item-selector/dropdown-list';
+
+const HEADER_ITEM_ID = 'HEADER_ITEM_ID';
+
+export type EffectTimeSelectorProps = {
+ value: string;
+ onChange: (string) => void;
+ theme?: any;
+};
+
+const StyledEffectTimeSelector = styled.div`
+ .item-selector {
+ background-color: transparent;
+ }
+ .item-selector .item-selector__dropdown {
+ padding: 0px;
+ width: 110px;
+ height: 30px;
+ }
+ border: 1px solid ${props => props.theme.inputBgd};
+ border-radius: 4px;
+ :hover {
+ border: 1px solid ${props => props.theme.inputBgdHover};
+ }
+ .active {
+ border: 1px solid ${props => props.theme.activeColor};
+ border-radius: 4px 4px 0px 0px;
+ }
+`;
+
+const StyledLabel = styled.div`
+ color: ${props => props.theme.effectPanelTextMain};
+ font-size: ${props => props.theme.inputFontSize};
+ height: 13px;
+ display: flex;
+ align-items: center;
+`;
+
+const DropdownListWrapper = styled.div`
+ ${props => props.theme.dropdownList};
+ background-color: ${props => props.theme.inputBgdHover};
+ display: flex;
+ flex-wrap: wrap;
+ padding: 0px;
+ max-height: 160px;
+ border-radius: 0px 0px 4px 4px;
+`;
+
+const StyledDropdownListItem = styled.div`
+ padding: 10px 5px 9px 10px;
+ width: 100%;
+ :hover {
+ background-color: ${props => props.theme.effectPanelElementColorSelected};
+ cursor: pointer;
+ }
+`;
+
+// Generate time options for the dropdown with 30 min intervals.
+const timeOptions = (() => {
+ const m = moment().utcOffset(0);
+ m.set({hour: 12, minute: 0, second: 0, millisecond: 0});
+
+ const out: {name: string; id: string}[] = [];
+ for (let i = 0; i < 48; i++) {
+ out.push({name: m.format('hh:mm A'), id: m.format('HH:mm')});
+ m.add(30, 'minutes');
+ }
+ return out;
+})();
+
+const getDisplayOption = op => op.name;
+const getOptionValue = op => op.id;
+
+/**
+ * A component to render TimePicker as the header for the dropdown component.
+ */
+const EffectTimeListItem = ({value}) => {
+ if (value?.id === HEADER_ITEM_ID) {
+ return (
+ <StyledTimePicker
+ value={value.value}
+ onChange={value.onChange}
+ onClick={value.onClick}
+ disableClock={true}
+ format={'hh:mm a'}
+ />
+ );
+ }
+
+ return <StyledLabel>{value.name}</StyledLabel>;
+};
+
+const EffectTimeDropdownList = ({
+ onOptionSelected,
+ options,
+ selectionIndex,
+ customListItemComponent
+}) => {
+ const onSelectOption = useCallback(
+ (e, value) => {
+ e.preventDefault();
+ onOptionSelected(value);
+ },
+ [onOptionSelected]
+ );
+
+ const ListItemComponent = customListItemComponent;
+
+ return (
+ <DropdownListWrapper className={classList.list}>
+ {options.map((value, i) => (
+ <StyledDropdownListItem
+ className={classNames('effect-type-selector__item', {
+ hover: selectionIndex === i
+ })}
+ key={`${value.id}_${i}`}
+ onMouseDown={e => onSelectOption(e, value)}
+ onClick={e => onSelectOption(e, value)}
+ >
+ <ListItemComponent value={value} />
+ </StyledDropdownListItem>
+ ))}
+ </DropdownListWrapper>
+ );
+};
+
+EffectTimeSelectorFactory.deps = [];
+
+function EffectTimeSelectorFactory() {
+ const EffectTimeSelector: React.FC<EffectTimeSelectorProps> = ({
+ value,
+ onChange
+ }: EffectTimeSelectorProps) => {
+ // Selected item is rendered as TimePicker in EffectTimeListItem
+ const selectedItems = useMemo(() => {
+ return [
+ {
+ id: HEADER_ITEM_ID,
+ value,
+ onChange,
+ onClick: e => {
+ // DatePicker is used as custom header.
+ // Don't open the dropdown when the user is editing time values directly.
+ const name = e?.target?.name;
+ if (name === 'hour12' || name === 'minute' || name === 'amPm') {
+ e.stopPropagation();
+ }
+ }
+ }
+ ];
+ }, [value, onChange]);
+
+ return (
+ <StyledEffectTimeSelector>
+ <ItemSelector
+ selectedItems={selectedItems}
+ options={timeOptions}
+ multiSelect={false}
+ searchable={false}
+ placeholder=""
+ filterOption="name"
+ onChange={onChange}
+ getOptionValue={getOptionValue}
+ displayOption={getDisplayOption}
+ DropDownLineItemRenderComponent={EffectTimeListItem}
+ DropDownRenderComponent={EffectTimeDropdownList}
+ />
+ </StyledEffectTimeSelector>
+ );
+ };
+
+ return withTheme(EffectTimeSelector);
+}
+
+export default EffectTimeSelectorFactory;
diff --git a/src/components/src/effects/effect-time-slider.tsx b/src/components/src/effects/effect-time-slider.tsx
new file mode 100644
index 000000000..23e988bcd
--- /dev/null
+++ b/src/components/src/effects/effect-time-slider.tsx
@@ -0,0 +1,300 @@
+import React, {useMemo} from 'react';
+import styled from 'styled-components';
+
+import RangeSliderFactory from '../common/range-slider';
+import {Sun, Moon, Sunset, Sunrise} from '../common/icons';
+
+export type EffectTimeSliderConfig = {
+ dawn: number;
+ sunrise: number;
+ sunset: number;
+ dusk: number;
+ sunriseTime: string;
+ sunsetTime: string;
+};
+
+export type UIBlock = {
+ type: string;
+ width: number;
+ center: number;
+ start: number;
+ end: number;
+ text?: string;
+ TopRowIcon?: React.ElementType<any>;
+ BottomRowIcon?: React.ElementType<any>;
+};
+
+export type EffectTimeSliderProps = {
+ value: number;
+ onChange: (number) => void;
+ config: EffectTimeSliderConfig;
+};
+
+const TimeSliderWrapper = styled.div`
+ width: 100%;
+ height: 48px;
+`;
+
+const TopRowWrapper = styled.div`
+ width: 100%;
+ height: 32px;
+ display: flex;
+ position: relative;
+ align-items: center;
+
+ .day {
+ background-color: ${props => props.theme.effectPanelElementColorHovered};
+ }
+ .night {
+ background-color: ${props => props.theme.effectPanelElementColor};
+ }
+ .sunrise,
+ .sunset {
+ background-color: ${props => props.theme.effectPanelElementColorActive};
+ }
+ .inline_icon__day {
+ color: ${props => props.theme.effectPanelElementColorSun};
+ }
+ .inline_icon__night {
+ color: ${props => props.theme.effectPanelTextSecondary2};
+ }
+`;
+
+const BottomRowWrapper = styled.div`
+ position: relative;
+ height: 16px;
+ .bottom_icon__sunrise,
+ .bottom_icon__sunset {
+ color: ${props => props.theme.effectPanelTextSecondary2};
+ }
+`;
+
+type BackgroundBlockProps = {width: string};
+const BackgroundBlock = styled.div<BackgroundBlockProps>`
+ margin: 0px;
+ padding: 0px;
+ width: ${props => props.width};
+ height: 24px;
+ pointer-events: none;
+`;
+
+type StyledIconProps = {left: number};
+const StyledIcon = styled.div<StyledIconProps>`
+ position: absolute;
+ top: 0px;
+ left: calc(${props => props.left}% - 8px);
+ height: 32px;
+ pointer-events: none;
+`;
+
+type StyledBottomIconProps = {left: number};
+const StyledBottomIcon = styled.div<StyledBottomIconProps>`
+ position: absolute;
+ top: 0px;
+ left: calc(${props => props.left}% - 27px);
+ height: 12px;
+ pointer-events: none;
+ margin-top: 1px;
+ display: flex;
+ align-items: flex-end;
+`;
+
+const RangeSliderWrapper = styled.div`
+ position: absolute;
+ width: 100%;
+ .kg-slider {
+ padding-left: 6px;
+ }
+ .kg-range-slider {
+ padding: 0px !important;
+ background-color: transparent;
+ }
+ .kg-range-slider__bar {
+ background-color: transparent;
+ }
+ .kg-range-slider__handle {
+ height: 32px;
+ width: 8px;
+ margin-top: -14px;
+ }
+ .kg-range-slider__input {
+ height: 32px;
+ text-align: center;
+ padding: 3px 6px;
+ }
+`;
+
+const Text = styled.div`
+ margin-left: 3px;
+ font-size: 10px;
+ line-height: 11px;
+ white-space: nowrap;
+`;
+
+const MODES = {
+ sunrise: 'sunrise',
+ day: 'day',
+ sunset: 'sunset',
+ night: 'night'
+};
+
+/**
+ * Generate rendering blocks for each part of the day.
+ */
+export function getUIBlocks(config: EffectTimeSliderConfig): UIBlock[] {
+ let {dawn, sunrise, sunset, dusk} = config;
+ if (dawn > sunrise) sunrise += 1;
+ if (dawn > sunset) sunset += 1;
+ if (dawn > dusk) dusk += 1;
+
+ const blocks = [
+ {
+ start: dawn,
+ end: sunrise,
+ type: MODES.sunrise,
+ width: 0,
+ center: 0
+ },
+ {
+ start: sunrise,
+ end: sunset,
+ type: MODES.day,
+ width: 0,
+ center: 0
+ },
+ {
+ start: sunset,
+ end: dusk,
+ type: MODES.sunset,
+ width: 0,
+ center: 0
+ },
+ {
+ start: dusk,
+ end: dawn,
+ type: MODES.night,
+ width: 0,
+ center: 0
+ }
+ ];
+ const updatedBlocks: UIBlock[] = [];
+
+ // sort and split ui blocks
+ blocks.forEach(block => {
+ if (block.start > block.end) {
+ block.end += 1;
+ }
+ if (block.start > 1 && block.end > 1) {
+ updatedBlocks.push({...block, start: block.start - 1, end: block.end - 1});
+ } else if (block.end > 1) {
+ updatedBlocks.push({
+ ...block,
+ end: 1
+ });
+
+ updatedBlocks.push({...block, start: 0, end: block.end - 1});
+ } else {
+ updatedBlocks.push(block);
+ }
+ });
+ updatedBlocks.sort((a, b) => a.start - b.start);
+
+ const existingBottomBlocks = {};
+ updatedBlocks.forEach(block => {
+ block.width = (block.end - block.start) * 100;
+ block.center = block.start * 100 + block.width / 2;
+
+ // Don't display inline icons when day or night is too short.
+ if ((block.type === MODES.day || block.type === MODES.night) && block.width > 5) {
+ block.TopRowIcon = block.type === MODES.day ? Sun : Moon;
+ }
+
+ // bottom row icons below the slider
+ if ((block.type === MODES.sunrise || block.type === MODES.sunset) && block.width > 0.1) {
+ // prevent duplicates for bottom row
+ const existingBlock = existingBottomBlocks[block.type];
+ if (existingBlock) {
+ if (existingBlock.width < block.width) existingBlock.BottomRowIcon = null;
+ else if (existingBlock.width > block.width) return;
+ }
+ existingBottomBlocks[block.type] = block;
+
+ // prevent bottom icon and labels
+ block.BottomRowIcon = block.type === MODES.sunrise ? Sunrise : Sunset;
+ if (block.center > 90) {
+ block.center = 90;
+ } else if (block.center < 10) {
+ block.center = 10;
+ }
+ block.text = block.type === MODES.sunrise ? config.sunriseTime : config.sunsetTime;
+ }
+ });
+ return updatedBlocks;
+}
+
+EffectTimeSliderFactory.deps = [RangeSliderFactory];
+
+export default function EffectTimeSliderFactory(
+ RangeSlider: ReturnType<typeof RangeSliderFactory>
+) {
+ const EffectTimeSlider: React.FC<EffectTimeSliderProps> = ({
+ value: rangeSliderValue,
+ onChange,
+ config
+ }: EffectTimeSliderProps) => {
+ const uiBlocks = useMemo(() => {
+ return getUIBlocks(config);
+ }, [config]);
+
+ const rangeSliderProps = useMemo(() => {
+ return {
+ label: 'value',
+ value1: rangeSliderValue,
+ step: 0.001,
+ range: [0, 1],
+ value0: 0,
+ onChange,
+ showInput: false,
+ isRanged: false
+ };
+ }, [rangeSliderValue, onChange]);
+
+ return (
+ <TimeSliderWrapper>
+ <TopRowWrapper>
+ {uiBlocks.map((block, index) => {
+ return <BackgroundBlock key={index} width={`${block.width}%`} className={block.type} />;
+ })}
+
+ {uiBlocks.map((block, index) => {
+ return block.TopRowIcon ? (
+ <StyledIcon key={index} left={block.center} className={`inline_icon__${block.type}`}>
+ <block.TopRowIcon width="16px" height="32px" />
+ </StyledIcon>
+ ) : null;
+ })}
+
+ <RangeSliderWrapper>
+ <RangeSlider {...rangeSliderProps} />
+ </RangeSliderWrapper>
+ </TopRowWrapper>
+ <BottomRowWrapper>
+ {uiBlocks.map((block, index) => {
+ return block.BottomRowIcon ? (
+ <StyledBottomIcon
+ key={index}
+ left={block.center}
+ className={`bottom_icon__${block.type}`}
+ >
+ <block.BottomRowIcon width="12px" height="12px" />
+ <Text>{block.text}</Text>
+ </StyledBottomIcon>
+ ) : null;
+ })}
+ </BottomRowWrapper>
+ </TimeSliderWrapper>
+ );
+ };
+
+ return EffectTimeSlider;
+}
diff --git a/src/components/src/effects/effect-type-dropdown-list.tsx b/src/components/src/effects/effect-type-dropdown-list.tsx
index 1d2fd44f7..5a09a82e1 100644
--- a/src/components/src/effects/effect-type-dropdown-list.tsx
+++ b/src/components/src/effects/effect-type-dropdown-list.tsx
@@ -24,7 +24,7 @@ const DropdownListWrapper = styled.div`
display: flex;
flex-wrap: wrap;
align-items: stretch;
- padding: 17px 0 12px 0;
+ padding: 24px 0 12px 0;
max-height: 430px;
justify-content: center;
`;
diff --git a/src/components/src/effects/effect-type-selector.tsx b/src/components/src/effects/effect-type-selector.tsx
index 98f5c6eb1..0c8c40fd8 100644
--- a/src/components/src/effects/effect-type-selector.tsx
+++ b/src/components/src/effects/effect-type-selector.tsx
@@ -9,6 +9,8 @@ export type EffectTypeSelectorProps = {
options: {type: string; name: string; disabled: boolean}[];
onSelect: (type: any) => void;
theme: any;
+ onBlur?: () => void;
+ onOpen?: () => void;
};
const DropdownWrapper = styled.div`
@@ -19,12 +21,21 @@ const DropdownWrapper = styled.div`
width: 297px;
margin-left: -194px;
margin-top: 26px;
+
+ .typeahead__input {
+ border-color: ${props => props.theme.activeColor};
+ border-radius: 4px 4px 0px 0px !important;
+ }
+ .typeahead__input_box {
+ padding: 0px;
+ }
.typeahead__input_icon {
- top: 41px;
+ top: 34px;
+ right: 9px;
}
`;
-const StyledLayerTypeSelector = styled.div`
+const StyledEffectTypeSelector = styled.div`
.item-selector .item-selector__dropdown {
padding: 4px 10px 4px 10px;
background-color: ${props => props.theme.secondaryBtnBgd};
@@ -46,9 +57,11 @@ const getOptionValue = op => op.type;
EffectTypeSelectorFactory.deps = [EffectTypeListItemFactory, EffectTypeDropdownListFactory];
function EffectTypeSelectorFactory(EffectTypeListItem, EffectTypeDropdownList) {
- const LayerTypeSelector: React.FC<EffectTypeSelectorProps> = ({
+ const EffectTypeSelector: React.FC<EffectTypeSelectorProps> = ({
options,
- onSelect
+ onSelect,
+ onBlur,
+ onOpen
}: EffectTypeSelectorProps) => {
// Make sure effect type selector has dummy as selection
const selectedItems = useMemo(() => {
@@ -61,7 +74,7 @@ function EffectTypeSelectorFactory(EffectTypeListItem, EffectTypeDropdownList) {
}, []);
return (
- <StyledLayerTypeSelector className="effect-config__type">
+ <StyledEffectTypeSelector className="effect-config__type">
<ItemSelector
selectedItems={selectedItems}
options={options}
@@ -69,6 +82,8 @@ function EffectTypeSelectorFactory(EffectTypeListItem, EffectTypeDropdownList) {
disabled={false}
placeholder="effectManager.addEffect"
onChange={onSelect}
+ onBlur={onBlur}
+ onOpen={onOpen}
getOptionValue={getOptionValue}
filterOption="name"
displayOption={getDisplayOption}
@@ -76,11 +91,11 @@ function EffectTypeSelectorFactory(EffectTypeListItem, EffectTypeDropdownList) {
DropDownRenderComponent={EffectTypeDropdownList}
DropDownWrapperComponent={DropdownWrapper}
/>
- </StyledLayerTypeSelector>
+ </StyledEffectTypeSelector>
);
};
- return withTheme(LayerTypeSelector);
+ return withTheme(EffectTypeSelector);
}
export default EffectTypeSelectorFactory;
diff --git a/src/components/src/effects/timezone-selector.tsx b/src/components/src/effects/timezone-selector.tsx
new file mode 100644
index 000000000..0b0e6d35e
--- /dev/null
+++ b/src/components/src/effects/timezone-selector.tsx
@@ -0,0 +1,65 @@
+import React, {useMemo} from 'react';
+import moment from 'moment-timezone';
+import styled, {withTheme} from 'styled-components';
+
+import {DEFAULT_TIMEZONE} from '@kepler.gl/constants';
+
+import ItemSelector from '../common/item-selector/item-selector';
+
+const getValue = op => op?.name || DEFAULT_TIMEZONE;
+
+export type TimezoneSelectorProps = {
+ selected?: string;
+ options?: {name: string}[];
+ onSelect: (string) => void;
+ theme?: any;
+};
+
+const StyledItemSelector = styled(ItemSelector)`
+ .item-selector__dropdown {
+ padding-left: 30px;
+ border-radius: 4px;
+ }
+ .active {
+ border-color: ${props => props.theme.activeColor};
+ border-radius: 4px 4px 0px 0px !important;
+ }
+`;
+
+const defaultTimezones = moment.tz.names().map(name => {
+ return {
+ name
+ };
+});
+
+function TimezoneSelectorFactory() {
+ const TimezoneTypeSelector: React.FC<TimezoneSelectorProps> = ({
+ selected,
+ options = defaultTimezones,
+ onSelect
+ }: TimezoneSelectorProps) => {
+ const selectedItems = useMemo(() => {
+ return selected ? [{name: selected}] : [];
+ }, [selected]);
+
+ return (
+ <StyledItemSelector
+ selectedItems={selectedItems}
+ options={options}
+ multiSelect={false}
+ disabled={false}
+ placeholder="effectManager.timezone"
+ onChange={onSelect}
+ filterOption="name"
+ getOptionValue={getValue}
+ displayOption={getValue}
+ searchable={true}
+ showArrow={true}
+ />
+ );
+ };
+
+ return withTheme(TimezoneTypeSelector);
+}
+
+export default TimezoneSelectorFactory;
diff --git a/src/constants/src/default-settings.ts b/src/constants/src/default-settings.ts
index a382ed8f4..7b0fa0422 100644
--- a/src/constants/src/default-settings.ts
+++ b/src/constants/src/default-settings.ts
@@ -1163,7 +1163,7 @@ export const dataTestIds: Record<string, string> = {
};
// Effects
-
+export const DEFAULT_TIMEZONE = 'UTC';
export const DEFAULT_POST_PROCESSING_EFFECT_TYPE: string = 'ink';
export const DEFAULT_LIGHT_COLOR: [number, number, number] = [255, 255, 255];
@@ -1215,12 +1215,12 @@ export const POSTPROCESSING_EFFECTS: {[key: string]: EffectDescription} = {
hueSaturation: {
type: 'hueSaturation',
name: 'Hue & Saturation',
- parameters: [{name: 'hue'}, {name: 'saturation'}]
+ parameters: [{name: 'hue'}, {name: 'saturation', default: 0.25}]
},
vibrance: {
type: 'vibrance',
name: 'Vibrance',
- parameters: [{name: 'amount'}]
+ parameters: [{name: 'amount', default: 0.5}]
},
sepia: {
type: 'sepia',
@@ -1286,7 +1286,8 @@ export const POSTPROCESSING_EFFECTS: {[key: string]: EffectDescription} = {
name: 'Blur (Zoom)',
parameters: [
{
- name: 'strength'
+ name: 'strength',
+ default: 0.05
},
{
name: 'center',
@@ -1379,7 +1380,7 @@ export const POSTPROCESSING_EFFECTS: {[key: string]: EffectDescription} = {
hexagonalPixelate: {
type: 'hexagonalPixelate',
name: 'Hexagonal Pixelate',
- parameters: [{name: 'scale'}]
+ parameters: [{name: 'scale', default: 20}]
}
};
diff --git a/src/effects/src/effect.ts b/src/effects/src/effect.ts
index 79ad06495..c6c2ada24 100644
--- a/src/effects/src/effect.ts
+++ b/src/effects/src/effect.ts
@@ -11,10 +11,11 @@ export class Effect implements EffectInterface {
id: string;
type: string;
isEnabled: boolean;
- isConfigActive: boolean;
- isJsonEditorActive: boolean;
// effect specific parameters for a deck.gl effect (uniforms)
parameters: {[key: string]: any};
+ // runtime props
+ isConfigActive: boolean;
+ isJsonEditorActive: boolean;
deckEffect: any;
_uiConfig: EffectParameterDescription[];
diff --git a/src/effects/src/lighting-effect.ts b/src/effects/src/lighting-effect.ts
index 6c8e7c0e5..03e1fd34c 100644
--- a/src/effects/src/lighting-effect.ts
+++ b/src/effects/src/lighting-effect.ts
@@ -1,4 +1,5 @@
import {AmbientLight, _SunLight as SunLight} from '@deck.gl/core';
+import moment from 'moment-timezone';
import {LIGHT_AND_SHADOW_EFFECT, DEFAULT_LIGHT_AND_SHADOW_PROPS} from '@kepler.gl/constants';
import {normalizeColor} from '@kepler.gl/utils';
@@ -20,7 +21,11 @@ class LightingEffect extends Effect {
}
_initializeEffect() {
- this.parameters = {...DEFAULT_LIGHT_AND_SHADOW_PROPS, ...this.parameters};
+ this.parameters = {
+ ...DEFAULT_LIGHT_AND_SHADOW_PROPS,
+ timezone: moment.tz.guess(true),
+ ...this.parameters
+ };
const {parameters} = this;
const ambientLight = new AmbientLight({
diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.ts
index 41bc69c24..5af205855 100644
--- a/src/localization/src/translations/en.ts
+++ b/src/localization/src/translations/en.ts
@@ -193,7 +193,8 @@ export default {
currentTime: 'Current time',
pickCurrrentTime: 'Pick current time',
date: 'Date',
- time: 'Time'
+ time: 'Time',
+ timezone: 'Timezone'
},
layerConfiguration: {
defaultDescription: 'Calculate {property} based on selected field',
diff --git a/src/styles/src/base.ts b/src/styles/src/base.ts
index 293bca39d..321df2989 100644
--- a/src/styles/src/base.ts
+++ b/src/styles/src/base.ts
@@ -490,6 +490,12 @@ export const effectPanelTextSecondary1 = '#A0A7B4';
export const effectPanelTextSecondary2 = '#6A7485';
export const effectPanelTextSecondary3 = '#5A6475';
+export const effectPanelElementColor = inputBgd;
+export const effectPanelElementColorActive = '#323843';
+export const effectPanelElementColorHovered = inputBgdHover;
+export const effectPanelElementColorSelected = '#454e5d';
+export const effectPanelElementColorSun = '#F7B26B';
+
// right panel
export const rightPanelMarginTop = 12;
export const rightPanelMarginRight = 12;
@@ -1588,7 +1594,13 @@ export const theme = {
effectPanelTextMain,
effectPanelTextSecondary1,
effectPanelTextSecondary2,
- effectPanelTextSecondary3
+ effectPanelTextSecondary3,
+
+ effectPanelElementColor,
+ effectPanelElementColorActive,
+ effectPanelElementColorHovered,
+ effectPanelElementColorSun,
+ effectPanelElementColorSelected
};
export const themeLT = {
diff --git a/test/browser/components/effects/effect-configurator-test.js b/test/browser/components/effects/effect-configurator-test.js
index cedbe919b..5bee99df3 100644
--- a/test/browser/components/effects/effect-configurator-test.js
+++ b/test/browser/components/effects/effect-configurator-test.js
@@ -19,6 +19,8 @@
// THE SOFTWARE.
import React from 'react';
+import {Provider} from 'react-redux';
+import configureStore from 'redux-mock-store';
import test from 'tape';
import {appInjector, EffectConfiguratorFactory} from '@kepler.gl/components';
@@ -69,7 +71,12 @@ test('Components -> EffectConfigurator -> render -> post processing effect', t =
t.end();
});
+const mockStore = configureStore();
+const ititialState = {mapState: {latitude: 0, longitude: 0}};
+
test('Components -> EffectConfigurator -> render -> light & shadow effect', t => {
+ const store = mockStore(ititialState);
+
let nextState = visStateReducer(
InitialState.visState,
VisStateActions.addEffect({
@@ -81,12 +88,14 @@ test('Components -> EffectConfigurator -> render -> light & shadow effect', t =>
t.doesNotThrow(() => {
wrapper = mountWithTheme(
<IntlWrapper>
- <EffectConfigurator
- {...{
- effect: nextState.effects[0],
- updateEffectConfig: () => {}
- }}
- />
+ <Provider store={store}>
+ <EffectConfigurator
+ {...{
+ effect: nextState.effects[0],
+ updateEffectConfig: () => {}
+ }}
+ />
+ </Provider>
</IntlWrapper>
);
}, `EffectConfigurator for ${nextState.effects[0].type} should not fail`);
diff --git a/test/browser/components/effects/effect-manager-test.js b/test/browser/components/effects/effect-manager-test.js
index 830dfdec5..fab0a5365 100644
--- a/test/browser/components/effects/effect-manager-test.js
+++ b/test/browser/components/effects/effect-manager-test.js
@@ -50,7 +50,8 @@ const initialState = {
}
}
}
- }
+ },
+ mapState: {latitude: 0, longitude: 0}
};
test('Components -> EffectManager -> render', t => {
diff --git a/test/browser/components/effects/effect-time-configurator-test.js b/test/browser/components/effects/effect-time-configurator-test.js
index d18b160d6..0dfb9133e 100644
--- a/test/browser/components/effects/effect-time-configurator-test.js
+++ b/test/browser/components/effects/effect-time-configurator-test.js
@@ -21,6 +21,8 @@
import React from 'react';
import test from 'tape';
import sinon from 'sinon';
+import {Provider} from 'react-redux';
+import configureStore from 'redux-mock-store';
import {LIGHT_AND_SHADOW_EFFECT_TIME_MODES} from '@kepler.gl/constants';
import {appInjector, EffectTimeConfiguratorFactory} from '@kepler.gl/components';
@@ -31,7 +33,12 @@ const EffectTimeConfigurator = appInjector.get(EffectTimeConfiguratorFactory);
const TEST_TIMESTAMP = 1690303570534;
+const mockStore = configureStore();
+const ititialState = {mapState: {latitude: 0, longitude: 0}};
+
test('Components -> EffectTimeConfigurator -> render', t => {
+ const store = mockStore(ititialState);
+
const props = {
timestamp: TEST_TIMESTAMP,
timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.pick
@@ -41,7 +48,9 @@ test('Components -> EffectTimeConfigurator -> render', t => {
t.doesNotThrow(() => {
wrapper = mountWithTheme(
<IntlWrapper>
- <EffectTimeConfigurator {...props} />
+ <Provider store={store}>
+ <EffectTimeConfigurator {...props} />
+ </Provider>
</IntlWrapper>
);
}, `EffectTimeConfigurator should not fail`);
@@ -55,19 +64,22 @@ test('Components -> EffectTimeConfigurator -> render', t => {
});
test('Components -> EffectTimeConfigurator -> time type', t => {
- const onTimeModeChange = sinon.spy();
+ const store = mockStore(ititialState);
+ const onTimeModeChange = sinon.spy();
const props = {
timestamp: TEST_TIMESTAMP,
timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.pick,
- onTimeModeChange
+ onChange: onTimeModeChange
};
let wrapper;
t.doesNotThrow(() => {
wrapper = mountWithTheme(
<IntlWrapper>
- <EffectTimeConfigurator {...props} />
+ <Provider store={store}>
+ <EffectTimeConfigurator {...props} />
+ </Provider>
</IntlWrapper>
);
}, `EffectTimeConfigurator should not fail`);
@@ -77,7 +89,7 @@ test('Components -> EffectTimeConfigurator -> time type', t => {
.at(0)
.invoke('onChange')();
t.ok(
- onTimeModeChange.calledWith(LIGHT_AND_SHADOW_EFFECT_TIME_MODES.pick),
+ onTimeModeChange.calledWith({timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.pick}),
`Should set ${LIGHT_AND_SHADOW_EFFECT_TIME_MODES.pick} mode`
);
@@ -86,7 +98,7 @@ test('Components -> EffectTimeConfigurator -> time type', t => {
.at(1)
.invoke('onChange')();
t.ok(
- onTimeModeChange.calledWith(LIGHT_AND_SHADOW_EFFECT_TIME_MODES.current),
+ onTimeModeChange.calledWith({timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.current}),
`Should set ${LIGHT_AND_SHADOW_EFFECT_TIME_MODES.current} mode`
);
@@ -95,7 +107,7 @@ test('Components -> EffectTimeConfigurator -> time type', t => {
.at(2)
.invoke('onChange')();
t.ok(
- onTimeModeChange.calledWith(LIGHT_AND_SHADOW_EFFECT_TIME_MODES.animation),
+ onTimeModeChange.calledWith({timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.animation}),
`Should set ${LIGHT_AND_SHADOW_EFFECT_TIME_MODES.animation} mode`
);
@@ -105,20 +117,23 @@ test('Components -> EffectTimeConfigurator -> time type', t => {
});
test('Components -> EffectTimeConfigurator -> pick time', t => {
- const onDateTimeChange = sinon.spy();
+ const store = mockStore(ititialState);
+ const onDateTimeChange = sinon.spy();
const props = {
timestamp: TEST_TIMESTAMP,
- onDateTimeChange,
+ timezone: 'UTC',
timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.pick,
- onTimeModeChange: () => {}
+ onChange: onDateTimeChange
};
let wrapper;
t.doesNotThrow(() => {
wrapper = mountWithTheme(
<IntlWrapper>
- <EffectTimeConfigurator {...props} />
+ <Provider store={store}>
+ <EffectTimeConfigurator {...props} />
+ </Provider>
</IntlWrapper>
);
}, `EffectTimeConfigurator should not fail`);
@@ -140,7 +155,11 @@ test('Components -> EffectTimeConfigurator -> pick time', t => {
// properly propagate in tests
.simulate('change', {target: {value: '2022', name: 'year'}});
- t.equal(onDateTimeChange.getCall(3).args[0], 1643820370000, `Date should be updated`);
+ t.deepEqual(
+ onDateTimeChange.getCall(3).args[0],
+ {timestamp: 1643820360000},
+ `Date should be updated`
+ );
// time
wrapper
@@ -154,7 +173,11 @@ test('Components -> EffectTimeConfigurator -> pick time', t => {
// properly propagate in tests
.simulate('change', {target: {value: '30', name: 'minute'}});
- t.equal(onDateTimeChange.getCall(6).args[0], 1690317010534, `Time should be updated`);
+ t.deepEqual(
+ onDateTimeChange.getCall(6).args[0],
+ {timestamp: 1690317000000},
+ `Time should be updated`
+ );
// pick current time button
wrapper
@@ -162,9 +185,179 @@ test('Components -> EffectTimeConfigurator -> pick time', t => {
.at(0)
.simulate('click');
t.ok(
- Math.abs(onDateTimeChange.getCall(7).args[0] - Date.now()) < 1000,
+ Math.abs(onDateTimeChange.getCall(7).args[0].timestamp - Date.now()) < 1000,
`Should pick current date & time`
);
t.end();
});
+
+const getDisplayedDateTimeValues = wrapper => {
+ return {
+ year: wrapper
+ .find('.react-date-picker__inputGroup__year')
+ .at(0)
+ .props().value,
+ month: wrapper
+ .find('.react-date-picker__inputGroup__month')
+ .at(0)
+ .props().value,
+ day: wrapper
+ .find('.react-date-picker__inputGroup__day')
+ .at(0)
+ .props().value,
+ hour: wrapper
+ .find('.react-time-picker__inputGroup__hour')
+ .at(0)
+ .props().value,
+ minute: wrapper
+ .find('.react-time-picker__inputGroup__minute')
+ .at(0)
+ .props().value,
+ amPm: wrapper
+ .find('.react-time-picker__inputGroup__amPm')
+ .at(0)
+ .props().value
+ };
+};
+
+test('Components -> EffectTimeConfigurator -> time zone update', t => {
+ const store = mockStore(ititialState);
+
+ const onDateTimeChange = sinon.spy();
+ const props = {
+ timestamp: 1690851835534,
+ timezone: 'America/Los_Angeles',
+ timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.pick,
+ onChange: onDateTimeChange
+ };
+
+ let wrapper;
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <IntlWrapper>
+ <Provider store={store}>
+ <EffectTimeConfigurator {...props} />
+ </Provider>
+ </IntlWrapper>
+ );
+ }, `EffectTimeConfigurator should not fail`);
+
+ // Los Angeles timezone is 7 hours ahead of UTC
+ // UTC time: 2023 Aug 1 01:03:55
+ // Displayed time: 2023 July 31 06:03:00 pm
+
+ let values = getDisplayedDateTimeValues(wrapper);
+ t.equal(values.year, '2023', `Year should be correctly set`);
+ t.equal(values.month, '7', `Month should be correctly set`);
+ t.equal(values.day, '31', `Day should be correctly set`);
+ t.equal(values.hour, '6', `Hour should be correctly set`);
+ t.equal(values.minute, '3', `Minute should be correctly set`);
+ t.equal(values.amPm, 'pm', `AM/PM should be correctly set`);
+
+ // Change time zone
+ wrapper
+ .find('.item-selector__dropdown')
+ .at(1)
+ .simulate('click');
+ wrapper
+ .find({children: 'America/Barbados'})
+ .at(0)
+ .simulate('click');
+
+ t.deepEqual(
+ onDateTimeChange.getCall(0).args[0],
+ {timestamp: 1690840980000, timezone: 'America/Barbados'},
+ `New time zone should be selected and timestamp updated`
+ );
+
+ // Timestamp should be updated internally,
+ // but displayed date and time shouldn't change
+ values = getDisplayedDateTimeValues(wrapper);
+ t.equal(values.year, '2023', `Year should be correctly set`);
+ t.equal(values.month, '7', `Month should be correctly set`);
+ t.equal(values.day, '31', `Day should be correctly set`);
+ t.equal(values.hour, '6', `Hour should be correctly set`);
+ t.equal(values.minute, '3', `Minute should be correctly set`);
+ t.equal(values.amPm, 'pm', `AM/PM should be correctly set`);
+
+ t.end();
+});
+
+test('Components -> EffectTimeConfigurator -> time with custom timezone update', t => {
+ const store = mockStore(ititialState);
+
+ const onDateTimeChange = sinon.spy();
+ const props = {
+ timestamp: 1690840980000,
+ timezone: 'America/Barbados',
+ timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.pick,
+ onChange: onDateTimeChange
+ };
+
+ let wrapper;
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <IntlWrapper>
+ <Provider store={store}>
+ <EffectTimeConfigurator {...props} />
+ </Provider>
+ </IntlWrapper>
+ );
+ }, `EffectTimeConfigurator should not fail`);
+
+ // Internal UTC timestamp should take time zone into account
+ wrapper
+ .find('.react-time-picker__inputGroup__hour')
+ .at(0)
+ .simulate('change', {target: {value: '20', name: 'hour24'}})
+ // Call twice to propagate chagne in date-time-picker
+ .simulate('change', {target: {value: '20', name: 'hour24'}});
+ t.deepEqual(
+ onDateTimeChange.getCall(1).args[0],
+ {timestamp: 1690848180000},
+ `time changed & timezone taken into account`
+ );
+
+ t.end();
+});
+
+test('Components -> EffectTimeConfigurator -> date with custom timezone update', t => {
+ const store = mockStore(ititialState);
+
+ const onDateTimeChange = sinon.spy();
+ const props = {
+ timestamp: 1690840980000,
+ timezone: 'America/Barbados',
+ timeMode: LIGHT_AND_SHADOW_EFFECT_TIME_MODES.pick,
+ onChange: onDateTimeChange
+ };
+
+ let wrapper;
+ t.doesNotThrow(() => {
+ wrapper = mountWithTheme(
+ <IntlWrapper>
+ <Provider store={store}>
+ <EffectTimeConfigurator {...props} />
+ </Provider>
+ </IntlWrapper>
+ );
+ }, `EffectTimeConfigurator should not fail`);
+
+ // Internal UTC timestamp should take time zone into account
+ wrapper
+ .find('input')
+ .find('.react-date-picker__inputGroup__day')
+ .at(0)
+ .simulate('change', {target: {value: '10', name: 'day'}})
+ // Call twice to propagate chagne in date-time-picker
+ .simulate('change', {target: {value: '10', name: 'day'}});
+
+ t.deepEqual(
+ onDateTimeChange.getCall(1).args[0],
+ {timestamp: 1689026580000},
+ `date changed & timezone taken into account`
+ );
+
+ t.end();
+});
diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.js
index e7a37afaf..e42696775 100644
--- a/test/helpers/mock-state.js
+++ b/test/helpers/mock-state.js
@@ -266,7 +266,7 @@ function mockStateWithEffects() {
},
{
action: VisStateActions.addEffect,
- payload: [{id: 'e_4', type: 'lightAndShadow', parameters: {timestamp: 100}}]
+ payload: [{id: 'e_4', type: 'lightAndShadow', parameters: {timestamp: 100, timezone: 'UTC'}}]
}
]);
return prepareState;
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index bee065d00..2f1ac2f42 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -5507,7 +5507,7 @@ test('#VisStateUpdater -> addEffect', t => {
VisStateActions.addEffect({
id: 'e_shadow',
type: 'lightAndShadow',
- parameters: {timestamp: 1689280466362}
+ parameters: {timestamp: 1689280466362, timezone: 'UTC'}
})
);
@@ -5520,6 +5520,7 @@ test('#VisStateUpdater -> addEffect', t => {
isEnabled: true,
parameters: {
timestamp: 1689280466362,
+ timezone: 'UTC',
timeMode: 'pick',
shadowIntensity: 0.5,
shadowColor: [0, 0, 0],
diff --git a/test/node/schemas/vis-state-schema-test.js b/test/node/schemas/vis-state-schema-test.js
index 215792fe6..24ce475f8 100644
--- a/test/node/schemas/vis-state-schema-test.js
+++ b/test/node/schemas/vis-state-schema-test.js
@@ -351,6 +351,7 @@ test('#visStateSchema -> v1 -> save load effects', t => {
isEnabled: true,
parameters: {
timestamp: 100,
+ timezone: 'UTC',
timeMode: 'pick',
shadowIntensity: 0.5,
shadowColor: [0, 0, 0],