Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore]: Technical: Translate utils (dataset-utils and export-utils) #1734

Merged
merged 3 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 89 additions & 61 deletions src/constants/default-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,57 +676,81 @@ export const EXPORT_IMG_RATIOS = keyMirror({
CUSTOM: null
});

export const EXPORT_IMG_RATIO_OPTIONS = [
{
id: EXPORT_IMG_RATIOS.SCREEN,
label: 'modal.exportImage.ratioOriginalScreen',
getSize: (screenW, screenH) => ({width: screenW, height: screenH})
},
{
id: EXPORT_IMG_RATIOS.CUSTOM,
hidden: true,
label: 'modal.exportImage.ratioCustom',
getSize: (mapW, mapH) => ({width: mapW, height: mapH})
},
{
id: EXPORT_IMG_RATIOS.FOUR_BY_THREE,
label: 'modal.exportImage.ratio4_3',
getSize: (screenW, screenH) => ({
width: screenW,
height: Math.round(screenW * 0.75)
})
},
{
id: EXPORT_IMG_RATIOS.SIXTEEN_BY_NINE,
label: 'modal.exportImage.ratio16_9',
getSize: (screenW, screenH) => ({
width: screenW,
height: Math.round(screenW * 0.5625)
})
}
export type ImageRatioOption = {
id: keyof typeof EXPORT_IMG_RATIOS;
label: string;
hidden?: boolean;
getSize: (screenW: number, screenH: number) => {width: number; height: number};
};

export const ScreenRatioOption: ImageRatioOption = {
id: EXPORT_IMG_RATIOS.SCREEN,
label: 'modal.exportImage.ratioOriginalScreen',
getSize: (screenW, screenH) => ({width: screenW, height: screenH})
};
export const CustomRatioOption: ImageRatioOption = {
id: EXPORT_IMG_RATIOS.CUSTOM,
hidden: true,
label: 'modal.exportImage.ratioCustom',
getSize: (mapW, mapH) => ({width: mapW, height: mapH})
};
export const FourByThreeRatioOption: ImageRatioOption = {
id: EXPORT_IMG_RATIOS.FOUR_BY_THREE,
label: 'modal.exportImage.ratio4_3',
getSize: (screenW, screenH) => ({
width: screenW,
height: Math.round(screenW * 0.75)
})
};
export const SixteenByNineRatioOption: ImageRatioOption = {
id: EXPORT_IMG_RATIOS.SIXTEEN_BY_NINE,
label: 'modal.exportImage.ratio16_9',
getSize: (screenW, screenH) => ({
width: screenW,
height: Math.round(screenW * 0.5625)
})
};

export const EXPORT_IMG_RATIO_OPTIONS: ReadonlyArray<ImageRatioOption> = [
ScreenRatioOption,
CustomRatioOption,
FourByThreeRatioOption,
SixteenByNineRatioOption
];

export const EXPORT_IMG_RESOLUTION_OPTIONS = [
{
id: RESOLUTIONS.ONE_X,
label: '1x',
available: true,
scale: 1,
getSize: (screenW, screenH) => ({
width: screenW,
height: screenH
})
},
{
id: RESOLUTIONS.TWO_X,
label: '2x',
available: true,
scale: 2,
getSize: (screenW, screenH) => ({
width: screenW * 2,
height: screenH * 2
})
}
export type ImageResolutionOption = {
id: keyof typeof RESOLUTIONS;
label: string;
available: boolean;
scale: number;
getSize: (screenW: number, screenH: number) => {width: number; height: number};
};

export const OneXResolutionOption: ImageResolutionOption = {
id: RESOLUTIONS.ONE_X,
label: '1x',
available: true,
scale: 1,
getSize: (screenW, screenH) => ({
width: screenW,
height: screenH
})
};

export const TwoXResolutionOption: ImageResolutionOption = {
id: RESOLUTIONS.TWO_X,
label: '2x',
available: true,
scale: 2,
getSize: (screenW, screenH) => ({
width: screenW * 2,
height: screenH * 2
})
};

export const EXPORT_IMG_RESOLUTION_OPTIONS: ReadonlyArray<ImageResolutionOption> = [
OneXResolutionOption,
TwoXResolutionOption
];

export const EXPORT_DATA_TYPE = keyMirror({
Expand Down Expand Up @@ -777,18 +801,22 @@ export const EXPORT_HTML_MAP_MODES = keyMirror({
});

// Export map options
export const EXPORT_MAP_FORMAT_OPTIONS = Object.entries(EXPORT_MAP_FORMATS).map((entry: [string, any]) => ({
id: entry[0],
label: entry[1].toLowerCase(),
available: true
}));

export const EXPORT_HTML_MAP_MODE_OPTIONS = Object.entries(EXPORT_HTML_MAP_MODES).map((entry: [string, any]) => ({
id: entry[0],
label: `modal.exportMap.html.${entry[1].toLowerCase()}`,
available: true,
url: getHTMLMapModeTileUrl(entry[1])
}));
export const EXPORT_MAP_FORMAT_OPTIONS = Object.entries(EXPORT_MAP_FORMATS).map(
(entry: [string, any]) => ({
id: entry[0],
label: entry[1].toLowerCase(),
available: true
})
);

export const EXPORT_HTML_MAP_MODE_OPTIONS = Object.entries(EXPORT_HTML_MAP_MODES).map(
(entry: [string, any]) => ({
id: entry[0],
label: `modal.exportMap.html.${entry[1].toLowerCase()}`,
available: true,
url: getHTMLMapModeTileUrl(entry[1])
})
);

export const DEFAULT_UUID_COUNT = 6;

Expand Down
9 changes: 6 additions & 3 deletions src/reducers/ui-state-updaters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ import {
} from 'constants/default-settings';
import {LOCALE_CODES} from 'localization/locales';
import {createNotification, errorNotification} from 'utils/notifications-utils';
import {calculateExportImageSize} from '../utils/export-utils.js';
import {calculateExportImageSize} from '../utils/export-utils';
import {payload_, apply_, compose_} from './composer-helpers';

import ActionTypes from '../constants/action-types';
import * as UiStateActions from 'actions/ui-state-actions';
import {KeplerGlInitPayload, LoadFilesErrUpdaterAction} from '../actions';

export type ExportImage = {
ratio: string;
resolution: string;
ratio: keyof typeof EXPORT_IMG_RATIOS;
resolution: keyof typeof RESOLUTIONS;
legend: boolean;
mapH: number;
mapW: number;
Expand Down Expand Up @@ -527,6 +527,9 @@ export const setExportImageSettingUpdater = (
...state,
exportImage: {
...updated,
// @ts-expect-error
// TODO: calculateExportImageSize does not return imageSize.zoomOffset,
// do we need take this value from current state, or return defaul value = 0
imageSize
}
};
Expand Down
10 changes: 0 additions & 10 deletions src/utils/dataset-utils.d.ts

This file was deleted.

20 changes: 13 additions & 7 deletions src/utils/dataset-utils.js → src/utils/dataset-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import {hexToRgb} from './color-utils';
import uniq from 'lodash.uniq';
import {ALL_FIELD_TYPES} from 'constants/default-settings';
import {validateInputData} from 'processors/data-processor';
import KeplerTable from './table-utils/kepler-table';
import KeplerTable, {Field} from './table-utils/kepler-table';

import {Datasets} from '../reducers/vis-state-updaters';
import {ProtoDataset} from '../actions';
import {RGBColor} from 'reducers/types';

// apply a color for each dataset
// to use as label colors
Expand All @@ -38,9 +42,8 @@ const datasetColors = [

/**
* Random color generator
* @return {Generator<import('reducers/types').RGBColor>}
*/
function* generateColor() {
function* generateColor(): Generator<RGBColor> {
let index = 0;
while (index < datasetColors.length + 1) {
if (index === datasetColors.length) {
Expand All @@ -53,7 +56,7 @@ function* generateColor() {
export const datasetColorMaker = generateColor();

/** @type {typeof import('./dataset-utils').getNewDatasetColor} */
export function getNewDatasetColor(datasets) {
export function getNewDatasetColor(datasets: Datasets): RGBColor {
const presetColors = datasetColors.map(String);
const usedColors = uniq(Object.values(datasets).map(d => String(d.color))).filter(c =>
presetColors.includes(c)
Expand All @@ -74,9 +77,11 @@ export function getNewDatasetColor(datasets) {

/**
* Take datasets payload from addDataToMap, create datasets entry save to visState
* @type {typeof import('./dataset-utils').createNewDataEntry}
*/
export function createNewDataEntry({info, data, ...opts}, datasets = {}) {
export function createNewDataEntry(
{info, data, ...opts}: ProtoDataset,
datasets: Datasets = {}
): Datasets {
const validatedData = validateInputData(data);
if (!validatedData) {
return {};
Expand Down Expand Up @@ -182,7 +187,7 @@ const METRIC_DEFAULT_FIELDS = [
*
* @param dataset
*/
export function findDefaultColorField({fields, fieldPairs = []}) {
export function findDefaultColorField({fields, fieldPairs = []}: KeplerTable): null | Field {
const fieldsWithoutExcluded = fields.filter(field => {
if (field.type !== ALL_FIELD_TYPES.real && field.type !== ALL_FIELD_TYPES.integer) {
// Only select numeric fields.
Expand Down Expand Up @@ -243,6 +248,7 @@ export function findDefaultColorField({fields, fieldPairs = []}) {
}

// Finally, order based on the order in the datasets columns
// @ts-expect-error
return left.index - right.index;
});

Expand Down
18 changes: 0 additions & 18 deletions src/utils/export-utils.d.ts

This file was deleted.

Loading