Skip to content

Commit

Permalink
[BUGFIX] Colormap returning null (#1168)
Browse files Browse the repository at this point in the history
Related to bug seen in Release PR
[here](#1167 (comment))

Fix on Local:
![Screenshot 2024-09-23 at 5 03 18
PM](https://github.com/user-attachments/assets/60cc5327-14e1-4725-a66b-18a04fc23087)
  • Loading branch information
sandrahoang686 authored Sep 24, 2024
2 parents b641b50 + 556eeec commit 61a6790
Show file tree
Hide file tree
Showing 5 changed files with 27,639 additions and 131 deletions.
17 changes: 7 additions & 10 deletions app/scripts/components/common/map/layer-legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
WidgetItemHGroup
} from '$styles/panel';
import { LayerLegendCategorical, LayerLegendGradient } from '$types/veda';
import { divergingColorMaps, sequentialColorMaps } from '$components/exploration/components/datasets/colorMaps';
import { divergingColorMaps, sequentialColorMaps, restColorMaps } from '$components/exploration/components/datasets/colorMaps';
import { DEFAULT_COLORMAP } from '$components/exploration/components/datasets/colormap-options';

interface LayerLegendCommonProps {
id: string;
Expand Down Expand Up @@ -347,14 +348,10 @@ export const LayerGradientGraphic = (props: LayerLegendGradient) => {
};

export const LayerGradientColormapGraphic = (props: Omit<LayerLegendGradient, 'stops' | 'type'>) => {
const { colorMap, ...otherProps } = props;
const { colorMap = DEFAULT_COLORMAP, ...otherProps } = props;
const colormapResult = findColormapByName(colorMap);

const colormapResult = findColormapByName(colorMap ?? 'viridis');
if (!colormapResult) {
return null;
}
const { foundColorMap, isReversed } = colormapResult;

const stops = Object.values(foundColorMap)
.filter(value => Array.isArray(value) && value.length === 4)
.map((value) => {
Expand All @@ -371,11 +368,11 @@ export const LayerGradientColormapGraphic = (props: Omit<LayerLegendGradient, 's
export const findColormapByName = (name: string) => {
const isReversed = name.toLowerCase().endsWith('_r');
const baseName = isReversed ? name.slice(0, -2).toLowerCase() : name.toLowerCase();

const colormap = sequentialColorMaps[baseName] ?? divergingColorMaps[baseName];
const colormap = sequentialColorMaps[baseName] ?? divergingColorMaps[baseName] ?? restColorMaps[baseName];

if (!colormap) {
return null;
const defaultColormap = sequentialColorMaps[DEFAULT_COLORMAP.toLowerCase()] ?? divergingColorMaps[DEFAULT_COLORMAP.toLowerCase()];
return { foundColorMap: {...defaultColormap}, isReversed: false };
}

return { foundColorMap: {...colormap}, isReversed };
Expand Down
Loading

0 comments on commit 61a6790

Please sign in to comment.