Skip to content

Commit bc458de

Browse files
authored
refactor: replace TooltipManager usage with attachTooltip function (#198)
This pull request refactors the tooltip management system by replacing the `TooltipManager` singleton class with individual functions. The changes involve updating all instances where `TooltipManager` methods were used to use the new functions instead. This refactor aims to simplify the code and improve maintainability.
1 parent 2e4b550 commit bc458de

File tree

16 files changed

+149
-142
lines changed

16 files changed

+149
-142
lines changed

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GlobalContext } from "./context";
2-
import { TooltipManager } from "./graphics/renderables/tooltip_manager";
2+
import { updateTooltipsState } from "./graphics/renderables/tooltip_manager";
33
import { deselectElement } from "./types/viewportManager";
44
import { Colors } from "./utils/utils";
55

@@ -236,7 +236,7 @@ export class ConfigModal {
236236
if (this.enableTooltipsSwitch) {
237237
this.enableTooltips = this.tempEnableTooltips; // Save the temporary value
238238
this.ctx.change_enable_tooltips(this.enableTooltips); // Update the GlobalContext
239-
TooltipManager.getInstance().updateTooltipsState(); // Update tooltips state in the app
239+
updateTooltipsState(); // Update tooltips state in the app
240240
}
241241

242242
console.log(

src/graphics/basic_components/button.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TooltipManager } from "../renderables/tooltip_manager";
1+
import { attachTooltip } from "../renderables/tooltip_manager";
22

33
export interface ButtonProps {
44
text: string; // Button text
@@ -24,7 +24,7 @@ export class Button {
2424
}
2525

2626
if (tooltip) {
27-
TooltipManager.getInstance().attachTooltip(this.button, tooltip);
27+
attachTooltip(this.button, tooltip);
2828
}
2929

3030
this.button.onclick = onClick; // Assign the click handler

src/graphics/basic_components/dropdown.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CSS_CLASSES } from "../../utils/constants/css_constants";
2-
import { TooltipManager } from "../renderables/tooltip_manager";
2+
import { attachTooltip } from "../renderables/tooltip_manager";
33
import { Label } from "./label";
44

55
export interface DropdownOption {
@@ -57,7 +57,7 @@ export class Dropdown {
5757
? `Select ${default_text}`
5858
: "Select option"; // Default text or fallback
5959
if (tooltip) {
60-
TooltipManager.getInstance().attachTooltip(this.selected, tooltip);
60+
attachTooltip(this.selected, tooltip);
6161
}
6262
dropdown.appendChild(this.selected);
6363

@@ -96,7 +96,7 @@ export class Dropdown {
9696
const option = document.createElement("div");
9797
option.classList.add(CSS_CLASSES.DROPDOWN_OPTION);
9898
option.textContent = optionData.text;
99-
TooltipManager.getInstance().attachTooltip(option, optionData.text, true);
99+
attachTooltip(option, optionData.text, true);
100100

101101
// Set up click event for option selection
102102
option.onclick = (e) => {

src/graphics/basic_components/label.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TooltipManager } from "../renderables/tooltip_manager";
1+
import { attachTooltip } from "../renderables/tooltip_manager";
22

33
export class Label {
44
private labelElement: HTMLLabelElement;
@@ -12,7 +12,7 @@ export class Label {
1212
}
1313

1414
if (tooltip) {
15-
TooltipManager.getInstance().attachTooltip(this.labelElement, tooltip); // Attach tooltip
15+
attachTooltip(this.labelElement, tooltip); // Attach tooltip
1616
}
1717
}
1818

src/graphics/basic_components/parameter_editor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CSS_CLASSES } from "../../utils/constants/css_constants";
22
import { ALERT_MESSAGES } from "../../utils/constants/alert_constants";
33
import { showError, showSuccess } from "../renderables/alert_manager";
4-
import { TooltipManager } from "../renderables/tooltip_manager";
4+
import { attachTooltip } from "../renderables/tooltip_manager";
55

66
export interface EditableParameter {
77
label: string;
@@ -35,7 +35,7 @@ export class ParameterEditor {
3535
const labelElement = document.createElement("label");
3636
labelElement.textContent = label;
3737
labelElement.className = CSS_CLASSES.PARAMETER_EDITOR_LABEL;
38-
TooltipManager.getInstance().attachTooltip(labelElement, label);
38+
attachTooltip(labelElement, label);
3939

4040
// Create the input
4141
const input = document.createElement("input");

src/graphics/basic_components/slider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CSS_CLASSES } from "../../utils/constants/css_constants";
2-
import { TooltipManager } from "../renderables/tooltip_manager";
2+
import { attachTooltip } from "../renderables/tooltip_manager";
33

44
export interface SliderProps {
55
label: string; // Label displayed above the slider
@@ -22,7 +22,7 @@ export class Slider {
2222
const label = document.createElement("div");
2323
label.textContent = props.label;
2424
label.classList.add(CSS_CLASSES.SLIDER_LABEL);
25-
TooltipManager.getInstance().attachTooltip(label, props.label);
25+
attachTooltip(label, props.label);
2626

2727
this.valueDisplay = document.createElement("div");
2828
this.valueDisplay.textContent = `${props.initialValue}x`;

src/graphics/basic_components/table.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CSS_CLASSES } from "../../utils/constants/css_constants";
2-
import { TooltipManager } from "../renderables/tooltip_manager";
2+
import { attachTooltip } from "../renderables/tooltip_manager";
33
import { Button } from "./button";
44

55
export interface TableOptions {
@@ -49,7 +49,7 @@ export class Table {
4949
}
5050

5151
// Assign the tooltip
52-
TooltipManager.getInstance().attachTooltip(th, tooltip);
52+
attachTooltip(th, tooltip);
5353

5454
headerRow.appendChild(th);
5555
});

src/graphics/basic_components/text_info.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CSS_CLASSES } from "../../utils/constants/css_constants";
2-
import { TooltipManager } from "../renderables/tooltip_manager";
2+
import { attachTooltip } from "../renderables/tooltip_manager";
33

44
export interface InfoField {
55
key: string;
@@ -21,7 +21,7 @@ export class TextInfo {
2121
titleElement.textContent = this.title;
2222
titleElement.classList.add(CSS_CLASSES.INFO_TITLE);
2323
this.container.appendChild(titleElement);
24-
TooltipManager.getInstance().attachTooltip(titleElement, this.title); // Attach tooltip to the title
24+
attachTooltip(titleElement, this.title); // Attach tooltip to the title
2525
}
2626

2727
this.list = document.createElement("ul");
@@ -81,7 +81,7 @@ export class TextInfo {
8181
keyElement.style.display = CSS_CLASSES.BLOCK;
8282
keyElement.style.textAlign = "center";
8383
if (tooltip) {
84-
TooltipManager.getInstance().attachTooltip(keyElement, tooltip);
84+
attachTooltip(keyElement, tooltip);
8585
}
8686

8787
// Create a container to wrap the JSON content
@@ -120,7 +120,7 @@ export class TextInfo {
120120
keyElement.textContent = `${key}`;
121121
keyElement.classList.add(CSS_CLASSES.DETAIL_KEY);
122122
if (tooltip) {
123-
TooltipManager.getInstance().attachTooltip(keyElement, tooltip);
123+
attachTooltip(keyElement, tooltip);
124124
}
125125

126126
const valueElement = document.createElement("span");

src/graphics/basic_components/toggle_button.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TooltipManager } from "../renderables/tooltip_manager";
1+
import { attachTooltip } from "../renderables/tooltip_manager";
22

33
export interface ToggleButtonProps {
44
text: string; // Default button text (used if textOn/textOff are not provided)
@@ -29,7 +29,7 @@ export class ToggleButton {
2929
}
3030

3131
if (tooltip) {
32-
TooltipManager.getInstance().attachTooltip(this.button, tooltip);
32+
attachTooltip(this.button, tooltip);
3333
}
3434

3535
this.button.onclick = () => {

src/graphics/components/labeled_progress_bar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CSS_CLASSES } from "../../utils/constants/css_constants";
22
import { ProgressBar } from "../basic_components/progress_bar";
3-
import { TooltipManager } from "../renderables/tooltip_manager";
3+
import { attachTooltip } from "../renderables/tooltip_manager";
44

55
export class LabeledProgressBar {
66
private container: HTMLElement;
@@ -21,7 +21,7 @@ export class LabeledProgressBar {
2121
this.labelElement = document.createElement("div");
2222
this.labelElement.className = CSS_CLASSES.CENTRAL_LABEL;
2323
this.labelElement.textContent = label;
24-
TooltipManager.getInstance().attachTooltip(this.labelElement, label);
24+
attachTooltip(this.labelElement, label);
2525

2626
// Create the progress bar
2727
this.progressBar = new ProgressBar({ current, max });

0 commit comments

Comments
 (0)