1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import numpy as np
- import plotly.graph_objects as go
- import pytest
- import reflex as rx
- from reflex.utils.serializers import serialize, serialize_figure
- @pytest.fixture
- def plotly_fig() -> go.Figure:
- """Get a plotly figure.
- Returns:
- A random plotly figure.
- """
- # Generate random data.
- data = np.random.randint(0, 10, size=(10, 4))
- trace = go.Scatter(
- x=list(range(len(data))), y=data[:, 0], mode="lines", name="Trace 1"
- )
- # Create a graph.
- return go.Figure(data=[trace])
- def test_serialize_plotly(plotly_fig: go.Figure):
- """Test that serializing a plotly figure works.
- Args:
- plotly_fig: The figure to serialize.
- """
- value = serialize(plotly_fig)
- assert isinstance(value, dict)
- assert value == serialize_figure(plotly_fig)
- def test_plotly_config_option(plotly_fig: go.Figure):
- """Test that the plotly component can be created with a config option.
- Args:
- plotly_fig: The figure to display.
- """
- # This tests just confirm that the component can be created with a config option.
- _ = rx.plotly(data=plotly_fig, config={"showLink": True})
|