Skip to content

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

[Feat] mobile bottom widget styling (#1930)

Jacob Wasilkowski49321f8711b5
diff --git a/package.json b/package.json
index 15978ce35..b569e04cc 100644
--- a/package.json
+++ b/package.json
@@ -65,7 +65,7 @@
"start:web": "yarn install-and-start -- website start",
"start:https": "yarn install-and-start -- examples/demo-app start-local-https",
"start:e2e": "yarn install-and-start -- examples/demo-app start-local-e2e",
- "build": "rm -fr dist && babel src/{actions,components,middleware,reducers,cloud-providers,connect,localization,tasks} --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
+ "build": "rm -fr dist && babel src/{actions,components,middleware,reducers,cloud-providers,localization,tasks} --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:umd": "webpack --config ./webpack/umd.js --progress --env.prod",
"build:types": "tsc --project tsconfig.production.json",
"analyze": "yarn analyze:bundle",
@@ -368,4 +368,4 @@
"node": "12.22.12",
"yarn": "1.22.19"
}
-}
\ No newline at end of file
+}
diff --git a/src/components/src/bottom-widget.tsx b/src/components/src/bottom-widget.tsx
index 374faaae3..770d8be63 100644
--- a/src/components/src/bottom-widget.tsx
+++ b/src/components/src/bottom-widget.tsx
@@ -24,8 +24,8 @@ import TimeWidgetFactory from './filters/time-widget';
import AnimationControlFactory from './common/animation-control/animation-control';
import AnimationControllerFactory from './common/animation-control/animation-controller';
import {ANIMATION_WINDOW, DIMENSIONS, FILTER_TYPES} from '@kepler.gl/constants';
-import {getIntervalBins} from '@kepler.gl/utils';
-import {media} from '@kepler.gl/styles';
+import {getIntervalBins, hasPortableWidth} from '@kepler.gl/utils';
+import {media, breakPointValues} from '@kepler.gl/styles';
import {AnimationConfig, TimeRangeFilter} from '@kepler.gl/types';
import {bottomWidgetSelector} from './kepler-gl';
@@ -142,6 +142,7 @@ export function LayerAnimationControllerFactory(
}
type BottomWidgetProps = {
+ rootRef: React.ForwardedRef<HTMLDivElement>;
containerW: number;
} & ReturnType<typeof bottomWidgetSelector>;
@@ -168,7 +169,8 @@ export default function BottomWidgetFactory(
containerW,
uiState,
sidePanelWidth,
- layers
+ layers,
+ rootRef
} = props;
const {activeSidePanel, readOnly} = uiState;
@@ -178,6 +180,9 @@ export default function BottomWidgetFactory(
() => filters.findIndex(f => f.enlarged && f.type === FILTER_TYPES.timeRange),
[filters]
);
+
+ const isMobile = hasPortableWidth(breakPointValues);
+
const animatedFilterIdx = useMemo(() => filters.findIndex(f => f.isAnimating), [filters]);
const animatedFilter = animatedFilterIdx > -1 ? filters[animatedFilterIdx] : null;
@@ -188,7 +193,7 @@ export default function BottomWidgetFactory(
: 0;
const enlargedFilterWidth =
- (isOpen ? containerW - sidePanelWidth : containerW) - spaceForLegendWidth;
+ (isOpen && !isMobile ? containerW - sidePanelWidth : containerW) - spaceForLegendWidth;
// show playback control if layers contain trip layer & at least one trip layer is visible
const animatableLayer = useMemo(
@@ -215,6 +220,7 @@ export default function BottomWidgetFactory(
style={{marginRight: spaceForLegendWidth}}
className="bottom-widget--container"
hasPadding={showAnimationControl || showTimeWidget}
+ ref={rootRef}
>
<LayerAnimationController
animationConfig={animationConfig}
diff --git a/src/components/src/common/animation-control/animation-control.tsx b/src/components/src/common/animation-control/animation-control.tsx
index 4528a7f91..e111a7e33 100644
--- a/src/components/src/common/animation-control/animation-control.tsx
+++ b/src/components/src/common/animation-control/animation-control.tsx
@@ -28,25 +28,58 @@ import PlaybackControlsFactory from './playback-controls';
import FloatingTimeDisplayFactory from './floating-time-display';
import {datetimeFormatter, snapToMarks} from '@kepler.gl/utils';
import {DEFAULT_TIME_FORMAT} from '@kepler.gl/constants';
+import {media} from '@kepler.gl/styles';
+
+const SLIDER_MARGIN_PALM = 6;
const SliderWrapper = styled.div`
display: flex;
position: relative;
flex-grow: 1;
- margin-right: 24px;
- margin-left: 24px;
+ margin: 0 24px;
+
+ ${media.palm`
+ margin: 0 ${SLIDER_MARGIN_PALM}px;
+ `}
`;
const AnimationWidgetInner = styled.div`
position: relative;
display: flex;
align-items: center;
- height: 32px;
+ .animation-control__time-slider {
+ display: flex;
+ align-items: center;
+ height: 32px;
+ width: 100%;
+ }
.playback-controls {
margin-left: -8px;
margin-right: 16px;
}
+
+ ${media.palm`
+ flex-direction: column;
+ .playback-controls {
+ margin: 0;
+ }
+ .animation-control__time-slider {
+ width: 100%;
+ position: relative;
+ }
+ .animation-control__time-domain {
+ position: absolute;
+ top: -24px;
+
+ &.domain-start {
+ left: ${SLIDER_MARGIN_PALM}px;
+ }
+ &.domain-end {
+ right: ${SLIDER_MARGIN_PALM}px;
+ }
+ }
+ `};
`;
const StyledDomain = styled.div.attrs(props => ({
@@ -116,23 +149,25 @@ function AnimationControlFactory(
isAnimatable={isAnimatable}
updateAnimationSpeed={updateAnimationSpeed}
/>
- <StyledDomain className="domain-start">
- <span>{timeStart}</span>
- </StyledDomain>
- <SliderWrapper className="animation-control__slider">
- <Slider
- isRanged={false}
- step={step}
- minValue={domain ? domain[0] : 0}
- maxValue={domain ? domain[1] : 1}
- value1={currentTime}
- onSlider1Change={onSlider1Change}
- enableBarDrag={true}
- />
- </SliderWrapper>
- <StyledDomain className="domain-end">
- <span>{timeEnd}</span>
- </StyledDomain>
+ <div className="animation-control__time-slider">
+ <StyledDomain className="domain-start">
+ <span>{timeStart}</span>
+ </StyledDomain>
+ <SliderWrapper className="animation-control__slider">
+ <Slider
+ isRanged={false}
+ step={step}
+ minValue={domain ? domain[0] : 0}
+ maxValue={domain ? domain[1] : 1}
+ value1={currentTime}
+ onSlider1Change={onSlider1Change}
+ enableBarDrag={true}
+ />
+ </SliderWrapper>
+ <StyledDomain className="domain-end">
+ <span>{timeEnd}</span>
+ </StyledDomain>
+ </div>
</AnimationWidgetInner>
<FloatingTimeDisplay
currentTime={currentTime}
diff --git a/src/components/src/common/range-plot.tsx b/src/components/src/common/range-plot.tsx
index 2b73014ca..ea1140ac7 100644
--- a/src/components/src/common/range-plot.tsx
+++ b/src/components/src/common/range-plot.tsx
@@ -23,7 +23,8 @@ import styled, {withTheme} from 'styled-components';
import RangeBrushFactory, {OnBrush, RangeBrushProps} from './range-brush';
import HistogramPlotFactory from './histogram-plot';
import LineChartFactory, {HoverDP} from './line-chart';
-import {isTest} from '@kepler.gl/utils';
+import {isTest, hasMobileWidth} from '@kepler.gl/utils';
+import {breakPointValues} from '@kepler.gl/styles';
import {LineChart} from '@kepler.gl/types';
const StyledRangePlot = styled.div`
@@ -71,7 +72,11 @@ export default function RangePlotFactory(
const [brushing, setBrushing] = useState(false);
const [hoveredDP, onMouseMove] = useState<HoverDP | null>(null);
const [enableChartHover, setEnableChartHover] = useState(false);
- const height = isEnlarged ? theme.rangePlotHLarge : theme.rangePlotH;
+ const height = isEnlarged
+ ? hasMobileWidth(breakPointValues)
+ ? theme.rangePlotHLargePalm
+ : theme.rangePlotHLarge
+ : theme.rangePlotH;
const onBrushStart = useCallback(() => {
setBrushing(true);
@@ -128,7 +133,13 @@ export default function RangePlotFactory(
return (
<StyledRangePlot
style={{
- height: `${isEnlarged ? theme.rangePlotContainerHLarge : theme.rangePlotContainerH}px`
+ height: `${
+ isEnlarged
+ ? hasMobileWidth(breakPointValues)
+ ? theme.rangePlotContainerHLargePalm
+ : theme.rangePlotContainerHLarge
+ : theme.rangePlotContainerH
+ }px`
}}
className="kg-range-slider__plot"
>
diff --git a/src/components/src/common/styled-components.tsx b/src/components/src/common/styled-components.tsx
index 827600bb5..4317b81df 100644
--- a/src/components/src/common/styled-components.tsx
+++ b/src/components/src/common/styled-components.tsx
@@ -539,8 +539,16 @@ export const StyledAttrbution = styled.div.attrs({
right: 0;
position: absolute;
display: block;
- margin: 0 10px 2px;
+ margin: 0 10px 6px;
z-index: 0;
+ .attrition-link {
+ display: flex;
+ align-items: center;
+
+ a {
+ margin-right: 2px;
+ }
+ }
.attrition-logo {
display: flex;
@@ -548,16 +556,25 @@ export const StyledAttrbution = styled.div.attrs({
justify-content: flex-end;
align-items: center;
color: ${props => props.theme.labelColor};
- margin-bottom: -4px;
a.mapboxgl-ctrl-logo {
width: 72px;
- margin-left: 6px;
+ margin-left: 4px;
}
}
a {
font-size: 10px;
}
+
+ ${media.palm`
+ .attrition-logo a {
+ width: 60px;
+ }
+
+ .attrition-link {
+ line-height: 1em;
+ }
+ `};
`;
export interface StyledExportSectionProps {
@@ -666,6 +683,13 @@ export const BottomWidgetInner = styled.div`
padding: ${props => `${props.theme.bottomInnerPdVert}px ${props.theme.bottomInnerPdSide}px`};
position: relative;
margin-top: ${props => props.theme.bottomPanelGap}px;
+
+ ${media.portable`
+ border-top: 1px solid ${props => props.theme.panelBorderColor};
+ border-left: 1px solid ${props => props.theme.panelBorderColor};
+ padding: 12px 12px;
+ margin-top: 0;
+ `}
`;
interface MapControlButtonProps {
diff --git a/src/components/src/index.ts b/src/components/src/index.ts
index 9d75afa79..88a130660 100644
--- a/src/components/src/index.ts
+++ b/src/components/src/index.ts
@@ -40,7 +40,7 @@ export {default as KeplerGl, default, injectComponents, ContainerFactory, ERROR_
export {default as KeplerGlFactory, DEFAULT_KEPLER_GL_PROPS, getVisibleDatasets, mapFieldsSelector, plotContainerSelector} from './kepler-gl';
export {default as SidePanelFactory} from './side-panel';
export {default as PanelTitleFactory} from './side-panel/panel-title';
-export {default as MapContainerFactory, Attribution} from './map-container';
+export {default as MapContainerFactory} from './map-container';
export {default as MapsLayoutFactory} from './maps-layout';
export {
default as BottomWidgetFactory,
diff --git a/src/components/src/kepler-gl.tsx b/src/components/src/kepler-gl.tsx
index 559a6870e..e163e65f1 100644
--- a/src/components/src/kepler-gl.tsx
+++ b/src/components/src/kepler-gl.tsx
@@ -70,10 +70,11 @@ import {
validateToken,
mergeMessages,
observeDimensions,
- unobserveDimensions
+ unobserveDimensions,
+ hasPortableWidth
} from '@kepler.gl/utils';
-import {theme as basicTheme, themeLT, themeBS} from '@kepler.gl/styles';
+import {theme as basicTheme, themeLT, themeBS, breakPointValues} from '@kepler.gl/styles';
import {KeplerGlState} from '@kepler.gl/reducers';
import {Provider} from '@kepler.gl/cloud-providers';
@@ -356,7 +357,7 @@ function KeplerGlFactory(
static contextType = RootContext;
root = createRef<HTMLDivElement>();
- bottomWidgetRef = createRef();
+ bottomWidgetRef = createRef<HTMLDivElement>();
/* selectors */
themeSelector = props => props.theme;
@@ -485,9 +486,9 @@ function KeplerGlFactory(
<MapsLayout className="maps">{mapContainers}</MapsLayout>
{isExportingImage && <PlotContainer {...plotContainerFields} />}
{interactionConfig.geocoder.enabled && <GeoCoderPanel {...geoCoderPanelFields} />}
- <BottomWidgetOuter absolute>
+ <BottomWidgetOuter absolute={!hasPortableWidth(breakPointValues)}>
<BottomWidget
- ref={this.bottomWidgetRef}
+ rootRef={this.bottomWidgetRef}
{...bottomWidgetFields}
containerW={dimensions.width}
/>
diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsx
index 0d4e38cc0..582f3fc0e 100644
--- a/src/components/src/map-container.tsx
+++ b/src/components/src/map-container.tsx
@@ -48,8 +48,10 @@ import {
setLayerBlending,
transformRequest,
observeDimensions,
- unobserveDimensions
+ unobserveDimensions,
+ hasMobileWidth
} from '@kepler.gl/utils';
+import {breakPointValues} from '@kepler.gl/styles';
// default-settings
import {FILTER_TYPES, GEOCODER_LAYER_ID, THROTTLE_NOTIFICATION_TIME} from '@kepler.gl/constants';
@@ -90,34 +92,42 @@ const MAPBOXGL_STYLE_UPDATE = 'style.load';
const MAPBOXGL_RENDER = 'render';
const nop = () => {};
-export const Attribution = () => (
- <StyledAttrbution>
- <div className="attrition-logo">
- Basemap by:
- <a
- className="mapboxgl-ctrl-logo"
- target="_blank"
- rel="noopener noreferrer"
- href="https://www.mapbox.com/"
- aria-label="Mapbox logo"
- />
- </div>
- <div className="attrition-link">
- <a href="https://kepler.gl/policy/" target="_blank" rel="noopener noreferrer">
- © kepler.gl |{' '}
- </a>
- <a href="https://www.mapbox.com/about/maps/" target="_blank" rel="noopener noreferrer">
- © Mapbox |{' '}
- </a>
- <a href="http://www.openstreetmap.org/copyright" target="_blank" rel="noopener noreferrer">
- © OpenStreetMap |{' '}
- </a>
- <a href="https://www.mapbox.com/map-feedback/" target="_blank" rel="noopener noreferrer">
- <strong>Improve this map</strong>
- </a>
- </div>
- </StyledAttrbution>
+const MapboxLogo = () => (
+ <div className="attrition-logo">
+ Basemap by:
+ <a
+ className="mapboxgl-ctrl-logo"
+ target="_blank"
+ rel="noopener noreferrer"
+ href="https://www.mapbox.com/"
+ aria-label="Mapbox logo"
+ />
+ </div>
);
+export const Attribution = () => {
+ const isPalm = hasMobileWidth(breakPointValues);
+ return (
+ <StyledAttrbution>
+ {isPalm ? <MapboxLogo /> : null}
+ <div className="attrition-link">
+ <a href="https://kepler.gl/policy/" target="_blank" rel="noopener noreferrer">
+ © kepler.gl |{' '}
+ </a>
+ <a href="https://www.mapbox.com/about/maps/" target="_blank" rel="noopener noreferrer">
+ © Mapbox |{' '}
+ </a>
+ <a href="http://www.openstreetmap.org/copyright" target="_blank" rel="noopener noreferrer">
+ © OpenStreetMap |{' '}
+ </a>
+ <a href="https://www.mapbox.com/map-feedback/" target="_blank" rel="noopener noreferrer">
+ <strong>Improve this map </strong>
+ {!isPalm ? <strong> | </strong> : null}
+ </a>
+ {!isPalm ? <MapboxLogo /> : null}
+ </div>
+ </StyledAttrbution>
+ );
+};
MapContainerFactory.deps = [MapPopoverFactory, MapControlFactory, EditorFactory];
diff --git a/src/components/src/map/map-control-panel.tsx b/src/components/src/map/map-control-panel.tsx
index 98bded733..904e30328 100644
--- a/src/components/src/map/map-control-panel.tsx
+++ b/src/components/src/map/map-control-panel.tsx
@@ -100,9 +100,10 @@ function MapControlPanelFactory() {
logoComponent
}) => (
<StyledMapControlPanel
+ className="map-control-panel"
style={{
transform: `scale(${scale})`,
- marginBottom: '8px'
+ marginBottom: '8px !important'
}}
>
<StyledMapControlPanelHeader>
diff --git a/src/components/src/map/map-legend-panel.tsx b/src/components/src/map/map-legend-panel.tsx
index 654057d89..a425839b6 100644
--- a/src/components/src/map/map-legend-panel.tsx
+++ b/src/components/src/map/map-legend-panel.tsx
@@ -31,6 +31,7 @@ import {createPortal} from 'react-dom';
import {DIMENSIONS} from '@kepler.gl/constants';
import {MapControl, MapControls} from '@kepler.gl/types';
import {Layer} from '@kepler.gl/layers';
+import {media} from '@kepler.gl/styles';
MapLegendPanelFactory.deps = [MapControlTooltipFactory, MapControlPanelFactory, MapLegendFactory];
@@ -38,6 +39,15 @@ const PinToBottom = styled.div`
position: absolute;
bottom: ${DIMENSIONS.mapControl.mapLegend.pinned.bottom}px;
right: ${DIMENSIONS.mapControl.mapLegend.pinned.right}px;
+ ${media.portable`
+ bottom: 0px;
+ right: 0px;
+ min-width: ${DIMENSIONS.mapControl.width + DIMENSIONS.mapControl.mapLegend.pinned.right}px;
+ .map-control-panel {
+ min-height: 215px;
+ margin-bottom: 0px;
+ };
+ `};
`;
interface MapLegendPanelIcons {
diff --git a/src/styles/src/base.ts b/src/styles/src/base.ts
index bfeda02c0..ce5bb037e 100644
--- a/src/styles/src/base.ts
+++ b/src/styles/src/base.ts
@@ -301,6 +301,7 @@ export const sidepanelDividerHeight = 12;
export const bottomInnerPdSide = 32;
export const bottomInnerPdVert = 6;
export const bottomPanelGap = 20;
+export const bottomPanelGapPalm = 20;
export const bottomWidgetPaddingTop = 20;
export const bottomWidgetPaddingRight = 20;
export const bottomWidgetPaddingBottom = 30;
@@ -370,7 +371,9 @@ export const rangePlotMarginLarge = {top: 18, bottom: 0, left: 0, right: 0};
export const rangePlotH = 62;
export const rangePlotContainerH = 78;
export const rangePlotHLarge = 102;
+export const rangePlotHLargePalm = 102;
export const rangePlotContainerHLarge = 120;
+export const rangePlotContainerHLargePalm = 120;
// Notification
export const notificationColors = {
@@ -1365,6 +1368,7 @@ export const theme = {
bottomInnerPdSide,
bottomInnerPdVert,
bottomPanelGap,
+ bottomPanelGapPalm,
bottomWidgetPaddingTop,
bottomWidgetPaddingRight,
bottomWidgetPaddingBottom,
@@ -1409,8 +1413,10 @@ export const theme = {
rangePlotMarginLarge,
rangePlotH,
rangePlotHLarge,
+ rangePlotHLargePalm,
rangePlotContainerH,
rangePlotContainerHLarge,
+ rangePlotContainerHLargePalm,
// Notifications
notificationColors,
diff --git a/src/styles/src/media-breakpoints.ts b/src/styles/src/media-breakpoints.ts
index 876ebd61d..e24ce6950 100644
--- a/src/styles/src/media-breakpoints.ts
+++ b/src/styles/src/media-breakpoints.ts
@@ -21,7 +21,7 @@
import {css} from 'styled-components';
// These are useful for test or when theme doesn't define them
-const breakPoints = {
+export const breakPointValues = {
palm: 588,
desk: 768
};
@@ -37,19 +37,19 @@ const breakPoints = {
export const media = {
palm: (first, ...args) => css`
- @media (max-width: ${props => (props.theme.breakPoints || breakPoints).palm}px) {
+ @media (max-width: ${props => (props.theme.breakPoints || breakPointValues).palm}px) {
${css(first, ...args)};
}
`,
portable: (first, ...args) => css`
- @media (max-width: ${props => (props.theme.breakPoints || breakPoints).desk}px) {
+ @media (max-width: ${props => (props.theme.breakPoints || breakPointValues).desk}px) {
${css(first, ...args)};
}
`,
desk: (first, ...args) => css`
- @media (min-width: ${props => (props.theme.breakPoints || breakPoints).desk + 1}px) {
+ @media (min-width: ${props => (props.theme.breakPoints || breakPointValues).desk + 1}px) {
${css(first, ...args)};
}
`
diff --git a/src/utils/src/index.ts b/src/utils/src/index.ts
index 2cdf5c660..9f4b710c4 100644
--- a/src/utils/src/index.ts
+++ b/src/utils/src/index.ts
@@ -142,7 +142,9 @@ export {
arrayInsert,
isTest,
filterObjectByPredicate,
- isFunction
+ isFunction,
+ hasMobileWidth,
+ hasPortableWidth
} from './utils';
export {
addNewLayersToSplitMap,
diff --git a/src/utils/src/utils.ts b/src/utils/src/utils.ts
index a820ff2df..03a940f44 100644
--- a/src/utils/src/utils.ts
+++ b/src/utils/src/utils.ts
@@ -180,6 +180,16 @@ export function arrayInsert(arr, index, val) {
return [...arr.slice(0, index), val, ...arr.slice(index)];
}
+export function hasMobileWidth(breakPointValues) {
+ const mobileWidth = window.matchMedia(`(max-width: ${breakPointValues.palm}px)`);
+ return mobileWidth.matches;
+}
+
+export function hasPortableWidth(breakPointValues) {
+ const mobileWidth = window.matchMedia(`(max-width: ${breakPointValues.desk}px)`);
+ return mobileWidth.matches;
+}
+
export function isTest() {
return process?.env?.NODE_ENV === 'test';
}
diff --git a/test/setup-browser-env.js b/test/setup-browser-env.js
index 02eb0e381..f6305d67f 100644
--- a/test/setup-browser-env.js
+++ b/test/setup-browser-env.js
@@ -49,6 +49,24 @@ Object.defineProperty(window, 'prompt', {
writable: true
});
+// TODO: This should be the right wat to mock matchMedia but matchMedia was still undefined so I moved to another way to mock it
+
+// Object.defineProperty(window, 'matchMedia', {
+// value: () => ({
+// matches: false,
+// addListener: function() {},
+// removeListener: function() {}
+// }),
+// writable: true
+// });
+window.matchMedia = () => {
+ return {
+ matches: false,
+ addListener: () => {},
+ removeListener: () => {}
+ };
+};
+
function mockClipboardData() {
let data = null;
const obj = {};