@rnacanvas/app-object 4.7.2 → 4.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +214 -0
- package/_config.yml +1 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
The RNAcanvas app object encapsulates an entire RNAcanvas app instance.
|
|
2
|
+
|
|
3
|
+
# Installation
|
|
4
|
+
|
|
5
|
+
With `npm`:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install @rnacanvas/app-object
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
# Usage
|
|
12
|
+
|
|
13
|
+
### Imports
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
// the RNAcanvas app object constructor
|
|
17
|
+
import { RNAcanvas } from '@rnacanvas/app-object';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Creating a new RNAcanvas app object
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
var app = new RNAcanvas();
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Adding an RNAcanvas app instance to the document
|
|
27
|
+
|
|
28
|
+
It is important that an RNAcanvas app object be added to the document of a webpage
|
|
29
|
+
since much of the underlying functionality related to SVG drawing
|
|
30
|
+
only works for elements that have been added to the document.
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
// can also be added to any container node
|
|
34
|
+
app.appendTo(document.body);
|
|
35
|
+
|
|
36
|
+
// remove the RNAcanvas app object from its parent container node
|
|
37
|
+
app.remove();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### The DOM node reference
|
|
41
|
+
|
|
42
|
+
The DOM node corresponding to an RNAcanvas app instance
|
|
43
|
+
contains all of the elements that comprise an RNAcanvas app instance
|
|
44
|
+
and can be accessed using the `domNode` property.
|
|
45
|
+
|
|
46
|
+
The DOM node reference can be used to set certain styles of an RNAcanvas app instance
|
|
47
|
+
(e.g., `width` and `height`).
|
|
48
|
+
|
|
49
|
+
However, the internal contents and styling
|
|
50
|
+
of the DOM node corresponding to an RNAcanvas app instance
|
|
51
|
+
are not meant to be directly edited by outside code.
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
app.domNode;
|
|
55
|
+
|
|
56
|
+
app.domNode.style.width = '600px';
|
|
57
|
+
app.domNode.style.height = '400px';
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### The `style` property
|
|
61
|
+
|
|
62
|
+
For convenience, a `style` property is also provided
|
|
63
|
+
that simply forwards to the `style` property of the DOM node
|
|
64
|
+
corresponding to an RNAcanvas app instance.
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
app.style.width = '600px';
|
|
68
|
+
app.style.height = '750px';
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### The drawing of the app
|
|
72
|
+
|
|
73
|
+
The drawing of an RNAcanvas app instance
|
|
74
|
+
represents an SVG document that is a two-dimensional nucleic acid structure drawing.
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
app.drawing;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Drawing structures
|
|
81
|
+
|
|
82
|
+
For convenience, structures expressed in dot-bracket notation
|
|
83
|
+
can be drawn using the `drawDotBracket` method,
|
|
84
|
+
which will append the specified structure to the drawing of the app.
|
|
85
|
+
|
|
86
|
+
Note that this method alone will not adjust the padding of the drawing
|
|
87
|
+
or the user's view of the drawing after a structure has been drawn.
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
var seq = 'AGAGUAGCAUUCUGCUUUAGACUGUUAACUUUAUGAACCACGCGUGUCACGUGGGGAGAGUUAACAGCGCCC';
|
|
91
|
+
var dotBracket = '(((((((....)))))))...(((((((((((.....(((((.......)))))..))))))))))).....';
|
|
92
|
+
|
|
93
|
+
app.drawDotBracket(seq, dotBracket);
|
|
94
|
+
|
|
95
|
+
// ensure that the drawn structure fits inside the drawing
|
|
96
|
+
// (and include some extra space around the drawn structure)
|
|
97
|
+
app.drawing.setPadding(200);
|
|
98
|
+
|
|
99
|
+
app.drawingView.fitToContent();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### The user's view of the drawing
|
|
103
|
+
|
|
104
|
+
The user's view of the drawing of the app is represented by the `drawingView` interface.
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
app.drawingView;
|
|
108
|
+
|
|
109
|
+
// the center point of the user's view of the drawing (in drawing coordinates)
|
|
110
|
+
app.drawingView.centerPoint = { x: 557, y: 1825 };
|
|
111
|
+
app.drawingView.centerPoint; // { x: 557, y: 1825 }
|
|
112
|
+
|
|
113
|
+
// adjusts the scaling of the drawing and scrollbar positions
|
|
114
|
+
// (to fit the content of the drawing all on screen)
|
|
115
|
+
app.drawingView.fitToContent();
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### The currently selected elements
|
|
119
|
+
|
|
120
|
+
The `selectedSVGElements` property represents the set of currently selected SVG elements
|
|
121
|
+
in the drawing of the app.
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
app.selectedSVGElements.addAll([...app.drawing.secondaryBonds].slice(10, 20).map(sb => sb.domNode));
|
|
125
|
+
|
|
126
|
+
[...app.selectedSVGElements].forEach(ele => {
|
|
127
|
+
ele.setAttribute('stroke', 'blue');
|
|
128
|
+
ele.setAttribute('stroke-width', '3');
|
|
129
|
+
ele.setAttribute('stroke-linecap', 'round');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
app.selectedSVGElements.include([...app.drawing.secondaryBonds][10].domNode); // true
|
|
133
|
+
|
|
134
|
+
app.selectedSVGElements.removeAll([...app.drawing.secondaryBonds].slice(5, 12).map(sb => sb.domNode));
|
|
135
|
+
app.selectedSVGElements.include([...app.drawing.secondaryBonds][10].domNode); // false
|
|
136
|
+
|
|
137
|
+
app.selectedSVGElements.clear();
|
|
138
|
+
[...app.drawing.secondaryBonds].every(sb => !app.selectedSVGElements.include(sb.domNode)); // true
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The currently selected SVG elements can also be listened to for when they change.
|
|
142
|
+
|
|
143
|
+
```javascript
|
|
144
|
+
var numSelectedSVGElements = [...app.selectedSVGElements].length;
|
|
145
|
+
|
|
146
|
+
app.selectedSVGElements.addEventListener('change', () => numSelectedSVGElements = [...app.selectedSVGElements].length);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Similarly, the `selectedBases` property represents the currently selected set of bases
|
|
150
|
+
in the drawing of the app.
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
let numSelectedBases = [...app.selectedBases].length;
|
|
154
|
+
app.selectedBases.addEventListener('change', () => numSelectedBases = [...app.selectedBases].length);
|
|
155
|
+
|
|
156
|
+
app.selectedBases.addAll([...app.drawing.bases].slice(25, 50));
|
|
157
|
+
numSelectedBases; // 25
|
|
158
|
+
|
|
159
|
+
app.selectedBases.include([...app.drawing.bases][25]); // true
|
|
160
|
+
app.selectedBases.include([...app.drawing.bases][24]); // false
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The `selectAll` method can also be used to select all elements in the drawing of the app.
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
app.selectAll();
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Opening forms
|
|
170
|
+
|
|
171
|
+
Forms can be opened using the `openForm` method.
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
// for controlling the layout of bases in the drawing of the app
|
|
175
|
+
app.openForm(app.basesLayoutForm);
|
|
176
|
+
|
|
177
|
+
// for exporting the drawing (e.g., as an SVG image)
|
|
178
|
+
app.openForm(app.exportForm);
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
In general, any element with absolute positioning
|
|
182
|
+
(i.e., with a `position` CSS style of `absolute`)
|
|
183
|
+
could potentially be opened as a custom form in an RNAcanvas app instance.
|
|
184
|
+
|
|
185
|
+
```javascript
|
|
186
|
+
var customForm = document.createElement('div');
|
|
187
|
+
customForm.textContent = 'A custom form.';
|
|
188
|
+
|
|
189
|
+
customForm.style.position = 'absolute';
|
|
190
|
+
customForm.style.left = '50px';
|
|
191
|
+
customForm.style.top = '50px';
|
|
192
|
+
|
|
193
|
+
app.openForm(customForm);
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Alternatively, a wrapping object can be opened as a form
|
|
197
|
+
(i.e., input to the `openForm` method)
|
|
198
|
+
so long as it fulfills the `Form` interface below.
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
interface Form {
|
|
202
|
+
/**
|
|
203
|
+
* Appends the DOM node corresponding to the form to the provided container node.
|
|
204
|
+
*/
|
|
205
|
+
appendTo(container: Node): void;
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Forms are positioned relative to the bounding box of the RNAcanvas app instance.
|
|
210
|
+
|
|
211
|
+
Forms are closed by simply removing them
|
|
212
|
+
(i.e., by calling the `remove` method on their corresponding DOM nodes).
|
|
213
|
+
|
|
214
|
+
Forms can be made draggable by applying the `DragTranslater` class of the `@rnacanvas/forms` package to them.
|
package/_config.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
theme: jekyll-theme-minimal
|