Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
Add export image module
Javid Hsueha5a4c484a5fc
diff --git a/src/actions/ui-state-actions.js b/src/actions/ui-state-actions.jsnew file mode 100644index 000000000..3b809c986--- /dev/null+++ b/src/actions/ui-state-actions.js@@ -0,0 +1,74 @@+// Copyright (c) 2018 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 {createAction} from 'redux-actions';+import ActionTypes from 'constants/action-types';++const {+ CLEANUP_EXPORT_IMAGE,+ OPEN_DELETE_MODAL,+ SET_EXPORT_DATA_TYPE,+ SET_EXPORT_FILTERED,+ SET_EXPORT_IMAGE_DATA_URI,+ SET_EXPORT_SELECTED_DATASET,+ SET_RATIO,+ SET_RESOLUTION,+ START_EXPORTING_IMAGE,+ TOGGLE_LEGEND,+ TOGGLE_MODAL,+ TOGGLE_SIDE_PANEL+} = ActionTypes;++// second argument of createAction is expected to be payloadCreator or undefined+const [+ toggleSidePanel,+ toggleModal,+ openDeleteModal,+ // export image+ setRatio,+ setResolution,+ toggleLegend,+ startExportingImage,+ setExportImageDataUri,+ cleanupExportImage,+ // export data+ setExportSelectedDataset,+ setExportDataType,+ setExportFiltered+] = [+ TOGGLE_SIDE_PANEL,+ TOGGLE_MODAL,+ OPEN_DELETE_MODAL,+ SET_RATIO,+ SET_RESOLUTION,+ TOGGLE_LEGEND,+ START_EXPORTING_IMAGE,+ SET_EXPORT_IMAGE_DATA_URI,+ CLEANUP_EXPORT_IMAGE,+ SET_EXPORT_SELECTED_DATASET,+ SET_EXPORT_DATA_TYPE,+ SET_EXPORT_FILTERED+].map(a => createAction(a));++export {+ toggleSidePanel, toggleModal, openDeleteModal,+ setRatio, setResolution, toggleLegend, startExportingImage, setExportImageDataUri, cleanupExportImage,+ setExportSelectedDataset, setExportDataType, setExportFiltered+};diff --git a/src/components/common/icons/file-type.js b/src/components/common/icons/file-type.jsnew file mode 100644index 000000000..cc49d5c18--- /dev/null+++ b/src/components/common/icons/file-type.js@@ -0,0 +1,57 @@+// Copyright (c) 2018 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 {File} from 'components/common/icons';++const FileNameTag = styled.div`+ background-color: currentColor;+ border-radius: 1px;+ display: inline-block;+ padding: 0 4px;+ position: absolute;+ top: 45%;+ left: 10%;++ .text {+ color: white;+ font-size: ${props => props.fontSize};+ }+`;++const FileTypeIconWrapper = styled.div`+ display: inline-block;+ position: relative;+ color: currentColor;+ height: ${props => props.height};+`;++const FileTypeIcon = ({ext, height, fontSize}) => (+ <FileTypeIconWrapper height={height}>+ <File height={height} />+ <FileNameTag fontSize={fontSize}>+ <div className="text">{ext}</div>+ </FileNameTag>+ </FileTypeIconWrapper>+);++export default FileTypeIcon;diff --git a/src/components/common/loading-spinner.js b/src/components/common/loading-spinner.jsnew file mode 100644index 000000000..cef17ac5d--- /dev/null+++ b/src/components/common/loading-spinner.js@@ -0,0 +1,52 @@+// Copyright (c) 2018 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, {keyframes} from 'styled-components';++const animationName = keyframes`+ 0% {+ transform: rotate(0deg);+ }+ 100% {+ transform: rotate(360deg);+ }+`;++const Loader = styled.span`+ border-left-color: rgb(198, 198, 198);+ border-top-color: rgb(198, 198, 198);+ height: 32px;+ width: 32px;+ animation: _preloader_spin_ 500ms linear infinite;+ border-radius: 50%;+ border-bottom-color: transparent;+ border-right-color: transparent;+ cursor: wait;+ border-style: solid;+ display: block;+ animation-name: ${animationName};+}`;++const LoadingSpinner = () => (+ <Loader/>+);++export default LoadingSpinner;diff --git a/src/components/modals/export-image-modal.js b/src/components/modals/export-image-modal.jsnew file mode 100644index 000000000..9180e2bcb--- /dev/null+++ b/src/components/modals/export-image-modal.js@@ -0,0 +1,211 @@+// Copyright (c) 2018 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 styled from 'styled-components';++import {calculateExportImageSize} from 'utils/export-image-utils';+import {+ RATIO_OPTIONS,+ RATIOS,+ RESOLUTION_OPTIONS+} from 'constants/default-settings';+import LoadingSpinner from 'components/common/loading-spinner';++const ImageOptionList = styled.div`+ display: flex;+ flex-direction: column;+ justify-content: space-around;+ width: 250px;++ .image-option-section {+ .image-option-section-title {+ font-weight: 500;+ font-size: 14px;+ }+ }++ .button-list {+ display: flex;+ flex-direction: row;+ padding: 8px 0px;+ }++ input {+ margin-right: 8px;+ }+`;++const PreviewImageSection = styled.div`+ align-items: center;+ display: flex;+ flex-direction: column;+ flex: 1;+ justify-content: center;+ padding: 30px;++ .dimension, .instruction {+ padding: 8px 0px;+ }++ .preview-image {+ background: #e2e2e2;+ border-radius: 4px;+ box-shadow: 0 8px 16px 0 rgba(0,0,0,0.18);+ width: 100%;+ padding-bottom: ${props => props.ratio === RATIOS.SCREEN ?+ `${100 * props.height/props.width}%`:+ (props.ratio === RATIOS.SIXTEEN_BY_NINE ? '56.25%' : '75%')+ };+ position: relative;+ }++ .preview-image-placeholder {+ position: absolute;+ top: 0;+ left: 0;+ width: 100%;+ height: 100%;+ }++ .preview-image-spinner {+ position: absolute;+ left: calc(50% - 25px);+ top: calc(50% - 25px);+ }+`;++const Button = 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};+ cursor: pointer;+ font-weight: 500;+ margin-right: 6px;+ padding: 6px 10px;++ :hover {+ color: ${props => props.available && props.theme.primaryBtnBgd};+ border: 1px solid ${props => props.available && props.theme.primaryBtnBgd};+ }+`;++const StyledExportImageModal = styled.div`+ background: ${props => props.theme.panelBackgroundLT};+ display: flex;+ flex-direction: row;+ font-size: 10px;+ margin: 0 -20px;+ padding: 30px 80px;+`;++class ExportImageModal extends Component {++ static propTypes = {+ height: PropTypes.number.isRequired,+ ratio: PropTypes.string.isRequired,+ resolution: PropTypes.string.isRequired,+ width: PropTypes.number.isRequired,+ exporting: PropTypes.bool.isRequired,+ imageDataUri: PropTypes.string,+ // callbacks+ onChangeRatio: PropTypes.func.isRequired,+ onChangeResolution: PropTypes.func.isRequired,+ onToggleLegend: PropTypes.func.isRequired+ };++ render() {+ const {+ height,+ legend,+ ratio,+ resolution,+ width,+ exporting,+ imageDataUri,+ // callbacks:+ onChangeRatio,+ onChangeResolution,+ onToggleLegend+ } = this.props;++ const exportImageSize = calculateExportImageSize({+ width, height, ratio, resolution+ });++ return (+ <div className="export-image-modal">+ <StyledExportImageModal>+ <ImageOptionList>+ <div className="image-option-section">+ <div className="image-option-section-title">Ratio</div>+ Choose the ratio for various usages.+ <div className="button-list">+ {RATIO_OPTIONS.map(op =>+ <Button+ key={op.id}+ selected={ratio === op.id}+ onClick={() => onChangeRatio({ratio: op.id})}+ >+ {op.label}+ </Button>+ )}+ </div>+ </div>+ <div className="image-option-section">+ <div className="image-option-section-title">Resolution</div>+ For print choose 2x (available soon). For digital use choose 1x.+ <div className="button-list">+ {RESOLUTION_OPTIONS.map(op =>+ <Button+ key={op.id}+ selected={resolution === op.id}+ onClick={() => op.available && onChangeResolution({resolution: op.id})}+ >+ {op.label}+ </Button>+ )}+ </div>+ </div>+ <div className="image-option-section">+ <div className="image-option-section-title">Map Legend</div>+ <input type="checkbox" disabled checked={legend} onClick={onToggleLegend}/>+ Add legend on map+ </div>+ </ImageOptionList>+ <PreviewImageSection ratio={ratio} width={width} height={height}>+ <div className="dimension">{`${exportImageSize.width} x ${exportImageSize.height}`}</div>+ <div className="preview-image">+ {exporting ?+ <div className="preview-image-spinner"><LoadingSpinner /></div> :+ <img className="preview-image-placeholder" src={imageDataUri} />+ }+ </div>+ <div className="instruction">Or drag and drop to export immediately</div>+ </PreviewImageSection>+ </StyledExportImageModal>+ </div>+ );+ }+}++const ExportImageModalFactory = () => ExportImageModal;+export default ExportImageModalFactory;diff --git a/src/components/plot-container.js b/src/components/plot-container.jsnew file mode 100644index 000000000..56fa71e88--- /dev/null+++ b/src/components/plot-container.js@@ -0,0 +1,119 @@+// Copyright (c) 2018 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.++// libraries+import React, {Component} from 'react';+import PropTypes from 'prop-types';+import {setTimeout} from 'global/window';++import MapContainerFactory from './map-container';+import {RATIOS, WAIT_FOR_LOADING} from 'constants/default-settings';+import {calculateExportImageSize, convertToPng} from 'utils/export-image-utils';++const propTypes = {+ width: PropTypes.number.isRequired,+ height: PropTypes.number.isRequired,+ exportImageSetting: PropTypes.object.isRequired,+ mapFields: PropTypes.object.isRequired+};++PlotContainerFactory.deps = [MapContainerFactory];++export default function PlotContainerFactory(MapContainer) {+ class PlotContainer extends Component {++ componentDidMount() {+ this._retrieveNewScreenshot();+ }++ componentWillReceiveProps(newProps) {+ // re-fetch the new screenshot only when ratio or resolution changes+ if (+ this.props.exportImageSetting.ratio !== newProps.exportImageSetting.ratio ||+ this.props.exportImageSetting.resolution !== this.props.exportImageSetting.resolution+ ) {+ this._retrieveNewScreenshot();+ }+ }++ _retrieveNewScreenshot = () => {+ this.props.startExportingImage();+ // Quick hack: wait for few seconds to load the map tiles and deck.gl layers.+ // TODO: we should hook up with the map loaded event+ // https://www.mapbox.com/mapbox-gl-js/api/#mapdataevent+ // and the "onAfterRender" event from deck.gl+ setTimeout(() => {+ convertToPng(this.plottingAreaRef).then(+ dataUri => this.props.setExportImageDataUri({dataUri})+ );+ }, WAIT_FOR_LOADING);+ };++ render() {+ const {width, height, exportImageSetting, mapFields} = this.props;+ const {ratio, resolution} = exportImageSetting;+ // const {exportImageSetting} = exportImageSetting; <= not used yet.+ const exportImageSize = calculateExportImageSize({+ width, height, ratio, resolution+ });++ const exportRatio = ratio === RATIOS.ONE_X ? 1 : 2;++ // TODO: should override the map style accoring to the exportRatio+ const mapboxStyle = mapFields.mapStyle;++ // figure out how to turn on legend through mapProps+ const mapProps = {+ ...mapFields,+ mapboxStyle,+ mapState: {+ ...mapFields.mapState,+ zoom: mapFields.mapState.zoom + Math.log2(exportRatio),+ width: exportImageSize.width,+ height: exportImageSize.height+ },+ mapStateActions: {+ ...mapFields.mapStateActions,+ updateMap: () => {}+ }+ };++ return (+ <div style={{position: 'absolute', top: -9999, left: -9999}}>+ <div+ ref={element => {this.plottingAreaRef = element}}+ style={{+ width: exportImageSize.width,+ height: exportImageSize.height+ }}+ >+ <MapContainer+ index={0}+ {...mapProps}+ />+ </div>+ </div>+ );+ }+ }++ PlotContainer.propsTypes = propTypes;+ return PlotContainer;+}diff --git a/src/reducers/ui-state-updaters.js b/src/reducers/ui-state-updaters.jsnew file mode 100644index 000000000..5cc5b1626--- /dev/null+++ b/src/reducers/ui-state-updaters.js@@ -0,0 +1,129 @@+// Copyright (c) 2018 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 {LAYER_CONFIG_ID, DELETE_DATA_ID} from 'constants/default-settings';++/* Updaters */+export const toggleSidePanelUpdater = (state, {payload: id}) => {+ if (id === state.activeSidePanel) {+ return state;+ }++ if (id === LAYER_CONFIG_ID) {+ return {+ ...state,+ currentModal: id+ };+ }++ return {+ ...state,+ activeSidePanel: id+ };+};++export const toggleModalUpdater = (state, {payload: id}) => ({+ ...state,+ currentModal: id+});++export const openDeleteModalUpdater = (+ state,+ {payload: datasetKeyToRemove}+) => ({+ ...state,+ currentModal: DELETE_DATA_ID,+ datasetKeyToRemove+});++export const toggleLegendUpdater = state => ({+ ...state,+ exportImage: {+ ...state.exportImage,+ legend: !state.legend+ }+});++export const setRatioUpdater = (state, {payload}) => ({+ ...state,+ exportImage: {+ ...state.exportImage,+ ratio: payload.ratio+ }+});++export const setResolutionUpdater = (state, {payload}) => ({+ ...state,+ exportImage: {+ ...state.exportImage,+ resolution: payload.resolution+ }+});++export const startExportingImage = state => ({+ ...state,+ exportImage: {+ ...state.exportImage,+ exporting: true,+ imageDataUri: ''+ }+});++export const setExportImageDataUri = (state, {payload}) => ({+ ...state,+ exportImage: {+ ...state.exportImage,+ exporting: false,+ imageDataUri: payload.dataUri+ }+});++export const cleanupExportImage = state => ({+ ...state,+ exportImage: {+ ...state.exportImage,+ exporting: false,+ imageDataUri: ''+ }+});++export const setExportSelectedDatasetUpdater = (state, {payload}) => ({+ ...state,+ exportData: {+ ...state.exportData,+ selectedDataset: payload.dataset+ }+});++export const setExportDataTypeUpdater = (state, {payload}) => ({+ ...state,+ exportData: {+ ...state.exportData,+ dataType: payload.dataType+ }+});++export const setExportFilteredUpdater = (state, {payload}) => ({+ ...state,+ exportData: {+ ...state.exportData,+ filtered: payload.filtered+ }+});diff --git a/src/reducers/ui-state.js b/src/reducers/ui-state.jsnew file mode 100644index 000000000..184730461--- /dev/null+++ b/src/reducers/ui-state.js@@ -0,0 +1,91 @@+// Copyright (c) 2018 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 {handleActions} from 'redux-actions';+import ActionTypes from 'constants/action-types';+import {+ ADD_DATA_ID,+ EXPORT_DATA_TYPE,+ RATIOS,+ RESOLUTIONS+} from 'constants/default-settings';+import {+ openDeleteModalUpdater,+ toggleModalUpdater,+ toggleSidePanelUpdater,+ // export image+ cleanupExportImage,+ setExportImageDataUri,+ setRatioUpdater,+ setResolutionUpdater,+ startExportingImage,+ toggleLegendUpdater,+ // export data+ setExportSelectedDatasetUpdater,+ setExportDataTypeUpdater,+ setExportFilteredUpdater+} from './ui-state-updaters';++export const INITIAL_UI_STATE = {+ readOnly: false,+ activeSidePanel: 'layer',+ currentModal: ADD_DATA_ID,+ datasetKeyToRemove: null,++ // export image modal ui+ exportImage: {+ // user options+ ratio: RATIOS.SCREEN,+ resolution: RESOLUTIONS.ONE_X,+ legend: false,+ // exporting state+ imageDataUri: '',+ exporting: false+ },+ // export data modal ui+ exportData: {+ selectedDataset: '',+ dataType: EXPORT_DATA_TYPE.CSV,+ filtered: true+ }+};++const actionHandler = {+ [ActionTypes.TOGGLE_SIDE_PANEL]: toggleSidePanelUpdater,+ [ActionTypes.TOGGLE_MODAL]: toggleModalUpdater,+ [ActionTypes.OPEN_DELETE_MODAL]: openDeleteModalUpdater,++ [ActionTypes.SET_RATIO]: setRatioUpdater,+ [ActionTypes.SET_RESOLUTION]: setResolutionUpdater,+ [ActionTypes.TOGGLE_LEGEND]: toggleLegendUpdater,+ [ActionTypes.START_EXPORTING_IMAGE]: startExportingImage,+ [ActionTypes.SET_EXPORT_IMAGE_DATA_URI]: setExportImageDataUri,+ [ActionTypes.CLEANUP_EXPORT_IMAGE]: cleanupExportImage,++ [ActionTypes.SET_EXPORT_SELECTED_DATASET]: setExportSelectedDatasetUpdater,+ [ActionTypes.SET_EXPORT_DATA_TYPE]: setExportDataTypeUpdater,+ [ActionTypes.SET_EXPORT_FILTERED]: setExportFilteredUpdater+};++/* Reducer */+export const uiStateReducerFactory = (initialState = {}) =>+ handleActions(actionHandler, {...INITIAL_UI_STATE, ...initialState, initialState});++export default uiStateReducerFactory();diff --git a/src/utils/export-image-utils.js b/src/utils/export-image-utils.jsnew file mode 100644index 000000000..bbe117a89--- /dev/null+++ b/src/utils/export-image-utils.js@@ -0,0 +1,34 @@+// Copyright (c) 2018 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 domtoimage from 'dom-to-image';+import {RESOLUTION_OPTIONS, RATIO_OPTIONS} from 'constants/default-settings';++export function calculateExportImageSize({width, height, ratio, resolution}) {+ const {+ width: scaledWidth,+ height: scaledHeight+ } = RESOLUTION_OPTIONS.find(op => op.id === resolution).getSize(width, height);+ return RATIO_OPTIONS.find(op => op.id === ratio).getSize(scaledWidth, scaledHeight);+}++export function convertToPng(sourceElem) {+ return domtoimage.toPng(sourceElem);+}