Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Bug] Display color legend for stroke color scale (#546)
Shan He5d827695b96e
diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.jsindex c171d1644..032de569a 100644--- a/examples/demo-app/src/app.js+++ b/examples/demo-app/src/app.js@@ -162,7 +162,7 @@ class App extends Component {_loadSampleData() {// this._loadTripData();this._loadGeojsonData();- // this._loadIconData();+ this._loadIconData();// this._loadH3HexagonData();}diff --git a/src/components/map/map-control.js b/src/components/map/map-control.jsindex 1db68f8f8..829ab3336 100644--- a/src/components/map/map-control.js+++ b/src/components/map/map-control.js@@ -161,144 +161,44 @@ const layerSelector = (layers, mapLayers) => {return availableItems;};-export class MapControl extends Component {- static propTypes = {- datasets: PropTypes.object.isRequired,- dragRotate: PropTypes.bool.isRequired,- isSplit: PropTypes.bool.isRequired,- layers: PropTypes.arrayOf(PropTypes.object),- mapIndex: PropTypes.number.isRequired,- mapControls: PropTypes.object.isRequired,- onTogglePerspective: PropTypes.func.isRequired,- onToggleSplitMap: PropTypes.func.isRequired,- onToggleMapControl: PropTypes.func.isRequired,- onMapToggleLayer: PropTypes.func.isRequired,- top: PropTypes.number.isRequired,-- // optional- scale: PropTypes.number,- mapLayers: PropTypes.object- };-- static defaultProps = {- isSplit: false,- top: 0- };-- layerSelector = state => state.layers;- mapLayersSelector = state => state.mapLayers;-- initialDataSelector = createSelector(- this.layerSelector,- this.mapLayersSelector,- layerSelector- );-- render() {- const items = this.initialDataSelector(this.props);+const ActionPanel = ({children}) => (+ <StyledMapControlAction>{children}</StyledMapControlAction>+);- if (!items) {- return null;- }+const MapLegendTooltip = ({id, message}) => (+ <Tooltip id={id} place="left" effect="solid">+ <span>{message}</span>+ </Tooltip>+);- const {- dragRotate,- isSplit,- isExport,- mapIndex,- mapControls,- onTogglePerspective,- onToggleSplitMap,- onMapToggleLayer,- onToggleMapControl,- scale- } = this.props;-- const {- visibleLayers = {},- mapLegend = {},- toggle3d = {},- splitMap = {}- } = mapControls;-- return (- <StyledMapControl className="map-control">- {/* Split Map */}- {splitMap.show ? (- <ActionPanel key={0}>- <StyledMapControlButton- active={isSplit}- onClick={e => {- e.preventDefault();- onToggleSplitMap(isSplit ? mapIndex : undefined);- }}- key={`split-${isSplit}`}- className="map-control-button split-map"- data-tip- data-for="action-toggle"- >- {isSplit ? <Delete height="18px" /> : <Split height="18px" />}- <MapLegendTooltip- id="action-toggle"- message={- isSplit ? 'Close current panel' : 'Switch to dual map view'- }- />- </StyledMapControlButton>- </ActionPanel>- ) : null}-- {/* Map Layers */}- {isSplit && visibleLayers.show ? (- <ActionPanel key={1}>- <LayerSelectorPanel- items={items}- onMapToggleLayer={onMapToggleLayer}- isActive={visibleLayers.active}- toggleMenuPanel={() => onToggleMapControl('visibleLayers')}- />- </ActionPanel>- ) : null}-- {/* 3D Map */}- {toggle3d.show ? (- <ActionPanel key={2}>- <StyledMapControlButton- onClick={e => {- e.preventDefault();- onTogglePerspective();- }}- active={dragRotate}- data-tip- data-for="action-3d"- >- <Cube3d height="22px" />- {/* No icon since we are injecting through css .threeD-map class*/}- <MapLegendTooltip- id="action-3d"- message={dragRotate ? 'Disable 3D Map' : '3D Map'}- />- </StyledMapControlButton>- </ActionPanel>- ) : null}-- {/* Map Legend */}- {mapLegend.show ? (- <ActionPanel key={3}>- <MapLegendPanel- items={items}- scale={scale}- isExport={isExport}- onMapToggleLayer={onMapToggleLayer}- isActive={mapLegend.active}- toggleMenuPanel={() => onToggleMapControl('mapLegend')}- />- </ActionPanel>- ) : null}- </StyledMapControl>- );- }-}+const LayerSelectorPanel = ({+ items,+ onMapToggleLayer,+ isActive,+ toggleMenuPanel+}) =>+ !isActive ? (+ <StyledMapControlButton+ key={1}+ onClick={e => {+ e.preventDefault();+ toggleMenuPanel();+ }}+ className="map-control-button toggle-layer"+ data-tip+ data-for="toggle-layer"+ >+ <Layers height="22px" />+ <MapLegendTooltip+ id="toggle-layer"+ message={isActive ? 'Hide layer panel' : 'Show layer panel'}+ />+ </StyledMapControlButton>+ ) : (+ <MapControlPanel header="Visible layers" onClick={toggleMenuPanel}>+ <MapLayerSelector layers={items} onMapToggleLayer={onMapToggleLayer} />+ </MapControlPanel>+ );const MapControlPanel = ({children, header, onClick, scale = 1, isExport}) => (<StyledMapControlPanel@@ -309,7 +209,7 @@ const MapControlPanel = ({children, header, onClick, scale = 1, isExport}) => (><StyledMapControlPanelHeader style={{position: 'relative'}}>{isExport ? (- <KeplerGlLogo version={false} appName="kepler.gl"/>+ <KeplerGlLogo version={false} appName="kepler.gl" />) : (<span style={{verticalAlign: 'middle'}}>{header}</span>)}@@ -351,45 +251,147 @@ const MapLegendPanel = ({items, isActive, scale, toggleMenuPanel, isExport}) =></MapControlPanel>);-const LayerSelectorPanel = ({- items,- onMapToggleLayer,- isActive,- toggleMenuPanel-}) =>- !isActive ? (- <StyledMapControlButton- key={1}- onClick={e => {- e.preventDefault();- toggleMenuPanel();- }}- className="map-control-button toggle-layer"- data-tip- data-for="toggle-layer"- >- <Layers height="22px" />- <MapLegendTooltip- id="toggle-layer"- message={isActive ? 'Hide layer panel' : 'Show layer panel'}- />- </StyledMapControlButton>- ) : (- <MapControlPanel header="Visible layers" onClick={toggleMenuPanel}>- <MapLayerSelector layers={items} onMapToggleLayer={onMapToggleLayer} />- </MapControlPanel>- );--const ActionPanel = ({children}) => (- <StyledMapControlAction>{children}</StyledMapControlAction>-);+const MapControlFactory = () => {+ class MapControl extends Component {+ static propTypes = {+ datasets: PropTypes.object.isRequired,+ dragRotate: PropTypes.bool.isRequired,+ isSplit: PropTypes.bool.isRequired,+ layers: PropTypes.arrayOf(PropTypes.object),+ mapIndex: PropTypes.number.isRequired,+ mapControls: PropTypes.object.isRequired,+ onTogglePerspective: PropTypes.func.isRequired,+ onToggleSplitMap: PropTypes.func.isRequired,+ onToggleMapControl: PropTypes.func.isRequired,+ onMapToggleLayer: PropTypes.func.isRequired,+ top: PropTypes.number.isRequired,++ // optional+ scale: PropTypes.number,+ mapLayers: PropTypes.object+ };++ static defaultProps = {+ isSplit: false,+ top: 0+ };++ layerSelector = state => state.layers;+ mapLayersSelector = state => state.mapLayers;++ initialDataSelector = createSelector(+ this.layerSelector,+ this.mapLayersSelector,+ layerSelector+ );-const MapLegendTooltip = ({id, message}) => (- <Tooltip id={id} place="left" effect="solid">- <span>{message}</span>- </Tooltip>-);+ render() {+ const items = this.initialDataSelector(this.props);++ if (!items) {+ return null;+ }++ const {+ dragRotate,+ isSplit,+ isExport,+ mapIndex,+ mapControls,+ onTogglePerspective,+ onToggleSplitMap,+ onMapToggleLayer,+ onToggleMapControl,+ scale+ } = this.props;++ const {+ visibleLayers = {},+ mapLegend = {},+ toggle3d = {},+ splitMap = {}+ } = mapControls;++ return (+ <StyledMapControl className="map-control">+ {/* Split Map */}+ {splitMap.show ? (+ <ActionPanel key={0}>+ <StyledMapControlButton+ active={isSplit}+ onClick={e => {+ e.preventDefault();+ onToggleSplitMap(isSplit ? mapIndex : undefined);+ }}+ key={`split-${isSplit}`}+ className="map-control-button split-map"+ data-tip+ data-for="action-toggle"+ >+ {isSplit ? <Delete height="18px" /> : <Split height="18px" />}+ <MapLegendTooltip+ id="action-toggle"+ message={+ isSplit ? 'Close current panel' : 'Switch to dual map view'+ }+ />+ </StyledMapControlButton>+ </ActionPanel>+ ) : null}++ {/* Map Layers */}+ {isSplit && visibleLayers.show ? (+ <ActionPanel key={1}>+ <LayerSelectorPanel+ items={items}+ onMapToggleLayer={onMapToggleLayer}+ isActive={visibleLayers.active}+ toggleMenuPanel={() => onToggleMapControl('visibleLayers')}+ />+ </ActionPanel>+ ) : null}++ {/* 3D Map */}+ {toggle3d.show ? (+ <ActionPanel key={2}>+ <StyledMapControlButton+ onClick={e => {+ e.preventDefault();+ onTogglePerspective();+ }}+ active={dragRotate}+ data-tip+ data-for="action-3d"+ >+ <Cube3d height="22px" />+ {/* No icon since we are injecting through css .threeD-map class*/}+ <MapLegendTooltip+ id="action-3d"+ message={dragRotate ? 'Disable 3D Map' : '3D Map'}+ />+ </StyledMapControlButton>+ </ActionPanel>+ ) : null}++ {/* Map Legend */}+ {mapLegend.show ? (+ <ActionPanel key={3}>+ <MapLegendPanel+ items={items}+ scale={scale}+ isExport={isExport}+ onMapToggleLayer={onMapToggleLayer}+ isActive={mapLegend.active}+ toggleMenuPanel={() => onToggleMapControl('mapLegend')}+ />+ </ActionPanel>+ ) : null}+ </StyledMapControl>+ );+ }+ }-const MapControlFactory = () => MapControl;+ return MapControl;+};export default MapControlFactory;diff --git a/src/components/map/map-legend.js b/src/components/map/map-legend.jsindex 35e613b83..518a55699 100644--- a/src/components/map/map-legend.js+++ b/src/components/map/map-legend.js@@ -23,10 +23,10 @@ import PropTypes from 'prop-types';import styled from 'styled-components';import {rgb} from 'd3-color';import ColorLegend from 'components/common/color-legend';-import {DIMENSIONS} from 'constants/default-settings';-import {capitalizeFirstLetter} from 'utils/utils';+import {DIMENSIONS, CHANNEL_SCALES} from 'constants/default-settings';+import {camelToTitle} from 'utils/utils';-const StyledMapControlLegend = styled.div`+export const StyledMapControlLegend = styled.div`padding: 10px 0 10px ${props => props.theme.mapControl.padding}px;font-size: 11px;border-bottom-color: ${props => props.theme.panelBorderColor};@@ -64,14 +64,14 @@ const StyledMapControlLegend = styled.div`}`;-const VisualChannelMetric = ({name}) => (+export const VisualChannelMetric = ({name}) => (<div className="legend--layer__title"><span className="legend--layer_by">by </span><span className="legend--layer_color_field">{name}</span></div>);-const LayerSizeLegend = ({label, name}) => (+export const LayerSizeLegend = ({label, name}) => (<div className="legend--layer_size-schema"><p><span className="legend--layer_by">{label}</span>@@ -84,19 +84,19 @@ const propTypes = {layers: PropTypes.arrayOf(PropTypes.object)};-const SingleColorLegend = ({layer, width}) => (+const SingleColorDomain = [''];+export const SingleColorLegend = ({width, color}) => (<ColorLegendscaleType="ordinal"displayLabel={false}- domain={['']}+ domain={SingleColorDomain}fieldType={null}- range={[rgb(...layer.config.color).toString()]}+ range={[rgb(...color).toString()]}width={width}/>);-const MultiColorLegend = ({layer, width}) => {- const {visConfig, colorField, colorScale, colorDomain} = layer.config;+export const MultiColorLegend = ({colorRange, colorScale, colorDomain, colorField, width}) => {return (<ColorLegend@@ -104,22 +104,61 @@ const MultiColorLegend = ({layer, width}) => {displayLabeldomain={colorDomain}fieldType={(colorField && colorField.type) || 'real'}- range={visConfig.colorRange.colors}+ range={colorRange.colors}width={width}/>);};-const MapLegend = ({layers}) => (+export const LayerColorLegend = ({description, config, width, colorChannel}) => {+ const enableColorBy = description.measure;+ const {scale, field, domain, range, property, key} = colorChannel;+ const [colorScale, colorField, colorDomain] = [scale, field, domain].map(k => config[k]);+ const colorRange = config.visConfig[range];++ return (+ <div>+ <div className="legend--layer_type">{camelToTitle(key)}</div>+ <div className="legend--layer_color-schema">+ <div>+ {enableColorBy ? (+ <VisualChannelMetric name={enableColorBy} />+ ) : null}+ <div className="legend--layer_color-legend">+ {enableColorBy ?+ <MultiColorLegend+ colorScale={colorScale}+ colorField={colorField}+ colorDomain={colorDomain}+ colorRange={colorRange}+ width={width} /> :+ <SingleColorLegend+ color={config.visConfig[property] || config[property] || config.color}+ width={width}+ />+ }+ </div>+ </div>+ </div>+ </div>+ )+}++const isColorChannel = (visualChannel) =>+ [CHANNEL_SCALES.color, CHANNEL_SCALES.colorAggr].includes(visualChannel.channelScaleType);++const MapLegend = ({layers = []}) => (<div>{layers.map((layer, index) => {if (!layer.isValidToSave()) {return null;}- const colorChannelConfig = layer.getVisualChannelDescription('color');- const enableColorBy = colorChannelConfig.measure;const width = DIMENSIONS.mapControl.width - 2 * DIMENSIONS.mapControl.padding;+ const colorChannels = Object.values(layer.visualChannels)+ .filter(isColorChannel);+ const nonColorChannels = Object.values(layer.visualChannels)+ .filter(vc => !isColorChannel(vc));return (<StyledMapControlLegend@@ -128,39 +167,32 @@ const MapLegend = ({layers}) => (key={index}><div className="legend--layer_name">{layer.config.label}</div>- <div className="legend--layer_type">{`${capitalizeFirstLetter(- layer.name- )} color`}</div>- <div className="legend--layer_color-schema">- <div>- {enableColorBy ? (- <VisualChannelMetric name={enableColorBy} />- ) : null}- <div className="legend--layer_color-legend">- {enableColorBy ?- <MultiColorLegend layer={layer} width={width}/> :- <SingleColorLegend layer={layer} width={width}/>- }- </div>- </div>- </div>- {Object.keys(layer.visualChannels)- .filter(k => k !== 'color')- .map(key => {+ {colorChannels.map(colorChannel =>+ !colorChannel.condition || colorChannel.condition(layer.config) ?+ <LayerColorLegend+ key={colorChannel.key}+ description={layer.getVisualChannelDescription(colorChannel.key)}+ config={layer.config}+ width={width}+ colorChannel={colorChannel}+ /> : null+ )}+ {nonColorChannels+ .map(visualChannel => {const matchCondition =- !layer.visualChannels[key].condition ||- layer.visualChannels[key].condition(layer.config);+ !visualChannel.condition ||+ visualChannel.condition(layer.config);const enabled =- layer.config[layer.visualChannels[key].field] ||- layer.visualChannels[key].defaultMeasure;+ layer.config[visualChannel.field] ||+ visualChannel.defaultMeasure;- const visualChannelDescription = layer.getVisualChannelDescription(key);+ const description = layer.getVisualChannelDescription(visualChannel.key);if (matchCondition && enabled) {return (<LayerSizeLegend- key={key}- label={visualChannelDescription.label}- name={visualChannelDescription.measure}+ key={visualChannel.key}+ label={description.label}+ name={description.measure}/>);}diff --git a/src/layers/geojson-layer/geojson-layer.js b/src/layers/geojson-layer/geojson-layer.jsindex 4a0bcccde..16c9ea09c 100644--- a/src/layers/geojson-layer/geojson-layer.js+++ b/src/layers/geojson-layer/geojson-layer.js@@ -99,7 +99,8 @@ export default class GeoJsonLayer extends Layer {domain: 'strokeColorDomain',range: 'strokeColorRange',key: 'strokeColor',- channelScaleType: CHANNEL_SCALES.color+ channelScaleType: CHANNEL_SCALES.color,+ condition: config => config.visConfig.stroked},size: {...super.visualChannels.size,diff --git a/src/layers/point-layer/point-layer.js b/src/layers/point-layer/point-layer.jsindex 344b67a82..178e5b745 100644--- a/src/layers/point-layer/point-layer.js+++ b/src/layers/point-layer/point-layer.js@@ -105,7 +105,10 @@ export default class PointLayer extends Layer {get visualChannels() {return {- ...super.visualChannels,+ color: {+ ...super.visualChannels.color,+ condition: config => config.visConfig.filled+ },strokeColor: {property: 'strokeColor',field: 'strokeColorField',@@ -113,7 +116,8 @@ export default class PointLayer extends Layer {domain: 'strokeColorDomain',range: 'strokeColorRange',key: 'strokeColor',- channelScaleType: CHANNEL_SCALES.color+ channelScaleType: CHANNEL_SCALES.color,+ condition: config => config.visConfig.outline},size: {...super.visualChannels.size,diff --git a/src/utils/utils.js b/src/utils/utils.jsindex 36f34214b..57cdcea37 100644--- a/src/utils/utils.js+++ b/src/utils/utils.js@@ -58,6 +58,22 @@ export function notNullorUndefined(d) {return d !== undefined && d !== null;}+/**+ * Capitalize first letter of a string+ * @param {string} str+ * @returns {string}+ */export function capitalizeFirstLetter(str) {return str.charAt(0).toUpperCase() + str.slice(1);}++/**+ * Convert camel style names to title+ * strokeColor -> Stroke Color+ * @param {string} str+ * @returns {string}+ */+export function camelToTitle(str){+ const breakWord = str.replace( /([A-Z])/g, " $1" );+ return capitalizeFirstLetter(breakWord);+}diff --git a/test/browser/components/index.js b/test/browser/components/index.jsindex e958ddd01..e69f43cbd 100644--- a/test/browser/components/index.js+++ b/test/browser/components/index.js@@ -28,3 +28,4 @@ import './container-test';import './data-table-model-test';import './notifications';import './kepler-gl-test';+import './map';diff --git a/test/browser/components/map/index.js b/test/browser/components/map/index.jsnew file mode 100644index 000000000..e5df858e4--- /dev/null+++ b/test/browser/components/map/index.js@@ -0,0 +1,21 @@+// Copyright (c) 2019 Uber Technologies, Inc.+//+// Permission is hereby granted, free of charge, to any person obtaining a copy+// of this software and associated documentation files (the "Software"), to deal+// in the Software without restriction, including without limitation the rights+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+// copies of the Software, and to permit persons to whom the Software is+// furnished to do so, subject to the following conditions:+//+// The above copyright notice and this permission notice shall be included in+// all copies or substantial portions of the Software.+//+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+// THE SOFTWARE.++import './map-legend-test';diff --git a/test/browser/components/map/map-legend-test.js b/test/browser/components/map/map-legend-test.jsnew file mode 100644index 000000000..fad614bf9--- /dev/null+++ b/test/browser/components/map/map-legend-test.js@@ -0,0 +1,217 @@+// Copyright (c) 2019 Uber Technologies, Inc.+//+// Permission is hereby granted, free of charge, to any person obtaining a copy+// of this software and associated documentation files (the "Software"), to deal+// in the Software without restriction, including without limitation the rights+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+// copies of the Software, and to permit persons to whom the Software is+// furnished to do so, subject to the following conditions:+//+// The above copyright notice and this permission notice shall be included in+// all copies or substantial portions of the Software.+//+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+// THE SOFTWARE.++import React from 'react';+import test from 'tape';+import {mount} from 'enzyme';+import cloneDeep from 'lodash.clonedeep';++import MapLegend, {+ StyledMapControlLegend,+ LayerColorLegend,+ VisualChannelMetric,+ LayerSizeLegend,+ SingleColorLegend+} from 'components/map/map-legend';+import {+ StateWFilesFiltersLayerColor,+ expectedSavedLayer1 as pointLayer,+ expectedSavedLayer0 as hexagonLayer,+ expectedSavedLayer2 as geojsonLayer+} from 'test/helpers/mock-state';+import {mountWithTheme} from 'test/helpers/component-utils';++test('Components -> MapLegend.render', t => {+ t.doesNotThrow(() => {+ mount(<MapLegend />);+ }, 'Show not fail without data');++ t.end();+});++test('Components -> MapLegend.render -> with layers', t => {+ const initialState = cloneDeep(StateWFilesFiltersLayerColor);+ const {layers} = initialState.visState;+ let wrapper;++ t.doesNotThrow(() => {+ wrapper = mountWithTheme(<MapLegend layers={layers} />);+ }, 'Show not fail with layers');++ t.equal(+ wrapper.find(StyledMapControlLegend).length,+ layers.length,+ 'should render 3 layer legends'+ );++ const pointLegend = wrapper.find(StyledMapControlLegend).at(0);+ const geojsonLegend = wrapper.find(StyledMapControlLegend).at(1);+ const hexagonLegend = wrapper.find(StyledMapControlLegend).at(2);++ testPointLayerLegend(t, pointLegend);+ testGeojsonLegend(t, geojsonLegend);+ testHexagonLayerLegend(t, hexagonLegend);++ t.end();+});++function testGeojsonLegend(t, geojsonLegend) {+ t.equal(+ geojsonLegend.find('.legend--layer_name').at(0).text(),+ geojsonLayer.config.label,+ 'geojson layer legend should render label'+ );+ t.equal(+ geojsonLegend.find(LayerColorLegend).length,+ 2,+ 'geojson layer legend should render 2 color legend'+ );+ t.equal(+ geojsonLegend.find(LayerSizeLegend).length,+ 0,+ 'geojson layer legend should render 1 size legend'+ );+ const fillColorLegend = geojsonLegend.find(LayerColorLegend).at(0);+ const strokeColorLegend = geojsonLegend.find(LayerColorLegend).at(1);+ t.equal(+ fillColorLegend+ .find('.legend--layer_type')+ .at(0)+ .text(),+ 'Color',+ 'geojson color legend should have Fill Color'+ );+ t.equal(+ fillColorLegend.find(SingleColorLegend).length,+ 1,+ 'geojson fill color should render SingleColorLegend'+ );+ t.deepEqual(+ fillColorLegend.find(SingleColorLegend).at(0).props().color,+ geojsonLayer.config.color,+ 'geojson color legend should be correct color'+ );+ t.equal(+ strokeColorLegend+ .find('.legend--layer_type')+ .at(0)+ .text(),+ 'Stroke Color',+ 'geojson color legend should have Stroke Color'+ );+ t.equal(+ strokeColorLegend.find(SingleColorLegend).length,+ 1,+ 'geojson stroke color should render SingleColorLegend'+ );+ t.deepEqual(+ strokeColorLegend.find(SingleColorLegend).at(0).props().color,+ geojsonLayer.config.visConfig.strokeColor,+ 'geojson color legend should be correct color'+ );+}++function testPointLayerLegend(t, pointLegend) {+ // layer[0] point layer+ // color by: gps_data.types+ // point layer has 2 color channels, only fill is enabled+ t.equal(+ pointLegend.find('.legend--layer_name').at(0).text(),+ pointLayer.config.label,+ 'point layer legend should render point label'+ );++ t.equal(+ pointLegend.find(LayerColorLegend).length,+ 1,+ 'point layer legend should render 1 point layer color legend'+ );+ t.equal(+ pointLegend.find(LayerSizeLegend).length,+ 0,+ 'point layer legend should render 0 point layer size legend'+ );+ const pointColorLegend = pointLegend.find(LayerColorLegend).at(0);+ t.equal(+ pointColorLegend+ .find('.legend--layer_type')+ .at(0)+ .text(),+ 'Color',+ 'point layer legend should have title Color'+ );+ t.equal(+ pointColorLegend.find(VisualChannelMetric).length,+ 1,+ 'point layer legend should render metric name'+ );+ t.equal(+ pointColorLegend+ .find(VisualChannelMetric)+ .at(0)+ .find('.legend--layer_color_field')+ .at(0)+ .text(),+ pointLayer.visualChannels.colorField.name,+ 'point layer legend should render color by measure: gps_data.types'+ );+}++function testHexagonLayerLegend(t, hexagonLegend) {+ t.equal(+ hexagonLegend.find('.legend--layer_name').at(0).text(),+ hexagonLayer.config.label,+ 'hexagon layer legend should render label'+ );+ t.equal(+ hexagonLegend.find(LayerColorLegend).length,+ 1,+ 'hexagon layer legend should render 1 color legend'+ );+ t.equal(+ hexagonLegend.find(LayerSizeLegend).length,+ 0,+ 'hexagon layer legend should render 0 size legend'+ );+ const hexagonColorLegend = hexagonLegend.find(LayerColorLegend).at(0);+ t.equal(+ hexagonColorLegend+ .find('.legend--layer_type')+ .at(0)+ .text(),+ 'Color',+ 'hexagon layer legend should have title Color'+ );+ t.equal(+ hexagonColorLegend.find(VisualChannelMetric).length,+ 1,+ 'hexagon layer legend should render metric name'+ );+ t.equal(+ hexagonColorLegend+ .find(VisualChannelMetric)+ .at(0)+ .find('.legend--layer_color_field')+ .at(0)+ .text(),+ 'Point Count',+ 'hexagon layer legend should render color by Point Count'+ );+}diff --git a/test/helpers/component-utils.js b/test/helpers/component-utils.jsnew file mode 100644index 000000000..a5e839013--- /dev/null+++ b/test/helpers/component-utils.js@@ -0,0 +1,30 @@+// Copyright (c) 2019 Uber Technologies, Inc.+//+// Permission is hereby granted, free of charge, to any person obtaining a copy+// of this software and associated documentation files (the "Software"), to deal+// in the Software without restriction, including without limitation the rights+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+// copies of the Software, and to permit persons to whom the Software is+// furnished to do so, subject to the following conditions:+//+// The above copyright notice and this permission notice shall be included in+// all copies or substantial portions of the Software.+//+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+// THE SOFTWARE.++import {mount} from 'enzyme';+import {theme} from 'styles/base';+import {ThemeProvider} from 'styled-components';++export function mountWithTheme(node) {+ return mount(node, {+ wrappingComponent: ThemeProvider,+ wrappingComponentProps: {theme}+ });+}