Example #1
0
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)
Example #2
0
class PivotTable(HTMLBox):
    """A Bokeh Model that enables easy use of perspective-viewer widget
    """

    # pylint: disable=line-too-long
    __javascript__ = [
        "https://code.jquery.com/jquery-3.5.1.min.js",
        "https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js",
        "https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.13.0/pivot.min.js",
    ]

    __js_skip__ = {
        "pivottable": __javascript__[2:3],
    }

    __js_require__ = {
        "paths": {
            "pivottable":
            "https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.13.0/pivot.min",
        },
        "exports": {
            "pivottable": "PivotTable",
        },
    }

    __css__ = [
        "https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.13.0/pivot.min.css"
    ]

    # pylint: enable=line-too-long

    source = properties.Instance(ColumnDataSource)
    source_stream = properties.Instance(ColumnDataSource)
    source_patch = properties.Instance(ColumnDataSource)
class TabulatorModel(HTMLBox):
    """A Bokeh Model that enables easy use of Tabulator tables

    See http://tabulator.info/
    """

    __javascript__ = [
        MOMENT_SRC,
        JS_SRC,
    ]

    # I could not get Tabulator loaded in Notebook
    # I found a working solution using requirejs the notebook
    # I'm working on getting the below working.
    # See https://github.com/holoviz/panel/issues/1529
    __js_skip__ = {"Tabulator": __javascript__[1:]}

    __js_require__ = {
        "paths": {
            "tabulator":
            ["https://unpkg.com/[email protected]/dist/js/tabulator.min"]
        },
        "exports": {
            "tabulator": "Tabulator"
        },
    }

    # __css__ = [CSS_HREFS["default"]]

    configuration = properties.Dict(properties.String, properties.Any)
    source = properties.Instance(ColumnDataSource)
    _cell_change = properties.Dict(properties.String, properties.Any)
def list_param_to_ppt(p, kwargs):
    if isinstance(p.item_type, type) and issubclass(p.item_type,
                                                    pm.Parameterized):
        return bp.List(bp.Instance(DataModel)), [
            (ParameterizedList,
             lambda ps: [create_linked_datamodel(p) for p in ps])
        ]
    return bp.List(bp.Any, **kwargs)
Example #5
0
class Sankey(bk_models.LayoutDOM):
    """
    TODO
        - manipulate the CDS into a tree structure in this class? then wont dynamically update if change inputs tho
        - other options to pass, node spacing/colouring?
    """
    # __implementation__ = "static/own_js/sankey.js"
    __implementation__ = os.path.join(os.path.dirname(__file__), "sankey.js")

    source = bk_properties.Instance(bk_models.ColumnDataSource)
Example #6
0
File: main.py Project: eegml/eegvis
class KeyboardResponder(LayoutDOM):
    #__implementation__ = TypeScript(KEYBOARDRESPONDERCODE_TS)
    __implementation__ = "keyboardresponder.ts"
    # can use # __css__ = '<a css file.css>'
    # can use # __javascript__ = 'katex.min.js'
    keycode = properties.Int(default=0) # this should match with javascript
    key_num_presses = properties.Int(default=0)
    keypress_callback = properties.Instance(bokeh.models.callbacks.Callback,
                                   help=""" A callback to run in the browser whenever a key is pressed
                                   """)
class WebComponent(HTMLBox):
    """A Bokeh Model that enables easily creating new Panel components from web components

    See https://www.predix-ui.com/#/elements/px-app-nav"""

    componentType = properties.String("htmlbox")
    innerHTML = properties.String("")
    attributesToWatch = properties.Dict(properties.String, properties.Any)
    attributesLastChange = properties.Dict(properties.String, properties.Any)
    propertiesToWatch = properties.Dict(properties.String, properties.Any)
    propertiesLastChange = properties.Dict(properties.String, properties.Any)
    eventsToWatch = properties.Dict(properties.String, properties.Any)
    eventsCountLastChange = properties.Dict(properties.String, properties.Int)
    columnDataSource = properties.Instance(ColumnDataSource)
    columnDataSourceOrient = properties.String()
    columnDataSourceLoadFunction = properties.String()
Example #8
0
File: main.py Project: eegml/eegvis
class KeyModResponder(LayoutDOM):
    """capture all aspects of keydown/up events"""
    #__implementation__ = TypeScript(KEYBOARDRESPONDERCODE_TS)
    __implementation__ = "keymodresponder.ts"
    # can use # __css__ = '<a css file.css>'
    # can use # __javascript__ = 'katex.min.js' # for additional javascript
    # this should match with javascript/typescript implementation 
    key = properties.String(default="")
    keyCode = properties.Int(default=0) 
    altKey = properties.Bool(default=False)
    ctrlKey = properties.Bool(default=False)
    metaKey = properties.Bool(default=False)
    shiftKey = properties.Bool(default=False)
    
    key_num_presses = properties.Int(default=0)
    
    keypress_callback = properties.Instance(bokeh.models.callbacks.Callback,
                                   help=""" A callback to run in the browser whenever a key is pressed
                                   """)
Example #9
0
class DpxCleaning(Widget):
    "Interface to filters needed for cleaning"
    __css__ = route("cleaning.css")
    __javascript__ = route()
    __implementation__ = "_widget.ts"
    frozen = props.Bool(True)
    framerate = props.Float(30.)
    figure = props.Instance(Figure)
    fixedbeads = props.String("")
    subtracted = props.String("")
    subtractcurrent = props.Int(0)

    maxabsvalue = props.Float(getattr(DataCleaningTask, 'maxabsvalue'))
    maxderivate = props.Float(getattr(DataCleaningTask, 'maxderivate'))
    minpopulation = props.Float(getattr(DataCleaningTask, 'minpopulation'))
    minhfsigma = props.Float(getattr(DataCleaningTask, 'minhfsigma'))
    maxhfsigma = props.Float(getattr(DataCleaningTask, 'maxhfsigma'))
    minextent = props.Float(getattr(DataCleaningTask, 'minextent'))
    maxextent = props.Float(getattr(DataCleaningTask, 'maxextent'))
    maxsaturation = props.Float(getattr(DataCleaningTask, 'maxsaturation'))
Example #10
0
        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:
    lambda p, kwargs: bp.Dict(bp.String, bp.Any, **kwargs),
    pm.Event:
Example #11
0
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)