Skip to content

Commit

Permalink
Passing a ctrl to the js
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Dec 18, 2015
1 parent 5435f53 commit c108063
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 51 deletions.
4 changes: 2 additions & 2 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,14 @@ def query(
select_exprs.append(s)
metrics_exprs = []

if is_timeseries and groupby:
if is_timeseries:
select_exprs += [timestamp]
groupby_exprs += [timestamp]

select_exprs += metrics_exprs
qry = select(select_exprs)
from_clause = table(self.table_name)
if groupby:
if not columns:
qry = qry.group_by(*groupby_exprs)

time_filter = [
Expand Down
6 changes: 4 additions & 2 deletions panoramix/static/panoramix.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ var px = (function() {
$('span.query').removeClass('disabled');
$('#timer').addClass('btn-success');
},
error: function (data) {
error: function (msg) {
clearInterval(timer);
token.find("img.loading").hide();
var err = '<div class="alert alert-danger">' + msg + '</div>';
token.html(err);
$('#timer').removeClass('btn-warning');
$('span.query').removeClass('disabled');
$('#timer').addClass('btn-error');
$('#timer').addClass('btn-danger');
}
};
widget = {
Expand Down
8 changes: 3 additions & 5 deletions panoramix/static/widgets/viz_bignumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ px.registerWidget('big_number', function(data_attribute) {
var json_callback = data_attribute['json_endpoint'];
var div = d3.select('#' + token_name);

function render(done) {
function render(ctrl) {
d3.json(json_callback, function(error, payload){
//Define the percentage bounds that define color from red to green
div.html("");
if (error != null){
var err = '<div class="alert alert-danger">' + error.responseText + '</div>';
div.html(err);
done(payload);
ctrl.error(error.responseText);
return '';
}
json = payload.data;
Expand Down Expand Up @@ -137,7 +135,7 @@ px.registerWidget('big_number', function(data_attribute) {
div.select('g.digits').transition().duration(500).attr('opacity', 1);
div.select('g.axis').transition().duration(500).attr('opacity', 0);
});
done(payload);
ctrl.done(payload);
});
};

Expand Down
8 changes: 3 additions & 5 deletions panoramix/static/widgets/viz_directed_force.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ function viz_directed_force(data_attribute) {
if (charge === undefined){
charge = -500;
}
var render = function(done) {
var render = function(ctrl) {
d3.json(data_attribute.json_endpoint, function(error, json) {

if (error != null){
var err = '<div class="alert alert-danger">' + error.responseText + '</div>';
token.html(err);
done();
ctrl.error(error.responseText);
return '';
}
links = json.data;
Expand Down Expand Up @@ -152,7 +150,7 @@ function viz_directed_force(data_attribute) {
.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")"; });
}
done(json);
ctrl.done(json);
});
}
return {
Expand Down
4 changes: 2 additions & 2 deletions panoramix/static/widgets/viz_markup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
px.registerWidget('markup', function(data_attribute) {

function refresh(done) {
function refresh(ctrl) {
$('#code').attr('rows', '15')
done();
ctrl.done();
}
return {
render: refresh,
Expand Down
8 changes: 3 additions & 5 deletions panoramix/static/widgets/viz_nvd3.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function viz_nvd3(data_attribute) {
var jtoken = $('#' + token_name);
var chart_div = $('#' + token_name).find("div.chart");

var refresh = function(done) {
var refresh = function(ctrl) {
chart_div.hide();
$.getJSON(json_callback, function(payload) {
var data = payload.data;
Expand Down Expand Up @@ -161,13 +161,11 @@ function viz_nvd3(data_attribute) {
return chart;
});
chart_div.show();
done(data);
ctrl.done(data);
})
.fail(function(xhr) {
var err = '<div class="alert alert-danger">' + xhr.responseText + '</div>';
done(data);
chart_div.show();
chart_div.html(err);
ctrl.error(xhr.responseText);
});
};
var resize = function() {
Expand Down
8 changes: 3 additions & 5 deletions panoramix/static/widgets/viz_pivot_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ px.registerWidget('pivot_table', function(data_attribute) {
var token = $('#' + token_name);
var form_data = data_attribute.form_data;

function refresh(done) {
function refresh(ctrl) {
$.getJSON(data_attribute.json_endpoint, function(json){
token.html(json.data);
if (form_data.groupby.length == 1){
Expand All @@ -14,12 +14,10 @@ px.registerWidget('pivot_table', function(data_attribute) {
table.column('-1').order( 'desc' ).draw();
}
token.show();
done(json);
ctrl.done(json);
}).fail(function(xhr){
var err = '<div class="alert alert-danger">' + xhr.responseText + '</div>';
token.html(err);
token.show();
done();
ctrl.error(xhr.responseText);
});
}
return {
Expand Down
8 changes: 3 additions & 5 deletions panoramix/static/widgets/viz_sankey.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function viz_sankey(data_attribute) {
var width = xy.width;
var height = xy.height - 25;

var render = function(done) {
var render = function(ctrl) {
var margin = {top: 1, right: 1, bottom: 6, left: 1};
width = width - margin.left - margin.right;
height = height - margin.top - margin.bottom;
Expand All @@ -28,9 +28,7 @@ function viz_sankey(data_attribute) {

d3.json(data_attribute.json_endpoint, function(error, json) {
if (error != null){
var err = '<div class="alert alert-danger">' + error.responseText + '</div>';
token.html(err);
done();
ctrl.error(error.responseText);
return '';
}
links = json.data;
Expand Down Expand Up @@ -98,7 +96,7 @@ function viz_sankey(data_attribute) {
link.attr("d", path);
}
token.select("img.loading").remove();
done(json);
ctrl.done(json);
});
}
return {
Expand Down
7 changes: 3 additions & 4 deletions panoramix/static/widgets/viz_sunburst.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Modified from http://bl.ocks.org/kerryrodden/7090426

function viz_sunburst(data_attribute) {
var token = d3.select('#' + data_attribute.token);
var render = function(done) {
var render = function(ctrl) {
// Breadcrumb dimensions: width, height, spacing, width of tip/tail.
var b = {
w: 100, h: 30, s: 3, t: 10
Expand Down Expand Up @@ -42,13 +42,12 @@ function viz_sunburst(data_attribute) {
d3.json(data_attribute.json_endpoint, function(error, json){

if (error != null){
var err = '<div class="alert alert-danger">' + error.responseText + '</div>';
token.html(err);
ctrl.error(error.responseText);
return '';
}
var tree = buildHierarchy(json.data);
createVisualization(tree);
done(json);
ctrl.done(json);
});

// Main function to draw and set up the visualization, once we have the data.
Expand Down
9 changes: 3 additions & 6 deletions panoramix/static/widgets/viz_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ px.registerWidget('table', function(data_attribute) {
var token_name = data_attribute['token'];
var token = $('#' + token_name);

function refresh(done) {
function refresh(ctrl) {
$.getJSON(data_attribute.json_endpoint, function(json){
var data = json.data;
var metrics = json.form_data.metrics;
Expand Down Expand Up @@ -50,12 +50,9 @@ px.registerWidget('table', function(data_attribute) {
var main_metric = data_attribute.form_data.metrics[0];
datatable.column(data.columns.indexOf(main_metric)).order( 'desc' ).draw();
}
done(json);
ctrl.done(json);
}).fail(function(xhr){
var err = '<div class="alert alert-danger">' + xhr.responseText + '</div>';
token.html(err);
token.show();
ctrl.done();
ctrl.error(xhr.responseText);
});
}

Expand Down
8 changes: 3 additions & 5 deletions panoramix/static/widgets/viz_wordcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ px.registerWidget('word_cloud', function(data_attribute) {
var json_callback = data_attribute['json_endpoint'];
var token = d3.select('#' + token_name);

function refresh(done) {
function refresh(ctrl) {
d3.json(json_callback, function(error, json) {
if (error != null){
var err = '<div class="alert alert-danger">' + error.responseText + '</div>';
token.html(err);
done();
ctrl.error(error.responseText);
return '';
}
var data = json.data;
Expand Down Expand Up @@ -63,7 +61,7 @@ px.registerWidget('word_cloud', function(data_attribute) {
})
.text(function(d) { return d.text; });
}
done(data);
ctrl.done(data);
});
}

Expand Down
8 changes: 3 additions & 5 deletions panoramix/static/widgets/viz_world_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

function viz_world_map(data_attribute) {
var token = d3.select('#' + data_attribute.token);
var render = function(done) {
var render = function(ctrl) {
// Breadcrumb dimensions: width, height, spacing, width of tip/tail.
var div = token;
var xy = div.node().getBoundingClientRect();
Expand All @@ -14,10 +14,8 @@ function viz_world_map(data_attribute) {
d3.json(data_attribute.json_endpoint, function(error, json){

if (error != null){
var err = '<div class="alert alert-danger">' + error.responseText + '</div>';
token.html(err);
ctrl.error(error.responseText);
return '';
done();
}
var ext = d3.extent(json.data, function(d){return d.m1});
var extRadius = d3.extent(json.data, function(d){return d.m2});
Expand Down Expand Up @@ -81,7 +79,7 @@ function viz_world_map(data_attribute) {
map.bubbles(json.data);
token.selectAll("circle.datamaps-bubble").style('fill', '#005a63');
}
done(json);
ctrl.done(json);
});
}

Expand Down

0 comments on commit c108063

Please sign in to comment.