Skip to content

Commit

Permalink
refactor(frontend): raster config cleanup
Browse files Browse the repository at this point in the history
- remove the redundant `Component` property from raster groups.
- remove the unused `RASTER_COLOR_MAPS`.
- simplify `viewLayer.renderTooltip` for raster layers.
  • Loading branch information
eatyourgreens committed Jul 1, 2024
1 parent 24d3c5b commit ee0a3b3
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 42 deletions.
19 changes: 0 additions & 19 deletions frontend/src/config/color-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,6 @@ import * as d3Scale from 'd3-scale';
import { ColorSpec } from 'lib/data-map/view-layers';
import { valueType } from 'lib/helpers';

export const RASTER_COLOR_MAPS = {
fluvial: {
scheme: 'blues',
range: [0, 10],
},
coastal: {
scheme: 'greens',
range: [0, 10],
},
surface: {
scheme: 'purples',
range: [0, 10],
},
cyclone: {
scheme: 'reds',
range: [0, 75],
},
};

function invertColorScale<T>(colorScale: (t: number) => T) {
return (i: number) => colorScale(1 - i);
}
Expand Down
12 changes: 2 additions & 10 deletions frontend/src/config/hazards/hazard-view-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,8 @@ export function hazardViewLayer(hazardType: string, hazardParams: HazardParams):
viewLayer: this,
});
},
renderTooltip({
key,
target,
viewLayer,
}: {
key?: string;
target: RasterTarget;
viewLayer: ViewLayer;
}) {
return createElement(HazardHoverDescription, { key, target, viewLayer });
renderTooltip({ target }: { target: RasterTarget }) {
return createElement(HazardHoverDescription, { key: this.id, target, viewLayer: this });
},
};
}
2 changes: 0 additions & 2 deletions frontend/src/config/interaction-groups.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { InteractionGroupConfig } from 'lib/data-map/types';

import { AssetHoverDescription } from './assets/AssetHoverDescription';
import { HazardHoverDescription } from './hazards/HazardHoverDescription';
import { SolutionHoverDescription } from './solutions/SolutionHoverDescription';
import { RegionHoverDescription } from './regions/RegionHoverDescription';
import { DroughtHoverDescription } from './drought/DroughtHoverDescription';
Expand All @@ -24,7 +23,6 @@ export const INTERACTION_GROUPS = new Map<string, InteractionGroupConfig>([
id: 'hazards',
type: 'raster',
pickMultiple: true,
Component: HazardHoverDescription,
},
],
[
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/data-map/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface InteractionGroupConfig {
pickingRadius?: number;
pickMultiple?: boolean;
usesAutoHighlight?: boolean;
Component: React.ComponentType<{
Component?: React.ComponentType<{
target: RasterTarget | VectorTarget;
viewLayer: ViewLayer;
}>;
Expand Down
10 changes: 1 addition & 9 deletions frontend/src/lib/data-map/view-layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,7 @@ export interface ViewLayer {
spatialType?: string;
interactionGroup?: string;
renderLegend?: () => JSX.Element;
renderTooltip?: ({
key,
target,
viewLayer,
}: {
key?: string;
target: RasterTarget | VectorTarget;
viewLayer: ViewLayer;
}) => JSX.Element;
renderTooltip?: ({ target }: { target: RasterTarget | VectorTarget }) => JSX.Element;
}

export function viewOnlyLayer(id, fn): ViewLayer {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/map/tooltip/TooltipContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function renderTooltip({
}) {
// renderTooltip isn't implemented on all view layers yet.
if (viewLayer.renderTooltip) {
return viewLayer.renderTooltip({ key, target, viewLayer });
return viewLayer.renderTooltip({ target });
}
// Fallback to the default tooltip component for older layers.
return <Component key={key} target={target} viewLayer={viewLayer} />;
Expand Down

0 comments on commit ee0a3b3

Please sign in to comment.