Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[fix] fixes for legend (#3199)

Igor Dykhta96dcef6b9125
diff --git a/src/components/src/common/color-legend.tsx b/src/components/src/common/color-legend.tsx
index 151c2042b..2dcedc729 100644
--- a/src/components/src/common/color-legend.tsx
+++ b/src/components/src/common/color-legend.tsx
@@ -32,7 +32,8 @@ const inputCss = css`
const StyledLegend = styled.div<{disableEdit: boolean; isExpanded?: boolean}>`
${props => props.theme.sidePanelScrollBar};
${props => (props.isExpanded ? '' : `max-height: 156px;`)};
- overflow: auto;
+ overflow-y: auto;
+ overflow-x: hidden;
margin-bottom: ${GAP}px;
display: grid;
grid-row-gap: ${GAP}px;
@@ -45,12 +46,15 @@ const StyledLegendRow = styled.div`
display: flex;
align-items: center;
height: 20px;
+ min-width: 0;
`;
export function ResetColorLabelFactory() {
return styled(Reset)`
color: ${props => props.theme.labelColorLT};
cursor: pointer;
+ flex-shrink: 0;
+ margin-left: ${GAP}px;
&:hover {
color: ${props => props.theme.panelHeaderIconHover};
@@ -66,6 +70,10 @@ const StyleInlineInput = styled(InlineInput)`
width: unset;
padding: 2px;
flex: 1;
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
margin: 0 ${GAP}px;
:hover {
height: ${ROW_H}px;
@@ -125,6 +133,11 @@ const StyledLabel = styled.div`
font-size: 10px;
color: ${props => props.theme.textColor};
padding-left: 2px;
+ flex: 1;
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
`;
export type LegendRowProps = {
diff --git a/src/components/src/map/map-legend-panel.tsx b/src/components/src/map/map-legend-panel.tsx
index 60c260864..74612131e 100644
--- a/src/components/src/map/map-legend-panel.tsx
+++ b/src/components/src/map/map-legend-panel.tsx
@@ -116,6 +116,23 @@ const StyledResizeHandle = styled.div`
cursor: ns-resize;
`;
+const StyledFixedLegendContent = styled.div<{contentHeight?: number}>`
+ .map-control__panel-content {
+ max-height: calc(100vh - 100px);
+ ${props => (props.contentHeight ? `height: ${props.contentHeight}px;` : '')};
+ }
+
+ /* Hide scrollbars in export to avoid OS default styling differences */
+ .styled-color-legend {
+ -ms-overflow-style: none; /* IE and old Edge */
+ scrollbar-width: none; /* Firefox */
+ }
+ .styled-color-legend::-webkit-scrollbar {
+ width: 0 !important; /* Chrome, Safari, new Edge */
+ height: 0 !important;
+ }
+`;
+
export type MapLegendPanelFactoryDeps = [
typeof MapControlTooltipFactory,
typeof MapControlPanelFactory,
@@ -240,7 +257,7 @@ const ImageExportLegend = withTheme(({settings, isSidePanelShown, theme, childre
const containerRef: React.MutableRefObject<HTMLDivElement | null> = useRef(null);
const legendContentRef: React.MutableRefObject<HTMLDivElement | null> = useRef(null);
- const {positionStyles} = useLegendPosition({
+ const {positionStyles, contentHeight} = useLegendPosition({
legendContentRef,
isSidePanelShown,
theme,
@@ -263,7 +280,9 @@ const ImageExportLegend = withTheme(({settings, isSidePanelShown, theme, childre
ref={legendContentRef}
style={{...positionStyles, position: 'absolute'}}
>
- {children}
+ <StyledFixedLegendContent contentHeight={contentHeight}>
+ {children}
+ </StyledFixedLegendContent>
</div>,
portalRoot
)
diff --git a/src/components/src/map/map-legend.tsx b/src/components/src/map/map-legend.tsx
index 36840e57a..64945d439 100644
--- a/src/components/src/map/map-legend.tsx
+++ b/src/components/src/map/map-legend.tsx
@@ -202,7 +202,7 @@ export function LayerColorLegendFactory(
fieldType={(colorField && colorField.type) || 'real'}
range={colorRange}
onUpdateColorLegend={onUpdateColorLegend}
- disableEdit={disableEdit}
+ disableEdit={disableEdit || Boolean(isExport)}
isFixed={isFixed}
mapState={mapState}
labelFormat={
diff --git a/src/components/src/plot-container.tsx b/src/components/src/plot-container.tsx
index 7ebd1453f..53eb9879b 100644
--- a/src/components/src/plot-container.tsx
+++ b/src/components/src/plot-container.tsx
@@ -276,7 +276,8 @@ export default function PlotContainerFactory(
mapControls: {
mapLegend: {
show: Boolean(legend),
- active: true
+ active: true,
+ settings: mapFields.mapControls?.mapLegend?.settings
}
},
MapComponent: Map,