Skip to content

Commit

Permalink
Fix hover info for observation trace in SimulationTimeSeries (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenherje authored Jan 28, 2022
1 parent e759bc6 commit 0fd30b1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#926](https://github.com/equinor/webviz-subsurface/pull/926) - `VolumetricAnalysis` - Fixed bug when building portables with aggregated (`csvfile_vol`) input.
- [#929](https://github.com/equinor/webviz-subsurface/pull/929) - `TornadoWidget` - No longer skipping sensitivities with `SENSNAME="ref"` from tornado bars if there is more than one realization with `SENSNAME="ref"`.
- [#932](https://github.com/equinor/webviz-subsurface/pull/932) - `RftPlotter` - Fixed bug related to calculated correlations returning `NaN` if the response variable has constant values.
- [#937](https://github.com/equinor/webviz-subsurface/pull/937) - `SimulationTimeSeries` - Fixed hover info for observation trace

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def test_crate_vector_observation_traces() -> None:
expected_traces = [
{
"name": "Observation",
"legendgroup": "Observation",
"x": [datetime.datetime(2020, 1, 1), []],
"y": [2.0, []],
"marker": {"color": "black"},
Expand All @@ -86,6 +87,7 @@ def test_crate_vector_observation_traces() -> None:
},
{
"name": "Observation",
"legendgroup": "Observation",
"x": [datetime.datetime(2020, 6, 5), []],
"y": [5.0, []],
"marker": {"color": "black"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def add_vector_observations(
self._add_vector_traces_set_to_figure(
{
vector_name: create_vector_observation_traces(
vector_observations, self._observation_color, "Observation"
vector_observations, color=self._observation_color
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,50 @@


def create_vector_observation_traces(
vector_observations: dict, color: str = "black", legend_group: Optional[str] = None
vector_observations: dict,
color: str = "black",
legend_group: Optional[str] = None,
show_legend: bool = False,
) -> List[dict]:
"""Create list of observations traces from vector observations
`Input:`
* vector_observations: dict - Dictionary with observation data for a vector
* color: str - Color of observation traces for vector
* legend_group: Optional[str] - Name of legend group, added as legend group and name if provided
* legend_group: Optional[str] - Overwrite default legend group. Name of legend group, added as
legend group and name if provided.
* show_legend: bool - Show legend status for traces
`Return:`
List of marker traces for each observation for vector
"""
observation_traces: List[dict] = []

_name = "Observation" if legend_group is None else "Observation: " + legend_group
_legend_group = "Observation" if legend_group is None else legend_group

for observation in vector_observations.get("observations", []):
hovertext = observation.get("comment", "")
hovertext = observation.get("comment")
hovertemplate = (
"(%{x}, %{y})<br>" + hovertext if hovertext else "(%{x}, %{y})<br>"
)
trace = {
"name": "Observation",
"x": [observation.get("date"), []],
"y": [observation.get("value"), []],
"marker": {"color": color},
"hovertemplate": hovertemplate,
"showlegend": False,
"error_y": {
"type": "data",
"array": [observation.get("error"), []],
"visible": True,
},
}
if legend_group:
trace["name"] = "Observation: " + legend_group
trace["legendgroup"] = legend_group

observation_traces.append(trace)
observation_traces.append(
{
"name": _name,
"legendgroup": _legend_group,
"x": [observation.get("date"), []],
"y": [observation.get("value"), []],
"marker": {"color": color},
"hovertemplate": hovertemplate,
"showlegend": show_legend,
"error_y": {
"type": "data",
"array": [observation.get("error"), []],
"visible": True,
},
}
)
return observation_traces


Expand Down

0 comments on commit 0fd30b1

Please sign in to comment.