Skip to content

Commit 3378266

Browse files
authored
Adding Legends for Heatmap (#956)
1 parent 1ac5afa commit 3378266

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

packages/base/src/panelview/components/legendItem.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,59 @@ export const LegendItem: React.FC<{
236236
return;
237237
}
238238

239+
// Heatmap
240+
if (renderType === 'Heatmap') {
241+
const colors = Array.isArray(symbology.color) ? symbology.color : [];
242+
if (!colors.length) {
243+
setContent(<p style={{ fontSize: '0.8em' }}>No heatmap colors</p>);
244+
return;
245+
}
246+
247+
const gradient = `linear-gradient(to right, ${colors.join(', ')})`;
248+
const reversed = symbology.symbologyState?.reverse;
249+
250+
setContent(
251+
<div style={{ padding: 6, width: '90%' }}>
252+
<div style={{ fontSize: '1em', marginBottom: 10 }}>
253+
<strong>Heatmap</strong>
254+
</div>
255+
<div
256+
style={{
257+
height: 12,
258+
background: gradient,
259+
border: '1px solid #ccc',
260+
borderRadius: 3,
261+
marginBottom: 4,
262+
}}
263+
/>
264+
<div
265+
style={{
266+
display: 'flex',
267+
justifyContent: 'space-between',
268+
fontSize: '0.75em',
269+
marginBottom: 8,
270+
}}
271+
>
272+
<span style={{ fontWeight: 'bold' }}>Low</span>
273+
<span style={{ fontWeight: 'bold' }}>High</span>
274+
</div>
275+
<div
276+
style={{
277+
fontSize: '0.75em',
278+
display: 'flex',
279+
flexDirection: 'column',
280+
gap: 2,
281+
}}
282+
>
283+
{reversed && (
284+
<span style={{ fontWeight: 'bold' }}>Reversed ramp</span>
285+
)}
286+
</div>
287+
</div>,
288+
);
289+
return;
290+
}
291+
239292
setContent(<p>Unsupported symbology: {String(renderType)}</p>);
240293
}, [symbology, isLoading, error]);
241294

0 commit comments

Comments
 (0)