ソースを参照

Merge branch 'master' of https://github.com/molstar/molstar

Alexander Rose 5 年 前
コミット
8855f51cfc

+ 1 - 1
src/examples/proteopedia-wrapper/index.ts

@@ -434,7 +434,7 @@ class MolStarProteopediaWrapper {
             try {
                 const snapshot = await this.plugin.runTask(this.plugin.fetch({ url, type: 'json' }));
                 // TODO: is this OK to test for snapshots from server?
-                await this.plugin.state.setSnapshot(snapshot?.data?.entries[0]?.snapshot || snapshot);
+                await this.plugin.state.setSnapshot(snapshot?.data?.entries?.[0]?.snapshot || snapshot);
             } catch (e) {
                 console.log(e);
             }

+ 0 - 4
src/mol-util/color/lists.ts

@@ -45,10 +45,6 @@ export const ColorLists = {
         '',
         [0xfff5f0, 0xfee0d2, 0xfcbba1, 0xfc9272, 0xfb6a4a, 0xef3b2c, 0xcb181d, 0xa50f15, 0x67000d]
     ),
-    'reds-darker': ColorList('Reds-darker', 'sequential',
-        '',
-        [0xff5252, 0xff0000, 0xa70000]
-    ),
     'red-purple': ColorList('Red-Purple', 'sequential',
         '',
         [0xfff7f3, 0xfde0dd, 0xfcc5c0, 0xfa9fb5, 0xf768a1, 0xdd3497, 0xae017e, 0x7a0177, 0x49006a]

+ 19 - 3
src/mol-util/color/palette.ts

@@ -1,7 +1,8 @@
 /**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ * @author David Sehnal <david.sehnal@gmail.com>
  */
 
 import { ParamDefinition as PD } from '../param-definition'
@@ -10,6 +11,7 @@ import { ColorScale } from './scale';
 import { Color } from '.';
 import { ColorListName, ColorListOptionsScale, ColorListOptionsSet, getColorListFromName } from './lists';
 import { TableLegend, ScaleLegend } from '../legend';
+import { ColorNames } from './names';
 
 type PaletteType = 'generate' | 'scale' | 'set'
 
@@ -32,7 +34,12 @@ export function getPaletteParams(props: Partial<GetPaletteProps> = {}) {
         palette: PD.MappedStatic(p.type, {
             scale: PD.Group({
                 ...LabelParams,
-                list: PD.ColorList<ColorListName>(p.scaleList, ColorListOptionsScale),
+                list: PD.MappedStatic('predefined', {
+                    predefined: PD.ColorList<ColorListName>(p.scaleList, ColorListOptionsScale),
+                    custom: PD.ObjectList({ color: PD.Color(0x0 as Color) }, ({ color }) => Color.toHexString(color), {
+                        defaultValue: [ { color: ColorNames.red }, { color: ColorNames.green }, { color: ColorNames.blue } ]
+                    })
+                })
             }, { isFlat: true }),
             set: PD.Group({
                 ...LabelParams,
@@ -66,8 +73,17 @@ export function getPalette(count: number, props: PaletteProps) {
     let legend: ScaleLegend | TableLegend | undefined
 
     if (props.palette.name === 'scale') {
-        const { list: listOrName, minLabel, maxLabel } = props.palette.params
+        const { list, minLabel, maxLabel } = props.palette.params
         const domain: [number, number] = [0, count - 1]
+
+        let listOrName: ColorListName | Color[];
+        if (list.name === 'predefined') {
+            listOrName = list.params;
+        } else {
+            listOrName = list.params.map(c => c.color);
+            if (listOrName.length === 0) listOrName = [ColorNames.black];
+        }
+
         const scale = ColorScale.create({ listOrName, domain, minLabel, maxLabel })
         legend = scale.legend
         color = scale.color