From 1923535918acb18cb24dd243e07ac7a62cf379f7 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alex.rose@rcsb.org>
Date: Mon, 19 Aug 2019 12:44:34 -0700
Subject: [PATCH] limit max number of generated colors

---
 src/apps/viewer/extensions/cellpack/model.ts | 3 ++-
 src/mol-theme/color/util.ts                  | 8 ++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/apps/viewer/extensions/cellpack/model.ts b/src/apps/viewer/extensions/cellpack/model.ts
index 4383c786f..18e80099c 100644
--- a/src/apps/viewer/extensions/cellpack/model.ts
+++ b/src/apps/viewer/extensions/cellpack/model.ts
@@ -201,7 +201,8 @@ export const LoadCellPackModel = StateAction.build({
                                     name: 'generate',
                                     params: {
                                         hue, chroma: [30, 80], luminance: [15, 85],
-                                        clusteringStepCount: 50, minSampleCount: 800
+                                        clusteringStepCount: 50, minSampleCount: 800,
+                                        maxCount: 75
                                     }
                                 }
                             }
diff --git a/src/mol-theme/color/util.ts b/src/mol-theme/color/util.ts
index f250571ed..45d5752ff 100644
--- a/src/mol-theme/color/util.ts
+++ b/src/mol-theme/color/util.ts
@@ -22,7 +22,10 @@ export function getPaletteParams(props: Partial<GetPaletteProps> = {}) {
             scale: PD.Group({
                 list: PD.ColorScale<ColorListName>(p.scaleList, ColorListOptions),
             }, { isFlat: true }),
-            generate: PD.Group(DistinctColorsParams, { isFlat: true })
+            generate: PD.Group({
+                ...DistinctColorsParams,
+                maxCount: PD.Numeric(75, { min: 1, max: 250, step: 1 })
+            }, { isFlat: true })
         }, {
             options: [
                 ['scale', 'From Scale'],
@@ -51,8 +54,9 @@ export function getPalette(count: number, props: PaletteProps) {
         legend = scale.legend
         color = scale.color
     } else {
+        count = Math.min(count, props.palette.params.maxCount)
         const colors = distinctColors(count, props.palette.params)
-        color = (i: number) => colors[i]
+        color = (i: number) => colors[i % count]
     }
 
     return { color, legend }
-- 
GitLab