Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Sep 23, 2015
1 parent f395c83 commit e126ab4
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 102 deletions.
117 changes: 72 additions & 45 deletions panoramix/bin/panoramix
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ def runserver(debug, port):
print("Starting server with command: " + cmd)
Popen(cmd, shell=True).wait()

@manager.command
def load_examples():
@manager.option(
'-s', '--sample', action='store_true',
help="Only load 1000 rows (faster, used for testing)")
def load_examples(sample):
"""Loads a set of Slices and Dashboards and a supporting dataset """
print("Loading examples into {}".format(db))
class BirthNames(Base):
Expand Down Expand Up @@ -75,7 +77,7 @@ def load_examples():
print("{} loaded out of 82527 rows".format(i))
session.commit()
session.commit()
#if i>5000: break
if sample and i>1000: break
print("Done loading table!")
print("-" * 80)
print("Creating database reference")
Expand Down Expand Up @@ -104,37 +106,32 @@ def load_examples():
tbl = obj

print("Creating some slices")
def get_slice_json(
slice_name, filter_value, viz_type="table", group_by=None,
granularity="all", filter_operator='in',
row_limit=config.ROW_LIMIT, flt_col_1="gender", code=""):
group_by = group_by if group_by is not None else ["name"]
default_json = {
def get_slice_json(slice_name, **kwargs):
defaults = {
"compare_lag": "10",
"compare_suffix": "o10Y",
"datasource_id": "1",
"datasource_name": "birth_names",
"datasource_type": "table",
"limit": "25",
"flt_col_1": flt_col_1,
"flt_eq_1": filter_value,
"flt_op_1": filter_operator,
"granularity": granularity,
"groupby": group_by,
"flt_col_1": "gender",
"flt_eq_1": "",
"flt_op_1": "in",
"granularity": "all",
"groupby": [],
"metric": 'sum__num',
"metrics": [
"sum__num"
],
"row_limit": row_limit,
"metrics": ["sum__num"],
"row_limit": config.ROW_LIMIT,
"since": "100 years",
"slice_name": slice_name,
"until": "now",
"viz_type": viz_type,
"viz_type": "table",
"where": "",
"code": code,
"markup_type": "markdown",
}
return json.dumps(default_json, indent=4, sort_keys=True)
d = defaults.copy()
d.update(kwargs)
return json.dumps(d, indent=4, sort_keys=True)
Slice = models.Slice
slices = []

Expand All @@ -146,7 +143,8 @@ def load_examples():
viz_type='table',
datasource_type='table',
table=tbl,
params=get_slice_json(slice_name, "girl", row_limit=50))
params=get_slice_json(
slice_name, groupby=['name'], flt_eq_1="girl", row_limit=50))
session.add(slc)
slices.append(slc)

Expand All @@ -158,7 +156,8 @@ def load_examples():
viz_type='table',
datasource_type='table',
table=tbl,
params=get_slice_json(slice_name, "boy", row_limit=50))
params=get_slice_json(
slice_name, groupby=['name'], flt_eq_1="boy", row_limit=50))
session.add(slc)
slices.append(slc)

Expand All @@ -170,7 +169,9 @@ def load_examples():
viz_type='big_number',
datasource_type='table',
table=tbl,
params=get_slice_json(slice_name, "", "big_number", [], "1 day"))
params=get_slice_json(
slice_name, viz_type="big_number", granularity="1 day",
compare_lag="5", compare_suffix="over 5Y"))
session.add(slc)
slices.append(slc)

Expand All @@ -182,7 +183,8 @@ def load_examples():
viz_type='pie',
datasource_type='table',
table=tbl,
params=get_slice_json(slice_name, "", "pie", ['gender']))
params=get_slice_json(
slice_name, viz_type="pie", groupby=['gender']))
session.add(slc)
slices.append(slc)

Expand All @@ -195,8 +197,8 @@ def load_examples():
datasource_type='table',
table=tbl,
params=get_slice_json(
slice_name, "other", "dist_bar", ['state'],
filter_operator='not in', flt_col_1='state'))
slice_name, flt_eq_1="other", viz_type="dist_bar",
groupby=['state'], flt_op_1='not in', flt_col_1='state'))
session.add(slc)
slices.append(slc)

Expand All @@ -208,7 +210,9 @@ def load_examples():
viz_type='line',
datasource_type='table',
table=tbl,
params=get_slice_json(slice_name, "", "line", ['name'], '1 day'))
params=get_slice_json(
slice_name, viz_type="line", groupby=['name'],
granularity='1 day'))
session.add(slc)
slices.append(slc)

Expand All @@ -227,7 +231,23 @@ The source dataset came from [here](https://github.com/hadley/babynames)
datasource_type='table',
table=tbl,
params=get_slice_json(
slice_name, "", "markup", ['name'], code=code))
slice_name, viz_type="markup", markup_type="markdown",
code=code))
session.add(slc)
slices.append(slc)

slice_name = "Name Cloud"
slc = session.query(Slice).filter_by(slice_name=slice_name).first()
if not slc:
slc = Slice(
slice_name=slice_name,
viz_type='word_cloud',
datasource_type='table',
table=tbl,
params=get_slice_json(
slice_name, viz_type="word_cloud", size_from="10",
groupby=['name'], size_to="70", rotation="square",
limit='100'))
session.add(slc)
slices.append(slc)

Expand All @@ -240,52 +260,59 @@ The source dataset came from [here](https://github.com/hadley/babynames)
position_json="""
[
{
"size_y": 5,
"size_y": 4,
"size_x": 2,
"col": 10,
"col": 3,
"slice_id": "1",
"row": 1
"row": 3
},
{
"size_y": 5,
"size_y": 4,
"size_x": 2,
"col": 8,
"col": 1,
"slice_id": "2",
"row": 1
"row": 3
},
{
"size_y": 2,
"size_x": 2,
"col": 6,
"col": 1,
"slice_id": "3",
"row": 1
},
{
"size_y": 2,
"size_x": 2,
"col": 4,
"col": 3,
"slice_id": "4",
"row": 1
},
{
"size_y": 3,
"size_x": 4,
"col": 4,
"size_x": 7,
"col": 5,
"slice_id": "5",
"row": 3
"row": 4
},
{
"size_y": 6,
"size_y": 5,
"size_x": 11,
"col": 1,
"slice_id": "6",
"row": 6
"row": 7
},
{
"size_y": 5,
"size_y": 3,
"size_x": 3,
"col": 1,
"slice_id": "9",
"col": 9,
"slice_id": "7",
"row": 1
},
{
"size_y": 3,
"size_x": 4,
"col": 5,
"slice_id": "8",
"row": 1
}
]
Expand Down
5 changes: 3 additions & 2 deletions panoramix/templates/panoramix/viz_bignumber.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
var v = data[data.length -1][1];
if (json.compare_lag >0){
pos = data.length - (json.compare_lag+1);
if(pos >=0)
v_compare = 1-(v / data[pos][1]);
if(pos >=0){
v_compare = (v / data[pos][1])-1;
}
}
var date_ext = d3.extent(data, function(d){return d[0]});
var value_ext = d3.extent(data, function(d){return d[1]});
Expand Down
1 change: 0 additions & 1 deletion panoramix/templates/panoramix/viz_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<script>
$( document ).ready(function() {
var url = "{{ viz.get_url(async="true", standalone="true", skip_libs="true")|safe }}";
console.log(url);
var token = $("#{{ viz.token }}");
token.load(url, function(response, status, xhr){
if(status=="error"){
Expand Down
113 changes: 59 additions & 54 deletions panoramix/templates/panoramix/viz_word_cloud.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,67 @@
{% macro viz_js(viz) %}
<script>
$( document ).ready(function() {
var range = [
{{ viz.args.get('size_from') or 20 }},
{{ viz.args.get('size_to') or 100 }}
];
var rotation = "{{ viz.args.get("rotation", "random") }}";
if (rotation == "square")
var f_rotation = function() { return ~~(Math.random() * 2) * 90; };
else if (rotation == "flat")
var f_rotation = function() { return 0};
else
var f_rotation = function() { return (~~(Math.random() * 6) - 3) * 30;};

var url = "{{ viz.get_url(json="true")|safe }}";
var token = d3.select("#{{ viz.token }}");
var box = token.node().getBoundingClientRect();
var size = [box.width, box.height-25];
d3.json(url, function(error, data){
if(error != null){
var err = '<div class="alert alert-danger">' + error.responseText + '</div>';
token.html(err);
return '';
}
scale = d3.scale.linear()
.range(range)
.domain(d3.extent(data, function(d) { return d.size; }));
var fill = d3.scale.category20();
var layout = d3.layout.cloud()
.size(size)
.words(data)
.padding(5)
.rotate(f_rotation)
.font("serif")
.fontSize(function(d) { return scale(d.size); })
.on("end", draw);
layout.start();
function draw(words) {
token.selectAll("*").remove();
function refresh() {
var range = [
{{ viz.args.get('size_from') or 20 }},
{{ viz.args.get('size_to') or 100 }}
];
var rotation = "{{ viz.args.get("rotation", "random") }}";
if (rotation == "square")
var f_rotation = function() { return ~~(Math.random() * 2) * 90; };
else if (rotation == "flat")
var f_rotation = function() { return 0};
else
var f_rotation = function() { return (~~(Math.random() * 6) - 3) * 30;};

var url = "{{ viz.get_url(json="true")|safe }}";
var box = token.node().getBoundingClientRect();
var size = [box.width, box.height-25];
d3.json(url, function(error, data){
if(error != null){
var err = '<div class="alert alert-danger">' + error.responseText + '</div>';
token.html(err);
return '';
}
scale = d3.scale.linear()
.range(range)
.domain(d3.extent(data, function(d) { return d.size; }));
var fill = d3.scale.category20();
var layout = d3.layout.cloud()
.size(size)
.words(data)
.padding(5)
.rotate(f_rotation)
.font("serif")
.fontSize(function(d) { return scale(d.size); })
.on("end", draw);
layout.start();
function draw(words) {
token.selectAll("*").remove();

token.append("svg")
.attr("width", layout.size()[0])
.attr("height", layout.size()[1])
.append("g")
.attr("transform", "translate(" + layout.size()[0] / 2 + "," + layout.size()[1] / 2 + ")")
.selectAll("text")
.data(words)
.enter().append("text")
.style("font-size", function(d) { return d.size + "px"; })
.style("font-family", "Impact")
.style("fill", function(d, i) { return fill(i); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ") rotate(" + d.rotate + ")";
})
.text(function(d) { return d.text; });
}
});
token.append("svg")
.attr("width", layout.size()[0])
.attr("height", layout.size()[1])
.append("g")
.attr("transform", "translate(" + layout.size()[0] / 2 + "," + layout.size()[1] / 2 + ")")
.selectAll("text")
.data(words)
.enter().append("text")
.style("font-size", function(d) { return d.size + "px"; })
.style("font-family", "Impact")
.style("fill", function(d, i) { return fill(i); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ") rotate(" + d.rotate + ")";
})
.text(function(d) { return d.text; });
}
});
}
refresh();
jtoken = $(token);
jtoken.parent().find("a.refresh").click(refresh);
});
</script>
{% endmacro %}
Expand Down

0 comments on commit e126ab4

Please sign in to comment.