Commit 3cc4c357 authored by Lukas Pravda's avatar Lukas Pravda
Browse files

allow atom names to be displayed

parent d323cd99
......@@ -70,6 +70,7 @@ namespace Config {
residueLabel: boolean;
tooltip: boolean;
menu: boolean;
names: boolean;
constructor() {
this.reinitialize = true;
......@@ -82,6 +83,7 @@ namespace Config {
this.residueLabel = true;
this.tooltip = true;
this.menu = true;
this.names = true;
}
}
}
\ No newline at end of file
......@@ -90,11 +90,13 @@ class Depiction {
return new Vector2D(x, y);
}
public draw() {
public draw(atom_names: boolean = false) {
this.structure.selectAll("*").remove();
this.appendBondVisuals();
this.appendTexts();
if (atom_names) this.appendAtomNames();
else this.appendLabels();
}
public highlightSubgraph(atoms: Array<string>, color: string = undefined) {
......@@ -145,6 +147,25 @@ class Depiction {
.attr('d', (y: Bond) => y.coords);
}
/**
* Append atom name labels to the visualization.
*
* @memberof Depiction
*/
private appendAtomNames() {
this.structure.selectAll()
.data(this.atoms)
.enter()
.append('text')
.attr('filter', "url(#solid-background)")
.attr('style', 'font-size:21px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;fill:#000000')
.attr('x', x => x.position.x)
.attr('y', x => x.position.y)
.attr('dominant-baseline', 'central')
.attr('text-anchor', 'middle')
.text(x => x.name);
}
/**
* Append depiction labels to the visualization. Because RDKIt places
* the labels slightly differently this information needs to be
......@@ -154,8 +175,7 @@ class Depiction {
*
* @memberof Depiction
*/
private appendTexts(): void {
private appendLabels() {
let data = this.atoms
.filter(x => x.labels.length > 0)
?.map(x => x.labels)
......@@ -172,7 +192,6 @@ class Depiction {
.attr('dominant-baseline', (x: any) => x['dominant-baseline'])
.attr('text-anchor', (x: any) => x['text-anchor'])
.each(function (x: any) {
for (var i = 0; i < x.tspans.length; i++) {
d3.select(this)
.append('tspan')
......
......@@ -285,6 +285,10 @@ class Visualization {
this.depiction.draw();
}
public toggleDepiction(atomNames: boolean) {
this.depiction.draw(atomNames);
}
/**
* Add atom highlight to the ligand structure. The previous highlight
......@@ -472,8 +476,8 @@ class Visualization {
private computeBoundingBox(minX: number, maxX: number, minY: number, maxY: number) {
// The width and the height of the graph
let molWidth = (maxX - minX) + 1; // +1 to avoid 0 division
let molHeight = (maxY - minY) + 1;
let molWidth = Math.max((maxX - minX), this.parent.offsetWidth);
let molHeight = Math.max((maxY - minY), this.parent.offsetHeight);
// how much larger the drawing area is than the width and the height
let widthRatio = this.parent.offsetWidth / molWidth;
......@@ -496,7 +500,6 @@ class Visualization {
// tell the zoomer what we did so that next we zoom, it uses the
// transformation we entered here
let translation = d3.zoomIdentity.translate(xTrans, yTrans).scale(minRatio);
this.zoomHandler?.transform(this.svg, translation);
}
......
......@@ -234,6 +234,15 @@ class UI {
.attr('class', 'icon icon-common icon-sync-alt')
.on('click', () => this.reinitialize());
}
if (p.reinitialize) {
dynamicPanel.append('i')
.attr('id', 'pdb-lig-env-names-btn')
.attr('title', 'Show/hide atom names')
.attr('class', 'icon icon-common icon-font')
.classed('active', false)
.on('click', () => this.showNames());
}
}
if (p.tooltip) {
......@@ -299,6 +308,21 @@ class UI {
}
}
private showNames() {
let btn = d3.select(this.parent).select('#pdb-lig-env-names-btn');
let isActive = btn.classed('active');
if (isActive) {
this.display.toggleDepiction(true);
btn.style('color', '#637ca0');
btn.classed('active', false);
} else {
this.display.toggleDepiction(false);
btn.style('color', '');
btn.classed('active', true);
}
}
private showHelp() {
let el = d3.select(this.parent).select('#pdb-lig-env-help-container');
let btn = d3.select(this.parent).select('#pdb-lig-env-help-btn');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment