@@ -24,6 +24,7 @@ import React, { useEffect, useState } from 'react';
2424import { LoadingIcon } from '@/src/shared/components/loading' ;
2525import ColorRampSelector from './ColorRampSelector' ;
2626import ModeSelectRow from './ModeSelectRow' ;
27+ import { COLOR_RAMP_DEFAULTS , ColorRampName } from '../../colorRampUtils' ;
2728
2829interface IColorRampControlsProps {
2930 modeOptions : string [ ] ;
@@ -55,13 +56,46 @@ const ColorRampControls: React.FC<IColorRampControlsProps> = ({
5556 const [ selectedMode , setSelectedMode ] = useState ( '' ) ;
5657 const [ numberOfShades , setNumberOfShades ] = useState ( '' ) ;
5758 const [ isLoading , setIsLoading ] = useState ( false ) ;
59+ const [ warning , setWarning ] = useState < string | null > ( null ) ;
5860
5961 useEffect ( ( ) => {
6062 if ( selectedRamp === '' && selectedMode === '' && numberOfShades === '' ) {
6163 populateOptions ( ) ;
6264 }
6365 } , [ layerParams ] ) ;
6466
67+ useEffect ( ( ) => {
68+ if ( ! selectedRamp ) {
69+ return ;
70+ }
71+
72+ const defaultClasses =
73+ COLOR_RAMP_DEFAULTS [ selectedRamp as ColorRampName ] ?? 9 ;
74+
75+ setNumberOfShades ( defaultClasses . toString ( ) ) ;
76+ setWarning ( null ) ;
77+ } , [ selectedRamp ] ) ;
78+
79+ useEffect ( ( ) => {
80+ if ( ! selectedRamp || ! numberOfShades ) {
81+ return ;
82+ }
83+
84+ const minRequired = COLOR_RAMP_DEFAULTS [ selectedRamp as ColorRampName ] ;
85+ const shades = parseInt ( numberOfShades , 10 ) ;
86+ const rampLabel = selectedRamp
87+ . split ( '-' )
88+ . map ( word => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) )
89+ . join ( '-' ) ;
90+
91+ if ( minRequired && shades < minRequired ) {
92+ setWarning (
93+ `${ rampLabel } requires at least ${ minRequired } classes (got ${ shades } )` ,
94+ ) ;
95+ } else {
96+ setWarning ( null ) ;
97+ }
98+ } , [ selectedRamp , numberOfShades ] ) ;
6599 const populateOptions = ( ) => {
66100 let nClasses , singleBandMode , colorRamp ;
67101
@@ -70,9 +104,13 @@ const ColorRampControls: React.FC<IColorRampControlsProps> = ({
70104 singleBandMode = layerParams . symbologyState . mode ;
71105 colorRamp = layerParams . symbologyState . colorRamp ;
72106 }
73- setNumberOfShades ( nClasses ? nClasses : '9' ) ;
107+ const defaultRamp = colorRamp ? colorRamp : 'viridis' ;
108+ const defaultClasses =
109+ nClasses ?? COLOR_RAMP_DEFAULTS [ defaultRamp as ColorRampName ] ?? 9 ;
110+
111+ setNumberOfShades ( defaultClasses . toString ( ) ) ;
74112 setSelectedMode ( singleBandMode ? singleBandMode : 'equal interval' ) ;
75- setSelectedRamp ( colorRamp ? colorRamp : 'viridis' ) ;
113+ setSelectedRamp ( defaultRamp ) ;
76114 } ;
77115
78116 return (
@@ -95,11 +133,20 @@ const ColorRampControls: React.FC<IColorRampControlsProps> = ({
95133 setSelectedMode = { setSelectedMode }
96134 />
97135 ) }
136+ { warning && (
137+ < div
138+ className = "jp-gis-warning"
139+ style = { { color : 'orange' , marginTop : 4 } }
140+ >
141+ { warning }
142+ </ div >
143+ ) }
98144 { isLoading ? (
99145 < LoadingIcon />
100146 ) : (
101147 < Button
102148 className = "jp-Dialog-button jp-mod-accept jp-mod-styled"
149+ disabled = { ! ! warning }
103150 onClick = { ( ) =>
104151 classifyFunc (
105152 selectedMode ,
0 commit comments