3535class AbstractFigureAggregator (BaseFigure , ABC ):
3636 """Abstract interface for data aggregation functionality for plotly figures."""
3737
38- _high_frequency_traces = ["scatter" , "scattergl" ] # TODO maybe change this
38+ _high_frequency_traces = ["scatter" , "scattergl" ]
3939
4040 def __init__ (
4141 self ,
@@ -96,7 +96,8 @@ def __init__(
9696
9797 self ._global_downsampler = default_downsampler
9898
99- # Given figure should always be a BaseFigure (that is not wrapped by a plotly-resampler class)
99+ # Given figure should always be a BaseFigure that is not wrapped by
100+ # a plotly-resampler class
100101 assert isinstance (figure , BaseFigure )
101102 assert not issubclass (type (figure ), AbstractFigureAggregator )
102103 self ._figure_class = figure .__class__
@@ -445,8 +446,8 @@ def _get_figure_class(constr: type) -> type:
445446 The plotly figure class (constructor) of the given `constr`.
446447
447448 """
448- from ..registering import get_plotly_constr # To avoid ImportError
449- return get_plotly_constr (constr )
449+ from ..registering import _get_plotly_constr # To avoid ImportError
450+ return _get_plotly_constr (constr )
450451
451452 @staticmethod
452453 def _slice_time (
@@ -565,31 +566,31 @@ def _to_hf_series(x: np.ndarray, y: np.ndarray) -> pd.Series:
565566 def _parse_get_trace_props (
566567 self ,
567568 trace : BaseTraceType ,
568- hf_x = None ,
569- hf_y = None ,
570- hf_text = None ,
571- hf_hovertext = None ,
569+ hf_x : Iterable = None ,
570+ hf_y : Iterable = None ,
571+ hf_text : Iterable = None ,
572+ hf_hovertext : Iterable = None ,
572573 ) -> _hf_data_container :
573574 """Parse and capture the possibly high-frequency trace-props in a datacontainer.
574575
575576 Parameters
576577 ----------
577578 trace : BaseTraceType
578579 The trace which will be parsed.
579- hf_x : _type_ , optional
580- high-frequency trace "x" data, overrides the current trace its x-data
581- hf_y : _type_ , optional
582- high-frequency trace "y" data, overrides the current trace its y-data
583- hf_text : _type_ , optional
580+ hf_x : Iterable , optional
581+ high-frequency trace "x" data, overrides the current trace its x-data.
582+ hf_y : Iterable , optional
583+ high-frequency trace "y" data, overrides the current trace its y-data.
584+ hf_text : Iterable , optional
584585 high-frequency trace "text" data, overrides the current trace its text-data.
585- hf_hovertext : _type_ , optional
586+ hf_hovertext : Iterable , optional
586587 high-frequency trace "hovertext" data, overrides the current trace its
587588 hovertext data.
588589
589590 Returns
590591 -------
591592 _hf_data_container
592- A namedtuple which serves as a datacontainer
593+ A namedtuple which serves as a datacontainer.
593594
594595 """
595596 hf_x = (
@@ -695,8 +696,8 @@ def _parse_get_trace_props(
695696
696697 def _construct_hf_data_dict (
697698 self ,
698- dc ,
699- trace ,
699+ dc : _hf_data_container ,
700+ trace : BaseTraceType ,
700701 downsampler : AbstractSeriesAggregator | None ,
701702 max_n_samples : int | None ,
702703 offset = 0 ,
@@ -706,7 +707,7 @@ def _construct_hf_data_dict(
706707 Parameters
707708 ----------
708709 dc : _hf_data_container
709- The hf_data container, withholding the parsed hf-data
710+ The hf_data container, withholding the parsed hf-data.
710711 trace : BaseTraceType
711712 The trace.
712713 downsampler : AbstractSeriesAggregator | None
@@ -720,7 +721,8 @@ def _construct_hf_data_dict(
720721 The hf_data dict.
721722 """
722723 # We will re-create this each time as hf_x and hf_y withholds
723- # high-frequency data
724+ # high-frequency data and can be adjusted on the fly with the public hf_data
725+ # property.
724726 hf_series = self ._to_hf_series (x = dc .x , y = dc .y )
725727
726728 # Checking this now avoids less interpretable `KeyError` when resampling
@@ -748,6 +750,9 @@ def _construct_hf_data_dict(
748750 default_downsampler = True
749751 downsampler = self ._global_downsampler
750752
753+ # TODO -> can't we just store the DC here (might be less duplication of
754+ # code knowledge, because now, you need to know all the eligible hf_keys in
755+ # dc
751756 return {
752757 "max_n_samples" : max_n_samples ,
753758 "default_n_samples" : default_n_samples ,
@@ -885,6 +890,8 @@ def add_trace(
885890 uuid_str = str (uuid4 ()) if trace .uid is None else trace .uid
886891 trace .uid = uuid_str
887892
893+ # construct the hf_data_container
894+ # TODO in future version -> maybe regex on kwargs which start with `hf_`
888895 dc = self ._parse_get_trace_props (trace , hf_x , hf_y , hf_text , hf_hovertext )
889896
890897 n_samples = len (dc .x )
@@ -922,6 +929,7 @@ def add_trace(
922929 return super (self ._figure_class , self ).add_trace (trace , ** trace_kwargs )
923930 else :
924931 self ._print (f"[i] NOT resampling { trace ['name' ]} - len={ n_samples } " )
932+ # TODO: can be made more generic
925933 trace .x = dc .x
926934 trace .y = dc .y
927935 trace .text = dc .text
@@ -940,10 +948,10 @@ def add_traces(
940948 limit_to_views : List [bool ] | bool = False ,
941949 ** traces_kwargs ,
942950 ):
943- """Add traces to the figure
951+ """Add traces to the figure.
944952
945953 .. note::
946- make sure to look at the :func:`add_trace` function for more info about
954+ Make sure to look at the :func:`add_trace` function for more info about
947955 **speed optimization**, and dealing with not ``high-frequency`` data, but
948956 still want to resample / limit the data to the front-end view.
949957
@@ -954,7 +962,7 @@ def add_traces(
954962 Trace specifications may be either:
955963
956964 - Instances of trace classes from the plotly.graph_objs
957- package (e.g plotly.graph_objs.Scatter, plotly.graph_objs.Bar)
965+ package (e.g plotly.graph_objs.Scatter, plotly.graph_objs.Bar).
958966 - Dicts where:
959967
960968 - The 'type' property specifies the trace type (e.g.
@@ -992,7 +1000,7 @@ def add_traces(
9921000 if not isinstance (data , (list , tuple )):
9931001 data = [data ]
9941002
995- # Convert each trace into a trace object
1003+ # Convert each trace into a BaseTraceType object
9961004 data = [
9971005 self ._data_validator .validate_coerce (trace )[0 ]
9981006 if not isinstance (trace , BaseTraceType )
@@ -1036,9 +1044,11 @@ def add_traces(
10361044 offset = i ,
10371045 )
10381046
1039- trace = trace ._props # convert the trace into a dict
1047+ # convert the trace into a dict, and only withholds the non-hf props
1048+ trace = trace ._props
10401049 trace = {k : trace [k ] for k in set (trace .keys ()).difference (set (dc ._fields ))}
10411050
1051+ # update the trace data with the HF props
10421052 trace = self ._check_update_trace_data (trace )
10431053 assert trace is not None
10441054 data [i ] = trace
@@ -1071,14 +1081,16 @@ def _copy_hf_data(self, hf_data: dict, adjust_default_values: bool = False) -> d
10711081 The copied (& default values adjusted) output dict.
10721082
10731083 """
1084+ # TODO: add pass by reference tests for this method
10741085 hf_data_cp = {
1075- k : {
1076- k_ : hf_data [ k ][ k_ ]
1077- for k_ in set (v .keys ()) # .difference(_hf_data_container._fields )
1086+ uid : {
1087+ k : hf_dict [ k ]
1088+ for k in set (hf_dict .keys ())
10781089 }
1079- for k , v in hf_data .items ()
1090+ for uid , hf_dict in hf_data .items ()
10801091 }
10811092
1093+ # Adjust the default arguments to the current argument values
10821094 if adjust_default_values :
10831095 for hf_props in hf_data_cp .values ():
10841096 if hf_props .get ("default_downsampler" , False ):
0 commit comments