Skip to content

Commit

Permalink
changing size categories helper sizeRange default values for points
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-contreras-deel committed Jun 4, 2020
1 parent fea1b49 commit 875d72b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/viz/__tests__/styles/SizeCategoriesStyle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { sizeCategoriesStyle } from '../../src/lib/style';
import { CARTOSource } from '../../src';
import { defaultStyles } from '../../src/lib/style/default-styles';
import { CartoStylingError } from '../../src/lib/errors/styling-error';
import { getDefaultSizeRange } from '../../src/lib/style/helpers/size-categories-style';

const FIELD_NAME = 'category';
const mapStats = mapsResponse.metadata.layers[0].meta.stats;
Expand Down Expand Up @@ -47,8 +48,7 @@ describe('SizeCategoriesStyle', () => {
expect(response).toHaveProperty('radiusUnits', 'pixels');
expect(response).toHaveProperty('pointRadiusMinPixels');
expect(response).toHaveProperty('pointRadiusMaxPixels');
const minSize = defaultStyles.Point.sizeRange[0];
const maxSize = defaultStyles.Point.sizeRange[1];
const [minSize, maxSize] = getDefaultSizeRange('Point', {});
expect(response.pointRadiusMinPixels).toBeGreaterThanOrEqual(minSize);
expect(response.pointRadiusMaxPixels).toBeLessThanOrEqual(maxSize);
});
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('SizeCategoriesStyle', () => {
r = getRadius({
properties: { [FIELD_NAME]: opts.categories[2] }
});
expect(r).toEqual(4.4);
expect(r).toEqual(5.6);
});
});
});
13 changes: 12 additions & 1 deletion packages/viz/src/lib/style/helpers/size-categories-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function defaultOptions(
return {
top: 11,
categories: [],
sizeRange: getStyleValue('sizeRange', geometryType, options),
sizeRange: getDefaultSizeRange(geometryType, options),
nullSize: getStyleValue('nullSize', geometryType, options),
...options
};
Expand Down Expand Up @@ -198,3 +198,14 @@ function validateParameters(
);
}
}

export function getDefaultSizeRange(
geometryType: GeometryType,
options: Partial<SizeCategoriesOptionsStyle>
) {
if (geometryType === 'Point') {
return options.sizeRange || [2, 20];
}

return getStyleValue('sizeRange', geometryType, options);
}

0 comments on commit 875d72b

Please sign in to comment.