@rnacanvas/app-object 18.7.0 → 18.8.0
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/LICENSE +674 -674
- package/README.md +411 -411
- package/__mocks__/styleMock.js +1 -1
- package/_config.yml +1 -1
- package/babel.config.js +6 -6
- package/dist/index.js +1 -1
- package/jest.config.js +8 -8
- package/package.json +60 -60
- package/tsconfig.json +15 -15
- package/webpack.config.js +43 -43
package/README.md
CHANGED
|
@@ -1,411 +1,411 @@
|
|
|
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
|
-
### `selectedTertiaryBonds()`
|
|
170
|
-
|
|
171
|
-
Represents the currently selected tertiary bonds.
|
|
172
|
-
|
|
173
|
-
```javascript
|
|
174
|
-
// add some bases to the drawing to start with
|
|
175
|
-
var bases = [...'AUGCAUGC'].map(letter => app.drawing.addBase(letter));
|
|
176
|
-
|
|
177
|
-
// add some tertiary bonds
|
|
178
|
-
var tbs = [[0, 6], [1, 7]].map(([i, j]) => (
|
|
179
|
-
app.drawing.addTertiaryBond(bases[i], bases[j])
|
|
180
|
-
));
|
|
181
|
-
|
|
182
|
-
app.select(tbs);
|
|
183
|
-
|
|
184
|
-
[...app.selectedTertiaryBonds].length; // 2
|
|
185
|
-
|
|
186
|
-
[...app.selectedTertiaryBonds].includes(tbs[0]); // true
|
|
187
|
-
[...app.selectedTertiaryBonds].includes(tbs[1]); // true
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
Changes to the currently selected tertiary bonds can also be listened for.
|
|
191
|
-
|
|
192
|
-
```javascript
|
|
193
|
-
var count = 0;
|
|
194
|
-
|
|
195
|
-
var listener = () => count += 1;
|
|
196
|
-
|
|
197
|
-
app.selectedTertiaryBonds.addEventListener('change', listener);
|
|
198
|
-
|
|
199
|
-
app.removeFromSelected([tbs[0]]);
|
|
200
|
-
|
|
201
|
-
count; // 1
|
|
202
|
-
|
|
203
|
-
app.selectedTertiaryBonds.removeEventListener('change', listener);
|
|
204
|
-
|
|
205
|
-
app.addToSelected([tbs[0]]);
|
|
206
|
-
|
|
207
|
-
// not incremented
|
|
208
|
-
count; // 1
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
### `selectedStrungElements()`
|
|
212
|
-
|
|
213
|
-
Represents the currently selected strung elements.
|
|
214
|
-
|
|
215
|
-
```javascript
|
|
216
|
-
// add some bases to the drawing to start with
|
|
217
|
-
var bases = [...'AUGCAUGC'].map(letter => app.drawing.addBase(letter));
|
|
218
|
-
|
|
219
|
-
// add some secondary bonds
|
|
220
|
-
var sbs = [[0, 7], [1, 6]].map(([i, j]) => (
|
|
221
|
-
app.drawing.addSecondaryBond(bases[i], bases[j])
|
|
222
|
-
));
|
|
223
|
-
|
|
224
|
-
// add some strung elements to the secondary bonds
|
|
225
|
-
var strungElements = [
|
|
226
|
-
app.drawing.addStrungElement('circle', sbs[0]),
|
|
227
|
-
app.drawing.addStrungElement('triangle', sbs[1]),
|
|
228
|
-
];
|
|
229
|
-
|
|
230
|
-
app.select(strungElements);
|
|
231
|
-
|
|
232
|
-
[...app.selectedStrungElements].length; // 2
|
|
233
|
-
|
|
234
|
-
[...app.selectedStrungElements].includes(strungElements[0]); // true
|
|
235
|
-
[...app.selectedStrungElements].includes(strungElements[1]); // true
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
The currently selected strung elements can also be retrieved as an array.
|
|
239
|
-
|
|
240
|
-
(Using the `toArray()` method is more performant than using the spread `...` operator.)
|
|
241
|
-
|
|
242
|
-
```javascript
|
|
243
|
-
app.selectedStrungElements.toArray().length; // 2
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
Changes to the currently selected strung elements can also be listened for.
|
|
247
|
-
|
|
248
|
-
```javascript
|
|
249
|
-
var count = 0;
|
|
250
|
-
|
|
251
|
-
var listener = () => count += 1;
|
|
252
|
-
|
|
253
|
-
app.selectedStrungElements.addEventListener('change', listener);
|
|
254
|
-
|
|
255
|
-
app.removeFromSelected([strungElements[0]]);
|
|
256
|
-
|
|
257
|
-
count; // 1
|
|
258
|
-
|
|
259
|
-
app.selectedStrungElements.removeEventListener('change', listener);
|
|
260
|
-
|
|
261
|
-
app.addToSelected([strungElements[0]]);
|
|
262
|
-
|
|
263
|
-
// not incremented
|
|
264
|
-
count; // 1
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
### Opening forms
|
|
268
|
-
|
|
269
|
-
Forms can be opened using the `openForm` method.
|
|
270
|
-
|
|
271
|
-
```javascript
|
|
272
|
-
// for controlling the layout of bases in the drawing of the app
|
|
273
|
-
app.openForm(app.basesLayoutForm);
|
|
274
|
-
|
|
275
|
-
// for exporting the drawing (e.g., as an SVG image)
|
|
276
|
-
app.openForm(app.exportForm);
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
In general, any element with absolute positioning
|
|
280
|
-
(i.e., with a `position` CSS style of `absolute`)
|
|
281
|
-
could potentially be opened as a custom form in an RNAcanvas app instance.
|
|
282
|
-
|
|
283
|
-
```javascript
|
|
284
|
-
var customForm = document.createElement('div');
|
|
285
|
-
customForm.textContent = 'A custom form.';
|
|
286
|
-
|
|
287
|
-
customForm.style.position = 'absolute';
|
|
288
|
-
customForm.style.left = '50px';
|
|
289
|
-
customForm.style.top = '50px';
|
|
290
|
-
|
|
291
|
-
app.openForm(customForm);
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
Alternatively, a wrapping object can be opened as a form
|
|
295
|
-
(i.e., input to the `openForm` method)
|
|
296
|
-
so long as it fulfills the `Form` interface below.
|
|
297
|
-
|
|
298
|
-
```typescript
|
|
299
|
-
interface Form {
|
|
300
|
-
/**
|
|
301
|
-
* Appends the DOM node corresponding to the form to the provided container node.
|
|
302
|
-
*/
|
|
303
|
-
appendTo(container: Node): void;
|
|
304
|
-
}
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
Forms are positioned relative to the bounding box of the RNAcanvas app instance.
|
|
308
|
-
|
|
309
|
-
Forms are closed by simply removing them
|
|
310
|
-
(i.e., by calling the `remove` method on their corresponding DOM nodes).
|
|
311
|
-
|
|
312
|
-
Forms can be made draggable by applying the `DragTranslater` class of the `@rnacanvas/forms` package to them.
|
|
313
|
-
|
|
314
|
-
### `closeForm()`
|
|
315
|
-
|
|
316
|
-
Closes the topmost form.
|
|
317
|
-
|
|
318
|
-
Does nothing if no forms are open.
|
|
319
|
-
|
|
320
|
-
```javascript
|
|
321
|
-
app.closeForm();
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
### `closeAllForms()`
|
|
325
|
-
|
|
326
|
-
Closes all currently open forms.
|
|
327
|
-
|
|
328
|
-
Does nothing if no forms are open.
|
|
329
|
-
|
|
330
|
-
```javascript
|
|
331
|
-
app.closeAllForms();
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
### `get startPage()`
|
|
335
|
-
|
|
336
|
-
The Start page interface.
|
|
337
|
-
|
|
338
|
-
```javascript
|
|
339
|
-
// open the Start page
|
|
340
|
-
app.startPage.open();
|
|
341
|
-
|
|
342
|
-
app.startPage.isOpen(); // true
|
|
343
|
-
|
|
344
|
-
// close the Start page
|
|
345
|
-
app.startPage.close();
|
|
346
|
-
|
|
347
|
-
app.startPage.isOpen(); // false
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
### `exportSVG()`
|
|
351
|
-
|
|
352
|
-
Downloads the drawing for the user in its current state
|
|
353
|
-
(including its current level of zoom)
|
|
354
|
-
as an SVG image.
|
|
355
|
-
|
|
356
|
-
```javascript
|
|
357
|
-
app.exportSVG();
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
### `exportPNG()`
|
|
361
|
-
|
|
362
|
-
Downloads the drawing for the user in its current state
|
|
363
|
-
(including its current level of zoom)
|
|
364
|
-
as a PNG image.
|
|
365
|
-
|
|
366
|
-
```javascript
|
|
367
|
-
app.exportPNG();
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
### `exportJPEG()`
|
|
371
|
-
|
|
372
|
-
Downloads the drawing for the user in its current state
|
|
373
|
-
(including its current level of zoom)
|
|
374
|
-
as a JPEG image.
|
|
375
|
-
|
|
376
|
-
```javascript
|
|
377
|
-
app.exportJPEG();
|
|
378
|
-
```
|
|
379
|
-
|
|
380
|
-
### `newTab()`
|
|
381
|
-
|
|
382
|
-
Opens a new blank tab of the RNAcanvas app.
|
|
383
|
-
|
|
384
|
-
```javascript
|
|
385
|
-
app.newTab();
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
### `duplicateTab()`
|
|
389
|
-
|
|
390
|
-
Opens a new duplicate tab of the RNAcanvas app
|
|
391
|
-
(i.e., a tab with the same URL parameters).
|
|
392
|
-
|
|
393
|
-
<b>Known issue #1:</b> This method cannot currently recreate (in the new duplicate tab)
|
|
394
|
-
edits to the drawing that the user has made.
|
|
395
|
-
|
|
396
|
-
To open a new tab of the drawing exactly as is (i.e., with all edits preserved),
|
|
397
|
-
download a `.rnacanvas` file of the drawing
|
|
398
|
-
and open the `.rnacanvas` file in a new tab of the RNAcanvas app.
|
|
399
|
-
|
|
400
|
-
<b>Known issue #2:</b> This method only works if the RNAcanvas URL interface
|
|
401
|
-
was used in the first place to draw the drawing currently being shown.
|
|
402
|
-
|
|
403
|
-
```javascript
|
|
404
|
-
app.duplicateTab();
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
This method will omit the `peripheral_ui` URL parameter from the new tab
|
|
408
|
-
so that it is always opened with a full peripheral UI.
|
|
409
|
-
|
|
410
|
-
(This is a useful property of this method when the RNAcanvas app is currently embedded in another website
|
|
411
|
-
without the full peripheral UI being shown.)
|
|
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
|
+
### `selectedTertiaryBonds()`
|
|
170
|
+
|
|
171
|
+
Represents the currently selected tertiary bonds.
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
// add some bases to the drawing to start with
|
|
175
|
+
var bases = [...'AUGCAUGC'].map(letter => app.drawing.addBase(letter));
|
|
176
|
+
|
|
177
|
+
// add some tertiary bonds
|
|
178
|
+
var tbs = [[0, 6], [1, 7]].map(([i, j]) => (
|
|
179
|
+
app.drawing.addTertiaryBond(bases[i], bases[j])
|
|
180
|
+
));
|
|
181
|
+
|
|
182
|
+
app.select(tbs);
|
|
183
|
+
|
|
184
|
+
[...app.selectedTertiaryBonds].length; // 2
|
|
185
|
+
|
|
186
|
+
[...app.selectedTertiaryBonds].includes(tbs[0]); // true
|
|
187
|
+
[...app.selectedTertiaryBonds].includes(tbs[1]); // true
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Changes to the currently selected tertiary bonds can also be listened for.
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
var count = 0;
|
|
194
|
+
|
|
195
|
+
var listener = () => count += 1;
|
|
196
|
+
|
|
197
|
+
app.selectedTertiaryBonds.addEventListener('change', listener);
|
|
198
|
+
|
|
199
|
+
app.removeFromSelected([tbs[0]]);
|
|
200
|
+
|
|
201
|
+
count; // 1
|
|
202
|
+
|
|
203
|
+
app.selectedTertiaryBonds.removeEventListener('change', listener);
|
|
204
|
+
|
|
205
|
+
app.addToSelected([tbs[0]]);
|
|
206
|
+
|
|
207
|
+
// not incremented
|
|
208
|
+
count; // 1
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### `selectedStrungElements()`
|
|
212
|
+
|
|
213
|
+
Represents the currently selected strung elements.
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
// add some bases to the drawing to start with
|
|
217
|
+
var bases = [...'AUGCAUGC'].map(letter => app.drawing.addBase(letter));
|
|
218
|
+
|
|
219
|
+
// add some secondary bonds
|
|
220
|
+
var sbs = [[0, 7], [1, 6]].map(([i, j]) => (
|
|
221
|
+
app.drawing.addSecondaryBond(bases[i], bases[j])
|
|
222
|
+
));
|
|
223
|
+
|
|
224
|
+
// add some strung elements to the secondary bonds
|
|
225
|
+
var strungElements = [
|
|
226
|
+
app.drawing.addStrungElement('circle', sbs[0]),
|
|
227
|
+
app.drawing.addStrungElement('triangle', sbs[1]),
|
|
228
|
+
];
|
|
229
|
+
|
|
230
|
+
app.select(strungElements);
|
|
231
|
+
|
|
232
|
+
[...app.selectedStrungElements].length; // 2
|
|
233
|
+
|
|
234
|
+
[...app.selectedStrungElements].includes(strungElements[0]); // true
|
|
235
|
+
[...app.selectedStrungElements].includes(strungElements[1]); // true
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
The currently selected strung elements can also be retrieved as an array.
|
|
239
|
+
|
|
240
|
+
(Using the `toArray()` method is more performant than using the spread `...` operator.)
|
|
241
|
+
|
|
242
|
+
```javascript
|
|
243
|
+
app.selectedStrungElements.toArray().length; // 2
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Changes to the currently selected strung elements can also be listened for.
|
|
247
|
+
|
|
248
|
+
```javascript
|
|
249
|
+
var count = 0;
|
|
250
|
+
|
|
251
|
+
var listener = () => count += 1;
|
|
252
|
+
|
|
253
|
+
app.selectedStrungElements.addEventListener('change', listener);
|
|
254
|
+
|
|
255
|
+
app.removeFromSelected([strungElements[0]]);
|
|
256
|
+
|
|
257
|
+
count; // 1
|
|
258
|
+
|
|
259
|
+
app.selectedStrungElements.removeEventListener('change', listener);
|
|
260
|
+
|
|
261
|
+
app.addToSelected([strungElements[0]]);
|
|
262
|
+
|
|
263
|
+
// not incremented
|
|
264
|
+
count; // 1
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Opening forms
|
|
268
|
+
|
|
269
|
+
Forms can be opened using the `openForm` method.
|
|
270
|
+
|
|
271
|
+
```javascript
|
|
272
|
+
// for controlling the layout of bases in the drawing of the app
|
|
273
|
+
app.openForm(app.basesLayoutForm);
|
|
274
|
+
|
|
275
|
+
// for exporting the drawing (e.g., as an SVG image)
|
|
276
|
+
app.openForm(app.exportForm);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
In general, any element with absolute positioning
|
|
280
|
+
(i.e., with a `position` CSS style of `absolute`)
|
|
281
|
+
could potentially be opened as a custom form in an RNAcanvas app instance.
|
|
282
|
+
|
|
283
|
+
```javascript
|
|
284
|
+
var customForm = document.createElement('div');
|
|
285
|
+
customForm.textContent = 'A custom form.';
|
|
286
|
+
|
|
287
|
+
customForm.style.position = 'absolute';
|
|
288
|
+
customForm.style.left = '50px';
|
|
289
|
+
customForm.style.top = '50px';
|
|
290
|
+
|
|
291
|
+
app.openForm(customForm);
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Alternatively, a wrapping object can be opened as a form
|
|
295
|
+
(i.e., input to the `openForm` method)
|
|
296
|
+
so long as it fulfills the `Form` interface below.
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
interface Form {
|
|
300
|
+
/**
|
|
301
|
+
* Appends the DOM node corresponding to the form to the provided container node.
|
|
302
|
+
*/
|
|
303
|
+
appendTo(container: Node): void;
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Forms are positioned relative to the bounding box of the RNAcanvas app instance.
|
|
308
|
+
|
|
309
|
+
Forms are closed by simply removing them
|
|
310
|
+
(i.e., by calling the `remove` method on their corresponding DOM nodes).
|
|
311
|
+
|
|
312
|
+
Forms can be made draggable by applying the `DragTranslater` class of the `@rnacanvas/forms` package to them.
|
|
313
|
+
|
|
314
|
+
### `closeForm()`
|
|
315
|
+
|
|
316
|
+
Closes the topmost form.
|
|
317
|
+
|
|
318
|
+
Does nothing if no forms are open.
|
|
319
|
+
|
|
320
|
+
```javascript
|
|
321
|
+
app.closeForm();
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### `closeAllForms()`
|
|
325
|
+
|
|
326
|
+
Closes all currently open forms.
|
|
327
|
+
|
|
328
|
+
Does nothing if no forms are open.
|
|
329
|
+
|
|
330
|
+
```javascript
|
|
331
|
+
app.closeAllForms();
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### `get startPage()`
|
|
335
|
+
|
|
336
|
+
The Start page interface.
|
|
337
|
+
|
|
338
|
+
```javascript
|
|
339
|
+
// open the Start page
|
|
340
|
+
app.startPage.open();
|
|
341
|
+
|
|
342
|
+
app.startPage.isOpen(); // true
|
|
343
|
+
|
|
344
|
+
// close the Start page
|
|
345
|
+
app.startPage.close();
|
|
346
|
+
|
|
347
|
+
app.startPage.isOpen(); // false
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### `exportSVG()`
|
|
351
|
+
|
|
352
|
+
Downloads the drawing for the user in its current state
|
|
353
|
+
(including its current level of zoom)
|
|
354
|
+
as an SVG image.
|
|
355
|
+
|
|
356
|
+
```javascript
|
|
357
|
+
app.exportSVG();
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### `exportPNG()`
|
|
361
|
+
|
|
362
|
+
Downloads the drawing for the user in its current state
|
|
363
|
+
(including its current level of zoom)
|
|
364
|
+
as a PNG image.
|
|
365
|
+
|
|
366
|
+
```javascript
|
|
367
|
+
app.exportPNG();
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### `exportJPEG()`
|
|
371
|
+
|
|
372
|
+
Downloads the drawing for the user in its current state
|
|
373
|
+
(including its current level of zoom)
|
|
374
|
+
as a JPEG image.
|
|
375
|
+
|
|
376
|
+
```javascript
|
|
377
|
+
app.exportJPEG();
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### `newTab()`
|
|
381
|
+
|
|
382
|
+
Opens a new blank tab of the RNAcanvas app.
|
|
383
|
+
|
|
384
|
+
```javascript
|
|
385
|
+
app.newTab();
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### `duplicateTab()`
|
|
389
|
+
|
|
390
|
+
Opens a new duplicate tab of the RNAcanvas app
|
|
391
|
+
(i.e., a tab with the same URL parameters).
|
|
392
|
+
|
|
393
|
+
<b>Known issue #1:</b> This method cannot currently recreate (in the new duplicate tab)
|
|
394
|
+
edits to the drawing that the user has made.
|
|
395
|
+
|
|
396
|
+
To open a new tab of the drawing exactly as is (i.e., with all edits preserved),
|
|
397
|
+
download a `.rnacanvas` file of the drawing
|
|
398
|
+
and open the `.rnacanvas` file in a new tab of the RNAcanvas app.
|
|
399
|
+
|
|
400
|
+
<b>Known issue #2:</b> This method only works if the RNAcanvas URL interface
|
|
401
|
+
was used in the first place to draw the drawing currently being shown.
|
|
402
|
+
|
|
403
|
+
```javascript
|
|
404
|
+
app.duplicateTab();
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
This method will omit the `peripheral_ui` URL parameter from the new tab
|
|
408
|
+
so that it is always opened with a full peripheral UI.
|
|
409
|
+
|
|
410
|
+
(This is a useful property of this method when the RNAcanvas app is currently embedded in another website
|
|
411
|
+
without the full peripheral UI being shown.)
|