-
Notifications
You must be signed in to change notification settings - Fork 949
Implement AppLayout widget #2333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
041aa2b
added test widget
btel bc0a5eb
adding applayout traitlet widgets
btel 79db631
add defaults
btel 8d79146
inherit from GridBox instead of delgating
btel 5e8d24e
allow to change the children dynamically
btel 0cb2687
added unit test
btel 6472f9b
remove print
btel 137d8da
refactor + add all widget positions
btel b3ee45e
linting + fix default merging
btel 28e6d6d
test layout with a single widget
btel 43ee468
rename AppLayout -> TwoByTwoLayout
btel 8fb6f33
added first draft of template docs
btel c821a3b
fix link to grid docs
btel 63785d3
add merge option
btel 0180c91
allow to pass custom layout opitions to layout class
btel 46d092c
add height/width properties
btel ca9c03a
refactoring
btel 4d5f6ba
implement AppLayout template
btel e0d0eb9
hide header and footer is missing
btel fac71f7
handle special case of merging in AppLayout
btel b6366f0
add AppLayout to the docs
btel 1d713fb
adding test to complete coverage
btel 451cdf6
delegate top level layout properties to self.layout attribute
btel 76235db
update examples (fix overflow + alignment options)
btel ed57196
fix issue with dynamically updated localtions (did not render correctly)
btel 94ca86b
check style tag
btel e89f23d
check for frontend updates
btel 59ce21f
add extra states for align_items
btel f02d21a
add style example in docs and fix layout bug
btel 0fce35b
handle correctly merge updates
btel 3823443
add control of width/height
btel ec9361d
added an example of full application
btel 0b61545
add gridspeclayout (first version)
btel 63bcfc2
adding merging by slicing support
btel ed4b088
added bqplot scatter example with gridspeclayout
btel 81865d9
coverage: remove obsolete code, add tests
btel f59dae5
cleaning code
btel 9be11ad
implement retrieving widget with slice
btel 4ba354b
updated layout templates notebooks
btel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,288 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from ipyleaflet import Map, basemaps, basemap_to_tiles, Heatmap, TileLayer\n", | ||
"from ipywidgets import AppLayout\n", | ||
btel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"from ipywidgets import HTML, Layout, Dropdown, Output, Textarea, VBox, Label\n", | ||
"import bqplot as bq\n", | ||
"import numpy as np\n", | ||
"from pandas import date_range" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"To see map overlays obtain your API key free of charge from [OpenWeatherMap](https://openweathermap.org/) and paste it below." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"OWM_API_KEY = \"PASTE_YOUR_OWM_API_KEY_HERE\" #openweathermap API key" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"m = Map(center=(52, 10), zoom=5, basemap=basemaps.Hydda.Full)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"maps = {'Hydda' : basemaps.Hydda.Full,\n", | ||
" 'Esri' : basemaps.Esri.DeLorme}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"header = HTML(\"<h1>Fictional World Weather</h1>\", layout=Layout(height='auto'))\n", | ||
"header.style.text_align='center'\n", | ||
"basemap_selector = Dropdown( options = list(maps.keys()),\n", | ||
" layout=Layout(width='auto'))\n", | ||
"\n", | ||
"heatmap_selector = Dropdown(options=('Temperature', 'Precipitation'),\n", | ||
" layout=Layout(width='auto'))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"basemap_selector.value = 'Hydda'\n", | ||
"m.layout.height='600px'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"security_1 = np.cumsum(np.random.randn(150)) + 100.\n", | ||
"\n", | ||
"dates = date_range(start='01-01-2007', periods=150)\n", | ||
"\n", | ||
"dt_x = bq.DateScale()\n", | ||
"sc_y = bq.LinearScale()\n", | ||
"\n", | ||
"time_series = bq.Lines(x=dates, y=security_1, scales={'x': dt_x, 'y': sc_y})\n", | ||
"ax_x = bq.Axis(scale=dt_x)\n", | ||
"ax_y = bq.Axis(scale=sc_y, orientation='vertical')\n", | ||
"\n", | ||
"fig = bq.Figure(marks=[time_series], axes=[ax_x, ax_y],\n", | ||
" fig_margin=dict(top=0, bottom=80, left=30, right=20))\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"m.layout.width='auto'\n", | ||
"m.layout.height='auto'\n", | ||
"fig.layout.width='auto'\n", | ||
"fig.layout.height='auto'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"out = HTML(\n", | ||
" value='',\n", | ||
" layout=Layout(width='auto', height='auto')\n", | ||
")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"AppLayout(center=m, \n", | ||
" header=header,\n", | ||
" left_sidebar=VBox([Label(\"Basemap:\"),\n", | ||
" basemap_selector,\n", | ||
" Label(\"Overlay:\"),\n", | ||
" heatmap_selector]),\n", | ||
" right_sidebar=fig,\n", | ||
" footer=out,\n", | ||
" pane_widths=['80px', 1, 1],\n", | ||
" pane_heights=['80px', 4, 1],\n", | ||
" height='600px',\n", | ||
" grid_gap=\"30px\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"rows = []" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"X, Y = np.mgrid[-90:90:10j, -180:180:20j]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"X = X.flatten()\n", | ||
"Y = Y.flatten()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"temps = np.random.randn(200, 150)*0.5" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from datetime import datetime" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import random" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def add_log(msg):\n", | ||
" max_rows = 3\n", | ||
" rows.append(msg)\n", | ||
" if len(rows) > max_rows:\n", | ||
" rows.pop(0)\n", | ||
" return '<h4>Activity log</h4><ul>{}</ul>'.format('<li>'.join([''] + rows))\n", | ||
"\n", | ||
"def generate_temp_series(x, y):\n", | ||
" if heatmap_selector.value == 'Precipitation':\n", | ||
" temp = np.cumsum(np.random.randn(150)) + 100.\n", | ||
" elif heatmap_selector.value == 'Temperature':\n", | ||
" dist = np.sqrt((X - x)**2 + (Y-y)**2) / 100\n", | ||
" dist = dist.max() - dist\n", | ||
" dist[dist > np.percentile(dist, 5)] = 0\n", | ||
" temp = np.cumsum(np.dot(dist, temps)+0.05) + 20 - np.abs(x) / 2\n", | ||
" time_series.y = temp\n", | ||
" \n", | ||
"def handle_interaction(**kwargs):\n", | ||
" if kwargs['type'] == 'click':\n", | ||
" generate_temp_series(*kwargs['coordinates'])\n", | ||
" msg = '%s Selected coordinates: %s, Temp: %d C Precipitation: %d mm\\n' % (\n", | ||
" datetime.now(), kwargs['coordinates'], random.randint(-20, 20), random.randint(0, 100))\n", | ||
" out.value = add_log(msg)\n", | ||
"\n", | ||
"m.on_interaction(handle_interaction) \n", | ||
"\n", | ||
"def on_map_selected(change):\n", | ||
" m.layers = [basemap_to_tiles(maps[basemap_selector.value]), weather_maps[heatmap_selector.value]]\n", | ||
" \n", | ||
"basemap_selector.observe(on_map_selected, names='value')\n", | ||
"heatmap_selector.observe(on_map_selected, names='value')\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"temp = TileLayer(min_zoom=1, max_zoom=18, url='https://tile.openweathermap.org/map/temp_new/{z}/{x}/{y}.png?appid='+OWM_API_KEY, name='owm', attribute='me')\n", | ||
"percipitation = TileLayer(min_zoom=1, max_zoom=18, url='https://tile.openweathermap.org/map/precipitation_new/{z}/{x}/{y}.png?appid='+OWM_API_KEY, name='owm', attribute='me')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"weather_maps = {'Temperature' : temp,\n", | ||
" 'Precipitation' : percipitation}" | ||
btel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"m.add_layer(weather_maps[heatmap_selector.value])" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.