class ReactiveHTML(HTMLBox): attrs = bp.Dict( bp.String, bp.List(bp.Tuple(bp.String, bp.List(bp.String), bp.String))) callbacks = bp.Dict(bp.String, bp.List(bp.Tuple(bp.String, bp.String))) children = bp.Dict(bp.String, bp.List(bp.Either(bp.Instance(LayoutDOM), bp.String))) data = bp.Instance(DataModel) events = bp.Dict(bp.String, bp.Dict(bp.String, bp.Bool)) html = bp.String() looped = bp.List(bp.String) nodes = bp.List(bp.String) scripts = bp.Dict(bp.String, bp.List(bp.String)) def __init__(self, **props): if 'attrs' not in props and 'html' in props: props['attrs'] = find_attrs(props['html']) super().__init__(**props)
msg = "" if not detail else f"expected param.Parameterized, got {value!r}" raise ValueError(msg) _DATA_MODELS = weakref.WeakKeyDictionary() PARAM_MAPPING = { pm.Array: lambda p, kwargs: bp.Array(bp.Any, **kwargs), pm.Boolean: lambda p, kwargs: bp.Bool(**kwargs), pm.CalendarDate: lambda p, kwargs: bp.Date(**kwargs), pm.CalendarDateRange: lambda p, kwargs: bp.Tuple(bp.Date, bp.Date, **kwargs), pm.ClassSelector: lambda p, kwargs: ((bp.Instance(DataModel, **kwargs), [ (Parameterized, create_linked_datamodel) ]) if isinstance(p.class_, type) and issubclass( p.class_, param.Parameterized) else bp.Any(**kwargs)), pm.Color: lambda p, kwargs: bp.Color(**kwargs), pm.DataFrame: lambda p, kwargs: (bp.ColumnData(bp.Any, bp.Seq(bp.Any), **kwargs), [( bp.PandasDataFrame, lambda x: ColumnDataSource._data_from_df(x))]), pm.DateRange: lambda p, kwargs: bp.Tuple(bp.Datetime, bp.Datetime, **kwargs), pm.Date: lambda p, kwargs: bp.Datetime(**kwargs), pm.Dict:
class DpxHoverModel( HoverTool, # pylint: disable=too-many-instance-attributes,too-many-ancestors SequenceHoverMixin): "controls keypress actions" maxcount = props.Int(3) framerate = props.Float(1.) shape = props.Tuple(props.Int, props.Int, default=(0, 0)) cycle = props.Int(-1) bias = props.Float(0.) stretch = props.Float(0.) updating = props.String('') rawrend = props.Instance(Renderer) impl = SequenceHoverMixin.impl __implementation__ = impl( 'DpxHoverModel', { '_hvr_cnt': ('[p.Number, -1]', 'number'), 'shape': ('[p.Array, [2,1]]', 'number[]'), 'cycle': ('[p.Int, -1]', 'number'), 'rawrend': ('[p.Instance, null]', 'any') }, __file__) @staticmethod def _createrawdata(data, shape): return dict(t=data['t'][:shape[1]], z=data['z'][:shape[1]]) @staticmethod def __settooltips(fig, theme): tooltips = theme.tooltips hover = fig.select(DpxHoverTool) if tooltips is None or len(tooltips) == 0: if len(hover): hover[0].tooltips = None elif len(hover): name = theme.raw.glyph rend = [ i for i in fig.renderers if hasattr(i, 'glyph') and type(i.glyph).__name__.lower() == name ][0] hover[0].tooltips = tooltips hover[0].renderers = [rend] rend.selection_glyph = None rend.nonselection_glyph = None rend.glyph.radius_dimension = 'x' rend.glyph.radius = theme.radius def __settap(self, mdl, fig, source, theme): tap = fig.select(TapTool) if tap is not None and len(tap): src = ColumnDataSource(self._createrawdata(source.data, self.shape)) sel = themed(mdl, theme.selection) glyph = PlotAttrsView(sel).addto(fig, x='t', y='z', source=src) args = dict(hvr=self, hvrsrc=src, rawsrc=source, glyph=glyph) code = "hvr.launch_hover(rawsrc, hvrsrc, glyph)" self.rawrend = glyph source.callback = CustomJS(code=code, args=args) def createraw(self, mdl, fig, source, shape, theme): # pylint: disable=too-many-arguments "creates the hover tool" self.shape = tuple(shape) self.__settooltips(fig, theme) self.__settap(mdl, fig, source, theme) def slaveaxes(self, fig, src): "slaves a histogram's axes to its y-axis" fig.y_range.callback = CustomJS( code="hvr.on_change_hist_bounds(fig, src)", args=dict(hvr=self, fig=fig, src=src)) def resetraw(self, fig, rdata, shape, resets): "updates the tooltips for a new file" hover = fig.select(DpxHoverTool) if len(hover) == 0: return resets[self]['shape'] = shape if self.rawrend is not None: resets[self.rawrend]['visible'] = False resets[self.rawrend.data_source]['data'] = self._createrawdata( rdata, shape)