Skip to content

Commit

Permalink
Included plotly conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shettland committed Jul 23, 2024
1 parent a09d1d6 commit a5ada62
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions relecov_core/utils/plotly_dash_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django_plotly_dash import DjangoDash
from dash.dependencies import Input, Output
from dash import dcc, html
from plotly.express import bar
import plotly.express as px
from dash.exceptions import PreventUpdate


Expand All @@ -12,7 +12,7 @@ def dash_bar_lab(option_list, data):
option.append({"label": opt_list, "value": opt_list})

app = DjangoDash("samplePerLabGraphic")
empty_fig = bar(x=[0], y=[0], height=300)
empty_fig = px.bar(x=[0], y=[0], height=300)

app.layout = html.Div(
[
Expand Down Expand Up @@ -45,7 +45,7 @@ def update_graph(select_lab_name):
if select_lab_name == 1:
raise PreventUpdate
sub_data = data[data.lab_name == select_lab_name]
graph = bar(
graph = px.bar(
sub_data,
x=sub_data["date"],
y=sub_data["num_samples"],
Expand Down
26 changes: 13 additions & 13 deletions relecov_core/utils/plotly_graphics.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generic imports
from plotly.offline import plot
from plotly.graph_objects import Figure, Bar, Scatter, Indicator, Pie
from plotly.express import bar
from plotly.figure_factory import create_bullet
import plotly.graph_objects as go
import plotly.express as px
import plotly.figure_factory as ff
from dash_bio import NeedlePlot
from dash import dcc, html
from django_plotly_dash import DjangoDash
Expand All @@ -15,10 +15,10 @@ def bar_graphic(data, col_names, legend, yaxis, options):
colors = options["colors"]
else:
colors = ["#0099ff", "#1aff8c", "#ffad33", "#ff7733", "#66b3ff", "#66ffcc"]
fig = Figure()
fig = go.Figure()
for idx in range(1, len(col_names)):
fig.add_trace(
Bar(
go.Bar(
x=data[col_names[0]],
y=data[col_names[idx]],
name=legend[idx - 1],
Expand Down Expand Up @@ -53,8 +53,8 @@ def bar_graphic(data, col_names, legend, yaxis, options):

def line_graphic(x_data, y_data, options):
# Create line
fig = Figure()
fig.add_trace(Scatter(x=x_data, y=y_data, mode="lines", name="lines"))
fig = go.Figure()
fig.add_trace(go.Scatter(x=x_data, y=y_data, mode="lines", name="lines"))

fig.update_layout(
height=options["height"],
Expand All @@ -73,7 +73,7 @@ def line_graphic(x_data, y_data, options):


def histogram_graphic(data, col_names, options):
graph = bar(
graph = px.bar(
data, y=col_names[1], x=col_names[0], text_auto=True, width=options["width"]
)
# Customize aspect
Expand All @@ -96,8 +96,8 @@ def histogram_graphic(data, col_names, options):


def gauge_graphic(data):
graph = Figure(
Indicator(
graph = go.Figure(
go.Indicator(
mode="gauge+number",
value=data["value"],
number={"suffix": "%"},
Expand Down Expand Up @@ -125,7 +125,7 @@ def bullet_graphic(value, title):
]

measure_colors = ["rgb(68, 107, 162)", "rgb(0, 153, 0)"]
fig = create_bullet(
fig = ff.create_bullet(
data,
titles="label",
title=title,
Expand Down Expand Up @@ -157,8 +157,8 @@ def pie_graphic(data, names, title, show_legend=False):
"darkorange",
"turquoise",
]
fig = Figure(
data=Pie(
fig = go.Figure(
data=go.Pie(
labels=names,
values=data,
)
Expand Down
6 changes: 3 additions & 3 deletions relecov_core/utils/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import shutil
from collections import OrderedDict
from datetime import datetime
from pandas import DataFrame as PandasDataFrame
import pandas as pd
from django.contrib.auth.models import Group, User
from django.core.files.storage import FileSystemStorage
from django.conf import settings
Expand Down Expand Up @@ -292,7 +292,7 @@ def create_date_sample_bar(lab_sample, cust_data):
"""Create bar graph where X-axis are the dates and Y-axis the number of
samples
"""
df = PandasDataFrame(lab_sample.items(), columns=cust_data["col_names"])
df = pd.DataFrame(lab_sample.items(), columns=cust_data["col_names"])
histogram = relecov_core.utils.plotly_graphics.histogram_graphic(
df, cust_data["col_names"], cust_data["options"]
)
Expand All @@ -303,7 +303,7 @@ def create_dash_bar_for_each_lab():
"""Function collect the list of lab and the samples per date per each lab
and call dash plotly function to display
"""
df_data = PandasDataFrame(get_sample_per_date_per_all_lab(detailed=True))
df_data = pd.DataFrame(get_sample_per_date_per_all_lab(detailed=True))
relecov_core.utils.plotly_dash_graphics(get_all_lab_list(), df_data)
return

Expand Down
4 changes: 2 additions & 2 deletions relecov_core/utils/samples_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import json
import pandas as pd
from plotly.express import choropleth_mapbox
import plotly.express as px
from dash import dcc, html
from django_plotly_dash import DjangoDash

Expand Down Expand Up @@ -37,7 +37,7 @@ def create_samples_received_map():
data["samples"].append("0")
ldata = pd.DataFrame(data)

fig = choropleth_mapbox(
fig = px.choropleth_mapbox(
ldata,
geojson=counties,
locations=ldata.ccaa_id,
Expand Down

0 comments on commit a5ada62

Please sign in to comment.