Skip to content

Commit

Permalink
dark altair hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhsmit committed Nov 8, 2024
1 parent 2b42045 commit 0163d6a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dont_fret/web/bursts/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ def make_overlay_chart(

@solara.component
def SelectionChart(chart: alt.Chart | alt.LayerChart, on_selection):
jchart = alt.JupyterChart.element(chart=chart, embed_options={"actions": False}) # type: ignore
dark_effective = solara.lab.use_dark_effective()
if dark_effective:
options = {"actions": False, "theme": "dark"}
else:
options = {"actions": False}
jchart = alt.JupyterChart.element(chart=chart, embed_options=options) # type: ignore

def bind():
widget = cast(alt.JupyterChart, solara.get_widget(jchart))
Expand Down
2 changes: 2 additions & 0 deletions dont_fret/web/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from dont_fret.web.bursts import BurstPage
from dont_fret.web.components import Snackbar
from dont_fret.web.home import HomePage
from dont_fret.web.methods import use_dark_altair
from dont_fret.web.models import BurstColorList
from dont_fret.web.state import disable_burst_page, disable_trace_page
from dont_fret.web.trace import TracePage
Expand Down Expand Up @@ -67,6 +68,7 @@ def Page():
password = solara.use_reactive("")

solara.Style(SCRIPT_PATH / "style.css")
use_dark_altair()

def initialize():
# TODO burst settings as listStore
Expand Down
14 changes: 14 additions & 0 deletions dont_fret/web/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,29 @@
from operator import and_
from typing import Literal, Optional, TypedDict, Union

import altair as alt
import numpy as np
import polars as pl
import solara
import solara.lab

from dont_fret.config.config import BurstColor
from dont_fret.fileIO import PhotonFile
from dont_fret.models import Bursts, PhotonData
from dont_fret.web.models import BurstFilterItem, BurstNode, FRETNode, PhotonNode


def use_dark_altair():
dark_effective = solara.lab.use_dark_effective()
dark_effective_previous = solara.use_previous(dark_effective)
if dark_effective != dark_effective_previous:
if dark_effective:
alt.themes.enable("dark")

else:
alt.themes.enable("default")


def make_burst_dataframe(
bursts: list[Bursts], names: Optional[list[str]], name_column="filename"
) -> pl.DataFrame:
Expand Down

0 comments on commit 0163d6a

Please sign in to comment.