-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: indicator chart #1088
base: main
Are you sure you want to change the base?
feat: indicator chart #1088
Changes from 11 commits
dc60b56
98e9edf
f487c4a
f386079
330c6c8
5cbe713
f9909ef
a38a1a7
dbf372a
31bd571
636d193
4d0f147
fd9eaae
ab6c9b2
c996f3e
c06d9d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
line_geo, | ||
line_mapbox, | ||
density_heatmap, | ||
indicator, | ||
) | ||
|
||
from .data import data_generators | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ def _setup_listeners(self) -> None: | |
for table, node in self._partitioned_tables.values(): | ||
listen_func = partial(self._on_update, node) | ||
# if a table is not refreshing, it will never update, so no need to listen | ||
if table.is_refreshing: | ||
if table and table.is_refreshing: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to have this fix as a separate PR just so it's clear this is fixed in the release notes (is there a ticket for it? When do we run into this issue?) |
||
handle = listen(table, listen_func) | ||
self._handles.append(handle) | ||
self._liveness_scope.manage(handle) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,14 @@ | |
from plotly.graph_objects import Figure | ||
from plotly.validators.heatmap import ColorscaleValidator | ||
|
||
# attach a prefix to the number format so that we can identify it as the GWT Java NumberFormat syntax | ||
# https://www.gwtproject.org/javadoc/latest/com/google/gwt/i18n/client/NumberFormat.html | ||
# this differentiates it from the d3 format syntax, which the user could provide through an unsafe update | ||
# this should be safe as it shouldn't appear naturally in a d3 format string | ||
# https://github.com/d3/d3-format/tree/v1.4.5#d3-format | ||
# but isn't a perfect solution | ||
FORMAT_PREFIX = "DEEPHAVEN_JAVA_FORMAT" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kind of want an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
|
||
def draw_finance( | ||
data_frame: DataFrame, | ||
|
@@ -186,3 +194,98 @@ def draw_density_heatmap( | |
) | ||
|
||
return heatmap | ||
|
||
|
||
def draw_indicator( | ||
data_frame: DataFrame, | ||
value: str, | ||
reference: str | None = None, | ||
number: bool = True, | ||
gauge: str | None = None, | ||
axis: bool = False, | ||
prefix: str | None = None, | ||
suffix: str | None = None, | ||
increasing_text: str | None = None, | ||
decreasing_text: str | None = None, | ||
number_format: str | None = None, | ||
text_indicator: str | None = None, | ||
title: str | None = None, | ||
) -> Figure: | ||
"""Create an indicator chart. | ||
|
||
Args: | ||
data_frame: The data frame to draw with | ||
value: The column to use as the value. | ||
reference: The column to use as the reference value. | ||
number: True to show the number, False to hide it. | ||
gauge: Specifies the type of gauge to use. | ||
Set to "angular" for a half-circle gauge and "bullet" for a horizontal gauge. | ||
axis: True to show the axis. Only valid if gauge is set. | ||
prefix: A string to prepend to the number value. | ||
suffix: A string to append to the number value. | ||
increasing_text: The text to display before the delta if the number value | ||
is greater than the reference value. | ||
decreasing_text: The text to display before the delta if the number value | ||
is less than the reference value. | ||
number_format: The format to use for the number. | ||
text_indicator: The column to use as text for the indicator. | ||
title: The title of the chart. | ||
|
||
Returns: | ||
The plotly indicator chart. | ||
|
||
""" | ||
|
||
modes = [] | ||
if number: | ||
modes.append("number") | ||
if reference: | ||
modes.append("delta") | ||
if gauge: | ||
modes.append("gauge") | ||
mode = "+".join(modes) | ||
|
||
fig = go.Figure( | ||
go.Indicator( | ||
value=data_frame[value][0], | ||
mode=mode, | ||
domain={"x": [0, 1], "y": [0, 1]}, | ||
), | ||
layout={ | ||
"legend": {"tracegroupgap": 0}, | ||
"margin": {"t": 60}, | ||
}, | ||
) | ||
|
||
if reference: | ||
fig.update_traces(delta_reference=data_frame[reference][0]) | ||
|
||
if text_indicator: | ||
fig.update_traces(title_text=data_frame[text_indicator][0]) | ||
|
||
if gauge: | ||
fig.update_traces(gauge={"shape": gauge, "axis": {"visible": axis}}) | ||
|
||
if prefix: | ||
fig.update_traces(delta_prefix=prefix, number_prefix=prefix) | ||
|
||
if suffix: | ||
fig.update_traces(delta_suffix=suffix, number_suffix=suffix) | ||
|
||
if increasing_text: | ||
fig.update_traces(delta_increasing_symbol=increasing_text) | ||
|
||
if decreasing_text: | ||
fig.update_traces(delta_decreasing_symbol=decreasing_text) | ||
|
||
if number_format: | ||
# Plotly expects d3 format strings so these will be converted on the client. | ||
fig.update_traces( | ||
delta_valueformat=FORMAT_PREFIX + number_format, | ||
number_valueformat=FORMAT_PREFIX + number_format, | ||
) | ||
|
||
if title: | ||
fig.update_layout(title=title) | ||
|
||
return fig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example is kind of confusing. What is the
by_vars
argument for? Why are we doing aby
here at all when we've already filtered the table to oneSym
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so that the symbol can be specified in the
increasing_color_map
anddecreasing_color_map
, although it shouldn't have filtered to one symbol so I'll fix that.