Skip to content

Commit 3df010a

Browse files
author
Nicholas Thomson
committed
Merge pull request #17 from cloudspace/development
[#63313086] Make minor crossfiltering improvements
2 parents 4ab59f8 + af1a10f commit 3df010a

File tree

3 files changed

+43
-66
lines changed

3 files changed

+43
-66
lines changed

app/scripts/controllers/crunchinator.js

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ angular.module('crunchinatorApp.controllers')
2121
$scope.filteredCompaniesList = [];
2222
$scope.filteredCategoriesList = [];
2323
$scope.filteredInvestorsList = [];
24-
$scope.mapboundary = 'Hello';
25-
$scope.$watch('mapBoundary', function(){
26-
});
2724

2825
$scope.geoJsonData = _.memoize(function(filteredCompanies) {
2926
var geojson = {
@@ -72,9 +69,15 @@ angular.module('crunchinatorApp.controllers')
7269
$scope.selectedCompanies = [];
7370
$scope.selectedCategories = [];
7471
$scope.selectedInvestors = [];
72+
73+
$scope.filteredCompanies();
74+
$scope.filteredCategories();
75+
$scope.filteredInvestors();
7576
};
76-
$scope.resetSelection();
7777

78+
var cat_ids = [];
79+
var company_ids = [];
80+
var inv_ids = [];
7881
$scope.toggleSelected = function(selectedItems, item) {
7982
$scope.selectedItem = item;
8083
var ind = selectedItems.indexOf(item);
@@ -86,78 +89,53 @@ angular.module('crunchinatorApp.controllers')
8689
selectedItems.push(item);
8790
}
8891

92+
cat_ids = _.pluck($scope.selectedCategories, 'id');
93+
company_ids = _.pluck($scope.selectedCompanies, 'id');
94+
inv_ids = _.pluck($scope.selectedInvestors, 'id');
95+
96+
$scope.filteredCompanies();
97+
$scope.filteredCategories();
98+
$scope.filteredInvestors();
99+
89100
$scope.selectedCompanies = _.intersection($scope.selectedCompanies, $scope.filteredCompaniesList);
90101
$scope.selectedCategories = _.intersection($scope.selectedCategories, $scope.filteredCategoriesList);
91102
$scope.selectedInvestors = _.intersection($scope.selectedInvestors, $scope.filteredInvestorsList);
92103
};
93104

94105
var crossCompanies;
95-
var companiesByCategory;
96-
var companiesByInvestors;
106+
var companiesDimension;
97107
var companiesById;
98108
$scope.filteredCompanies = function() {
99-
if(crossCompanies && companiesByCategory) {
100-
var cat_ids = _.pluck($scope.selectedCategories, 'id');
101-
var inv_ids = _.pluck($scope.selectedInvestors, 'id');
102-
companiesByCategory.filterAll(); //clear filter
103-
companiesByInvestors.filterAll(); //clear filter
104-
if(cat_ids.length > 0) {
105-
companiesByCategory.filter(function(c) { return cat_ids.indexOf(c) > -1; });
106-
}
107-
if(inv_ids.length > 0) {
108-
companiesByInvestors.filter(function(invs) { return _.intersection(invs, inv_ids).length > 0;});
109-
}
109+
if(crossCompanies) {
110+
companiesDimension.filterAll(); //clear filter
111+
companiesDimension.filter(function(c){ return ( cat_ids.length === 0 || cat_ids.indexOf(c.category_id) > -1) && (inv_ids.length === 0 || _.intersection(c.investor_ids, inv_ids).length > 0); });
110112

111-
$scope.filteredCompaniesList = companiesById.bottom(Infinity);
113+
$scope.filteredCompaniesList = companiesById.bottom(100);
112114
}
113-
114-
return $scope.filteredCompaniesList;
115115
};
116116

117117
var crossInvestors;
118-
var investorsByCategories;
119-
var investorsByCompanies;
118+
var investorsDimension;
120119
var investorsById;
121120
$scope.filteredInvestors = function() {
122121
if(crossInvestors) {
123-
var cat_ids = _.pluck($scope.selectedCategories, 'id');
124-
var company_ids = _.pluck($scope.selectedCompanies, 'id');
125-
126-
investorsByCategories.filterAll();
127-
investorsByCompanies.filterAll();
122+
investorsDimension.filterAll();
123+
investorsDimension.filter(function(i){ return (cat_ids.length === 0 || _.intersection(i.invested_category_ids, cat_ids).length > 0) && (company_ids.length === 0 || _.intersection(i.invested_company_ids, company_ids).length > 0); });
128124

129-
if(cat_ids.length > 0) {
130-
investorsByCategories.filter(function(d){ return _.intersection(d, cat_ids).length > 0;});
131-
}
132-
if(company_ids.length > 0) {
133-
investorsByCompanies.filter(function(d){ return _.intersection(d, company_ids).length > 0;});
134-
}
135-
$scope.filteredInvestorsList = investorsById.bottom(Infinity);
125+
$scope.filteredInvestorsList = investorsById.bottom(100);
136126
}
137-
return $scope.filteredInvestorsList;
138127
};
139128

140129
var crossCategories;
141-
var categoriesByInvestors;
142-
var categoriesByCompanies;
130+
var categoriesDimension;
143131
var categoriesById;
144132
$scope.filteredCategories = function() {
145133
if(crossCategories) {
146-
var company_ids = _.pluck($scope.selectedCompanies, 'id');
147-
var inv_ids = _.pluck($scope.selectedInvestors, 'id');
134+
categoriesDimension.filterAll();
135+
categoriesDimension.filter(function(c){ return (company_ids.length === 0 || _.intersection(company_ids, c.company_ids).length > 0) && (inv_ids.length === 0 || _.intersection(inv_ids, c.investor_ids).length > 0); });
148136

149-
categoriesByInvestors.filterAll();
150-
categoriesByCompanies.filterAll();
151-
152-
if(company_ids.length > 0) {
153-
categoriesByCompanies.filter(function(d){ return _.intersection(d, company_ids).length > 0;});
154-
}
155-
if(inv_ids.length > 0) {
156-
categoriesByInvestors.filter(function(invs) { return _.intersection(invs, inv_ids).length > 0;});
157-
}
158-
$scope.filteredCategoriesList = categoriesById.bottom(Infinity);
137+
$scope.filteredCategoriesList = categoriesById.bottom(100);
159138
}
160-
return $scope.filteredCategoriesList;
161139
};
162140

163141
$scope.companies = CompanyModel;
@@ -166,20 +144,23 @@ angular.module('crunchinatorApp.controllers')
166144

167145
CompanyModel.fetch().then(function(){
168146
crossCompanies = crossfilter(CompanyModel.all());
169-
companiesByCategory = crossCompanies.dimension(function(company) { return company.category_id; });
170-
companiesByInvestors = crossCompanies.dimension(function(company) { return company.investor_ids; });
147+
companiesDimension = crossCompanies.dimension(function(company) { return company; });
171148
companiesById = crossCompanies.dimension(function(company) {return company.id;});
149+
$scope.filteredCompanies();
172150
});
173151
InvestorModel.fetch().then(function(){
174152
crossInvestors = crossfilter(InvestorModel.all());
175-
investorsByCategories = crossInvestors.dimension(function(investor) { return investor.invested_category_ids; });
176-
investorsByCompanies = crossInvestors.dimension(function(investor) { return investor.invested_company_ids; });
153+
investorsDimension = crossInvestors.dimension(function(investor) { return investor; });
177154
investorsById = crossInvestors.dimension(function(investor) {return investor.id;});
155+
$scope.filteredInvestors();
178156
});
179157
CategoryModel.fetch().then(function(){
180158
crossCategories = crossfilter(CategoryModel.all());
181-
categoriesByInvestors = crossCategories.dimension(function(category) { return category.investor_ids; });
182-
categoriesByCompanies = crossCategories.dimension(function(category) { return category.company_ids; });
159+
categoriesDimension = crossCategories.dimension(function(category) { return category; });
183160
categoriesById = crossCategories.dimension(function(category) {return category.id;});
161+
$scope.filteredCategories();
184162
});
163+
164+
$scope.resetSelection();
165+
185166
});

app/scripts/directives/leafCluster.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ angular.module('crunchinatorApp.directives').directive('leafCluster', function()
2323
return scope.render(newval);
2424
}, true);
2525

26-
map.on('zoomend', function(){
27-
scope.mapBoundary = map.getBounds();
28-
});
29-
3026

3127
scope.$watch(function() {
3228
return angular.element(window)[0].innerWidth;

app/views/main.tpl.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h4 class="pull-left">Environment: {{environment}}</h4>
66
<div class="row clear-both">
77
<div class='col-sm-4 spacing-med'>
88
<h3 class="pull-left">Companies</h3>
9-
<p class="pull-right count">Count: {{f = filteredCompanies(); f.length}}</p>
9+
<p class="pull-right count">Count: {{filteredCompaniesList.length}}</p>
1010
<div id="companies" class="textlist clear-both">
1111
<div class="form-group">
1212
<div class="controls">
@@ -18,7 +18,7 @@ <h3 class="pull-left">Companies</h3>
1818
</div>
1919
<div class="dataset">
2020
<table class="table">
21-
<tbody><tr ng-class="{success: selectedCompanies.indexOf(company) &gt; -1}" ng-repeat="company in filteredCompanies()">
21+
<tbody><tr ng-class="{success: selectedCompanies.indexOf(company) &gt; -1}" ng-repeat="company in filteredCompaniesList">
2222
<td ng-click="toggleSelected(selectedCompanies, company)">{{company.name}}</td>
2323
</tr>
2424
</tbody></table>
@@ -28,7 +28,7 @@ <h3 class="pull-left">Companies</h3>
2828

2929
<div class='col-sm-4 spacing-med'>
3030
<h3 class="pull-left">Categories</h3>
31-
<p class="pull-right count">Count: {{f = filteredCategories(); f.length}}</p>
31+
<p class="pull-right count">Count: {{filteredCategoriesList.length}}</p>
3232
<div id="categories" class="textlist clear-both">
3333
<div class="form-group">
3434
<div class="controls">
@@ -40,7 +40,7 @@ <h3 class="pull-left">Categories</h3>
4040
</div>
4141
<div class="dataset">
4242
<table class="table">
43-
<tbody><tr ng-class="{success: selectedCategories.indexOf(category) &gt; -1}" ng-repeat="category in filteredCategories()">
43+
<tbody><tr ng-class="{success: selectedCategories.indexOf(category) &gt; -1}" ng-repeat="category in filteredCategoriesList">
4444
<td ng-click="toggleSelected(selectedCategories, category)">{{category.name}}</td>
4545
</tr>
4646
</tbody></table>
@@ -50,7 +50,7 @@ <h3 class="pull-left">Categories</h3>
5050

5151
<div class='col-sm-4 spacing-med'>
5252
<h3 class="pull-left">Investors</h3>
53-
<p class="pull-right count">Count: {{f = filteredInvestors(); f.length}}</p>
53+
<p class="pull-right count">Count: {{filteredInvestorsList.length}}</p>
5454
<div id="investors" class="textlist clear-both">
5555
<div class="form-group">
5656
<div class="controls">
@@ -62,7 +62,7 @@ <h3 class="pull-left">Investors</h3>
6262
</div>
6363
<div class="dataset">
6464
<table class="table">
65-
<tbody><tr ng-class="{success: selectedInvestors.indexOf(investor) &gt; -1}" ng-repeat="investor in filteredInvestors()">
65+
<tbody><tr ng-class="{success: selectedInvestors.indexOf(investor) &gt; -1}" ng-repeat="investor in filteredInvestorsList">
6666
<td ng-click="toggleSelected(selectedInvestors, investor)">{{investor.name}}</td>
6767
</tr>
6868
</tbody></table>

0 commit comments

Comments
 (0)