Skip to content

Commit

Permalink
Use order instead of sort + ASC and DESC [ch58612]
Browse files Browse the repository at this point in the history
  • Loading branch information
elenatorro committed Feb 13, 2020
1 parent 6da4765 commit 83547c0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/renderer/viz/expressions/CategoryIndex.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/viz/expressions/RampGeneric.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/viz/expressions/RampImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand Down
10 changes: 5 additions & 5 deletions src/renderer/viz/expressions/buckets.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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'
Expand All @@ -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++) {
Expand All @@ -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]);
}

Expand All @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion src/renderer/viz/expressions/classification/Classifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/renderer/viz/expressions/color/Opacity.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import BaseExpression from '../base';
import { checkType, checkMaxArguments, checkExpression, implicitCast } from '../utils';
import { ALTERNATIVE_SORT } from '../constants';

/**
* Override the input opacity.
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/viz/expressions/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 2 additions & 2 deletions src/renderer/viz/expressions/linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)`.
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 83547c0

Please sign in to comment.