Skip to content

Commit 0a95626

Browse files
committed
Merge pull request #16 from dsten/split-stuff
Restructure package, datascience.py -> table.py, and stub map widget
2 parents 30e8c93 + 63c75a4 commit 0a95626

File tree

7 files changed

+81
-6
lines changed

7 files changed

+81
-6
lines changed

datascience/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .table import *
2+
from .maps import *

datascience/maps/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .loader import *
2+
from .maps import *
3+
4+
init_js()

datascience/maps/js/maps.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Registers the Backbone view for the Polymap widget, although for now this is
2+
// a dummy view until we can get everything hooked up properly.
3+
// TODO(sam): Make this actually do things.
4+
5+
require(["widgets/js/widget", "widgets/js/manager"], function(widget, manager) {
6+
var TestWidgetView = widget.DOMWidgetView.extend({
7+
render: function() {
8+
this.$el.text("Hello world!");
9+
}
10+
});
11+
12+
manager.WidgetManager.register_widget_view('TestWidgetView', TestWidgetView);
13+
});

datascience/maps/loader.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from IPython.display import display_javascript
2+
3+
__maps_js_has_initialized__ = False
4+
5+
# Uses a hack to load the Javascript needed to render the map. Becaose of this,
6+
# calls to draw_map cannot be in the same cell as the import statement.
7+
#
8+
# Maybe it's a good idea to put this login in a line magic?
9+
def init_js():
10+
global __maps_js_has_initialized__
11+
if not __maps_js_has_initialized__:
12+
# Keep in sync with the the data_files variable in setup.py
13+
display_javascript("IPython.load_extensions('datascience_js/maps')")

datascience/maps/maps.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from IPython.html import widgets # Widget definitions
2+
from IPython.utils.traitlets import Unicode
3+
4+
"""
5+
This file contains the Python backend to draw maps with overlaid polygons.
6+
TODO(sam): Actually make this draw maps
7+
"""
8+
9+
class TestWidget(widgets.DOMWidget):
10+
_view_name = Unicode('TestWidgetView', sync=True)
11+
_view_module = Unicode('maps', sync=True)
12+
13+
14+
def draw_map(center, zoom, points=[], regions=[]):
15+
"""Draw a map with center & zoom containing all points and
16+
regions that displays points as circles and regions as polygons.
17+
18+
center -- lat-long pair at the center of the map
19+
zoom -- zoom level
20+
points -- a sequence of MapPoints
21+
regions -- a sequence of MapRegions
22+
"""
23+
# Some magic to get javascript to display the map
24+
25+
class MapPoint:
26+
"""A circle https://developers.google.com/maps/documentation/javascript/shapes#circles"""
27+
def __init__(self, center, radius, strokeColor, strokeOpacity, strokeWeight, fillColor, fillOpacity):
28+
pass
29+
30+
class MapRegion:
31+
"""A polygon https://developers.google.com/maps/documentation/javascript/shapes#polygons"""
32+
def __init__(self, paths, strokeColor, strokeOpacity, strokeWeight, fillColor, fillOpacity):
33+
"""paths -- a list of lat-long pairs or a list of list of lat-long pairs"""
34+
pass

datascience.py renamed to datascience/table.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ def __len__(self):
667667
def __repr__(self):
668668
return '{0}({1})'.format(type(self).__name__, repr(self._table))
669669

670-
671670
def _zero_on_type_error(column_fn):
672671
"""Wrap a function on an np.ndarray to return 0 on a type error."""
673672
@functools.wraps(column_fn)

setup.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import sys
2-
from distutils.core import setup
2+
import os
3+
import IPython
4+
from setuptools import setup
35
from setuptools.command.test import test as TestCommand
46

57
install_requires = [
@@ -31,15 +33,23 @@ def run_tests(self):
3133
sys.exit(errno)
3234

3335

36+
# Installs GMaps Javascript in the nbextensions folder for loading.
37+
# We load this file using IPython.load_extensions('datascience_js/maps') in
38+
# Javascript. Keep in sync with the path in maps/leader.py
39+
ipython_dir = IPython.utils.path.get_ipython_dir()
40+
data_files = [(os.path.join(ipython_dir, "nbextensions/datascience_js"),
41+
["datascience/maps/js/maps.js"] )]
42+
3443
setup(
3544
name = 'datascience',
36-
py_modules = ['datascience'],
37-
version = '0.2.1',
45+
packages = ['datascience'],
46+
version = '0.2.2',
3847
install_requires = install_requires,
3948
tests_require = test_requires,
49+
data_files = data_files,
4050
cmdclass = {'test': PyTest},
41-
description = 'A Python library for introductory data science',
42-
author = 'John DeNero, David Culler, Alvin Wan',
51+
description = 'A Jupyter notebook Python library for introductory data science',
52+
author = 'John DeNero, David Culler, Alvin Wan, Sam Lau',
4353
author_email = '[email protected]',
4454
url = 'https://github.com/dsten/datascience',
4555
download_url = 'https://github.com/dsten/datascience/archive/0.2.0.zip',

0 commit comments

Comments
 (0)