Skip to content

Commit

Permalink
Improve charting to roll up count when the filter value is missing.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmegginson committed Feb 24, 2016
1 parent 8dc78d2 commit e6599da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hxl_proxy/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def find_column(source, pattern):
count_col = None
if count_tag:
count_tag = hxl.TagPattern.parse(count_tag)
count_col = find_column(count_tag)
count_col = find_column(source, count_tag)

type = args.get('type', 'bar')

Expand Down
20 changes: 17 additions & 3 deletions hxl_proxy/static/hxl-proxy/hxl-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,23 @@ hxl_proxy.setupChart = function(params) {
$.get(params.data_url, function(csvString) {
var rawData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar});
var hxlData = hxl.wrap(rawData);
if (params.filter_pattern && params.filter_value) {
hxlData = hxlData.withRows(params.filter_pattern + '=' + params.filter_value);

if (params.filter_pattern) {
// If we have a filter pattern, apply it first
if (params.filter_value) {
// If there's a value, use it to filter
hxlData = hxlData.withRows(params.filter_pattern + '=' + params.filter_value);
} else if (!params.count_pattern) {
// If there's no value and we're not counting rows, sum up the results
hxlData = hxlData.count(params.label_pattern, get_value_pattern(hxlData));
for (var i in hxlData.columns) {
column = hxlData.columns[i]
if (column.attributes.indexOf('sum') != -1) {
params.value_pattern = column.displayTag;
break;
}
}
}
}
if (params.count_pattern) {
hxlData = hxlData.count(params.count_pattern);
Expand All @@ -289,7 +304,6 @@ hxl_proxy.setupChart = function(params) {
chartData.push([label, 0 + value]);
}
}
console.log(chartData);

var data = google.visualization.arrayToDataTable(chartData);

Expand Down

0 comments on commit e6599da

Please sign in to comment.