-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from nismod/feature/update-backend
Update backend, dataset references
- Loading branch information
Showing
23 changed files
with
14,893 additions
and
7,555 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Color } from 'deck.gl/typed'; | ||
import React from 'react'; | ||
|
||
import { InteractionTarget, RasterTarget } from '@/lib/data-map/interactions/types'; | ||
import { RasterColorMap, RasterLegend } from '@/lib/data-map/legend/RasterLegend'; | ||
import { RasterHoverDescription } from '@/lib/data-map/tooltip/RasterHoverDescription'; | ||
import { ViewLayer } from '@/lib/data-map/view-layers'; | ||
import { rasterTileLayer } from '@/lib/deck/layers/raster-tile-layer'; | ||
import { numFormat, toLabelLookup } from '@/lib/helpers'; | ||
|
||
import { SOURCES } from '../sources'; | ||
import { CDDType, METRIC_VALUE_LABELS } from './metadata'; | ||
|
||
const METRIC_FORMATS: Record< | ||
CDDType, | ||
{ | ||
colorMap: RasterColorMap; | ||
formatValue: (x: number) => string; | ||
transparentColor?: Color; | ||
} | ||
> = { | ||
relative: { | ||
colorMap: { | ||
scheme: 'magma', | ||
range: [0, 1], | ||
}, | ||
formatValue: (x: number) => `${numFormat(x * 100, 2)}%`, | ||
}, | ||
absolute: { | ||
colorMap: { | ||
scheme: 'magma', | ||
range: [0, 360], | ||
}, | ||
formatValue: numFormat, | ||
transparentColor: [255, 255, 255, 0], | ||
}, | ||
}; | ||
|
||
const valueLabelLookup = toLabelLookup(METRIC_VALUE_LABELS); | ||
|
||
export function cddViewLayer(type: CDDType): ViewLayer { | ||
const { colorMap, formatValue, transparentColor = [255, 255, 255, 0] } = METRIC_FORMATS[type]; | ||
const label = `${valueLabelLookup[type]}`; | ||
|
||
const formatFn = (x: number) => (x != null ? formatValue(x) : '-'); | ||
|
||
return { | ||
id: `cdd_${type}`, | ||
interactionGroup: 'raster_assets', | ||
params: { | ||
type, | ||
}, | ||
fn: ({ deckProps }) => | ||
rasterTileLayer( | ||
{ | ||
transparentColor, | ||
}, | ||
deckProps, | ||
{ | ||
data: SOURCES.raster.getUrl({ | ||
path: `cdd_miranda/${type}`, | ||
...colorMap, | ||
}), | ||
refinementStrategy: 'no-overlap', | ||
}, | ||
), | ||
renderLegend: () => | ||
React.createElement(RasterLegend, { | ||
label, | ||
colorMap, | ||
getValueLabel: formatFn, | ||
}), | ||
renderTooltip(hoveredObject: InteractionTarget<RasterTarget>) { | ||
return React.createElement(RasterHoverDescription, { | ||
colorMap, | ||
color: hoveredObject.target.color, | ||
label, | ||
formatValue: formatFn, | ||
}); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ValueLabel } from '@/lib/controls/params/value-label'; | ||
|
||
export const METRIC_TYPES = ['absolute', 'relative'] as const; | ||
|
||
export type CDDType = (typeof METRIC_TYPES)[number]; | ||
|
||
export const METRIC_VALUE_LABELS: ValueLabel<CDDType>[] = [ | ||
{ | ||
value: 'absolute', | ||
label: 'Mean absolute Change (days per year)', | ||
}, | ||
{ | ||
value: 'relative', | ||
label: 'Relative Change', | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.