saraedum / ipyvue-time-series

Real-Time Plots in Jupyter
2 stars 0 forks source link

Customize widget layout and properties #38

Open DunklesArchipel opened 10 months ago

DunklesArchipel commented 10 months ago
          Indeed it would be great if it would be possible to

I figured that one has to modify by some means the template in the TimeSeries class. So a template, which allows drawing a rescaled plot with a title would look as follows.

template = Unicode(r"""
        <time-series v-slot="{ x, y }">
            <remote-component url="https://unpkg.com/vue-plotly@1.1.0/dist/vue-plotly.umd.min.js" integrity="sha384-3YjbENL4Izchmbn7RCdWL5tHYGPP7fy2B/vzCgBd3corbolRfPgjimXK4JEwGpYg" :extract="library => library.Plotly" :props="{
                data: [{ x: [...x], y: [...y], type: 'scatter' }],
                'display-mode-bar': false,
                layout:{'width': 100, 'height': 240, 'title': 'A Fancy Plot'},
                        }" />
        </time-series>
        """).tag(sync=True)

Originally posted by @DunklesArchipel in https://github.com/saraedum/ipyvue-time-series/issues/6#issuecomment-1786128678

DunklesArchipel commented 10 months ago

I tried to implement it by adding an __init__ to the Timeseries class, where you could for example define the width and the height. When you want to show the widget with

ts = TimeSeries() # this line does not throw an error
ts # this one does

one gets the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File C:\Miniconda3\envs\iok\lib\site-packages\IPython\core\formatters.py:973, in MimeBundleFormatter.__call__(self, obj, include, exclude)
    970     method = get_real_method(obj, self.print_method)
    972     if method is not None:
--> 973         return method(include=include, exclude=exclude)
    974     return None
    975 else:

File C:\Miniconda3\envs\iok\lib\site-packages\ipywidgets\widgets\widget.py:811, in Widget._repr_mimebundle_(self, **kwargs)
    799 data = {
    800     'text/plain': plaintext,
    801 }
    802 if self._view_name is not None:
    803     # The 'application/vnd.jupyter.widget-view+json' mimetype has not been registered yet.
    804     # See the registration process and naming convention at
    805     # http://tools.ietf.org/html/rfc6838
    806     # and the currently registered mimetypes at
    807     # http://www.iana.org/assignments/media-types/media-types.xhtml.
    808     data['application/vnd.jupyter.widget-view+json'] = {
    809         'version_major': 2,
    810         'version_minor': 0,
--> 811         'model_id': self._model_id
    812     }
    813     return data

AttributeError: 'TimeSeries' object has no attribute '_model_id'