npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rnacanvas/app-object

v9.18.1

Published

The RNAcanvas app object

Downloads

1,126

Readme

The RNAcanvas app object encapsulates an entire RNAcanvas app instance.

Installation

With npm:

npm install @rnacanvas/app-object

Usage

Imports

// the RNAcanvas app object constructor
import { RNAcanvas } from '@rnacanvas/app-object';

Creating a new RNAcanvas app object

var app = new RNAcanvas();

Adding an RNAcanvas app instance to the document

It is important that an RNAcanvas app object be added to the document of a webpage since much of the underlying functionality related to SVG drawing only works for elements that have been added to the document.

// can also be added to any container node
app.appendTo(document.body);

// remove the RNAcanvas app object from its parent container node
app.remove();

The DOM node reference

The DOM node corresponding to an RNAcanvas app instance contains all of the elements that comprise an RNAcanvas app instance and can be accessed using the domNode property.

The DOM node reference can be used to set certain styles of an RNAcanvas app instance (e.g., width and height).

However, the internal contents and styling of the DOM node corresponding to an RNAcanvas app instance are not meant to be directly edited by outside code.

app.domNode;

app.domNode.style.width = '600px';
app.domNode.style.height = '400px';

The style property

For convenience, a style property is also provided that simply forwards to the style property of the DOM node corresponding to an RNAcanvas app instance.

app.style.width = '600px';
app.style.height = '750px';

The drawing of the app

The drawing of an RNAcanvas app instance represents an SVG document that is a two-dimensional nucleic acid structure drawing.

app.drawing;

Drawing structures

For convenience, structures expressed in dot-bracket notation can be drawn using the drawDotBracket method, which will append the specified structure to the drawing of the app.

Note that this method alone will not adjust the padding of the drawing or the user's view of the drawing after a structure has been drawn.

var seq = 'AGAGUAGCAUUCUGCUUUAGACUGUUAACUUUAUGAACCACGCGUGUCACGUGGGGAGAGUUAACAGCGCCC';
var dotBracket = '(((((((....)))))))...(((((((((((.....(((((.......)))))..))))))))))).....';

app.drawDotBracket(seq, dotBracket);

// ensure that the drawn structure fits inside the drawing
// (and include some extra space around the drawn structure)
app.drawing.setPadding(200);

app.drawingView.fitToContent();

The user's view of the drawing

The user's view of the drawing of the app is represented by the drawingView interface.

app.drawingView;

// the center point of the user's view of the drawing (in drawing coordinates)
app.drawingView.centerPoint = { x: 557, y: 1825 };
app.drawingView.centerPoint; // { x: 557, y: 1825 }

// adjusts the scaling of the drawing and scrollbar positions
// (to fit the content of the drawing all on screen)
app.drawingView.fitToContent();

The currently selected elements

The selectedSVGElements property represents the set of currently selected SVG elements in the drawing of the app.

app.selectedSVGElements.addAll([...app.drawing.secondaryBonds].slice(10, 20).map(sb => sb.domNode));

[...app.selectedSVGElements].forEach(ele => {
  ele.setAttribute('stroke', 'blue');
  ele.setAttribute('stroke-width', '3');
  ele.setAttribute('stroke-linecap', 'round');
});

app.selectedSVGElements.include([...app.drawing.secondaryBonds][10].domNode); // true

app.selectedSVGElements.removeAll([...app.drawing.secondaryBonds].slice(5, 12).map(sb => sb.domNode));
app.selectedSVGElements.include([...app.drawing.secondaryBonds][10].domNode); // false

app.selectedSVGElements.clear();
[...app.drawing.secondaryBonds].every(sb => !app.selectedSVGElements.include(sb.domNode)); // true

The currently selected SVG elements can also be listened to for when they change.

var numSelectedSVGElements = [...app.selectedSVGElements].length;

app.selectedSVGElements.addEventListener('change', () => numSelectedSVGElements = [...app.selectedSVGElements].length);

Similarly, the selectedBases property represents the currently selected set of bases in the drawing of the app.

let numSelectedBases = [...app.selectedBases].length;
app.selectedBases.addEventListener('change', () => numSelectedBases = [...app.selectedBases].length);

app.selectedBases.addAll([...app.drawing.bases].slice(25, 50));
numSelectedBases; // 25

app.selectedBases.include([...app.drawing.bases][25]); // true
app.selectedBases.include([...app.drawing.bases][24]); // false

The selectAll method can also be used to select all elements in the drawing of the app.

app.selectAll();

Opening forms

Forms can be opened using the openForm method.

// for controlling the layout of bases in the drawing of the app
app.openForm(app.basesLayoutForm);

// for exporting the drawing (e.g., as an SVG image)
app.openForm(app.exportForm);

In general, any element with absolute positioning (i.e., with a position CSS style of absolute) could potentially be opened as a custom form in an RNAcanvas app instance.

var customForm = document.createElement('div');
customForm.textContent = 'A custom form.';

customForm.style.position = 'absolute';
customForm.style.left = '50px';
customForm.style.top = '50px';

app.openForm(customForm);

Alternatively, a wrapping object can be opened as a form (i.e., input to the openForm method) so long as it fulfills the Form interface below.

interface Form {
  /**
   * Appends the DOM node corresponding to the form to the provided container node.
   */
  appendTo(container: Node): void;
}

Forms are positioned relative to the bounding box of the RNAcanvas app instance.

Forms are closed by simply removing them (i.e., by calling the remove method on their corresponding DOM nodes).

Forms can be made draggable by applying the DragTranslater class of the @rnacanvas/forms package to them.