@@ -68,6 +68,8 @@ const Umap2DScatterPlot = React.memo(function Umap2DScatterPlot({
6868 setSelectedIndices ( [ ] )
6969 } , [ x , y ] )
7070
71+ const hasColorValues = colorValues && colorValues . length > 0
72+
7173 const plotData = useMemo ( ( ) : Partial < PlotData > [ ] => {
7274 if ( ! x || ! y || x . length === 0 ) {
7375 return [ ]
@@ -89,11 +91,11 @@ const Umap2DScatterPlot = React.memo(function Umap2DScatterPlot({
8991 const traces : Partial < PlotData > [ ] = [ ]
9092 const groupNames = Array . from ( groups . keys ( ) ) . sort ( )
9193
92- groupNames . forEach ( ( groupName ) => {
94+ groupNames . forEach ( ( groupName , groupIndex ) => {
9395 const indices = groups . get ( groupName ) !
9496 const groupX = indices . map ( i => x [ i ] )
9597 const groupY = indices . map ( i => y [ i ] )
96- const groupColorValues = colorValues ? indices . map ( i => colorValues [ i ] ) : undefined
98+ const groupColorValues = hasColorValues ? indices . map ( i => colorValues [ i ] ) : undefined
9799 const customdata = indices . map ( i => ( { index : i } ) )
98100
99101 // Determine marker color
@@ -112,7 +114,12 @@ const Umap2DScatterPlot = React.memo(function Umap2DScatterPlot({
112114 size : markerSize ,
113115 opacity : opacity ,
114116 color : markerColor ,
115- colorscale : colorValues ? colorScale : undefined ,
117+ colorscale : hasColorValues ? colorScale : undefined ,
118+ showscale : hasColorValues && groupIndex === 0 , // Only show colorbar on first trace
119+ colorbar : hasColorValues ? {
120+ thickness : 15 ,
121+ len : 0.5
122+ } : undefined ,
116123 line : {
117124 width : 0.5 ,
118125 color : colors . foreground
@@ -130,7 +137,7 @@ const Umap2DScatterPlot = React.memo(function Umap2DScatterPlot({
130137 // Single trace (no breakdown)
131138 // Determine marker color based on colorValues or selection
132139 let markerColor : string [ ] | number [ ]
133- if ( colorValues && colorValues . length > 0 ) {
140+ if ( hasColorValues ) {
134141 markerColor = colorValues
135142 } else {
136143 markerColor = x . map ( ( _ , i ) =>
@@ -150,7 +157,12 @@ const Umap2DScatterPlot = React.memo(function Umap2DScatterPlot({
150157 size : markerSize ,
151158 opacity : opacity ,
152159 color : markerColor ,
153- colorscale : colorValues ? colorScale : undefined ,
160+ colorscale : hasColorValues ? colorScale : undefined ,
161+ showscale : hasColorValues ,
162+ colorbar : hasColorValues ? {
163+ thickness : 15 ,
164+ len : 0.5
165+ } : undefined ,
154166 line : {
155167 width : 0.5 ,
156168 color : colors . foreground
@@ -160,7 +172,7 @@ const Umap2DScatterPlot = React.memo(function Umap2DScatterPlot({
160172 customdata : customdata as any ,
161173 hoverinfo : 'none' , // Disable default hover
162174 } ]
163- } , [ x , y , selectedIndices , colors . primary , colors . foreground , markerSize , opacity , colorScale , breakdownValues , colorValues ] )
175+ } , [ x , y , selectedIndices , colors . primary , colors . foreground , markerSize , opacity , colorScale , breakdownValues , colorValues , hasColorValues ] )
164176
165177 const hasBreakdown = breakdownValues && breakdownValues . length > 0
166178
@@ -172,6 +184,7 @@ const Umap2DScatterPlot = React.memo(function Umap2DScatterPlot({
172184 ...baseLayout ,
173185 dragmode : 'lasso' ,
174186 hovermode : 'closest' ,
187+ showlegend : hasBreakdown ,
175188 margin : {
176189 l : 0 ,
177190 r : 0 ,
0 commit comments