From 83547c051dd9fc3b948a8c71cc2041a0f5a963bc Mon Sep 17 00:00:00 2001 From: elenatorro Date: Thu, 13 Feb 2020 11:43:27 +0100 Subject: [PATCH] Use order instead of sort + ASC and DESC [ch58612] --- src/renderer/viz/expressions/CategoryIndex.js | 4 ++-- src/renderer/viz/expressions/RampGeneric.js | 4 ++-- src/renderer/viz/expressions/RampImage.js | 4 ++-- src/renderer/viz/expressions/buckets.js | 10 +++++----- .../viz/expressions/classification/Classifier.js | 1 - src/renderer/viz/expressions/color/Opacity.js | 1 - src/renderer/viz/expressions/constants.js | 5 +++-- src/renderer/viz/expressions/linear.js | 4 ++-- 8 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/renderer/viz/expressions/CategoryIndex.js b/src/renderer/viz/expressions/CategoryIndex.js index aaa7bbc69..f9890fb7a 100644 --- a/src/renderer/viz/expressions/CategoryIndex.js +++ b/src/renderer/viz/expressions/CategoryIndex.js @@ -1,6 +1,6 @@ import BaseExpression from './base'; import { checkExpression, implicitCast, checkType, checkMaxArguments } from './utils'; -import { ALTERNATIVE_SORT } from './constants'; +import { SORT_DESC } from './constants'; const SQRT_MAX_CATEGORIES_PER_PROPERTY = 256; @@ -151,7 +151,7 @@ export default class CategoryIndex extends BaseExpression { data.push({ key, value }); } - if (options.sort && options.sort === ALTERNATIVE_SORT) { + if (options.order && options.order === SORT_DESC) { data = data.sort((a, b) => b.key - a.key); } diff --git a/src/renderer/viz/expressions/RampGeneric.js b/src/renderer/viz/expressions/RampGeneric.js index 6bf701e66..44b7a2fe5 100644 --- a/src/renderer/viz/expressions/RampGeneric.js +++ b/src/renderer/viz/expressions/RampGeneric.js @@ -4,7 +4,7 @@ import Property from './basic/property'; import Linear from './linear'; import CIELabGLSL from './color/CIELab.glsl'; import CategoryIndex from './CategoryIndex'; -import { OTHERS_GLSL_VALUE, OTHERS_INDEX, DEFAULT_OPTIONS, DEFAULT_RAMP_OTHERS, ALTERNATIVE_SORT } from './constants'; +import { OTHERS_GLSL_VALUE, OTHERS_INDEX, DEFAULT_OPTIONS, DEFAULT_RAMP_OTHERS, SORT_DESC } from './constants'; import Palette from './color/palettes/Palette'; import Base from './base'; import Constant from './basic/constant'; @@ -83,7 +83,7 @@ export default class RampGeneric extends Base { return { key, value }; }); - if (config.sort && config.sort === ALTERNATIVE_SORT) { + if (config.order && config.order === SORT_DESC) { data = data.sort((a, b) => b.key[0] - a.key[0]); legendData = legendData.data.sort((a, b) => b.key[0] - a.key[0]); } diff --git a/src/renderer/viz/expressions/RampImage.js b/src/renderer/viz/expressions/RampImage.js index 8bcadbe6b..bfe518b14 100644 --- a/src/renderer/viz/expressions/RampImage.js +++ b/src/renderer/viz/expressions/RampImage.js @@ -5,7 +5,7 @@ import CategoryIndex from './CategoryIndex'; import ListImage from './ListImage'; import Image from './Image'; import Base from './base'; -import { OTHERS_GLSL_VALUE, DEFAULT_RAMP_OTHERS, ALTERNATIVE_SORT } from './constants'; +import { OTHERS_GLSL_VALUE, DEFAULT_RAMP_OTHERS, SORT_DESC } from './constants'; const DEFAULT_RAMP_OTHERS_IMAGE = new Image(defaultSVGs.circle); export default class RampImage extends Base { @@ -54,7 +54,7 @@ export default class RampImage extends Base { return { key, value }; }); - if (options && options.sort && options.sort === ALTERNATIVE_SORT) { + if (options && options.order && options.order === SORT_DESC) { data = data.sort((a, b) => b.key - a.key); } diff --git a/src/renderer/viz/expressions/buckets.js b/src/renderer/viz/expressions/buckets.js index 1c1d0b737..fd2e93a91 100644 --- a/src/renderer/viz/expressions/buckets.js +++ b/src/renderer/viz/expressions/buckets.js @@ -1,6 +1,6 @@ import BaseExpression from './base'; import { implicitCast, getOrdinalFromIndex, checkMaxArguments, checkType, checkFeatureIndependent } from './utils'; -import { OTHERS_INDEX, OTHERS_LABEL, ALTERNATIVE_SORT } from './constants'; +import { OTHERS_INDEX, OTHERS_LABEL, SORT_DESC } from './constants'; import CartoValidationError, { CartoValidationErrorTypes } from '../../../errors/carto-validation-error'; import BucketsGLSLHelper from './BucketsGLSLHelper'; @@ -173,7 +173,7 @@ export default class Buckets extends BaseExpression { const list = this.list.elems.map(elem => elem.value); const config = { othersLabel: options && options.othersLabel ? options.othersLabel : this.othersLabel.value, - sort: options ? options.sort : ALTERNATIVE_SORT.ASCENDING + order: options ? options.order : SORT_DESC.ASCENDING }; let data = this.input.type === 'number' @@ -185,7 +185,7 @@ export default class Buckets extends BaseExpression { } } -function _getLegendDataNumeric (list, sort) { +function _getLegendDataNumeric (list, order) { let data = []; for (let i = 0; i <= list.length; i++) { @@ -196,7 +196,7 @@ function _getLegendDataNumeric (list, sort) { data.push({ key, value }); } - if (sort && sort === ALTERNATIVE_SORT) { + if (order && order === SORT_DESC) { data = data.sort((a, b) => b.key[0] - a.key[0]); } @@ -219,7 +219,7 @@ function _getLegendDataCategory (list, numDatasetCategories, config) { }); } - if (config.sort && config.sort === ALTERNATIVE_SORT) { + if (config.order && config.order === SORT_DESC) { data = data.sort((a, b) => b.key - a.key); } diff --git a/src/renderer/viz/expressions/classification/Classifier.js b/src/renderer/viz/expressions/classification/Classifier.js index 604e78c41..3dd0819c1 100644 --- a/src/renderer/viz/expressions/classification/Classifier.js +++ b/src/renderer/viz/expressions/classification/Classifier.js @@ -4,7 +4,6 @@ import { number } from '../../expressions'; import { checkType, checkNumber } from '../utils'; import CartoValidationError, { CartoValidationErrorTypes } from '../../../../errors/carto-validation-error'; import ClassifierGLSLHelper from './ClassifierGLSLHelper'; -import { ALTERNATIVE_SORT } from '../constants'; export const DEFAULT_HISTOGRAM_SIZE = 1000; diff --git a/src/renderer/viz/expressions/color/Opacity.js b/src/renderer/viz/expressions/color/Opacity.js index add4c41b9..4c0d26d0e 100644 --- a/src/renderer/viz/expressions/color/Opacity.js +++ b/src/renderer/viz/expressions/color/Opacity.js @@ -1,6 +1,5 @@ import BaseExpression from '../base'; import { checkType, checkMaxArguments, checkExpression, implicitCast } from '../utils'; -import { ALTERNATIVE_SORT } from '../constants'; /** * Override the input opacity. diff --git a/src/renderer/viz/expressions/constants.js b/src/renderer/viz/expressions/constants.js index 9deff6a40..dc28904aa 100644 --- a/src/renderer/viz/expressions/constants.js +++ b/src/renderer/viz/expressions/constants.js @@ -3,11 +3,12 @@ export const DEFAULT_SAMPLES = 10; export const OTHERS_GLSL_VALUE = '(-1.)'; export const OTHERS_INDEX = -1; export const OTHERS_LABEL = 'CARTO_VL_OTHERS'; -export const ALTERNATIVE_SORT = 'descending'; +export const SORT_DESC = 'DESC'; +export const SORT_ASC = 'ASC'; export const DEFAULT_OPTIONS = { othersLabel: OTHERS_LABEL, samples: DEFAULT_SAMPLES, - sort: 'ascending' + order: SORT_ASC }; export const FP32_DESIGNATED_NULL_VALUE = -(1 << 24); diff --git a/src/renderer/viz/expressions/linear.js b/src/renderer/viz/expressions/linear.js index 0a17b7c05..7d58a648f 100644 --- a/src/renderer/viz/expressions/linear.js +++ b/src/renderer/viz/expressions/linear.js @@ -4,7 +4,7 @@ import { globalMin, globalMax } from '../expressions'; import { castTimeRange, msToDate } from '../../../utils/util'; import IdentityCodec from '../../../codecs/Identity'; import TimeZoneDate from '../../../utils/time/TimeZoneDate'; -import { DEFAULT_SAMPLES, ALTERNATIVE_SORT } from './constants'; +import { DEFAULT_SAMPLES, SORT_DESC } from './constants'; /** * Linearly interpolates the value of a given input between a minimum and a maximum. If `min` and `max` are not defined they will * default to `globalMin(input)` and `globalMax(input)`. @@ -258,7 +258,7 @@ export default class Linear extends BaseExpression { data.push({ key, value }); } - if (options.sort && options.sort === ALTERNATIVE_SORT) { + if (options.order && options.order === SORT_DESC) { data = data.sort((a, b) => b.key - a.key); }