Skip to content

Commit

Permalink
[feat] Edit color legend value (#2681)
Browse files Browse the repository at this point in the history
- feat: Allow color legend category edit
- Able to reset previously customized value
- Updated factory type definitions
- Add disableEdit to mapControl.mapLegend

Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
Co-authored-by: Ilya Boyandin <iboyandin@foursquare.com>
  • Loading branch information
igorDykhta and ilyabo authored Oct 14, 2024
1 parent 9c82daa commit ecb5ed4
Show file tree
Hide file tree
Showing 12 changed files with 466 additions and 181 deletions.
373 changes: 274 additions & 99 deletions src/components/src/common/color-legend.tsx

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions src/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ export {
LayerLegendHeaderFactory,
LayerLegendContentFactory,
StyledMapControlLegend,
LayerColorLegend,
LayerColorLegendFactory,
VisualChannelMetric,
LayerDefaultLegend,
SingleColorLegend
SingleColorLegendFactory
} from './map/map-legend';
export {default as MapDrawPanelFactory} from './map/map-draw-panel';
export {default as SplitMapButtonFactory} from './map/split-map-button';
Expand Down Expand Up @@ -220,7 +220,7 @@ export {
} from './editor/feature-action-panel';

// Injector
export {injector, provideRecipesToInjector, withState} from './injector';
export * from './injector';

// Common Components
export {default as CloudTile} from './modals/cloud-tile';
Expand All @@ -246,7 +246,13 @@ export {default as Modal, ModalFooter, ModalTitle} from './common/modal';
export {default as AppLogo} from './common/logo';
export {default as Switch} from './common/switch';
export {default as Checkbox} from './common/checkbox';
export {default as ColorLegend, LegendRow} from './common/color-legend';
export {
default as ColorLegendFactory,
LegendRowFactory,
LegendColorDisplayFactory,
LegendRowEditorFactory,
ResetColorLabelFactory
} from './common/color-legend';
export {default as EffectControlFactory} from './map/effects/effect-control';
export {default as LoadingSpinner} from './common/loading-spinner';
export {default as LoadingDialog} from './modals/loading-dialog';
Expand Down
1 change: 1 addition & 0 deletions src/components/src/map-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ export default function MapContainerFactory(
onSetEditorMode={visStateActions.setEditorMode}
onSetLocale={uiStateActions.setLocale}
onToggleEditorVisibility={visStateActions.toggleEditorVisibility}
onLayerVisConfigChange={visStateActions.layerVisConfigChange}
mapHeight={mapState.height}
/>
{isSplitSelector(this.props) && <Droppable containerId={containerId} />}
Expand Down
5 changes: 3 additions & 2 deletions src/components/src/map/map-control-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const StyledMapControlPanelHeader = styled.div.attrs({
color: ${props => props.theme.titleTextColor};
position: relative;
box-sizing: border-box;
align-items: center;
button {
width: 18px;
Expand Down Expand Up @@ -101,14 +102,14 @@ const StyledIcon = styled(IconRoundSmall)`
:hover {
cursor: pointer;
background-color: transparent;
color: ${props => props.theme.linkBtnColor};
color: ${props => props.theme.floatingBtnActColor};
}
`;

export type MapControlPanelProps = {
header?: string;
scale?: number;
onClick: React.MouseEventHandler<HTMLDivElement>;
onClick?: React.MouseEventHandler<HTMLDivElement>;
onPinClick?: React.MouseEventHandler<HTMLDivElement>;
pinnable?: boolean;
disableClose?: boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/components/src/map/map-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MapLegendPanelFactory from './map-legend-panel';
import MapDrawPanelFactory from './map-draw-panel';
import LocalePanelFactory from './locale-panel';
import {Layer} from '@kepler.gl/layers';
import {Editor, MapControls, MapState} from '@kepler.gl/types';
import {Editor, LayerVisConfig, MapControls, MapState} from '@kepler.gl/types';
import {Datasets} from '@kepler.gl/table';
import {MapStateActions, UIStateActions} from '@kepler.gl/actions';

Expand Down Expand Up @@ -62,6 +62,7 @@ export type MapControlProps = {
onToggleMapControl: (control: string) => void;
onSetEditorMode: (mode: string) => void;
onToggleEditorVisibility: () => void;
onLayerVisConfigChange: (oldLayer: Layer, newVisConfig: Partial<LayerVisConfig>) => void;
top: number;
onSetLocale: typeof UIStateActions.setLocale;
locale: string;
Expand Down
17 changes: 12 additions & 5 deletions src/components/src/map/map-legend-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MapControlPanelFactory from './map-control-panel';
import MapLegendFactory from './map-legend';
import {createPortal} from 'react-dom';
import {DIMENSIONS} from '@kepler.gl/constants';
import {MapControlItem, MapControls, MapState} from '@kepler.gl/types';
import {LayerVisConfig, MapControlMapLegend, MapControls, MapState} from '@kepler.gl/types';
import {Layer} from '@kepler.gl/layers';
import {media} from '@kepler.gl/styles';
import {ActionHandler, toggleSplitMapViewport} from '@kepler.gl/actions';
Expand Down Expand Up @@ -70,6 +70,7 @@ export type MapLegendPanelProps = {
onToggleSplitMapViewport?: ActionHandler<typeof toggleSplitMapViewport>;
isViewportUnsyncAllowed?: boolean;
onClickControlBtn?: (e?: MouseEvent) => void;
onLayerVisConfigChange?: (oldLayer: Layer, newVisConfig: Partial<LayerVisConfig>) => void;
};

function MapLegendPanelFactory(MapControlTooltip, MapControlPanel, MapLegend) {
Expand All @@ -89,10 +90,11 @@ function MapLegendPanelFactory(MapControlTooltip, MapControlPanel, MapLegend) {
offsetRight,
onToggleSplitMapViewport,
onClickControlBtn,
isViewportUnsyncAllowed = true
isViewportUnsyncAllowed = true,
onLayerVisConfigChange
}) => {
const mapLegend = mapControls?.mapLegend || ({} as MapControlItem);
const {active: isPinned} = mapLegend || {};
const mapLegend = mapControls?.mapLegend || ({} as MapControlMapLegend);
const {active: isPinned, disableEdit} = mapLegend || {};
const rootContext = useContext(RootContext);
const [isOpened, setIsOpened] = useState(false);

Expand Down Expand Up @@ -154,7 +156,12 @@ function MapLegendPanelFactory(MapControlTooltip, MapControlPanel, MapLegend) {
onToggleSplitMapViewport={onToggleSplitMapViewport}
isViewportUnsyncAllowed={isViewportUnsyncAllowed}
>
<MapLegend layers={layers} mapState={mapState} />
<MapLegend
layers={layers}
mapState={mapState}
disableEdit={disableEdit}
onLayerVisConfigChange={onLayerVisConfigChange}
/>
</MapControlPanel>
);

Expand Down
Loading

0 comments on commit ecb5ed4

Please sign in to comment.