@linkurious/ogma-annotations 1.1.27 → 2.0.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/Readme.md +3 -132
- package/dist/index.js +65 -24
- package/dist/index.mjs +6559 -1898
- package/dist/ogma-annotations.css +1 -1
- package/dist/types/index.d.ts +1352 -307
- package/package.json +45 -15
package/Readme.md
CHANGED
|
@@ -1,138 +1,9 @@
|
|
|
1
1
|
# `@linkurious/ogma-annotations`
|
|
2
2
|
|
|
3
|
-
This package provides
|
|
3
|
+
This package provides core functionalities to create and manage annotations in an Ogma graph. It is UI library agnostic and can be used in any JavaScript or TypeScript project.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @linkurious/ogma @linkurious/ogma-annotations
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
The plugin comes with no UI of its own, but provides a set of tools that you can enable in your Ogma instance. Currently, it supports the following features:
|
|
14
|
-
|
|
15
|
-
- **Text boxes**: You can create text boxes on top of your visualisation. They can be moved around and resized. Styling is encoded in the feature's data.
|
|
16
|
-
- **Arrows**: Arrows can be drawn between nodes. They can be styled and can snap to both nodes and text annotations.
|
|
17
|
-
|
|
18
|
-
```ts
|
|
19
|
-
import Ogma from '@linkurious/ogma';
|
|
20
|
-
import {
|
|
21
|
-
Control,
|
|
22
|
-
createArrow,
|
|
23
|
-
createText,
|
|
24
|
-
AnnotationCollection,
|
|
25
|
-
} from "@linkurious/ogma-annotations";
|
|
26
|
-
// CSS required to style the controls and handles
|
|
27
|
-
import "@linkurious/ogma-annotations/style.css";
|
|
28
|
-
|
|
29
|
-
const ogma = new Ogma({...});
|
|
30
|
-
const annotationsEditor = new Control(ogma);
|
|
31
|
-
|
|
32
|
-
// we assume you have a button with the id 'add-text'
|
|
33
|
-
const addTexts = document.getElementById("add-text")! as HTMLButtonElement;
|
|
34
|
-
|
|
35
|
-
// user has clicked on the button to add text annotations
|
|
36
|
-
addTexts.addEventListener("click", () => {
|
|
37
|
-
// disable the button to prevent multiple text annotations from being created
|
|
38
|
-
addTexts.disabled = true;
|
|
39
|
-
|
|
40
|
-
// create a new text annotation when user starts dragging the pointer
|
|
41
|
-
ogma.events.once("mousedown", (evt) => {
|
|
42
|
-
// annotations are in graph coordinates
|
|
43
|
-
const { x, y } = ogma.view.screenToGraphCoordinates(evt);
|
|
44
|
-
// create a text annotation feature
|
|
45
|
-
const text = createText(x, y, 0, 0);
|
|
46
|
-
|
|
47
|
-
// start drawing
|
|
48
|
-
annotationsEditor.startText(x, y, text);
|
|
49
|
-
// finish drawing
|
|
50
|
-
annotationsEditor.once('dragend', (annotation) => {
|
|
51
|
-
if (annotation.id !== text.id) return;
|
|
52
|
-
addTexts.disabled = false;
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// also stop drawing but pressing the escape key
|
|
58
|
-
document.addEventListener("keydown", (evt) => {
|
|
59
|
-
if (evt.key === "Escape") annotationsEditor.cancelDrawing();
|
|
60
|
-
});
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## API
|
|
64
|
-
|
|
65
|
-
### `Control`
|
|
66
|
-
|
|
67
|
-
The `Control` class is the main entry point for the plugin. It provides a set of methods to create and manage annotations.
|
|
68
|
-
|
|
69
|
-
#### `new Control(ogma: Ogma)`
|
|
70
|
-
|
|
71
|
-
Creates a new control instance.
|
|
72
|
-
|
|
73
|
-
#### `.add(annotation: AnnotationCollection | Text | Arrow)`
|
|
74
|
-
|
|
75
|
-
Adds an annotation to the graph.
|
|
76
|
-
|
|
77
|
-
#### `.remove(annotation: AnnotationCollection | Text | Arrow)`
|
|
78
|
-
|
|
79
|
-
Removes an annotation from the graph.
|
|
80
|
-
|
|
81
|
-
#### `.startText(x: number, y: number, text: Text)`
|
|
82
|
-
|
|
83
|
-
Starts drawing a text annotation at the given coordinates.
|
|
84
|
-
|
|
85
|
-
#### `.startArrow(x: number, y: number, arrow: Arrow)`
|
|
86
|
-
|
|
87
|
-
Starts drawing an arrow annotation at the given coordinates.
|
|
88
|
-
|
|
89
|
-
#### `.cancelDrawing()`
|
|
90
|
-
|
|
91
|
-
Cancels the current drawing operation.
|
|
92
|
-
|
|
93
|
-
#### `.on(event: 'dragend' | 'dragstart' | 'drag' | 'click', listener: (annotation: AnnotationCollection) => void)`
|
|
94
|
-
|
|
95
|
-
Registers an event listener.
|
|
96
|
-
|
|
97
|
-
#### `.once(event: 'dragend' | 'dragstart' | 'drag' | 'click', listener: (annotation: AnnotationCollection) => void)`
|
|
98
|
-
|
|
99
|
-
Registers a one-time event listener.
|
|
100
|
-
|
|
101
|
-
## `createText(x[=0], y[=0], width[=100], height[=50], content = '', styles?: TextStyles): Text`
|
|
102
|
-
|
|
103
|
-
Creates a new text annotation.
|
|
104
|
-
|
|
105
|
-
## `createArrow(x0: number, y0: number, x1: number, y1: number, styles?: ArrowStyles): Arrow`
|
|
106
|
-
|
|
107
|
-
Creates a new arrow annotation.
|
|
108
|
-
|
|
109
|
-
## `AnnotationCollection`
|
|
110
|
-
|
|
111
|
-
An annotation collection is a group of annotations that are related to each other. It can be a text annotation or an arrow annotation. It follows GeoJSON's feature collection format.
|
|
112
|
-
|
|
113
|
-
## `Text`
|
|
114
|
-
|
|
115
|
-
A text annotation is a feature that represents a text box on the graph. It has the following properties:
|
|
116
|
-
|
|
117
|
-
- `id`: a unique identifier for the text annotation.
|
|
118
|
-
- `type`: the type of the feature, which is always `text`.
|
|
119
|
-
- `properties`: an object that contains the text content and the style of the text.
|
|
120
|
-
- `properties.content: string`: the content of the text.
|
|
121
|
-
- `properties.style: TextStyle`: the style of the text.
|
|
122
|
-
|
|
123
|
-
## `Arrow`
|
|
124
|
-
|
|
125
|
-
An arrow annotation is a feature that represents an arrow on the graph. It has the following properties:
|
|
126
|
-
|
|
127
|
-
- `id`: a unique identifier for the arrow annotation.
|
|
128
|
-
- `type`: the type of the feature, which is always `arrow`.
|
|
129
|
-
- `properties`: an object that contains the style of the arrow.
|
|
130
|
-
- `properties.style: ArrowStyle`: the style of the arrow.
|
|
131
|
-
- `properties.links: { ['start'| 'end']: Link }`: Encoded connections of the arrow to nodes or text annotations.
|
|
132
|
-
|
|
133
|
-
## [`TextStyle`](src/types.ts)
|
|
134
|
-
|
|
135
|
-
## [`ArrowStyle`](src/types.ts)
|
|
5
|
+
- [Installation & Setup](/typescript/installation.md)
|
|
6
|
+
- [Core concepts](/typescript/core-concepts/)
|
|
136
7
|
|
|
137
8
|
## License
|
|
138
9
|
|