code: def _maybe_resample_data(
      resample_rule, df, indicators, equity_data, trades
  ):
      if isinstance(resample_rule, str):
          freq = resample_rule
      else:
          if resample_rule is False or len(df) <= _MAX_CANDLES:
              return df, indicators, equity_data, trades
  
          freq_minutes = pd.Series(
              {
                  "1T": 1,
                  "5T": 5,
                  "10T": 10,
                  "15T": 15,
                  "30T": 30,
                  "1H": 60,
                  "2H": 60 * 2,
                  "4H": 60 * 4,
                  "8H": 60 * 8,
                  "1D": 60 * 24,
                  "1W": 60 * 24 * 7,
                  "1M": np.inf,
              }
          )
          timespan = df.index[-1] - df.index[0]
          require_minutes = (
              timespan / _MAX_CANDLES
          ).total_seconds() // 60
          freq = freq_minutes.where(
              freq_minutes >= require_minutes
          ).first_valid_index()
          warnings.warn(
              f"Data contains too many candlesticks to plot; downsampling to {freq!r}. "
              "See `Backtest.plot(resample=...)`"
          )
  
      from .lib import OHLCV_AGG, TRADES_AGG, _EQUITY_AGG
  
      df = df.resample(freq, label="right").agg(OHLCV_AGG).dropna()
  
      indicators = [
          _Indicator(
              i.df.resample(freq, label="right")
              .mean()
              .dropna()
              .reindex(df.index)
              .values.T,
              **dict(
                  i._opts,
                  name=i.name,
                  # Replace saved index with the resampled one
                  index=df.index,
              ),
          )
          for i in indicators
      ]
      assert not indicators or indicators[0].df.index.equals(df.index)
  
      equity_data = (
          equity_data.resample(freq, label="right")
          .agg(_EQUITY_AGG)
          .dropna(how="all")
      )
      assert equity_data.index.equals(df.index)
  
      def _weighted_returns(s, trades=trades):
          df = trades.loc[s.index]
          return (
              (df["Size"].abs() * df["ReturnPct"])
              / df["Size"].abs().sum()
          ).sum()
  
      def _group_trades(column):
          def f(
              s,
              new_index=pd.Index(df.index.view(int)),
              bars=trades[column],
          ):
              if s.size:
                  # Via int64 because on pandas recently broken datetime
                  mean_time = int(bars.loc[s.index].view(int).mean())
                  new_bar_idx = new_index.get_indexer(
                      [mean_time], method="nearest"
                  )[0]
                  return new_bar_idx
  
          return f
  
      if len(trades):  # Avoid pandas "resampling on Int64 index" error
          trades = (
              trades.assign(count=1)
              .resample(freq, on="ExitTime", label="right")
              .agg(
                  dict(
                      TRADES_AGG,
                      ReturnPct=_weighted_returns,
                      count="sum",
                      EntryBar=_group_trades("EntryTime"),
                      ExitBar=_group_trades("ExitTime"),
                  )
              )
              .dropna()
          )
  
      return df, indicators, equity_data, trades
  
imports: import os
  import re
  import sys
  import warnings
  from colorsys import hls_to_rgb, rgb_to_hls
  from itertools import cycle, combinations
  from functools import partial
  from typing import Callable, List, Union
  import numpy
  import pandas
  from bokeh.colors import RGB
  from bokeh.colors.named import lime, tomato
  from bokeh.plotting import figure
  from bokeh.models import CrosshairTool, CustomJS, ColumnDataSource, NumeralTickFormatter, Span, HoverTool, Range1d, DatetimeTickFormatter, WheelZoomTool, LinearColorMapper
  from bokeh.io import output_notebook, output_file, show
  from bokeh.io.state import curstate
  from bokeh.layouts import gridplot
  from bokeh.palettes import Category10
  from bokeh.transform import factor_cmap
  from backtesting._util import _data_period, _as_list, _Indicator
label_desc: Use image node_id 6 for calling a global function with example usage: _maybe_resample_data(resample_rule, df, indicators, equity_data, trades) and returns: df,  indicators,  equity_data,  trades, unknown, f, df,  indicators,  equity_data,  trades, new_bar_idx