From 13b5f126226adcdbda71dbbbcc808b8b81141cfd Mon Sep 17 00:00:00 2001 From: Allen Cook Date: Thu, 26 Feb 2015 20:32:33 -0500 Subject: [PATCH] Make the pie charts run dynamically from the table data instead of the global budget data --- coffee/directives.coffee | 18 ++++++++++-------- haml/home.haml | 4 ++-- public/home.html | 4 ++-- public/js/all.js | 22 ++++++++++------------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/coffee/directives.coffee b/coffee/directives.coffee index 7411d55..eff79e5 100644 --- a/coffee/directives.coffee +++ b/coffee/directives.coffee @@ -1,13 +1,14 @@ lex_app.directive 'allfundschart', (Budget) -> restrict: 'E' replace: true + transclude: true scope: - data: '=' + {} template: '
' link: (scope, element, attrs) -> - scope.$watch 'data.length', -> - return unless scope.data && scope.data.length > 0 - grouped_data = Budget.group_data(scope.data, 'fund_name', + scope.$watch '$parent.table_data.length', -> + return unless scope.$parent.table_data && scope.$parent.table_data.length > 0 + grouped_data = Budget.group_data(scope.$parent.table_data, 'fund_name', 'fy_2014_adopted') color = d3.scale.category20() chart = new PieChart(element[0], color, 'fy_2014_adopted') @@ -19,13 +20,14 @@ lex_app.directive 'allfundschart', (Budget) -> lex_app.directive 'generalserviceschart', (Budget) -> restrict: 'E' replace: true + transclude: true scope: - data: '=' + {} template: '
' link: (scope, element, attrs) -> - scope.$watch 'data.length', -> - return unless scope.data && scope.data.length > 0 - gen_serv_data = Budget.extract_fund_data(1101, scope.data) + scope.$watch '$parent.table_data.length', -> + return unless scope.$parent.table_data && scope.$parent.table_data.length > 0 + gen_serv_data = Budget.extract_fund_data(1101, scope.$parent.table_data) grouped_data = Budget.group_data(gen_serv_data, 'division_name', 'fy_2014_adopted') color = d3.scale.category20() diff --git a/haml/home.haml b/haml/home.haml index bb5149f..511dcaa 100644 --- a/haml/home.haml +++ b/haml/home.haml @@ -6,12 +6,12 @@ %h3 All Funds %i.fa.fa-spinner.fa-spin{ng: {show: 'loading.budget_data'}} - %allFundsChart{data: 'budget_data'} + %allFundsChart .col-md-6 %h3 General Services %i.fa.fa-spinner.fa-spin{ng: {show: 'loading.budget_data'}} - %generalServicesChart{data: 'budget_data'} + %generalServicesChart %hr %table.table.table-striped{ng: {if: 'table_data.length > 0'}} %thead diff --git a/public/home.html b/public/home.html index e1bd015..3904725 100644 --- a/public/home.html +++ b/public/home.html @@ -7,14 +7,14 @@

All Funds

- +

General Services

- +
diff --git a/public/js/all.js b/public/js/all.js index 8167930..40287f6 100644 --- a/public/js/all.js +++ b/public/js/all.js @@ -830,17 +830,16 @@ lex_app.directive('allfundschart', function(Budget) { return { restrict: 'E', replace: true, - scope: { - data: '=' - }, + transclude: true, + scope: {}, template: '
', link: function(scope, element, attrs) { - return scope.$watch('data.length', function() { + return scope.$watch('$parent.table_data.length', function() { var chart, color, grouped_data; - if (!(scope.data && scope.data.length > 0)) { + if (!(scope.$parent.table_data && scope.$parent.table_data.length > 0)) { return; } - grouped_data = Budget.group_data(scope.data, 'fund_name', 'fy_2014_adopted'); + grouped_data = Budget.group_data(scope.$parent.table_data, 'fund_name', 'fy_2014_adopted'); color = d3.scale.category20(); chart = new PieChart(element[0], color, 'fy_2014_adopted'); chart.create_root(grouped_data); @@ -860,17 +859,16 @@ lex_app.directive('generalserviceschart', function(Budget) { return { restrict: 'E', replace: true, - scope: { - data: '=' - }, + transclude: true, + scope: {}, template: '
', link: function(scope, element, attrs) { - return scope.$watch('data.length', function() { + return scope.$watch('$parent.table_data.length', function() { var chart, color, gen_serv_data, grouped_data; - if (!(scope.data && scope.data.length > 0)) { + if (!(scope.$parent.table_data && scope.$parent.table_data.length > 0)) { return; } - gen_serv_data = Budget.extract_fund_data(1101, scope.data); + gen_serv_data = Budget.extract_fund_data(1101, scope.$parent.table_data); grouped_data = Budget.group_data(gen_serv_data, 'division_name', 'fy_2014_adopted'); color = d3.scale.category20(); chart = new PieChart(element[0], color, 'fy_2014_adopted');