Skip to content

Commit c067f57

Browse files
committed
Update selectedRamp state initialization and lint fix.
1 parent df7df8f commit c067f57

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

packages/base/src/dialogs/symbology/colorRampUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ export const getColorMapList = (): IColorMap[] => {
9191
/**
9292
* Hook that loads and sets color maps.
9393
*/
94-
export const useColorMapList = (setColorMaps: React.Dispatch<React.SetStateAction<IColorMap[]>>) => {
94+
export const useColorMapList = (
95+
setColorMaps: React.Dispatch<React.SetStateAction<IColorMap[]>>,
96+
) => {
9597
useEffect(() => {
9698
setColorMaps(getColorMapList());
9799
}, [setColorMaps]);

packages/base/src/dialogs/symbology/components/color_ramp/CanvasSelectComponent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Button } from '@jupyterlab/ui-components';
22
import React, { useEffect, useRef, useState } from 'react';
33

44
import { useColorMapList } from '@/src/dialogs/symbology/colorRampUtils';
5-
import ColorRampEntry from './ColorRampEntry';
65
import { IColorMap } from '@/src/types';
6+
import ColorRampEntry from './ColorRampEntry';
77

88
interface ICanvasSelectComponentProps {
99
selectedRamp: string;
@@ -24,7 +24,7 @@ const CanvasSelectComponent: React.FC<ICanvasSelectComponentProps> = ({
2424
if (colorMaps.length > 0) {
2525
updateCanvas(selectedRamp);
2626
}
27-
}, [selectedRamp]);
27+
}, [selectedRamp, colorMaps]);
2828

2929
const toggleDropdown = () => {
3030
setIsOpen(!isOpen);

packages/base/src/dialogs/symbology/components/color_ramp/ColorRamp.tsx

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,37 +52,19 @@ const ColorRamp: React.FC<IColorRampProps> = ({
5252
initialMin,
5353
initialMax,
5454
}) => {
55-
const [selectedRamp, setSelectedRamp] = useState<ColorRampName | undefined>();
55+
const [selectedRamp, setSelectedRamp] = useState<ColorRampName>('viridis');
5656
const [selectedMode, setSelectedMode] = useState('');
5757
const [numberOfShades, setNumberOfShades] = useState('');
5858
const [minValue, setMinValue] = useState<number | undefined>(initialMin);
5959
const [maxValue, setMaxValue] = useState<number | undefined>(initialMax);
6060
const [isLoading, setIsLoading] = useState(false);
6161

6262
useEffect(() => {
63-
if (selectedRamp === undefined && selectedMode === '' && numberOfShades === '') {
63+
if (selectedRamp && selectedMode === '' && numberOfShades === '') {
6464
populateOptions();
6565
}
6666
}, [layerParams]);
6767

68-
useEffect(() => {
69-
if (!layerParams.symbologyState) {
70-
layerParams.symbologyState = {};
71-
}
72-
73-
if (renderType !== 'Heatmap') {
74-
layerParams.symbologyState.min = minValue;
75-
layerParams.symbologyState.max = maxValue;
76-
layerParams.symbologyState.colorRamp = selectedRamp;
77-
layerParams.symbologyState.nClasses = numberOfShades;
78-
layerParams.symbologyState.mode = selectedMode;
79-
80-
if (rampDef?.type === 'Divergent') {
81-
layerParams.symbologyState.criticalValue = scaledCritical;
82-
}
83-
}
84-
}, [minValue, maxValue, selectedRamp, selectedMode, numberOfShades]);
85-
8668
useEffect(() => {
8769
if (renderType === 'Graduated') {
8870
if (initialMin !== undefined) {
@@ -109,10 +91,6 @@ const ColorRamp: React.FC<IColorRampProps> = ({
10991
setMaxValue(initialMax);
11092
};
11193

112-
if (selectedRamp === undefined) {
113-
// This should be set at this point!
114-
return;
115-
}
11694
const rampDef = COLOR_RAMP_DEFINITIONS[selectedRamp];
11795

11896
const normalizedCritical =
@@ -139,6 +117,24 @@ const ColorRamp: React.FC<IColorRampProps> = ({
139117
displayMax = absMax;
140118
}
141119

120+
useEffect(() => {
121+
if (!layerParams.symbologyState) {
122+
layerParams.symbologyState = {};
123+
}
124+
125+
if (renderType !== 'Heatmap') {
126+
layerParams.symbologyState.min = minValue;
127+
layerParams.symbologyState.max = maxValue;
128+
layerParams.symbologyState.colorRamp = selectedRamp;
129+
layerParams.symbologyState.nClasses = numberOfShades;
130+
layerParams.symbologyState.mode = selectedMode;
131+
132+
if (rampDef?.type === 'Divergent') {
133+
layerParams.symbologyState.criticalValue = scaledCritical;
134+
}
135+
}
136+
}, [minValue, maxValue, selectedRamp, selectedMode, numberOfShades]);
137+
142138
return (
143139
<div className="jp-gis-color-ramp-container">
144140
{showRampSelector && (

0 commit comments

Comments
 (0)