openbb-charting 2.1.2__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/PKG-INFO +39 -9
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/README.md +34 -5
- openbb_charting-2.2.0/openbb_charting/__init__.py +25 -0
- openbb_charting-2.1.2/openbb_charting/__init__.py → openbb_charting-2.2.0/openbb_charting/charting.py +131 -98
- {openbb_charting-2.1.2/openbb_charting/utils → openbb_charting-2.2.0/openbb_charting/charts}/generic_charts.py +39 -29
- {openbb_charting-2.1.2/openbb_charting/utils → openbb_charting-2.2.0/openbb_charting/charts}/helpers.py +27 -19
- openbb_charting-2.2.0/openbb_charting/charts/price_historical.py +319 -0
- openbb_charting-2.2.0/openbb_charting/charts/price_performance.py +108 -0
- {openbb_charting-2.1.2/openbb_charting/utils → openbb_charting-2.2.0/openbb_charting/charts}/relative_rotation.py +18 -10
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/backend.py +71 -54
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/config/openbb_styles.py +5 -4
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/openbb_figure.py +80 -51
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/base.py +19 -7
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/data_classes.py +23 -17
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/ta_class.py +7 -5
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/ta_helpers.py +8 -5
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/to_chart.py +12 -10
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/query_params.py +3 -2
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/pyproject.toml +4 -3
- openbb_charting-2.1.2/openbb_charting/builder.py +0 -53
- openbb_charting-2.1.2/openbb_charting/charting_router.py +0 -1446
- {openbb_charting-2.1.2/openbb_charting/utils → openbb_charting-2.2.0/openbb_charting/charts}/__init__.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/__init__.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/assets/Terminal_icon.png +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/assets/plotly-2.32.0.min.js +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/chart_style.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/config/__init__.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/dummy_backend.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly.html +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/__init__.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/plugins/__init__.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/plugins/custom_indicators_plugin.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/plugins/momentum_plugin.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/plugins/overlap_plugin.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/plugins/trend_indicators_plugin.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/plugins/volatility_plugin.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/plotly_ta/plugins/volume_plugin.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/core/table.html +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/styles/__init__.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/styles/colors.py +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/styles/default/dark.pltstyle.json +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/styles/default/light.pltstyle.json +0 -0
- {openbb_charting-2.1.2 → openbb_charting-2.2.0}/openbb_charting/styles/default/tables.pltstyle.json +0 -0
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: openbb-charting
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Charting extension for OpenBB
|
|
5
5
|
License: AGPL-3.0-only
|
|
6
6
|
Author: OpenBB Team
|
|
7
7
|
Author-email: hello@openbb.co
|
|
8
|
-
Requires-Python: >=3.
|
|
8
|
+
Requires-Python: >=3.9,<3.13
|
|
9
9
|
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
12
11
|
Classifier: Programming Language :: Python :: 3.9
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
15
|
Requires-Dist: nbformat (>=5.9.2,<6.0.0)
|
|
16
|
-
Requires-Dist:
|
|
16
|
+
Requires-Dist: numpy (>=1,<2)
|
|
17
|
+
Requires-Dist: openbb-core (>=1.3.0,<2.0.0)
|
|
17
18
|
Requires-Dist: pandas-ta (>=0.3.14b,<0.4.0)
|
|
18
19
|
Requires-Dist: plotly (>=5.17.0,<6.0.0)
|
|
19
20
|
Requires-Dist: pywry (>=0.6.1,<0.7.0)
|
|
@@ -32,7 +33,7 @@ The library includes:
|
|
|
32
33
|
- prebuilt charts for a set of commands that are built-in OpenBB extensions
|
|
33
34
|
|
|
34
35
|
>[!NOTE]
|
|
35
|
-
> The charting library is an
|
|
36
|
+
> The charting library is an `OBBject` extension which means you'll have the functionality it exposes on every command result.
|
|
36
37
|
|
|
37
38
|
## Installation
|
|
38
39
|
|
|
@@ -143,15 +144,44 @@ Example usage:
|
|
|
143
144
|
|
|
144
145
|
## Add a visualization to an existing Platform command
|
|
145
146
|
|
|
146
|
-
|
|
147
|
+
To add a visualization to an existing command, you'll need to add a `poetry` plugin to your `pyproject.toml` file. The syntax should be the following:
|
|
147
148
|
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
```toml
|
|
150
|
+
[tool.poetry.plugins."openbb_charting_extension"]
|
|
151
|
+
my_extension = "openbb_my_extension.my_extension_views:MyExtensionViews"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Where the `openbb_charting_extension` is **mandatory**, otherwise the charting extension won't be able to find the visualization.
|
|
155
|
+
|
|
156
|
+
And the suggested structure for the `my_extension_views` module is the following:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
"""Views for MyExtension."""
|
|
160
|
+
|
|
161
|
+
from typing import Any, Dict, Tuple
|
|
162
|
+
|
|
163
|
+
from openbb_charting.charts.price_historical import price_historical
|
|
164
|
+
from openbb_charting.core.openbb_figure import OpenBBFigure
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class MyExtensionViews:
|
|
168
|
+
"""MyExtension Views."""
|
|
169
|
+
|
|
170
|
+
@staticmethod
|
|
171
|
+
def my_extension_price_historical(
|
|
172
|
+
**kwargs,
|
|
173
|
+
) -> Tuple[OpenBBFigure, Dict[str, Any]]:
|
|
174
|
+
"""MyExtension Price Historical Chart."""
|
|
175
|
+
return price_historical(**kwargs)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
> Note that `my_extension_views` lives under the `openbb_my_extension` package.
|
|
150
179
|
|
|
151
|
-
Afterwards, you'll need to add the visualization to
|
|
180
|
+
Afterwards, you'll need to add the visualization to your new `MyExtensionViews` class. The convention to match the endpoint with the respective charting function is the following:
|
|
152
181
|
|
|
153
182
|
- `/equity/price/historical` -> `equity_price_historical`
|
|
154
183
|
- `/technical/ema` -> `technical_ema`
|
|
184
|
+
- `/my_extension/price_historical` -> `my_extension_price_historical`
|
|
155
185
|
|
|
156
186
|
When you spot the charting function on the charting router file, you can add the visualization to it.
|
|
157
187
|
|
|
@@ -9,7 +9,7 @@ The library includes:
|
|
|
9
9
|
- prebuilt charts for a set of commands that are built-in OpenBB extensions
|
|
10
10
|
|
|
11
11
|
>[!NOTE]
|
|
12
|
-
> The charting library is an
|
|
12
|
+
> The charting library is an `OBBject` extension which means you'll have the functionality it exposes on every command result.
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
@@ -120,15 +120,44 @@ Example usage:
|
|
|
120
120
|
|
|
121
121
|
## Add a visualization to an existing Platform command
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
To add a visualization to an existing command, you'll need to add a `poetry` plugin to your `pyproject.toml` file. The syntax should be the following:
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
```toml
|
|
126
|
+
[tool.poetry.plugins."openbb_charting_extension"]
|
|
127
|
+
my_extension = "openbb_my_extension.my_extension_views:MyExtensionViews"
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Where the `openbb_charting_extension` is **mandatory**, otherwise the charting extension won't be able to find the visualization.
|
|
131
|
+
|
|
132
|
+
And the suggested structure for the `my_extension_views` module is the following:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
"""Views for MyExtension."""
|
|
136
|
+
|
|
137
|
+
from typing import Any, Dict, Tuple
|
|
138
|
+
|
|
139
|
+
from openbb_charting.charts.price_historical import price_historical
|
|
140
|
+
from openbb_charting.core.openbb_figure import OpenBBFigure
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class MyExtensionViews:
|
|
144
|
+
"""MyExtension Views."""
|
|
145
|
+
|
|
146
|
+
@staticmethod
|
|
147
|
+
def my_extension_price_historical(
|
|
148
|
+
**kwargs,
|
|
149
|
+
) -> Tuple[OpenBBFigure, Dict[str, Any]]:
|
|
150
|
+
"""MyExtension Price Historical Chart."""
|
|
151
|
+
return price_historical(**kwargs)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
> Note that `my_extension_views` lives under the `openbb_my_extension` package.
|
|
127
155
|
|
|
128
|
-
Afterwards, you'll need to add the visualization to
|
|
156
|
+
Afterwards, you'll need to add the visualization to your new `MyExtensionViews` class. The convention to match the endpoint with the respective charting function is the following:
|
|
129
157
|
|
|
130
158
|
- `/equity/price/historical` -> `equity_price_historical`
|
|
131
159
|
- `/technical/ema` -> `technical_ema`
|
|
160
|
+
- `/my_extension/price_historical` -> `my_extension_price_historical`
|
|
132
161
|
|
|
133
162
|
When you spot the charting function on the charting router file, you can add the visualization to it.
|
|
134
163
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""OpenBB OBBject extension for charting."""
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
|
|
5
|
+
from openbb_core.app.model.extension import Extension
|
|
6
|
+
|
|
7
|
+
warnings.filterwarnings(
|
|
8
|
+
"ignore",
|
|
9
|
+
category=UserWarning,
|
|
10
|
+
module="openbb_core.app.model.extension",
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_charting_module():
|
|
15
|
+
"""Get the Charting module."""
|
|
16
|
+
# pylint: disable=import-outside-toplevel
|
|
17
|
+
import importlib
|
|
18
|
+
|
|
19
|
+
_Charting = importlib.import_module("openbb_charting.charting").Charting
|
|
20
|
+
return _Charting
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
ext = Extension(name="charting", description="Create custom charts from OBBject data.")
|
|
24
|
+
|
|
25
|
+
Charting = ext.obbject_accessor(get_charting_module())
|
|
@@ -1,44 +1,41 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Charting Class implementation."""
|
|
2
2
|
|
|
3
3
|
# pylint: disable=too-many-arguments,unused-argument
|
|
4
4
|
|
|
5
|
-
import warnings
|
|
6
5
|
from typing import (
|
|
6
|
+
TYPE_CHECKING,
|
|
7
7
|
Any,
|
|
8
8
|
Callable,
|
|
9
|
+
ClassVar,
|
|
9
10
|
Dict,
|
|
10
11
|
List,
|
|
11
12
|
Literal,
|
|
12
13
|
Optional,
|
|
13
14
|
Tuple,
|
|
15
|
+
Type,
|
|
14
16
|
Union,
|
|
15
17
|
)
|
|
16
18
|
from warnings import warn
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
import pandas as pd
|
|
20
|
+
from importlib_metadata import entry_points
|
|
20
21
|
from openbb_core.app.model.charts.chart import Chart
|
|
21
|
-
from openbb_core.app.model.extension import Extension
|
|
22
22
|
from openbb_core.app.model.obbject import OBBject
|
|
23
|
-
from openbb_core.app.utils import basemodel_to_df, convert_to_basemodel
|
|
24
23
|
from openbb_core.provider.abstract.data import Data
|
|
25
|
-
from plotly.graph_objs import Figure
|
|
26
24
|
|
|
27
|
-
from openbb_charting import
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
from openbb_charting.query_params import ChartParams, IndicatorsParams
|
|
31
|
-
from openbb_charting.utils.generic_charts import bar_chart, line_chart
|
|
32
|
-
from openbb_charting.utils.helpers import get_charting_functions
|
|
33
|
-
|
|
34
|
-
warnings.filterwarnings(
|
|
35
|
-
"ignore", category=UserWarning, module="openbb_core.app.model.extension", lineno=47
|
|
25
|
+
from openbb_charting.charts.helpers import (
|
|
26
|
+
get_charting_functions,
|
|
27
|
+
get_charting_functions_list,
|
|
36
28
|
)
|
|
37
29
|
|
|
38
|
-
|
|
30
|
+
if TYPE_CHECKING:
|
|
31
|
+
from numpy import ndarray # noqa
|
|
32
|
+
from pandas import DataFrame, Series # noqa
|
|
33
|
+
from plotly.graph_objs import Figure # noqa
|
|
34
|
+
from openbb_charting.core.openbb_figure import OpenBBFigure # noqa
|
|
35
|
+
from openbb_charting.query_params import ChartParams # noqa
|
|
36
|
+
from openbb_charting.core.backend import Backend # noqa
|
|
39
37
|
|
|
40
38
|
|
|
41
|
-
@ext.obbject_accessor
|
|
42
39
|
class Charting:
|
|
43
40
|
"""Charting extension.
|
|
44
41
|
|
|
@@ -64,17 +61,29 @@ class Charting:
|
|
|
64
61
|
Toggle the chart style, of an existing chart, between light and dark mode.
|
|
65
62
|
"""
|
|
66
63
|
|
|
64
|
+
_extension_views: ClassVar[List[Type]] = [
|
|
65
|
+
entry_point.load()
|
|
66
|
+
for entry_point in entry_points(group="openbb_charting_extension")
|
|
67
|
+
]
|
|
68
|
+
_format = "plotly" # the charts computed by this extension will be in plotly format
|
|
69
|
+
|
|
67
70
|
def __init__(self, obbject):
|
|
68
71
|
"""Initialize Charting extension."""
|
|
69
72
|
# pylint: disable=import-outside-toplevel
|
|
70
|
-
|
|
73
|
+
import importlib # noqa
|
|
74
|
+
|
|
75
|
+
charting_settings_module = importlib.import_module(
|
|
76
|
+
"openbb_core.app.model.charts.charting_settings", "ChartingSettings"
|
|
77
|
+
)
|
|
78
|
+
ChartingSettings = charting_settings_module.ChartingSettings
|
|
71
79
|
|
|
72
80
|
self._obbject: OBBject = obbject
|
|
73
81
|
self._charting_settings = ChartingSettings(
|
|
74
82
|
user_settings=self._obbject._user_settings, # type: ignore
|
|
75
83
|
system_settings=self._obbject._system_settings, # type: ignore
|
|
76
84
|
)
|
|
77
|
-
self._backend
|
|
85
|
+
self._backend = self._handle_backend()
|
|
86
|
+
self._functions: Dict[str, Callable] = self._get_functions()
|
|
78
87
|
|
|
79
88
|
@classmethod
|
|
80
89
|
def indicators(cls):
|
|
@@ -82,33 +91,58 @@ class Charting:
|
|
|
82
91
|
|
|
83
92
|
Without assigning to a variable, it will print the the information to the console.
|
|
84
93
|
"""
|
|
94
|
+
# pylint: disable=import-outside-toplevel
|
|
95
|
+
from openbb_charting.query_params import IndicatorsParams
|
|
96
|
+
|
|
85
97
|
return IndicatorsParams()
|
|
86
98
|
|
|
87
99
|
@classmethod
|
|
88
|
-
def functions(cls):
|
|
100
|
+
def functions(cls) -> List[str]:
|
|
89
101
|
"""Return a list of the available functions."""
|
|
90
|
-
|
|
102
|
+
functions: List[str] = []
|
|
103
|
+
for view in cls._extension_views:
|
|
104
|
+
functions.extend(get_charting_functions_list(view))
|
|
105
|
+
|
|
106
|
+
return functions
|
|
107
|
+
|
|
108
|
+
def _get_functions(self) -> Dict[str, Callable]:
|
|
109
|
+
"""Return a dict with the available functions."""
|
|
110
|
+
functions: Dict[str, Callable] = {}
|
|
111
|
+
for view in self._extension_views:
|
|
112
|
+
functions.update(get_charting_functions(view))
|
|
91
113
|
|
|
92
|
-
|
|
114
|
+
return functions
|
|
115
|
+
|
|
116
|
+
def _handle_backend(self) -> "Backend":
|
|
93
117
|
"""Create and start the backend."""
|
|
118
|
+
# pylint: disable=import-outside-toplevel
|
|
119
|
+
from openbb_charting.core.backend import create_backend, get_backend
|
|
120
|
+
|
|
94
121
|
create_backend(self._charting_settings)
|
|
95
122
|
backend = get_backend()
|
|
96
123
|
backend.start(debug=self._charting_settings.debug_mode)
|
|
97
124
|
return backend
|
|
98
125
|
|
|
99
|
-
|
|
100
|
-
def _get_chart_function(route: str) -> Callable:
|
|
126
|
+
def _get_chart_function(self, route: str) -> Callable:
|
|
101
127
|
"""Given a route, it returns the chart function. The module must contain the given route."""
|
|
102
128
|
if route is None:
|
|
103
129
|
raise ValueError("OBBject was initialized with no function route.")
|
|
104
130
|
adjusted_route = route.replace("/", "_")[1:]
|
|
105
|
-
|
|
131
|
+
if adjusted_route not in self._functions:
|
|
132
|
+
raise ValueError(
|
|
133
|
+
f"Could not find the route `{adjusted_route}` in the charting functions."
|
|
134
|
+
)
|
|
135
|
+
return self._functions[adjusted_route]
|
|
106
136
|
|
|
107
|
-
def get_params(self) -> ChartParams:
|
|
137
|
+
def get_params(self) -> Union["ChartParams", None]:
|
|
108
138
|
"""Return the ChartQueryParams class for the function the OBBject was created from.
|
|
109
139
|
|
|
110
140
|
Without assigning to a variable, it will print the docstring to the console.
|
|
141
|
+
If the class is not defined, the help for the function will be returned.
|
|
111
142
|
"""
|
|
143
|
+
# pylint: disable=import-outside-toplevel
|
|
144
|
+
from openbb_charting.query_params import ChartParams
|
|
145
|
+
|
|
112
146
|
if self._obbject._route is None: # pylint: disable=protected-access
|
|
113
147
|
raise ValueError("OBBject was initialized with no function route.")
|
|
114
148
|
charting_function = (
|
|
@@ -116,23 +150,32 @@ class Charting:
|
|
|
116
150
|
).replace("/", "_")[1:]
|
|
117
151
|
if hasattr(ChartParams, charting_function):
|
|
118
152
|
return getattr(ChartParams, charting_function)()
|
|
119
|
-
|
|
120
|
-
|
|
153
|
+
|
|
154
|
+
return help( # type: ignore
|
|
155
|
+
self._get_chart_function( # pylint: disable=protected-access
|
|
156
|
+
self._obbject.extra[ # pylint: disable=protected-access
|
|
157
|
+
"metadata"
|
|
158
|
+
].route
|
|
159
|
+
)
|
|
121
160
|
)
|
|
122
161
|
|
|
123
162
|
def _prepare_data_as_df(
|
|
124
|
-
self, data: Optional[Union[
|
|
125
|
-
) -> Tuple[
|
|
163
|
+
self, data: Optional[Union["DataFrame", "Series"]]
|
|
164
|
+
) -> Tuple["DataFrame", bool]:
|
|
126
165
|
"""Convert supplied data to a DataFrame."""
|
|
166
|
+
# pylint: disable=import-outside-toplevel
|
|
167
|
+
from openbb_core.app.utils import basemodel_to_df, convert_to_basemodel
|
|
168
|
+
from pandas import DataFrame, Series
|
|
169
|
+
|
|
127
170
|
has_data = (
|
|
128
|
-
isinstance(data, (Data,
|
|
171
|
+
isinstance(data, (Data, DataFrame, Series)) and not data.empty # type: ignore
|
|
129
172
|
) or (bool(data))
|
|
130
173
|
index = (
|
|
131
174
|
data.index.name
|
|
132
|
-
if has_data and isinstance(data, (
|
|
175
|
+
if has_data and isinstance(data, (DataFrame, Series))
|
|
133
176
|
else None
|
|
134
177
|
)
|
|
135
|
-
data_as_df:
|
|
178
|
+
data_as_df: DataFrame = (
|
|
136
179
|
basemodel_to_df(convert_to_basemodel(data), index=index)
|
|
137
180
|
if has_data
|
|
138
181
|
else self._obbject.to_dataframe(index=index)
|
|
@@ -149,11 +192,11 @@ class Charting:
|
|
|
149
192
|
data: Union[
|
|
150
193
|
list,
|
|
151
194
|
dict,
|
|
152
|
-
|
|
153
|
-
List[
|
|
154
|
-
|
|
155
|
-
List[
|
|
156
|
-
|
|
195
|
+
"DataFrame",
|
|
196
|
+
List["DataFrame"],
|
|
197
|
+
"Series",
|
|
198
|
+
List["Series"],
|
|
199
|
+
"ndarray",
|
|
157
200
|
Data,
|
|
158
201
|
],
|
|
159
202
|
index: Optional[str] = None,
|
|
@@ -172,12 +215,12 @@ class Charting:
|
|
|
172
215
|
same_axis: bool = False,
|
|
173
216
|
render: bool = True,
|
|
174
217
|
**kwargs,
|
|
175
|
-
) -> Union[OpenBBFigure, Figure, None]:
|
|
218
|
+
) -> Union["OpenBBFigure", "Figure", None]:
|
|
176
219
|
"""Create a line chart from external data and render a chart or return the OpenBBFigure.
|
|
177
220
|
|
|
178
221
|
Parameters
|
|
179
222
|
----------
|
|
180
|
-
data : Union[Data,
|
|
223
|
+
data : Union[Data, DataFrame, Series]
|
|
181
224
|
Data to be plotted (OHLCV data).
|
|
182
225
|
index : Optional[str], optional
|
|
183
226
|
Index column, by default None
|
|
@@ -215,6 +258,9 @@ class Charting:
|
|
|
215
258
|
**kwargs: Dict[str, Any]
|
|
216
259
|
Extra parameters to be passed to `figure.show()`
|
|
217
260
|
"""
|
|
261
|
+
# pylint: disable=import-outside-toplevel
|
|
262
|
+
from openbb_charting.charts.generic_charts import line_chart
|
|
263
|
+
|
|
218
264
|
fig = line_chart(
|
|
219
265
|
data=data,
|
|
220
266
|
index=index,
|
|
@@ -244,11 +290,11 @@ class Charting:
|
|
|
244
290
|
data: Union[
|
|
245
291
|
list,
|
|
246
292
|
dict,
|
|
247
|
-
|
|
248
|
-
List[
|
|
249
|
-
|
|
250
|
-
List[
|
|
251
|
-
|
|
293
|
+
"DataFrame",
|
|
294
|
+
List["DataFrame"],
|
|
295
|
+
"Series",
|
|
296
|
+
List["Series"],
|
|
297
|
+
"ndarray",
|
|
252
298
|
Data,
|
|
253
299
|
],
|
|
254
300
|
x: str,
|
|
@@ -266,12 +312,12 @@ class Charting:
|
|
|
266
312
|
bar_kwargs: Optional[Dict[str, Any]] = None,
|
|
267
313
|
render: bool = True,
|
|
268
314
|
**kwargs,
|
|
269
|
-
) -> Union[OpenBBFigure, Figure, None]:
|
|
315
|
+
) -> Union["OpenBBFigure", "Figure", None]:
|
|
270
316
|
"""Create a bar chart on a single x-axis with one or more values for the y-axis.
|
|
271
317
|
|
|
272
318
|
Parameters
|
|
273
319
|
----------
|
|
274
|
-
data : Union[list, dict,
|
|
320
|
+
data : Union[list, dict, DataFrame, List[DataFrame], Series, List[Series], ndarray, Data]
|
|
275
321
|
Data to plot.
|
|
276
322
|
x : str
|
|
277
323
|
The x-axis column name.
|
|
@@ -298,6 +344,9 @@ class Charting:
|
|
|
298
344
|
OpenBBFigure
|
|
299
345
|
The OpenBBFigure object.
|
|
300
346
|
"""
|
|
347
|
+
# pylint: disable=import-outside-toplevel
|
|
348
|
+
from openbb_charting.charts.generic_charts import bar_chart
|
|
349
|
+
|
|
301
350
|
fig = bar_chart(
|
|
302
351
|
data=data,
|
|
303
352
|
x=x,
|
|
@@ -326,28 +375,19 @@ class Charting:
|
|
|
326
375
|
self._obbject._route # pylint: disable=protected-access
|
|
327
376
|
)
|
|
328
377
|
kwargs["obbject_item"] = self._obbject.results
|
|
329
|
-
kwargs["charting_settings"] = self._charting_settings
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
kwargs["
|
|
338
|
-
self._obbject.provider
|
|
339
|
-
) # pylint: disable=protected-access
|
|
340
|
-
kwargs["extra"] = self._obbject.extra # pylint: disable=protected-access
|
|
341
|
-
|
|
342
|
-
if "kwargs" in kwargs:
|
|
343
|
-
_kwargs = kwargs.pop("kwargs")
|
|
344
|
-
kwargs.update(_kwargs.get("chart_params", {}))
|
|
378
|
+
kwargs["charting_settings"] = self._charting_settings #
|
|
379
|
+
kwargs["standard_params"] = (
|
|
380
|
+
self._obbject._standard_params # pylint: disable=protected-access
|
|
381
|
+
)
|
|
382
|
+
kwargs["extra_params"] = (
|
|
383
|
+
self._obbject._extra_params # pylint: disable=protected-access
|
|
384
|
+
)
|
|
385
|
+
kwargs["provider"] = self._obbject.provider
|
|
386
|
+
kwargs["extra"] = self._obbject.extra
|
|
345
387
|
fig, content = charting_function(**kwargs)
|
|
346
388
|
fig = self._set_chart_style(fig)
|
|
347
389
|
content = fig.show(external=True, **kwargs).to_plotly_json()
|
|
348
|
-
self._obbject.chart = Chart(
|
|
349
|
-
fig=fig, content=content, format=charting_router.CHART_FORMAT
|
|
350
|
-
)
|
|
390
|
+
self._obbject.chart = Chart(fig=fig, content=content, format=self._format)
|
|
351
391
|
if render:
|
|
352
392
|
fig.show(**kwargs)
|
|
353
393
|
except Exception: # pylint: disable=W0718
|
|
@@ -356,7 +396,7 @@ class Charting:
|
|
|
356
396
|
fig = self._set_chart_style(fig)
|
|
357
397
|
content = fig.show(external=True, **kwargs).to_plotly_json() # type: ignore
|
|
358
398
|
self._obbject.chart = Chart(
|
|
359
|
-
fig=fig, content=content, format=
|
|
399
|
+
fig=fig, content=content, format=self._format
|
|
360
400
|
)
|
|
361
401
|
if render:
|
|
362
402
|
return fig.show(**kwargs) # type: ignore
|
|
@@ -372,11 +412,11 @@ class Charting:
|
|
|
372
412
|
Union[
|
|
373
413
|
list,
|
|
374
414
|
dict,
|
|
375
|
-
|
|
376
|
-
List[
|
|
377
|
-
|
|
378
|
-
List[
|
|
379
|
-
|
|
415
|
+
"DataFrame",
|
|
416
|
+
List["DataFrame"],
|
|
417
|
+
"Series",
|
|
418
|
+
List["Series"],
|
|
419
|
+
"ndarray",
|
|
380
420
|
Data,
|
|
381
421
|
]
|
|
382
422
|
] = None,
|
|
@@ -398,7 +438,7 @@ class Charting:
|
|
|
398
438
|
|
|
399
439
|
Parameters
|
|
400
440
|
----------
|
|
401
|
-
data : Union[Data,
|
|
441
|
+
data : Union[Data, DataFrame, Series]
|
|
402
442
|
Data to be plotted.
|
|
403
443
|
indicators : Dict[str, Dict[str, Any]], optional
|
|
404
444
|
Indicators to be plotted, by default None
|
|
@@ -450,22 +490,14 @@ class Charting:
|
|
|
450
490
|
kwargs["index"] = index
|
|
451
491
|
kwargs["obbject_item"] = self._obbject.results
|
|
452
492
|
kwargs["charting_settings"] = self._charting_settings
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
):
|
|
457
|
-
kwargs["standard_params"] = (
|
|
458
|
-
self._obbject._standard_params.__dict__ # pylint: disable=protected-access
|
|
459
|
-
)
|
|
460
|
-
kwargs["provider"] = self._obbject.provider # pylint: disable=protected-access
|
|
461
|
-
kwargs["extra"] = self._obbject.extra # pylint: disable=protected-access
|
|
462
|
-
metadata = kwargs["extra"].get("metadata")
|
|
493
|
+
kwargs["standard_params"] = (
|
|
494
|
+
self._obbject._standard_params # pylint: disable=protected-access
|
|
495
|
+
)
|
|
463
496
|
kwargs["extra_params"] = (
|
|
464
|
-
|
|
497
|
+
self._obbject._extra_params # pylint: disable=protected-access
|
|
465
498
|
)
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
kwargs.update(_kwargs.get("chart_params", {}))
|
|
499
|
+
kwargs["provider"] = self._obbject.provider # pylint: disable=protected-access
|
|
500
|
+
kwargs["extra"] = self._obbject.extra # pylint: disable=protected-access
|
|
469
501
|
try:
|
|
470
502
|
if has_data:
|
|
471
503
|
self.show(data=data_as_df, render=render, **kwargs)
|
|
@@ -477,7 +509,7 @@ class Charting:
|
|
|
477
509
|
fig = self._set_chart_style(fig)
|
|
478
510
|
content = fig.show(external=True, **kwargs).to_plotly_json() # type: ignore
|
|
479
511
|
self._obbject.chart = Chart(
|
|
480
|
-
fig=fig, content=content, format=
|
|
512
|
+
fig=fig, content=content, format=self._format
|
|
481
513
|
)
|
|
482
514
|
if render:
|
|
483
515
|
return fig.show(**kwargs) # type: ignore
|
|
@@ -486,9 +518,9 @@ class Charting:
|
|
|
486
518
|
"Failed to automatically create a generic chart with the data provided."
|
|
487
519
|
) from e
|
|
488
520
|
|
|
489
|
-
def _set_chart_style(self, figure: Figure):
|
|
521
|
+
def _set_chart_style(self, figure: "Figure"):
|
|
490
522
|
"""Set the user preference for light or dark mode."""
|
|
491
|
-
style = self._charting_settings.chart_style
|
|
523
|
+
style = self._charting_settings.chart_style
|
|
492
524
|
font_color = "black" if style == "light" else "white"
|
|
493
525
|
paper_bgcolor = "white" if style == "light" else "black"
|
|
494
526
|
figure = figure.update_layout(
|
|
@@ -498,7 +530,7 @@ class Charting:
|
|
|
498
530
|
)
|
|
499
531
|
return figure
|
|
500
532
|
|
|
501
|
-
def toggle_chart_style(self):
|
|
533
|
+
def toggle_chart_style(self):
|
|
502
534
|
"""Toggle the chart style between light and dark mode."""
|
|
503
535
|
if not hasattr(self._obbject.chart, "fig"):
|
|
504
536
|
raise ValueError(
|
|
@@ -516,21 +548,24 @@ class Charting:
|
|
|
516
548
|
|
|
517
549
|
def table(
|
|
518
550
|
self,
|
|
519
|
-
data: Optional[Union[
|
|
551
|
+
data: Optional[Union["DataFrame", "Series"]] = None,
|
|
520
552
|
title: str = "",
|
|
521
553
|
):
|
|
522
554
|
"""Display an interactive table.
|
|
523
555
|
|
|
524
556
|
Parameters
|
|
525
557
|
----------
|
|
526
|
-
data : Optional[Union[
|
|
558
|
+
data : Optional[Union[DataFrame, Series]], optional
|
|
527
559
|
Data to be plotted, by default None.
|
|
528
560
|
If no data is provided the OBBject results will be used.
|
|
529
561
|
title : str, optional
|
|
530
562
|
Title of the table, by default "".
|
|
531
563
|
"""
|
|
564
|
+
# pylint: disable=import-outside-toplevel
|
|
565
|
+
from pandas import RangeIndex
|
|
566
|
+
|
|
532
567
|
data_as_df, _ = self._prepare_data_as_df(data)
|
|
533
|
-
if isinstance(data_as_df.index,
|
|
568
|
+
if isinstance(data_as_df.index, RangeIndex):
|
|
534
569
|
data_as_df.reset_index(inplace=True, drop=True)
|
|
535
570
|
else:
|
|
536
571
|
data_as_df.reset_index(inplace=True)
|
|
@@ -546,9 +581,7 @@ class Charting:
|
|
|
546
581
|
warn(f"Failed to show figure with backend. {e}")
|
|
547
582
|
|
|
548
583
|
else:
|
|
549
|
-
from plotly import
|
|
550
|
-
optional_imports,
|
|
551
|
-
)
|
|
584
|
+
from plotly import optional_imports
|
|
552
585
|
|
|
553
586
|
ipython_display = optional_imports.get_module("IPython.display")
|
|
554
587
|
if ipython_display:
|