Skip to content

Commit 112bb95

Browse files
committed
- first nobel_viz commit
1 parent 9f8cc8e commit 112bb95

File tree

1,675 files changed

+3224
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,675 files changed

+3224
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ target/
6060

6161
#Ipython Notebook
6262
.ipynb_checkpoints
63+
64+
# nobel_viz specific
65+
nobel_viz/.old
66+
/nobel_viz/.#index.html

nobel_viz/.bowerrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "static/libs"
3+
}

nobel_viz/.projectile

Whitespace-only changes.

nobel_viz/SpecRunner.html

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Jasmine Spec Runner v2.4.1</title>
6+
7+
<link rel="shortcut icon" type="image/png" href="tests/jasmine/lib/jasmine-2.4.1/jasmine_favicon.png">
8+
<link rel="stylesheet" href="tests/jasmine/lib/jasmine-2.4.1/jasmine.css">
9+
10+
<script src="tests/jasmine/lib/jasmine-2.4.1/jasmine.js"></script>
11+
<script src="tests/jasmine/lib/jasmine-2.4.1/jasmine-html.js"></script>
12+
<script src="tests/jasmine/lib/jasmine-2.4.1/boot.js"></script>
13+
14+
<!-- include source files here... -->
15+
<!-- <script src="src/Player.js"></script> -->
16+
<!-- <script src="src/Song.js"></script> -->
17+
18+
<script src="http://d3js.org/d3.v3.min.js"></script>
19+
<script src="http://d3js.org/topojson.v1.min.js"></script>
20+
<script src="static/lib/crossfilter.min.js"></script>
21+
22+
<script src="static/js/nbviz_core.js"></script>
23+
24+
25+
<!-- include spec files here... -->
26+
<script src="tests/NbvizSpec.js"></script>
27+
28+
<!-- <script src="spec/SpecHelper.js"></script> -->
29+
<!-- <script src="spec/PlayerSpec.js"></script> -->
30+
31+
</head>
32+
33+
<body>
34+
</body>
35+
</html>

nobel_viz/api

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 4a34d0419d8e54ac1ad777e360df6ca1ffbf4fce

nobel_viz/config.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Config(object):
2+
APP_TITLE = 'Visualizing the Nobel Prize'
3+
DEBUG = False
4+
TESTING = False
5+
DATABASE_URI = 'sqlite://:memory:'
6+
EVE_API = 'http://localhost:5000/api/'
7+
8+
class ProductionConfig(Config):
9+
DATABASE_URI = 'mysql://user@localhost/foo'
10+
EVE_API = 'http://foo.com:5000/api/'
11+
12+
class DevelopmentConfig(Config):
13+
DEBUG = True
14+
15+
class TestingConfig(Config):
16+
TESTING = True

nobel_viz/index.html

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>Nobel-prize Visualisation (for book 'Data-visualisation with Python and JavaScript'</title>
4+
<!-- IMPORT THE VISUALISATIONS CSS STYLING -->
5+
<link rel="stylesheet" href="static/css/style.css" type="" media="screen" />
6+
<body>
7+
<div id='chart'>
8+
<!-- A HEADER WITH TITLE AND SOME EXPLANATORY INFO -->
9+
<div id='title'>Visualising the Nobel Prize</div>
10+
<div id="info">
11+
This is a companion piece to the book <a href='http://'>Data Visualisation with Python and JavaScript</a>, in which its construction is detailed. The data used was scraped Wikipedia using the <a href='https://en.wikipedia.org/wiki/List_of_Nobel_laureates_by_country'>list of winners by country</a> as a starting point. The accompanying Github repo is <a href='http://github.com/Kyrand/dataviz-with-python-and-js'>here</a>.
12+
</div>
13+
<!-- 2. THE PLACEHOLDERS FOR OUR VISUAL COMPONENTS -->
14+
<div id="nbviz">
15+
<!-- BEGIN MENU-BAR -->
16+
<div id="nobel-menu">
17+
<div id="cat-select">
18+
Category
19+
<select></select>
20+
</div>
21+
<div id="gender-select">
22+
Gender
23+
<select>
24+
<option value="All">All</option>
25+
<option value="female">female</option>
26+
<option value="male">male</option>
27+
</select>
28+
</div>
29+
<div id="country-select">
30+
Country
31+
<select></select>
32+
</div>
33+
<div id='metric-radio'>
34+
Number of Winners:&nbsp;
35+
<form>
36+
<label>absolute
37+
<input type="radio" name="mode" value="0" checked>
38+
</label>
39+
<label>per-capita
40+
<input type="radio" name="mode" value="1">
41+
</label>
42+
</form>
43+
</div>
44+
</div>
45+
<!-- END MENU-BAR -->
46+
<!-- BEGIN NOBEL-VIZ COMPONENTS -->
47+
<div id='chart-holder' class='_dev'>
48+
<div id="nobel-time"></div>
49+
<div id="nobel-map">
50+
<div id="map-tooltip">
51+
<h2></h2>
52+
<p></p>
53+
</div>
54+
</div>
55+
<div id="nobel-list">
56+
<h2>Selected winners</h2>
57+
<table>
58+
<thead>
59+
<tr><th id='year'>Year</th><th id='category'>Category</th><th id='name'>Name</th></tr>
60+
</thead>
61+
<tbody>
62+
</tbody>
63+
</table>
64+
</div>
65+
<div id="nobel-winner">
66+
<div id="picbox"><img /></div>
67+
<div id='winner-title'></div>
68+
<div id='infobox'>
69+
<div class='property'>
70+
<div class='label'>Category</div>
71+
<span name='category'></span>
72+
</div>
73+
<div class='property'>
74+
<div class='label'>Year</div>
75+
<span name='year'></span>
76+
</div>
77+
<div class='property'>
78+
<div class='label'>Country</div>
79+
<span name='country'></span>
80+
</div>
81+
</div>
82+
<div id='biobox'></div>
83+
<div id='readmore'><a href='#'>Read more at Wikipedia</a></div>
84+
</div>
85+
<div id="nobel-bar"></div>
86+
</div>
87+
<!-- END NOBEL-VIZ COMPONENTS -->
88+
</div>
89+
</div>
90+
<!-- 3. THE JAVASCRIPT FILES -->
91+
<!-- THIRD-PARTY JAVASCRIPT LIBRARIES, MAINLY D3 -->
92+
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.16/d3.js"></script>
93+
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.20/topojson.min.js"></script>
94+
<script src="https://cdnjs.cloudflare.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script>
95+
<script src="static/lib/crossfilter.min.js"></script>
96+
<!-- THE JAVASCRIPT FOR OUR NOBEL ELEMENTS -->
97+
98+
<script>
99+
window.$STATIC_API = true;
100+
$EVE_API = 'static/data/api/';
101+
<!-- $EVE_API = {{ config.EVE_API|tojson|safe }}; -->
102+
</script>
103+
104+
<script src="static/js/nbviz_core.js" ></script>
105+
<script src="static/js/nbviz_menu.js" ></script>
106+
<script src="static/js/nbviz_map.js"></script>
107+
<script src="static/js/nbviz_bar.js"></script>
108+
<script src="static/js/nbviz_time.js"></script>
109+
<script src="static/js/nbviz_details.js"></script>
110+
<script src="static/js/nbviz_main.js"></script>
111+
</body>

nobel_viz/nobel_viz.py

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# server.py
2+
import flask
3+
from flask import Flask, send_from_directory, render_template, redirect
4+
5+
import flask.ext.login as flask_login
6+
7+
app = Flask(__name__)
8+
9+
import os
10+
11+
# Try to find an NBVIZ_CONFIG environment variable - default is development
12+
cfg_var = os.environ.get('NBVIZ_CONFIG', 'config.DevelopmentConfig')
13+
# if not cfg_var:
14+
# raise RuntimeError('The environment variable NBVIZ_CONFIG is '
15+
# 'not set. Please set to enable configuration'
16+
# )
17+
18+
app.config.from_object(cfg_var)
19+
20+
app.secret_key = 'special secret key-string'
21+
# @app.route('/')
22+
# def root():
23+
# return send_from_directory('.', 'index.html')
24+
login_manager = flask_login.LoginManager()
25+
login_manager.init_app(app)
26+
login_manager.login_view = "login"
27+
28+
#users = {'groucho': {'pw': 'swordfish'}}
29+
users = {'groucho': {'pw': 'swordfish'}}
30+
31+
class User(flask_login.UserMixin):
32+
pass
33+
34+
35+
@login_manager.user_loader
36+
def user_loader(name):
37+
38+
if name not in users:
39+
return
40+
41+
user = User()
42+
user.id = name
43+
return user
44+
45+
46+
# @login_manager.request_loader
47+
# def request_loader(request):
48+
49+
# name = request.form.get('name')
50+
# if name not in users:
51+
# return
52+
53+
# user = User()
54+
# user.id = name
55+
56+
# # DO NOT ever store passwords in plaintext and always compare password
57+
# # hashes using constant-time comparison!
58+
# user.is_authenticated = request.form['pw'] == users[name]['pw']
59+
60+
# return user
61+
62+
63+
@app.route('/login', methods=['GET', 'POST'])
64+
def login():
65+
66+
if flask.request.method == 'GET':
67+
return render_template('login.html')
68+
69+
name = flask.request.form['name']
70+
if users.get(name) and flask.request.form['pw'] == users[name]['pw']:
71+
user = User()
72+
user.id = name
73+
flask_login.login_user(user)
74+
return flask.redirect(flask.url_for('root'))
75+
76+
return '<h2>A Bad Login Attempt</h2><p>Wrong name and/or password given</p>'
77+
#return 'Bad login'
78+
79+
80+
# @app.route('/protected')
81+
# @flask_login.login_required
82+
# def protected():
83+
# return 'Logged in as: ' + flask_login.current_user.id
84+
85+
86+
@app.route('/logout')
87+
def logout():
88+
flask_login.logout_user()
89+
return '<h2>Logged Out!</h2>'
90+
91+
92+
@login_manager.unauthorized_handler
93+
def unauthorized_callback():
94+
app.logger.debug('An unauthorized user!')
95+
return redirect('/login')
96+
97+
98+
@app.route('/')
99+
@flask_login.login_required
100+
def root():
101+
return render_template('index.html')
102+
103+
104+
winners = [
105+
{'name': 'Albert Einstein', 'category':'Physics'},
106+
{'name': 'V.S. Naipaul', 'category':'Literature'},
107+
{'name': 'Dorothy Hodgkin', 'category':'Chemistry'}
108+
]
109+
110+
@app.route('/demolist')
111+
def demo_list():
112+
return render_template('testj2.html',
113+
heading="A little winners' list",
114+
winners=winners
115+
)
116+
117+
if __name__ == '__main__':
118+
app.run(debug=True, port=8000)

nobel_viz/nobel_viz.wsgi

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sys
2+
import os
3+
4+
sys.path.insert(0, '/var/www/nobel_viz')
5+
6+
activate_this = '/home/kyran/.virtualenvs/pyjsbook/bin/activate_this.py'
7+
execfile(activate_this, dict(__file__=activate_this))
8+
9+
os.environ["NBVIZ_CONFIG"] = "config.DevelopmentConfig"
10+
11+
from server import app as application

nobel_viz/notes.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## D3
2+
### SVG
3+
- order of addition important - no z property. E.g. svg.insert('path', '.graticule') # before graticule
4+
5+
6+
### Making the thing
7+
- pass through mouse
8+
9+
10+
### Snippets
11+
`var shapeData = ["Triangle", "Circle", "Square", "Rectangle"],
12+
j = 3; // Choose the rectangle as default
13+
14+
// Create the shape selectors
15+
var form = d3.select("body").append("form");
16+
17+
labels = form.selectAll("label")
18+
.data(shapeData)
19+
.enter()
20+
.append("label")
21+
.text(function(d) {return d;})
22+
.insert("input")
23+
.attr({
24+
type: "radio",
25+
class: "shape",
26+
name: "mode",
27+
value: function(d, i) {return i;}
28+
})
29+
.property("checked", function(d, i) {return i===j;});
30+
`
31+

0 commit comments

Comments
 (0)