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/draw.bases

v3.8.5

Published

Draw nucleobases

Downloads

724

Readme

Installation

With npm:

npm install @rnacanvas/draw.bases

Usage

All exports of the package can be accessed as named imports.

import { Nucleobase } from '@rnacanvas/draw.bases';

Exports

Nucleobase

The Nucleobase class represents a text element within an SVG document that is a nucleobase.

static create()

Creates a nucleobase with the specified text content.

This method will also apply default values to the created nucleobase and assign it a UUID.

(It is necessary for all elements to have a unique ID when saving an RNAcanvas drawing.)

let b = Nucleobase.create('A');

b.textContent === 'A'; // true

constructor()

Receives an SVGTextElement instance as input.

The created nucleobase "adopts" the input SVG text element and behaves as though it is the SVG text element.

let textElement = document.createElementNS('http://www.w3.org/2000/svg', 'text');

let b = new Nucleobase(textElement);

domNode

A reference to the SVGTextElement instance that is the nucleobase.

let textElement = document.createElementNS('http://www.w3.org/2000/svg', 'text');
let b = new Nucleobase(textElement);

b.domNode === textElement; // true

appendTo()

Appends the text element that is the nucleobase to the given container node.

let svgDoc = document.createElementNS('http://www.w3.org/2000/svg', 'svg');

let b = Nucleobase.create('A');
b.appendTo(svgDoc);

svgDoc.contains(b.domNode); // true

remove()

Removes the text element that is the nucleobase from any parent container node that it is in.

This method does nothing if the text element does not have a parent container node.

let svgDoc = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
let b = Nucleobase.create('G');

b.appendTo(svgDoc);
svgDoc.contains(b.domNode); // true

b.remove();
svgDoc.contains(b.domNode); // false

isIn()

Returns true if the text element that is the nucleobase is a child (or grandchild, great-grandchild, etc.) of the given node.

Returns false otherwise, including when input the text element itself.

let svgDoc = document.createElementNS('http://www.w3.org/2000/svg', 'svg');

let b = Nucleobase.create('U');
b.appendTo(svgDoc);

b.isIn(svgDoc); // true
b.isIn(b.domNode); // false

getAttribute()

Get an attribute of the SVG text element that is the nucleobase.

nucleobase.domNode.setAttribute('fill', '#a62cf1');

nucleobase.getAttribute('fill') === '#a62cf1'; // true

setAttribute()

Set an attribute of the SVG text element that is the nucleobase.

nucleobase.setAttribute('fill', '#b28ccf');

nucleobase.domNode.getAttribute('fill') === '#b28ccf'; // true

setAttributes()

Set multiple attributes of the SVG text element that is the nucleobase at once using an object of attribute values keyed by attribute name.

Invalid inputs are ignored. (This method is not supposed to throw.)

nucleobase.setAttributes({ 'font-family': 'Comic Sans', 'fill': '#fa391c' });

nucleobase.domNode.getAttribute('font-family') === 'Comic Sans'; // true
nucleobase.domNode.getAttribute('fill') === '#fa391c'; // true

id

The id attribute of the text element that is the nucleobase.

(More precisely, returns that which is returned by the id property of the text element.)

nucleobase.domNode.setAttribute('id', 'text-123456');

nucleobase.id === 'text-123456'; // true

assignUUID()

Creates and assigns a new UUID to the text element that is the nucleobase.

This method will overwrite any existing ID that the nucleobase has.

The assigned UUID might also have some letters prepended to it (since all SVG element IDs must start with a letter), resulting in the assigned UUID having more than 36 characters.

nucleobase.assignUUID();

textContent

The text content of the text element that is the nucleobase.

(More precisely, returns that which is returned by the textContent property of the text element when used as a getter.)

nucleobase.domNode.textContent = 'R';

nucleobase.textContent === 'R'; // true

bbox

The bounding box of the text element that is the nucleobase.

Essentially, just forwards the values returned by the underlying getBBox method.

nucleobase.bbox; // a box with X and Y coordinates and width and height

centerPoint

The center point of the bounding box of the nucleobase.

Setting this will move the nucleobase.

// recenter the nucleobase on point (92, -112)
nucleobase.centerPoint = { x: 92, y: -112 };

getCenterPoint()

A simple getter method for the center point of the nucleobase.

nucleobase.getCenterPoint();

setCenterPoint()

A simple setter method for the center point of the nucleobase.

nucleobase.setCenterPoint({ x: 92, y: 178 });

addEventListener()

For listening for events on the nucleobase.

Listening for move events

Move events are defined as occurring when either the x or y attributes of the text element that is the nucleobase are changed.

Note that this definition does not include other changes that might change where the nucleobase appears on screen (e.g., transforms).

let listener = () => attachedElement.reposition();

nucleobase.addEventListener('move', listener);