@@ -14,6 +14,7 @@ const Taxonomy = (function() {
1414 '#a6761d' ,
1515 '#7f7f7f'
1616 ] ;
17+ let tagTypes = { } ;
1718
1819 function updateColor ( word , color ) {
1920 if ( word instanceof Word ) {
@@ -29,28 +30,27 @@ const Taxonomy = (function() {
2930 class Taxonomy {
3031 constructor ( id ) {
3132 this . tree = { } ;
32- this . tagTypes = { } ;
3333 div = document . getElementById ( 'taxonomy' ) ;
3434 }
3535
3636 buildTagTypes ( words ) {
37- this . tagTypes = { } ;
37+ tagTypes = { } ;
3838 words . forEach ( word => {
3939 if ( word . tag ) {
40- if ( this . tagTypes [ word . tag . val ] ) {
41- this . tagTypes [ word . tag . val ] . push ( word ) ;
40+ if ( tagTypes [ word . tag . val ] ) {
41+ tagTypes [ word . tag . val ] . push ( word ) ;
4242 }
4343 else {
44- this . tagTypes [ word . tag . val ] = [ word ] ;
44+ tagTypes [ word . tag . val ] = [ word ] ;
4545 }
4646 }
4747 if ( word . clusters . length > 0 ) {
4848 word . clusters . forEach ( cluster => {
49- if ( this . tagTypes [ cluster . val ] ) {
50- this . tagTypes [ cluster . val ] . push ( cluster ) ;
49+ if ( tagTypes [ cluster . val ] ) {
50+ tagTypes [ cluster . val ] . push ( cluster ) ;
5151 }
5252 else {
53- this . tagTypes [ cluster . val ] = [ cluster ] ;
53+ tagTypes [ cluster . val ] = [ cluster ] ;
5454 }
5555 } ) ;
5656 }
@@ -96,7 +96,6 @@ const Taxonomy = (function() {
9696 }
9797
9898 populateTaxonomy ( ) {
99- let tagTypes = this . tagTypes ;
10099 let keys = Object . keys ( tagTypes ) ;
101100
102101 // populate taxonomy
@@ -204,6 +203,35 @@ const Taxonomy = (function() {
204203 tagTypes [ tag ] . forEach ( word => updateColor ( word , colors [ i ] ) ) ;
205204 } ) ;
206205 }
206+
207+ remove ( object ) {
208+ // TODO: fix the fuck out of this
209+ return ;
210+ let tag = object . val ;
211+ let entity = object . entity ;
212+ if ( tagTypes [ tag ] ) {
213+ let i = tagTypes [ tag ] . indexOf ( entity ) ;
214+ if ( i > - 1 ) {
215+ tagTypes [ tag ] . splice ( i , 1 ) ;
216+ if ( tagTypes [ tag ] . length < 1 ) {
217+ delete tagTypes [ tag ] ;
218+ }
219+ }
220+ }
221+ }
222+
223+ getColor ( label , object ) {
224+ //FIXME: fix me the fuck up
225+ return ;
226+ let keys = Object . keys ( tagTypes ) ;
227+ if ( tagTypes [ label ] ) {
228+ return colors [ keys . indexOf ( label ) ] ;
229+ }
230+ else {
231+ tagTypes [ label ] = object ;
232+ return colors [ keys . length ] || 'black' ;
233+ }
234+ }
207235 }
208236 return Taxonomy ;
209237} ) ( ) ;
0 commit comments