Skip to content

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

[Feat] Global export of image export constants (#923)

Jon Sadkacb060f9b3578
diff --git a/src/components/modals/export-image-modal.js b/src/components/modals/export-image-modal.js
index 1176bbe9d..c9a1d95f1 100644
--- a/src/components/modals/export-image-modal.js
+++ b/src/components/modals/export-image-modal.js
@@ -24,9 +24,9 @@ import styled from 'styled-components';
import {calculateExportImageSize} from 'utils/export-image-utils';
import {
- RATIO_OPTIONS,
- RATIOS,
- RESOLUTION_OPTIONS
+ EXPORT_IMG_RATIO_OPTIONS,
+ EXPORT_IMG_RATIOS,
+ EXPORT_IMG_RESOLUTION_OPTIONS
} from 'constants/default-settings';
import {
@@ -79,9 +79,9 @@ const PreviewImageSection = styled.div`
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.18);
width: 100%;
padding-bottom: ${props =>
- props.ratio === RATIOS.SCREEN
+ props.ratio === EXPORT_IMG_RATIOS.SCREEN
? `${(100 * props.height) / props.width}%`
- : props.ratio === RATIOS.SIXTEEN_BY_NINE
+ : props.ratio === EXPORT_IMG_RATIOS.SIXTEEN_BY_NINE
? '56.25%'
: '75%'};
position: relative;
@@ -153,7 +153,7 @@ class ExportImageModal extends Component {
<div className="image-option-section-title">Ratio</div>
Choose the ratio for various usages.
<div className="button-list">
- {RATIO_OPTIONS.map(op => (
+ {EXPORT_IMG_RATIO_OPTIONS.map(op => (
<SelectionButton
key={op.id}
selected={ratio === op.id}
@@ -168,7 +168,7 @@ class ExportImageModal extends Component {
<div className="image-option-section-title">Resolution</div>
High resolution is better for prints.
<div className="button-list">
- {RESOLUTION_OPTIONS.map(op => (
+ {EXPORT_IMG_RESOLUTION_OPTIONS.map(op => (
<SelectionButton
key={op.id}
selected={resolution === op.id}
@@ -193,9 +193,7 @@ class ExportImageModal extends Component {
</div>
</ImageOptionList>
<PreviewImageSection ratio={ratio} width={width} height={height}>
- <div className="dimension">{`${exportImageSize.width} x ${
- exportImageSize.height
- }`}</div>
+ <div className="dimension">{`${exportImageSize.width} x ${exportImageSize.height}`}</div>
<div className="preview-image">
{exporting ? (
<div className="preview-image-spinner">
diff --git a/src/constants/default-settings.js b/src/constants/default-settings.js
index fccc7f9f3..e6ddff299 100644
--- a/src/constants/default-settings.js
+++ b/src/constants/default-settings.js
@@ -101,7 +101,7 @@ export const KEPLER_GL_NAME = 'kepler.gl';
// Since we are injecting this during the build process with babel
// while developing VERSION is not defined, we capture the exception and return
// an empty string which will allow us to retrieve the latest umd version
-export const KEPLER_GL_VERSION = "__PACKAGE_VERSION__";
+export const KEPLER_GL_VERSION = '__PACKAGE_VERSION__';
export const KEPLER_GL_WEBSITE = 'http://kepler.gl/';
export const DIMENSIONS = {
@@ -406,7 +406,7 @@ export const notSupportedScaleOpts = {
[CHANNEL_SCALES.size]: []
};
-export const notSupportAggrOpts = {
+export const notSupportAggrOpts = {
[CHANNEL_SCALES.colorAggr]: {},
[CHANNEL_SCALES.sizeAggr]: {}
};
@@ -564,47 +564,60 @@ export const RESOLUTIONS = keyMirror({
TWO_X: null
});
-export const RATIOS = keyMirror({
+export const EXPORT_IMG_RATIOS = keyMirror({
SCREEN: null,
FOUR_BY_THREE: null,
SIXTEEN_BY_NINE: null
});
-export const RATIO_OPTIONS = [{
- id: RATIOS.SCREEN,
- label: 'Original Screen',
- getSize: (screenW, screenH) => ({width: screenW, height: screenH})
-}, {
- id: RATIOS.FOUR_BY_THREE,
- label: '4:3',
- getSize: (screenW, screenH) => ({width: screenW, height: Math.round(screenW * 0.75)})
-}, {
- id: RATIOS.SIXTEEN_BY_NINE,
- label: '16:9',
- getSize: (screenW, screenH) => ({width: screenW, height: Math.round(screenW * 0.5625)})
-}];
-
-export const RESOLUTION_OPTIONS = [{
- id: RESOLUTIONS.ONE_X,
- label: '1x',
- available: true,
- scale: 1,
- zoomOffset: Math.log2(1),
- getSize: (screenW, screenH) => ({
- width: screenW,
- height: screenH
- })
-}, {
- id: RESOLUTIONS.TWO_X,
- label: '2x',
- available: true,
- scale: 2,
- zoomOffset: Math.log2(2),
- getSize: (screenW, screenH) => ({
- width: screenW * 2,
- height: screenH * 2
- })
-}];
+export const EXPORT_IMG_RATIO_OPTIONS = [
+ {
+ id: EXPORT_IMG_RATIOS.SCREEN,
+ label: 'Original Screen',
+ getSize: (screenW, screenH) => ({width: screenW, height: screenH})
+ },
+ {
+ id: EXPORT_IMG_RATIOS.FOUR_BY_THREE,
+ label: '4:3',
+ getSize: (screenW, screenH) => ({
+ width: screenW,
+ height: Math.round(screenW * 0.75)
+ })
+ },
+ {
+ id: EXPORT_IMG_RATIOS.SIXTEEN_BY_NINE,
+ label: '16:9',
+ getSize: (screenW, screenH) => ({
+ width: screenW,
+ height: Math.round(screenW * 0.5625)
+ })
+ }
+];
+
+export const EXPORT_IMG_RESOLUTION_OPTIONS = [
+ {
+ id: RESOLUTIONS.ONE_X,
+ label: '1x',
+ available: true,
+ scale: 1,
+ zoomOffset: Math.log2(1),
+ getSize: (screenW, screenH) => ({
+ width: screenW,
+ height: screenH
+ })
+ },
+ {
+ id: RESOLUTIONS.TWO_X,
+ label: '2x',
+ available: true,
+ scale: 2,
+ zoomOffset: Math.log2(2),
+ getSize: (screenW, screenH) => ({
+ width: screenW * 2,
+ height: screenH * 2
+ })
+ }
+];
export const DEFAULT_EXPORT_IMAGE_NAME = 'kepler-gl.png';
diff --git a/src/constants/index.js b/src/constants/index.js
index 8b6de3b1c..8cffa1207 100644
--- a/src/constants/index.js
+++ b/src/constants/index.js
@@ -20,46 +20,46 @@
// Constants
export {
- KEPLER_GL_VERSION,
- KEPLER_GL_WEBSITE,
- KEPLER_GL_NAME,
- DIMENSIONS,
+ ADD_DATA_ID,
+ ADD_MAP_STYLE_ID,
+ AGGREGATION_TYPES,
ALL_FIELD_TYPES,
+ DATA_TABLE_ID,
+ DEFAULT_COLOR_RANGE,
+ DEFAULT_LAYER_GROUPS,
+ DEFAULT_MAP_STYLES,
+ DEFAULT_NOTIFICATION_TOPICS,
+ DEFAULT_NOTIFICATION_TYPES,
+ DELETE_DATA_ID,
+ DIMENSIONS,
+ EDITOR_MODES,
+ EXPORT_DATA_ID,
+ EXPORT_DATA_TYPE_OPTIONS,
+ EXPORT_IMAGE_ID,
+ EXPORT_IMG_RATIO_OPTIONS,
+ EXPORT_IMG_RATIOS,
+ EXPORT_IMG_RESOLUTION_OPTIONS,
+ EXPORT_MAP_FORMAT_OPTIONS,
+ EXPORT_MAP_FORMATS,
+ EXPORT_MAP_ID,
FIELD_OPTS,
FILTER_TYPES,
GEOJSON_FIELDS,
ICON_FIELDS,
- TRIP_POINT_FIELDS,
- TRIP_ARC_FIELDS,
- SCALE_TYPES,
- LAYER_TYPES,
+ KEPLER_GL_NAME,
+ KEPLER_GL_VERSION,
+ KEPLER_GL_WEBSITE,
LAYER_BLENDINGS,
- AGGREGATION_TYPES,
+ LAYER_TYPES,
MAX_DEFAULT_TOOLTIPS,
- DATA_TABLE_ID,
- DELETE_DATA_ID,
- ADD_DATA_ID,
- EXPORT_IMAGE_ID,
- EXPORT_DATA_ID,
- EXPORT_MAP_ID,
- ADD_MAP_STYLE_ID,
- DEFAULT_LAYER_GROUPS,
- DEFAULT_MAP_STYLES,
- THEME,
- EXPORT_MAP_FORMATS,
- EXPORT_MAP_FORMAT_OPTIONS,
- EXPORT_DATA_TYPE_OPTIONS,
- DEFAULT_NOTIFICATION_TYPES,
- DEFAULT_NOTIFICATION_TOPICS,
- DEFAULT_COLOR_RANGE,
PANELS,
- EDITOR_MODES
+ SCALE_TYPES,
+ THEME,
+ TRIP_ARC_FIELDS,
+ TRIP_POINT_FIELDS
} from './default-settings';
-export {
- GITHUB_BUG_REPORT,
- GITHUB_USER_GUIDE
-} from './user-guides';
+export {GITHUB_BUG_REPORT, GITHUB_USER_GUIDE} from './user-guides';
export {VizColorPalette, DataVizColors} from './custom-color-ranges';
export {COLOR_RANGES, DefaultColorRange} from './color-ranges';
diff --git a/src/reducers/ui-state-updaters.js b/src/reducers/ui-state-updaters.js
index 28e0f0186..5202ad6d9 100644
--- a/src/reducers/ui-state-updaters.js
+++ b/src/reducers/ui-state-updaters.js
@@ -19,14 +19,14 @@
// THE SOFTWARE.
import {
- DELETE_DATA_ID,
ADD_DATA_ID,
+ DEFAULT_NOTIFICATION_TOPICS,
+ DELETE_DATA_ID,
EXPORT_DATA_TYPE,
- RATIOS,
- RESOLUTIONS,
- EXPORT_MAP_FORMATS,
EXPORT_HTML_MAP_MODES,
- DEFAULT_NOTIFICATION_TOPICS
+ EXPORT_IMG_RATIOS,
+ EXPORT_MAP_FORMATS,
+ RESOLUTIONS
} from 'constants/default-settings';
import {createNotification, errorNotification} from 'utils/notifications-utils';
@@ -117,7 +117,7 @@ export const DEFAULT_MAP_CONTROLS = [
*/
export const DEFAULT_EXPORT_IMAGE = {
// user options
- ratio: RATIOS.SCREEN,
+ ratio: EXPORT_IMG_RATIOS.SCREEN,
resolution: RESOLUTIONS.ONE_X,
legend: false,
// exporting state
diff --git a/src/utils/export-image-utils.js b/src/utils/export-image-utils.js
index 224af4862..b492988be 100644
--- a/src/utils/export-image-utils.js
+++ b/src/utils/export-image-utils.js
@@ -27,10 +27,15 @@ import {
ArrayBuffer,
document
} from 'global/window';
-import {RESOLUTION_OPTIONS, RATIO_OPTIONS} from 'constants/default-settings';
+import {
+ EXPORT_IMG_RATIO_OPTIONS,
+ EXPORT_IMG_RESOLUTION_OPTIONS
+} from 'constants/default-settings';
export function calculateExportImageSize({width, height, ratio, resolution}) {
- const resolutionItem = RESOLUTION_OPTIONS.find(op => op.id === resolution);
+ const resolutionItem = EXPORT_IMG_RESOLUTION_OPTIONS.find(
+ op => op.id === resolution
+ );
const {width: scaledWidth, height: scaledHeight} = resolutionItem.getSize(
width,
height
@@ -40,7 +45,7 @@ export function calculateExportImageSize({width, height, ratio, resolution}) {
return {
zoomOffset,
scale,
- ...RATIO_OPTIONS.find(op => op.id === ratio).getSize(
+ ...EXPORT_IMG_RATIO_OPTIONS.find(op => op.id === ratio).getSize(
scaledWidth,
scaledHeight
)
diff --git a/src/utils/map-style-utils/mapbox-gl-style-editor.js b/src/utils/map-style-utils/mapbox-gl-style-editor.js
index 46b3ef592..dc44148ae 100644
--- a/src/utils/map-style-utils/mapbox-gl-style-editor.js
+++ b/src/utils/map-style-utils/mapbox-gl-style-editor.js
@@ -23,7 +23,7 @@ import clondDeep from 'lodash.clonedeep';
import {
DEFAULT_LAYER_GROUPS,
RESOLUTIONS,
- RESOLUTION_OPTIONS,
+ EXPORT_IMG_RESOLUTION_OPTIONS,
DEFAULT_MAPBOX_API_URL
} from 'constants/default-settings';
@@ -156,7 +156,7 @@ export function scaleMapStyleByResolution(mapboxStyle, resolution) {
const {filter: labelLayerFilter} = labelLayerGroup;
if (resolution !== RESOLUTIONS.ONE_X && mapboxStyle) {
- const {scale, zoomOffset} = RESOLUTION_OPTIONS.find(
+ const {scale, zoomOffset} = EXPORT_IMG_RESOLUTION_OPTIONS.find(
r => r.id === resolution
);
const copyStyle = clondDeep(mapboxStyle);
diff --git a/test/node/reducers/ui-state-test.js b/test/node/reducers/ui-state-test.js
index 72b81f2e2..0566c3b2d 100644
--- a/test/node/reducers/ui-state-test.js
+++ b/test/node/reducers/ui-state-test.js
@@ -37,9 +37,9 @@ import {loadFiles, loadFilesErr} from 'actions/vis-state-actions';
import reducer, {uiStateReducerFactory} from 'reducers/ui-state';
import {INITIAL_UI_STATE} from 'reducers/ui-state-updaters';
import {
- RATIOS,
- RESOLUTIONS,
- EXPORT_DATA_TYPE
+ EXPORT_DATA_TYPE,
+ EXPORT_IMG_RATIOS,
+ RESOLUTIONS
} from 'constants/default-settings';
import {
DEFAULT_NOTIFICATION_TOPICS,
@@ -119,14 +119,14 @@ test('#uiStateReducer -> OPEN_DELETE_MODAL', t => {
test('#uiStateReducer -> SET_RATIO', t => {
const newReducer = reducer(
INITIAL_UI_STATE,
- setRatio({ratio: RATIOS.SIXTEEN_BY_NINE})
+ setRatio({ratio: EXPORT_IMG_RATIOS.SIXTEEN_BY_NINE})
);
const expectedState = {
...INITIAL_UI_STATE,
exportImage: {
...INITIAL_UI_STATE.exportImage,
- ratio: RATIOS.SIXTEEN_BY_NINE
+ ratio: EXPORT_IMG_RATIOS.SIXTEEN_BY_NINE
}
};