-
Notifications
You must be signed in to change notification settings - Fork 56
/
many-bubbles.js
executable file
·164 lines (144 loc) · 5.74 KB
/
many-bubbles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*! ***************************************************************************
*
* evolutility-ui-jquery :: many-bubbles.js
*
* View "many bubbles" to show a Bubble Chart of a collection of many models.
*
* https://github.com/evoluteur/evolutility-ui-jquery
* (c) 2017 Olivier Giulieri
*
*************************************************************************** */
Evol.ViewMany.Bubbles = Evol.View_Many.extend({
viewName: 'bubbles',
icon: 'adjust', // glyphicon-adjust
events: {
//'click .evol-buttons>button': 'click_button',
//'click .evol-title-toggle': 'click_toggle',
//'click .glyphicon-wrench': 'click_customize',
'click .btn': 'clickGroup',
'change .bubble-group': 'changeGroup',
'change .bubble-color': 'changeColor',
'change .bubble-size': 'changeSize',
'click svg>circle': 'clickCircle'
},
fieldsetFilter: Evol.Def.fieldChartable,
setupBubbles: function() {
var that=this,
ui=this.uiModel,
models = this.collection.models;
if(!this._bubblesInitialized){
var flds = Evol.Def.getFields(this.uiModel, Evol.Def.fieldChartable),
fd=flds.length?flds[0].id:null;
this.bubbles = new Evol.Bubbles({
//selector:'.evol-bubbles-body',
elem: this.$('.evol-bubbles-body').get(0),
width:1200,
height:700,
fields: flds,
colorFieldId: fd,
groupFieldId: fd,
sizeFieldId: null,
uiModel: this.uiModel,
tooltip: function(d){
var h=[],
flds=that.getFields();
Evol.ViewMany.Cards.prototype.HTMLItem.call(that, h, flds, new Backbone.Model(d), null, null, null, true);
return h.join('');
}
});
this.bubbles.setData(_.map(models, function(m){
return _.extend({
id: m.id
}, m.attributes);
}));
this._bubblesInitialized=true;
}
},
_render: function (models) {
var dom = Evol.DOM,
i18nTools = Evol.i18n.tools,
hOpt = dom.input.option,
hOptNull = dom.html.emptyOption,
fo,
fs2 = Evol.Def.getFields(this.uiModel, Evol.Def.fieldChartable),
h = '<div class="evol-many-bubbles panel '+this.style+'"><div class="evol-bubbles-body">'+
'<div class="d3-tooltip" style="opacity:0;"></div>';
//h+=this._HTMLbody(this.getFields(), pSize, this.uiModel.icon, 0, this.selectable);
h+='<div class="bubbles-opts '+this.style+'">';
if(fs2.length){
// --- Group ---
h+='<label>'+i18nTools.vizGroupBy+': </label>';
if(fs2.length>5){
fo=_.map(fs2, function(f, idx){
return hOpt(f.id, f.label, idx===0);
});
h+='<select class="form-control bubble-group">'+hOptNull + fo.join('')+'</select>';
}else{
h+='<div class="btn-group" data-toggle="buttons">'+
_.map(fs2, function(f, idx){
if(_.isUndefined(f.groupable) || f.groupable){
return '<label class="btn btn-default'+(idx===0?' active':'')+'" id="'+f.id+'">'+
'<input type="radio" name="options"'+(idx===0?' checked':'')+'>'+f.label+'</label>';
}
}).join('')+
'</div>';
}
// --- Color ---
fo=_.map(fs2, function(f, idx){
return (_.isUndefined(f.colorable) || f.colorable) ? hOpt(f.id, f.label, idx===0) : '';
});
h+='<label>'+i18nTools.vizColorBy+': </label><select class="form-control bubble-color">'+hOptNull + fo.join('')+'</select>';
// --- Size ---
fs2=_.filter(fs2, function(f){
return (_.isUndefined(f.sizable) || f.sizable) ? Evol.Def.fieldIsNumber(f) : '';
});
fo=_.map(fs2, function(f, idx){
return hOpt(f.id, f.label);
});
if(fo.length){
h+='<label>'+i18nTools.vizSizeBy+': </label><select class="form-control bubble-size">'+hOptNull+fo.join('')+'</select>';
}
//h+=dom.html.clearer;
}else{
h+=Evol.i18n.notEnoughdata;
}
h+='</div></div></div>';
this.$el.html(h);
this.setupBubbles();
return this;
},
_HTMLbody: function(){
},
_HTMLlegend: function(){
// todo
},
_$body: function(){
return this.$('.evol-bubbles-body');
},
setCollection: function(collec){
this.collection = collec;
this.bubbles.setData(_.map(collec.models, function(m){
return _.extend({
id: m.id
}, m.attributes);
}));
return this;
},
clickGroup: function(evt){
this.bubbles.changeBubblesGroup(evt.currentTarget.id);
},
changeGroup: function(evt){
this.bubbles.changeBubblesGroup(evt.target.value);
},
changeColor: function(evt){
this.bubbles.changeBubblesColor(evt.target.value);
},
changeSize: function(evt){
this.bubbles.changeBubblesSize(evt.target.value);
},
clickCircle: function(evt){
var id=$(evt.currentTarget).data('mid');
this.$el.trigger('click.bubble', {id:id});
window.location.href = '#'+ this.uiModel.id + '/browse/'+id;
}
});