Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/subtask getters #186

Merged
merged 11 commits into from
Oct 2, 2024
8 changes: 8 additions & 0 deletions api_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@ Display utilities are provided for a constructed `ULabel` object.

*(string) => string* -- Changes the background color for the annotation box. Returns the old color.

### `get_current_subtask_key()`

*() => string* -- Returns the key of the current subtask.

### `get_current_subtask()`

*() => object* -- Returns the current subtask object.

### `get_annotations(subtask)`

*(string) => array* -- Gets the current list of annotations within the provided subtask.
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to this project will be documented here.

Nothing yet.

## [0.14.0] - Oct 1st, 2024
- Add `.get_current_subtask_key()` and `.get_current_subtask()` utility methods
- Updated almost all internal methods to use these utility methods

## [0.13.1] - Sept 30th, 2024
- Remove unecessary and confusing default in global edit dialog
- Squash `active_annotation` into `edit_candidate` in subtask state
Expand Down
2 changes: 1 addition & 1 deletion dist/ulabel.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ulabel.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export class ULabel {
public show_whole_image(): void;
public swap_frame_image(new_src: string, frame?: number): string;
public swap_anno_bg_color(new_bg_color: string): string;
public get_current_subtask_key(): string;
public get_current_subtask(): ULabelSubtask;
public get_annotations(subtask: ULabelSubtask): ULabelAnnotation[];
public set_annotations(annotations: ULabelAnnotation[], subtask: ULabelSubtask);
public set_saved(saved: boolean);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ulabel",
"description": "An image annotation tool.",
"version": "0.13.1",
"version": "0.14.0",
"main": "dist/ulabel.js",
"module": "dist/ulabel.js",
"scripts": {
Expand Down
562 changes: 291 additions & 271 deletions src/index.js

Large diffs are not rendered by default.

27 changes: 13 additions & 14 deletions src/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class Toolbox {
public get_toolbox_tabs(ulabel: ULabel): string{
let ret: string = "";
for (const st_key in ulabel.subtasks) {
let selected = st_key == ulabel.state["current_subtask"];
let selected = st_key == ulabel.get_current_subtask_key();
let subtask = ulabel.subtasks[st_key];
let current_tab = new ToolboxTab(
[],
Expand Down Expand Up @@ -336,26 +336,26 @@ export class ModeSelectionToolboxItem extends ToolboxItem {

// Grab the current target and the current subtask
let target_jq = $(e.currentTarget);
let current_subtask = ulabel.state["current_subtask"];
let current_subtask = ulabel.get_current_subtask();

// Check if button clicked is already selected, or if creation of a new annotation is in progress
if (target_jq.hasClass("sel") || ulabel.subtasks[current_subtask]["state"]["is_in_progress"]) return;
if (target_jq.hasClass("sel") || current_subtask["state"]["is_in_progress"]) return;

// Get the new mode and set it to ulabel's current mode
let new_mode = target_jq.attr("id").split("--")[1];
ulabel.subtasks[current_subtask]["state"]["annotation_mode"] = new_mode;
current_subtask["state"]["annotation_mode"] = new_mode;

// Show the BrushToolboxItem when polygon mode is selected
if (new_mode === "polygon") {
BrushToolboxItem.show_brush_toolbox_item();
} else {
BrushToolboxItem.hide_brush_toolbox_item();
// Turn off erase mode if it's on
if (ulabel.subtasks[current_subtask]["state"]["is_in_erase_mode"]) {
if (current_subtask["state"]["is_in_erase_mode"]) {
ulabel.toggle_erase_mode(e);
}
// Turn off brush mode if it's on
if (ulabel.subtasks[current_subtask]["state"]["is_in_brush_mode"]) {
if (current_subtask["state"]["is_in_brush_mode"]) {
ulabel.toggle_brush_mode(e);
}
}
Expand All @@ -375,8 +375,7 @@ export class ModeSelectionToolboxItem extends ToolboxItem {
$(document).on("keypress.ulabel", (e) => {

// If creation of a new annotation is in progress, don't change the mode
let current_subtask = ulabel.state["current_subtask"];
if (ulabel.subtasks[current_subtask]["state"]["is_in_progress"]) return;
if (ulabel.get_current_subtask()["state"]["is_in_progress"]) return;

// Check if the correct key was pressed
if (e.key == ulabel.config.toggle_annotation_mode_keybind) {
Expand Down Expand Up @@ -629,7 +628,7 @@ export class BrushToolboxItem extends ToolboxItem {

public after_init() {
// Only show BrushToolboxItem if the current mode is polygon
if (this.ulabel.subtasks[this.ulabel.state["current_subtask"]].state["annotation_mode"] !== "polygon") {
if (this.ulabel.get_current_subtask().state["annotation_mode"] === "polygon") {
BrushToolboxItem.hide_brush_toolbox_item()
}
}
Expand Down Expand Up @@ -1138,7 +1137,7 @@ export class ClassCounterToolboxItem extends ToolboxItem {

public redraw_update(ulabel: ULabel) {
this.update_toolbox_counter(
ulabel.subtasks[ulabel.state["current_subtask"]],
ulabel.get_current_subtask(),
);
$("#" + ulabel.config["toolbox_id"] + " div.toolbox-class-counter").html(this.inner_HTML);
}
Expand Down Expand Up @@ -1266,9 +1265,10 @@ export class AnnotationResizeItem extends ToolboxItem {

private add_event_listeners() {
$(document).on("click.ulabel", ".annotation-resize-button", (event) => {

// Get the current subtask
const current_subtask_key = this.ulabel.state["current_subtask"];
const current_subtask = this.ulabel.subtasks[current_subtask_key];
const current_subtask_key = this.ulabel.get_current_subtask_key();
const current_subtask = this.ulabel.get_current_subtask();

// Get the clicked button
const button = $(event.currentTarget)
Expand All @@ -1284,8 +1284,7 @@ export class AnnotationResizeItem extends ToolboxItem {

$(document).on("keydown.ulabel", (event) => {
// Get the current subtask
const current_subtask_key = this.ulabel.state["current_subtask"];
const current_subtask = this.ulabel.subtasks[current_subtask_key];
const current_subtask = this.ulabel.get_current_subtask();

switch(event.key) {
case this.keybind_configuration.annotation_vanish.toUpperCase():
Expand Down
2 changes: 1 addition & 1 deletion src/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const ULABEL_VERSION = "0.13.1";
export const ULABEL_VERSION = "0.14.0";