Skip to content

Commit

Permalink
Feature: use kiwi.js for controlling min and max aspect (#1046)
Browse files Browse the repository at this point in the history
* Use Kiwi for auto layout

* Iterate

* Fix default side computation for axis

* Explore removing orientation property from axis in the front-end code

* Clean notebooks outputs

* Fix orientation

* Update Playwright Snapshots

* Try and uncomment tests

* Prettier

---------

Co-authored-by: martinRenou <martin.renou@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 17, 2023
1 parent 703d4b0 commit 72514f3
Show file tree
Hide file tree
Showing 112 changed files with 1,760 additions and 1,052 deletions.
43 changes: 33 additions & 10 deletions bqplot/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from traitlets import Int, Unicode, Instance, Enum, Dict, Bool
from traitlets import observe, Int, Unicode, Instance, Enum, Dict, Bool
from traittypes import Array
from ipywidgets import Widget, Color, widget_serialization

Expand Down Expand Up @@ -102,10 +102,7 @@ class Axis(BaseAxis):
Degrees to rotate tick labels by.
"""
icon = 'fa-arrows'
orientation = Enum(['horizontal', 'vertical'], default_value='horizontal')\
.tag(sync=True)
side = Enum(['bottom', 'top', 'left', 'right'],
allow_none=True, default_value=None).tag(sync=True)
side = Enum(['bottom', 'top', 'left', 'right'], default_value='bottom').tag(sync=True)
label = Unicode().tag(sync=True)
grid_lines = Enum(['none', 'solid', 'dashed'], default_value='solid')\
.tag(sync=True)
Expand All @@ -132,6 +129,37 @@ class Axis(BaseAxis):
_model_name = Unicode('AxisModel').tag(sync=True)
_ipython_display_ = None # We cannot display an axis outside of a figure.

def __init__(self, *args, **kwargs):
super(Axis, self).__init__(**kwargs)

if kwargs.get('orientation') is not None:
self.orientation = kwargs.get('orientation')

@property
def orientation(self):
return 'vertical' if self.side in ['right', 'left'] else 'horizontal'

@orientation.setter
def orientation(self, orientation):
if orientation not in ['horizontal', 'vertical']:
raise ValueError('orientation must be "horizontal" or "vertical"')

if orientation == 'horizontal' and self.side not in ['bottom', 'top']:
self.side = 'bottom'

if orientation == 'vertical' and self.side not in ['right', 'left']:
self.side = 'left'

@observe('side')
def _observe_side(self, change):
side = change['new']

if side in ['left', 'right'] and self.orientation != 'vertical':
self.orientation = 'vertical'

if side in ['bottom', 'top'] and self.orientation != 'horizontal':
self.orientation = 'horizontal'


@register_axis('bqplot.ColorAxis')
class ColorAxis(Axis):
Expand All @@ -145,11 +173,6 @@ class ColorAxis(Axis):
scale: ColorScale
The scale represented by the axis
"""
orientation = Enum(['horizontal', 'vertical'],
default_value='horizontal').tag(sync=True)
side = Enum(['bottom', 'top', 'left', 'right'],
default_value='bottom').tag(sync=True)
label = Unicode().tag(sync=True)
scale = Instance(ColorScale).tag(sync=True, **widget_serialization)
_view_name = Unicode('ColorAxis').tag(sync=True)
_model_name = Unicode('ColorAxisModel').tag(sync=True)
7 changes: 5 additions & 2 deletions bqplot/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ class Figure(DOMWidget):
Dictionary containing the top, bottom, left and right margins. The user
is responsible for making sure that the width and height are greater
than the sum of the margins.
auto_layout: boolean (default: False)
Whether to use the auto-layout solver or not
min_aspect_ratio: float
minimum width / height ratio of the figure
Minimum width / height ratio of the figure
max_aspect_ratio: float
maximum width / height ratio of the figure
Maximum width / height ratio of the figure
!!! Note
Expand Down Expand Up @@ -137,6 +139,7 @@ class Figure(DOMWidget):
legend_text = Dict().tag(sync=True)
theme = Enum(['classic', 'gg'], default_value='classic').tag(sync=True)

auto_layout = Bool(False).tag(sync=True)
min_aspect_ratio = Float(0.01).tag(sync=True)
max_aspect_ratio = Float(100).tag(sync=True)
pixel_ratio = Float(None, allow_none=True).tag(sync=True)
Expand Down
4 changes: 1 addition & 3 deletions examples/Advanced Plotting/Axis Properties.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure()\n",
Expand Down
15 changes: 0 additions & 15 deletions examples/Advanced Plotting/Plotting Dates.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
Expand All @@ -23,7 +22,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
Expand All @@ -50,7 +48,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
Expand All @@ -63,7 +60,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
Expand All @@ -88,7 +84,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
Expand All @@ -107,7 +102,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
Expand All @@ -132,7 +126,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
Expand All @@ -146,7 +139,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
Expand All @@ -171,7 +163,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
Expand All @@ -186,7 +177,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
Expand All @@ -211,7 +201,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
Expand All @@ -224,7 +213,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
Expand All @@ -249,7 +237,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
Expand All @@ -268,7 +255,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
Expand All @@ -281,7 +267,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"feature_vector_distribution(\n",
Expand Down Expand Up @@ -425,9 +423,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"feature_vector_distribution(\n",
Expand Down
23 changes: 4 additions & 19 deletions examples/Applications/Neural Network.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -23,7 +23,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -129,24 +129,9 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b2d75468c39d4bcf896561f72febb74d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"NeuralNet(fig_margin={'top': 60, 'bottom': 60, 'left': 60, 'right': 60}, layout=Layout(height='600px', width='…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"NeuralNet(num_inputs=3, num_hidden_layers=[10, 10, 8, 5], num_outputs=1)"
]
Expand Down
4 changes: 1 addition & 3 deletions examples/Applications/Outlier Detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [],
"source": [
"data_clean = data_dna.get_filtered_df()"
Expand Down
4 changes: 1 addition & 3 deletions examples/Interactions/Interaction Layer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"VBox([db_scat_brush, fig_scat_brush])"
Expand Down
4 changes: 1 addition & 3 deletions examples/Interactions/Mark Interactions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"x_sc = LinearScale()\n",
Expand Down
4 changes: 1 addition & 3 deletions examples/Interactions/Selectors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"create_figure(FastIntervalSelector, scale=scales[\"x\"])"
Expand Down
11 changes: 7 additions & 4 deletions examples/Marks/Object Model/HeatMap.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"source": [
"# Heatmap"
Expand Down Expand Up @@ -135,7 +138,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -149,9 +152,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

0 comments on commit 72514f3

Please sign in to comment.