OEDrawSVGHoverText

bool OEDrawSVGHoverText(OE2DMolDisplay &disp, OE2DAtomDisplay *adisp,
                        const std::string &text, const OEFont &font)

bool OEDrawSVGHoverText(OE2DMolDisplay &disp, OE2DBondDisplay *bdisp,
                        const std::string &text, const OEFont &font)

Creates and interactive effect in .svg images. The given text will appear when the mouse is hovering over the position defined by the given atom / bond display.

Note

This functionality is only available for .svg image format. In other image formats it has no effect.

The generated svg image should be included into and HTML page with the SVG MIME type.

<object data="<imagename>.svg" type="image/svg+xml"></object>
disp

The OE2DMolDisplay object that holds the data necessary to depict the molecule with which it is initialized.

adisp

The OE2DAtomDisplay object that defines where the text will appear.

bdisp

The OE2DBondDisplay object that defines where the text will appear.

text

The text that appears when the cursor is hovered over the given position.

font

The graphical properties of the font used to draw the text.

int width  = 400;
int height = 200;

OEImage image = new OEImage(width, height);

OEGraphMol mol = new OEGraphMol();
oechem.OESmilesToMol(mol, "Cc1cccnc1/C=C/[C@H](C(=O)O)O");
oedepict.OEPrepareDepiction(mol);

OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(width, height, OEScale.AutoScale);
opts.SetMargins(10);
OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);

OEFont font = new OEFont(OEFontFamily.Default, OEFontStyle.Default, 12,
                         OEAlignment.Center, oechem.getOEDarkRed());

for (OE2DAtomDisplay adisp : disp.GetAtomDisplays()) {
    OEAtomBase atom = adisp.GetAtom();
    String hovertext = "atom idx=" + Integer.toString(atom.GetIdx());
    oedepict.OEDrawSVGHoverText(disp, adisp, hovertext, font);
}
oedepict.OERenderMolecule("HoverAtomText.svg", disp);

Download code

HoverAtomText.java

hover mouse over any atoms

Example of using the OEDrawSVGHoverText function for atom positions

../../_images/HoverAtomText.svg

int width  = 400;
int height = 200;

OEImage image = new OEImage(width, height);

OEGraphMol mol = new OEGraphMol();
oechem.OESmilesToMol(mol, "Cc1cccnc1/C=C/[C@H](C(=O)O)O");
oedepict.OEPrepareDepiction(mol);

OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(width, height, OEScale.AutoScale);
opts.SetMargins(10);
OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);

OEFont font = new OEFont(OEFontFamily.Default, OEFontStyle.Default, 12,
                         OEAlignment.Center, oechem.getOEDarkRed());

for (OE2DBondDisplay bdisp : disp.GetBondDisplays()) {
    OEBondBase bond = bdisp.GetBond();
    String hovertext = "bond idx=" + Integer.toString(bond.GetIdx());
    oedepict.OEDrawSVGHoverText(disp, bdisp, hovertext, font);
}
oedepict.OERenderMolecule("HoverBondText.svg", disp);

Download code

HoverBondText.java

hover mouse over the middle of any bonds

Example of using the OEDrawSVGHoverText function for bond positions

../../_images/HoverBondText.svg

See also