@@ -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} ) ;
0 commit comments