diff --git a/assets/functions.js b/assets/functions.js index 0309f5e6..cf5b5666 100644 --- a/assets/functions.js +++ b/assets/functions.js @@ -1,7 +1,10 @@ -function changeFilters(js_path, brightness, contrast) { +function changeFilters(js_path, brightness, contrast, hue_rotate) { const element = document.querySelector(js_path); if (element) { - // Apply the new brightness value to the element - element.style.filter = `brightness(${brightness}%) contrast(${contrast}%)`; + if (hue_rotate == 0) { + element.style.filter = `brightness(${brightness}%) contrast(${contrast}%)`; + } else { + element.style.filter = `brightness(${brightness}%) contrast(${contrast}%) sepia(100%) hue-rotate(${hue_rotate}deg)`; + } } } \ No newline at end of file diff --git a/callbacks/control_bar.py b/callbacks/control_bar.py index 5e0b1c83..48527c97 100644 --- a/callbacks/control_bar.py +++ b/callbacks/control_bar.py @@ -121,16 +121,17 @@ def annotation_visibility(checked, store, figure, image_idx): clientside_callback( """ - function dash_filters_clientside(brightness, contrast) { + function dash_filters_clientside(brightness, contrast, hue_rotate) { console.log(brightness, contrast) js_path = "#image-viewer > div.js-plotly-plot > div > div > svg:nth-child(1) > g.cartesianlayer > g > g.plot > g" - changeFilters(js_path, brightness, contrast) + changeFilters(js_path, brightness, contrast, hue_rotate) return "" } """, Output("dummy-output", "children", allow_duplicate=True), Input("figure-brightness", "value"), Input("figure-contrast", "value"), + Input("figure-hue-rotate", "value"), prevent_initial_call=True, ) @@ -138,10 +139,12 @@ def annotation_visibility(checked, store, figure, image_idx): @callback( Output("figure-brightness", "value", allow_duplicate=True), Output("figure-contrast", "value", allow_duplicate=True), + Output("figure-hue-rotate", "value", allow_duplicate=True), Input("filters-reset", "n_clicks"), prevent_initial_call=True, ) def reset_filters(n_clicks): default_brightness = 100 default_contrast = 100 - return default_brightness, default_contrast + default_color = 0 + return default_brightness, default_contrast, default_color diff --git a/components/control_bar.py b/components/control_bar.py index f6f2a172..a9878240 100644 --- a/components/control_bar.py +++ b/components/control_bar.py @@ -83,7 +83,25 @@ def layout(): color="gray", size="sm", ), - dmc.Space(h=10), + dmc.Text("Color", size="sm"), + dmc.Slider( + id=f"figure-hue-rotate", + value=0, + min=0, + max=360, + step=1, + color="gray", + size="sm", + styles={"label": {"display": "none"}}, + marks=[ + {"value": 0, "label": "Original"}, + {"value": 80, "label": "Green"}, + {"value": 160, "label": "Blue"}, + {"value": 240, "label": "Purple"}, + {"value": 320, "label": "Red"}, + ], + ), + dmc.Space(h=35), dmc.ActionIcon( dmc.Tooltip( label="Reset filters", @@ -98,8 +116,6 @@ def layout(): variant="filled", id="filters-reset", n_clicks=0, - mb=10, - ml="auto", style={"margin": "auto"}, ), ]