Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions api_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class ULabel({
reset_zoom_keybind: string,
show_full_image_keybind: string,
create_point_annotation_keybind: string,
default_annotation_size: number,
delete_annotation_keybind: string,
keypoint_slider_default_value: number,
filter_annotations_on_load: boolean,
Expand Down Expand Up @@ -316,7 +315,7 @@ In some cases, you may want the annotations to render at a higher or lower resol

### `initial_line_size`

The line width with which new annotations are drawn initially. Units are pixels in the underlying image. When this value is not included, the default value of `4` is used.
The line width with which new annotations are drawn initially. Units are pixels in the underlying image. When this value is not included, the default value of `5` is used.

### `anno_scaling_mode`

Expand Down Expand Up @@ -433,9 +432,6 @@ Keybind to set the zoom level to show the full image. Default is `shift+r`.
### `create_point_annotation_keybind`
Keybind to create a point annotation at the mouse location. Default is `c`. Requires the active subtask to have a `point` mode.

### `default_annotation_size`
Default size of annotations in pixels. Default is `6`.

### `delete_annotation_keybind`
Keybind to delete the annotation that the mouse is hovering over. Default is `d`.

Expand Down Expand Up @@ -485,7 +481,10 @@ Keybind to increment the annotation size for the current subtask. Default is `=`
Keybind to decrement the annotation size for the current subtask. Default is `-`.

### `annotation_vanish_keybind`
Keybind to toggle vanish mode for annotations in the current subtask (lowercase toggles current subtask, uppercase toggles all subtasks). Default is `v`.
Keybind to toggle vanish mode for annotations in the current subtask. Default is `v`.

### `annotation_vanish_all_keybind`
Keybind to toggle vanish mode for all subtasks. Default is `shift+v`

### `fly_to_max_zoom`
Maximum zoom factor used when flying-to an annotation. Default is `10`, value must be > `0`.
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export class ULabel {
// TODO (joshua-dean): this is never assigned, is it used?
demo_canvas_context: CanvasRenderingContext2D;
edited: boolean;
all_subtasks_vanished: boolean;
};

config: Configuration;
Expand Down
6 changes: 3 additions & 3 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class Configuration {
public allow_soft_id: boolean = false;
public default_annotation_color: string = "#fa9d2a";
public username: string = "ULabelUser";
public initial_line_size: number = 4;
public initial_line_size: number = 5;

// ID Dialog config
public cl_opacity: number = 0.4;
Expand Down Expand Up @@ -196,8 +196,6 @@ export class Configuration {

public create_point_annotation_keybind: string = "c";

public default_annotation_size: number = 6;

public delete_annotation_keybind: string = "d";

public keypoint_slider_default_value: number;
Expand Down Expand Up @@ -228,6 +226,8 @@ export class Configuration {

public annotation_vanish_keybind: string = "v";

public annotation_vanish_all_keybind: string = "shift+v";

public fly_to_next_annotation_keybind: string = "tab";

public fly_to_previous_annotation_keybind: string = "shift+tab";
Expand Down
26 changes: 18 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export class ULabel {
if (
(cand.line_size === undefined) || (cand.line_size == null)
) {
cand.line_size = ul.get_initial_line_size();
cand.line_size = ul.config.initial_line_size;
}

// Add created by attribute if there is none
Expand Down Expand Up @@ -446,9 +446,11 @@ export class ULabel {
starting_complex_polygon: false,
is_in_brush_mode: false,
is_in_erase_mode: false,
is_vanished: false,
edit_candidate: null,
move_candidate: null,
fly_to_idx: null,
line_size: ul.config.initial_line_size,

// Rendering context
front_context: null,
Expand Down Expand Up @@ -520,7 +522,7 @@ export class ULabel {
annotation_meta: arguments[6] ?? {},
px_per_px: arguments[7] ?? 1,
initial_crop: arguments[8] ?? null,
initial_line_size: arguments[9] ?? 4,
initial_line_size: arguments[9] ?? 5,
config_data: arguments[10] ?? null,
toolbox_order: arguments[11] ?? null,
};
Expand Down Expand Up @@ -584,7 +586,6 @@ export class ULabel {
// Global annotation state (subtasks also maintain an annotation state)
current_subtask: null, // The key of the current subtask
last_brush_stroke: null,
line_size: this.config.initial_line_size,
anno_scaling_mode: this.config.anno_scaling_mode,

// Keybind editing state
Expand All @@ -593,6 +594,7 @@ export class ULabel {
// Renderings state
demo_canvas_context: null,
edited: false,
all_subtasks_vanished: false,
};

// Create a place on ulabel to store resize observer objects
Expand Down Expand Up @@ -1906,6 +1908,10 @@ export class ULabel {
redraw_all_annotations_in_annotation_context(canvas_id, subtask, offset = null, annotation_ids_to_offset = null) {
// Clear the canvas
this.clear_annotation_canvas(canvas_id, subtask);

// If the subtask is vanished, don't draw anything
if (this.subtasks[subtask]["state"]["is_vanished"]) return;

// Handle redraw of each annotation in the context
for (const annid of this.subtasks[subtask]["state"]["annotation_contexts"][canvas_id]["annotation_ids"]) {
// Only draw with offset if the annotation is in the list of annotations to offset, or if the list is null
Expand Down Expand Up @@ -2994,7 +3000,7 @@ export class ULabel {
spatial_payload: spatial_payload,
classification_payloads: this.get_init_id_payload(spatial_type),
text_payload: "",
line_size: this.get_initial_line_size(),
line_size: this.get_subtask_line_size(),
canvas_id: this.get_init_canvas_context_id(unique_id),
};

Expand Down Expand Up @@ -3282,7 +3288,7 @@ export class ULabel {
if ("line_size" in annotation && annotation["line_size"] !== null) {
line_size = annotation["line_size"];
} else {
line_size = this.get_initial_line_size();
line_size = this.get_subtask_line_size();
}

// fixed: line size is independent of zoom level
Expand All @@ -3297,8 +3303,11 @@ export class ULabel {
return line_size;
}

get_initial_line_size() {
return this.state.line_size;
get_subtask_line_size(subtask_key = null) {
if (subtask_key === null) {
subtask_key = this.get_current_subtask_key();
}
return this.subtasks[subtask_key]["state"]["line_size"];
}

// Action Stream Events
Expand Down Expand Up @@ -3394,7 +3403,7 @@ export class ULabel {

if (redo_payload === null) {
annotation_id = this.make_new_annotation_id();
line_size = this.get_initial_line_size();
line_size = this.get_subtask_line_size(subtask_key);
annotation_mode = current_subtask["state"]["annotation_mode"];
[gmx, gmy] = this.get_image_aware_mouse_x_y(mouse_event);
init_spatial = this.get_init_spatial(gmx, gmy, annotation_mode, mouse_event);
Expand Down Expand Up @@ -4827,6 +4836,7 @@ export class ULabel {
// Don't show any dialogs when currently drawing/editing an annotation,
// And hide just edit dialogs when moving
if (
current_subtask["state"]["is_vanished"] ||
current_subtask["state"]["is_in_progress"] ||
current_subtask["state"]["starting_complex_polygon"] ||
current_subtask["state"]["is_in_brush_mode"] ||
Expand Down
47 changes: 47 additions & 0 deletions src/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { ULabel } from "..";
import { NightModeCookie } from "./cookies";
import { DELETE_CLASS_ID, DELETE_MODES, NONSPATIAL_MODES } from "./annotation";
import { set_local_storage_item } from "./utilities";
import { AnnotationResizeItem, SMALL_ANNOTATION_SIZE, LARGE_ANNOTATION_SIZE, INCREMENT_ANNOTATION_SIZE } from "./toolbox";

const ULABEL_NAMESPACE = ".ulabel";

Expand Down Expand Up @@ -314,6 +315,52 @@ function handle_keydown_event(
ulabel.fly_to_next_annotation(-1, ulabel.config.fly_to_max_zoom);
return false;
}

// Handle annotation resizing keybinds

if (event_matches_keybind(keydown_event, ulabel.config.annotation_vanish_all_keybind)) {
keydown_event.preventDefault();
// Toggle global vanish flag
ulabel.state.all_subtasks_vanished = !ulabel.state.all_subtasks_vanished;

// For each subtask, toggle vanished state if needed
for (const subtask_key in ulabel.subtasks) {
if (ulabel.subtasks[subtask_key].state.is_vanished !== ulabel.state.all_subtasks_vanished) {
AnnotationResizeItem.toggle_subtask_vanished(ulabel, subtask_key);
}
}
return false;
}

if (event_matches_keybind(keydown_event, ulabel.config.annotation_vanish_keybind)) {
keydown_event.preventDefault();
AnnotationResizeItem.toggle_subtask_vanished(ulabel, ulabel.get_current_subtask_key());
return false;
}

if (event_matches_keybind(keydown_event, ulabel.config.annotation_size_small_keybind)) {
keydown_event.preventDefault();
AnnotationResizeItem.update_annotation_size(ulabel, ulabel.get_current_subtask_key(), SMALL_ANNOTATION_SIZE);
return false;
}

if (event_matches_keybind(keydown_event, ulabel.config.annotation_size_large_keybind)) {
keydown_event.preventDefault();
AnnotationResizeItem.update_annotation_size(ulabel, ulabel.get_current_subtask_key(), LARGE_ANNOTATION_SIZE);
return false;
}

if (event_matches_keybind(keydown_event, ulabel.config.annotation_size_minus_keybind)) {
keydown_event.preventDefault();
AnnotationResizeItem.update_annotation_size(ulabel, ulabel.get_current_subtask_key(), -INCREMENT_ANNOTATION_SIZE, true);
return false;
}

if (event_matches_keybind(keydown_event, ulabel.config.annotation_size_plus_keybind)) {
keydown_event.preventDefault();
AnnotationResizeItem.update_annotation_size(ulabel, ulabel.get_current_subtask_key(), INCREMENT_ANNOTATION_SIZE, true);
return false;
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/subtask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ export class ULabelSubtask {
starting_complex_polygon: boolean;
is_in_brush_mode: boolean;
is_in_erase_mode: boolean;
is_vanished: boolean;
visible_dialogs: {
[key: string]: ULabelDialogPosition;
};
spatial_type: ULabelSpatialType;
fly_to_idx: number | null;
line_size: number;
};

constructor(
Expand Down
Loading