def _build_graph(self, datas, inds, obs): self._data_graph = {} self._volume_graphs = [] for d in datas: if not d.plotinfo.plot: continue pmaster = Bokeh._resolve_plotmaster(d.plotinfo.plotmaster) if pmaster is None: self._data_graph[d] = [] else: if pmaster not in self._data_graph: self._data_graph[pmaster] = [] self._data_graph[pmaster].append(d) if self.p.scheme.volume and self.p.scheme.voloverlay is False: self._volume_graphs.append(d) # Sort observers in the different lists/dictionaries for o in obs: if not o.plotinfo.plot or o.plotinfo.plotskip: continue if o.plotinfo.subplot: self._data_graph[o] = [] else: pmaster = Bokeh._resolve_plotmaster(o.plotinfo.plotmaster or o.data) if pmaster not in self._data_graph: self._data_graph[pmaster] = [] self._data_graph[pmaster].append(o) for ind in inds: if not hasattr(ind, 'plotinfo'): # no plotting support - so far LineSingle derived classes continue # should this indicator be plotted? if not ind.plotinfo.plot or ind.plotinfo.plotskip: continue # subplot = create a new figure for this indicator subplot = ind.plotinfo.subplot if subplot: self._data_graph[ind] = [] else: pm = ind.plotinfo.plotmaster if ind.plotinfo.plotmaster is not None else ind.data pm = get_data_obj(pm) pmaster = Bokeh._resolve_plotmaster(pm) if pmaster not in self._data_graph: self._data_graph[pmaster] = [] self._data_graph[pmaster].append(ind)
def _plot_indicator_observer(self, obj: Union[bt.Indicator, bt.Observer], master, strat_clk: array = None): pl = plotobj2label(obj) self._figure_append_title(pl) indlabel = obj.plotlabel() plotinfo = obj.plotinfo for lineidx in range(obj.size()): line = obj.lines[lineidx] source_id = Figure._source_id(line) linealias = obj.lines._getlinealias(lineidx) lineplotinfo = getattr(obj.plotlines, '_%d' % lineidx, None) if not lineplotinfo: lineplotinfo = getattr(obj.plotlines, linealias, None) if not lineplotinfo: lineplotinfo = bt.AutoInfoClass() if lineplotinfo._get('_plotskip', False): continue marker = lineplotinfo._get("marker", None) method = lineplotinfo._get('_method', "line") color = getattr(lineplotinfo, "color", None) if color is None: if not lineplotinfo._get('_samecolor', False): self._nextcolor() color = self._color() color = convert_color(color) kwglyphs = {'name': linealias} dataline = line.plotrange(self._start, self._end) line_clk = get_data_obj(obj).lines.datetime.plotrange( self._start, self._end) dataline = resample_line(dataline, line_clk, strat_clk) self._add_to_cds(dataline, source_id) label = None if master is None or lineidx == 0 or plotinfo.plotlinelabels: label = indlabel if master is None or plotinfo.plotlinelabels: label += " " + (lineplotinfo._get("_name", "") or linealias) kwglyphs['legend_label'] = label if marker is not None: kwglyphs['size'] = lineplotinfo.markersize * 1.2 kwglyphs['color'] = color kwglyphs['y'] = source_id mrk_fncs = { '^': self.figure.triangle, 'v': self.figure.inverted_triangle, 'o': self.figure.circle, '<': self.figure.circle_cross, '>': self.figure.circle_x, '1': self.figure.diamond, '2': self.figure.diamond_cross, '3': self.figure.hex, '4': self.figure.square, '8': self.figure.square_cross, 's': self.figure.square_x, 'p': self.figure.triangle, '*': self.figure.asterisk, 'h': self.figure.hex, 'H': self.figure.hex, '+': self.figure.asterisk, 'x': self.figure.x, 'D': self.figure.diamond_cross, 'd': self.figure.diamond, } if marker not in mrk_fncs: raise Exception( f"Sorry, unsupported marker: '{marker}'. Please report to GitHub." ) glyph_fnc = mrk_fncs[marker] elif method == "bar": kwglyphs['bottom'] = 0 kwglyphs['line_color'] = 'black' kwglyphs['fill_color'] = color kwglyphs['width'] = get_bar_width() kwglyphs['top'] = source_id glyph_fnc = self.figure.vbar elif method == "line": kwglyphs['line_width'] = 1 kwglyphs['color'] = color kwglyphs['y'] = source_id linestyle = getattr(lineplotinfo, "ls", None) if linestyle is not None: kwglyphs['line_dash'] = convert_linestyle(linestyle) glyph_fnc = self.figure.line else: raise Exception(f"Unknown plotting method '{method}'") renderer = glyph_fnc("index", source=self._cds, **kwglyphs) # for markers add additional renderer so hover pops up for all of them if marker is None: self._set_single_hover_renderer(renderer) else: self._add_hover_renderer(renderer) hover_label_suffix = f" - {linealias}" if obj.size( ) > 1 else "" # we need no suffix if there is just one line in the indicator anyway hover_label = indlabel + hover_label_suffix hover_data = f"@{source_id}{{{self._scheme.number_format}}}" self._hoverc.add_hovertip(hover_label, hover_data, obj) # adapt y-axis if needed if master is None or getattr(master.plotinfo, 'plotylimited', False) is False: adapt_yranges(self.figure.y_range, dataline) self._set_yticks(obj) self._plot_hlines(obj)