def test_charts_read_yaml(self): values = [ V1Event( timestamp=dt_parser.parse("2018-12-11 10:24:57"), chart=V1EventChart(kind="plotly", figure={"foo": "bar"}), step=12, ), V1Event( timestamp=dt_parser.parse("2018-12-11 10:25:57"), chart=V1EventChart(kind="vega", figure={"foo2": "bar2"}), step=13, ), V1Event( timestamp=dt_parser.parse("2018-12-11 10:26:57"), chart=V1EventChart(kind="bokeh", figure={"foo3": "bar3"}), step=14, ), ] events = V1Events.read( name="foo", kind="chart", data=os.path.abspath( "tests/fixtures/polyboard/chart/chart_events.plx"), ) assert events.name == "foo" assert len(events.df.values) == 3 for i in range(3): assert events.get_event_at(i).to_dict() == values[i].to_dict()
def bokeh_chart(figure) -> V1EventChart: try: from bokeh.embed import json_item except ImportError: logger.warning(BOKEH_ERROR_MESSAGE) return UNKNOWN return V1EventChart(kind=V1EventChartKind.BOKEH, figure=json_item(figure))
def plotly_chart(figure) -> V1EventChart: try: import plotly.tools except ImportError: logger.warning(PLOTLY_ERROR_MESSAGE) return UNKNOWN if module_type(figure, "matplotlib.figure.Figure"): figure = plotly.tools.mpl_to_plotly(figure) else: figure = plotly.tools.return_figure_from_figure_or_data( figure, validate_figure=True) return V1EventChart(kind=V1EventChartKind.PLOTLY, figure=figure)
def test_chart(self): events = LoggedEventListSpec( name="foo", kind="chart", events=[ V1Event( timestamp=dt_parser.parse("2018-12-11 10:24:57"), chart=V1EventChart(kind="plotly", figure={"foo": "bar"}), step=12, ), V1Event( timestamp=dt_parser.parse("2018-12-11 11:24:57"), chart=V1EventChart(kind="vega", figure={"foo": "bar"}), step=13, ), V1Event( timestamp=dt_parser.parse("2018-12-11 12:24:57"), chart=V1EventChart(kind="bokeh", figure={"foo": "bar"}), step=14, ), ], ) events_dict = events.to_dict() assert events_dict == events.from_dict(events_dict).to_dict()
def altair_chart(figure) -> V1EventChart: return V1EventChart(kind=V1EventChartKind.VEGA, figure=figure.to_dict())