Skip to content

Commit

Permalink
Adding volume indicators on filter box
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Dec 27, 2015
1 parent 07df0f1 commit ef14c21
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It empowers its user to perform **analytics at the speed of thought**.

Panoramix provides:
* A quick way to intuitively visualize datasets
* Create and share simple dashboards
* Create and share interactive dashboards
* A rich set of visualizations to analyze your data, as well as a flexible
way to extend the capabilities
* An extensible, high granularity security model allowing intricate rules
Expand Down
2 changes: 1 addition & 1 deletion panoramix/static/panoramix.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ var px = (function() {
addFilter: function(slice_id, filters) {
this.filters[slice_id] = filters;
this.refreshExcept(slice_id);
console.log(this.filters);
},
refreshExcept: function(slice_id) {
this.slices.forEach(function(slice){
Expand Down Expand Up @@ -197,6 +196,7 @@ var px = (function() {

function druidify(){
prepForm();
$('div.alert').remove();
slice.render();
}

Expand Down
4 changes: 4 additions & 0 deletions panoramix/static/widgets/viz_filter_box.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.select2-highlighted>.filter_box {
background-color: transparent;
border: 1px dashed black;
}
34 changes: 26 additions & 8 deletions panoramix/static/widgets/viz_filter_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,47 @@ px.registerViz('filter_box', function(slice) {
.append('div')
.classed('padded', true);
$.getJSON(slice.jsonEndpoint(), function(payload) {
var maxes = {};
for (filter in payload.data){
data = payload.data[filter];
var data = payload.data[filter];
maxes[filter] = d3.max(data, function(d){return d.metric});
var id = 'fltbox__' + filter;

var div = container.append('div');
div.append("label").text(filter);
var sel = div
.append('select')
.append('div')
.attr('name', filter)
.classed('form-control', true)
.attr('multiple', '')
.attr('id', id);

sel.classed('select2_box_filter form-control', true);
sel.selectAll('option').data(data).enter()
.append('option')
.attr('value', function(d){return d[0];})
.text(function(d){return d[0];});
$('#' + id).select2({
//allowClear: true,
placeholder: "Select [" + filter + ']',
containment: 'parent',
dropdownAutoWidth : true,
data:data,
multiple: true,
formatResult: function(result, container, query, escapeMarkup) {
var perc = Math.round((result.metric / maxes[result.filter]) * 100);
var style = 'padding: 2px 5px;';
style += "background-image: ";
style += "linear-gradient(to right, lightgrey, lightgrey " + perc + "%, rgba(0,0,0,0) " + perc + "%";

$(container).attr('style', 'padding: 0px; background: white;');
$(container).addClass('filter_box');
return '<div style="' + style + '"><span>' + result.text + '</span></div>';
},
})
.on('change', fltChanged);
/*
.style('background-image', function(d){
if (d.isMetric){
var perc = Math.round((d.val / maxes[d.col]) * 100);
return "linear-gradient(to right, lightgrey, lightgrey " + perc + "%, rgba(0,0,0,0) " + perc + "%";
}
})
*/
}
slice.done();
})
Expand Down
10 changes: 8 additions & 2 deletions panoramix/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,8 @@ class FilterBoxViz(BaseViz):
js_files = [
'lib/d3.min.js',
'widgets/viz_filter_box.js']
css_files = []
css_files = [
'widgets/viz_filter_box.css']
fieldsets = (
{
'label': None,
Expand Down Expand Up @@ -1149,7 +1150,12 @@ def get_df(self):
for flt in filters:
qry['groupby'] = [flt]
df = super(FilterBoxViz, self).get_df(qry)
d[flt] = [row for row in df.itertuples(index=False)]
d[flt] = [
{'id': row[0],
'text': row[0],
'filter': flt,
'metric': row[1]}
for row in df.itertuples(index=False)]
return d

def get_json_data(self):
Expand Down

0 comments on commit ef14c21

Please sign in to comment.