mirror of https://github.com/apache/superset.git
Touchups
This commit is contained in:
parent
48c1481caa
commit
b3edc077dc
|
@ -12,7 +12,7 @@ from panoramix import app
|
|||
from flask.ext.migrate import MigrateCommand
|
||||
from panoramix import db
|
||||
from flask.ext.appbuilder import Base
|
||||
from sqlalchemy import Column, Integer, String, Table, DateTime, Float
|
||||
from sqlalchemy import Column, Integer, String, Table, DateTime
|
||||
from panoramix import models, utils
|
||||
|
||||
config = app.config
|
||||
|
@ -59,63 +59,6 @@ def init():
|
|||
def load_examples(sample):
|
||||
"""Loads a set of Slices and Dashboards and a supporting dataset """
|
||||
print("Loading examples into {}".format(db))
|
||||
session = db.session()
|
||||
Country = Table(
|
||||
"countries", Base.metadata,
|
||||
Column("id", Integer, primary_key=True),
|
||||
Column("ds", DateTime, default=datetime.now()),
|
||||
Column("name", String(255)),
|
||||
Column("cca2", String(2)),
|
||||
Column("cca3", String(3)),
|
||||
Column("cioc", String(3)),
|
||||
Column("capital", String(255)),
|
||||
Column("lat", Float),
|
||||
Column("lng", Float),
|
||||
Column("area", Float),
|
||||
)
|
||||
try:
|
||||
Country.drop(db.engine)
|
||||
except:
|
||||
pass
|
||||
Country.create(db.engine)
|
||||
|
||||
filepath = os.path.join(config.get("BASE_DIR"), 'data/countries.json')
|
||||
with open(filepath, 'r') as f:
|
||||
d = {}
|
||||
for c in json.load(f):
|
||||
if not c['latlng']:
|
||||
continue
|
||||
db.engine.execute(
|
||||
Country.insert(),
|
||||
name=c['name']['common'].encode('utf8'),
|
||||
cca2=c['cca2'],
|
||||
cca3=c['cca3'],
|
||||
cioc=c['cioc'],
|
||||
capital=c['capital'],
|
||||
lat=c['latlng'][0],
|
||||
lng=c['latlng'][1],
|
||||
area=c['area'],
|
||||
)
|
||||
d[c['cca3']] = dict(
|
||||
name=c['name']['common'],
|
||||
cca2=c['cca2'],
|
||||
cca3=c['cca3'],
|
||||
cioc=c['cioc'],
|
||||
capital=c['capital'],
|
||||
lat=c['latlng'][0],
|
||||
lng=c['latlng'][1],
|
||||
area=c['area'],
|
||||
)
|
||||
#print(json.dumps(d, indent=4))
|
||||
print("Creating database reference")
|
||||
DB = models.Database
|
||||
dbobj = session.query(DB).filter_by(database_name='main').first()
|
||||
if not dbobj:
|
||||
dbobj = DB(database_name="main")
|
||||
print(config.get("SQLALCHEMY_DATABASE_URI"))
|
||||
dbobj.sqlalchemy_uri = config.get("SQLALCHEMY_DATABASE_URI")
|
||||
session.add(dbobj)
|
||||
session.commit()
|
||||
|
||||
|
||||
BirthNames = Table(
|
||||
|
@ -136,8 +79,8 @@ def load_examples(sample):
|
|||
pass
|
||||
|
||||
BirthNames.create(db.engine)
|
||||
session = db.session()
|
||||
filepath = os.path.join(config.get("BASE_DIR"), 'data/birth_names.csv.gz')
|
||||
'''
|
||||
with gzip.open(filepath, mode='rt') as f:
|
||||
bb_csv = csv.reader(f)
|
||||
for i, (state, year, name, gender, num) in enumerate(bb_csv):
|
||||
|
@ -162,8 +105,16 @@ def load_examples(sample):
|
|||
if sample and i>1000: break
|
||||
print("Done loading table!")
|
||||
print("-" * 80)
|
||||
'''
|
||||
|
||||
print("Creating database reference")
|
||||
DB = models.Database
|
||||
dbobj = session.query(DB).filter_by(database_name='main').first()
|
||||
if not dbobj:
|
||||
dbobj = DB(database_name="main")
|
||||
print(config.get("SQLALCHEMY_DATABASE_URI"))
|
||||
dbobj.sqlalchemy_uri = config.get("SQLALCHEMY_DATABASE_URI")
|
||||
session.add(dbobj)
|
||||
session.commit()
|
||||
|
||||
print("Creating table reference")
|
||||
TBL = models.SqlaTable
|
||||
|
|
|
@ -203,6 +203,18 @@ class FormFactory(object):
|
|||
'90 days ago',
|
||||
'1 year ago'])
|
||||
),
|
||||
'max_bubble_size': FreeFormSelectField(
|
||||
'Max Bubble Size', default="25",
|
||||
choices=self.choicify([
|
||||
'5',
|
||||
'10',
|
||||
'15',
|
||||
'25',
|
||||
'50',
|
||||
'75',
|
||||
'100',
|
||||
])
|
||||
),
|
||||
'row_limit':
|
||||
FreeFormSelectField(
|
||||
'Row limit',
|
||||
|
|
|
@ -19,13 +19,13 @@ function viz_world_map(data_attribute) {
|
|||
return '';
|
||||
done();
|
||||
}
|
||||
var ext = d3.extent(json.data, function(d){return d.metric});
|
||||
var extRadius = d3.extent(json.data, function(d){return d.radius});
|
||||
var ext = d3.extent(json.data, function(d){return d.m1});
|
||||
var extRadius = d3.extent(json.data, function(d){return d.m2});
|
||||
var radiusScale = d3.scale.linear()
|
||||
.domain([extRadius[0], extRadius[1]])
|
||||
.range([1, 40]);
|
||||
.range([1, data_attribute.form_data.max_bubble_size]);
|
||||
json.data.forEach(function(d){
|
||||
d.radius = radiusScale(d.radius);
|
||||
d.radius = radiusScale(d.m2);
|
||||
})
|
||||
var colorScale = d3.scale.linear()
|
||||
.domain([ext[0], ext[1]])
|
||||
|
@ -33,10 +33,13 @@ function viz_world_map(data_attribute) {
|
|||
var d = {};
|
||||
for (var i=0; i<json.data.length; i++){
|
||||
var country = json.data[i];
|
||||
d[country.country] = colorScale(country.metric);
|
||||
country['fillColor'] = colorScale(country.m1);
|
||||
d[country.country] = country;
|
||||
}
|
||||
f = d3.format('.3s');
|
||||
var map = new Datamap({
|
||||
element: document.getElementById(data_attribute.token),
|
||||
data: json.data,
|
||||
fills: {
|
||||
defaultFill: 'grey'
|
||||
},
|
||||
|
@ -48,6 +51,9 @@ function viz_world_map(data_attribute) {
|
|||
highlightBorderColor: 'black',
|
||||
highlightFillColor: '#005a63',
|
||||
highlightBorderWidth: 1,
|
||||
popupTemplate: function(geo, data) {
|
||||
return '<div class="hoverinfo"><strong>' + data.name + '</strong><br>'+ f(data.m1) + '</div>';
|
||||
},
|
||||
},
|
||||
bubblesConfig: {
|
||||
borderWidth: 1,
|
||||
|
@ -55,8 +61,8 @@ function viz_world_map(data_attribute) {
|
|||
borderColor: '#005a63',
|
||||
popupOnHover: true,
|
||||
radius: null,
|
||||
popupTemplate: function(geography, data) {
|
||||
return '<div class="hoverinfo"><strong>' + data.country + '</strong></div>';
|
||||
popupTemplate: function(geo, data) {
|
||||
return '<div class="hoverinfo"><strong>' + data.name + '</strong><br>'+ f(data.m2) + '</div>';
|
||||
},
|
||||
fillOpacity: 0.5,
|
||||
animate: true,
|
||||
|
|
|
@ -982,7 +982,6 @@ class WorldMapViz(BaseViz):
|
|||
'entity',
|
||||
'country_fieldtype',
|
||||
'metric',
|
||||
'secondary_metric',
|
||||
)
|
||||
},
|
||||
{
|
||||
|
@ -990,6 +989,7 @@ class WorldMapViz(BaseViz):
|
|||
'fields': (
|
||||
('show_bubbles', None),
|
||||
'secondary_metric',
|
||||
'max_bubble_size',
|
||||
)
|
||||
})
|
||||
form_overrides = {
|
||||
|
@ -1021,13 +1021,13 @@ class WorldMapViz(BaseViz):
|
|||
secondary_metric = self.form_data.get('secondary_metric')
|
||||
if metric == secondary_metric:
|
||||
ndf = df[cols]
|
||||
ndf['metric'] = df[metric]
|
||||
ndf['radius'] = df[metric]
|
||||
ndf['m1'] = df[metric]
|
||||
ndf['m2'] = df[metric]
|
||||
else:
|
||||
cols += [metric, secondary_metric]
|
||||
ndf = df[cols]
|
||||
df = ndf
|
||||
df.columns = ['country', 'metric', 'radius']
|
||||
df.columns = ['country', 'm1', 'm2']
|
||||
d = df.to_dict(orient='records')
|
||||
for row in d:
|
||||
country = countries.get(
|
||||
|
@ -1036,6 +1036,7 @@ class WorldMapViz(BaseViz):
|
|||
row['country'] = country['cca3']
|
||||
row['latitude'] = country['lat']
|
||||
row['longitude'] = country['lng']
|
||||
row['name'] = country['name']
|
||||
else:
|
||||
row['country'] = "XXX"
|
||||
return dumps(d)
|
||||
|
|
Loading…
Reference in New Issue