@@ -173,6 +173,27 @@ def test_box_histogram(float_series):
173
173
)
174
174
175
175
176
+ def test_add_traces_from_other_figure ():
177
+ labels = ["Investing" , "Liquid" , "Real Estate" , "Retirement" ]
178
+ values = [324643.4435821581 , 112238.37140194925 , 2710711.06 , 604360.2864262027 ]
179
+
180
+ changes_section = FigureResampler (
181
+ make_subplots (
182
+ rows = 1 ,
183
+ cols = 2 ,
184
+ subplot_titles = ("Asset Allocation" , "Changes in last 12 hours" ),
185
+ specs = [[{"type" : "pie" }, {"type" : "xy" }]],
186
+ )
187
+ )
188
+
189
+ # First create a pie chart Figure
190
+ pie_total = go .Figure (data = [go .Pie (labels = labels , values = values )])
191
+
192
+ # Add the pie chart traces to the changes_section figure
193
+ for trace in pie_total .data :
194
+ changes_section .add_trace (trace , row = 1 , col = 1 )
195
+
196
+
176
197
def test_cat_box_histogram (float_series ):
177
198
# Create a categorical series, with mostly a's, but a few sparse b's and c's
178
199
cats_list = np .array (list ("aaaaaaaaaa" * 1000 ))
@@ -620,7 +641,9 @@ def test_stop_server_inline_persistent():
620
641
fr .add_trace (go .Scattergl (name = "test" ), hf_x = x , hf_y = y )
621
642
fr .update_layout (height = 900 )
622
643
fr .stop_server ()
623
- proc = multiprocessing .Process (target = fr .show_dash , kwargs = dict (mode = "inline_persistent" ))
644
+ proc = multiprocessing .Process (
645
+ target = fr .show_dash , kwargs = dict (mode = "inline_persistent" )
646
+ )
624
647
proc .start ()
625
648
626
649
time .sleep (3 )
@@ -640,8 +663,11 @@ def test_manual_jupyterdashpersistentinline():
640
663
641
664
# no need to start the app (we just need the FigureResampler object)
642
665
643
- from plotly_resampler .figure_resampler .figure_resampler import JupyterDashPersistentInlineOutput
666
+ from plotly_resampler .figure_resampler .figure_resampler import (
667
+ JupyterDashPersistentInlineOutput ,
668
+ )
644
669
import dash
670
+
645
671
app = JupyterDashPersistentInlineOutput ("manual_app" )
646
672
assert hasattr (app , "_uid" )
647
673
@@ -650,17 +676,15 @@ def test_manual_jupyterdashpersistentinline():
650
676
# JupyterDashPersistentInline its _display_inline_output method (to create the img)
651
677
app .layout = dash .html .Div (
652
678
[
653
- dash .dcc .Graph (
654
- id = "resample-figure" , figure = fr
655
- ),
679
+ dash .dcc .Graph (id = "resample-figure" , figure = fr ),
656
680
# no need to add traceupdater for this dummy app
657
681
]
658
682
)
659
683
660
684
# call the method (as it would normally be called)
661
- app ._display_in_jupyter (f"" , port = "" , mode = "inline" , width = ' 100%' , height = 500 )
685
+ app ._display_in_jupyter (f"" , port = "" , mode = "inline" , width = " 100%" , height = 500 )
662
686
# call with a different mode (as it normally never would be called)
663
- app ._display_in_jupyter (f"" , port = "" , mode = "external" , width = ' 100%' , height = 500 )
687
+ app ._display_in_jupyter (f"" , port = "" , mode = "external" , width = " 100%" , height = 500 )
664
688
665
689
666
690
def test_stop_server_external ():
@@ -977,7 +1001,9 @@ def test_fr_object_bool_data(bool_series):
977
1001
978
1002
979
1003
def test_fr_object_binary_data ():
980
- binary_series = np .array ([0 , 1 ]* 20 , dtype = "int32" ) # as this is << max_n_samples -> limit_to_view
1004
+ binary_series = np .array (
1005
+ [0 , 1 ] * 20 , dtype = "int32"
1006
+ ) # as this is << max_n_samples -> limit_to_view
981
1007
982
1008
# First try with the original non-object binary series
983
1009
fig = FigureResampler ()
@@ -994,7 +1020,9 @@ def test_fr_object_binary_data():
994
1020
fig .add_trace ({"name" : "s0" }, hf_y = binary_series_o , limit_to_view = True )
995
1021
assert binary_series_o .dtype == object
996
1022
assert len (fig .hf_data ) == 1
997
- assert (fig .hf_data [0 ]["y" ].dtype == "int32" ) or (fig .hf_data [0 ]["y" ].dtype == "int64" )
1023
+ assert (fig .hf_data [0 ]["y" ].dtype == "int32" ) or (
1024
+ fig .hf_data [0 ]["y" ].dtype == "int64"
1025
+ )
998
1026
assert str (fig .data [0 ]["y" ].dtype ).startswith ("int" )
999
1027
assert np .all (fig .data [0 ]["y" ] == binary_series )
1000
1028
@@ -1015,7 +1043,7 @@ def test_fr_copy_grid():
1015
1043
assert fr ._grid_ref == f ._grid_ref
1016
1044
assert fr ._grid_str is not None
1017
1045
assert fr ._grid_str == f ._grid_str
1018
-
1046
+
1019
1047
## go.FigureWidget
1020
1048
fw = go .FigureWidget (f )
1021
1049
assert fw ._grid_ref is not None
@@ -1040,6 +1068,7 @@ def test_fr_copy_grid():
1040
1068
1041
1069
## FigureWidgetResampler
1042
1070
from plotly_resampler import FigureWidgetResampler
1071
+
1043
1072
fwr = FigureWidgetResampler (f )
1044
1073
assert fwr ._grid_ref is not None
1045
1074
assert fwr ._grid_str is not None
0 commit comments