-
Notifications
You must be signed in to change notification settings - Fork 69
Add cmocean colormaps, fix bug when switching render type #886
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
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dde4e9c
Adding cmocean colormaps
nakul-py d0aa30e
removing duplicate colormaps and some refactoring
nakul-py 457c9c2
Merge branch 'main' into cmocean
nakul-py 0269633
removing duplicate colormaps
nakul-py af6118d
update cmocean colors format
nakul-py 49ccd87
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 59d40cc
Merge branch 'main' into cmocean
nakul-py b144c18
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 074863d
adding all color names in colrRampUtils file
nakul-py a5a895d
Merge branch 'main' into cmocean
nakul-py a55b328
reducing cmocean number to 9
nakul-py 534bb62
Change colormap/colorScale.js stub to empty
mfisher87 7e06d2c
Let the compiler infer type from cmocean.json import
mfisher87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,136 @@ | ||
| import colormap from 'colormap'; | ||
| import colorScale from 'colormap/colorScale.js'; | ||
| import { useEffect } from 'react'; | ||
|
|
||
| import rawCmocean from '@/src/dialogs/symbology/components/color_ramp/cmocean.json'; | ||
|
|
||
| export interface IColorMap { | ||
| name: ColorRampName; | ||
| colors: string[]; | ||
| } | ||
|
|
||
| const { __license__: _, ...cmocean } = rawCmocean as any; | ||
|
|
||
| Object.assign(colorScale, cmocean); | ||
|
|
||
| export const COLOR_RAMP_NAMES = [ | ||
| 'jet', | ||
| // 'hsv', 11 steps min | ||
| 'hot', | ||
| 'cool', | ||
| 'spring', | ||
| 'summer', | ||
| 'autumn', | ||
| 'winter', | ||
| 'bone', | ||
| 'copper', | ||
| 'greys', | ||
| 'YiGnBu', | ||
| 'greens', | ||
| 'YiOrRd', | ||
| 'bluered', | ||
| 'RdBu', | ||
| // 'picnic', 11 steps min | ||
| 'rainbow', | ||
| 'portland', | ||
| 'blackbody', | ||
| 'earth', | ||
| 'electric', | ||
| 'viridis', | ||
| 'inferno', | ||
| 'magma', | ||
| 'plasma', | ||
| 'warm', | ||
| // 'rainbow-soft', 11 steps min | ||
| 'bathymetry', | ||
| 'cdom', | ||
| 'chlorophyll', | ||
| 'density', | ||
| 'freesurface-blue', | ||
| 'freesurface-red', | ||
| 'oxygen', | ||
| 'par', | ||
| 'phase', | ||
| 'salinity', | ||
| 'temperature', | ||
| 'turbidity', | ||
| 'velocity-blue', | ||
| 'velocity-green', | ||
| // 'cubehelix' 16 steps min | ||
| 'ice', | ||
| 'oxy', | ||
| 'matter', | ||
| 'amp', | ||
| 'tempo', | ||
| 'rain', | ||
| 'topo', | ||
| 'balance', | ||
| 'delta', | ||
| 'curl', | ||
| 'diff', | ||
| 'tarn', | ||
| ] as const; | ||
|
|
||
| export type ColorRampName = (typeof COLOR_RAMP_NAMES)[number]; | ||
|
|
||
| export const getColorMapList = (): IColorMap[] => { | ||
| const colorMapList: IColorMap[] = []; | ||
|
|
||
| COLOR_RAMP_NAMES.forEach(name => { | ||
| const colorRamp = colormap({ | ||
| colormap: name, | ||
| nshades: 255, | ||
| format: 'rgbaString', | ||
| }); | ||
|
|
||
| colorMapList.push({ name, colors: colorRamp }); | ||
| }); | ||
|
|
||
| return colorMapList; | ||
| }; | ||
|
|
||
| /** | ||
| * Hook that loads and sets color maps. | ||
| */ | ||
mfisher87 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export const useColorMapList = (setColorMaps: (maps: IColorMap[]) => void) => { | ||
| useEffect(() => { | ||
| setColorMaps(getColorMapList()); | ||
| }, [setColorMaps]); | ||
| }; | ||
|
|
||
| /** | ||
| * Ensure we always get a valid hex string from either an RGB(A) array or string. | ||
| */ | ||
| export const ensureHexColorCode = (color: number[] | string): string => { | ||
| if (typeof color === 'string') { | ||
| return color; | ||
| } | ||
|
|
||
| // color must be an RGBA array | ||
| const hex = color | ||
| .slice(0, -1) // Color input doesn't support hex alpha values so cut that out | ||
| .map((val: { toString: (arg0: number) => string }) => { | ||
| return val.toString(16).padStart(2, '0'); | ||
| }) | ||
| .join(''); | ||
|
|
||
| return '#' + hex; | ||
| }; | ||
|
|
||
| /** | ||
| * Convert hex to [r,g,b,a] array. | ||
| */ | ||
| export function hexToRgb(hex: string): [number, number, number, number] { | ||
| const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); | ||
|
|
||
| if (!result) { | ||
| console.warn('Unable to parse hex value, defaulting to black'); | ||
| return [0, 0, 0, 255]; | ||
| } | ||
| return [ | ||
| parseInt(result[1], 16), | ||
| parseInt(result[2], 16), | ||
| parseInt(result[3], 16), | ||
| 255, // TODO: Make alpha customizable? | ||
| ]; | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.