Skip to content
Snippets Groups Projects
Commit 5ae2dfcf authored by Alexander Rose's avatar Alexander Rose
Browse files

fixed element-index color-scheme

parent ce0385f7
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import { ColorScale, Color } from 'mol-util/color'; import { ColorScale, Color } from 'mol-util/color';
import { Location } from 'mol-model/location'; import { Location } from 'mol-model/location';
import { StructureElement, Link, Unit } from 'mol-model/structure'; import { StructureElement, Link } from 'mol-model/structure';
import { OrderedSet } from 'mol-data/int'; import { OrderedSet } from 'mol-data/int';
import { ColorThemeProps, ColorTheme, LocationColor } from '../color'; import { ColorThemeProps, ColorTheme, LocationColor } from '../color';
...@@ -19,22 +19,24 @@ export function ElementIndexColorTheme(props: ColorThemeProps): ColorTheme { ...@@ -19,22 +19,24 @@ export function ElementIndexColorTheme(props: ColorThemeProps): ColorTheme {
const { units } = props.structure const { units } = props.structure
const unitCount = units.length const unitCount = units.length
const cummulativeElementCount = new Map<number, number>() const cummulativeElementCount = new Map<number, number>()
const unitIdIndex = new Map<number, number>()
let elementCount = 0 let elementCount = 0
for (let i = 0; i < unitCount; ++i) { for (let i = 0; i < unitCount; ++i) {
cummulativeElementCount.set(i, elementCount) cummulativeElementCount.set(i, elementCount)
elementCount += units[i].elements.length elementCount += units[i].elements.length
unitIdIndex.set(units[i].id, i)
} }
const scale = ColorScale.create({ domain: [ 0, elementCount ] }) const scale = ColorScale.create({ domain: [ 0, elementCount - 1 ] })
color = (location: Location): Color => { color = (location: Location): Color => {
if (StructureElement.isLocation(location)) { if (StructureElement.isLocation(location)) {
const unitIndex = Unit.findUnitById(location.unit.id, units) const unitIndex = unitIdIndex.get(location.unit.id)!
const unitElementIndex = OrderedSet.findPredecessorIndex(location.unit.elements, location.element) const unitElementIndex = OrderedSet.findPredecessorIndex(location.unit.elements, location.element)
return scale.color(cummulativeElementCount.get(unitIndex) || 0 + unitElementIndex) return scale.color(cummulativeElementCount.get(unitIndex)! + unitElementIndex)
} else if (Link.isLocation(location)) { } else if (Link.isLocation(location)) {
const unitId = Unit.findUnitById(location.aUnit.id, units) const unitIndex = unitIdIndex.get(location.aUnit.id)!
return scale.color(cummulativeElementCount.get(unitId) || 0 + location.aIndex) return scale.color(cummulativeElementCount.get(unitIndex)! + location.aIndex)
} }
return DefaultColor return DefaultColor
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment