From 43dbc12e17c135744af81d05add4cc094e152448 Mon Sep 17 00:00:00 2001 From: teh_coderer Date: Mon, 3 Apr 2023 11:25:08 -0500 Subject: [PATCH] Feature/Interactive Plot CSV Bar (#4664) * init * cleanup * Update popups.js * Update popups.js * Update plotly.html * add hoverlabel to `ba/redditsent` #4618 --- .../behavioural_analysis/reddit_view.py | 14 +- openbb_terminal/core/plots/plotly.html | 33 +- openbb_terminal/core/plots/plotly_helper.py | 8 +- openbb_terminal/core/plots/web/bar_menus.js | 4 +- openbb_terminal/core/plots/web/helpers.js | 38 ++- openbb_terminal/core/plots/web/popups.js | 304 ++++++++++++------ openbb_terminal/forex/forex_helper.py | 1 - .../behavioural_analysis/ba_controller.py | 2 +- openbb_terminal/stocks/stocks_helper.py | 1 - 9 files changed, 274 insertions(+), 131 deletions(-) diff --git a/openbb_terminal/common/behavioural_analysis/reddit_view.py b/openbb_terminal/common/behavioural_analysis/reddit_view.py index 7af722d49ea..291a2a22f5b 100644 --- a/openbb_terminal/common/behavioural_analysis/reddit_view.py +++ b/openbb_terminal/common/behavioural_analysis/reddit_view.py @@ -3,6 +3,7 @@ __docformat__ = "numpy" import logging import os +import textwrap from datetime import datetime from typing import Dict, Optional, Union @@ -24,9 +25,6 @@ from openbb_terminal.rich_config import console logger = logging.getLogger(__name__) -# TODO: Test OpenBBFigure conversion - - @log_start_end(log=logger) @check_api_key(reddit_requirements) def print_and_record_reddit_post( @@ -313,11 +311,19 @@ def display_redditsent( console.print(f"Sentiment Analysis for {symbol} is {avg_polarity}\n") if graphic: + df["Title"] = df["Title"].apply( + lambda x: "
".join(textwrap.wrap(str(x), 50)) + ) fig = OpenBBFigure( title=f"Sentiment Score of {symbol}", xaxis_title="Sentiment Score", ) - fig.add_bar(x=polarity_scores) + fig.add_bar( + x=polarity_scores, + customdata=df["Title"], + hovertemplate="%{customdata}", + ) + fig.update_layout(hovermode="y") # remove y ticks of graph object because number based index doesn't make sense here fig.layout.yaxis.tickvals = [] diff --git a/openbb_terminal/core/plots/plotly.html b/openbb_terminal/core/plots/plotly.html index 484a442f61b..39e1c8a4be2 100644 --- a/openbb_terminal/core/plots/plotly.html +++ b/openbb_terminal/core/plots/plotly.html @@ -56,7 +56,7 @@
@@ -71,37 +71,42 @@