-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
103 lines (93 loc) · 3.07 KB
/
app.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
$(function() {
var context = {
dataset: "de-nrw-bonn",
siteUrl: "http://openspending.org",
pagesize: 50,
createLabel: function(widget, domElement, node) {
if ((node.data.value/widget.total)>0.03) {
domElement.innerHTML = "<div class='desc'><h2>" + $.format.number(node.data.value, '#,##0.') + "€</h2>" + node.name + "</div>";
}
}
};
OpenSpending.scriptRoot = "http://clients.openspending.org/zebralog/bonn/openspendingjs";
OpenSpending.WidgetLink = Backbone.Router.extend({
routes: {
"": "home",
"pg/:year/:art": "produktgruppe",
"pb/:name/:year/:art": "produktbereich"
},
home: function() {
OpenSpending.app.navigate('pg/2014/Aufwand', {trigger: true});
},
produktgruppe: function(year, art) {
var state = {
year: year,
prefix: 'pg',
drilldown: "produktbereich",
drilldowns: ["produktbereich"],
cuts: {
art: art
}
};
this.render(state, function(name) {
OpenSpending.app.navigate("pb/" + name + '/' + year + '/' + art, {trigger: true});
});
},
produktbereich: function(name, year, art) {
var state = {
year: year,
prefix: 'pb/' + name,
drilldown: "produktgruppe",
drilldowns: ["produktgruppe"],
cuts: {
produktbereich: name,
art: art
}
};
this.render(state, function(pname) {
var name_parts = pname.split("-");
document.location.href = 'http://clients.openspending.org/zebralog/bonn/details/' +
name_parts[0] + '.pdf';
});
},
render: function(state, callback) {
var treemap_ctx = _.extend(context, {
click: function(node) { callback(node.data.name); }
});
$('.openspending-link-filter').each(function(i, el) {
el = $(el);
var art = state.cuts.art;
var year = state.year;
if (el.data('year')) {
if (el.data('year')==year) {
el.addClass('disable');
} else {
year = el.data('year');
el.removeClass('disable');
}
}
if (el.data('art')) {
if (el.data('art')==art) {
el.addClass('disable');
} else {
art = el.data('art');
el.removeClass('disable');
}
}
el.prop('href', '#' + state.prefix + '/' + year + '/' + art);
});
var treemap_dfd = new OpenSpending.Treemap($('.openspending#vis_widget'), treemap_ctx, state);
var table_dfd = new OpenSpending.AggregateTable($('.openspending#table_widget'), context, state);
$.when(treemap_dfd.promise(), table_dfd.promise()).then(function(w) {
$('.openspending#table_widget').unbind('click', 'td a');
$('.openspending#table_widget').on('click', 'td a', function(e) {
var name = $(e.target).data('name') + '';
if (name.length<2) name = '0' + name;
callback(name);
return false;
});
});
}
});
OpenSpending.app = new OpenSpending.WidgetLink;
});