@@ -450,12 +450,19 @@ var MetadataPlot = Panel.extend({
450450 } ,
451451
452452 plotDataToPlotly : function ( plotData ) {
453- const colorBrewerPaired12 = [ '#a6cee3' , '#1f78b4' , '#b2df8a' , '#33a02c' , '#fb9a99' , '#e31a1c' , '#fdbf6f' , '#ff7f00' , '#cab2d6' , '#6a3d9a' , '#ffff99' , '#b15928' ] ;
453+ let colorBrewerPaired12 = [ '#a6cee3' , '#1f78b4' , '#b2df8a' , '#33a02c' , '#fb9a99' , '#e31a1c' , '#fdbf6f' , '#ff7f00' , '#cab2d6' , '#6a3d9a' , '#ffff99' , '#b15928' ] ;
454454 const viridis = [ '#440154' , '#482172' , '#423d84' , '#38578c' , '#2d6f8e' , '#24858d' , '#1e9a89' , '#2ab07e' , '#51c468' , '#86d449' , '#c2df22' , '#fde724' ] ;
455- let colorScale ;
456- if ( plotData . series . c && ( plotData . series . c . type === 'number' || ! plotData . series . c . distinctcount ) ) {
455+ // concatenate this so we have predictable colors for a longer scale
456+ // for discrete values. It would probably be better to use a longer
457+ // scale
458+ colorBrewerPaired12 = colorBrewerPaired12 . concat ( viridis ) ;
459+ let colorScale , sColorScale ;
460+ if ( plotData . series . c && ( plotData . series . c . type === 'number' || ! plotData . series . c . distinctcount || plotData . series . c . distinctcount > colorBrewerPaired12 . length ) ) {
457461 colorScale = window . d3 . scale . linear ( ) . domain ( viridis . map ( ( _ , i ) => i / ( viridis . length - 1 ) * ( ( plotData . series . c . max - plotData . series . c . min ) || 0 ) + plotData . series . c . min ) ) . range ( viridis ) ;
458462 }
463+ if ( plotData . series . s && ( plotData . series . s . type === 'number' || ! plotData . series . s . distinctcount || plotData . series . s . distinctcount > colorBrewerPaired12 . length ) ) {
464+ sColorScale = window . d3 . scale . linear ( ) . domain ( viridis . map ( ( _ , i ) => i / ( viridis . length - 1 ) * ( ( plotData . series . s . max - plotData . series . s . min ) || 0 ) + plotData . series . s . min ) ) . range ( viridis ) ;
465+ }
459466 const plotlyData = {
460467 x : plotData . data . map ( ( d ) => d [ plotData . series . x . index ] ) ,
461468 y : plotData . data . map ( ( d ) => d [ plotData . series . y . index ] ) ,
@@ -475,7 +482,7 @@ var MetadataPlot = Panel.extend({
475482 : 10 ,
476483 color : plotData . series . c
477484 ? (
478- ! plotData . series . c . distinctcount
485+ colorScale
479486 ? plotData . data . map ( ( d ) => colorScale ( d [ plotData . series . c . index ] ) )
480487 : plotData . data . map ( ( d ) => colorBrewerPaired12 [ plotData . series . c . distinct . indexOf ( d [ plotData . series . c . index ] ) ] || '#000000' )
481488 )
@@ -509,8 +516,15 @@ var MetadataPlot = Panel.extend({
509516 for ( let didx = 0 ; didx < plotData . data . length ; didx += 1 ) {
510517 if ( plotData . data [ didx ] [ plotData . series . s . index ] === k ) {
511518 const cval = plotData . data [ didx ] [ plotData . series . c . index ] ;
512- const cidx = plotData . series . c . distinct . indexOf ( cval ) ;
513- return { target : kidx , value : { line : { color : colorBrewerPaired12 [ cidx ] } } } ;
519+ const cidx = plotData . series . s . distinct . indexOf ( cval ) ;
520+ return {
521+ target : kidx ,
522+ value : {
523+ line : {
524+ color : colorScale ? sColorScale [ cval ] : colorBrewerPaired12 [ cidx ]
525+ }
526+ }
527+ } ;
514528 }
515529 }
516530 return { target : kidx , value : { line : { color : '#000000' } } } ;
0 commit comments