Repository: bokeh/bokeh

Issue:
responsive no longer supported?
Is the responsive keyword no longer supported in 0.12.0rc1?  In 0.11.1 I could pass it to `bokeh.plotting.figure`, and it would make the plot fill the container it was in:

``` python
import bokeh
print(bokeh.__version__)
import bokeh.plotting as bp
from bokeh.models.tiles import WMTSTileSource

bp.output_notebook()
p = bp.figure(tools='pan,wheel_zoom,reset', x_range=(-13884029,  -7453304), y_range=(2698291, 6455972))
p.add_tile(WMTSTileSource(url="http://tile.stamen.com/toner-background/{Z}/{X}/{Y}.png"))
p.responsive = True
bp.show(p)
```

![image](https://cloud.githubusercontent.com/assets/1695496/16247425/4722eaf8-37cf-11e6-8eee-ca851c5448ca.png)

But in 0.12.0rc1, I get an error:

``` python
0.12.0rc1
 BokehJS successfully loaded
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-58565180fe65> in <module>()
      7 p = bp.figure(tools='pan,wheel_zoom,reset', x_range=(-13884029,  -7453304), y_range=(2698291, 6455972))
      8 p.add_tile(WMTSTileSource(url="http://tile.stamen.com/toner-background/{Z}/{X}/{Y}.png"))
----> 9 p.responsive = True
     10 bp.show(p)

/Users/jbednar/anaconda/lib/python2.7/site-packages/bokeh/core/properties.py in __setattr__(self, name, value)
    722 
    723             raise AttributeError("unexpected attribute '%s' to %s, %s attributes are %s" %
--> 724                 (name, self.__class__.__name__, text, nice_join(matches)))
    725 
    726     def set_from_json(self, name, json, models=None):

AttributeError: unexpected attribute 'responsive' to Figure, possible attributes are above, background_fill_alpha, background_fill_color, below, border_fill_alpha, border_fill_color, disabled, extra_x_ranges, extra_y_ranges, h_symmetry, height, hidpi, left, lod_factor, lod_interval, lod_threshold, lod_timeout, min_border, min_border_bottom, min_border_left, min_border_right, min_border_top, name, outline_line_alpha, outline_line_cap, outline_line_color, outline_line_dash, outline_line_dash_offset, outline_line_join, outline_line_width, plot_height, plot_width, renderers, right, sizing_mode, tags, title, title_location, tool_events, toolbar, toolbar_location, toolbar_sticky, v_symmetry, webgl, width, x_mapper_type, x_range, y_mapper_type or y_range

In [ ]:
```



Discussion:
you want to set `responsive='scale_both'`, and if necessary call `plot.model.document.resize()` when the size of the container changed.

You can pass the bool to `figure` still but the actual property is an enum now. 

> On Jun 21, 2016, at 16:45, James A. Bednar notifications@github.com wrote:
> 
> Is the responsive keyword no longer supported in 0.12.0rc1? In 0.11.1 I could pass it to bokeh.plotting.figure, and it would make the plot fill the container it was in:
> 
> import bokeh
> print(bokeh.**version**)
> import bokeh.plotting as bp
> from bokeh.models.tiles import WMTSTileSource
> 
> bp.output_notebook()
> p = bp.figure(tools='pan,wheel_zoom,reset', x_range=(-13884029,  -7453304), y_range=(2698291, 6455972))
> p.add_tile(WMTSTileSource(url="http://tile.stamen.com/toner-background/{Z}/{X}/{Y}.png"))
> p.responsive = True
> bp.show(p)
> 
> But in 0.12.0rc1, I get an error:
> 
> 0.12.0rc1
> 
> ##  BokehJS successfully loaded
> 
> AttributeError                            Traceback (most recent call last)
> <ipython-input-1-58565180fe65> in <module>()
>       7 p = bp.figure(tools='pan,wheel_zoom,reset', x_range=(-13884029,  -7453304), y_range=(2698291, 6455972))
>       8 p.add_tile(WMTSTileSource(url="http://tile.stamen.com/toner-background/{Z}/{X}/{Y}.png"))
> ----> 9 p.responsive = True
>      10 bp.show(p)
> 
> /Users/jbednar/anaconda/lib/python2.7/site-packages/bokeh/core/properties.py in **setattr**(self, name, value)
>     722 
>     723             raise AttributeError("unexpected attribute '%s' to %s, %s attributes are %s" %
> --> 724                 (name, self.**class**.**name**, text, nice_join(matches)))
>     725 
>     726     def set_from_json(self, name, json, models=None):
> 
> AttributeError: unexpected attribute 'responsive' to Figure, possible attributes are above, background_fill_alpha, background_fill_color, below, border_fill_alpha, border_fill_color, disabled, extra_x_ranges, extra_y_ranges, h_symmetry, height, hidpi, left, lod_factor, lod_interval, lod_threshold, lod_timeout, min_border, min_border_bottom, min_border_left, min_border_right, min_border_top, name, outline_line_alpha, outline_line_cap, outline_line_color, outline_line_dash, outline_line_dash_offset, outline_line_join, outline_line_width, plot_height, plot_width, renderers, right, sizing_mode, tags, title, title_location, tool_events, toolbar, toolbar_location, toolbar_sticky, v_symmetry, webgl, width, x_mapper_type, x_range, y_mapper_type or y_range
> 
> In [ ]:
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub, or mute the thread.

Thanks.  And that's a deliberate break in backwards compatibility?  E.g. it breaks the various datashader notebooks that have been distributed.  I'm happy to update them, as long as that's really what's intended.

Yes, we could not find a technical way to support it and move forward. 

An enum that includes True and False as options wouldn't work, then?  Ah well.

> you want to set responsive='scale_both', and if necessary call plot.model.document.resize() when the size of the container changed.

It would be `sizing_mode=` not `responsive=`. Secondly I can't recommend the use of `scale_both` it's experimental at this point and you have to have decent web knowledge to make it work for you.

@jbednar I think you want `sizing_mode='scale_width'` and `responsive=True` is a synonym for that and still works, although, as you've noted not as a subsequent property setter. 

Also, @almarklein I'd be shocked if `scale_both` works in the notebook where output cells don't have an inherent height.

Ah, I missed that this was for the notebook. In that case `scale_width` is likely better, yes :)

closing this (I don't think there's anything left to discuss)

Well should add @jbednar you can still pass `responsive` as a keyword argument to `Figure` and charts initializers. 

Actually I can add a python getter / setter that is deprecated for this, so I will. 


Resolving patch:
diff --git a/bokeh/models/plots.py b/bokeh/models/plots.py
--- a/bokeh/models/plots.py
+++ b/bokeh/models/plots.py
@@ -385,7 +385,7 @@ def _check_snapped_toolbar_and_axis(self):
             return str(self)
 
     __deprecated_attributes__ = (
-        'background_fill', 'border_fill', 'logo', 'tools',
+        'background_fill', 'border_fill', 'logo', 'tools', 'responsive',
         'title_text_baseline', 'title_text_align', 'title_text_alpha', 'title_text_color',
         'title_text_font_style', 'title_text_font_size', 'title_text_font', 'title_standoff'
     )
@@ -611,6 +611,31 @@ def _check_snapped_toolbar_and_axis(self):
     # DEPRECATED PROPERTIES
     #
 
+    @property
+    def responsive(self):
+        warnings.warn(DEP_MSG_0_12_0 % ('responsive', 'Plot.sizing_mode'))
+        return self.sizing_mode != "fixed"
+
+    @responsive.setter
+    def responsive(self, value):
+        warnings.warn(DEP_MSG_0_12_0 % ('responsive', 'Plot.sizing_mode'))
+        warnings.warn("""
+        The 'responsive' property has been deprecated in 0.12.0. It has been
+        replaced by 'sizing_mode' which accepts one of five modes:
+
+            fixed, scale_width, scale_height, scale_both, stretch_both
+
+        'responsive = False' is the equivalent of 'sizing_mode = "fixed"'
+
+        'responsive = True' is the equivalent of 'sizing_mode = "scale_width"'
+        """)
+        if value is True:
+            self.sizing_mode = "scale_width"
+        elif value is False:
+            self.sizing_mode = "fixed"
+        else:
+            raise ValueError("Plot.responsive only accepts True or False, got: %r" % value)
+
     @property
     def background_fill(self):
         warnings.warn(


Test patch: