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

[Maps] Get number of categories from palette #66454

Merged
merged 7 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,8 @@ import React from 'react';
import { shallow } from 'enzyme';

import { DynamicColorProperty } from './dynamic_color_property';
import { StyleMeta } from '../style_meta';
import { COLOR_MAP_TYPE, FIELD_ORIGIN, VECTOR_STYLES } from '../../../../../common/constants';

const mockField = {
async getLabel() {
return 'foobar_label';
},
getName() {
return 'foobar';
},
getRootName() {
return 'foobar';
},
getOrigin() {
return FIELD_ORIGIN.SOURCE;
},
supportsFieldMeta() {
return true;
},
};

class MockStyle {
getStyleMeta() {
return new StyleMeta({
geometryTypes: {
isPointsOnly: false,
isLinesOnly: false,
isPolygonsOnly: false,
},
fieldMeta: {
foobar: {
range: { min: 0, max: 100 },
categories: {
categories: [
{
key: 'US',
count: 10,
},
{
key: 'CN',
count: 8,
},
],
},
},
},
});
}
}

class MockLayer {
getStyle() {
return new MockStyle();
}

getDataRequest() {
return null;
}
}
import { COLOR_MAP_TYPE, VECTOR_STYLES } from '../../../../../common/constants';
import { mockField, MockLayer } from './test_util';

const makeProperty = (options, field = mockField) => {
return new DynamicColorProperty(options, VECTOR_STYLES.LINE_COLOR, field, new MockLayer(), () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export class DynamicIconProperty extends DynamicStyleProperty {
return true;
}

getNumberOfCategories() {
const palette = getIconPalette(this._options.iconPaletteId);
return palette ? palette.length : 0;
}

syncIconWithMb(symbolLayerId, mbMap, iconPixelSize) {
if (this._isIconDynamicConfigComplete()) {
mbMap.setLayoutProperty(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

// eslint-disable-next-line max-classes-per-file
import { shallow } from 'enzyme';

jest.mock('ui/new_platform');
jest.mock('../components/vector_style_editor', () => ({
VectorStyleEditor: () => {
return <div>mockVectorStyleEditor</div>;
},
}));

import React from 'react';
import { VECTOR_STYLES } from '../../../../../common/constants';
// @ts-ignore
import { DynamicIconProperty } from './dynamic_icon_property';
import { mockField, MockLayer } from './test_util';

const makeProperty = (options, field = mockField) => {
return new DynamicIconProperty(options, VECTOR_STYLES.ICON, field, new MockLayer(), () => {
return x => x + '_format';
});
};

describe('DynamicIconProperty', () => {
it('should derive category number from palettes', async () => {
const filled = makeProperty({
iconPaletteId: 'filledShapes',
});
expect(filled.getNumberOfCategories()).toEqual(6);
const hollow = makeProperty({
iconPaletteId: 'hollowShapes',
});
expect(hollow.getNumberOfCategories()).toEqual(5);
});
});

test('Should render categorical legend with breaks', async () => {
const iconStyle = makeProperty({
iconPaletteId: 'filledShapes',
});

const legendRow = iconStyle.renderLegendDetailRow({ isPointsOnly: true, isLinesOnly: false });
const component = shallow(legendRow);
await new Promise(resolve => process.nextTick(resolve));
component.update();

expect(component).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export class DynamicStyleProperty extends AbstractStyleProperty {
if (this.isOrdinal()) {
return this._field.getOrdinalFieldMetaRequest();
} else if (this.isCategorical()) {
return this._field.getCategoricalFieldMetaRequest(this.getNumberOfCategories());
const numberOfCategories = this.getNumberOfCategories();
return this._field.getCategoricalFieldMetaRequest(numberOfCategories);
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

// eslint-disable-next-line max-classes-per-file
import { FIELD_ORIGIN } from '../../../../../common/constants';
import { StyleMeta } from '../style_meta';

export const mockField = {
async getLabel() {
return 'foobar_label';
},
getName() {
return 'foobar';
},
getRootName() {
return 'foobar';
},
getOrigin() {
return FIELD_ORIGIN.SOURCE;
},
supportsFieldMeta() {
return true;
},
};

class MockStyle {
getStyleMeta() {
return new StyleMeta({
geometryTypes: {
isPointsOnly: false,
isLinesOnly: false,
isPolygonsOnly: false,
},
fieldMeta: {
foobar: {
range: { min: 0, max: 100 },
categories: {
categories: [
{
key: 'US',
count: 10,
},
{
key: 'CN',
count: 8,
},
],
},
},
},
});
}
}

export class MockLayer {
getStyle() {
return new MockStyle();
}

getDataRequest() {
return null;
}
}