Post code clean-up, before attempt to upgrade controls to FigureWidgets
This commit is contained in:
@@ -4,6 +4,7 @@ Contains all operations for creating charts, graphs and visual effects.
|
||||
from PyQt6.QtWidgets import QWidget
|
||||
import plotly
|
||||
from plotly.graph_objects import Figure
|
||||
from plotly.graph_objs import FigureWidget
|
||||
import pandas as pd
|
||||
from frontend.widgets.functions import select_save_file
|
||||
|
||||
@@ -35,7 +36,6 @@ class CustomFigure(Figure):
|
||||
output = select_save_file(obj=parent, default_name=group_name, extension="xlsx")
|
||||
self.df.to_excel(output.absolute().__str__(), engine="openpyxl", index=False)
|
||||
|
||||
|
||||
def to_html(self) -> str:
|
||||
"""
|
||||
Creates final html code from plotly
|
||||
|
||||
@@ -3,14 +3,13 @@ Functions for constructing irida controls graphs using plotly.
|
||||
"""
|
||||
from datetime import date
|
||||
from pprint import pformat
|
||||
import plotly
|
||||
from typing import Generator
|
||||
import plotly.express as px
|
||||
import pandas as pd
|
||||
from PyQt6.QtWidgets import QWidget
|
||||
from . import CustomFigure
|
||||
import logging
|
||||
from tools import get_unique_values_in_df_column, divide_chunks
|
||||
from frontend.widgets.functions import select_save_file
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
|
||||
@@ -67,7 +66,6 @@ class IridaFigure(CustomFigure):
|
||||
)
|
||||
bar.update_traces(visible=ii == 0)
|
||||
self.add_traces(bar.data)
|
||||
# return generic_figure_markers(modes=modes, ytitle=ytitle)
|
||||
|
||||
def generic_figure_markers(self, modes: list = [], ytitle: str | None = None, months: int = 6):
|
||||
"""
|
||||
@@ -83,7 +81,7 @@ class IridaFigure(CustomFigure):
|
||||
"""
|
||||
if modes:
|
||||
ytitle = modes[0]
|
||||
# Creating visibles list for each mode.
|
||||
# logger.debug("Creating visibles list for each mode.")
|
||||
self.update_layout(
|
||||
xaxis_title="Submitted Date (* - Date parsed from fastq file creation date)",
|
||||
yaxis_title=ytitle,
|
||||
@@ -100,7 +98,6 @@ class IridaFigure(CustomFigure):
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
self.update_xaxes(
|
||||
rangeslider_visible=True,
|
||||
rangeselector=dict(
|
||||
@@ -109,7 +106,16 @@ class IridaFigure(CustomFigure):
|
||||
)
|
||||
assert isinstance(self, CustomFigure)
|
||||
|
||||
def make_plotly_buttons(self, months: int = 6):
|
||||
def make_plotly_buttons(self, months: int = 6) -> Generator[dict, None, None]:
|
||||
"""
|
||||
Creates html buttons to zoom in on date areas
|
||||
|
||||
Args:
|
||||
months (int, optional): Number of months of data given. Defaults to 6.
|
||||
|
||||
Yields:
|
||||
Generator[dict, None, None]: Button details.
|
||||
"""
|
||||
rng = [1]
|
||||
if months > 2:
|
||||
rng += [iii for iii in range(3, months, 3)]
|
||||
@@ -121,7 +127,7 @@ class IridaFigure(CustomFigure):
|
||||
for button in buttons:
|
||||
yield button
|
||||
|
||||
def make_pyqt_buttons(self, modes: list) -> list:
|
||||
def make_pyqt_buttons(self, modes: list) -> Generator[dict, None, None]:
|
||||
"""
|
||||
Creates list of buttons with one for each mode to be used in showing/hiding mode traces.
|
||||
|
||||
@@ -130,7 +136,7 @@ class IridaFigure(CustomFigure):
|
||||
fig_len (int): number of traces in the figure
|
||||
|
||||
Returns:
|
||||
list: list of buttons.
|
||||
Generator[dict, None, None]: list of buttons.
|
||||
"""
|
||||
fig_len = len(self.data)
|
||||
if len(modes) > 1:
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
"""
|
||||
Functions for constructing irida controls graphs using plotly.
|
||||
"""
|
||||
from datetime import date
|
||||
from pprint import pformat
|
||||
import plotly
|
||||
|
||||
from plotly.graph_objs import FigureWidget, Scatter
|
||||
|
||||
from . import CustomFigure
|
||||
import plotly.express as px
|
||||
import pandas as pd
|
||||
from PyQt6.QtWidgets import QWidget
|
||||
from plotly.graph_objects import Figure
|
||||
import logging
|
||||
from tools import get_unique_values_in_df_column, divide_chunks
|
||||
from frontend.widgets.functions import select_save_file
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
|
||||
# NOTE: For click events try (haven't got working yet) ipywidgets >=7.0.0 required for figurewidgets:
|
||||
# https://plotly.com/python/click-events/
|
||||
|
||||
|
||||
class PCRFigure(CustomFigure):
|
||||
|
||||
@@ -23,13 +24,20 @@ class PCRFigure(CustomFigure):
|
||||
super().__init__(df=df, modes=modes)
|
||||
logger.debug(f"DF: {self.df}")
|
||||
self.construct_chart(df=df)
|
||||
# self.generic_figure_markers(modes=modes, ytitle=ytitle, months=months)
|
||||
|
||||
def hello(self):
|
||||
print("hello")
|
||||
|
||||
def construct_chart(self, df: pd.DataFrame):
|
||||
logger.debug(f"PCR df: {df}")
|
||||
logger.debug(f"PCR df:\n {df}")
|
||||
try:
|
||||
scatter = px.scatter(data_frame=df, x='submitted_date', y="ct", hover_data=["name", "target", "ct", "reagent_lot"], color='target')
|
||||
express = px.scatter(data_frame=df, x='submitted_date', y="ct",
|
||||
hover_data=["name", "target", "ct", "reagent_lot"],
|
||||
color="target")
|
||||
except ValueError:
|
||||
scatter = px.scatter()
|
||||
express = px.scatter()
|
||||
scatter = FigureWidget([datum for datum in express.data])
|
||||
self.add_traces(scatter.data)
|
||||
self.update_traces(marker={'size': 15})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user