Skip to content

Commit

Permalink
Merge pull request #41 from dieterich-lab/bugfix/nicer_histgram_labels
Browse files Browse the repository at this point in the history
Nicer labels for histogram
  • Loading branch information
HaraldWilhelmi authored Sep 8, 2023
2 parents 81007b4 + a9c7a56 commit 2de99e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ have to add `node_modules/.bin` to your path. To execute the tests run:

* v1.0.1 - XXXX-XX-XX:
* Basic Stats/Database: Patient count is incorrect if case_id field is used
* NodeJS modules: updated -including tough-cookie (now 4.1.3)
* Histogram: Nicer measurement labels in some cases
* NodeJS modules: updated - including tough-cookie (now 4.1.3)

* v1.0.0 - 2023-08-30:
* Caching filter data per session in database to allow efficient and correct filtering
Expand Down
16 changes: 14 additions & 2 deletions medex/services/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
import plotly.express as px


def _get_fix_annotation_text(orig: str):
value = orig.split('=')[-1]
if len(value) > 5:
return value
else:
return orig


class HistogramService:
SVG_HEADER = b"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
Expand Down Expand Up @@ -77,8 +85,7 @@ def _get_dataframe(self, histogram_data, query_with_filter):
)
return df

@staticmethod
def _get_figure_with_layout(df, histogram_data):
def _get_figure_with_layout(self, df, histogram_data):
fig = px.histogram(df, x=histogram_data.numerical_entity, facet_row='measurement',
color=histogram_data.categorical_entity, barmode='overlay', nbins=histogram_data.bins,
opacity=0.7, template="plotly_white")
Expand All @@ -92,4 +99,9 @@ def _get_figure_with_layout(df, histogram_data):
'x': 0.5,
'xanchor': 'center'}
)
self._fix_measurement_labels(fig)
return fig

@staticmethod
def _fix_measurement_labels(fig):
fig.for_each_annotation(lambda a: a.update(text=_get_fix_annotation_text(a.text)))

0 comments on commit 2de99e6

Please sign in to comment.