From 86b60c28f70d31de4abd30f72b6fcb4525fc3436 Mon Sep 17 00:00:00 2001 From: akacarlyann Date: Fri, 21 Jun 2019 22:29:21 -0700 Subject: [PATCH 1/9] Add identity color_function_type (requires some defaults to be set for legend CSS; also handles radius_function_type, height..., etc. --- examples/data/state_colors.geojson | 94 ++++ examples/notebooks/identity_example.ipynb | 642 ++++++++++++++++++++++ mapboxgl/templates/main.html | 32 +- mapboxgl/viz.py | 25 + 4 files changed, 779 insertions(+), 14 deletions(-) create mode 100644 examples/data/state_colors.geojson create mode 100644 examples/notebooks/identity_example.ipynb diff --git a/examples/data/state_colors.geojson b/examples/data/state_colors.geojson new file mode 100644 index 0000000..602bfb4 --- /dev/null +++ b/examples/data/state_colors.geojson @@ -0,0 +1,94 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "id": "49", + "properties": { + "name": "Utah", + "density": 34.3, + "color": "gold" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-112.164359, 41.995232], + [-111.047063, 42.000709], + [-111.047063, 40.998429], + [-109.04798, 40.998429], + [-109.053457, 39.125316], + [-109.058934, 38.27639], + [-109.042503, 38.166851], + [-109.042503, 37.000263], + [-110.499369, 37.00574], + [-114.048427, 37.000263], + [-114.04295, 41.995232], + [-112.164359, 41.995232] + ] + ] + } + }, + { + "type": "Feature", + "id": "08", + "properties": { + "name": "Colorado", + "density": 49.33, + "color": "skyblue" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-107.919731, 41.003906], + [-105.728954, 40.998429], + [-104.053011, 41.003906], + [-102.053927, 41.003906], + [-102.053927, 40.001626], + [-102.042974, 36.994786], + [-103.001438, 37.000263], + [-104.337812, 36.994786], + [-106.868158, 36.994786], + [-107.421329, 37.000263], + [-109.042503, 37.000263], + [-109.042503, 38.166851], + [-109.058934, 38.27639], + [-109.053457, 39.125316], + [-109.04798, 40.998429], + [-107.919731, 41.003906] + ] + ] + } + }, + { + "type": "Feature", + "id": "56", + "properties": { + "name": "Wyoming", + "density": 5.851, + "color": "orange" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-109.080842, 45.002073], + [-105.91517, 45.002073], + [-104.058488, 44.996596], + [-104.053011, 43.002989], + [-104.053011, 41.003906], + [-105.728954, 40.998429], + [-107.919731, 41.003906], + [-109.04798, 40.998429], + [-111.047063, 40.998429], + [-111.047063, 42.000709], + [-111.047063, 44.476286], + [-111.05254, 45.002073], + [-109.080842, 45.002073] + ] + ] + } + } + ] +} \ No newline at end of file diff --git a/examples/notebooks/identity_example.ipynb b/examples/notebooks/identity_example.ipynb new file mode 100644 index 0000000..968275d --- /dev/null +++ b/examples/notebooks/identity_example.ipynb @@ -0,0 +1,642 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from mapboxgl.viz import *\n", + "viz = ChoroplethViz('../data/state_colors.geojson', \n", + " access_token=os.getenv('MAPBOX_ACCESS_TOKEN'),\n", + " center=(-96, 42), \n", + " zoom=3,\n", + " color_function_type='identity',\n", + " height='200px',\n", + " legend=False)\n", + "viz.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/mapboxgl/templates/main.html b/mapboxgl/templates/main.html index 0dfc844..15dfbaf 100644 --- a/mapboxgl/templates/main.html +++ b/mapboxgl/templates/main.html @@ -14,9 +14,10 @@