Skip to content
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

Factory functions for creating layers #91

Merged
merged 42 commits into from
Jan 28, 2017
Merged

Conversation

pbugnion
Copy link
Owner

@pbugnion pbugnion commented Oct 9, 2016

Creating layers is currently brittle and error prone. Since we use traitlets, the argument type is fixed. This breaks duck typing and is generally surprising to Python developers. For instance, at the moment, the data argument for a heatmap only takes a list of tuples. It should really take any iterable. The solution is to create factory functions for the layers that let us massage the arguments before the create the widget model itself.

This will address several issues:

  • the ugly interface to the Directions widget: instead of passing the start and end point and waypoints as an array, we can just pass them as a arguments to the functions, with a signature like directions_layer(start, end, waypoints=None, **kwargs).
  • the ugly way in which WeightedHeatmaps are implemented. Instead of having two different ways of creating the heat maps, we can just have a single heatmap_layer(locations, weights=None). This will create either a WeightedHeatmap or a Heatmap internally.

The markers and symbols layer already use a factory method. This PR will just bring the rest of the layers in line.

This PR will fix #65, #66 and #68.

 Remaining tasks:

  • factory function for heatmaps
  • factory function for directions
  • refactor datasets implementation to integrate better with factory functions
  • docstrings for factory functions
  • rewrite tutorial to make use of factory functions
  • add unit tests for marker and symbol layers to verify that they work with common data types

@pbugnion pbugnion added this to the 0.4.0 milestone Oct 9, 2016
@pbugnion pbugnion force-pushed the enhancement/factory-functions branch from 12984d4 to 631629a Compare October 9, 2016 17:38
@pbugnion
Copy link
Owner Author

The interface for heat maps and weighted heat maps is now unified:

heatmap = gmaps.heatmap_layer(locations, weights=None)

We can now do this:

screen shot 2016-10-11 at 07 57 07

@pbugnion pbugnion force-pushed the enhancement/factory-functions branch from 98efa2c to 6349328 Compare October 12, 2016 06:18
@pbugnion pbugnion force-pushed the enhancement/factory-functions branch from 8c7e1c4 to 5e823de Compare January 22, 2017 15:39
Now that we don't have deprecated functions, we don't need to import
warnings.
This commit:
 - fixes the tests following the refactor of heatmaps into their own
 module
 - adds a unit test for weighted heatmaps.
Currently requires extracting the numpy array with `.values`, which is
probably not what we want.
zip() returns an iterator, rather than a list, in Python 3.
We now need to tell Travis about numpy and pandas.
Building pandas on Travis takes a long time. For now, we just skip the
test.
The locations object can now be a pandas dataframe. This allows, eg.

    heatmap_layer(df[['lat', 'lng']])
This refactors the maps module to extract out directions.
This allows re-using the functionality for other layers.
We can create the test dataframe in a slightly simpler manner.
This adds a test for a fairly common use case: the user has the entire
data in a pandas dataframe and passes specific columns to factory
function.
This gives meta information about a particular dataset.
@pbugnion pbugnion force-pushed the enhancement/factory-functions branch from d5941bc to fd9e732 Compare January 28, 2017 08:01
@pbugnion pbugnion merged commit 6b36b67 into master Jan 28, 2017
@pbugnion pbugnion changed the title [WIP] Factory functions for creating layers Factory functions for creating layers Jan 28, 2017
@pbugnion pbugnion deleted the enhancement/factory-functions branch March 12, 2017 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Room for improvement on directions interface
1 participant