| 50 | |
| 51 | |
| 52 | def test_newdatain_hover_data(): |
| 53 | hover_dicts = [ |
| 54 | {"comment": ["a", "b", "c"]}, |
| 55 | {"comment": (1.234, 45.3455, 5666.234)}, |
| 56 | {"comment": [1.234, 45.3455, 5666.234]}, |
| 57 | {"comment": np.array([1.234, 45.3455, 5666.234])}, |
| 58 | {"comment": pd.Series([1.234, 45.3455, 5666.234])}, |
| 59 | ] |
| 60 | for hover_dict in hover_dicts: |
| 61 | fig = px.scatter(x=[1, 2, 3], y=[3, 4, 5], hover_data=hover_dict) |
| 62 | assert ( |
| 63 | fig.data[0].hovertemplate |
| 64 | == "x=%{x}<br>y=%{y}<br>comment=%{customdata[0]}<extra></extra>" |
| 65 | ) |
| 66 | fig = px.scatter( |
| 67 | x=[1, 2, 3], y=[3, 4, 5], hover_data={"comment": (True, ["a", "b", "c"])} |
| 68 | ) |
| 69 | assert ( |
| 70 | fig.data[0].hovertemplate |
| 71 | == "x=%{x}<br>y=%{y}<br>comment=%{customdata[0]}<extra></extra>" |
| 72 | ) |
| 73 | hover_dicts = [ |
| 74 | {"comment": (":.1f", (1.234, 45.3455, 5666.234))}, |
| 75 | {"comment": (":.1f", [1.234, 45.3455, 5666.234])}, |
| 76 | {"comment": (":.1f", np.array([1.234, 45.3455, 5666.234]))}, |
| 77 | {"comment": (":.1f", pd.Series([1.234, 45.3455, 5666.234]))}, |
| 78 | ] |
| 79 | for hover_dict in hover_dicts: |
| 80 | fig = px.scatter( |
| 81 | x=[1, 2, 3], |
| 82 | y=[3, 4, 5], |
| 83 | hover_data=hover_dict, |
| 84 | ) |
| 85 | assert ( |
| 86 | fig.data[0].hovertemplate |
| 87 | == "x=%{x}<br>y=%{y}<br>comment=%{customdata[0]:.1f}<extra></extra>" |
| 88 | ) |
| 89 | |
| 90 | |
| 91 | def test_formatted_hover_and_labels(backend): |