Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit 78fb375

Browse files
committed
Support for interactive legend
1 parent ba10d36 commit 78fb375

1 file changed

Lines changed: 43 additions & 2 deletions

File tree

app/components/vistk-network.js

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default Ember.Component.extend({
2222
d.name_short_en = datum.name_short_en + ` (${datum.code})`;
2323
d.name_short_es = datum.name_short_es + ` (${datum.code})`;
2424
d.color = datum.color;
25+
d.group = datum.group;
2526
d[this.get('varDependent')] = datum[this.get('varDependent')];
2627
d[this.get('varRCA')] = datum[this.get('varRCA')];
2728
}
@@ -47,6 +48,7 @@ export default Ember.Component.extend({
4748
return this.get('graph').edges;
4849
}),
4950
network: computed('data.[]', 'varDependent', 'dataType', 'vis', 'i18n.locale', function() {
51+
let keyFilter = this.get('keyFilter');
5052
return vistk.viz().params({
5153
type: 'productspace',
5254
height: this.get('height'),
@@ -68,10 +70,16 @@ export default Ember.Component.extend({
6870
attr: 'name',
6971
marks: [{
7072
type: 'circle',
71-
fill: (d) => {
73+
fill: (d, i, vars) => {
7274
//if there is no search, color products export > 0 and rca > 1
7375
// industries if RCA > 1 ( varDependent for industries is also rca )
74-
if(d[this.get('varRCA')] >= 1){
76+
if(keyFilter.length > 0) {
77+
if(d.group === keyFilter[0]) {
78+
return d.color;
79+
} else {
80+
return 'white';
81+
}
82+
} else if(d[this.get('varRCA')] >= 1) {
7583
return d.color;
7684
}
7785
},
@@ -142,6 +150,39 @@ export default Ember.Component.extend({
142150
this.removeObserver('i18n.locale', this, this.update);
143151
this.removeObserver('data.[]', this, this.update);
144152
},
153+
refresh: observer('keyFilter', function() {
154+
if(!this.element){ return ; } //do not redraw if not there
155+
let keyFilter = this.get('keyFilter');
156+
157+
Ember.run.later(this , function() {
158+
if(this.get('network')) {
159+
console.log('filter netowr', keyFilter)
160+
d3.select(this.get('id')).call(this.get('network'));
161+
this.get('network').params({filter: keyFilter});
162+
this.get('network').params({
163+
y_invert: true,
164+
items: [{
165+
marks: [{
166+
type: 'circle',
167+
fill: (d, i, vars) => {
168+
if(keyFilter.length > 0) {
169+
if(d.group === keyFilter[0]) {
170+
return d.color;
171+
} else {
172+
return 'white';
173+
}
174+
} else if(d[this.get('varRCA')] >= 1) {
175+
return d.color;
176+
}
177+
}
178+
}]
179+
}]
180+
});
181+
this.get('network').params().refresh = true;
182+
d3.select(this.get('id')).call(this.get('network'));
183+
}
184+
});
185+
}),
145186
update: observer('data.[]', 'varDependent', 'i18n.locale', function() {
146187
if(!this.element){ return false; } //do not redraw if not there
147188
d3.select(this.get('id')).select('svg').remove();

0 commit comments

Comments
 (0)