Skip to content

[fix] Image export legend positioning #2895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions examples/demo-app/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
// Sample data
/* eslint-disable no-unused-vars */
import sampleTripData, {testCsvData, sampleTripDataConfig} from './data/sample-trip-data';
import sampleGeojson from './data/sample-small-geojson';

Check warning on line 47 in examples/demo-app/src/app.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'sampleGeojson' is defined but never used
import sampleGeojsonPoints from './data/sample-geojson-points';
// import sampleGeojsonPoints from './data/sample-geojson-points';
import sampleGeojsonConfig from './data/sample-geojson-config';
import sampleH3Data, {config as h3MapConfig} from './data/sample-hex-id-csv';
import sampleS2Data, {config as s2MapConfig, dataId as s2DataId} from './data/sample-s2-data';
Expand Down Expand Up @@ -160,11 +160,11 @@
// window.setTimeout(_showBanner, 3000);
// }
// load sample data
// _loadSampleData();
_loadSampleData();

// Notifications
// _loadMockNotifications();
}, [dispatch, id, provider, query]);

Check warning on line 167 in examples/demo-app/src/app.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

React Hook useEffect has a missing dependency: '_loadSampleData'. Either include it or remove the dependency array

const _setStartScreenCapture = useCallback(
flag => {
Expand All @@ -180,8 +180,7 @@
[dispatch]
);

// eslint-disable-next-line no-unused-vars
const _showBanner = useCallback(() => {

Check warning on line 183 in examples/demo-app/src/app.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'_showBanner' is assigned a value but never used
toggleShowBanner(true);
}, [toggleShowBanner]);

Expand Down Expand Up @@ -542,7 +541,6 @@
);
}, []);

// eslint-disable-next-line no-unused-vars
const _loadSampleData = useCallback(() => {
// _loadPointData();
// _loadGeojsonData();
Expand All @@ -554,8 +552,8 @@
// _loadGpsData();
// _loadRowData();
// _loadVectorTileData();
_loadSyncedFilterWTripLayer();
_replaceSyncedFilterWTripLayer();
// _loadSyncedFilterWTripLayer();
// _replaceSyncedFilterWTripLayer();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
_loadPointData,
Expand Down
2 changes: 1 addition & 1 deletion src/common-utils/src/h3-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
};
}

export const isHexField = (field, fieldIdx, dataContainer) => {
export const isHexField = (field, _fieldIdx, _dataContainer) => {

Check warning on line 39 in src/common-utils/src/h3-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_fieldIdx' is defined but never used

Check warning on line 39 in src/common-utils/src/h3-utils.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_dataContainer' is defined but never used
return field.type === ALL_FIELD_TYPES.h3;
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/src/common/histogram-plot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
const barWidth = useMemo(() => {
if (groupKeys.length === 0) return 0;
// find histogramsByGroup with max number of bins
const maxGroup = groupKeys.reduce((accu, key, idx) => {
const maxGroup = groupKeys.reduce((accu, key, _idx) => {

Check warning on line 135 in src/components/src/common/histogram-plot.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'_idx' is defined but never used
if (histogramsByGroup[key].length > accu.length) {
return histogramsByGroup[key];
}
Expand Down
1 change: 0 additions & 1 deletion src/components/src/common/item-selector/dropdown-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
};

const defaultDisplay = d => d;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const ListItem = ({
value,
displayOption = defaultDisplay,
disabled,
light

Check warning on line 33 in src/components/src/common/item-selector/dropdown-list.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'light' is defined but never used
}: ListItemProps<any>) => {
const displayValue = displayOption(value);
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/src/common/sync-timeline-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
return (
<div>
{Object.values(syncTimelineAnimationItems)
.filter((item, index) => item.id !== syncTimelineMode)
.filter((item, _index) => item.id !== syncTimelineMode)

Check warning on line 53 in src/components/src/common/sync-timeline-control.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'_index' is defined but never used
.map(item => (
<IconButton
key={item.id}
Expand Down
10 changes: 9 additions & 1 deletion src/components/src/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,15 @@ export function ContainerFactory(
dispatch(deleteEntry(id));
}
};
}, [id]);
}, [
id,
dispatch,
initialUiState,
mapStylesReplaceDefault,
mapboxApiAccessToken,
mapboxApiUrl,
mint
]);

useEffect(() => {
// check if id has changed, if true, copy state over
Expand Down
52 changes: 35 additions & 17 deletions src/components/src/hooks/use-legend-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,18 @@
};
const MIN_CONTENT_HEIGHT = 100;

/**
* Returns a function that calculates the anchored position of the map legend
* that is being dragged.
*/
export default function useLegendPosition({
export type UseCalcLegendPositionProps = {
legendContentRef: React.MutableRefObject<HTMLElement | null>;
isSidePanelShown: boolean;
sidePanelWidth: number;
};

export function useCalcLegendPosition({
legendContentRef,
isSidePanelShown,
settings,
onChangeSettings,
theme
}: Params): ReturnType {
const pos = settings?.position ?? DEFAULT_POSITION;
const contentHeight = settings?.contentHeight ?? -1;
const positionStyles = useMemo(() => ({[pos.anchorX]: pos.x, [pos.anchorY]: pos.y}), [pos]);
const startHeightRef = useRef(0);

const calcPosition = useCallback((): MapLegendControlSettings['position'] => {
sidePanelWidth
}: UseCalcLegendPositionProps) {
return useCallback((): MapLegendControlSettings['position'] => {
const root = legendContentRef.current?.closest('.kepler-gl');
const legendContent = legendContentRef.current;
if (!legendContent || !(root instanceof HTMLElement)) {
Expand All @@ -86,7 +81,31 @@
? {y: topOffset, anchorY: 'top'}
: {y: bottomOffset, anchorY: 'bottom'})
};
}, [isSidePanelShown]);
}, [isSidePanelShown, legendContentRef?.current, sidePanelWidth]);

Check warning on line 84 in src/components/src/hooks/use-legend-position.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

React Hook useCallback has a missing dependency: 'legendContentRef'. Either include it or remove the dependency array. Mutable values like 'legendContentRef.current' aren't valid dependencies because mutating them doesn't re-render the component
}

/**
* Returns a function that calculates the anchored position of the map legend
* that is being dragged.
*/
export default function useLegendPosition({
legendContentRef,
isSidePanelShown,
settings,
onChangeSettings,
theme
}: Params): ReturnType {
const pos = settings?.position ?? DEFAULT_POSITION;
const contentHeight = settings?.contentHeight ?? -1;
const positionStyles = useMemo(() => ({[pos.anchorX]: pos.x, [pos.anchorY]: pos.y}), [pos]);
const startHeightRef = useRef(0);
const sidePanelWidth = theme.sidePanel?.width || 0;

const calcPosition = useCalcLegendPosition({
legendContentRef,
isSidePanelShown,
sidePanelWidth
});
const updatePosition = useCallback(
() => onChangeSettings({position: calcPosition()}),
[calcPosition, onChangeSettings]
Expand Down Expand Up @@ -118,7 +137,6 @@
);

// Shift when side panel is shown/hidden
const sidePanelWidth = theme.sidePanel?.width || 0;
const posRef = useRef(pos);
posRef.current = pos;
useEffect(() => {
Expand Down
Loading
Loading