Skip to content

Commit fe138c8

Browse files
Merge pull request #170 from SenteraLLC/refactor/config
Refactor/config
2 parents 834ad63 + c2e54f2 commit fe138c8

14 files changed

Lines changed: 259 additions & 219 deletions

api_spec.md

Lines changed: 91 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,42 @@ The constructor is used to specify the configuration for an "annotation session"
3434

3535
```javascript
3636
class ULabel({
37+
// Required arguments
3738
container_id: string,
3839
image_data: string | string[],
3940
username: string,
4041
submit_buttons: function | ULabelSubmitButton[],
4142
subtasks: object,
43+
// Optional arguments
4244
task_meta: object,
4345
annotation_meta: object,
4446
px_per_px: number,
4547
initial_crop: InitialCrop,
4648
initial_line_size: number,
4749
instructions_url: string,
48-
config_data: object,
49-
toolbox_order: AllowedToolboxItem[]
50+
toolbox_order: AllowedToolboxItem[],
51+
default_keybinds = {
52+
"annotation_size_small": string,
53+
"annotation_size_large": string,
54+
"annotation_size_plus": string,
55+
"annotation_size_minus": string,
56+
"annotation_vanish": string
57+
},
58+
distance_filter_toolbox_item: FilterDistanceConfig,
59+
change_zoom_keybind: string,
60+
create_point_annotation_keybind: string,
61+
default_annotation_size: number,
62+
delete_annotation_keybind: string,
63+
keypoint_slider_default_value: number,
64+
filter_annotations_on_load: boolean,
65+
switch_subtask_keybind: string,
66+
toggle_annotation_mode_keybind: string,
67+
create_bbox_on_initial_crop: string,
68+
toggle_brush_mode_keybind: string,
69+
toggle_erase_mode_keybind: string,
70+
increase_brush_size_keybind: string,
71+
decrease_brush_size_keybind: string,
72+
n_annos_per_canvas: number
5073
})
5174
```
5275

@@ -284,57 +307,11 @@ The line width with which new annotations are drawn initially. Units are pixels
284307
285308
URL to a page that gives annotation instructions.
286309
287-
### `config_data`
288-
289-
*object* -- An object to configure much of ULabel's behaviors.
310+
### `toolbox_order`
311+
An array of numbers that defines the vertical order of items in the toolbox. At least one item must be included in the array. Any excluded items will not be displayed in the toolbox.
290312
313+
The supported toolbox items are:
291314
```javascript
292-
{
293-
default_toolbox_item_order: AllowedToolboxItem[],
294-
295-
default_keybinds = {
296-
"annotation_size_small": string,
297-
"annotation_size_large": string,
298-
"annotation_size_plus": string,
299-
"annotation_size_minus": string,
300-
"annotation_vanish": string
301-
},
302-
303-
distance_filter_toolbox_item: FilterDistanceConfig,
304-
305-
change_zoom_keybind: string,
306-
307-
create_point_annotation_keybind: string,
308-
309-
default_annotation_size: number,
310-
311-
delete_annotation_keybind: string,
312-
313-
keypoint_slider_default_value: number,
314-
315-
filter_annotations_on_load: boolean,
316-
317-
switch_subtask_keybind: string,
318-
319-
toggle_annotation_mode_keybind: string,
320-
321-
create_bbox_on_initial_crop: string,
322-
323-
annotation_gradient_default: boolean
324-
325-
toggle_brush_mode_keybind: string
326-
327-
toggle_erase_mode_keybind: string
328-
329-
increase_brush_size_keybind: string
330-
331-
decrease_brush_size_keybind: string
332-
333-
n_annos_per_canvas: number // Default is 100. Setting higher for jobs with a large number annotations may help performance.
334-
}
335-
```
336-
With the following custom definitions.
337-
```Javascript
338315
enum AllowedToolboxItem {
339316
ModeSelect, // 0
340317
ZoomPan, // 1
@@ -347,7 +324,27 @@ enum AllowedToolboxItem {
347324
FilterDistance, // 8
348325
Brush // 9
349326
}
327+
```
328+
You can access the AllowedToolboxItem enum by calling the static method:
329+
```javascript
330+
const AllowedToolboxItem = ULabel.get_allowed_toolbox_item_enum();
331+
```
350332
333+
### `default_keybinds`
334+
Keybinds can be set to control the annotation session. The default values are:
335+
```javascript
336+
{
337+
"annotation_size_small": "s",
338+
"annotation_size_large": "l",
339+
"annotation_size_plus": "=",
340+
"annotation_size_minus": "-",
341+
"annotation_vanish": "v"
342+
}
343+
```
344+
345+
### `distance_filter_toolbox_item`
346+
Configuration object for the `FilterDistance` toolbox item with the following custom definitions:
347+
```javascript
351348
type DistanceFromPolyline = {
352349
distance: number // distance in pixels
353350
}
@@ -374,7 +371,49 @@ type FilterDistanceConfig = {
374371
// since it will not update the filter/overlay until polyline moves/edits are complete.
375372
}
376373
```
377-
Where all `config_data` properties are optional.
374+
375+
### `change_zoom_keybind`
376+
Keybind to change the zoom level. Must be a letter, and the lowercase version of the letter will set the zoom level to the `initial_crop`, while the capitalized version will show the full image. Default is `r`.
377+
378+
### `create_point_annotation_keybind`
379+
Keybind to create a point annotation at the mouse location. Default is `c`. Requires the active subtask to have a `point` mode.
380+
381+
### `default_annotation_size`
382+
Default size of annotations in pixels. Default is `6`.
383+
384+
### `delete_annotation_keybind`
385+
Keybind to delete the annotation that the mouse is hovering over. Default is `d`.
386+
387+
### `keypoint_slider_default_value`
388+
Default value for the keypoint slider. Must be a number between 0 and 1. Default is `0`.
389+
390+
### `filter_annotations_on_load`
391+
If true, the annotations will be filtered on load based on the `keypoint_slider_default_value`. Default is `true`.
392+
393+
### `switch_subtask_keybind`
394+
Keybind to switch between subtasks. Default is `z`.
395+
396+
### `toggle_annotation_mode_keybind`
397+
Keybind to toggle between annotation and selection modes. Default is `u`.
398+
399+
### `create_bbox_on_initial_crop`
400+
Keybind to create a bounding box annotation around the `initial_crop`. Default is `f`. Requires the active subtask to have a `bbox` mode.
401+
402+
### `toggle_brush_mode_keybind`
403+
Keybind to toggle brush mode for polygon annotations. Default is `g`. Requires the active subtask to have a `polygon` mode.
404+
405+
### `toggle_erase_mode_keybind`
406+
Keybind to toggle erase mode for polygon annotations. Default is `e`. Requires the active subtask to have a `polygon` mode.
407+
408+
### `increase_brush_size_keybind`
409+
Keybind to increase the brush size. Default is `]`. Requires the active subtask to have a `polygon` mode.
410+
411+
### `decrease_brush_size_keybind`
412+
Keybind to decrease the brush size. Default is `[`. Requires the active subtask to have a `polygon` mode.
413+
414+
### `n_annos_per_canvas`
415+
The number of annotations to render on a single canvas. Default is `100`. Increasing this number may improve performance for jobs with a large number of annotations.
416+
378417
379418
## Display Utility Functions
380419

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented here.
55
## [unreleased]
66

77
Nothing yet.
8+
## [0.13.0] - Sept 26th, 2024
9+
- Fix bug where the `filter_annotations_on_load = true` option would not work as expected.
10+
- The `keypoint_slider_default_value` option was not being properly multiplied by 100 internally.
11+
- Move several config argument defaults into the configuration class instead of in the ULabel constructor.
12+
- Add `get_allowed_toolbox_item_enum()` static method to ULabel.
13+
#### Breaking Changes
14+
- Changed default for `filter_annotations_on_load` from `false` to `true`.
15+
- Deprecated the `default_toolbox_item_order` argument in the ULabel constructor. Use `toolbox_order` instead.
16+
- Deprecated `config_data` argument in the ULabel constructor. Instead, pass all configuration options as keyword arguments directly to the ULabel constructor.
17+
- For now, the `config_data` argument will still work, but may be removed in a future release.
818

919
## [0.12.5] - Sept 26th, 2024
1020
- Fix release workflow using actions on `node` 16, which is now deprecated.

demo/multi-class.html

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
}
8181
};
8282

83+
const AllowedToolboxItem = ULabel.get_allowed_toolbox_item_enum();
8384
// Initial ULabel configuration
8485
let ulabel = new ULabel({
8586
"container_id": "container",
@@ -106,26 +107,6 @@
106107
"color": "green",
107108
"row_number": 1,
108109
},
109-
// {
110-
// "name": "Submit",
111-
// "hook": on_submit,
112-
// "size_factor": 0.9,
113-
// "row_number": 2,
114-
// },
115-
// {
116-
// "name": "Reject",
117-
// "hook": () => { console.log("Reject"); },
118-
// "size_factor": 0.9,
119-
// "color": "red",
120-
// "row_number": 2,
121-
// },
122-
// {
123-
// "name": "Approve",
124-
// "hook": () => { console.log("Approve"); },
125-
// "size_factor": 0.9,
126-
// "color": "green",
127-
// "row_number": 2,
128-
// },
129110
{
130111
"name": "Skip",
131112
"hook": () => { console.log("Skip"); },
@@ -136,22 +117,19 @@
136117
],
137118
"subtasks": subtasks,
138119
"initial_line_size": 2,
139-
"config_data": {
140-
"default_toolbox_item_order": [
141-
7, // SubmitButtons
142-
0, // ModeSelect
143-
// 1, // ZoomPan
144-
2, // AnnotationResize
145-
3, // AnnotationID
146-
4, // Recolor Active
147-
5, // ClassCounter
148-
6, // KeypointSlider
149-
8, // FilterDistance
150-
// 9, // Brush
151-
],
152-
"toggle_brush_mode_keybind": "f",
153-
"create_bbox_on_initial_crop": "|",
154-
}
120+
"toolbox_order": [
121+
AllowedToolboxItem.SubmitButtons,
122+
AllowedToolboxItem.ModeSelect,
123+
AllowedToolboxItem.ZoomPan,
124+
AllowedToolboxItem.AnnotationID,
125+
AllowedToolboxItem.ClassCounter,
126+
AllowedToolboxItem.AnnotationResize,
127+
AllowedToolboxItem.KeypointSlider,
128+
AllowedToolboxItem.FilterDistance,
129+
AllowedToolboxItem.RecolorActive,
130+
],
131+
"toggle_brush_mode_keybind": "f",
132+
"create_bbox_on_initial_crop": "|",
155133
});
156134
// Wait for ULabel instance to finish initialization
157135
ulabel.init(function () {

demo/row-filtering-example.html

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313

1414
<!-- ULabel Usage -->
1515
<script>
16-
/* global $ */
17-
/* global ULabel */
18-
1916
$(window).on("load", function () {
2017

2118
function on_submit(annotations) {
@@ -718,7 +715,7 @@
718715
}
719716
]
720717

721-
let subtasks = {
718+
const subtasks = {
722719
"plants": {
723720
"display_name": "Plants",
724721
"classes": [
@@ -754,21 +751,36 @@
754751
}
755752
};
756753

754+
const AllowedToolboxItem = ULabel.get_allowed_toolbox_item_enum();
757755
// Initial ULabel configuration
758756
let ulabel = new ULabel({
759757
"container_id": "container",
760758
"image_data": "https://ulabel.s3.us-east-2.amazonaws.com/cs-demo-0.png",
761759
"username": "DemoUser",
762760
"submit_buttons": on_submit,
763761
"subtasks": subtasks,
764-
"toolbox_order": [0, 1, 3, 6, 8, 2, 7, 4, 5],
765-
"config_data": {
766-
"distance_filter_toolbox_item": {
767-
"show_overlay": true,
768-
// "disable_multi_class_mode": true,
769-
// "filter_during_polyline_move": false,
770-
}
771-
}
762+
"toolbox_order": [
763+
AllowedToolboxItem.ModeSelect,
764+
AllowedToolboxItem.ZoomPan,
765+
AllowedToolboxItem.AnnotationID,
766+
AllowedToolboxItem.ClassCounter,
767+
AllowedToolboxItem.KeypointSlider,
768+
AllowedToolboxItem.FilterDistance,
769+
AllowedToolboxItem.AnnotationResize,
770+
AllowedToolboxItem.SubmitButtons,
771+
AllowedToolboxItem.RecolorActive,
772+
],
773+
"distance_filter_toolbox_item": {
774+
"default_values": {
775+
"closest_row": {
776+
"distance": 200, // px
777+
}
778+
},
779+
"show_overlay": true,
780+
// "disable_multi_class_mode": true,
781+
// "filter_during_polyline_move": false,
782+
},
783+
"keypoint_slider_default_value": 0.2,
772784
});
773785
// Wait for ULabel instance to finish initialization
774786
ulabel.init(function () {

dist/ulabel.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ulabel.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.d.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ULabelAnnotation } from "./src/annotation";
2-
import { AllowedToolboxItem } from "./src/configuration";
2+
import { AllowedToolboxItem, Configuration } from "./src/configuration";
33
import { FilterDistanceOverlay } from "./src/overlays";
44
import { ULabelSubtask } from "./src/subtask";
55
import { Toolbox } from "./src/toolbox";
@@ -150,12 +150,22 @@ export type InitialCrop = {
150150
width: number;
151151
}
152152

153+
export type ImageData = {
154+
spacing: {
155+
x: number,
156+
y: number,
157+
z: number,
158+
units: string
159+
},
160+
frames: string[]
161+
}
162+
153163
export type ULabelSubtasks = { [key: string]: ULabelSubtask };
154164

155165
export class ULabel {
156166
subtasks: ULabelSubtask[];
157167
state: any;
158-
config: any;
168+
config: Configuration;
159169
toolbox: Toolbox;
160170
color_info: {[key: number]: string}
161171
valid_class_ids: number[];
@@ -203,6 +213,7 @@ export class ULabel {
203213
public toggle_delete_class_id_in_toolbox(): void;
204214
public change_brush_size(scale_factor: number): void;
205215
public remove_listeners(): void;
216+
static get_allowed_toolbox_item_enum(): AllowedToolboxItem;
206217
static process_classes(ulabel_obj: any, arg1: string, subtask_obj: any);
207218
static build_id_dialogs(ulabel_obj: any);
208219

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ulabel",
33
"description": "An image annotation tool.",
4-
"version": "0.12.5",
4+
"version": "0.13.0",
55
"main": "dist/ulabel.js",
66
"module": "dist/ulabel.js",
77
"scripts": {

0 commit comments

Comments
 (0)