Skip to content

Commit

Permalink
add category-rollups
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Jul 1, 2021
1 parent ba79ed5 commit 4ad1ae7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import _ from 'lodash';
import React from 'react';
import { Feature, FeatureCollection } from 'geojson';
import type { FeatureIdentifier, Map as MbMap } from '@kbn/mapbox-gl';
import { Map } from '@kbn/mapbox-gl';
import { AbstractStyleProperty, IStyleProperty } from './style_property';
import { DEFAULT_SIGMA } from '../vector_style_defaults';
import {
Expand Down Expand Up @@ -341,7 +340,7 @@ export class DynamicStyleProperty<T>

const name = this.getFieldName();

const counts = new Map();
const counts = new Map<string, number>();
for (let i = 0; i < metaFeatures.length; i++) {
const fieldMeta = metaFeatures[i].properties.fieldMeta;
if (fieldMeta && fieldMeta[name] && fieldMeta[name].categories) {
Expand All @@ -352,7 +351,7 @@ export class DynamicStyleProperty<T>
// properties object may be sparse, so need to check if the field is effectively present
if (typeof category.key !== undefined) {
if (counts.has(category.key)) {
counts.set(category.key, counts.get(category.key) + category.count);
counts.set(category.key, (counts.get(category.key) as number) + category.count);
} else {
counts.set(category.key, category.count);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,20 @@ export class VectorStyle implements IVectorStyle {
}

dynamicProperties.forEach((dynamicProperty) => {
const name = dynamicProperty.getFieldName();

const ordinalStyleMeta = dynamicProperty.pluckOrdinalStyleMetaFromTileMetaFeatures(
metaFeatures
);
const categoricalStyleMeta = dynamicProperty.pluckCategoricalStyleMetaFromTileMetaFeatures(
metaFeatures
);

const name = dynamicProperty.getFieldName();
if (!styleMeta.fieldMeta[name]) {
styleMeta.fieldMeta[name] = {};
}
if (categoricalStyleMeta) {
styleMeta.fieldMeta[name].categories = categoricalStyleMeta;
}

if (ordinalStyleMeta) {
styleMeta.fieldMeta[name].range = ordinalStyleMeta;
Expand Down

0 comments on commit 4ad1ae7

Please sign in to comment.