Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Enhancement] Enable ordinal aggregation in aggregation layer (hex, grid, cluster) (#29)
Shan He14de86c99d15
diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.jsindex a32f47b53..bc61a6519 100644--- a/examples/demo-app/src/app.js+++ b/examples/demo-app/src/app.js@@ -49,8 +49,8 @@ class App extends Component {}componentDidMount() {- // load trip based data with config- // this._loadSampleData();+ // load sample data+ this._loadSampleData();}_loadSampleData() {@@ -85,31 +85,31 @@ class App extends Component {);// load icon data and config and process csv file- this.props.dispatch(- addDataToMap({- datasets: [- {- info: {- label: 'Icon Data',- id: 'test_icon_data'- },- data: Processors.processCsvData(sampleIconCsv)- }- ],- options: {- centerMap: false- },- config: savedMapConfig- })- );+ // this.props.dispatch(+ // addDataToMap({+ // datasets: [+ // {+ // info: {+ // label: 'Icon Data',+ // id: 'test_icon_data'+ // },+ // data: Processors.processCsvData(sampleIconCsv)+ // }+ // ],+ // options: {+ // centerMap: false+ // },+ // config: savedMapConfig+ // })+ // );// load geojson- this.props.dispatch(- updateVisData({- info: {label: 'SF Zip Geo'},- data: Processors.processGeojson(sampleGeojson)- })- );+ // this.props.dispatch(+ // updateVisData({+ // info: {label: 'SF Zip Geo'},+ // data: Processors.processGeojson(sampleGeojson)+ // })+ // );}render() {diff --git a/src/components/common/color-legend.js b/src/components/common/color-legend.jsindex 7ff9c7f97..8b5b65924 100644--- a/src/components/common/color-legend.js+++ b/src/components/common/color-legend.js@@ -96,8 +96,8 @@ const getQuantLegends = (scale, labelFormat) => {export default class ColorLegend extends Component {static propTypes = {width: PropTypes.number.isRequired,- scaleType: PropTypes.string.isRequired,- domain: PropTypes.oneOfType([PropTypes.array, PropTypes.object]).isRequired,+ scaleType: PropTypes.string,+ domain: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),fieldType: PropTypes.string,range: PropTypes.arrayOf(PropTypes.string),labelFormat: PropTypes.funcdiff --git a/src/components/common/field-selector.js b/src/components/common/field-selector.jsindex ad37c3959..ba05e51ac 100644--- a/src/components/common/field-selector.js+++ b/src/components/common/field-selector.js@@ -69,6 +69,7 @@ export default class FieldSelector extends Component {value: FieldType,filterFieldTypes: PropTypes.oneOfType([FieldType, PropTypes.arrayOf(FieldType)]),inputTheme: PropTypes.string,+ placeholder: PropTypes.string,erasable: PropTypes.bool,error: PropTypes.bool,multiSelect: PropTypes.bool,diff --git a/src/components/map/map-legend.js b/src/components/map/map-legend.jsindex 10ad313a8..8f502a7b5 100644--- a/src/components/map/map-legend.js+++ b/src/components/map/map-legend.js@@ -71,7 +71,7 @@ const VisualChannelMetric = ({name}) => (</div>);-const LayerSize = ({label, name}) => (+const LayerSizeLegend = ({label, name}) => (<div className="legend--layer_size-schema"><p><span className="legend--layer_by">{label}</span>@@ -84,12 +84,38 @@ const propTypes = {layers: PropTypes.array};+const SingleColorLegend = ({layer, width}) => (+ <ColorLegend+ scaleType="ordinal"+ displayLabel={false}+ domain={['']}+ fieldType={null}+ range={[rgb(...layer.config.color).toString()]}+ width={width}+ />+);++const MultiColorLegend = ({layer, width}) => {+ const {visConfig, colorField, colorScale, colorDomain} = layer.config;++ return (+ <ColorLegend+ scaleType={colorScale}+ displayLabel+ domain={colorDomain}+ fieldType={(colorField && colorField.type) || 'real'}+ range={visConfig.colorRange.colors}+ width={width}+ />+ );+};+const MapLegend = ({layers}) => (<div>{layers.map((layer, index) => {- const enableColorBy = layer.config.colorField- ? layer.config.colorField.name- : layer.visualChannels.color.defaultMeasure;+ const colorChannelConfig = layer.getVisualChannelDescription('color');+ const enableColorBy = colorChannelConfig.measure;+ const width = DIMENSIONS.mapControl.width - 2 * DIMENSIONS.mapControl.padding;if (!layer.isValidToSave()) {return null;@@ -111,29 +137,10 @@ const MapLegend = ({layers}) => (<VisualChannelMetric name={enableColorBy} />) : null}<div className="legend--layer_color-legend">- <ColorLegend- scaleType={- enableColorBy ? layer.config.colorScale : 'ordinal'- }- displayLabel={enableColorBy}- domain={enableColorBy ? layer.config.colorDomain : ['']}- fieldType={- enableColorBy- ? (layer.config.colorField &&- layer.config.colorField.type) ||- 'real'- : null- }- range={- enableColorBy- ? layer.config.visConfig.colorRange.colors- : [rgb(...layer.config.color).toString()]- }- width={- DIMENSIONS.mapControl.width -- 2 * DIMENSIONS.mapControl.padding- }- />+ {enableColorBy ?+ <MultiColorLegend layer={layer} width={width}/> :+ <SingleColorLegend layer={layer} width={width}/>+ }</div></div></div>@@ -146,19 +153,14 @@ const MapLegend = ({layers}) => (const enabled =layer.config[layer.visualChannels[key].field] ||layer.visualChannels[key].defaultMeasure;++ const visualChannelDescription = layer.getVisualChannelDescription(key);if (matchCondition && enabled) {return (- <LayerSize+ <LayerSizeLegendkey={key}- label={- layer.visConfigSettings[layer.visualChannels[key].range]- .label- }- name={- layer.config[layer.visualChannels[key].field]- ? layer.config[layer.visualChannels[key].field].name- : layer.visualChannels[key].defaultMeasure- }+ label={visualChannelDescription.label}+ name={visualChannelDescription.measure}/>);}diff --git a/src/components/map/map-popover.js b/src/components/map/map-popover.jsindex 2ccf62704..b89ea40df 100644--- a/src/components/map/map-popover.js+++ b/src/components/map/map-popover.js@@ -269,21 +269,20 @@ const EntryInfoRow = ({name, fields, data}) => {const CellInfo = ({data, layer}) => {const {colorField, sizeField} = layer.config;- const {colorAggregation, sizeAggregation} = layer.config.visConfig;return (<tbody><Row name={'total points'} key="count" value={data.points.length} />{colorField ? (<Row- name={`${colorAggregation} ${colorField.name}`}+ name={layer.getVisualChannelDescription('color').measure}key="color"value={data.colorValue || 'N/A'}/>) : null}{sizeField ? (<Row- name={`${sizeAggregation} ${sizeField.name}`}+ name={layer.getVisualChannelDescription('size').measure}key="size"value={data.elevationValue || 'N/A'}/>diff --git a/src/components/side-panel/layer-panel/layer-configurator.js b/src/components/side-panel/layer-panel/layer-configurator.jsindex bc15ca291..a4968a1d7 100644--- a/src/components/side-panel/layer-panel/layer-configurator.js+++ b/src/components/side-panel/layer-panel/layer-configurator.js@@ -43,7 +43,6 @@ import {LAYER_VIS_CONFIGS} from 'layers/layer-factory';import {capitalizeFirstLetter} from 'utils/utils';import {- FIELD_OPTS,LAYER_TYPES,CHANNEL_SCALE_SUPPORTED_FIELDS} from 'constants/default-settings';@@ -175,8 +174,15 @@ export default class LayerConfigurator extends Component {channel={layer.visualChannels.color}{...layerChannelConfigProps}/>+ {layer.visConfigSettings.colorAggregation.condition(layer.config) ?+ <AggregationTypeSelector+ {...layer.visConfigSettings.colorAggregation}+ {...layerChannelConfigProps}+ channel={layer.visualChannels.color}+ />+ : null}<VisConfigSlider- {...LAYER_VIS_CONFIGS.opacity}+ {...layer.visConfigSettings.opacity}{...visConfiguratorProps}/></LayerConfigGroup>@@ -184,20 +190,12 @@ export default class LayerConfigurator extends Component {{/* Cluster Radius */}<LayerConfigGroup label={'radius'}><VisConfigSlider- {...LAYER_VIS_CONFIGS.clusterRadius}+ {...layer.visConfigSettings.clusterRadius}{...visConfiguratorProps}/><VisConfigSlider- {...LAYER_VIS_CONFIGS.clusterRadiusRange}- {...visConfiguratorProps}- />- </LayerConfigGroup>- {/* Aggregation Type */}- <LayerConfigGroup label={'aggregation'}>- <AggregationTypeSelector- {...LAYER_VIS_CONFIGS.aggregation}+ {...layer.visConfigSettings.radiusRange}{...visConfiguratorProps}- field={layer.config.colorField}/></LayerConfigGroup></StyledLayerVisualConfigurator>@@ -205,25 +203,25 @@ export default class LayerConfigurator extends Component {}_renderHeatmapLayerConfig({- layer,- visConfiguratorProps,- layerConfiguratorProps,- layerChannelConfigProps- }) {+ layer,+ visConfiguratorProps,+ layerConfiguratorProps,+ layerChannelConfigProps+ }) {return (<StyledLayerVisualConfigurator>{/* Color */}<LayerConfigGroup label={'color'}><ColorRangeConfig {...visConfiguratorProps} /><VisConfigSlider- {...LAYER_VIS_CONFIGS.opacity}+ {...layer.visConfigSettings.opacity}{...visConfiguratorProps}/></LayerConfigGroup>{/* Radius */}<LayerConfigGroup label={'radius'}><VisConfigSlider- {...LAYER_VIS_CONFIGS.radius}+ {...layer.visConfigSettings.radius}{...visConfiguratorProps}label={false}/>@@ -253,8 +251,10 @@ export default class LayerConfigurator extends Component {layerConfiguratorProps,layerChannelConfigProps}) {- const {type, config} = layer;- const {visConfig: {enable3d}, colorField, sizeField} = config;+ const {config} = layer;+ const {+ visConfig: {enable3d}+ } = config;const elevationByDescription ='When off, height is based on count of points';const colorByDescription = 'When off, color is based on count of points';@@ -269,18 +269,22 @@ export default class LayerConfigurator extends Component {channel={layer.visualChannels.color}{...layerChannelConfigProps}/>- <AggregationTypeSelector- {...LAYER_VIS_CONFIGS.aggregation}- {...visConfiguratorProps}- descreiption={colorByDescription}- field={colorField}- />- <VisConfigSlider- {...LAYER_VIS_CONFIGS.percentile}- {...visConfiguratorProps}- />+ {layer.visConfigSettings.colorAggregation.condition(layer.config) ? (+ <AggregationTypeSelector+ {...layer.visConfigSettings.colorAggregation}+ {...layerChannelConfigProps}+ descreiption={colorByDescription}+ channel={layer.visualChannels.color}+ />+ ) : null}+ {layer.visConfigSettings.percentile && layer.visConfigSettings.percentile.condition(layer.config) ? (+ <VisConfigSlider+ {...layer.visConfigSettings.percentile}+ {...visConfiguratorProps}+ />+ ) : null}<VisConfigSlider- {...LAYER_VIS_CONFIGS.opacity}+ {...layer.visConfigSettings.opacity}{...visConfiguratorProps}/></LayerConfigGroup>@@ -288,48 +292,51 @@ export default class LayerConfigurator extends Component {{/* Cell size */}<LayerConfigGroup label={'radius'}><VisConfigSlider- {...LAYER_VIS_CONFIGS.worldUnitSize}+ {...layer.visConfigSettings.worldUnitSize}{...visConfiguratorProps}- label={`${- type === LAYER_TYPES.grid ? 'Grid Size' : 'Hexagon Radius'- } (km)`}/><VisConfigSlider- {...LAYER_VIS_CONFIGS.coverage}+ {...layer.visConfigSettings.coverage}{...visConfiguratorProps}/></LayerConfigGroup>{/* Elevation */}- <LayerConfigGroup- {...LAYER_VIS_CONFIGS.enable3d}- {...visConfiguratorProps}- >- <VisConfigSlider- {...LAYER_VIS_CONFIGS.elevationScale}- {...visConfiguratorProps}- />- <ChannelByValueSelector- {...layerChannelConfigProps}- channel={layer.visualChannels.size}- description={elevationByDescription}- disabled={!enable3d}- />- <AggregationTypeSelector- {...LAYER_VIS_CONFIGS.aggregation}- {...visConfiguratorProps}- property={'sizeAggregation'}- field={sizeField}- />- <VisConfigSlider- {...LAYER_VIS_CONFIGS.percentile}+ {layer.visConfigSettings.enable3d ?+ <LayerConfigGroup+ {...layer.visConfigSettings.enable3d}{...visConfiguratorProps}- property={'elevationPercentile'}- disabled={!enable3d || (!colorField && !sizeField)}- />- </LayerConfigGroup>+ >+ <VisConfigSlider+ {...layer.visConfigSettings.elevationScale}+ {...visConfiguratorProps}+ />+ <ChannelByValueSelector+ {...layerChannelConfigProps}+ channel={layer.visualChannels.size}+ description={elevationByDescription}+ disabled={!enable3d}+ />+ {layer.visConfigSettings.sizeAggregation.condition(layer.config) ? (+ <AggregationTypeSelector+ {...layer.visConfigSettings.sizeAggregation}+ {...layerChannelConfigProps}+ channel={layer.visualChannels.size}+ />+ ) : null}+ {layer.visConfigSettings.elevationPercentile.condition(+ layer.config+ ) ? (+ <VisConfigSlider+ {...layer.visConfigSettings.elevationPercentile}+ {...visConfiguratorProps}+ />+ ) : null}+ </LayerConfigGroup> : null}++ {/* High Precision */}<LayerConfigGroup- {...LAYER_VIS_CONFIGS['hi-precision']}+ {...layer.visConfigSettings['hi-precision']}{...visConfiguratorProps}/></StyledLayerVisualConfigurator>@@ -452,7 +459,10 @@ export default class LayerConfigurator extends Component {layerConfiguratorProps,layerChannelConfigProps}) {- const {meta: {featureTypes = {}}, config: {visConfig}} = layer;+ const {+ meta: {featureTypes = {}},+ config: {visConfig}+ } = layer;return (<StyledLayerVisualConfigurator>@@ -559,7 +569,13 @@ export default class LayerConfigurator extends Component {}render() {- const {layer, datasets, updateLayerConfig, layerTypeOptions, updateLayerType} = this.props;+ const {+ layer,+ datasets,+ updateLayerConfig,+ layerTypeOptions,+ updateLayerType+ } = this.props;const {fields = [], fieldPairs} = layer.config.dataId? datasets[layer.config.dataId]: {};@@ -643,7 +659,11 @@ export const LayerColorSelector = ({layer, onChange, label}) => (</SidePanelSection>);-export const ArcLayerColorSelector = ({layer, onChangeConfig, onChangeVisConfig}) => (+export const ArcLayerColorSelector = ({+ layer,+ onChangeConfig,+ onChangeVisConfig+}) => (<SidePanelSection><ColorSelectorcolorSets={[@@ -691,17 +711,16 @@ export const ChannelByValueSelector = ({key,property,range,- scale+ scale,+ defaultMeasure,+ supportedFieldTypes} = channel;- const supportedFieldTypes = CHANNEL_SCALE_SUPPORTED_FIELDS[channelScaleType];+ const channelSupportedFieldTypes = supportedFieldTypes || CHANNEL_SCALE_SUPPORTED_FIELDS[channelScaleType];const supportedFields = fields.filter(({type}) =>- supportedFieldTypes.includes(type)+ channelSupportedFieldTypes.includes(type));- const selectedField = layer.config[field];- const scaleOptions =- (selectedField && FIELD_OPTS[selectedField.type].scale[channelScaleType]) ||- [];- const showScale = !layer.isAggregated && scaleOptions.length > 1;+ const scaleOptions = layer.getScaleOptions(channel.key);+ const showScale = !layer.isAggregated && layer.config[scale] && scaleOptions.length > 1;const defaultDescription = `Calculate ${property} based on selected field`;return (@@ -713,9 +732,10 @@ export const ChannelByValueSelector = ({id={layer.id}key={`${key}-channel-selector`}property={property}+ placeholder={defaultMeasure || 'Select a field'}range={layer.config.visConfig[range]}scaleOptions={scaleOptions}- scaleType={layer.config[scale]}+ scaleType={scale ? layer.config[scale] : null}selectedField={layer.config[field]}showScale={showScale}updateField={val => onChange({[field]: val}, key)}@@ -724,36 +744,48 @@ export const ChannelByValueSelector = ({);};-export const AggrColorScaleSelector = ({layer: {config}, onChange}) => (- <DimensionScaleSelector- label="Color Scale"- options={- config.colorField- ? FIELD_OPTS[config.colorField.type].scale.colorAggr- : FIELD_OPTS.integer.scale.colorAggr- }- scaleType={config.colorScale}- onSelect={val => onChange({colorScale: val}, 'color')}- />-);+export const AggrColorScaleSelector = ({layer, onChange}) => {+ const scaleOptions = layer.getScaleOptions('color');+ return (+ Array.isArray(scaleOptions) && scaleOptions.length > 1 ?+ <DimensionScaleSelector+ label="Color Scale"+ options={scaleOptions}+ scaleType={layer.config.colorScale}+ onSelect={val => onChange({colorScale: val}, 'color')}+ /> : null+ );+};-export const AggregationTypeSelector = ({- layer: {config: {visConfig}},- field,- property,- options,- onChange-}) => (- <SidePanelSection>- <PanelLabel>{`Aggregate ${field ? field.name : ''} by`}</PanelLabel>- <ItemSelector- disabled={!field}- selectedItems={visConfig[property]}- options={options}- multiSelect={false}- searchable={false}- onChange={value => onChange({[property]: value})}- />- </SidePanelSection>-);+export const AggregationTypeSelector = ({layer, channel, onChange}) => {+ const {field, aggregation, key} = channel;+ const selectedField = layer.config[field];+ const {visConfig} = layer.config;++ // aggregation should only be selectable when field is selected+ const aggregationOptions = layer.getAggregationOptions(key);++ return (+ <SidePanelSection>+ <PanelLabel>{`Aggregate ${selectedField.name} by`}</PanelLabel>+ <ItemSelector+ selectedItems={visConfig[aggregation]}+ options={aggregationOptions}+ multiSelect={false}+ searchable={false}+ onChange={value =>+ onChange(+ {+ visConfig: {+ ...layer.config.visConfig,+ [aggregation]: value+ }+ },+ channel.key+ )+ }+ />+ </SidePanelSection>+ );+};/* eslint-enable max-params */diff --git a/src/components/side-panel/layer-panel/vis-config-by-field-selector.js b/src/components/side-panel/layer-panel/vis-config-by-field-selector.jsindex a4f2feb53..3a94ef538 100644--- a/src/components/side-panel/layer-panel/vis-config-by-field-selector.js+++ b/src/components/side-panel/layer-panel/vis-config-by-field-selector.js@@ -34,19 +34,19 @@ import {capitalizeFirstLetter} from 'utils/utils';export default class VisConfigByFieldSelector extends Component {static propTypes = {channel: PropTypes.string.isRequired,- domain: PropTypes.arrayOf(PropTypes.any).isRequired,fields: PropTypes.arrayOf(PropTypes.any).isRequired,id: PropTypes.string.isRequired,property: PropTypes.string.isRequired,- scaleType: PropTypes.string.isRequired,showScale: PropTypes.bool.isRequired,updateField: PropTypes.func.isRequired,updateScale: PropTypes.func.isRequired,// optional+ scaleType: PropTypes.string,selectedField: PropTypes.object,description: PropTypes.string,- label: PropTypes.string+ label: PropTypes.string,+ placeholder: PropTypes.string};_updateVisByField = val => {@@ -79,6 +79,7 @@ export default class VisConfigByFieldSelector extends Component {<FieldSelectorfields={this.props.fields}value={selectedField && selectedField.name}+ placeholder={this.props.placeholder}onSelect={this._updateVisByField}erasable/>diff --git a/src/constants/default-settings.js b/src/constants/default-settings.jsindex 32b081c7b..322f216d5 100644--- a/src/constants/default-settings.js+++ b/src/constants/default-settings.js@@ -275,6 +275,20 @@ export const CHANNEL_SCALES = keyMirror({sizeAggr: null});+export const AGGREGATION_TYPES = {+ // default+ count: 'count',+ // linear+ average: 'average',+ maximum: 'maximum',+ minimum: 'minimum',+ median: 'median',+ sum: 'sum',+ // ordinal+ mode: 'mode',+ countUnique: 'count unique'+};+export const linearFieldScaleFunctions = {[CHANNEL_SCALES.color]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile],[CHANNEL_SCALES.radius]: [SCALE_TYPES.sqrt],@@ -282,8 +296,21 @@ export const linearFieldScaleFunctions = {};export const linearFieldAggrScaleFunctions = {- [CHANNEL_SCALES.colorAggr]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile],- [CHANNEL_SCALES.sizeAggr]: [SCALE_TYPES.linear]+ [CHANNEL_SCALES.colorAggr]: {+ [AGGREGATION_TYPES.average]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile],+ [AGGREGATION_TYPES.maximum]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile],+ [AGGREGATION_TYPES.minimum]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile],+ [AGGREGATION_TYPES.median]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile],+ [AGGREGATION_TYPES.sum]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile]+ },++ [CHANNEL_SCALES.sizeAggr]: {+ [AGGREGATION_TYPES.average]: [SCALE_TYPES.linear],+ [AGGREGATION_TYPES.maximum]: [SCALE_TYPES.linear],+ [AGGREGATION_TYPES.minimum]: [SCALE_TYPES.linear],+ [AGGREGATION_TYPES.median]: [SCALE_TYPES.linear],+ [AGGREGATION_TYPES.sum]: [SCALE_TYPES.linear]+ }};export const OrdinalFieldScaleFunctions = {@@ -293,17 +320,37 @@ export const OrdinalFieldScaleFunctions = {};export const OrdinalFieldAggrScaleFunctions = {+ // [CHANNEL_SCALES.colorAggr]: [SCALE_TYPES.ordinal, SCALE_TYPES.linear],+ [CHANNEL_SCALES.colorAggr]: {+ [AGGREGATION_TYPES.mode]: [SCALE_TYPES.ordinal],+ [AGGREGATION_TYPES.countUnique]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile]+ },+// Currently doesn't support yet- [CHANNEL_SCALES.colorAggr]: [],- [CHANNEL_SCALES.sizeAggr]: []+ [CHANNEL_SCALES.sizeAggr]: {}};export const notSupportedScaleOpts = {[CHANNEL_SCALES.color]: [],[CHANNEL_SCALES.radius]: [],- [CHANNEL_SCALES.size]: [],- [CHANNEL_SCALES.colorAggr]: [],- [CHANNEL_SCALES.sizeAggr]: []+ [CHANNEL_SCALES.size]: []+};++export const notSupportAggrOpts = {+ [CHANNEL_SCALES.colorAggr]: {},+ [CHANNEL_SCALES.sizeAggr]: {}+};++/**+ * Default aggregation are based on ocunt+ */+export const DEFAULT_AGGREGATION = {+ [CHANNEL_SCALES.colorAggr]: {+ [AGGREGATION_TYPES.count]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile]+ },+ [CHANNEL_SCALES.sizeAggr]: {+ [AGGREGATION_TYPES.count]: [SCALE_TYPES.linear]+ }};/**@@ -332,7 +379,10 @@ export const FIELD_OPTS = {},timestamp: {type: 'time',- scale: linearFieldScaleFunctions,+ scale: {+ ...linearFieldScaleFunctions,+ ...notSupportAggrOpts+ },format: {legend: d => d}@@ -349,20 +399,29 @@ export const FIELD_OPTS = {},boolean: {type: 'boolean',- scale: OrdinalFieldScaleFunctions,+ scale: {+ ...OrdinalFieldScaleFunctions,+ ...OrdinalFieldAggrScaleFunctions+ },format: {legend: d => d}},date: {- scale: OrdinalFieldScaleFunctions,+ scale: {+ ...OrdinalFieldScaleFunctions,+ ...OrdinalFieldAggrScaleFunctions+ },format: {legend: d => d}},geojson: {type: 'geometry',- scale: notSupportedScaleOpts,+ scale: {+ ...notSupportedScaleOpts,+ ...notSupportAggrOpts+ },format: {legend: d => '...'}@@ -375,7 +434,7 @@ export const CHANNEL_SCALE_SUPPORTED_FIELDS = Object.keys((accu, key) => ({...accu,[key]: Object.keys(FIELD_OPTS).filter(- ft => FIELD_OPTS[ft].scale[key] && FIELD_OPTS[ft].scale[key].length+ ft => Object.keys(FIELD_OPTS[ft].scale[key]).length)}),{}@@ -440,15 +499,6 @@ export const LAYER_BLENDINGS = {}};-export const AGGREGATION_TYPES = keyMirror({- average: null,- maximum: null,- minimum: null,- median: null,- sum: null,- countUnique: null-});-export const MAX_DEFAULT_TOOLTIPS = 5;export const RESOLUTIONS = keyMirror({diff --git a/src/deckgl-layers/cluster-layer/cluster-layer.js b/src/deckgl-layers/cluster-layer/cluster-layer.jsindex 42d41b981..1ac2eb01f 100644--- a/src/deckgl-layers/cluster-layer/cluster-layer.js+++ b/src/deckgl-layers/cluster-layer/cluster-layer.js@@ -20,8 +20,12 @@import {CompositeLayer, ScatterplotLayer} from 'deck.gl';import geoViewport from '@mapbox/geo-viewport';-import {ascending, extent, max} from 'd3-array';-+import {ascending, max} from 'd3-array';+import {+ getQuantileDomain,+ getOrdinalDomain,+ getLinearDomain+} from 'utils/data-scale-utils';import {getColorScaleFunction,getRadiusScaleFunction,@@ -150,13 +154,16 @@ export default class ClusterLayer extends CompositeLayer {const radiusDomain = [0, max(clusters, getRadiusValue)];- const colorValues = clusters- .map(d => getColorValue(d.properties.points))- .filter(n => Number.isFinite(n));+ const colorValues = clusters.map(d => getColorValue(d.properties.points));++ const identity = d => d;+const colorDomain =- colorScale === SCALE_TYPES.quantize- ? extent(colorValues)- : colorValues.sort(ascending);+ colorScale === SCALE_TYPES.ordinal+ ? getOrdinalDomain(colorValues, identity)+ : colorScale === SCALE_TYPES.quantile+ ? getQuantileDomain(colorValues, identity, ascending)+ : getLinearDomain(colorValues, identity);this.setState({colorDomain,@@ -198,9 +205,7 @@ export default class ClusterLayer extends CompositeLayer {// if cell value is outside domain, set alpha to 0const color =- Number.isFinite(cv) &&- cv >= colorDomain[0] &&- cv <= colorDomain[colorDomain.length - 1]+ cv >= colorDomain[0] && cv <= colorDomain[colorDomain.length - 1]? colorScaleFunc(cv): [0, 0, 0, 0];diff --git a/src/deckgl-layers/layer-utils/utils.js b/src/deckgl-layers/layer-utils/utils.jsindex a846b5a13..63dc2c7b4 100644--- a/src/deckgl-layers/layer-utils/utils.js+++ b/src/deckgl-layers/layer-utils/utils.js@@ -18,7 +18,9 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import {scaleQuantize, scaleQuantile, scaleSqrt} from 'd3-scale';+import {scaleQuantize, scaleOrdinal, scaleQuantile, scaleSqrt} from 'd3-scale';+import {unique} from 'utils//data-utils';+import {SCALE_TYPES} from 'constants/default-settings';// Enable render color by customized color Scale@@ -29,7 +31,8 @@ export function getBinColorDomain(scaleType, bins, [lowerIdx, upperIdx]) {case SCALE_TYPES.quantile:return bins.slice(lowerIdx, upperIdx + 1).map(d => d.value);-+ case SCALE_TYPES.ordinal:+ return unique(bins.map(b => b.value)).sort();default:return [bins[lowerIdx].value, bins[upperIdx].value];}@@ -42,7 +45,8 @@ export function getScaleFunctor(scaleType) {case SCALE_TYPES.quantile:return scaleQuantile;-+ case SCALE_TYPES.ordinal:+ return scaleOrdinal;default:return scaleQuantile;}diff --git a/src/layers/aggregation-layer.js b/src/layers/aggregation-layer.jsindex fd2fe5dc6..bd394ea17 100644--- a/src/layers/aggregation-layer.js+++ b/src/layers/aggregation-layer.js@@ -22,7 +22,7 @@ import memoize from 'lodash.memoize';import Layer from './base-layer';import {hexToRgb} from 'utils/color-utils';import {aggregate} from 'utils/aggregate-utils';-import {CHANNEL_SCALES} from 'constants/default-settings';+import {CHANNEL_SCALES, FIELD_OPTS, DEFAULT_AGGREGATION} from 'constants/default-settings';export const pointPosAccessor = ({lat, lng}) => d => [d[lng.fieldIdx],@@ -83,29 +83,47 @@ export default class AggregationLayer extends Layer {get visualChannels() {return {color: {- property: 'color',- field: 'colorField',- scale: 'colorScale',+ aggregation: 'colorAggregation',+ channelScaleType: CHANNEL_SCALES.colorAggr,+ defaultMeasure: 'Point Count',domain: 'colorDomain',- range: 'colorRange',+ field: 'colorField',key: 'color',- channelScaleType: CHANNEL_SCALES.colorAggr,- defaultMeasure: 'Point Count'+ property: 'color',+ range: 'colorRange',+ scale: 'colorScale'},size: {- property: 'height',- field: 'sizeField',- scale: 'sizeScale',- domain: 'sizeDomain',- range: 'sizeRange',- key: 'size',+ aggregation: 'sizeAggregation',channelScaleType: CHANNEL_SCALES.sizeAggr,+ condition: config => config.visConfig.enable3d,defaultMeasure: 'Point Count',- condition: config => config.visConfig.enable3d+ domain: 'sizeDomain',+ field: 'sizeField',+ key: 'size',+ property: 'height',+ range: 'sizeRange',+ scale: 'sizeScale'}};}+ /**+ * Get the description of a visualChannel config+ * @param key+ * @returns {{label: string, measure: (string|string)}}+ */+ getVisualChannelDescription(key) {+ // e.g. label: Color, measure: Average of ETA+ const {range, field, defaultMeasure, aggregation} = this.visualChannels[key];+ return {+ label: this.visConfigSettings[range].label,+ measure: this.config[field]+ ? `${this.config.visConfig[aggregation]} of ${this.config[field].name}`+ : defaultMeasure+ }+ }+getHoverData(object) {// return aggregated objectreturn object;@@ -118,6 +136,66 @@ export default class AggregationLayer extends Layer {this.validateVisualChannel(channel);}+ /**+ * Validate aggregation type on top of basic layer visual channel validation+ * @param channel+ */+ validateVisualChannel(channel) {++ // field type decides aggregation type decides scale type+ this.validateFieldType(channel);+ this.validateAggregationType(channel);+ this.validateScale(channel);+ }++ /**+ * Validate aggregation type based on selected field+ */+ validateAggregationType(channel) {+ const visualChannel = this.visualChannels[channel];+ const {field, aggregation} = visualChannel;+ const aggregationOptions = this.getAggregationOptions(channel);++ if (!aggregation) {+ return;+ }++ if (!aggregationOptions.length) {+ // if field cannot be aggregated, set field to null+ this.updateLayerConfig({[field]: null});++ } else if (!aggregationOptions.includes(this.config.visConfig[aggregation])) {+ // current aggregation type is not supported by this field+ // set aggregation to the first supported option+ this.updateLayerVisConfig({[aggregation]: aggregationOptions[0]});+ }+ }++ getAggregationOptions(channel) {+ const visualChannel = this.visualChannels[channel];+ const {field, channelScaleType} = visualChannel;++ return Object.keys(+ this.config[field] ? FIELD_OPTS[this.config[field].type].scale[channelScaleType] :+ DEFAULT_AGGREGATION[channelScaleType])+ }++ /**+ * Get scale options based on current field and aggregation type+ * @param {string} channel+ * @returns {string[]}+ */+ getScaleOptions(channel) {+ const visualChannel = this.visualChannels[channel];+ const {field, aggregation, channelScaleType} = visualChannel;+ const aggregationType = this.config.visConfig[aggregation];+ return this.config[field] ?+ // scale options based on aggregation+ FIELD_OPTS[this.config[field].type].scale[channelScaleType][aggregationType] :+ // default scale options for point count+ DEFAULT_AGGREGATION[channelScaleType][aggregationType];+ }+/*** Aggregation layer handles visual channel aggregation inside deck.gl layer*/diff --git a/src/layers/base-layer.js b/src/layers/base-layer.jsindex 24b259c05..52ddd2a94 100644--- a/src/layers/base-layer.js+++ b/src/layers/base-layer.js@@ -271,7 +271,7 @@ export default class Layer {isConfigActive: props.isConfigActive || false,highlightColor: props.highlightColor || [252, 242, 26],- // TODO: refactor this into seperate visual Channel config+ // TODO: refactor this into separate visual Channel config// color by field, domain is set by filters, field, scale typecolorField: null,colorDomain: [0, 1],@@ -286,6 +286,21 @@ export default class Layer {};}+ /**+ * Get the description of a visualChannel config+ * @param key+ * @returns {{label: string, measure: (string|string)}}+ */+ getVisualChannelDescription(key) {+ // e.g. label: Color, measure: Vehicle Type+ return {+ label: this.visConfigSettings[this.visualChannels[key].range].label,+ measure: this.config[this.visualChannels[key].field]+ ? this.config[this.visualChannels[key].field].name+ : this.visualChannels[key].defaultMeasure+ }+ }+/*** Assign a field to layer column, return column config* @param key - Column Key@@ -399,7 +414,6 @@ export default class Layer {const copied = this.copyLayerConfig(currentConfig, configToCopy, {notToDeepMerge, notToCopy});this.updateLayerConfig(copied);-// validate visualChannel field type and scale typesObject.keys(this.visualChannels).forEach(channel => {this.validateVisualChannel(channel);@@ -633,32 +647,61 @@ export default class Layer {* @param channel*/validateVisualChannel(channel) {+ this.validateFieldType(channel);+ this.validateScale(channel);+ }++ /**+ * Validate field type based on channelScaleType+ */+ validateFieldType(channel) {const visualChannel = this.visualChannels[channel];- const {field, scale, channelScaleType} = visualChannel;+ const {field, channelScaleType, supportedFieldTypes} = visualChannel;if (this.config[field]) {// if field is selected, check if field type is supported- const supportedFieldType = CHANNEL_SCALE_SUPPORTED_FIELDS[channelScaleType];+ const channelSupportedFieldTypes = supportedFieldTypes || CHANNEL_SCALE_SUPPORTED_FIELDS[channelScaleType];- if (!supportedFieldType.includes(this.config[field].type)) {+ if (!channelSupportedFieldTypes.includes(this.config[field].type)) {// field type is not supported, set it back to null// set scale back to default- const defaultScale = this.getDefaultLayerConfig()[scale];- this.updateLayerConfig({[field]: null, [scale]: defaultScale});+ this.updateLayerConfig({[field]: null});}+ }+ }- // check if current selected scale is- // supported, if not, update to default- if (this.config[field]) {- const scaleOptions =- FIELD_OPTS[this.config[field].type].scale[channelScaleType];- if (!scaleOptions.includes(this.config[scale])) {- this.updateLayerConfig({[scale]: scaleOptions[0]});- }- }+ /**+ * Validate scale type based on aggregation+ */+ validateScale(channel) {+ const visualChannel = this.visualChannels[channel];+ const {scale} = visualChannel;+ if (!scale) {+ // visualChannel doesn't have scale+ return;+ }+ const scaleOptions = this.getScaleOptions(channel);+ // check if current selected scale is+ // supported, if not, change to default+ if (!scaleOptions.includes(this.config[scale])) {+ this.updateLayerConfig({[scale]: scaleOptions[0]});}}+ /**+ * Get scale options based on current field+ * @param {string} channel+ * @returns {string[]}+ */+ getScaleOptions(channel) {+ const visualChannel = this.visualChannels[channel];+ const {field, scale, channelScaleType} = visualChannel;++ return this.config[field] ?+ FIELD_OPTS[this.config[field].type].scale[channelScaleType] :+ [this.getDefaultLayerConfig()[scale]];+ }+updateLayerVisualChannel(dataset, channel) {const visualChannel = this.visualChannels[channel];diff --git a/src/layers/cluster-layer/cluster-layer.js b/src/layers/cluster-layer/cluster-layer.jsindex 228914d70..5028aa1d1 100644--- a/src/layers/cluster-layer/cluster-layer.js+++ b/src/layers/cluster-layer/cluster-layer.js@@ -30,14 +30,12 @@ export const clusterVisConfigs = {colorRange: 'colorRange',radiusRange: 'clusterRadiusRange','hi-precision': 'hi-precision',- colorAggregation: 'aggregation',- sizeAggregation: 'aggregation'+ colorAggregation: 'aggregation'};export default class ClusterLayer extends AggregationLayer {constructor(props) {super(props);-this.registerVisConfig(clusterVisConfigs);}@@ -51,14 +49,15 @@ export default class ClusterLayer extends AggregationLayer {get visualChannels() {return {color: {- property: 'color',- field: 'colorField',- scale: 'colorScale',+ aggregation: 'colorAggregation',+ channelScaleType: CHANNEL_SCALES.colorAggr,+ defaultMeasure: 'Point Count',domain: 'colorDomain',- range: 'colorRange',+ field: 'colorField',key: 'color',- defaultMeasure: 'Point Count',- channelScaleType: CHANNEL_SCALES.colorAggr+ property: 'color',+ range: 'colorRange',+ scale: 'colorScale'}};}diff --git a/src/layers/grid-layer/grid-layer.js b/src/layers/grid-layer/grid-layer.jsindex 4ed7e63a5..057aef519 100644--- a/src/layers/grid-layer/grid-layer.js+++ b/src/layers/grid-layer/grid-layer.js@@ -31,11 +31,11 @@ export const gridVisConfigs = {coverage: 'coverage',sizeRange: 'elevationRange',percentile: 'percentile',- elevationPercentile: 'percentile',+ elevationPercentile: 'elevationPercentile',elevationScale: 'elevationScale','hi-precision': 'hi-precision',colorAggregation: 'aggregation',- sizeAggregation: 'aggregation',+ sizeAggregation: 'sizeAggregation',enable3d: 'enable3d'};@@ -44,6 +44,7 @@ export default class GridLayer extends AggregationLayer {super(props);this.registerVisConfig(gridVisConfigs);+ this.visConfigSettings.worldUnitSize.label = 'Grid Size (km)';}get type() {diff --git a/src/layers/heatmap-layer/heatmap-layer.js b/src/layers/heatmap-layer/heatmap-layer.jsindex ca98a1e9d..0fd885833 100644--- a/src/layers/heatmap-layer/heatmap-layer.js+++ b/src/layers/heatmap-layer/heatmap-layer.js@@ -19,29 +19,24 @@// THE SOFTWARE.import {createSelector} from 'reselect';-import {CHANNEL_SCALES, SCALE_FUNC, SCALE_TYPES} from 'constants/default-settings';+import {CHANNEL_SCALES, SCALE_FUNC, ALL_FIELD_TYPES} from 'constants/default-settings';import {hexToRgb} from 'utils/color-utils';import {geojsonFromPoints} from '../mapbox-utils';import MapboxGLLayer from '../mapboxgl-layer';import HeatmapLayerIcon from './heatmap-layer-icon';const MAX_ZOOM_LEVEL = 18;-const DEFAULT_OPACITY = .8;export const heatmapVisConfigs = {opacity: 'opacity',- weight: 'weight',colorRange: 'colorRange',- radius: 'heatmapRadius',- weightRange: 'weight'+ radius: 'heatmapRadius'};/***- * @param colorDomain- * @param colorScale- * @param visConfig- * @return [+ * @param {Object} colorRange+ * @return {Array} [* 0, "rgba(33,102,172,0)",* 0.2, "rgb(103,169,207)",* 0.4, "rgb(209,229,240)",@@ -50,27 +45,13 @@ export const heatmapVisConfigs = {* 1, "rgb(178,24,43)"* ]*/-const heatmapDensity = (colorDomain, colorScale, visConfig) => {+const heatmapDensity = (colorRange) => {- // this is work around to deal with ordinal scale type.- // I checked other aggregate layers and we don't deal with ordinal scales- const scaleType = colorScale === SCALE_TYPES.ordinal ?- SCALE_TYPES.quantize : colorScale;-- const scaleFunction = SCALE_FUNC[scaleType];+ const scaleFunction = SCALE_FUNC.quantize;const scale = scaleFunction()- .domain(colorDomain)- .range(visConfig.colorRange.colors);-- if (colorScale === SCALE_TYPES.ordinal) {- scale.domain().map(level => {- return [- scale(level),- `rgb(${hexToRgb(scale(level)).join(',')})` // color- ];- })- }+ .domain([0, 1])+ .range(colorRange.colors);return scale.range().reduce((bands, level) => {const invert = scale.invertExtent(level);@@ -96,15 +77,17 @@ class HeatmapLayer extends MapboxGLLayer {get visualChannels() {return {- ...super.visualChannels,weight: {property: 'weight',field: 'weightField',scale: 'weightScale',domain: 'weightDomain',- range: 'weightRange',key: 'weight',- channelScaleType: CHANNEL_SCALES.sizeAggr+ // supportedFieldTypes can be determined by channelScaleType+ // or specified here+ defaultMeasure: 'density',+ supportedFieldTypes: [ALL_FIELD_TYPES.real, ALL_FIELD_TYPES.integer],+ channelScaleType: CHANNEL_SCALES.size}};}@@ -113,25 +96,40 @@ class HeatmapLayer extends MapboxGLLayer {return HeatmapLayerIcon;}+ getVisualChannelDescription(channel) {+ return channel === 'color' ? {+ label: 'color',+ measure: 'Density'+ } : {+ label: 'weight',+ measure: this.config.weightField ? this.config.weightField.name : 'Density'+ }+ }+getDefaultLayerConfig(props = {}) {- return {++ // mapbox heatmap layer color is always based on density+ // no need to set colorField, colorDomain and colorScale+ /* eslint-disable no-unused-vars */+ const {colorField, colorDomain, colorScale, ...layerConfig} = {...super.getDefaultLayerConfig(props),- // add height visual channel+weightField: null,weightDomain: [0, 1],- weightRange: [0, 1],weightScale: 'linear'- }+ };+ /* eslint-enable no-unused-vars */++ return layerConfig;}- sameDataSelector = ({allData, filteredIndex, oldLayerData, opt = {}}) => {- return Boolean(oldLayerData &&- oldLayerData.data && oldLayerData.columns &&+ isSameData = ({allData, filteredIndex, oldLayerData, opt = {}}, config) => {+ return Boolean(oldLayerData && oldLayerData.columns === config.columns &&opt.sameData);};- sameConfigSelector = ({oldLayerData, config}) => {+ isSameConfig = ({oldLayerData, config}) => {// columns must use the same filedIdx// this is a fast way to compare columns objectconst {@@ -148,32 +146,24 @@ class HeatmapLayer extends MapboxGLLayer {return sameColumns && sameWeightField;};- rebuildSelector = createSelector(- this.sameDataSelector,- this.sameConfigSelector,- (sameData, sameColumns) => !(sameData && sameColumns)- );-datasetSelector = config => config.dataId;isVisibleSelector = config => config.isVisible;visConfigSelector = config => config.visConfig;- weightFieldSelector = config => config.weightField;- colorDomainSelector = config => config.colorDomain;- colorScaleSelector = config => config.colorScale;- radiusSelector = config => config.visConfig.radius;+ weightFieldSelector = config => config.weightField ? config.weightField.name : null;+ weightDomainSelector = config => config.weightDomain;computeHeatmapConfiguration = createSelector(this.datasetSelector,this.isVisibleSelector,this.visConfigSelector,this.weightFieldSelector,- this.colorDomainSelector,- this.colorScaleSelector,- this.radiusSelector,- (datasetId, isVisible, visConfig, weightField, colorDomain, colorScale, radius) => {- // TODO: improve using setPaintProperty- return {+ this.weightDomainSelector,++ (datasetId, isVisible, visConfig, weightField, weightDomain) => {++ const layer = {type: 'heatmap',+ id: this.id,source: datasetId,layout: {visibility: isVisible ? 'visible' : 'none'@@ -183,9 +173,9 @@ class HeatmapLayer extends MapboxGLLayer {'heatmap-weight': weightField ? ['interpolate',['linear'],- ['get', weightField.name],- 0, 0,- MAX_ZOOM_LEVEL, visConfig.weight+ ['get', weightField],+ weightDomain[0], 0,+ weightDomain[1], 1] : 1,'heatmap-intensity': ['interpolate',@@ -198,18 +188,20 @@ class HeatmapLayer extends MapboxGLLayer {'interpolate',['linear'],['heatmap-density'],- ...heatmapDensity(colorDomain, colorScale, visConfig)+ ...heatmapDensity(visConfig.colorRange)],'heatmap-radius': ['interpolate',['linear'],['zoom'],0, 2,- MAX_ZOOM_LEVEL, radius // radius+ MAX_ZOOM_LEVEL, visConfig.radius // radius],- 'heatmap-opacity': visConfig.opacity || DEFAULT_OPACITY+ 'heatmap-opacity': visConfig.opacity}};++ return layer;});@@ -223,8 +215,10 @@ class HeatmapLayer extends MapboxGLLayer {};const {weightField} = this.config;+ const isSameData = this.isSameData(options, this.config);+ const isSameConfig = this.isSameConfig(options);- const data = !shouldRebuild(this.sameDataSelector(options), this.sameConfigSelector(options)) ?+ const data = !shouldRebuild(isSameData, isSameConfig) ?null :geojsonFromPoints(allData,diff --git a/src/layers/hexagon-layer/hexagon-layer.js b/src/layers/hexagon-layer/hexagon-layer.jsindex 979053a2b..3db7671c8 100644--- a/src/layers/hexagon-layer/hexagon-layer.js+++ b/src/layers/hexagon-layer/hexagon-layer.js@@ -36,7 +36,7 @@ export const hexagonVisConfigs = {elevationScale: 'elevationScale','hi-precision': 'hi-precision',colorAggregation: 'aggregation',- sizeAggregation: 'aggregation',+ sizeAggregation: 'sizeAggregation',enable3d: 'enable3d'};@@ -45,6 +45,7 @@ export default class HexagonLayer extends AggregationLayer {super(props);this.registerVisConfig(hexagonVisConfigs);+ this.visConfigSettings.worldUnitSize.label = 'Hexagon Radius (km)';}get type() {diff --git a/src/layers/layer-factory.js b/src/layers/layer-factory.jsindex 821202070..704c1f26b 100644--- a/src/layers/layer-factory.js+++ b/src/layers/layer-factory.js@@ -149,9 +149,21 @@ export const LAYER_VIS_CONFIGS = {type: 'select',defaultValue: AGGREGATION_TYPES.average,label: 'Color Aggregation',+ // aggregation options are based on color field typesoptions: Object.keys(AGGREGATION_TYPES),group: PROPERTY_GROUPS.color,- property: 'colorAggregation'+ property: 'colorAggregation',+ condition: config => config.colorField+ },+ sizeAggregation: {+ type: 'select',+ defaultValue: AGGREGATION_TYPES.average,+ label: 'Height Aggregation',+ // aggregation options are based on color field types+ options: Object.keys(AGGREGATION_TYPES),+ group: PROPERTY_GROUPS.height,+ property: 'sizeAggregation',+ condition: config => config.sizeField},percentile: {type: 'number',@@ -166,7 +178,10 @@ export const LAYER_VIS_CONFIGS = {range: [0, 100],step: 0.01,group: PROPERTY_GROUPS.color,- property: 'percentile'+ property: 'percentile',++ // percentile filter only makes sense with linear aggregation+ condition: config => config.colorScale !== 'ordinal'},elevationPercentile: {type: 'number',@@ -181,7 +196,9 @@ export const LAYER_VIS_CONFIGS = {range: [0, 100],step: 0.01,group: PROPERTY_GROUPS.height,- property: 'elevationPercentile'+ property: 'elevationPercentile',+ // percentile filter only makes sense with linear aggregation+ condition: config => config.visConfig.enable3d && (config.colorField || config.sizeField)},resolution: {type: 'number',@@ -209,7 +226,7 @@ export const LAYER_VIS_CONFIGS = {label: 'Elevation Scale',isRanged: false,range: [0, 100],- step: 1,+ step: 0.1,group: PROPERTY_GROUPS.height,property: 'elevationScale'},@@ -271,12 +288,13 @@ export const LAYER_VIS_CONFIGS = {weight: {type: 'number',defaultValue: 1,- label: 'Weight',+ label: 'Weight Intensity',isRanged: false,range: [0.01, 500],step: 0.01,group: PROPERTY_GROUPS.cell,- property: 'weight'+ property: 'weight',+ condition: config => config.weightField},heatmapRadius: {type: 'number',diff --git a/src/layers/mapbox-utils.js b/src/layers/mapbox-utils.jsindex 846a31b9e..0a3fe9b8f 100644--- a/src/layers/mapbox-utils.js+++ b/src/layers/mapbox-utils.js@@ -61,6 +61,7 @@ export function generateMapboxLayers(layers = [], layerData = [], layerOrder = [*/export function updateMapboxLayers(map, newLayers = [], oldLayers = null, mapLayers = null, opt = {force: true}) {// delete non existing layers+if (oldLayers) {const oldLayersKeys = Object.keys(oldLayers);if (newLayers.length === 0 && oldLayersKeys.length > 0) {diff --git a/src/layers/mapboxgl-layer.js b/src/layers/mapboxgl-layer.jsindex 295b37c9e..eefd08df2 100644--- a/src/layers/mapboxgl-layer.js+++ b/src/layers/mapboxgl-layer.js@@ -18,7 +18,6 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import {CHANNEL_SCALES} from 'constants/default-settings';import Layer, {OVERLAY_TYPE} from './base-layer';export const mapboxRequiredColumns = ['lat', 'lng'];@@ -50,28 +49,7 @@ class MapboxLayerGL extends Layer {}get visualChannels() {- return {- color: {- property: 'color',- field: 'colorField',- scale: 'colorScale',- domain: 'colorDomain',- range: 'colorRange',- key: 'color',- channelScaleType: CHANNEL_SCALES.colorAggr,- defaultMeasure: 'Point Count'- },- weight: {- property: 'weight',- field: 'weightField',- scale: 'weightScale',- domain: 'weightDomain',- range: 'weightRange',- key: 'weight',- channelScaleType: CHANNEL_SCALES.sizeAggr,- defaultMeasure: 'Weight'- }- };+ return {};}// this layer is rendered at mapbox leveldiff --git a/src/utils/aggregate-utils.js b/src/utils/aggregate-utils.jsindex 9816db645..469913f75 100644--- a/src/utils/aggregate-utils.js+++ b/src/utils/aggregate-utils.js@@ -21,6 +21,17 @@import {min, max, mean, median, sum} from 'd3-array';import {AGGREGATION_TYPES} from 'constants/default-settings';+const getFrenquency = data => data.reduce((uniques, val) => {+ uniques[val] = (uniques[val] || 0) + 1;+ return uniques;+}, {});++function getMode(data) {+ const occur = getFrenquency(data);+ return Object.keys(occur).reduce((prev, key) =>+ occur[prev] >= occur[key] ? prev : key, Object.keys(occur)[0]);+}+export function aggregate(data, technique) {switch (technique) {case AGGREGATION_TYPES.average:@@ -28,10 +39,14 @@ export function aggregate(data, technique) {case AGGREGATION_TYPES.countUnique:return Object.keys(data.reduce((uniques, val) => {- uniques[val] = true;+ uniques[val] = uniques[val] || 0;+ uniques[val] += 1;return uniques;}, {})).length;+ case AGGREGATION_TYPES.mode:+ return getMode(data);+case AGGREGATION_TYPES.maximum:return max(data);case AGGREGATION_TYPES.minimum:diff --git a/src/utils/data-scale-utils.js b/src/utils/data-scale-utils.jsindex d6b9db8f6..e18378b9e 100644--- a/src/utils/data-scale-utils.js+++ b/src/utils/data-scale-utils.js@@ -45,7 +45,7 @@ export function getOrdinalDomain(data, valueAccessor) {const values =typeof valueAccessor === 'function' ? data.map(valueAccessor) : data;- return unique(values).filter(notNullorUndefined);+ return unique(values).filter(notNullorUndefined).sort();}/**diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.jsindex 71403fcdb..99d10fcc8 100644--- a/test/fixtures/state-saved-v0.js+++ b/test/fixtures/state-saved-v0.js@@ -897,7 +897,7 @@ export const mergedFilters = [name: 'song_name',type: 'multiSelect',fieldIdx: 0,- domain: ['3.68.4', '2.117.1', '2.116.2', '2.103.2', '2.107.3'],+ domain: ['2.103.2', '2.107.3', '2.116.2', '2.117.1', '3.68.4' ],value: ['3.68.4', '2.117.1', '2.103.2', '2.116.2'],fieldType: 'string',plotType: 'histogram',@@ -1152,7 +1152,7 @@ mergedLayer2.config = {tableFieldIndex: 1},colorScale: 'ordinal',- colorDomain: ['3.68.4', '2.117.1', '2.116.2', '2.103.2', '2.107.3'],+ colorDomain: ['2.103.2', '2.107.3', '2.116.2', '2.117.1', '3.68.4'],sizeField: {name: 'int_range',format: '',diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.jsindex f46c94135..b5bbf756f 100644--- a/test/helpers/mock-state.js+++ b/test/helpers/mock-state.js@@ -287,8 +287,8 @@ export const expectedSavedLayer0 = {elevationPercentile: [0, 100],elevationScale: 5,'hi-precision': false,- colorAggregation: 'average',- sizeAggregation: 'average',+ colorAggregation: 'count',+ sizeAggregation: 'count',enable3d: false}},@@ -335,8 +335,8 @@ export const expectedLoadedLayer0 = {elevationPercentile: [0, 100],elevationScale: 5,'hi-precision': false,- colorAggregation: 'average',- sizeAggregation: 'average',+ colorAggregation: 'count',+ sizeAggregation: 'count',enable3d: false},colorField: null,diff --git a/test/node/layer-tests/heatmap-layer-specs.js b/test/node/layer-tests/heatmap-layer-specs.jsindex 520072d02..9da097a48 100644--- a/test/node/layer-tests/heatmap-layer-specs.js+++ b/test/node/layer-tests/heatmap-layer-specs.js@@ -40,9 +40,9 @@ test('#HeatmapLayer -> contructor', t => {test: layer => {// test constructort.equal(- layer.config.visConfig.weight,- 1,- 'Heatmap default layer weight should be 1'+ layer.config.visConfig.radius,+ 20,+ 'Heatmap default radius should be 20')}}diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.jsindex d430fdd7f..fd35afe17 100644--- a/test/node/reducers/vis-state-test.js+++ b/test/node/reducers/vis-state-test.js@@ -458,18 +458,18 @@ test('#visStateReducer -> LAYER_TYPE_CHANGE.2', t => {t.equal(newLayer3.type, 'hexagon', 'should change type to hexagon');t.equal(newLayer3.config.colorField,- null,- 'should set colorField back to null'+ stringField,+ 'should keep colorField');t.deepEqual(newLayer3.config.colorDomain,[0, 1],- 'should set colorDomain back to default'+ 'should set colorDomain to default, it is calculated inside deck.gl layer');t.equal(newLayer3.config.colorScale,- 'quantile',- 'should set colorScale to default'+ 'ordinal',+ 'should set colorScale to ordinal');t.equal(newLayer3.config.sizeScale,diff --git a/test/node/utils/data-scale-utils-test.js b/test/node/utils/data-scale-utils-test.jsindex fb7e4983f..872e84d99 100644--- a/test/node/utils/data-scale-utils-test.js+++ b/test/node/utils/data-scale-utils-test.js@@ -30,7 +30,6 @@ function numberSort(a, b) {}test('DataScaleUtils -> getOrdinalDomain', t => {- t.plan(2);const data = ['a', 'a', 'b', undefined, null, 0];function valueAccessor(d) {@@ -39,15 +38,16 @@ test('DataScaleUtils -> getOrdinalDomain', t => {const values = [{value: 'a'}, {value: 'b'}, {value: 'b'}];- t.deepEqual(getOrdinalDomain(data), ['a', 'b', 0],+ t.deepEqual(getOrdinalDomain(data), [0, 'a', 'b'],'should get correct ordinal domain');t.deepEqual(getOrdinalDomain(values, valueAccessor), ['a', 'b'],'should get correct ordinal domain');++ t.end();});test('DataScaleUtils -> getQuantileDomain', t => {- t.plan(3);const data = ['a', 'b', 'c', 'b', undefined, null];const quanData = [1, 4, 2, 3, 1, undefined, null, 0];@@ -65,10 +65,11 @@ test('DataScaleUtils -> getQuantileDomain', t => {t.deepEqual(getQuantileDomain(values, valueAccessor), ['a', 'b', 'b'],'should get correct quantile domain');++ t.end();});test('DataScaleUtils -> getLinearDomain', t => {- t.plan(5);const quanData = [1, 4, 2, 3, 1, undefined, null, 0];function valueAccessor(d) {@@ -91,4 +92,6 @@ test('DataScaleUtils -> getLinearDomain', t => {t.deepEqual(getLinearDomain(values, valueAccessor), [-3, 1],'should get correct Linear domain');++ t.end();});