|
@@ -1,23 +1,25 @@
|
|
|
/**
|
|
|
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
+ * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
*
|
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
|
*/
|
|
|
|
|
|
-import { ColorScale, Color } from '../../mol-util/color';
|
|
|
+import { Color } from '../../mol-util/color';
|
|
|
import { Location } from '../../mol-model/location';
|
|
|
import { StructureElement, Link } from '../../mol-model/structure';
|
|
|
import { OrderedSet } from '../../mol-data/int';
|
|
|
import { ColorTheme, LocationColor } from '../color';
|
|
|
import { ParamDefinition as PD } from '../../mol-util/param-definition'
|
|
|
import { ThemeDataContext } from '../../mol-theme/theme';
|
|
|
-import { ColorListOptions, ColorListName } from '../../mol-util/color/lists';
|
|
|
+import { getPaletteParams, getPalette } from './util';
|
|
|
+import { TableLegend } from '../../mol-util/color/lists';
|
|
|
+import { ScaleLegend } from '../../mol-util/color/scale';
|
|
|
|
|
|
const DefaultColor = Color(0xCCCCCC)
|
|
|
const Description = 'Gives every element (atom or coarse sphere/gaussian) a unique color based on the position (index) of the element in the list of elements in the structure.'
|
|
|
|
|
|
export const ElementIndexColorThemeParams = {
|
|
|
- list: PD.ColorScale<ColorListName>('red-yellow-blue', ColorListOptions),
|
|
|
+ ...getPaletteParams({ scaleList: 'red-yellow-blue' }),
|
|
|
}
|
|
|
export type ElementIndexColorThemeParams = typeof ElementIndexColorThemeParams
|
|
|
export function getElementIndexColorThemeParams(ctx: ThemeDataContext) {
|
|
@@ -26,7 +28,7 @@ export function getElementIndexColorThemeParams(ctx: ThemeDataContext) {
|
|
|
|
|
|
export function ElementIndexColorTheme(ctx: ThemeDataContext, props: PD.Values<ElementIndexColorThemeParams>): ColorTheme<ElementIndexColorThemeParams> {
|
|
|
let color: LocationColor
|
|
|
- let scale = ColorScale.create({ listOrName: props.list, minLabel: 'Start', maxLabel: 'End' })
|
|
|
+ let legend: ScaleLegend | TableLegend | undefined
|
|
|
|
|
|
if (ctx.structure) {
|
|
|
const { units } = ctx.structure
|
|
@@ -40,17 +42,18 @@ export function ElementIndexColorTheme(ctx: ThemeDataContext, props: PD.Values<E
|
|
|
elementCount += units[i].elements.length
|
|
|
unitIdIndex.set(units[i].id, i)
|
|
|
}
|
|
|
- scale.setDomain(0, elementCount - 1)
|
|
|
- const scaleColor = scale.color
|
|
|
+
|
|
|
+ const palette = getPalette(elementCount, props)
|
|
|
+ legend = palette.legend
|
|
|
|
|
|
color = (location: Location): Color => {
|
|
|
if (StructureElement.isLocation(location)) {
|
|
|
const unitIndex = unitIdIndex.get(location.unit.id)!
|
|
|
const unitElementIndex = OrderedSet.findPredecessorIndex(location.unit.elements, location.element)
|
|
|
- return scaleColor(cummulativeElementCount.get(unitIndex)! + unitElementIndex)
|
|
|
+ return palette.color(cummulativeElementCount.get(unitIndex)! + unitElementIndex)
|
|
|
} else if (Link.isLocation(location)) {
|
|
|
const unitIndex = unitIdIndex.get(location.aUnit.id)!
|
|
|
- return scaleColor(cummulativeElementCount.get(unitIndex)! + location.aIndex)
|
|
|
+ return palette.color(cummulativeElementCount.get(unitIndex)! + location.aIndex)
|
|
|
}
|
|
|
return DefaultColor
|
|
|
}
|
|
@@ -64,7 +67,7 @@ export function ElementIndexColorTheme(ctx: ThemeDataContext, props: PD.Values<E
|
|
|
color,
|
|
|
props,
|
|
|
description: Description,
|
|
|
- legend: scale ? scale.legend : undefined
|
|
|
+ legend
|
|
|
}
|
|
|
}
|
|
|
|