From 13ee904e58ac3cebf5fbd79f3a94f33c8916ae8c Mon Sep 17 00:00:00 2001 From: Brian Wylie Date: Fri, 6 Dec 2024 12:23:19 -0700 Subject: [PATCH] changing the colorscale logic to be more robust --- applications/aws_dashboard/app.py | 2 +- src/sageworks/utils/theme_manager.py | 33 ++++++++++--------- .../components/plugins/scatter_plot.py | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/applications/aws_dashboard/app.py b/applications/aws_dashboard/app.py index 447d6c092..e9cc78c40 100644 --- a/applications/aws_dashboard/app.py +++ b/applications/aws_dashboard/app.py @@ -12,7 +12,7 @@ # import this file and use the server object as an ^entry-point^ into the Dash Application Code # Set up the Theme Manager -tm = ThemeManager(theme="minty_dark") +tm = ThemeManager(theme="quartz") css_files = tm.css_files() print(css_files) diff --git a/src/sageworks/utils/theme_manager.py b/src/sageworks/utils/theme_manager.py index 163e20d91..19e9541a8 100644 --- a/src/sageworks/utils/theme_manager.py +++ b/src/sageworks/utils/theme_manager.py @@ -2,7 +2,6 @@ import logging from pathlib import Path import plotly.io as pio -from plotly.colors import sequential import dash_bootstrap_components as dbc from flask import send_from_directory from sageworks.utils.config_manager import ConfigManager @@ -18,7 +17,7 @@ class ThemeManager: "dark": dbc.themes.DARKLY, "light": dbc.themes.FLATLY, "minty": dbc.themes.MINTY, - "minty_dark": dbc.themes.MINTY, + "quartz": dbc.themes.QUARTZ, } _dbc_css = "https://cdn.jsdelivr.net/gh/AnnMarieW/dash-bootstrap-templates/dbc.min.css" _available_themes = {} @@ -108,22 +107,24 @@ def current_theme(cls) -> str: return cls._current_theme_name @classmethod - def colorscale(cls) -> list[list[float | str]]: + def colorscale(cls, scale_type: str = "diverging") -> list[list[float | str]]: """Get the colorscale for the current theme.""" - # Map themes to Plotly's predefined colorscales - theme_to_colorscale = { - "dark": sequential.Turbo, # Bright and colorful for dark themes - "light": sequential.Viridis, # Bright and colorful for light themes - "minty": sequential.Greens, # Shades of green to match "minty" - "minty_dark": sequential.Darkmint, # Dark greens and teals for "minty_dark" - } - - # Return the colorscale for the current theme, default to Inferno - return theme_to_colorscale.get(cls._current_theme_name, sequential.Inferno) - - # All the dash-bootstrap-templates seem to use the same colorscale (Plasma) - # return cls._current_template["data"]["heatmapgl"][0]["colorscale"] + # We have 3 colorscale options (diverging, sequential, and sequentialminus) + color_scales = cls._current_template["layout"]["colorscale"] + if scale_type in color_scales: + return color_scales[scale_type] + else: + # Use the default colorscale (first one in the dictionary) + try: + first_colorscale_name = list(color_scales.keys())[0] + backup_colorscale = color_scales[first_colorscale_name] + cls._log.warning(f"Color scale '{scale_type}' not found for template '{cls._current_theme_name}'.") + cls._log.warning(f"Using color scale '{backup_colorscale}' instead.") + return backup_colorscale + except IndexError: + cls._log.error(f"No color scales found for template '{cls._current_theme_name}'.") + return [] @classmethod def css_files(cls) -> list[str]: diff --git a/src/sageworks/web_interface/components/plugins/scatter_plot.py b/src/sageworks/web_interface/components/plugins/scatter_plot.py index 1ed7bf57f..74940b64b 100644 --- a/src/sageworks/web_interface/components/plugins/scatter_plot.py +++ b/src/sageworks/web_interface/components/plugins/scatter_plot.py @@ -267,4 +267,4 @@ def update_graph(x_value, y_value, color_value, regression_line): from sageworks.web_interface.components.plugin_unit_test import PluginUnitTest # Run the Unit Test on the Plugin - PluginUnitTest(ScatterPlot, theme="light").run() + PluginUnitTest(ScatterPlot, theme="dark").run()