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

improved color theme legend with labels from data

parent 0a16ec1b
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,10 @@ export function getChainIdColorThemeParams(ctx: ThemeDataContext) { ...@@ -26,7 +26,10 @@ export function getChainIdColorThemeParams(ctx: ThemeDataContext) {
if (ctx.structure) { if (ctx.structure) {
if (getAsymIdSerialMap(ctx.structure.root).size > 12) { if (getAsymIdSerialMap(ctx.structure.root).size > 12) {
params.palette.defaultValue.name = 'scale' params.palette.defaultValue.name = 'scale'
params.palette.defaultValue.params = { list: 'red-yellow-blue' } params.palette.defaultValue.params = {
...params.palette.defaultValue.params,
list: 'red-yellow-blue'
}
} }
} }
return params return params
...@@ -79,6 +82,9 @@ export function ChainIdColorTheme(ctx: ThemeDataContext, props: PD.Values<ChainI ...@@ -79,6 +82,9 @@ export function ChainIdColorTheme(ctx: ThemeDataContext, props: PD.Values<ChainI
const l = StructureElement.Location.create() const l = StructureElement.Location.create()
const asymIdSerialMap = getAsymIdSerialMap(ctx.structure.root) const asymIdSerialMap = getAsymIdSerialMap(ctx.structure.root)
const labelTable = Array.from(asymIdSerialMap.keys())
props.palette.params.valueLabel = (i: number) => labelTable[i]
const palette = getPalette(asymIdSerialMap.size, props) const palette = getPalette(asymIdSerialMap.size, props)
legend = palette.legend legend = palette.legend
......
...@@ -27,7 +27,10 @@ export function getEntitySourceColorThemeParams(ctx: ThemeDataContext) { ...@@ -27,7 +27,10 @@ export function getEntitySourceColorThemeParams(ctx: ThemeDataContext) {
if (ctx.structure) { if (ctx.structure) {
if (getMaps(ctx.structure.root.models).srcKeySerialMap.size > 12) { if (getMaps(ctx.structure.root.models).srcKeySerialMap.size > 12) {
params.palette.defaultValue.name = 'scale' params.palette.defaultValue.name = 'scale'
params.palette.defaultValue.params = { list: 'red-yellow-blue' } params.palette.defaultValue.params = {
...params.palette.defaultValue.params,
list: 'red-yellow-blue'
}
} }
} }
return params return params
...@@ -108,6 +111,13 @@ export function EntitySourceColorTheme(ctx: ThemeDataContext, props: PD.Values<E ...@@ -108,6 +111,13 @@ export function EntitySourceColorTheme(ctx: ThemeDataContext, props: PD.Values<E
const { models } = ctx.structure.root const { models } = ctx.structure.root
const { seqToSrcByModelEntity, srcKeySerialMap } = getMaps(models) const { seqToSrcByModelEntity, srcKeySerialMap } = getMaps(models)
const labelTable = Array.from(srcKeySerialMap.keys()).map(v => {
const l = v.split('|')[2]
return l === '1' ? 'Unnamed' : l
})
labelTable.push('Unknown')
props.palette.params.valueLabel = (i: number) => labelTable[i]
const palette = getPalette(srcKeySerialMap.size + 1, props) const palette = getPalette(srcKeySerialMap.size + 1, props)
legend = palette.legend legend = palette.legend
......
...@@ -27,7 +27,10 @@ export function getPolymerIdColorThemeParams(ctx: ThemeDataContext) { ...@@ -27,7 +27,10 @@ export function getPolymerIdColorThemeParams(ctx: ThemeDataContext) {
if (ctx.structure) { if (ctx.structure) {
if (getPolymerAsymIdSerialMap(ctx.structure.root).size > 12) { if (getPolymerAsymIdSerialMap(ctx.structure.root).size > 12) {
params.palette.defaultValue.name = 'scale' params.palette.defaultValue.name = 'scale'
params.palette.defaultValue.params = { list: 'red-yellow-blue' } params.palette.defaultValue.params = {
...params.palette.defaultValue.params,
list: 'red-yellow-blue'
}
} }
} }
return params return params
...@@ -88,6 +91,9 @@ export function PolymerIdColorTheme(ctx: ThemeDataContext, props: PD.Values<Poly ...@@ -88,6 +91,9 @@ export function PolymerIdColorTheme(ctx: ThemeDataContext, props: PD.Values<Poly
const l = StructureElement.Location.create() const l = StructureElement.Location.create()
const polymerAsymIdSerialMap = getPolymerAsymIdSerialMap(ctx.structure.root) const polymerAsymIdSerialMap = getPolymerAsymIdSerialMap(ctx.structure.root)
const labelTable = Array.from(polymerAsymIdSerialMap.keys())
props.palette.params.valueLabel = (i: number) => labelTable[i]
const palette = getPalette(polymerAsymIdSerialMap.size, props) const palette = getPalette(polymerAsymIdSerialMap.size, props)
legend = palette.legend legend = palette.legend
......
...@@ -25,7 +25,10 @@ export function getPolymerIndexColorThemeParams(ctx: ThemeDataContext) { ...@@ -25,7 +25,10 @@ export function getPolymerIndexColorThemeParams(ctx: ThemeDataContext) {
if (ctx.structure) { if (ctx.structure) {
if (getPolymerChainCount(ctx.structure.root) > 12) { if (getPolymerChainCount(ctx.structure.root) > 12) {
params.palette.defaultValue.name = 'scale' params.palette.defaultValue.name = 'scale'
params.palette.defaultValue.params = { list: 'red-yellow-blue' } params.palette.defaultValue.params = {
...params.palette.defaultValue.params,
list: 'red-yellow-blue'
}
} }
} }
return params return params
......
...@@ -25,7 +25,10 @@ export function getUnitIndexColorThemeParams(ctx: ThemeDataContext) { ...@@ -25,7 +25,10 @@ export function getUnitIndexColorThemeParams(ctx: ThemeDataContext) {
if (ctx.structure) { if (ctx.structure) {
if (ctx.structure.root.units.length > 12) { if (ctx.structure.root.units.length > 12) {
params.palette.defaultValue.name = 'scale' params.palette.defaultValue.name = 'scale'
params.palette.defaultValue.params = { list: 'red-yellow-blue' } params.palette.defaultValue.params = {
...params.palette.defaultValue.params,
list: 'red-yellow-blue'
}
} }
} }
return params return params
......
...@@ -20,19 +20,28 @@ const DefaultGetPaletteProps = { ...@@ -20,19 +20,28 @@ const DefaultGetPaletteProps = {
} }
type GetPaletteProps = typeof DefaultGetPaletteProps type GetPaletteProps = typeof DefaultGetPaletteProps
const LabelParams = {
valueLabel: PD.Value((i: number) => `${i + 1}`, { isHidden: true }),
minLabel: PD.Value('Start', { isHidden: true }),
maxLabel: PD.Value('End', { isHidden: true }),
}
export function getPaletteParams(props: Partial<GetPaletteProps> = {}) { export function getPaletteParams(props: Partial<GetPaletteProps> = {}) {
const p = { ...DefaultGetPaletteProps, ...props } const p = { ...DefaultGetPaletteProps, ...props }
return { return {
palette: PD.MappedStatic(p.type, { palette: PD.MappedStatic(p.type, {
scale: PD.Group({ scale: PD.Group({
...LabelParams,
list: PD.ColorList<ColorListName>(p.scaleList, ColorListOptionsScale), list: PD.ColorList<ColorListName>(p.scaleList, ColorListOptionsScale),
}, { isFlat: true }), }, { isFlat: true }),
set: PD.Group({ set: PD.Group({
...LabelParams,
list: PD.ColorList<ColorListName>(p.setList, ColorListOptionsSet), list: PD.ColorList<ColorListName>(p.setList, ColorListOptionsSet),
}, { isFlat: true }), }, { isFlat: true }),
generate: PD.Group({ generate: PD.Group({
...LabelParams,
...DistinctColorsParams, ...DistinctColorsParams,
maxCount: PD.Numeric(75, { min: 1, max: 250, step: 1 }) maxCount: PD.Numeric(75, { min: 1, max: 250, step: 1 }),
}, { isFlat: true }) }, { isFlat: true })
}, { }, {
options: [ options: [
...@@ -57,9 +66,9 @@ export function getPalette(count: number, props: PaletteProps) { ...@@ -57,9 +66,9 @@ export function getPalette(count: number, props: PaletteProps) {
let legend: ScaleLegend | TableLegend | undefined let legend: ScaleLegend | TableLegend | undefined
if (props.palette.name === 'scale') { if (props.palette.name === 'scale') {
const listOrName = props.palette.params.list const { list: listOrName, minLabel, maxLabel } = props.palette.params
const domain: [number, number] = [0, count - 1] const domain: [number, number] = [0, count - 1]
const scale = ColorScale.create({ listOrName, domain, minLabel: 'Start', maxLabel: 'End' }) const scale = ColorScale.create({ listOrName, domain, minLabel, maxLabel })
legend = scale.legend legend = scale.legend
color = scale.color color = scale.color
} else { } else {
...@@ -71,8 +80,18 @@ export function getPalette(count: number, props: PaletteProps) { ...@@ -71,8 +80,18 @@ export function getPalette(count: number, props: PaletteProps) {
count = Math.min(count, props.palette.params.maxCount) count = Math.min(count, props.palette.params.maxCount)
colors = distinctColors(count, props.palette.params) colors = distinctColors(count, props.palette.params)
} }
const { valueLabel } = props.palette.params
const colorsLength = colors.length const colorsLength = colors.length
legend = TableLegend(colors.map((c, i) => [`${i + 1}`, c])) const table: [string, Color][] = []
for (let i = 0; i < count; ++i) {
const j = i % colorsLength
if (table[j] === undefined) {
table[j] = [valueLabel(i), colors[j]]
} else {
table[j][0] += `, ${valueLabel(i)}`
}
}
legend = TableLegend(table)
color = (i: number) => colors[i % colorsLength] color = (i: number) => colors[i % colorsLength]
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment