Skip to content

Commit

Permalink
Update html.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-migas committed Nov 21, 2024
1 parent d71ec59 commit 0903a5a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/spec_utils/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def make_peaks_spectrum(
window: float = 0.1,
normalize: bool = False,
n_cols: int = 3,
style="plotly_white",
width: int = 400,
height: int = 350,
) -> go.Figure:
"""Export Plotly mass spectrum as HTML document."""
import plotly.graph_objects as go
Expand All @@ -57,6 +60,8 @@ def make_peaks_spectrum(
n_peaks = len(peaks)
n_rows = (n_peaks + n_cols - 1) // n_cols
colors = ["blue", "red", "green", "orange", "purple", "brown", "pink", "gray", "olive", "cyan"]
if len(spectra) > len(colors):
colors = [f"hsl({360 * i / len(spectra)}, 100%, 50%)" for i in range(len(spectra))]

# Create a figure
fig = make_subplots(rows=n_rows, cols=n_cols, subplot_titles=[f"Peak {peaks[i]:.3f}" for i in range(n_peaks)])
Expand Down Expand Up @@ -87,9 +92,9 @@ def make_peaks_spectrum(
title="Mass Spectrum",
xaxis_title="m/z",
yaxis_title="Intensity",
template="plotly_white",
width=50 + 400 * n_cols, # Adjust width here
height=350 * n_rows, # Adjust height here
template=style,
width=50 + width * n_cols, # Adjust width here
height=height * n_rows, # Adjust height here
hoverlabel={"namelength": -1},
)
return fig
Expand Down

0 comments on commit 0903a5a

Please sign in to comment.