Skip to content

Commit 4876af9

Browse files
committed
Use actual ramp for display and adjust css
1 parent a9fd8a9 commit 4876af9

File tree

3 files changed

+58
-68
lines changed

3 files changed

+58
-68
lines changed

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

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ export interface IColorMap {
99
}
1010

1111
interface ICanvasSelectComponentProps {
12+
selectedRamp: string;
1213
setSelected: (item: any) => void;
1314
}
1415

1516
const CanvasSelectComponent = ({
17+
selectedRamp,
1618
setSelected
1719
}: ICanvasSelectComponentProps) => {
18-
const [isOpen, setIsOpen] = useState(false);
19-
const containerRef = useRef<HTMLDivElement>(null);
20-
21-
const colorRampList = [
20+
const colorRampNames = [
2221
'jet',
2322
// 'hsv', 11 steps min
2423
'hot',
@@ -46,7 +45,6 @@ const CanvasSelectComponent = ({
4645
'magma',
4746
'plasma',
4847
'warm',
49-
'cool',
5048
// 'rainbow-soft', 11 steps min
5149
'bathymetry',
5250
'cdom',
@@ -65,7 +63,31 @@ const CanvasSelectComponent = ({
6563
// 'cubehelix' 16 steps min
6664
];
6765

68-
const [colorMap, setColorMap] = useState<IColorMap[]>([]);
66+
const containerRef = useRef<HTMLDivElement>(null);
67+
const [isOpen, setIsOpen] = useState(false);
68+
const [colorMaps, setColorMaps] = useState<IColorMap[]>([]);
69+
70+
useEffect(() => {
71+
const colorMapList: IColorMap[] = [];
72+
73+
colorRampNames.forEach(name => {
74+
const colorRamp = colormap({
75+
colormap: name,
76+
nshades: 255,
77+
format: 'rgbaString'
78+
});
79+
const ting = { name: name, colors: colorRamp };
80+
colorMapList.push(ting);
81+
82+
setColorMaps(colorMapList);
83+
});
84+
}, []);
85+
86+
useEffect(() => {
87+
if (colorMaps.length > 0) {
88+
updateCanvas(selectedRamp);
89+
}
90+
}, [selectedRamp]);
6991

7092
const toggleDropdown = () => {
7193
setIsOpen(!isOpen);
@@ -74,6 +96,7 @@ const CanvasSelectComponent = ({
7496
const selectItem = (item: any) => {
7597
setSelected(item);
7698
setIsOpen(false);
99+
updateCanvas(item);
77100
};
78101

79102
const handleOutsideClick = (event: any) => {
@@ -85,40 +108,31 @@ const CanvasSelectComponent = ({
85108
}
86109
};
87110

88-
useEffect(() => {
89-
const colorMapT: IColorMap[] = [];
90-
91-
colorRampList.forEach(name => {
92-
const t = colormap({
93-
colormap: name,
94-
nshades: 255,
95-
format: 'rgbaString'
96-
});
97-
const ting = { name: name, colors: t };
98-
colorMapT.push(ting);
99-
100-
setColorMap(colorMapT);
101-
});
111+
const updateCanvas = (rampName: string) => {
112+
// update canvas for displayed color ramp
113+
const cv = document.getElementById('cv') as HTMLCanvasElement;
114+
if (!cv) {
115+
return;
116+
}
117+
cv.style.visibility = 'hidden';
118+
const ctx = cv.getContext('2d');
102119

103-
// const cv = document.getElementById('cv') as HTMLCanvasElement;
104-
// if (!cv) {
105-
// return;
106-
// }
107-
// const ctx = cv.getContext('2d');
120+
if (!ctx) {
121+
return;
122+
}
108123

109-
// if (!ctx) {
110-
// return;
111-
// }
124+
const ramp = colorMaps.filter(c => c.name === rampName);
112125

113-
// for (let i = 0; i <= 255; i++) {
114-
// ctx.beginPath();
126+
for (let i = 0; i <= 255; i++) {
127+
ctx.beginPath();
115128

116-
// const color = colorMapT[0].colors[i];
117-
// ctx.fillStyle = color;
129+
const color = ramp[0].colors[i];
130+
ctx.fillStyle = color;
118131

119-
// ctx.fillRect(i * 2, 0, 2, 50);
120-
// }
121-
}, []);
132+
ctx.fillRect(i * 2, 0, 2, 50);
133+
}
134+
cv.style.visibility = '';
135+
};
122136

123137
useEffect(() => {
124138
document.addEventListener('mousedown', handleOutsideClick);
@@ -133,11 +147,10 @@ const CanvasSelectComponent = ({
133147
onClick={toggleDropdown}
134148
className="jp-Dialog-button jp-mod-accept jp-mod-styled"
135149
>
136-
{/* <canvas width="512" height="50" id="cv"></canvas> */}
137-
Select Colormap
150+
<canvas width="354" height="30" id="cv"></canvas>
138151
</Button>
139152
<div className={`dropdown ${isOpen ? 'open' : ''}`}>
140-
{colorMap.map((item, index) => (
153+
{colorMaps.map((item, index) => (
141154
<ColorRampEntry index={index} colorMap={item} onClick={selectItem} />
142155
))}
143156
</div>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ const ColorRamp = ({ layerId, modeOptions, classifyFunc }: IColorRampProps) => {
5050
<div className="jp-gis-color-ramp-container">
5151
<div className="jp-gis-symbology-row">
5252
<label htmlFor="color-ramp-select">Color Ramp:</label>
53-
<CanvasSelectComponent setSelected={setSelectedRamp} />
53+
<CanvasSelectComponent
54+
selectedRamp={selectedRamp}
55+
setSelected={setSelectedRamp}
56+
/>
5457
</div>
5558
<div className="jp-gis-symbology-row">
5659
<div className="jp-gis-color-ramp-div">

packages/base/style/symbologyDialog.css

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@
152152
flex-direction: column;
153153
gap: 0.25rem;
154154
position: absolute;
155-
/* box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1); */
156-
overflow: hidden;
155+
overflow-x: hidden;
156+
overflow-y: auto;
157157
visibility: hidden;
158158
z-index: 40;
159159
flex: 1 1 auto;
160160
width: 100%;
161-
/* font-size: var(--jp-ui-font-size2); */
161+
max-height: 375px;
162162
background: var(--jp-input-background);
163163
padding: 0 25px 0 8px;
164164
border: var(--jp-border-width) solid var(--jp-input-border-color);
@@ -173,41 +173,15 @@
173173
visibility: visible;
174174
}
175175

176-
.dropdown-header {
177-
padding: 10px;
178-
display: flex;
179-
justify-content: space-between;
180-
align-items: center;
181-
border-bottom: 1px solid #ccc;
182-
}
183-
184-
.dropdown ul {
185-
list-style-type: none;
186-
padding: 0;
187-
margin: 0;
188-
}
189-
190-
.dropdown li {
191-
padding: 10px;
192-
cursor: pointer;
193-
}
194-
195176
.dropdown > jp-gis-color-ramp-entry:hover {
196177
background-color: #f1f1f1;
197178
}
198179

199180
.jp-gis-color-ramp-entry {
200181
display: flex;
201182
align-items: center;
202-
/* flex: 1 1 auto; */
203-
/* width: 100%; */
204183
font-size: var(--jp-ui-font-size2);
205-
/* background: var(--jp-input-background); */
206184
color: var(--jp-ui-font-color0);
207-
/* padding: 0 25px 0 8px; */
208-
/* border: var(--jp-border-width) solid var(--jp-input-border-color); */
209-
/* border-radius: 0; */
210-
/* outline: none; */
211185
appearance: none;
212186
-webkit-appearance: none;
213187
-moz-appearance: none;

0 commit comments

Comments
 (0)